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

Generated on Thu Apr 26 04:03:29 2007 for TNTsdk by  doxygen 1.5.2