1 // Created on: 2014-11-24
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _SelectMgr_FrustumBuilder_HeaderFile
17 #define _SelectMgr_FrustumBuilder_HeaderFile
19 #include <Standard_DefineHandle.hxx>
21 #include <Graphic3d_Camera.hxx>
22 #include <Precision.hxx>
23 #include <SelectMgr_VectorTypes.hxx>
25 //! The purpose of this class is to provide unified interface for building
26 //! selecting frustum depending on current camera projection and orientation
27 //! matrices, window size and viewport parameters.
28 class SelectMgr_FrustumBuilder : public Standard_Transient
31 //! Creates new frustum builder with empty matrices
32 SelectMgr_FrustumBuilder();
34 //! Stores current orientation matrix
35 void SetOrientation (const Graphic3d_Mat4d& theOrientation);
37 //! Stores current projection matrix
38 void SetProjection (const Graphic3d_Mat4d& theProjection);
40 //! Stores current window width and height
41 void SetWindowSize (const Standard_Integer theWidth,
42 const Standard_Integer theHeight);
44 //! Stores current viewport coordinates
45 void SetViewport (const Standard_Real theX,
46 const Standard_Real theY,
47 const Standard_Real theWidth,
48 const Standard_Real theHeight);
50 void InvalidateViewport();
52 //! Calculates signed distance between plane with equation
53 //! theEq and point thePnt
54 Standard_Real SignedPlanePntDist (const SelectMgr_Vec3& theEq,
55 const SelectMgr_Vec3& thePnt) const;
57 //! Projects 2d screen point onto view frustum plane:
58 //! theZ = 0 - near plane,
59 //! theZ = 1 - far plane
60 SelectMgr_Vec3 ProjectPntOnViewPlane (const Standard_Real& theX,
61 const Standard_Real& theY,
62 const Standard_Real& theZ) const;
64 DEFINE_STANDARD_RTTI(SelectMgr_FrustumBuilder)
68 //! Unprojects point from NDC coords to 3d world space
69 SelectMgr_Vec3 unProject (const gp_Pnt& thePnt) const;
73 Graphic3d_Mat4d myOrientation;
74 Graphic3d_Mat4d myProjection;
75 Standard_Integer myWidth;
76 Standard_Integer myHeight;
77 NCollection_Vec4<Standard_Real> myViewport;
78 Standard_Boolean myIsViewportSet;
81 DEFINE_STANDARD_HANDLE(SelectMgr_FrustumBuilder, Standard_Transient)
83 #endif // _SelectMgr_FrustumBuilder_HeaderFile