CFx SDK Documentation  2020SP3
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
GETBIT
#define GETBIT(flags, bit)
Definition: OdaDefs.h:498
OdTrVisCamera::overlayOwnerCamera
OdTrVisCamera * overlayOwnerCamera() const
Definition: TrVisCamera.h:53
OdTrVisCamera::isModified
bool isModified() const
Definition: TrVisCamera.h:45
OdTrVisCamera::computeAspectRatio
static double computeAspectRatio(const OdGsDCRectDouble &dcRect)
OdTrVisCamera::viewBasisZ
const OdGeVector3d & viewBasisZ() const
Definition: TrVisCamera.h:112
OdTrVisCamera::isPerspectiveProjection
bool isPerspectiveProjection() const
Definition: TrVisCamera.h:119
OdTrVisCamera::CameraFlags
CameraFlags
Definition: TrVisCamera.h:248
OdTrVisCamera::m_siblingCameras
std::set< OdTrVisCamera * > m_siblingCameras
Definition: TrVisCamera.h:267
OdTrVisCamera::setOverlayOwnerCamera
void setOverlayOwnerCamera(OdTrVisCamera *)
OdTrVisCamera::viewportRect
bool viewportRect(OdGsDCRect &vpRect, bool bClipped=false) const
OdGeVector3d
Definition: GeVector3d.h:54
OdTrVisCamera::frontClip
const OdTrVisViewClipped & frontClip() const
Definition: TrVisCamera.h:154
NULL
#define NULL
Definition: GsProperties.h:177
OdTrVisCamera::viewTarget
const OdGePoint3d & viewTarget() const
Definition: TrVisCamera.h:147
OdTrVisCamera::computeProjectionMatrix
OdGeMatrix3d computeProjectionMatrix(const OdGsDCRectDouble &dcRect, const OdTrVisViewportDef *sets, const OdGeExtents3d &sceneExtents) const
OdTrVisViewParamsDef::m_screenMatrix
OdGeMatrix3d m_screenMatrix
Definition: TrVisOverlayDef.h:114
OdTrVisCamera::orbit
virtual void orbit(int nX, int nY, OrbitType type=kOrbitPerp, float angle=0.0f)
OdUInt8
unsigned char OdUInt8
Definition: OdPlatformSettings.h:759
OdTrVisCamera::correctionMatrix
const OdGeMatrix3d & correctionMatrix() const
Definition: TrVisCamera.h:202
OdTrVisCamera::setFieldWidth
void setFieldWidth(double w)
Definition: TrVisCamera.h:127
OdTrVisCamera::viewBasisX
const OdGeVector3d & viewBasisX() const
Definition: TrVisCamera.h:100
OdTrVisCamera::setBackClip
void setBackClip(const OdTrVisViewClipped &cl)
Definition: TrVisCamera.h:162
OdTrVisCamera::fieldWidth
double fieldWidth() const
Definition: TrVisCamera.h:126
OdGsDCRectDouble
Definition: GsDefs.h:242
OdTrVisCamera::outputMatrix
const OdGeMatrix3d & outputMatrix() const
Definition: TrVisCamera.h:208
OdTrVisViewParamsDef::m_bPerspectiveProjection
bool m_bPerspectiveProjection
Definition: TrVisOverlayDef.h:123
OdTrVisCamera::screenHeight
long screenHeight() const
OdTrVisCamera::copyViewParams
virtual void copyViewParams(const OdTrVisCamera *)
OdTrVisCamera::setViewPosition
void setViewPosition(const OdGePoint3d &pt)
Definition: TrVisCamera.h:94
OdTrVisCamera::fieldHeight
double fieldHeight() const
Definition: TrVisCamera.h:133
type
GLuint GLsizei GLsizei GLint GLenum * type
Definition: gles2_ext.h:274
OdTrVisExtentsDef
Definition: TrVisExtentsDef.h:36
OdTrVisViewParamsDef::m_viewBasis
OdGeVector3d m_viewBasis[3]
Definition: TrVisOverlayDef.h:122
OdTrVisCamera::setContext
void setContext(OdTrVisSurfaceDef *pSurface, OdTrVisViewportDef *pViewport, OdTrVisExtentsDef *pExtents)
Definition: TrVisCamera.h:60
OdTrVisCamera::removeOverlayCamera
void removeOverlayCamera(OdTrVisCamera *)
OdTrVisCamera::projectionScreenDepth
double projectionScreenDepth() const
Definition: TrVisCamera.h:216
OdGsDCRect
Definition: GsDefs.h:111
OdTrVisCamera::setFieldHeight
void setFieldHeight(double h)
Definition: TrVisCamera.h:134
OdTrVisViewportDef
Definition: TrVisViewportDef.h:42
SETBIT
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:497
OdTrVisCamera::m_viewParams
OdTrVisViewParamsDef m_viewParams
Definition: TrVisCamera.h:252
OdTrVisCamera::setViewBasisZ
void setViewBasisZ(const OdGeVector3d &zBasis)
Definition: TrVisCamera.h:113
OdTrVisCamera::kCameraModified
@ kCameraModified
Definition: TrVisCamera.h:249
OdTrVisCamera::preComputeViewportDefMatrices
void preComputeViewportDefMatrices() const
OdTrVisCamera::applyMetafileXform
void applyMetafileXform(bool bSetModified=false) const
TrVisViewportDef.h
OdTrVisCamera::setModified
void setModified(bool modified=true) const
OdTrVisCamera::m_flags
OdUInt8 m_flags
Definition: TrVisCamera.h:254
OdTrVisCamera::viewingMatrix
const OdGeMatrix3d & viewingMatrix() const
Definition: TrVisCamera.h:190
OdTrVisCamera::computeFieldWidth
double computeFieldWidth(double aspectRatio) const
OdTrVisCamera::projectedExtents
void projectedExtents(OdGePoint2d &extMin, OdGePoint2d &extMax, const OdGeExtents3d &extents) const
OdTrVisCamera::removeSiblingCamera
void removeSiblingCamera(OdTrVisCamera *)
OdTrVisCamera::setMetafileMatrix
void setMetafileMatrix(const OdGeMatrix3d &m)
Definition: TrVisCamera.h:176
OdTrVisCamera::projectionFocalLengthReciprocal
double projectionFocalLengthReciprocal() const
Definition: TrVisCamera.h:220
OdTrVisViewParamsDef::m_fieldHeight
double m_fieldHeight
Definition: TrVisOverlayDef.h:126
OdGeMatrix3d
Definition: GeMatrix3d.h:73
OdTrVisCamera::setParentCamera
void setParentCamera(OdTrVisCamera *)
OdTrVisCamera::~OdTrVisCamera
~OdTrVisCamera()
OdTrVisCamera::OrbitType
OrbitType
Definition: TrVisCamera.h:71
OdTrVisCamera::setSiblingCamera
void setSiblingCamera(OdTrVisCamera *)
OdTrVisViewParamsDef::m_viewPosition
OdGePoint3d m_viewPosition
Definition: TrVisOverlayDef.h:121
OdTrVisCamera::kOrbitVertical
@ kOrbitVertical
Definition: TrVisCamera.h:74
OdTrVisCamera::lensLength
double lensLength() const
Definition: TrVisCamera.h:140
OdTrVisViewParamsDef::m_projectionMatrix
OdGeMatrix3d m_projectionMatrix
Definition: TrVisOverlayDef.h:116
OdTrVisViewParamsDef::m_viewingMatrix
OdGeMatrix3d m_viewingMatrix
Definition: TrVisOverlayDef.h:115
w
GLfloat GLfloat GLfloat GLfloat w
Definition: gles2_ext.h:320
OdTrVisCamera::siblingOwnerCamera
OdTrVisCamera * siblingOwnerCamera() const
Definition: TrVisCamera.h:57
OdTrVisCamera::backClip
const OdTrVisViewClipped & backClip() const
Definition: TrVisCamera.h:161
OdTrVisCamera::removeChildCamera
void removeChildCamera(OdTrVisCamera *)
OdTrVisCamera::kOrbitPerp
@ kOrbitPerp
Definition: TrVisCamera.h:72
OdTrVisExtentsDef::preferRealExtents
const OdGeExtents3d & preferRealExtents() const
Definition: TrVisExtentsDef.h:73
OdTrVisCamera::pan
virtual void pan(int nX, int nY)
OdTrVisCamera::computeCorrectionMatrix
static OdGeMatrix3d computeCorrectionMatrix(const OdGsDCRectDouble &dcRect, double screenWidth, double screenHeight)
OdTrVisCamera::rotate
virtual void rotate(double xAngle, double yAngle, double zAngle, bool bLocalCS=true)
OdGePoint3d
Definition: GePoint3d.h:55
offset
GLintptr offset
Definition: gles2_ext.h:183
OdTrVisCamera::screenWidht
long screenWidht() const
OdTrVisCamera::setOverlayCamera
void setOverlayCamera(OdTrVisCamera *)
OdTrVisCamera::setViewTarget
void setViewTarget(const OdGePoint3d &pt)
Definition: TrVisCamera.h:148
OdTrVisCamera::screenMatrix
const OdGeMatrix3d & screenMatrix() const
Definition: TrVisCamera.h:184
OdTrVisCamera::viewBasisY
const OdGeVector3d & viewBasisY() const
Definition: TrVisCamera.h:106
OdTrVisCamera::cameraCumulative
bool cameraCumulative() const
Definition: TrVisCamera.h:243
OdTrVisCamera::translate
virtual void translate(const OdGeVector3d &offset)
OdTrVisCamera::update
virtual void update() const
OdTrVisCamera::m_pViewportDef
OdTrVisViewportDef * m_pViewportDef
Definition: TrVisCamera.h:260
OdTrVisCamera::extents
const OdGeExtents3d & extents() const
Definition: TrVisCamera.h:296
OdTrVisCamera::projectionFocalLength
double projectionFocalLength() const
Definition: TrVisCamera.h:224
OdTrVisCamera::m_pParentCamera
OdTrVisCamera * m_pParentCamera
Definition: TrVisCamera.h:256
TrVisDefs.h
OdTrVisCamera::setFrontClip
void setFrontClip(const OdTrVisViewClipped &cl)
Definition: TrVisCamera.h:155
OdTrVisCamera::computeFieldHeight
double computeFieldHeight(double aspectRatio) const
OdTrVisViewParamsDef::m_backClip
OdTrVisViewClipped m_backClip
Definition: TrVisOverlayDef.h:130
OdTrVisCamera::m_pExtentsDef
OdTrVisExtentsDef * m_pExtentsDef
Definition: TrVisCamera.h:261
OdTrVisCamera::parentCamera
OdTrVisCamera * parentCamera() const
Definition: TrVisCamera.h:50
OdTrVisViewParamsDef::m_frontClip
OdTrVisViewClipped m_frontClip
Definition: TrVisOverlayDef.h:129
OdTrVisCamera::m_pSurfaceDef
OdTrVisSurfaceDef * m_pSurfaceDef
Definition: TrVisCamera.h:259
OdTrVisCamera::setLensLength
void setLensLength(double l)
Definition: TrVisCamera.h:141
OdTrVisCamera
Definition: TrVisCamera.h:37
OdTrVisCamera::zoom
virtual void zoom(float fDelta)
OdTrVisCamera::setViewParams
void setViewParams(const OdTrVisViewParamsDef &viewParams, bool bSetModified=false)
OdTrVisCamera::setPerspectiveProjection
void setPerspectiveProjection(bool p)
Definition: TrVisCamera.h:120
OdTrVisViewClipped
Definition: TrVisOverlayDef.h:92
OdTrVisCamera::zoom
virtual void zoom(int nX, int nY, float fDelta)
OdTrVisCamera::computeSceneDepth
static void computeSceneDepth(const OdGeMatrix3d &ecsToWcs, const OdGeExtents3d &sceneExtents, double &dNear, double &dFar)
OdTrVisCamera::kOrbitHorizontal
@ kOrbitHorizontal
Definition: TrVisCamera.h:73
OdTrVisCamera::metafileMatrix
const OdGeMatrix3d & metafileMatrix() const
Definition: TrVisCamera.h:172
OdTrVisCamera::zoomExtents
virtual void zoomExtents(float coef=1.03f)
OdTrVisCamera::sibling
OdTrVisCamera * sibling()
Definition: TrVisCamera.h:288
OdTrVisCamera::m_pSiblingOwnerCamera
OdTrVisCamera * m_pSiblingOwnerCamera
Definition: TrVisCamera.h:266
OdTrVisCamera::m_UnXForm
OdGeMatrix3d m_UnXForm
Definition: TrVisCamera.h:253
OdTrVisViewParamsDef::m_fieldWidth
double m_fieldWidth
Definition: TrVisOverlayDef.h:125
OdTrVisCamera::setChildCamera
void setChildCamera(OdTrVisCamera *)
OdTrVisCamera::projectionMatrix
const OdGeMatrix3d & projectionMatrix() const
Definition: TrVisCamera.h:196
OdTrVisCamera::kCameraCumulative
@ kCameraCumulative
Definition: TrVisCamera.h:250
OdTrVisCamera::setSiblingOwnerCamera
void setSiblingOwnerCamera(OdTrVisCamera *)
OdTrVisCamera::setCameraCumulative
void setCameraCumulative(bool bSet)
Definition: TrVisCamera.h:244
OdGeExtents3d
Definition: GeExtents3d.h:45
OdTrVisViewParamsDef
Definition: TrVisOverlayDef.h:112
f
GLfloat f
Definition: gles2_ext.h:564
OdTrVisViewParamsDef::m_metafileMatrix
OdGeMatrix3d m_metafileMatrix
Definition: TrVisOverlayDef.h:119
OdTrVisCamera::setViewBasisY
void setViewBasisY(const OdGeVector3d &yBasis)
Definition: TrVisCamera.h:107
OdTrVisCamera::viewPosition
const OdGePoint3d & viewPosition() const
Definition: TrVisCamera.h:93
OdTrVisViewParamsDef::m_correctionMatrix
OdGeMatrix3d m_correctionMatrix
Definition: TrVisOverlayDef.h:117
TrVisExtentsDef.h
OdTrVisCamera::computeFocalLength
static double computeFocalLength(double lensLength, double fieldWidth, double fieldHeight)
OdTrVisCamera::kOrbitEye
@ kOrbitEye
Definition: TrVisCamera.h:75
OdTrVisViewParamsDef::m_lensLength
double m_lensLength
Definition: TrVisOverlayDef.h:127
OdTrVisCamera::setViewBasisX
void setViewBasisX(const OdGeVector3d &xBasis)
Definition: TrVisCamera.h:101
OdTrVisCamera::m_pOverlayOwnerCamera
OdTrVisCamera * m_pOverlayOwnerCamera
Definition: TrVisCamera.h:263
OdGeExtents3d::kInvalid
static GE_STATIC_EXPORT const OdGeExtents3d kInvalid
Definition: GeExtents3d.h:60
OdTrVisCamera::UnXForm
const OdGeMatrix3d & UnXForm() const
Definition: TrVisCamera.h:170
OdTrVisSurfaceDef
Definition: TrVisSurfaceDef.h:36
OdTrVisCamera::m_overlayCameras
std::set< OdTrVisCamera * > m_overlayCameras
Definition: TrVisCamera.h:264
OdTrVisCamera::markModified
void markModified()
Definition: TrVisCamera.h:47
OdZero
bool OdZero(double x, double tol=1.e-10)
Definition: OdaDefs.h:513
OdTrVisViewParamsDef::m_viewTarget
OdGePoint3d m_viewTarget
Definition: TrVisOverlayDef.h:128
OdTrVisCamera::OdTrVisCamera
OdTrVisCamera()
OdTrVisCamera::viewParams
const OdTrVisViewParamsDef & viewParams(bool bUpdated=true) const
Definition: TrVisCamera.h:42
OdTrVisCamera::projectionPerspective
bool projectionPerspective() const
Definition: TrVisCamera.h:228
OdTrVisViewParamsDef::m_outputMatrix
OdGeMatrix3d m_outputMatrix
Definition: TrVisOverlayDef.h:118
OdTrVisCamera::m_childCameras
std::set< OdTrVisCamera * > m_childCameras
Definition: TrVisCamera.h:257
OdGePoint2d
Definition: GePoint2d.h:60