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

Generated on Tue Dec 14 13:18:11 2004 for TNTsdk by  doxygen 1.3.8-20040913