b5ac8292 |
1 | // Created on: 2013-05-29 |
2 | // Created by: Anton POLETAEV |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
d5f74e42 |
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 |
b5ac8292 |
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 _Graphic3d_Camera_HeaderFile |
17 | #define _Graphic3d_Camera_HeaderFile |
18 | |
197ac94e |
19 | #include <Graphic3d_Mat4d.hxx> |
b5ac8292 |
20 | #include <Graphic3d_Mat4.hxx> |
21 | #include <Graphic3d_Vec3.hxx> |
825aa485 |
22 | #include <Graphic3d_WorldViewProjState.hxx> |
b5ac8292 |
23 | |
197ac94e |
24 | #include <NCollection_Handle.hxx> |
25 | |
b5ac8292 |
26 | #include <gp_Dir.hxx> |
27 | #include <gp_Pnt.hxx> |
28 | |
29 | #include <Standard_Macro.hxx> |
30 | #include <Standard_TypeDef.hxx> |
31 | |
6bc6a6fc |
32 | #include <Bnd_Box.hxx> |
33 | |
494782f6 |
34 | //! Forward declaration |
825aa485 |
35 | class Graphic3d_WorldViewProjState; |
b5ac8292 |
36 | |
37 | //! Camera class provides object-oriented approach to setting up projection |
38 | //! and orientation properties of 3D view. |
39 | class Graphic3d_Camera : public Standard_Transient |
40 | { |
197ac94e |
41 | private: |
42 | |
43 | //! Template container for cached matrices or Real/ShortReal types. |
44 | template<typename Elem_t> |
45 | struct TransformMatrices |
46 | { |
47 | void InitOrientation() |
48 | { |
49 | Orientation = new NCollection_Mat4<Elem_t>(); |
50 | } |
51 | |
52 | void InitProjection() |
53 | { |
54 | MProjection = new NCollection_Mat4<Elem_t>(); |
55 | LProjection = new NCollection_Mat4<Elem_t>(); |
56 | RProjection = new NCollection_Mat4<Elem_t>(); |
57 | } |
58 | |
59 | void ResetOrientation() |
60 | { |
61 | Orientation.Nullify(); |
62 | } |
63 | |
64 | void ResetProjection() |
65 | { |
66 | MProjection.Nullify(); |
67 | LProjection.Nullify(); |
68 | RProjection.Nullify(); |
69 | } |
70 | |
71 | Standard_Boolean IsOrientationValid() |
72 | { |
73 | return !Orientation.IsNull(); |
74 | } |
75 | |
76 | Standard_Boolean IsProjectionValid() |
77 | { |
78 | return !MProjection.IsNull() && |
79 | !LProjection.IsNull() && |
80 | !RProjection.IsNull(); |
81 | } |
82 | |
83 | NCollection_Handle< NCollection_Mat4<Elem_t> > Orientation; |
84 | NCollection_Handle< NCollection_Mat4<Elem_t> > MProjection; |
85 | NCollection_Handle< NCollection_Mat4<Elem_t> > LProjection; |
86 | NCollection_Handle< NCollection_Mat4<Elem_t> > RProjection; |
87 | }; |
b5ac8292 |
88 | |
89 | public: |
90 | |
91 | //! Enumerates supported monographic projections. |
92 | //! - Projection_Orthographic : orthographic projection. |
93 | //! - Projection_Perspective : perspective projection. |
38a0206f |
94 | //! - Projection_Stereo : stereographic projection. |
b5ac8292 |
95 | //! - Projection_MonoLeftEye : mono projection for stereo left eye. |
96 | //! - Projection_MonoRightEye : mono projection for stereo right eye. |
97 | enum Projection |
98 | { |
99 | Projection_Orthographic, |
100 | Projection_Perspective, |
101 | Projection_Stereo, |
102 | Projection_MonoLeftEye, |
103 | Projection_MonoRightEye |
104 | }; |
105 | |
106 | //! Enumerates approaches to define stereographic focus. |
107 | //! - FocusType_Absolute : focus is specified as absolute value. |
108 | //! - FocusType_Relative : focus is specified relative to |
109 | //! (as coefficient of) camera focal length. |
110 | enum FocusType |
111 | { |
112 | FocusType_Absolute, |
113 | FocusType_Relative |
114 | }; |
115 | |
116 | //! Enumerates approaches to define Intraocular distance. |
117 | //! - IODType_Absolute : Intraocular distance is defined as absolute value. |
118 | //! - IODType_Relative : Intraocular distance is defined relative to |
119 | //! (as coefficient of) camera focal length. |
120 | enum IODType |
121 | { |
122 | IODType_Absolute, |
123 | IODType_Relative |
124 | }; |
125 | |
126 | public: |
127 | |
128 | //! Default constructor. |
129 | //! Initializes camera with the following properties: |
130 | //! Eye (0, 0, -2); Center (0, 0, 0); Up (0, 1, 0); |
131 | //! Type (Orthographic); FOVy (45); Scale (1000); IsStereo(false); |
197ac94e |
132 | //! ZNear (0.001); ZFar (3000.0); Aspect(1); |
b5ac8292 |
133 | //! ZFocus(1.0); ZFocusType(Relative); IOD(0.05); IODType(Relative) |
134 | Standard_EXPORT Graphic3d_Camera(); |
135 | |
136 | //! Copy constructor. |
137 | //! @param theOther [in] the camera to copy from. |
138 | Standard_EXPORT Graphic3d_Camera (const Handle(Graphic3d_Camera)& theOther); |
139 | |
140 | //! Initialize mapping related parameters from other camera handle. |
141 | Standard_EXPORT void CopyMappingData (const Handle(Graphic3d_Camera)& theOtherCamera); |
142 | |
143 | //! Initialize orientation related parameters from other camera handle. |
144 | Standard_EXPORT void CopyOrientationData (const Handle(Graphic3d_Camera)& theOtherCamera); |
145 | |
146 | //! Copy properties of another camera. |
147 | //! @param theOther [in] the camera to copy from. |
148 | Standard_EXPORT void Copy (const Handle(Graphic3d_Camera)& theOther); |
149 | |
197ac94e |
150 | //! @name Public camera properties |
151 | public: |
b5ac8292 |
152 | |
153 | //! Sets camera Eye position. |
154 | //! @param theEye [in] the location of camera's Eye. |
155 | Standard_EXPORT void SetEye (const gp_Pnt& theEye); |
156 | |
157 | //! Get camera Eye position. |
158 | //! @return camera eye location. |
159 | const gp_Pnt& Eye() const |
160 | { |
161 | return myEye; |
162 | } |
163 | |
164 | //! Sets Center of the camera. |
165 | //! @param theCenter [in] the point where the camera looks at. |
166 | Standard_EXPORT void SetCenter (const gp_Pnt& theCenter); |
167 | |
168 | //! Get Center of the camera. |
169 | //! @return the point where the camera looks at. |
170 | const gp_Pnt& Center() const |
171 | { |
172 | return myCenter; |
173 | } |
174 | |
197ac94e |
175 | //! Sets camera Up direction vector, orthogonal to camera direction. |
b5ac8292 |
176 | //! @param theUp [in] the Up direction vector. |
177 | Standard_EXPORT void SetUp (const gp_Dir& theUp); |
178 | |
197ac94e |
179 | //! Orthogonalize up direction vector. |
180 | Standard_EXPORT void OrthogonalizeUp(); |
181 | |
182 | //! Return a copy of orthogonalized up direction vector. |
183 | Standard_EXPORT gp_Dir OrthogonalizedUp() const; |
184 | |
b5ac8292 |
185 | //! Get camera Up direction vector. |
186 | //! @return Camera's Up direction vector. |
187 | const gp_Dir& Up() const |
188 | { |
189 | return myUp; |
190 | } |
191 | |
ebc93ae7 |
192 | //! Set camera axial scale. |
b5ac8292 |
193 | //! @param theAxialScale [in] the axial scale vector. |
197ac94e |
194 | Standard_EXPORT void SetAxialScale (const gp_XYZ& theAxialScale); |
b5ac8292 |
195 | |
196 | //! Get camera axial scale. |
197 | //! @return Camera's axial scale. |
197ac94e |
198 | const gp_XYZ& AxialScale() const |
b5ac8292 |
199 | { |
200 | return myAxialScale; |
201 | } |
202 | |
203 | //! Set distance of Eye from camera Center. |
204 | //! @param theDistance [in] the distance. |
205 | Standard_EXPORT void SetDistance (const Standard_Real theDistance); |
206 | |
207 | //! Get distance of Eye from camera Center. |
208 | //! @return the distance. |
209 | Standard_EXPORT Standard_Real Distance() const; |
210 | |
211 | //! Sets camera look direction. |
212 | //! @param theDir [in] the direction. |
213 | Standard_EXPORT void SetDirection (const gp_Dir& theDir); |
214 | |
215 | //! Get camera look direction. |
216 | //! @return camera look direction. |
217 | Standard_EXPORT gp_Dir Direction() const; |
218 | |
219 | //! Sets camera scale. For orthographic projection the scale factor |
220 | //! corresponds to parallel scale of view mapping (i.e. size |
221 | //! of viewport). For perspective camera scale is converted to |
3dfe95cd |
222 | //! distance. The scale specifies equal size of the view projection in |
223 | //! both dimensions assuming that the aspect is 1.0. The projection height |
224 | //! and width are specified with the scale and correspondingly multiplied |
225 | //! by the aspect. |
b5ac8292 |
226 | //! @param theScale [in] the scale factor. |
227 | Standard_EXPORT void SetScale (const Standard_Real theScale); |
228 | |
229 | //! Get camera scale. |
230 | //! @return camera scale factor. |
231 | Standard_EXPORT Standard_Real Scale() const; |
232 | |
233 | //! Change camera projection type. |
197ac94e |
234 | //! When switching to perspective projection from orthographic one, |
235 | //! the ZNear and ZFar are reset to default values (0.001, 3000.0) |
236 | //! if less than 0.0. |
b5ac8292 |
237 | //! @param theProjectionType [in] the camera projection type. |
238 | Standard_EXPORT void SetProjectionType (const Projection theProjection); |
239 | |
240 | //! @return camera projection type. |
241 | Projection ProjectionType() const |
242 | { |
243 | return myProjType; |
244 | } |
245 | |
246 | //! Check that the camera projection is orthographic. |
247 | //! @return boolean flag that indicates whether the camera's projection is |
248 | //! orthographic or not. |
249 | Standard_Boolean IsOrthographic() const |
250 | { |
251 | return (myProjType == Projection_Orthographic); |
252 | } |
253 | |
254 | //! Check whether the camera projection is stereo. |
255 | //! Please note that stereo rendering is now implemented with support of |
256 | //! Quad buffering. |
257 | //! @return boolean flag indicating whether the stereographic L/R projection |
258 | //! is chosen. |
259 | Standard_Boolean IsStereo() const |
260 | { |
261 | return (myProjType == Projection_Stereo); |
262 | } |
263 | |
264 | //! Set Field Of View (FOV) in y axis for perspective projection. |
265 | //! @param theFOVy [in] the FOV in degrees. |
266 | Standard_EXPORT void SetFOVy (const Standard_Real theFOVy); |
267 | |
268 | //! Get Field Of View (FOV) in y axis. |
269 | //! @return the FOV value in degrees. |
270 | Standard_Real FOVy() const |
271 | { |
272 | return myFOVy; |
273 | } |
274 | |
10dbdf34 |
275 | //! Estimate Z-min and Z-max planes of projection volume to match the |
6bc6a6fc |
276 | //! displayed objects. The methods ensures that view volume will |
277 | //! be close by depth range to the displayed objects. Fitting assumes that |
278 | //! for orthogonal projection the view volume contains the displayed objects |
279 | //! completely. For zoomed perspective view, the view volume is adjusted such |
280 | //! that it contains the objects or their parts, located in front of the camera. |
281 | //! @param theScaleFactor [in] the scale factor for Z-range. |
282 | //! The range between Z-min, Z-max projection volume planes |
283 | //! evaluated by z fitting method will be scaled using this coefficient. |
284 | //! Program error exception is thrown if negative or zero value is passed. |
285 | //! @param theMinMax [in] applicative min max boundaries. |
286 | //! @param theScaleFactor [in] real graphical boundaries (not accounting infinite flag). |
10dbdf34 |
287 | Standard_EXPORT bool ZFitAll (const Standard_Real theScaleFactor, |
288 | const Bnd_Box& theMinMax, |
289 | const Bnd_Box& theGraphicBB, |
290 | Standard_Real& theZNear, |
291 | Standard_Real& theZFar) const; |
292 | |
293 | //! Change Z-min and Z-max planes of projection volume to match the displayed objects. |
294 | void ZFitAll (const Standard_Real theScaleFactor, const Bnd_Box& theMinMax, const Bnd_Box& theGraphicBB) |
295 | { |
296 | Standard_Real aZNear = 0.0, aZFar = 1.0; |
297 | ZFitAll (theScaleFactor, theMinMax, theGraphicBB, aZNear, aZFar); |
298 | SetZRange (aZNear, aZFar); |
299 | } |
6bc6a6fc |
300 | |
197ac94e |
301 | //! Change the Near and Far Z-clipping plane positions. |
302 | //! For orthographic projection, theZNear, theZFar can be negative or positive. |
303 | //! For perspective projection, only positive values are allowed. |
304 | //! Program error exception is raised if non-positive values are |
305 | //! specified for perspective projection or theZNear >= theZFar. |
b5ac8292 |
306 | //! @param theZNear [in] the distance of the plane from the Eye. |
197ac94e |
307 | //! @param theZFar [in] the distance of the plane from the Eye. |
308 | Standard_EXPORT void SetZRange (const Standard_Real theZNear, const Standard_Real theZFar); |
b5ac8292 |
309 | |
310 | //! Get the Near Z-clipping plane position. |
311 | //! @return the distance of the plane from the Eye. |
312 | Standard_Real ZNear() const |
313 | { |
314 | return myZNear; |
315 | } |
316 | |
b5ac8292 |
317 | //! Get the Far Z-clipping plane position. |
318 | //! @return the distance of the plane from the Eye. |
319 | Standard_Real ZFar() const |
320 | { |
321 | return myZFar; |
322 | } |
323 | |
3dfe95cd |
324 | //! Changes width / height display ratio. |
b5ac8292 |
325 | //! @param theAspect [in] the display ratio. |
326 | Standard_EXPORT void SetAspect (const Standard_Real theAspect); |
327 | |
328 | //! Get camera display ratio. |
329 | //! @return display ratio. |
330 | Standard_Real Aspect() const |
331 | { |
332 | return myAspect; |
333 | } |
334 | |
335 | //! Sets stereographic focus distance. |
336 | //! @param theType [in] the focus definition type. Focus can be defined |
337 | //! as absolute value or relatively to (as coefficient of) coefficient of |
338 | //! camera focal length. |
339 | //! @param theZFocus [in] the focus absolute value or coefficient depending |
340 | //! on the passed definition type. |
341 | Standard_EXPORT void SetZFocus (const FocusType theType, const Standard_Real theZFocus); |
342 | |
343 | //! Get stereographic focus value. |
344 | //! @return absolute or relative stereographic focus value |
345 | //! depending on its definition type. |
346 | Standard_Real ZFocus() const |
347 | { |
348 | return myZFocus; |
349 | } |
350 | |
351 | //! Get stereographic focus definition type. |
352 | //! @return definition type used for stereographic focus. |
353 | FocusType ZFocusType() const |
354 | { |
355 | return myZFocusType; |
356 | } |
357 | |
358 | //! Sets Intraocular distance. |
359 | //! @param theType [in] the IOD definition type. IOD can be defined as |
360 | //! absolute value or relatively to (as coefficient of) camera focal length. |
361 | //! @param theIOD [in] the Intraocular distance. |
362 | Standard_EXPORT void SetIOD (const IODType theType, const Standard_Real theIOD); |
363 | |
364 | //! Get Intraocular distance value. |
365 | //! @return absolute or relative IOD value depending on its definition type. |
366 | Standard_Real IOD() const |
367 | { |
368 | return myIOD; |
369 | } |
370 | |
371 | //! Get Intraocular distance definition type. |
372 | //! @return definition type used for Intraocular distance. |
373 | IODType GetIODType() const |
374 | { |
375 | return myIODType; |
376 | } |
377 | |
197ac94e |
378 | //! @name Basic camera operations |
b5ac8292 |
379 | public: |
380 | |
381 | //! Transform orientation components of the camera: |
382 | //! Eye, Up and Center points. |
383 | //! @param theTrsf [in] the transformation to apply. |
384 | Standard_EXPORT void Transform (const gp_Trsf& theTrsf); |
385 | |
386 | //! Calculate view plane size at center (target) point |
387 | //! and distance between ZFar and ZNear planes. |
388 | //! @return values in form of gp_Pnt (Width, Height, Depth). |
3fe9ce0e |
389 | gp_XYZ ViewDimensions() const |
390 | { |
391 | return ViewDimensions (Distance()); |
392 | } |
393 | |
394 | //! Calculate view plane size at center point with specified Z offset |
395 | //! and distance between ZFar and ZNear planes. |
396 | //! @param theZValue [in] the distance from the eye in eye-to-center direction |
397 | //! @return values in form of gp_Pnt (Width, Height, Depth). |
398 | Standard_EXPORT gp_XYZ ViewDimensions (const Standard_Real theZValue) const; |
197ac94e |
399 | |
400 | //! Calculate WCS frustum planes for the camera projection volume. |
401 | //! Frustum is a convex volume determined by six planes directing |
402 | //! inwards. |
403 | //! The frustum planes are usually used as inputs for camera algorithms. |
404 | //! Thus, if any changes to projection matrix calculation are necessary, |
405 | //! the frustum planes calculation should be also touched. |
406 | //! @param theLeft [out] the frustum plane for left side of view. |
407 | //! @param theRight [out] the frustum plane for right side of view. |
408 | //! @param theBottom [out] the frustum plane for bottom side of view. |
409 | //! @param theTop [out] the frustum plane for top side of view. |
410 | //! @param theNear [out] the frustum plane for near side of view. |
411 | //! @param theFar [out] the frustum plane for far side of view. |
412 | Standard_EXPORT void Frustum (gp_Pln& theLeft, |
413 | gp_Pln& theRight, |
414 | gp_Pln& theBottom, |
415 | gp_Pln& theTop, |
416 | gp_Pln& theNear, |
417 | gp_Pln& theFar) const; |
418 | |
419 | //! @name Projection methods |
b5ac8292 |
420 | public: |
421 | |
422 | //! Project point from world coordinate space to |
423 | //! normalized device coordinates (mapping). |
424 | //! @param thePnt [in] the 3D point in WCS. |
425 | //! @return mapped point in NDC. |
426 | Standard_EXPORT gp_Pnt Project (const gp_Pnt& thePnt) const; |
427 | |
428 | //! Unproject point from normalized device coordinates |
429 | //! to world coordinate space. |
430 | //! @param thePnt [in] the NDC point. |
431 | //! @return 3D point in WCS. |
432 | Standard_EXPORT gp_Pnt UnProject (const gp_Pnt& thePnt) const; |
433 | |
434 | //! Convert point from view coordinate space to |
435 | //! projection coordinate space. |
436 | //! @param thePnt [in] the point in VCS. |
437 | //! @return point in NDC. |
438 | Standard_EXPORT gp_Pnt ConvertView2Proj (const gp_Pnt& thePnt) const; |
439 | |
440 | //! Convert point from projection coordinate space |
441 | //! to view coordinate space. |
442 | //! @param thePnt [in] the point in NDC. |
443 | //! @return point in VCS. |
444 | Standard_EXPORT gp_Pnt ConvertProj2View (const gp_Pnt& thePnt) const; |
445 | |
446 | //! Convert point from world coordinate space to |
447 | //! view coordinate space. |
448 | //! @param thePnt [in] the 3D point in WCS. |
449 | //! @return point in VCS. |
450 | Standard_EXPORT gp_Pnt ConvertWorld2View (const gp_Pnt& thePnt) const; |
451 | |
452 | //! Convert point from view coordinate space to |
453 | //! world coordinates. |
454 | //! @param thePnt [in] the 3D point in VCS. |
455 | //! @return point in WCS. |
456 | Standard_EXPORT gp_Pnt ConvertView2World (const gp_Pnt& thePnt) const; |
457 | |
197ac94e |
458 | //! @name Camera modification state |
b5ac8292 |
459 | public: |
460 | |
825aa485 |
461 | //! @return projection modification state of the camera. |
462 | const Graphic3d_WorldViewProjState& WorldViewProjState() const |
463 | { |
464 | return myWorldViewProjState; |
465 | } |
466 | |
467 | |
197ac94e |
468 | //! Returns modification state of camera projection matrix |
469 | Standard_Size ProjectionState() const |
470 | { |
825aa485 |
471 | return myWorldViewProjState.ProjectionState(); |
197ac94e |
472 | } |
473 | |
825aa485 |
474 | //! Returns modification state of camera world view transformation matrix. |
475 | Standard_Size WorldViewState() const |
197ac94e |
476 | { |
825aa485 |
477 | return myWorldViewProjState.WorldViewState(); |
197ac94e |
478 | } |
479 | |
480 | //! @name Lazily-computed orientation and projection matrices derived from camera parameters |
481 | public: |
b5ac8292 |
482 | |
197ac94e |
483 | //! Get orientation matrix. |
484 | //! @return camera orientation matrix. |
485 | Standard_EXPORT const Graphic3d_Mat4d& OrientationMatrix() const; |
486 | |
487 | //! Get orientation matrix of Standard_ShortReal precision. |
488 | //! @return camera orientation matrix. |
489 | Standard_EXPORT const Graphic3d_Mat4& OrientationMatrixF() const; |
490 | |
491 | //! Get monographic or middle point projection matrix used for monographic |
492 | //! rendering and for point projection / unprojection. |
493 | //! @return monographic projection matrix. |
494 | Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const; |
495 | |
496 | //! Get monographic or middle point projection matrix of Standard_ShortReal precision used for monographic |
497 | //! rendering and for point projection / unprojection. |
498 | //! @return monographic projection matrix. |
499 | Standard_EXPORT const Graphic3d_Mat4& ProjectionMatrixF() const; |
500 | |
501 | //! @return stereographic matrix computed for left eye. Please note |
502 | //! that this method is used for rendering for <i>Projection_Stereo</i>. |
503 | Standard_EXPORT const Graphic3d_Mat4d& ProjectionStereoLeft() const; |
504 | |
505 | //! @return stereographic matrix of Standard_ShortReal precision computed for left eye. |
506 | //! Please note that this method is used for rendering for <i>Projection_Stereo</i>. |
507 | Standard_EXPORT const Graphic3d_Mat4& ProjectionStereoLeftF() const; |
508 | |
509 | //! @return stereographic matrix computed for right eye. Please note |
510 | //! that this method is used for rendering for <i>Projection_Stereo</i>. |
511 | Standard_EXPORT const Graphic3d_Mat4d& ProjectionStereoRight() const; |
512 | |
513 | //! @return stereographic matrix of Standard_ShortReal precision computed for right eye. |
514 | //! Please note that this method is used for rendering for <i>Projection_Stereo</i>. |
515 | Standard_EXPORT const Graphic3d_Mat4& ProjectionStereoRightF() const; |
516 | |
05e2200b |
517 | //! Invalidate state of projection matrix. |
518 | //! The matrix will be updated on request. |
519 | Standard_EXPORT void InvalidateProjection(); |
520 | |
521 | //! Invalidate orientation matrix. |
522 | //! The matrix will be updated on request. |
523 | Standard_EXPORT void InvalidateOrientation(); |
524 | |
197ac94e |
525 | //! @name Managing projection and orientation cache |
526 | private: |
527 | |
528 | //! Compute projection matrices. |
529 | //! @param theMatrices [in] the matrices data container. |
530 | template <typename Elem_t> |
531 | Standard_EXPORT |
532 | TransformMatrices<Elem_t>& UpdateProjection (TransformMatrices<Elem_t>& theMatrices) const; |
533 | |
534 | //! Compute orientation matrix. |
535 | //! @param theMatrices [in] the matrices data container. |
536 | template <typename Elem_t> |
537 | Standard_EXPORT |
538 | TransformMatrices<Elem_t>& UpdateOrientation (TransformMatrices<Elem_t>& theMatrices) const; |
539 | |
b5ac8292 |
540 | private: |
541 | |
542 | //! Compose orthographic projection matrix for |
543 | //! the passed camera volume mapping. |
544 | //! @param theLeft [in] the left mapping (clipping) coordinate. |
545 | //! @param theRight [in] the right mapping (clipping) coordinate. |
546 | //! @param theBottom [in] the bottom mapping (clipping) coordinate. |
547 | //! @param theTop [in] the top mapping (clipping) coordinate. |
548 | //! @param theNear [in] the near mapping (clipping) coordinate. |
549 | //! @param theFar [in] the far mapping (clipping) coordinate. |
b5ac8292 |
550 | //! @param theOutMx [out] the projection matrix. |
197ac94e |
551 | template <typename Elem_t> |
b5ac8292 |
552 | static void |
197ac94e |
553 | OrthoProj (const Elem_t theLeft, |
554 | const Elem_t theRight, |
555 | const Elem_t theBottom, |
556 | const Elem_t theTop, |
557 | const Elem_t theNear, |
558 | const Elem_t theFar, |
559 | NCollection_Mat4<Elem_t>& theOutMx); |
b5ac8292 |
560 | |
561 | //! Compose perspective projection matrix for |
562 | //! the passed camera volume mapping. |
563 | //! @param theLeft [in] the left mapping (clipping) coordinate. |
564 | //! @param theRight [in] the right mapping (clipping) coordinate. |
565 | //! @param theBottom [in] the bottom mapping (clipping) coordinate. |
566 | //! @param theTop [in] the top mapping (clipping) coordinate. |
567 | //! @param theNear [in] the near mapping (clipping) coordinate. |
568 | //! @param theFar [in] the far mapping (clipping) coordinate. |
b5ac8292 |
569 | //! @param theOutMx [out] the projection matrix. |
197ac94e |
570 | template <typename Elem_t> |
b5ac8292 |
571 | static void |
197ac94e |
572 | PerspectiveProj (const Elem_t theLeft, |
573 | const Elem_t theRight, |
574 | const Elem_t theBottom, |
575 | const Elem_t theTop, |
576 | const Elem_t theNear, |
577 | const Elem_t theFar, |
578 | NCollection_Mat4<Elem_t>& theOutMx); |
b5ac8292 |
579 | |
580 | //! Compose projection matrix for L/R stereo eyes. |
581 | //! @param theLeft [in] the left mapping (clipping) coordinate. |
582 | //! @param theRight [in] the right mapping (clipping) coordinate. |
583 | //! @param theBottom [in] the bottom mapping (clipping) coordinate. |
584 | //! @param theTop [in] the top mapping (clipping) coordinate. |
585 | //! @param theNear [in] the near mapping (clipping) coordinate. |
586 | //! @param theFar [in] the far mapping (clipping) coordinate. |
587 | //! @param theIOD [in] the Intraocular distance. |
588 | //! @param theZFocus [in] the z coordinate of off-axis |
589 | //! projection plane with zero parallax. |
b5ac8292 |
590 | //! @param theIsLeft [in] boolean flag to choose between L/R eyes. |
591 | //! @param theOutMx [out] the projection matrix. |
197ac94e |
592 | template <typename Elem_t> |
b5ac8292 |
593 | static void |
197ac94e |
594 | StereoEyeProj (const Elem_t theLeft, |
595 | const Elem_t theRight, |
596 | const Elem_t theBottom, |
597 | const Elem_t theTop, |
598 | const Elem_t theNear, |
599 | const Elem_t theFar, |
600 | const Elem_t theIOD, |
601 | const Elem_t theZFocus, |
602 | const Standard_Boolean theIsLeft, |
603 | NCollection_Mat4<Elem_t>& theOutMx); |
b5ac8292 |
604 | |
605 | //! Construct "look at" orientation transformation. |
606 | //! Reference point differs for perspective and ortho modes |
607 | //! (made for compatibility, to be improved..). |
608 | //! @param theEye [in] the eye coordinates in 3D space. |
609 | //! @param theLookAt [in] the point the camera looks at. |
610 | //! @param theUpDir [in] the up direction vector. |
611 | //! @param theAxialScale [in] the axial scale vector. |
612 | //! @param theOutMx [in/out] the orientation matrix. |
197ac94e |
613 | template <typename Elem_t> |
b5ac8292 |
614 | static void |
197ac94e |
615 | LookOrientation (const NCollection_Vec3<Elem_t>& theEye, |
616 | const NCollection_Vec3<Elem_t>& theLookAt, |
617 | const NCollection_Vec3<Elem_t>& theUpDir, |
618 | const NCollection_Vec3<Elem_t>& theAxialScale, |
619 | NCollection_Mat4<Elem_t>& theOutMx); |
b5ac8292 |
620 | |
621 | private: |
622 | |
623 | gp_Dir myUp; //!< Camera up direction vector. |
624 | gp_Pnt myEye; //!< Camera eye position. |
625 | gp_Pnt myCenter; //!< Camera center. |
626 | |
197ac94e |
627 | gp_XYZ myAxialScale; //!< World axial scale. |
b5ac8292 |
628 | |
197ac94e |
629 | Projection myProjType; //!< Projection type used for rendering. |
630 | Standard_Real myFOVy; //!< Field Of View in y axis. |
631 | Standard_Real myZNear; //!< Distance to near clipping plane. |
632 | Standard_Real myZFar; //!< Distance to far clipping plane. |
633 | Standard_Real myAspect; //!< Width to height display ratio. |
b5ac8292 |
634 | |
635 | Standard_Real myScale; //!< Specifies parallel scale for orthographic projection. |
636 | Standard_Real myZFocus; //!< Stereographic focus value. |
637 | FocusType myZFocusType; //!< Stereographic focus definition type. |
638 | |
639 | Standard_Real myIOD; //!< Intraocular distance value. |
640 | IODType myIODType; //!< Intraocular distance definition type. |
641 | |
197ac94e |
642 | mutable TransformMatrices<Standard_Real> myMatricesD; |
643 | mutable TransformMatrices<Standard_ShortReal> myMatricesF; |
b5ac8292 |
644 | |
825aa485 |
645 | mutable Graphic3d_WorldViewProjState myWorldViewProjState; |
b5ac8292 |
646 | |
647 | public: |
648 | |
a3f6f591 |
649 | DEFINE_STANDARD_RTTIEXT(Graphic3d_Camera,Standard_Transient) |
b5ac8292 |
650 | }; |
651 | |
494782f6 |
652 | DEFINE_STANDARD_HANDLE (Graphic3d_Camera, Standard_Transient) |
653 | |
b5ac8292 |
654 | #endif |