gre/3dscene.h

Go to the documentation of this file.
00001 /**
00002  * \file 3dscene.h <gre/3dscene.h>
00003  * \brief class for scene algorithms
00004  *
00005  * \if NODOC
00006  * $Id: 3dscene.h_v 1.22 2005/03/21 18:56:14 vdronov Exp $
00007  *
00008  * $Log: 3dscene.h_v $
00009  * Revision 1.22  2005/03/21 18:56:14  vdronov
00010  * *** empty log message ***
00011  *
00012  * Revision 1.21  2005/03/10 21:43:07  vdronov
00013  * *** empty log message ***
00014  *
00015  * Revision 1.20  2005/01/24 21:30:54  mju
00016  * Add GetStereoView.
00017  * Add STEREOVIEW enum.
00018  *
00019  * Revision 1.19  2004/12/01 20:54:58  vdronov
00020  * ALIGN
00021  *
00022  * Revision 1.18  2004/08/11 23:01:41  vdronov
00023  * *** empty log message ***
00024  *
00025  * Revision 1.17  2004/07/23 22:57:53  vdronov
00026  * *** empty log message ***
00027  *
00028  * Revision 1.16  2004/07/20 20:57:40  vdronov
00029  * *** empty log message ***
00030  *
00031  * Revision 1.15  2004/07/19 21:00:57  vdronov
00032  * *** empty log message ***
00033  *
00034  * Revision 1.14  2004/06/02 22:25:02  vdronov
00035  * *** empty log message ***
00036  *
00037  * Revision 1.13  2004/06/01 23:47:38  vdronov
00038  * *** empty log message ***
00039  *
00040  * Revision 1.12  2004/02/13 17:02:54  vdronov
00041  * fixed warnings
00042  *
00043  * Revision 1.11  2003/09/23 13:10:00  mju
00044  * Fix compiler warnings.
00045  *
00046  * Revision 1.10  2003/09/15 13:48:59  fileserver!dwilliss
00047  * Doxygen
00048  *
00049  * Revision 1.9  2003/08/15 22:10:52  vdronov
00050  * add docs
00051  *
00052  * Revision 1.8  2003/07/30 13:57:26  mju
00053  * Check inclusion guards.
00054  * Ignore private section.
00055  *
00056  * Revision 1.7  2003/04/07 20:41:50  vdronov
00057  * parallel projection
00058  *
00059  * Revision 1.6  2003/03/20 23:14:22  vdronov
00060  * new trans
00061  *
00062  * Revision 1.5  2003/03/13 15:57:46  vdronov
00063  * added const for GetFrustum
00064  *
00065  * Revision 1.4  2003/03/13 15:50:40  vdronov
00066  * added GetFrustum
00067  *
00068  * Revision 1.3  2003/03/12 20:26:53  vdronov
00069  * changed transformation
00070  *
00071  * Revision 1.2  2003/03/11 21:58:10  vdronov
00072  * used ScreenRect instead of w, h
00073  *
00074  * Revision 1.1  2003/03/10 15:06:32  vdronov
00075  * Initial revision
00076  * \endif
00077 **/ 
00078 
00079 #ifndef  INC_GRE_3DSCENE_H
00080 #define  INC_GRE_3DSCENE_H
00081 
00082 #ifndef  INC_MI32_POINT_H
00083 #include <mi32/point.h>
00084 #endif
00085 
00086 #ifndef  INC_MI32_MXSTEREO_H
00087 #include <mi32/mxstereo.h>
00088 #endif
00089 
00090 #ifndef  INC_MI32_RECT_H
00091 #include <mi32/rect.h>
00092 #endif
00093 
00094 #ifndef  INC_MI32_TRANS3D_H
00095 #include <mi32/trans3d.h>
00096 #endif
00097 
00098 #ifndef  INC_MI32_DOUBLEAR_H
00099 #include <mi32/doublear.h>
00100 #endif
00101 
00102 namespace GRE {
00103 
00104 //! SCENE3D class describes view scene and all transformation beetween
00105 //! model and world and view and unit cube and screne
00106 //!
00107 //! All angles are in degrees;
00108 //! All distances are in meters;
00109 //! All points are in orthogonal coordinate system
00110 class SCENE3D {
00111    public:
00112 
00113       enum STEREOVIEW {
00114          STEREOVIEW_None,
00115          STEREOVIEW_Left,
00116          STEREOVIEW_Right
00117          };
00118 
00119       SCENE3D (                                 //! Constructor 
00120          const float FieldOfViewAngle = 45
00121          );
00122 
00123       ~SCENE3D (                                //! Destructor 
00124          );
00125 
00126       SCENE3D& operator= (
00127          const SCENE3D& rhs
00128          );
00129 
00130 
00131       //! Calculate scene parameters for given screen rectangle
00132       //! 
00133       //! @return true if calculation is completed
00134       bool CalculateParameters (
00135          const DRECT2D& screenrect
00136          );
00137 
00138       //! Clear scene parameters
00139       void Clear (
00140          );
00141 
00142       //! Clear Model to World transformation to identity transformation
00143       void ClearModelToWorld ();
00144 
00145    //! Clip segment with endpoints pts and pte with frustum. If segment intersects frustum than
00146       //! pts and pte contains endpoints of intersection in return.
00147       //!
00148       //! @return true if segment intersects frustum 
00149       bool ClipSegment (
00150          FPOINT3D &pts,
00151          FPOINT3D &pte
00152          );
00153 
00154       //! Get azimuth angle in degrees
00155       //! 
00156       //! @return azimuth angle
00157       float GetAzimuth (
00158          ) const;
00159 
00160       //! Get view direction
00161       //! 
00162       //! @return view direction
00163       const FPOINT3D& GetDirection (
00164          ) const;
00165 
00166       //! Get elevation in meters
00167       //! 
00168       //! @return elevation in meters
00169       float GetElevation (
00170          ) const {return m_Elevation;};
00171 
00172       //! Retrieve base elevation.
00173       float GetBaseElevation (
00174          ) const;
00175 
00176       //! Get field of view angle in degrees
00177       //! 
00178       //! @return field of view angle in degrees
00179       float GetFieldOfViewAngle (
00180          ) const;
00181 
00182       //! Get frustum   as DRECT3D
00183       //! 
00184       //! @return frustum sa DRECT3D
00185       const DRECT3D& GetFrustum (
00186          ) const;
00187 
00188       //! Get look at point
00189       //! 
00190       //! @return look at point
00191       const FPOINT3D& GetLookAt (
00192          ) const;
00193 
00194       //! Get parallel projection distance
00195       //! 
00196       //! @return parallel projection distance
00197       float GetParallelProjectionDistance (
00198          ) const;
00199 
00200       //! Get pixel sixe in meters
00201       double GetPixelSizeInMeters (
00202          ) const;
00203 
00204       //! Get roll angle in degrees
00205       //! @return roll angle
00206       float GetRoll (
00207          ) const;
00208 
00209       //! Get screen rectangle
00210       //! @return screen rectangle
00211       const DRECT2D& GetScreenRect (
00212          ) const;
00213 
00214       //! Get stereo view.
00215       STEREOVIEW GetStereoView (
00216          ) const { return (m_StereoView); }
00217 
00218       float GetSunAzimuthAngle (
00219          ) const;
00220 
00221       float GetSunElevationAngle (
00222          ) const;
00223 
00224       //! Get viewer point
00225       //! 
00226       //! @return viewer point
00227       FPOINT3D GetViewer (
00228          ) const;
00229 
00230       //! Get up direction
00231       //! 
00232       //! @return up direction
00233       const FPOINT3D& GetUp (
00234          ) const;
00235 
00236       //! Are scene parameters calculated
00237       //! 
00238       //! @return true if scene parameters are calculated
00239       bool IsCalculated (
00240          ) const;
00241 
00242       //! Is projection perspective
00243       //! 
00244       //! @return true if projecton is perspective
00245       bool IsPerspective (
00246          ) const;
00247 
00248       //! Is given rectangle overlapped with scene frustum
00249       //! 
00250       //! @return true if rectangle is overlapped
00251       bool IsRectangleOverlapped (
00252          const DRECT3D& rect
00253          ) const;
00254 
00255       //! Is segment with given endpoints overlapped with scene frustum
00256       //! 
00257       //! @return true if segement is overlapped
00258       bool IsSegmentOverlapped (
00259          const FPOINT3D &pts,
00260          const FPOINT3D &pte
00261          ) const;
00262 
00263       //! Is sphere with given center and given radius overlapped with scene frustum
00264       //! 
00265       //! @return true if sphere is overlapped
00266       bool IsSphereOverlapped (
00267          const FPOINT3D &center,
00268          const float radiussquared = 0.0f
00269          ) const;
00270 
00271       //! Is stereo set
00272       //! 
00273       //! @return true if stereo is set
00274       bool IsStereo (
00275          ) const;
00276 
00277       //! Is triangle with given vertices overlapped with scene frustum
00278       //! 
00279       //! @return true if triangle is overlapped
00280       bool IsTriangleOverlapped (
00281          const FPOINT3D &pt1,
00282          const FPOINT3D &pt2,
00283          const FPOINT3D &pt3
00284          ) const;
00285 
00286       //! Set azimuth angle in degrees
00287       void SetAzimuth (
00288          const float azimuth,
00289          const bool recalculate = true
00290          );
00291 
00292       //! Set elevation angle in degrees
00293       void SetElevation (
00294          const float elevation
00295          );
00296 
00297       //! Set base elevation  in meters
00298       void SetBaseElevation (
00299          const float BaseElevation
00300          );
00301 
00302       //! Set clipping extents for scene
00303       void SetExtents (
00304          DOUBLE_ARRAY<DRECT3D>& extents
00305          );
00306 
00307       //! Set field of view angle in degrees
00308       void SetFieldOfViewAngle (
00309          const float FieldOfViewAngle
00310          );
00311 
00312       //! Set frustum   as DRECT2D
00313       void SetFrustum (
00314          const DRECT2D& frustum
00315          );
00316 
00317       //! Set look at point
00318       void SetLookAt (
00319          const FPOINT3D& lookAt
00320          );
00321 
00322       //! Get Model to World transformation
00323       void SetModelToWorld (const TRANS3D& ModelToWorld);
00324 
00325       void SetMonitorSeparation (
00326          const double monitor
00327          );
00328 
00329       //! Get near and far planes
00330       void SetNearFarPlanes (
00331          const double nearplane,
00332          const double farplane,
00333          const bool use = false
00334          );
00335 
00336       void SetOpticalSeparation (
00337          const double optical
00338          );
00339 
00340       //! Set parallel projection distance
00341       void SetParallelProjectionDistance (
00342          const float distance
00343          );
00344 
00345       //! Set perspective projection on or off
00346       void SetPerspective (
00347          const bool isPerspective
00348          );
00349 
00350       //! Set roll angle in degrees
00351       void SetRoll (
00352          const float roll,
00353          const bool recalculate = true
00354          );
00355 
00356       void SetSunAzimuthAngle (
00357          const float SunAzimuthAngle
00358          );
00359 
00360       void SetSunElevationAngle (
00361          const float SunElevationAngle
00362          );
00363 
00364       //! Set stereo  on or off
00365       void SetStereo (
00366          const bool isStereo
00367          );
00368 
00369       void SetStereoDistance (
00370          const double distance
00371          );
00372 
00373       void SetStereoMode (
00374          const STEREOMODE mode
00375          );
00376 
00377       void SetStereoScale (
00378          const double scale
00379          );
00380 
00381       void SetStereoView (
00382          const STEREOVIEW stereoview
00383          );
00384 
00385       //! Set viewer point
00386       void SetViewer (
00387          const FPOINT3D& viewer
00388          );
00389 
00390       //! Update azimuth angle in degrees
00391       void UpdateAzimuth (
00392          const float update
00393          );
00394 
00395       //! Update elevation in meters
00396       void UpdateElevation (
00397          const float update
00398          );
00399 
00400       //! Update roll angle in degrees
00401       void UpdateRoll (
00402          const float update
00403          );
00404 
00405       //! Move viewer point along view direction
00406       void ViewerMoveAlongDirection (
00407          const float distance
00408          );
00409 
00410       //! Update viewer point z coordinate
00411       void ViewerUpdateZ (
00412          const float distance
00413          );
00414 
00415       //! Get Model to World transformation
00416       //! 
00417       //! @return Model to World transformation
00418       const TRANS3D& GetModelToWorld () const     { return m_Parameters[m_Index].m_ModelToWorld;       };
00419 
00420       //! Get Model to View transformation
00421       //! 
00422       //! @return Model to View transformation
00423       const TRANS3D& GetModelToView () const      { return m_Parameters[m_Index].m_ModelToView;     };
00424 
00425       //! Get Model to UnitCube transformation
00426       //! 
00427       //! @return Model to UnitCube transformation
00428       const TRANS3D& GetModelToUnitCube () const  { return m_Parameters[m_Index].m_ModelToUnitCube;  };
00429 
00430       //! Get Model to Screen transformation
00431       //! 
00432       //! @return Model to Screen transformation
00433       const TRANS3D& GetModelToScreen () const    { return m_Parameters[m_Index].m_ModelToScreen;   };
00434 
00435       //! Get World to View transformation
00436       //! 
00437       //! @return World to View transformation
00438       const TRANS3D& GetWorldToView () const      { return m_Parameters[m_Index].m_WorldToView;     };
00439 
00440       //! Get World to UnitCube transformation
00441       //! 
00442       //! @return World to UnitCube transformation
00443       const TRANS3D& GetWorldToUnitCube () const  { return m_Parameters[m_Index].m_WorldToUnitCube;  };
00444 
00445       //! Get World to Screen transformation
00446       //! 
00447       //! @return World to Screen transformation
00448       const TRANS3D& GetWorldToScreen () const    { return m_Parameters[m_Index].m_WorldToScreen;   };
00449 
00450       //! Get View to UnitCube transformation
00451       //! 
00452       //! @return View to UnitCube transformation
00453       const TRANS3D& GetViewToUnitCube () const   { return m_Parameters[m_Index].m_ViewToUnitCube;   };
00454 
00455       //! Get View to Screen transformation
00456       //! 
00457       //! @return View to Screen transformation
00458       const TRANS3D& GetViewToScreen () const     { return m_Parameters[m_Index].m_ViewToScreen;     };
00459 
00460       //! Get UnitCube to Screen transformation
00461       //! 
00462       //! @return UnitCube to Screen transformation
00463       const TRANS3D& GetUnitCubeToScreen () const { return m_Parameters[m_Index].m_UnitCubeToScreen; };
00464 
00465       void PrintToFile (const char* filename, const char* mode);
00466 
00467    private:
00468 
00469       enum INDEX {
00470          INDEX_Left = 0,
00471          INDEX_Center = 1,
00472          INDEX_Right = 2,
00473          INDEX_Count = 3
00474          };
00475 
00476       #ifndef GENERATING_DOXYGEN_OUTPUT
00477 
00478       class PARAMETERS {
00479 
00480          public:
00481 
00482          #define NUMPLANES 4
00483          typedef FPOINT3D FRUSTUMVECTORS[NUMPLANES];
00484          typedef FLOAT FRUSTUMSCALARS[NUMPLANES];
00485 
00486          FPOINT3D m_Viewer;
00487          FPOINT3D m_LookAt;
00488 
00489          TRANS3D ALIGN16(m_ModelToWorld);              
00490          TRANS3D ALIGN16(m_ModelToView);               
00491          TRANS3D ALIGN16(m_ModelToUnitCube);              
00492          TRANS3D ALIGN16(m_ModelToScreen);                
00493          TRANS3D ALIGN16(m_WorldToView);               
00494          TRANS3D ALIGN16(m_WorldToUnitCube);              
00495          TRANS3D ALIGN16(m_WorldToScreen);                 
00496          TRANS3D ALIGN16(m_ViewToUnitCube);
00497          TRANS3D ALIGN16(m_ViewToScreen);
00498          TRANS3D ALIGN16(m_UnitCubeToScreen);
00499 
00500          DRECT2D ALIGN16(m_ScreenRect);            //!< Destination or screen rectangle
00501 
00502          DRECT3D ALIGN16(m_Frustum);               //!< 6 parameters 
00503                                           //! (xinit = left, xlast = right, 
00504                                           //! yinit = bottom, ylast = top, 
00505                                           //! zinit = near, zlast = far) specify frustum in meters 
00506 
00507          FRUSTUMVECTORS m_Normals;              //!<  Bounding Planes {p[i].normal.x * x + p[i].normal.y * y + p[i].normal.z * z + p[i].D = 0}
00508          FRUSTUMSCALARS m_D;                    //!< { right, bottom, left, top}
00509          FRUSTUMVECTORS m_Lines;                //!< Bounding Line Vectors {right-bottom,bottom-left,left-top,top-right}
00510          FRUSTUMVECTORS m_Corners;
00511 
00512          PARAMETERS ();
00513          PARAMETERS& operator= (const PARAMETERS& rhs);
00514          };
00515 
00516       static const UINT8 s_OutCodes[NUMPLANES];
00517 
00518       bool m_Calculated;
00519 
00520       float m_FieldOfViewAngle;
00521 
00522       FPOINT3D m_Dir;
00523       FPOINT3D m_Up;
00524 
00525       float m_Azimuth;
00526       float m_Elevation;
00527       float m_Roll;
00528 
00529       float m_Distance;
00530 
00531       float m_BaseElevation;
00532       float m_SunAzimuthAngle;            
00533       float m_SunElevationAngle;                
00534 
00535       bool m_IsPerspective;
00536       float m_ParallelProjectionDistance;
00537 
00538       float m_NearPlane;
00539       float m_FarPlane;
00540       bool m_UseNearFarPlanes;
00541 
00542       bool m_IsStereo;
00543       float m_StereoDistance;
00544       float m_StereoScale;
00545       STEREOMODE m_StereoMode;
00546       STEREOVIEW m_StereoView;
00547       float m_OpticalSeparation;
00548       float m_MonitorSeparation;
00549 
00550       DRECT2D ALIGN16(m_ScreenRect);            //!< Destination or screen rectangle
00551 
00552       DOUBLE_ARRAY<DRECT3D> m_Extents;       //!< Extents of all terrains for this scene
00553 
00554       INDEX m_Index;
00555       PARAMETERS m_Parameters[INDEX_Count];
00556 
00557 
00558       UINT8 AssignCodes (const FPOINT3D &pt) const;
00559 
00560       void CalculateAngles ();
00561 
00562       bool CalculateCenterParameters ();
00563 
00564       void CalculateDependantTransformations ();
00565 
00566       void CalculateFrustum ();
00567 
00568       void CalculateFrustumParameters (const INDEX index);
00569 
00570       void CalculateLookAt ();
00571 
00572       float CalculateSquaredDistanceToLine (const FPOINT3D &pt, const int index) const;
00573 
00574       float CalculateSquaredDistanceToPlane (const FPOINT3D &pt, const int index) const;
00575 
00576       bool CalculateStereoParameters ();
00577 
00578       void CalculateUnitCubeToScreen (const INDEX index);
00579 
00580       bool CalculateViewToUnitCube (const INDEX index);
00581 
00582       void CalculateWorldToView (INDEX index);
00583 
00584       void CalculateZRange (double& zmin, double& zmax);
00585 
00586       #endif //!< GENERATING_DOXYGEN_OUTPUT
00587    };
00588 
00589 
00590 };    //! End of namespace
00591 
00592 #endif
00593 

Generated on Thu Apr 26 04:44:38 2007 for TNTsdk by  doxygen 1.5.2