0027536: Visualization - incorrect behavior of zoom persisted objects
[occt.git] / src / SelectMgr / SelectMgr_FrustumBuilder.hxx
CommitLineData
f751596e 1// Created on: 2014-11-24
2// Created by: Varvara POSKONINA
3// Copyright (c) 2005-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _SelectMgr_FrustumBuilder_HeaderFile
17#define _SelectMgr_FrustumBuilder_HeaderFile
18
ec357c5c 19#include <Standard_Type.hxx>
bf3977c9 20
f751596e 21#include <Graphic3d_Camera.hxx>
825aa485 22#include <Graphic3d_WorldViewProjState.hxx>
f751596e 23#include <Precision.hxx>
24#include <SelectMgr_VectorTypes.hxx>
25
26//! The purpose of this class is to provide unified interface for building
27//! selecting frustum depending on current camera projection and orientation
28//! matrices, window size and viewport parameters.
bf3977c9 29class SelectMgr_FrustumBuilder : public Standard_Transient
f751596e 30{
31public:
32 //! Creates new frustum builder with empty matrices
33 SelectMgr_FrustumBuilder();
34
825aa485 35 //! Stores current world view transformation matrix
1f3913c6 36 Standard_EXPORT void SetWorldViewMatrix (const Graphic3d_Mat4d& theWorldViewMatrix);
825aa485 37
38 //! @return current world view transformation matrix
1f3913c6 39 Standard_EXPORT const Graphic3d_Mat4d& WorldViewMatrix() const;
f751596e 40
41 //! Stores current projection matrix
1f3913c6 42 Standard_EXPORT void SetProjectionMatrix (const Graphic3d_Mat4d& theProjection);
825aa485 43
44 //! @return current projection matrix
1f3913c6 45 Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const;
825aa485 46
47 //! Stores current world view projection matrix state for the orientation and projection matrices
1f3913c6 48 Standard_EXPORT void SetWorldViewProjState (const Graphic3d_WorldViewProjState& theState);
825aa485 49
50 //! @return current world view projection state
1f3913c6 51 Standard_EXPORT const Graphic3d_WorldViewProjState& WorldViewProjState() const;
f751596e 52
53 //! Stores current window width and height
1f3913c6 54 Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth,
55 const Standard_Integer theHeight);
f751596e 56
57 //! Stores current viewport coordinates
1f3913c6 58 Standard_EXPORT void SetViewport (const Standard_Real theX,
59 const Standard_Real theY,
60 const Standard_Real theWidth,
61 const Standard_Real theHeight);
f751596e 62
1f3913c6 63 Standard_EXPORT void InvalidateViewport();
f751596e 64
91d96372 65 Standard_EXPORT void WindowSize (Standard_Integer& theWidth,
66 Standard_Integer& theHeight);
67
f751596e 68 //! Calculates signed distance between plane with equation
69 //! theEq and point thePnt
1f3913c6 70 Standard_EXPORT Standard_Real SignedPlanePntDist (const SelectMgr_Vec3& theEq,
71 const SelectMgr_Vec3& thePnt) const;
f751596e 72
f751596e 73 //! Projects 2d screen point onto view frustum plane:
74 //! theZ = 0 - near plane,
75 //! theZ = 1 - far plane
3bf9a45f 76 Standard_EXPORT gp_Pnt ProjectPntOnViewPlane (const Standard_Real& theX,
77 const Standard_Real& theY,
78 const Standard_Real& theZ) const;
f751596e 79
92efcf78 80 DEFINE_STANDARD_RTTIEXT(SelectMgr_FrustumBuilder,Standard_Transient)
bf3977c9 81
f751596e 82private:
83
84 //! Unprojects point from NDC coords to 3d world space
3bf9a45f 85 gp_Pnt unProject (const gp_Pnt& thePnt) const;
f751596e 86
87private:
88
825aa485 89 Graphic3d_Mat4d myWorldView;
f751596e 90 Graphic3d_Mat4d myProjection;
825aa485 91 Graphic3d_WorldViewProjState myWorldViewProjState;
f751596e 92 Standard_Integer myWidth;
93 Standard_Integer myHeight;
94 NCollection_Vec4<Standard_Real> myViewport;
95 Standard_Boolean myIsViewportSet;
96};
97
bf3977c9 98DEFINE_STANDARD_HANDLE(SelectMgr_FrustumBuilder, Standard_Transient)
99
f751596e 100#endif // _SelectMgr_FrustumBuilder_HeaderFile