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 | |
6bc6a6fc |
275 | //! Change Z-min and Z-max planes of projection volume to match the |
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). |
287 | |
e3e895af |
288 | Standard_EXPORT void ZFitAll (const Standard_Real theScaleFactor, const Bnd_Box& theMinMax, const Bnd_Box& theGraphicBB); |
6bc6a6fc |
289 | |
197ac94e |
290 | //! Change the Near and Far Z-clipping plane positions. |
291 | //! For orthographic projection, theZNear, theZFar can be negative or positive. |
292 | //! For perspective projection, only positive values are allowed. |
293 | //! Program error exception is raised if non-positive values are |
294 | //! specified for perspective projection or theZNear >= theZFar. |
b5ac8292 |
295 | //! @param theZNear [in] the distance of the plane from the Eye. |
197ac94e |
296 | //! @param theZFar [in] the distance of the plane from the Eye. |
297 | Standard_EXPORT void SetZRange (const Standard_Real theZNear, const Standard_Real theZFar); |
b5ac8292 |
298 | |
299 | //! Get the Near Z-clipping plane position. |
300 | //! @return the distance of the plane from the Eye. |
301 | Standard_Real ZNear() const |
302 | { |
303 | return myZNear; |
304 | } |
305 | |
b5ac8292 |
306 | //! Get the Far Z-clipping plane position. |
307 | //! @return the distance of the plane from the Eye. |
308 | Standard_Real ZFar() const |
309 | { |
310 | return myZFar; |
311 | } |
312 | |
3dfe95cd |
313 | //! Changes width / height display ratio. |
b5ac8292 |
314 | //! @param theAspect [in] the display ratio. |
315 | Standard_EXPORT void SetAspect (const Standard_Real theAspect); |
316 | |
317 | //! Get camera display ratio. |
318 | //! @return display ratio. |
319 | Standard_Real Aspect() const |
320 | { |
321 | return myAspect; |
322 | } |
323 | |
324 | //! Sets stereographic focus distance. |
325 | //! @param theType [in] the focus definition type. Focus can be defined |
326 | //! as absolute value or relatively to (as coefficient of) coefficient of |
327 | //! camera focal length. |
328 | //! @param theZFocus [in] the focus absolute value or coefficient depending |
329 | //! on the passed definition type. |
330 | Standard_EXPORT void SetZFocus (const FocusType theType, const Standard_Real theZFocus); |
331 | |
332 | //! Get stereographic focus value. |
333 | //! @return absolute or relative stereographic focus value |
334 | //! depending on its definition type. |
335 | Standard_Real ZFocus() const |
336 | { |
337 | return myZFocus; |
338 | } |
339 | |
340 | //! Get stereographic focus definition type. |
341 | //! @return definition type used for stereographic focus. |
342 | FocusType ZFocusType() const |
343 | { |
344 | return myZFocusType; |
345 | } |
346 | |
347 | //! Sets Intraocular distance. |
348 | //! @param theType [in] the IOD definition type. IOD can be defined as |
349 | //! absolute value or relatively to (as coefficient of) camera focal length. |
350 | //! @param theIOD [in] the Intraocular distance. |
351 | Standard_EXPORT void SetIOD (const IODType theType, const Standard_Real theIOD); |
352 | |
353 | //! Get Intraocular distance value. |
354 | //! @return absolute or relative IOD value depending on its definition type. |
355 | Standard_Real IOD() const |
356 | { |
357 | return myIOD; |
358 | } |
359 | |
360 | //! Get Intraocular distance definition type. |
361 | //! @return definition type used for Intraocular distance. |
362 | IODType GetIODType() const |
363 | { |
364 | return myIODType; |
365 | } |
366 | |
197ac94e |
367 | //! @name Basic camera operations |
b5ac8292 |
368 | public: |
369 | |
370 | //! Transform orientation components of the camera: |
371 | //! Eye, Up and Center points. |
372 | //! @param theTrsf [in] the transformation to apply. |
373 | Standard_EXPORT void Transform (const gp_Trsf& theTrsf); |
374 | |
375 | //! Calculate view plane size at center (target) point |
376 | //! and distance between ZFar and ZNear planes. |
377 | //! @return values in form of gp_Pnt (Width, Height, Depth). |
197ac94e |
378 | Standard_EXPORT gp_XYZ ViewDimensions() const; |
379 | |
380 | //! Calculate WCS frustum planes for the camera projection volume. |
381 | //! Frustum is a convex volume determined by six planes directing |
382 | //! inwards. |
383 | //! The frustum planes are usually used as inputs for camera algorithms. |
384 | //! Thus, if any changes to projection matrix calculation are necessary, |
385 | //! the frustum planes calculation should be also touched. |
386 | //! @param theLeft [out] the frustum plane for left side of view. |
387 | //! @param theRight [out] the frustum plane for right side of view. |
388 | //! @param theBottom [out] the frustum plane for bottom side of view. |
389 | //! @param theTop [out] the frustum plane for top side of view. |
390 | //! @param theNear [out] the frustum plane for near side of view. |
391 | //! @param theFar [out] the frustum plane for far side of view. |
392 | Standard_EXPORT void Frustum (gp_Pln& theLeft, |
393 | gp_Pln& theRight, |
394 | gp_Pln& theBottom, |
395 | gp_Pln& theTop, |
396 | gp_Pln& theNear, |
397 | gp_Pln& theFar) const; |
398 | |
399 | //! @name Projection methods |
b5ac8292 |
400 | public: |
401 | |
402 | //! Project point from world coordinate space to |
403 | //! normalized device coordinates (mapping). |
404 | //! @param thePnt [in] the 3D point in WCS. |
405 | //! @return mapped point in NDC. |
406 | Standard_EXPORT gp_Pnt Project (const gp_Pnt& thePnt) const; |
407 | |
408 | //! Unproject point from normalized device coordinates |
409 | //! to world coordinate space. |
410 | //! @param thePnt [in] the NDC point. |
411 | //! @return 3D point in WCS. |
412 | Standard_EXPORT gp_Pnt UnProject (const gp_Pnt& thePnt) const; |
413 | |
414 | //! Convert point from view coordinate space to |
415 | //! projection coordinate space. |
416 | //! @param thePnt [in] the point in VCS. |
417 | //! @return point in NDC. |
418 | Standard_EXPORT gp_Pnt ConvertView2Proj (const gp_Pnt& thePnt) const; |
419 | |
420 | //! Convert point from projection coordinate space |
421 | //! to view coordinate space. |
422 | //! @param thePnt [in] the point in NDC. |
423 | //! @return point in VCS. |
424 | Standard_EXPORT gp_Pnt ConvertProj2View (const gp_Pnt& thePnt) const; |
425 | |
426 | //! Convert point from world coordinate space to |
427 | //! view coordinate space. |
428 | //! @param thePnt [in] the 3D point in WCS. |
429 | //! @return point in VCS. |
430 | Standard_EXPORT gp_Pnt ConvertWorld2View (const gp_Pnt& thePnt) const; |
431 | |
432 | //! Convert point from view coordinate space to |
433 | //! world coordinates. |
434 | //! @param thePnt [in] the 3D point in VCS. |
435 | //! @return point in WCS. |
436 | Standard_EXPORT gp_Pnt ConvertView2World (const gp_Pnt& thePnt) const; |
437 | |
197ac94e |
438 | //! @name Camera modification state |
b5ac8292 |
439 | public: |
440 | |
825aa485 |
441 | //! @return projection modification state of the camera. |
442 | const Graphic3d_WorldViewProjState& WorldViewProjState() const |
443 | { |
444 | return myWorldViewProjState; |
445 | } |
446 | |
447 | |
197ac94e |
448 | //! Returns modification state of camera projection matrix |
449 | Standard_Size ProjectionState() const |
450 | { |
825aa485 |
451 | return myWorldViewProjState.ProjectionState(); |
197ac94e |
452 | } |
453 | |
825aa485 |
454 | //! Returns modification state of camera world view transformation matrix. |
455 | Standard_Size WorldViewState() const |
197ac94e |
456 | { |
825aa485 |
457 | return myWorldViewProjState.WorldViewState(); |
197ac94e |
458 | } |
459 | |
460 | //! @name Lazily-computed orientation and projection matrices derived from camera parameters |
461 | public: |
b5ac8292 |
462 | |
197ac94e |
463 | //! Get orientation matrix. |
464 | //! @return camera orientation matrix. |
465 | Standard_EXPORT const Graphic3d_Mat4d& OrientationMatrix() const; |
466 | |
467 | //! Get orientation matrix of Standard_ShortReal precision. |
468 | //! @return camera orientation matrix. |
469 | Standard_EXPORT const Graphic3d_Mat4& OrientationMatrixF() const; |
470 | |
471 | //! Get monographic or middle point projection matrix used for monographic |
472 | //! rendering and for point projection / unprojection. |
473 | //! @return monographic projection matrix. |
474 | Standard_EXPORT const Graphic3d_Mat4d& ProjectionMatrix() const; |
475 | |
476 | //! Get monographic or middle point projection matrix of Standard_ShortReal precision used for monographic |
477 | //! rendering and for point projection / unprojection. |
478 | //! @return monographic projection matrix. |
479 | Standard_EXPORT const Graphic3d_Mat4& ProjectionMatrixF() const; |
480 | |
481 | //! @return stereographic matrix computed for left eye. Please note |
482 | //! that this method is used for rendering for <i>Projection_Stereo</i>. |
483 | Standard_EXPORT const Graphic3d_Mat4d& ProjectionStereoLeft() const; |
484 | |
485 | //! @return stereographic matrix of Standard_ShortReal precision computed for left eye. |
486 | //! Please note that this method is used for rendering for <i>Projection_Stereo</i>. |
487 | Standard_EXPORT const Graphic3d_Mat4& ProjectionStereoLeftF() const; |
488 | |
489 | //! @return stereographic matrix computed for right eye. Please note |
490 | //! that this method is used for rendering for <i>Projection_Stereo</i>. |
491 | Standard_EXPORT const Graphic3d_Mat4d& ProjectionStereoRight() const; |
492 | |
493 | //! @return stereographic matrix of Standard_ShortReal precision computed for right eye. |
494 | //! Please note that this method is used for rendering for <i>Projection_Stereo</i>. |
495 | Standard_EXPORT const Graphic3d_Mat4& ProjectionStereoRightF() const; |
496 | |
05e2200b |
497 | //! Invalidate state of projection matrix. |
498 | //! The matrix will be updated on request. |
499 | Standard_EXPORT void InvalidateProjection(); |
500 | |
501 | //! Invalidate orientation matrix. |
502 | //! The matrix will be updated on request. |
503 | Standard_EXPORT void InvalidateOrientation(); |
504 | |
197ac94e |
505 | //! @name Managing projection and orientation cache |
506 | private: |
507 | |
508 | //! Compute projection matrices. |
509 | //! @param theMatrices [in] the matrices data container. |
510 | template <typename Elem_t> |
511 | Standard_EXPORT |
512 | TransformMatrices<Elem_t>& UpdateProjection (TransformMatrices<Elem_t>& theMatrices) const; |
513 | |
514 | //! Compute orientation matrix. |
515 | //! @param theMatrices [in] the matrices data container. |
516 | template <typename Elem_t> |
517 | Standard_EXPORT |
518 | TransformMatrices<Elem_t>& UpdateOrientation (TransformMatrices<Elem_t>& theMatrices) const; |
519 | |
b5ac8292 |
520 | private: |
521 | |
522 | //! Compose orthographic projection matrix for |
523 | //! the passed camera volume mapping. |
524 | //! @param theLeft [in] the left mapping (clipping) coordinate. |
525 | //! @param theRight [in] the right mapping (clipping) coordinate. |
526 | //! @param theBottom [in] the bottom mapping (clipping) coordinate. |
527 | //! @param theTop [in] the top mapping (clipping) coordinate. |
528 | //! @param theNear [in] the near mapping (clipping) coordinate. |
529 | //! @param theFar [in] the far mapping (clipping) coordinate. |
b5ac8292 |
530 | //! @param theOutMx [out] the projection matrix. |
197ac94e |
531 | template <typename Elem_t> |
b5ac8292 |
532 | static void |
197ac94e |
533 | OrthoProj (const Elem_t theLeft, |
534 | const Elem_t theRight, |
535 | const Elem_t theBottom, |
536 | const Elem_t theTop, |
537 | const Elem_t theNear, |
538 | const Elem_t theFar, |
539 | NCollection_Mat4<Elem_t>& theOutMx); |
b5ac8292 |
540 | |
541 | //! Compose perspective projection matrix for |
542 | //! the passed camera volume mapping. |
543 | //! @param theLeft [in] the left mapping (clipping) coordinate. |
544 | //! @param theRight [in] the right mapping (clipping) coordinate. |
545 | //! @param theBottom [in] the bottom mapping (clipping) coordinate. |
546 | //! @param theTop [in] the top mapping (clipping) coordinate. |
547 | //! @param theNear [in] the near mapping (clipping) coordinate. |
548 | //! @param theFar [in] the far mapping (clipping) coordinate. |
b5ac8292 |
549 | //! @param theOutMx [out] the projection matrix. |
197ac94e |
550 | template <typename Elem_t> |
b5ac8292 |
551 | static void |
197ac94e |
552 | PerspectiveProj (const Elem_t theLeft, |
553 | const Elem_t theRight, |
554 | const Elem_t theBottom, |
555 | const Elem_t theTop, |
556 | const Elem_t theNear, |
557 | const Elem_t theFar, |
558 | NCollection_Mat4<Elem_t>& theOutMx); |
b5ac8292 |
559 | |
560 | //! Compose projection matrix for L/R stereo eyes. |
561 | //! @param theLeft [in] the left mapping (clipping) coordinate. |
562 | //! @param theRight [in] the right mapping (clipping) coordinate. |
563 | //! @param theBottom [in] the bottom mapping (clipping) coordinate. |
564 | //! @param theTop [in] the top mapping (clipping) coordinate. |
565 | //! @param theNear [in] the near mapping (clipping) coordinate. |
566 | //! @param theFar [in] the far mapping (clipping) coordinate. |
567 | //! @param theIOD [in] the Intraocular distance. |
568 | //! @param theZFocus [in] the z coordinate of off-axis |
569 | //! projection plane with zero parallax. |
b5ac8292 |
570 | //! @param theIsLeft [in] boolean flag to choose between L/R eyes. |
571 | //! @param theOutMx [out] the projection matrix. |
197ac94e |
572 | template <typename Elem_t> |
b5ac8292 |
573 | static void |
197ac94e |
574 | StereoEyeProj (const Elem_t theLeft, |
575 | const Elem_t theRight, |
576 | const Elem_t theBottom, |
577 | const Elem_t theTop, |
578 | const Elem_t theNear, |
579 | const Elem_t theFar, |
580 | const Elem_t theIOD, |
581 | const Elem_t theZFocus, |
582 | const Standard_Boolean theIsLeft, |
583 | NCollection_Mat4<Elem_t>& theOutMx); |
b5ac8292 |
584 | |
585 | //! Construct "look at" orientation transformation. |
586 | //! Reference point differs for perspective and ortho modes |
587 | //! (made for compatibility, to be improved..). |
588 | //! @param theEye [in] the eye coordinates in 3D space. |
589 | //! @param theLookAt [in] the point the camera looks at. |
590 | //! @param theUpDir [in] the up direction vector. |
591 | //! @param theAxialScale [in] the axial scale vector. |
592 | //! @param theOutMx [in/out] the orientation matrix. |
197ac94e |
593 | template <typename Elem_t> |
b5ac8292 |
594 | static void |
197ac94e |
595 | LookOrientation (const NCollection_Vec3<Elem_t>& theEye, |
596 | const NCollection_Vec3<Elem_t>& theLookAt, |
597 | const NCollection_Vec3<Elem_t>& theUpDir, |
598 | const NCollection_Vec3<Elem_t>& theAxialScale, |
599 | NCollection_Mat4<Elem_t>& theOutMx); |
b5ac8292 |
600 | |
601 | private: |
602 | |
603 | gp_Dir myUp; //!< Camera up direction vector. |
604 | gp_Pnt myEye; //!< Camera eye position. |
605 | gp_Pnt myCenter; //!< Camera center. |
606 | |
197ac94e |
607 | gp_XYZ myAxialScale; //!< World axial scale. |
b5ac8292 |
608 | |
197ac94e |
609 | Projection myProjType; //!< Projection type used for rendering. |
610 | Standard_Real myFOVy; //!< Field Of View in y axis. |
611 | Standard_Real myZNear; //!< Distance to near clipping plane. |
612 | Standard_Real myZFar; //!< Distance to far clipping plane. |
613 | Standard_Real myAspect; //!< Width to height display ratio. |
b5ac8292 |
614 | |
615 | Standard_Real myScale; //!< Specifies parallel scale for orthographic projection. |
616 | Standard_Real myZFocus; //!< Stereographic focus value. |
617 | FocusType myZFocusType; //!< Stereographic focus definition type. |
618 | |
619 | Standard_Real myIOD; //!< Intraocular distance value. |
620 | IODType myIODType; //!< Intraocular distance definition type. |
621 | |
197ac94e |
622 | mutable TransformMatrices<Standard_Real> myMatricesD; |
623 | mutable TransformMatrices<Standard_ShortReal> myMatricesF; |
b5ac8292 |
624 | |
825aa485 |
625 | mutable Graphic3d_WorldViewProjState myWorldViewProjState; |
b5ac8292 |
626 | |
627 | public: |
628 | |
ec357c5c |
629 | DEFINE_STANDARD_RTTI(Graphic3d_Camera, Standard_Transient); |
b5ac8292 |
630 | }; |
631 | |
494782f6 |
632 | DEFINE_STANDARD_HANDLE (Graphic3d_Camera, Standard_Transient) |
633 | |
b5ac8292 |
634 | #endif |