CFx SDK Documentation  2022 SP0
TrVisCamera.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 // GLES2 camera
24 
25 #ifndef ODTRVISCAMERA
26 #define ODTRVISCAMERA
27 
28 #include <set>
29 
30 #include "TrVisDefs.h"
31 #include "TrVisExtentsDef.h"
32 #include "TrVisViewportDef.h"
33 
34 struct OdTrVisSurfaceDef;
35 
37 {
38 public:
41 
42  const OdTrVisViewParamsDef& viewParams(bool bUpdated = true) const { if (bUpdated && isModified()) update(); return m_viewParams; }
43  void setViewParams( const OdTrVisViewParamsDef& viewParams, bool bSetModified = false );
44 
45  bool isModified() const { return GETBIT( m_flags, kCameraModified ); }
46  // @@@TODO: eliminate this method usage. cameras must be linked with modified objects and must be updated automatically.
47  void markModified() { setModified(); }
48 
51 
55 
59 
60  void setContext(OdTrVisSurfaceDef *pSurface, OdTrVisViewportDef *pViewport, OdTrVisExtentsDef *pExtents)
61  { m_pSurfaceDef = pSurface; m_pViewportDef = pViewport; m_pExtentsDef = pExtents; }
62 
63  // Produce panning operation
64  virtual void pan(int nX, int nY);
65  // Produce simple zooming operation
66  virtual void zoom(float fDelta);
67  // Zooming around point
68  virtual void zoom(int nX, int nY, float fDelta);
69  // Orbit
70  enum OrbitType
71  {
75  kOrbitEye
76  };
77  virtual void orbit(int nX, int nY, OrbitType type = kOrbitPerp, float angle = 0.0f);
78  // Zoom extents
79  virtual void zoomExtents(float coef = 1.03f);
80 
81  // Low-level transformation routines
82  virtual void translate(const OdGeVector3d &offset);
83  virtual void rotate(double xAngle, double yAngle, double zAngle, bool bLocalCS = true);
84 
85  // Recalculate matrices
86  virtual void update() const;
87 
88  //Copy view params
89  virtual void copyViewParams( const OdTrVisCamera* );
90 
91  //OdTrVisViewParamsDef accessors
92 
94  void setViewPosition( const OdGePoint3d& pt )
95  {
97  setModified();
98  }
99 
100  const OdGeVector3d &viewBasisX() const { return m_viewParams.m_viewBasis[0]; }
101  void setViewBasisX(const OdGeVector3d &xBasis)
102  {
103  m_viewParams.m_viewBasis[0] = xBasis;
104  setModified();
105  }
106  const OdGeVector3d &viewBasisY() const { return m_viewParams.m_viewBasis[1]; }
107  void setViewBasisY(const OdGeVector3d &yBasis)
108  {
109  m_viewParams.m_viewBasis[1] = yBasis;
110  setModified();
111  }
112  const OdGeVector3d &viewBasisZ() const { return m_viewParams.m_viewBasis[2]; }
113  void setViewBasisZ(const OdGeVector3d &zBasis)
114  {
115  m_viewParams.m_viewBasis[2] = zBasis;
116  setModified();
117  }
118 
121  {
123  setModified();
124  }
125 
126  double fieldWidth() const { return m_viewParams.m_fieldWidth; }
127  void setFieldWidth( double w )
128  {
130  setModified();
131  }
132 
133  double fieldHeight() const { return m_viewParams.m_fieldHeight; }
134  void setFieldHeight( double h )
135  {
137  setModified();
138  }
139 
140  double lensLength() const { return m_viewParams.m_lensLength; }
141  void setLensLength( double l )
142  {
144  setModified();
145  }
146 
147  const OdGePoint3d &viewTarget() const { return m_viewParams.m_viewTarget; }
148  void setViewTarget( const OdGePoint3d& pt )
149  {
151  setModified();
152  }
153 
156  {
158  setModified();
159  }
160 
162  void setBackClip( const OdTrVisViewClipped& cl )
163  {
165  setModified();
166  }
167 
168  // Matrix accessors
169 
170  const OdGeMatrix3d &UnXForm() const { if (isModified()) update(); return m_UnXForm; }
171 
173  {
175  }
177  {
179  setModified();
180  }
181 
182  // Computed matrix accessors
183 
184  const OdGeMatrix3d &screenMatrix() const
185  {
186  if (isModified()) update();
188  }
189 
191  {
192  if (isModified()) update();
194  }
195 
197  {
198  if (isModified()) update();
200  }
201 
203  {
204  if (isModified()) update();
206  }
207 
208  const OdGeMatrix3d &outputMatrix() const
209  {
210  if (isModified()) update();
212  }
213 
214  // Extended data accessors
215 
216  double projectionScreenDepth() const
217  {
218  return projectionMatrix()(2, 3);
219  }
221  {
222  return projectionMatrix()(3, 2);
223  }
224  double projectionFocalLength() const
225  {
226  return -1.0 / projectionFocalLengthReciprocal();
227  }
229  {
231  }
232 
233  long screenWidht() const;
234  long screenHeight() const;
235 
236  // Extended viewport calculations
237 
238  bool viewportRect(OdGsDCRect &vpRect, bool bClipped = false) const;
239  void applyMetafileXform(bool bSetModified = false) const;
240 
241  // Temporary
242 
243  bool cameraCumulative() const { return GETBIT( m_flags, kCameraCumulative ); }
244  void setCameraCumulative( bool bSet ){ SETBIT( m_flags, kCameraCumulative, bSet ); }
245 
246 protected:
248  {
250  kCameraCumulative = 2 //Viewport parameters override was based onto basic viewport parameters
251  };
254  mutable OdUInt8 m_flags;
255 
257  std::set< OdTrVisCamera* > m_childCameras;
258 
262 
264  std::set< OdTrVisCamera* > m_overlayCameras;
265 
267  std::set< OdTrVisCamera* > m_siblingCameras;
268 
269 protected: //helpers
270  static double computeAspectRatio(const OdGsDCRectDouble& dcRect);
271  double computeFieldWidth(double aspectRatio) const;
272  double computeFieldHeight(double aspectRatio) const;
273  void projectedExtents(OdGePoint2d &extMin, OdGePoint2d &extMax, const OdGeExtents3d &extents) const;
274  static double computeFocalLength(double lensLength, double fieldWidth, double fieldHeight);
275  static void computeSceneDepth(const OdGeMatrix3d &ecsToWcs, const OdGeExtents3d &sceneExtents, double &dNear, double &dFar);
276  OdGeMatrix3d computeProjectionMatrix(const OdGsDCRectDouble &dcRect, const OdTrVisViewportDef* sets, const OdGeExtents3d &sceneExtents) const;
277  static OdGeMatrix3d computeCorrectionMatrix(const OdGsDCRectDouble &dcRect, double screenWidth, double screenHeight);
278 
279 protected:
283 
285 
287 
289  {
290  if( m_siblingCameras.empty() ) return NULL;
291  return *(m_siblingCameras.begin());
292  }
293 
294  void setModified(bool modified = true) const;
295 
296  const OdGeExtents3d &extents() const
297  {
300  }
301 };
302 
303 #endif
#define NULL
Definition: GsProperties.h:177
unsigned char OdUInt8
bool OdZero(double x, double tol=1.e-10)
Definition: OdaDefs.h:513
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:497
#define GETBIT(flags, bit)
Definition: OdaDefs.h:498
static GE_STATIC_EXPORT const OdGeExtents3d kInvalid
Definition: GeExtents3d.h:60
const OdGeMatrix3d & screenMatrix() const
Definition: TrVisCamera.h:184
OdUInt8 m_flags
Definition: TrVisCamera.h:254
const OdTrVisViewClipped & backClip() const
Definition: TrVisCamera.h:161
bool cameraCumulative() const
Definition: TrVisCamera.h:243
std::set< OdTrVisCamera * > m_siblingCameras
Definition: TrVisCamera.h:267
OdTrVisCamera * parentCamera() const
Definition: TrVisCamera.h:50
double projectionFocalLength() const
Definition: TrVisCamera.h:224
const OdGeMatrix3d & outputMatrix() const
Definition: TrVisCamera.h:208
void setViewBasisY(const OdGeVector3d &yBasis)
Definition: TrVisCamera.h:107
void setOverlayOwnerCamera(OdTrVisCamera *)
OdTrVisCamera * siblingOwnerCamera() const
Definition: TrVisCamera.h:57
void setChildCamera(OdTrVisCamera *)
double projectionFocalLengthReciprocal() const
Definition: TrVisCamera.h:220
void applyMetafileXform(bool bSetModified=false) const
const OdTrVisViewParamsDef & viewParams(bool bUpdated=true) const
Definition: TrVisCamera.h:42
void setOverlayCamera(OdTrVisCamera *)
const OdGeVector3d & viewBasisX() const
Definition: TrVisCamera.h:100
std::set< OdTrVisCamera * > m_childCameras
Definition: TrVisCamera.h:257
OdTrVisSurfaceDef * m_pSurfaceDef
Definition: TrVisCamera.h:259
OdTrVisCamera * m_pOverlayOwnerCamera
Definition: TrVisCamera.h:263
long screenWidht() const
void setViewBasisX(const OdGeVector3d &xBasis)
Definition: TrVisCamera.h:101
virtual void copyViewParams(const OdTrVisCamera *)
const OdGeMatrix3d & UnXForm() const
Definition: TrVisCamera.h:170
void setPerspectiveProjection(bool p)
Definition: TrVisCamera.h:120
const OdGeVector3d & viewBasisZ() const
Definition: TrVisCamera.h:112
void setCameraCumulative(bool bSet)
Definition: TrVisCamera.h:244
const OdGeExtents3d & extents() const
Definition: TrVisCamera.h:296
void preComputeViewportDefMatrices() const
const OdGeMatrix3d & projectionMatrix() const
Definition: TrVisCamera.h:196
void projectedExtents(OdGePoint2d &extMin, OdGePoint2d &extMax, const OdGeExtents3d &extents) const
void removeOverlayCamera(OdTrVisCamera *)
void setMetafileMatrix(const OdGeMatrix3d &m)
Definition: TrVisCamera.h:176
OdTrVisViewportDef * m_pViewportDef
Definition: TrVisCamera.h:260
const OdGePoint3d & viewTarget() const
Definition: TrVisCamera.h:147
void setParentCamera(OdTrVisCamera *)
bool viewportRect(OdGsDCRect &vpRect, bool bClipped=false) const
void setSiblingCamera(OdTrVisCamera *)
bool isPerspectiveProjection() const
Definition: TrVisCamera.h:119
double fieldWidth() const
Definition: TrVisCamera.h:126
virtual void zoomExtents(float coef=1.03f)
OdTrVisCamera * m_pParentCamera
Definition: TrVisCamera.h:256
virtual void translate(const OdGeVector3d &offset)
virtual void zoom(int nX, int nY, float fDelta)
double fieldHeight() const
Definition: TrVisCamera.h:133
static void computeSceneDepth(const OdGeMatrix3d &ecsToWcs, const OdGeExtents3d &sceneExtents, double &dNear, double &dFar)
void setModified(bool modified=true) const
void setViewPosition(const OdGePoint3d &pt)
Definition: TrVisCamera.h:94
static double computeFocalLength(double lensLength, double fieldWidth, double fieldHeight)
void setBackClip(const OdTrVisViewClipped &cl)
Definition: TrVisCamera.h:162
OdTrVisCamera * overlayOwnerCamera() const
Definition: TrVisCamera.h:53
virtual void orbit(int nX, int nY, OrbitType type=kOrbitPerp, float angle=0.0f)
void setFieldWidth(double w)
Definition: TrVisCamera.h:127
void removeChildCamera(OdTrVisCamera *)
const OdTrVisViewClipped & frontClip() const
Definition: TrVisCamera.h:154
void setFrontClip(const OdTrVisViewClipped &cl)
Definition: TrVisCamera.h:155
virtual void pan(int nX, int nY)
void setFieldHeight(double h)
Definition: TrVisCamera.h:134
OdTrVisViewParamsDef m_viewParams
Definition: TrVisCamera.h:252
double lensLength() const
Definition: TrVisCamera.h:140
OdTrVisCamera * m_pSiblingOwnerCamera
Definition: TrVisCamera.h:266
const OdGeMatrix3d & correctionMatrix() const
Definition: TrVisCamera.h:202
OdGeMatrix3d computeProjectionMatrix(const OdGsDCRectDouble &dcRect, const OdTrVisViewportDef *sets, const OdGeExtents3d &sceneExtents) const
void removeSiblingCamera(OdTrVisCamera *)
long screenHeight() const
double computeFieldHeight(double aspectRatio) const
virtual void zoom(float fDelta)
void setContext(OdTrVisSurfaceDef *pSurface, OdTrVisViewportDef *pViewport, OdTrVisExtentsDef *pExtents)
Definition: TrVisCamera.h:60
OdTrVisCamera * sibling()
Definition: TrVisCamera.h:288
const OdGePoint3d & viewPosition() const
Definition: TrVisCamera.h:93
virtual void update() const
bool isModified() const
Definition: TrVisCamera.h:45
OdGeMatrix3d m_UnXForm
Definition: TrVisCamera.h:253
virtual void rotate(double xAngle, double yAngle, double zAngle, bool bLocalCS=true)
double projectionScreenDepth() const
Definition: TrVisCamera.h:216
const OdGeMatrix3d & viewingMatrix() const
Definition: TrVisCamera.h:190
static double computeAspectRatio(const OdGsDCRectDouble &dcRect)
void markModified()
Definition: TrVisCamera.h:47
void setSiblingOwnerCamera(OdTrVisCamera *)
const OdGeMatrix3d & metafileMatrix() const
Definition: TrVisCamera.h:172
double computeFieldWidth(double aspectRatio) const
OdTrVisExtentsDef * m_pExtentsDef
Definition: TrVisCamera.h:261
std::set< OdTrVisCamera * > m_overlayCameras
Definition: TrVisCamera.h:264
bool projectionPerspective() const
Definition: TrVisCamera.h:228
void setLensLength(double l)
Definition: TrVisCamera.h:141
void setViewParams(const OdTrVisViewParamsDef &viewParams, bool bSetModified=false)
static OdGeMatrix3d computeCorrectionMatrix(const OdGsDCRectDouble &dcRect, double screenWidth, double screenHeight)
void setViewBasisZ(const OdGeVector3d &zBasis)
Definition: TrVisCamera.h:113
const OdGeVector3d & viewBasisY() const
Definition: TrVisCamera.h:106
void setViewTarget(const OdGePoint3d &pt)
Definition: TrVisCamera.h:148
GLfloat GLfloat GLfloat GLfloat w
Definition: gles2_ext.h:320
GLuint GLsizei GLsizei GLint GLenum * type
Definition: gles2_ext.h:274
GLintptr offset
Definition: gles2_ext.h:183
const OdGeExtents3d & preferRealExtents() const
OdTrVisViewClipped m_frontClip
OdGeMatrix3d m_outputMatrix
OdGeMatrix3d m_viewingMatrix
OdTrVisViewClipped m_backClip
OdGeMatrix3d m_correctionMatrix
OdGeVector3d m_viewBasis[3]
OdGeMatrix3d m_projectionMatrix
OdGeMatrix3d m_screenMatrix
OdGePoint3d m_viewPosition
OdGeMatrix3d m_metafileMatrix