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