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