CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
TrVisCamera.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 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
35
37{
38public:
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.
48
51
55
59
60 void setContext(const OdTrVisSurfaceDef *pSurface, const OdTrVisViewportShadingDef *pViewportShading,
61 const OdTrVisViewportClipDef *pViewportClip, const OdTrVisExtentsDef *pExtents)
62 { m_pSurfaceDef = pSurface; m_pViewportShadingDef = pViewportShading; m_pViewportClipDef = pViewportClip; m_pExtentsDef = pExtents; }
63
64 // Produce panning operation
65 virtual void pan(int nX, int nY);
66 // Produce simple zooming operation
67 virtual void zoom(float fDelta);
68 // Zooming around point
69 virtual void zoom(int nX, int nY, float fDelta);
70 // Orbit
72 {
77 };
78 virtual void orbit(int nX, int nY, OrbitType type = kOrbitPerp, float angle = 0.0f);
79 // Zoom extents
80 virtual void zoomExtents(float coef = 1.03f);
81
82 // Low-level transformation routines
83 virtual void translate(const OdGeVector3d &offset);
84 virtual void rotate(double xAngle, double yAngle, double zAngle, bool bLocalCS = true);
85
86 // Recalculate matrices
87 virtual void update() const;
88
89 //Copy view params
90 virtual void copyViewParams( const OdTrVisCamera* );
91
92 //OdTrVisViewParamsDef accessors
93
95 void setViewPosition( const OdGePoint3d& pt )
96 {
99 }
100
102 void setViewBasisX(const OdGeVector3d &xBasis)
103 {
105 setModified();
106 }
108 void setViewBasisY(const OdGeVector3d &yBasis)
109 {
111 setModified();
112 }
114 void setViewBasisZ(const OdGeVector3d &zBasis)
115 {
117 setModified();
118 }
119
122 {
124 setModified();
125 }
126
127 double fieldWidth() const { return m_viewParams.m_fieldWidth; }
128 void setFieldWidth( double w )
129 {
131 setModified();
132 }
133
134 double fieldHeight() const { return m_viewParams.m_fieldHeight; }
135 void setFieldHeight( double h )
136 {
138 setModified();
139 }
140
141 double lensLength() const { return m_viewParams.m_lensLength; }
142 void setLensLength( double l )
143 {
145 setModified();
146 }
147
149 void setViewTarget( const OdGePoint3d& pt )
150 {
152 setModified();
153 }
154
157 {
159 setModified();
160 }
161
164 {
166 setModified();
167 }
168
169 bool hasViewClip() const { return backClip().enabled() || frontClip().enabled(); }
170
171 // Matrix accessors
172
173 const OdGeMatrix3d &UnXForm() const { if (isModified()) update(); return m_UnXForm; }
174
176 {
178 }
179 bool hasMetafileMatrix() const
180 {
182 }
184 {
186 setModified();
187 }
188
189 // Computed matrix accessors
190
192 {
193 if (isModified()) update();
195 }
196
198 {
199 if (isModified()) update();
201 }
202
204 {
205 if (isModified()) update();
207 }
208
210 {
211 if (isModified()) update();
213 }
214
216 {
217 if (isModified()) update();
219 }
220
221 // Extended data accessors
222
224 {
225 return projectionMatrix()(2, 3);
226 }
228 {
229 return projectionMatrix()(3, 2);
230 }
232 {
233 return -1.0 / projectionFocalLengthReciprocal();
234 }
236 {
238 }
239
240 long screenWidth() const;
241 long screenHeight() const;
242
243 // Extended viewport calculations
244
245 bool viewportRect(OdGsDCRect &vpRect, bool bClipped = false) const;
246 void applyMetafileXform(bool bSetModified = false) const;
247
248 // Temporary
249
251 void setCameraCumulative( bool bSet ){ SETBIT( m_flags, kCameraCumulative, bSet ); }
252
253protected:
255 {
257 kCameraCumulative = 2 //Viewport parameters override was based onto basic viewport parameters
258 };
262
264 std::set< OdTrVisCamera* > m_childCameras;
265
270
272 std::set< OdTrVisCamera* > m_overlayCameras;
273
275 std::set< OdTrVisCamera* > m_siblingCameras;
276
277protected: //helpers
278 static double computeAspectRatio(const OdGsDCRectDouble& dcRect);
279 double computeFieldWidth(double aspectRatio) const;
280 double computeFieldHeight(double aspectRatio) const;
281 void projectedExtents(OdGePoint2d &extMin, OdGePoint2d &extMax, const OdGeExtents3d &extents) const;
282 static double computeFocalLength(double lensLength, double fieldWidth, double fieldHeight);
283 static void computeSceneDepth(const OdGeMatrix3d &ecsToWcs, const OdGeExtents3d &sceneExtents, double &dNear, double &dFar);
286
287protected:
291
293
295
297 {
298 if( m_siblingCameras.empty() ) return NULL;
299 return *(m_siblingCameras.begin());
300 }
301
302 void setModified(bool modified = true) const;
303
304 const OdGeExtents3d &extents() const
305 {
308 }
309};
310
311#endif
unsigned char OdUInt8
bool OdZero(double x, double tol=1.e-10)
Definition: OdaDefs.h:532
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:516
#define GETBIT(flags, bit)
Definition: OdaDefs.h:517
static GE_STATIC_EXPORT const OdGeExtents3d kInvalid
Definition: GeExtents3d.h:65
bool isEqualTo(const OdGeMatrix3d &matrix, const OdGeTol &tol=OdGeContext::gTol) const
static GE_STATIC_EXPORT const OdGeMatrix3d kIdentity
Definition: GeMatrix3d.h:97
OdUInt8 m_flags
Definition: TrVisCamera.h:261
bool cameraCumulative() const
Definition: TrVisCamera.h:250
OdTrVisCamera * parentCamera() const
Definition: TrVisCamera.h:50
std::set< OdTrVisCamera * > m_siblingCameras
Definition: TrVisCamera.h:275
double projectionFocalLength() const
Definition: TrVisCamera.h:231
void setViewBasisY(const OdGeVector3d &yBasis)
Definition: TrVisCamera.h:108
void setOverlayOwnerCamera(OdTrVisCamera *)
const OdGeMatrix3d & projectionMatrix() const
Definition: TrVisCamera.h:203
void setChildCamera(OdTrVisCamera *)
double projectionFocalLengthReciprocal() const
Definition: TrVisCamera.h:227
void applyMetafileXform(bool bSetModified=false) const
void setOverlayCamera(OdTrVisCamera *)
std::set< OdTrVisCamera * > m_childCameras
Definition: TrVisCamera.h:264
OdTrVisCamera * m_pOverlayOwnerCamera
Definition: TrVisCamera.h:271
void setViewBasisX(const OdGeVector3d &xBasis)
Definition: TrVisCamera.h:102
const OdGeMatrix3d & metafileMatrix() const
Definition: TrVisCamera.h:175
const OdTrVisExtentsDef * m_pExtentsDef
Definition: TrVisCamera.h:269
virtual void copyViewParams(const OdTrVisCamera *)
const OdGePoint3d & viewTarget() const
Definition: TrVisCamera.h:148
void setPerspectiveProjection(bool p)
Definition: TrVisCamera.h:121
const OdGeMatrix3d & outputMatrix() const
Definition: TrVisCamera.h:215
void setCameraCumulative(bool bSet)
Definition: TrVisCamera.h:251
void preComputeViewportDefMatrices() const
const OdGeMatrix3d & viewingMatrix() const
Definition: TrVisCamera.h:197
bool hasViewClip() const
Definition: TrVisCamera.h:169
void projectedExtents(OdGePoint2d &extMin, OdGePoint2d &extMax, const OdGeExtents3d &extents) const
void removeOverlayCamera(OdTrVisCamera *)
void setMetafileMatrix(const OdGeMatrix3d &m)
Definition: TrVisCamera.h:183
const OdGeVector3d & viewBasisZ() const
Definition: TrVisCamera.h:113
void setContext(const OdTrVisSurfaceDef *pSurface, const OdTrVisViewportShadingDef *pViewportShading, const OdTrVisViewportClipDef *pViewportClip, const OdTrVisExtentsDef *pExtents)
Definition: TrVisCamera.h:60
void setParentCamera(OdTrVisCamera *)
bool viewportRect(OdGsDCRect &vpRect, bool bClipped=false) const
const OdTrVisViewClipped & frontClip() const
Definition: TrVisCamera.h:155
void setSiblingCamera(OdTrVisCamera *)
bool isPerspectiveProjection() const
Definition: TrVisCamera.h:120
const OdGeExtents3d & extents() const
Definition: TrVisCamera.h:304
double fieldWidth() const
Definition: TrVisCamera.h:127
virtual void zoomExtents(float coef=1.03f)
OdTrVisCamera * m_pParentCamera
Definition: TrVisCamera.h:263
const OdTrVisViewportClipDef * m_pViewportClipDef
Definition: TrVisCamera.h:268
virtual void translate(const OdGeVector3d &offset)
virtual void zoom(int nX, int nY, float fDelta)
double fieldHeight() const
Definition: TrVisCamera.h:134
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:95
static double computeFocalLength(double lensLength, double fieldWidth, double fieldHeight)
void setBackClip(const OdTrVisViewClipped &cl)
Definition: TrVisCamera.h:163
virtual void orbit(int nX, int nY, OrbitType type=kOrbitPerp, float angle=0.0f)
const OdGeMatrix3d & UnXForm() const
Definition: TrVisCamera.h:173
const OdGePoint3d & viewPosition() const
Definition: TrVisCamera.h:94
void setFieldWidth(double w)
Definition: TrVisCamera.h:128
void removeChildCamera(OdTrVisCamera *)
OdTrVisCamera * overlayOwnerCamera() const
Definition: TrVisCamera.h:53
const OdGeVector3d & viewBasisX() const
Definition: TrVisCamera.h:101
const OdGeVector3d & viewBasisY() const
Definition: TrVisCamera.h:107
void setFrontClip(const OdTrVisViewClipped &cl)
Definition: TrVisCamera.h:156
virtual void pan(int nX, int nY)
void setFieldHeight(double h)
Definition: TrVisCamera.h:135
OdTrVisViewParamsDef m_viewParams
Definition: TrVisCamera.h:259
double lensLength() const
Definition: TrVisCamera.h:141
OdTrVisCamera * m_pSiblingOwnerCamera
Definition: TrVisCamera.h:274
long screenWidth() const
OdGeMatrix3d computeProjectionMatrix(const OdGsDCRectDouble &dcRect, const OdTrVisViewportShadingDef *sets, const OdGeExtents3d &sceneExtents) const
void removeSiblingCamera(OdTrVisCamera *)
long screenHeight() const
double computeFieldHeight(double aspectRatio) const
virtual void zoom(float fDelta)
const OdGeMatrix3d & correctionMatrix() const
Definition: TrVisCamera.h:209
bool hasMetafileMatrix() const
Definition: TrVisCamera.h:179
virtual void update() const
OdTrVisCamera * siblingOwnerCamera() const
Definition: TrVisCamera.h:57
bool isModified() const
Definition: TrVisCamera.h:45
const OdGeMatrix3d & screenMatrix() const
Definition: TrVisCamera.h:191
OdGeMatrix3d m_UnXForm
Definition: TrVisCamera.h:260
virtual void rotate(double xAngle, double yAngle, double zAngle, bool bLocalCS=true)
double projectionScreenDepth() const
Definition: TrVisCamera.h:223
static double computeAspectRatio(const OdGsDCRectDouble &dcRect)
void markModified()
Definition: TrVisCamera.h:47
void setSiblingOwnerCamera(OdTrVisCamera *)
const OdTrVisViewClipped & backClip() const
Definition: TrVisCamera.h:162
OdTrVisCamera * sibling()
Definition: TrVisCamera.h:296
const OdTrVisViewParamsDef & viewParams(bool bUpdated=true) const
Definition: TrVisCamera.h:42
double computeFieldWidth(double aspectRatio) const
const OdTrVisSurfaceDef * m_pSurfaceDef
Definition: TrVisCamera.h:266
const OdTrVisViewportShadingDef * m_pViewportShadingDef
Definition: TrVisCamera.h:267
std::set< OdTrVisCamera * > m_overlayCameras
Definition: TrVisCamera.h:272
bool projectionPerspective() const
Definition: TrVisCamera.h:235
void setLensLength(double l)
Definition: TrVisCamera.h:142
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:114
void setViewTarget(const OdGePoint3d &pt)
Definition: TrVisCamera.h:149
const OdGeVector3d & yAxis() const
Definition: TrVisBasis.h:99
const OdGeVector3d & xAxis() const
Definition: TrVisBasis.h:98
const OdGeVector3d & zAxis() const
Definition: TrVisBasis.h:100
OdTrVisOrthoBasis & setYAxis(const OdGeVector3d &axis)
Definition: TrVisBasis.h:92
OdTrVisOrthoBasis & setZAxis(const OdGeVector3d &axis)
Definition: TrVisBasis.h:93
OdTrVisOrthoBasis & setXAxis(const OdGeVector3d &axis)
Definition: TrVisBasis.h:91
const OdGePoint3d & origin() const
Definition: TrVisBasis.h:322
OdTrVisViewBasis & setOrigin(const OdGePoint3d &origin)
Definition: TrVisBasis.h:319
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
bool enabled() const
OdTrVisViewClipped m_frontClip
OdGeMatrix3d m_outputMatrix
OdTrVisViewBasis m_viewBasis
OdGeMatrix3d m_viewingMatrix
OdTrVisViewClipped m_backClip
OdGeMatrix3d m_correctionMatrix
OdGeMatrix3d m_projectionMatrix
OdGeMatrix3d m_screenMatrix
OdGeMatrix3d m_metafileMatrix