00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
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
00105
00106
00107
00108
00109
00110 class SCENE3D {
00111 public:
00112
00113 enum STEREOVIEW {
00114 STEREOVIEW_None,
00115 STEREOVIEW_Left,
00116 STEREOVIEW_Right
00117 };
00118
00119 SCENE3D (
00120 const float FieldOfViewAngle = 45
00121 );
00122
00123 ~SCENE3D (
00124 );
00125
00126 SCENE3D& operator= (
00127 const SCENE3D& rhs
00128 );
00129
00130
00131
00132
00133
00134 bool CalculateParameters (
00135 const DRECT2D& screenrect
00136 );
00137
00138
00139 void Clear (
00140 );
00141
00142
00143 void ClearModelToWorld ();
00144
00145
00146
00147
00148
00149 bool ClipSegment (
00150 FPOINT3D &pts,
00151 FPOINT3D &pte
00152 );
00153
00154
00155
00156
00157 float GetAzimuth (
00158 ) const;
00159
00160
00161
00162
00163 const FPOINT3D& GetDirection (
00164 ) const;
00165
00166
00167
00168
00169 float GetElevation (
00170 ) const {return m_Elevation;};
00171
00172
00173 float GetBaseElevation (
00174 ) const;
00175
00176
00177
00178
00179 float GetFieldOfViewAngle (
00180 ) const;
00181
00182
00183
00184
00185 const DRECT3D& GetFrustum (
00186 ) const;
00187
00188
00189
00190
00191 const FPOINT3D& GetLookAt (
00192 ) const;
00193
00194
00195
00196
00197 float GetParallelProjectionDistance (
00198 ) const;
00199
00200
00201 double GetPixelSizeInMeters (
00202 ) const;
00203
00204
00205
00206 float GetRoll (
00207 ) const;
00208
00209
00210
00211 const DRECT2D& GetScreenRect (
00212 ) const;
00213
00214
00215 STEREOVIEW GetStereoView (
00216 ) const { return (m_StereoView); }
00217
00218 float GetSunAzimuthAngle (
00219 ) const;
00220
00221 float GetSunElevationAngle (
00222 ) const;
00223
00224
00225
00226
00227 FPOINT3D GetViewer (
00228 ) const;
00229
00230
00231
00232
00233 const FPOINT3D& GetUp (
00234 ) const;
00235
00236
00237
00238
00239 bool IsCalculated (
00240 ) const;
00241
00242
00243
00244
00245 bool IsPerspective (
00246 ) const;
00247
00248
00249
00250
00251 bool IsRectangleOverlapped (
00252 const DRECT3D& rect
00253 ) const;
00254
00255
00256
00257
00258 bool IsSegmentOverlapped (
00259 const FPOINT3D &pts,
00260 const FPOINT3D &pte
00261 ) const;
00262
00263
00264
00265
00266 bool IsSphereOverlapped (
00267 const FPOINT3D ¢er,
00268 const float radiussquared = 0.0f
00269 ) const;
00270
00271
00272
00273
00274 bool IsStereo (
00275 ) const;
00276
00277
00278
00279
00280 bool IsTriangleOverlapped (
00281 const FPOINT3D &pt1,
00282 const FPOINT3D &pt2,
00283 const FPOINT3D &pt3
00284 ) const;
00285
00286
00287 void SetAzimuth (
00288 const float azimuth,
00289 const bool recalculate = true
00290 );
00291
00292
00293 void SetElevation (
00294 const float elevation
00295 );
00296
00297
00298 void SetBaseElevation (
00299 const float BaseElevation
00300 );
00301
00302
00303 void SetExtents (
00304 DOUBLE_ARRAY<DRECT3D>& extents
00305 );
00306
00307
00308 void SetFieldOfViewAngle (
00309 const float FieldOfViewAngle
00310 );
00311
00312
00313 void SetFrustum (
00314 const DRECT2D& frustum
00315 );
00316
00317
00318 void SetLookAt (
00319 const FPOINT3D& lookAt
00320 );
00321
00322
00323 void SetModelToWorld (const TRANS3D& ModelToWorld);
00324
00325 void SetMonitorSeparation (
00326 const double monitor
00327 );
00328
00329
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
00341 void SetParallelProjectionDistance (
00342 const float distance
00343 );
00344
00345
00346 void SetPerspective (
00347 const bool isPerspective
00348 );
00349
00350
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
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
00386 void SetViewer (
00387 const FPOINT3D& viewer
00388 );
00389
00390
00391 void UpdateAzimuth (
00392 const float update
00393 );
00394
00395
00396 void UpdateElevation (
00397 const float update
00398 );
00399
00400
00401 void UpdateRoll (
00402 const float update
00403 );
00404
00405
00406 void ViewerMoveAlongDirection (
00407 const float distance
00408 );
00409
00410
00411 void ViewerUpdateZ (
00412 const float distance
00413 );
00414
00415
00416
00417
00418 const TRANS3D& GetModelToWorld () const { return m_Parameters[m_Index].m_ModelToWorld; };
00419
00420
00421
00422
00423 const TRANS3D& GetModelToView () const { return m_Parameters[m_Index].m_ModelToView; };
00424
00425
00426
00427
00428 const TRANS3D& GetModelToUnitCube () const { return m_Parameters[m_Index].m_ModelToUnitCube; };
00429
00430
00431
00432
00433 const TRANS3D& GetModelToScreen () const { return m_Parameters[m_Index].m_ModelToScreen; };
00434
00435
00436
00437
00438 const TRANS3D& GetWorldToView () const { return m_Parameters[m_Index].m_WorldToView; };
00439
00440
00441
00442
00443 const TRANS3D& GetWorldToUnitCube () const { return m_Parameters[m_Index].m_WorldToUnitCube; };
00444
00445
00446
00447
00448 const TRANS3D& GetWorldToScreen () const { return m_Parameters[m_Index].m_WorldToScreen; };
00449
00450
00451
00452
00453 const TRANS3D& GetViewToUnitCube () const { return m_Parameters[m_Index].m_ViewToUnitCube; };
00454
00455
00456
00457
00458 const TRANS3D& GetViewToScreen () const { return m_Parameters[m_Index].m_ViewToScreen; };
00459
00460
00461
00462
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);
00501
00502 DRECT3D ALIGN16(m_Frustum);
00503
00504
00505
00506
00507 FRUSTUMVECTORS m_Normals;
00508 FRUSTUMSCALARS m_D;
00509 FRUSTUMVECTORS m_Lines;
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);
00551
00552 DOUBLE_ARRAY<DRECT3D> m_Extents;
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
00587 };
00588
00589
00590 };
00591
00592 #endif
00593