00001
00033 #ifndef INC_GRE_3DSCENE_H
00034 #define INC_GRE_3DSCENE_H
00035
00036 #ifndef INC_GRE_BASE_H
00037 #include <gre/base.h>
00038 #endif
00039
00040 #ifndef INC_MI32_STEREOVIEW_H
00041 #include <mi32/stereoview.h>
00042 #endif
00043
00044 #ifndef INC_MI32_STEREODEVICE_H
00045 #include <mi32/stereodevice.h>
00046 #endif
00047
00048 #ifndef INC_MI32_RECT_H
00049 #include <mi32/rect.h>
00050 #endif
00051
00052 #ifndef INC_MI32_TRANS3D_H
00053 #include <mi32/trans3d.h>
00054 #endif
00055
00056 #ifndef INC_MI32_DOUBLEAR_H
00057 #include <mi32/doublear.h>
00058 #endif
00059
00060
00061 namespace GRE {
00062
00069 class SCENE3D {
00070 public:
00071
00072 SCENE3D (
00073 const float FieldOfViewAngle = 45
00074 );
00075
00076 ~SCENE3D ();
00077
00078 SCENE3D& operator= (
00079 const SCENE3D& rhs
00080 );
00081
00085 bool CalculateParameters (
00086 const DRECT2D& screenrect
00087 );
00088
00090 void Clear (
00091 );
00092
00094 void ClearModelToWorld ();
00095
00100 bool ClipSegment (
00101 FPOINT3D &pts,
00102 FPOINT3D &pte
00103 );
00104
00108 float GetAzimuth (
00109 ) const;
00110
00114 const FPOINT3D& GetDirection (
00115 ) const;
00116
00120 float GetElevation (
00121 ) const {return m_Elevation;};
00122
00124 float GetBaseElevation (
00125 ) const;
00126
00130 float GetFieldOfViewAngle (
00131 ) const;
00132
00136 const DRECT3D& GetFrustum (
00137 ) const;
00138
00142 const FPOINT3D& GetLookAt (
00143 ) const;
00144
00148 float GetParallelProjectionDistance (
00149 ) const;
00150
00152 double GetPixelSizeInMeters (
00153 ) const;
00154
00157 float GetRoll (
00158 ) const;
00159
00162 const DRECT2D& GetScreenRect (
00163 ) const;
00164
00166 STEREOVIEW GetStereoView (
00167 ) const { return (m_StereoView); }
00168
00169 float GetSunAzimuthAngle (
00170 ) const;
00171
00172 float GetSunElevationAngle (
00173 ) const;
00174
00178 FPOINT3D GetViewer (
00179 ) const;
00180
00184 const FPOINT3D& GetUp (
00185 ) const;
00186
00190 bool IsCalculated (
00191 ) const;
00192
00196 bool IsPerspective (
00197 ) const;
00198
00202 bool IsRectangleOverlapped (
00203 const DRECT3D& rect
00204 ) const;
00205
00209 bool IsSegmentOverlapped (
00210 const FPOINT3D &pts,
00211 const FPOINT3D &pte
00212 ) const;
00213
00217 bool IsSphereOverlapped (
00218 const FPOINT3D ¢er,
00219 const float radiussquared = 0.0f
00220 ) const;
00221
00225 bool IsStereo (
00226 ) const;
00227
00231 bool IsTriangleOverlapped (
00232 const FPOINT3D &pt1,
00233 const FPOINT3D &pt2,
00234 const FPOINT3D &pt3
00235 ) const;
00236
00238 void SetAzimuth (
00239 const float azimuth,
00240 const bool recalculate = true
00241 );
00242
00244 void SetElevation (
00245 const float elevation
00246 );
00247
00249 void SetBaseElevation (
00250 const float BaseElevation
00251 );
00252
00254 void SetExtents (
00255 DOUBLE_ARRAY<DRECT3D>& extents
00256 );
00257
00259 void SetFieldOfViewAngle (
00260 const float FieldOfViewAngle
00261 );
00262
00264 void SetFrustum (
00265 const DRECT2D& frustum
00266 );
00267
00269 void SetLookAt (
00270 const FPOINT3D& lookAt
00271 );
00272
00274 void SetModelToWorld (const TRANS3D& ModelToWorld);
00275
00276 void SetMonitorSeparation (
00277 const double monitor
00278 );
00279
00281 void SetNearFarPlanes (
00282 const double nearplane,
00283 const double farplane,
00284 const bool use = false
00285 );
00286
00287 void SetOpticalSeparation (
00288 const double optical
00289 );
00290
00292 void SetParallelProjectionDistance (
00293 const float distance
00294 );
00295
00297 void SetPerspective (
00298 const bool isPerspective
00299 );
00300
00302 void SetRoll (
00303 const float roll,
00304 const bool recalculate = true
00305 );
00306
00307 void SetSunAzimuthAngle (
00308 const float SunAzimuthAngle
00309 );
00310
00311 void SetSunElevationAngle (
00312 const float SunElevationAngle
00313 );
00314
00316 void SetStereo (
00317 const bool isStereo
00318 );
00319
00320 void SetStereoDistance (
00321 const double distance
00322 );
00323
00324 void SetStereoMode (
00325 const STEREODEVICE::METHOD mode
00326 );
00327
00328 void SetStereoScale (
00329 const double scale
00330 );
00331
00332 void SetStereoView (
00333 const STEREOVIEW stereoview
00334 );
00335
00337 void SetViewer (
00338 const FPOINT3D& viewer
00339 );
00340
00342 void UpdateAzimuth (
00343 const float update
00344 );
00345
00347 void UpdateElevation (
00348 const float update
00349 );
00350
00352 void UpdateRoll (
00353 const float update
00354 );
00355
00357 void ViewerMoveAlongDirection (
00358 const float distance
00359 );
00360
00362 void ViewerUpdateZ (
00363 const float distance
00364 );
00365
00369 const TRANS3D& GetModelToWorld () const { return m_Parameters[m_Index].m_ModelToWorld; };
00370
00374 const TRANS3D& GetModelToView () const { return m_Parameters[m_Index].m_ModelToView; };
00375
00379 const TRANS3D& GetModelToUnitCube () const { return m_Parameters[m_Index].m_ModelToUnitCube; };
00380
00384 const TRANS3D& GetModelToScreen () const { return m_Parameters[m_Index].m_ModelToScreen; };
00385
00389 const TRANS3D& GetWorldToView () const { return m_Parameters[m_Index].m_WorldToView; };
00390
00394 const TRANS3D& GetWorldToUnitCube () const { return m_Parameters[m_Index].m_WorldToUnitCube; };
00395
00399 const TRANS3D& GetWorldToScreen () const { return m_Parameters[m_Index].m_WorldToScreen; };
00400
00404 const TRANS3D& GetViewToUnitCube () const { return m_Parameters[m_Index].m_ViewToUnitCube; };
00405
00409 const TRANS3D& GetViewToScreen () const { return m_Parameters[m_Index].m_ViewToScreen; };
00410
00414 const TRANS3D& GetUnitCubeToScreen () const { return m_Parameters[m_Index].m_UnitCubeToScreen; };
00415
00416 private:
00417 #ifndef GENERATING_DOXYGEN_OUTPUT
00418
00419 enum INDEX {
00420 INDEX_Left = 0,
00421 INDEX_Center = 1,
00422 INDEX_Right = 2,
00423 INDEX_Count = 3
00424 };
00425
00426 class PARAMETERS {
00427
00428 public:
00429 #define NUMPLANES 4
00430 typedef FPOINT3D FRUSTUMVECTORS[NUMPLANES];
00431 typedef FLOAT FRUSTUMSCALARS[NUMPLANES];
00432
00433 FPOINT3D m_Viewer;
00434 FPOINT3D m_LookAt;
00435 TRANS3D ALIGN16(m_ModelToWorld);
00436 TRANS3D ALIGN16(m_ModelToView);
00437 TRANS3D ALIGN16(m_ModelToUnitCube);
00438 TRANS3D ALIGN16(m_ModelToScreen);
00439 TRANS3D ALIGN16(m_WorldToView);
00440 TRANS3D ALIGN16(m_WorldToUnitCube);
00441 TRANS3D ALIGN16(m_WorldToScreen);
00442 TRANS3D ALIGN16(m_ViewToUnitCube);
00443 TRANS3D ALIGN16(m_ViewToScreen);
00444 TRANS3D ALIGN16(m_UnitCubeToScreen);
00445 DRECT2D ALIGN16(m_ScreenRect);
00446 DRECT3D ALIGN16(m_Frustum);
00447 FRUSTUMVECTORS m_Normals;
00448 FRUSTUMSCALARS m_D;
00449 FRUSTUMVECTORS m_Lines;
00450 FRUSTUMVECTORS m_Corners;
00451
00452 PARAMETERS ();
00453 PARAMETERS& operator= (const PARAMETERS& rhs);
00454 };
00455
00456 static const UINT8 s_OutCodes[NUMPLANES];
00457
00458 bool m_Calculated;
00459 float m_FieldOfViewAngle;
00460 FPOINT3D m_Dir;
00461 FPOINT3D m_Up;
00462 float m_Azimuth;
00463 float m_Elevation;
00464 float m_Roll;
00465 float m_Distance;
00466 float m_BaseElevation;
00467 float m_SunAzimuthAngle;
00468 float m_SunElevationAngle;
00469 bool m_IsPerspective;
00470 float m_ParallelProjectionDistance;
00471 float m_NearPlane;
00472 float m_FarPlane;
00473 bool m_UseNearFarPlanes;
00474 bool m_IsStereo;
00475 float m_StereoDistance;
00476 float m_StereoScale;
00477 STEREODEVICE::METHOD m_StereoMode;
00478 STEREOVIEW m_StereoView;
00479 float m_OpticalSeparation;
00480 float m_MonitorSeparation;
00481 DRECT2D ALIGN16(m_ScreenRect);
00482 DOUBLE_ARRAY<DRECT3D> m_Extents;
00483 INDEX m_Index;
00484 PARAMETERS m_Parameters[INDEX_Count];
00485
00486 UINT8 AssignCodes (const FPOINT3D &pt) const;
00487 void CalculateAngles ();
00488 bool CalculateCenterParameters ();
00489 void CalculateDependantTransformations ();
00490 void CalculateFrustum ();
00491 void CalculateFrustumParameters (const INDEX index);
00492 void CalculateLookAt ();
00493 float CalculateSquaredDistanceToLine (const FPOINT3D &pt, const int index) const;
00494 float CalculateSquaredDistanceToPlane (const FPOINT3D &pt, const int index) const;
00495 bool CalculateStereoParameters ();
00496 void CalculateUnitCubeToScreen (const INDEX index);
00497 bool CalculateViewToUnitCube (const INDEX index);
00498 void CalculateWorldToView (INDEX index);
00499 void CalculateZRange (double& zmin, double& zmax);
00500
00501 #endif
00502 };
00503
00504
00505 };
00506
00507 #endif
00508