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 #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
00092
00093
00094
00095
00096
00097 class SCENE3D {
00098 public:
00099
00100 SCENE3D (
00101 const float FieldOfViewAngle = 45
00102 );
00103
00104 ~SCENE3D (
00105 );
00106
00107 SCENE3D& operator= (
00108 const SCENE3D& rhs
00109 );
00110
00111
00112
00113
00114
00115 bool CalculateParameters (
00116 const DRECT2D& screenrect
00117 );
00118
00119
00120 void Clear (
00121 );
00122
00123
00124 void ClearModelToWorld ();
00125
00126
00127
00128
00129
00130 bool ClipSegment (
00131 FPOINT3D &pts,
00132 FPOINT3D &pte
00133 );
00134
00135
00136
00137
00138 float GetAzimuth (
00139 ) const;
00140
00141
00142
00143
00144 const FPOINT3D& GetDirection (
00145 ) const;
00146
00147
00148
00149
00150 float GetElevation (
00151 ) const {return m_Elevation;};
00152
00153
00154 float GetBaseElevation (
00155 ) const;
00156
00157
00158
00159
00160 float GetFieldOfViewAngle (
00161 ) const;
00162
00163
00164
00165
00166 const DRECT3D& GetFrustum (
00167 ) const;
00168
00169
00170
00171
00172 const FPOINT3D& GetLookAt (
00173 ) const;
00174
00175
00176
00177
00178 float GetParallelProjectionDistance (
00179 ) const;
00180
00181
00182
00183
00184 float GetRoll (
00185 ) const;
00186
00187
00188
00189
00190 const DRECT2D& GetScreenRect (
00191 ) const;
00192
00193 float GetSunAzimuthAngle (
00194 ) const;
00195
00196 float GetSunElevationAngle (
00197 ) const;
00198
00199
00200
00201
00202 FPOINT3D GetViewer (
00203 ) const;
00204
00205
00206
00207
00208 const FPOINT3D& GetUp (
00209 ) const;
00210
00211
00212
00213
00214 bool IsCalculated (
00215 ) const;
00216
00217
00218
00219
00220 bool IsPerspective (
00221 ) const;
00222
00223
00224
00225
00226 bool IsRectangleOverlapped (
00227 const DRECT3D& rect
00228 ) const;
00229
00230
00231
00232
00233 bool IsSegmentOverlapped (
00234 const FPOINT3D &pts,
00235 const FPOINT3D &pte
00236 ) const;
00237
00238
00239
00240
00241 bool IsSphereOverlapped (
00242 const FPOINT3D ¢er,
00243 const float radiussquared = 0.0f
00244 ) const;
00245
00246
00247
00248
00249 bool IsStereo (
00250 ) const;
00251
00252
00253
00254
00255 bool IsTriangleOverlapped (
00256 const FPOINT3D &pt1,
00257 const FPOINT3D &pt2,
00258 const FPOINT3D &pt3
00259 ) const;
00260
00261
00262 void SetAzimuth (
00263 const float azimuth,
00264 const bool recalculate = true
00265 );
00266
00267
00268 void SetElevation (
00269 const float elevation
00270 );
00271
00272
00273 void SetBaseElevation (
00274 const float BaseElevation
00275 );
00276
00277
00278 void SetExtents (
00279 DOUBLE_ARRAY<DRECT3D>& extents
00280 );
00281
00282
00283 void SetFieldOfViewAngle (
00284 const float FieldOfViewAngle
00285 );
00286
00287
00288 void SetFrustum (
00289 const DRECT2D& frustum
00290 );
00291
00292
00293 void SetLookAt (
00294 const FPOINT3D& lookAt
00295 );
00296
00297
00298 void SetModelToWorld (const TRANS3D& ModelToWorld);
00299
00300
00301 void SetNearFarPlanes (
00302 const double nearplane,
00303 const double farplane,
00304 const bool use = false
00305 );
00306
00307
00308 void SetParallelProjectionDistance (
00309 const float distance
00310 );
00311
00312
00313 void SetPerspective (
00314 const bool isPerspective
00315 );
00316
00317
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
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
00361 void SetViewer (
00362 const FPOINT3D& viewer
00363 );
00364
00365
00366 void UpdateAzimuth (
00367 const float update
00368 );
00369
00370
00371 void UpdateElevation (
00372 const float update
00373 );
00374
00375
00376 void UpdateRoll (
00377 const float update
00378 );
00379
00380
00381 void ViewerMoveAlongDirection (
00382 const float distance
00383 );
00384
00385
00386 void ViewerUpdateZ (
00387 const float distance
00388 );
00389
00390
00391
00392
00393 const TRANS3D& GetModelToWorld () const { return m_Parameters[m_Index].m_ModelToWorld; };
00394
00395
00396
00397
00398 const TRANS3D& GetModelToView () const { return m_Parameters[m_Index].m_ModelToView; };
00399
00400
00401
00402
00403 const TRANS3D& GetModelToUnitCube () const { return m_Parameters[m_Index].m_ModelToUnitCube; };
00404
00405
00406
00407
00408 const TRANS3D& GetModelToScreen () const { return m_Parameters[m_Index].m_ModelToScreen; };
00409
00410
00411
00412
00413 const TRANS3D& GetWorldToView () const { return m_Parameters[m_Index].m_WorldToView; };
00414
00415
00416
00417
00418 const TRANS3D& GetWorldToUnitCube () const { return m_Parameters[m_Index].m_WorldToUnitCube; };
00419
00420
00421
00422
00423 const TRANS3D& GetWorldToScreen () const { return m_Parameters[m_Index].m_WorldToScreen; };
00424
00425
00426
00427
00428 const TRANS3D& GetViewToUnitCube () const { return m_Parameters[m_Index].m_ViewToUnitCube; };
00429
00430
00431
00432
00433 const TRANS3D& GetViewToScreen () const { return m_Parameters[m_Index].m_ViewToScreen; };
00434
00435
00436
00437
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;
00475
00476 DRECT3D m_Frustum;
00477
00478
00479
00480
00481 FRUSTUMVECTORS m_Normals;
00482 FRUSTUMSCALARS m_D;
00483 FRUSTUMVECTORS m_Lines;
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;
00525
00526 DOUBLE_ARRAY<DRECT3D> m_Extents;
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
00561 };
00562
00563
00564 };
00565
00566 #endif
00567