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