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 |
29 | class SelectMgr_FrustumBuilder : public Standard_Transient |
f751596e |
30 | { |
31 | public: |
32 | //! Creates new frustum builder with empty matrices |
33 | SelectMgr_FrustumBuilder(); |
34 | |
825aa485 |
35 | //! Stores current world view transformation matrix |
36 | void SetWorldViewMatrix (const Graphic3d_Mat4d& theWorldViewMatrix); |
37 | |
38 | //! @return current world view transformation matrix |
39 | const Graphic3d_Mat4d& WorldViewMatrix() const; |
f751596e |
40 | |
41 | //! Stores current projection matrix |
825aa485 |
42 | void SetProjectionMatrix (const Graphic3d_Mat4d& theProjection); |
43 | |
44 | //! @return current projection matrix |
45 | const Graphic3d_Mat4d& ProjectionMatrix() const; |
46 | |
47 | //! Stores current world view projection matrix state for the orientation and projection matrices |
48 | void SetWorldViewProjState (const Graphic3d_WorldViewProjState& theState); |
49 | |
50 | //! @return current world view projection state |
51 | const Graphic3d_WorldViewProjState& WorldViewProjState() const; |
f751596e |
52 | |
53 | //! Stores current window width and height |
54 | void SetWindowSize (const Standard_Integer theWidth, |
55 | const Standard_Integer theHeight); |
56 | |
57 | //! Stores current viewport coordinates |
58 | void SetViewport (const Standard_Real theX, |
59 | const Standard_Real theY, |
60 | const Standard_Real theWidth, |
61 | const Standard_Real theHeight); |
62 | |
63 | void InvalidateViewport(); |
64 | |
65 | //! Calculates signed distance between plane with equation |
66 | //! theEq and point thePnt |
67 | Standard_Real SignedPlanePntDist (const SelectMgr_Vec3& theEq, |
68 | const SelectMgr_Vec3& thePnt) const; |
69 | |
f751596e |
70 | //! Projects 2d screen point onto view frustum plane: |
71 | //! theZ = 0 - near plane, |
72 | //! theZ = 1 - far plane |
73 | SelectMgr_Vec3 ProjectPntOnViewPlane (const Standard_Real& theX, |
74 | const Standard_Real& theY, |
75 | const Standard_Real& theZ) const; |
76 | |
ec357c5c |
77 | DEFINE_STANDARD_RTTI(SelectMgr_FrustumBuilder, Standard_Transient) |
bf3977c9 |
78 | |
f751596e |
79 | private: |
80 | |
81 | //! Unprojects point from NDC coords to 3d world space |
82 | SelectMgr_Vec3 unProject (const gp_Pnt& thePnt) const; |
83 | |
84 | private: |
85 | |
825aa485 |
86 | Graphic3d_Mat4d myWorldView; |
f751596e |
87 | Graphic3d_Mat4d myProjection; |
825aa485 |
88 | Graphic3d_WorldViewProjState myWorldViewProjState; |
f751596e |
89 | Standard_Integer myWidth; |
90 | Standard_Integer myHeight; |
91 | NCollection_Vec4<Standard_Real> myViewport; |
92 | Standard_Boolean myIsViewportSet; |
93 | }; |
94 | |
bf3977c9 |
95 | DEFINE_STANDARD_HANDLE(SelectMgr_FrustumBuilder, Standard_Transient) |
96 | |
f751596e |
97 | #endif // _SelectMgr_FrustumBuilder_HeaderFile |