![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /***************************************************************************** 00002 * Copyright (c) 2011 MAK Technologies, Inc. 00003 * All rights reserved. 00004 *****************************************************************************/ 00005 /***************************************************************************** 00006 * $RCSfile: DtOsgObserverObject.h,v $ $Revision: 1.66 $ $State: Exp $ 00007 *****************************************************************************/ 00008 00012 00013 #pragma once 00014 00015 #include <vrvOsg/vrvOsg.h> 00016 00017 #include <vrvCore/DtObserverObject.h> 00018 00019 #include <boost/unordered_map.hpp> 00020 00021 #include <osg/Matrixd> 00022 #include <osg/Vec3d> 00023 #include <osg/Vec3> 00024 00025 class DtTaitBryan; 00026 00027 namespace osg 00028 { 00029 class Node; 00030 } 00031 00032 namespace makVrv 00033 { 00034 00035 class DtOsgChannel; 00036 class DtCoordinateConverter; 00037 class DtSceneObject; 00038 class DtTerrainPatchObject; 00039 class DtAgentUpdateResolverInterface; 00040 00044 class DT_DLL_VRVOSG DtOsgObserverObject : public DtObserverObject 00045 { 00046 00047 public: 00048 00049 enum TerrainResult 00050 { 00051 TerrainResultNoData = 0, 00052 TerrainResultNewCenter, 00053 TerrainResultComplete 00054 }; 00055 00057 DtOsgObserverObject( DtDe& de, DtUniqueID id, const std::string& name="" ); 00058 00060 virtual ~DtOsgObserverObject(); 00061 00063 virtual void tick( double simTime ); 00064 00065 virtual void tickAttachment(); 00066 00069 virtual void setModelSet( int modelSet ); 00070 00072 virtual double altitude() const; 00073 00074 virtual void setNameAndRegister( const std::string& name ); 00075 00076 virtual void getCameraPositionAndOrientation( osg::Vec3d& position, 00077 osg::Quat& rotation ) const; 00078 00079 // 00080 // 00082 // 00083 // 00084 00086 00087 00088 virtual void startMoveObserverRight(); 00089 virtual void stopMoveObserverRight(); 00090 virtual void moveObserverRight( double meters ); 00091 00093 00094 00095 virtual void startMoveObserverForward(); 00096 virtual void stopMoveObserverForward(); 00097 virtual void moveObserverForward( double meters ); 00099 00101 00102 00103 virtual void startMoveObserverUp(); 00104 virtual void stopMoveObserverUp(); 00105 virtual void moveObserverUp( double meters ); 00107 00109 00110 00111 virtual void startMoveObserverLeft(); 00112 virtual void stopMoveObserverLeft(); 00113 virtual void moveObserverLeft( double meters ); 00115 00117 00118 00119 virtual void startMoveObserverBack(); 00120 virtual void stopMoveObserverBack(); 00121 virtual void moveObserverBack( double meters ); 00123 00125 00126 00127 virtual void startMoveObserverDown(); 00128 virtual void stopMoveObserverDown(); 00129 virtual void moveObserverDown( double meters ); 00131 00133 00134 00135 00136 virtual void startMoveLevelObserverRight(); 00137 virtual void stopMoveLevelObserverRight(); 00138 virtual void moveLevelObserverRight( double meters ); 00140 00142 00143 00144 00145 virtual void startMoveLevelObserverForward(); 00146 virtual void stopMoveLevelObserverForward(); 00147 virtual void moveLevelObserverForward( double meters ); 00149 00151 00152 00153 00154 virtual void startMoveLevelObserverUp(); 00155 virtual void stopMoveLevelObserverUp(); 00156 virtual void moveLevelObserverUp( double meters ); 00158 00160 00161 00162 00163 virtual void startMoveLevelObserverLeft(); 00164 virtual void stopMoveLevelObserverLeft(); 00165 virtual void moveLevelObserverLeft( double meters ); 00167 00169 00170 00171 00172 virtual void startMoveLevelObserverBack(); 00173 virtual void stopMoveLevelObserverBack(); 00174 virtual void moveLevelObserverBack( double meters ); 00176 00178 00179 00180 virtual void startMoveLevelObserverDown(); 00181 virtual void stopMoveLevelObserverDown(); 00182 virtual void moveLevelObserverDown( double meters ); 00184 00186 00187 00188 virtual void startMoveAttachedRight(); 00189 virtual void stopMoveAttachedRight(); 00190 virtual void moveAttachedRight( double meters ); 00191 00193 00194 00195 virtual void startMoveAttachedForward(); 00196 virtual void stopMoveAttachedForward(); 00197 virtual void moveAttachedForward( double meters ); 00199 00201 00202 00203 virtual void startMoveAttachedUp(); 00204 virtual void stopMoveAttachedUp(); 00205 virtual void moveAttachedUp( double meters ); 00207 00209 00210 00211 virtual void startMoveAttachedLeft(); 00212 virtual void stopMoveAttachedLeft(); 00213 virtual void moveAttachedLeft( double meters ); 00215 00217 00218 00219 virtual void startMoveAttachedBack(); 00220 virtual void stopMoveAttachedBack(); 00221 virtual void moveAttachedBack( double meters ); 00223 00225 00226 00227 virtual void startMoveAttachedDown(); 00228 virtual void stopMoveAttachedDown(); 00229 virtual void moveAttachedDown( double meters ); 00231 00233 00234 00235 00236 virtual void startMoveLevelAttachedRight(); 00237 virtual void stopMoveLevelAttachedRight(); 00238 virtual void moveLevelAttachedRight( double meters ); 00240 00242 00243 00244 00245 virtual void startMoveLevelAttachedForward(); 00246 virtual void stopMoveLevelAttachedForward(); 00247 virtual void moveLevelAttachedForward( double meters ); 00249 00251 00252 00253 00254 virtual void startMoveLevelAttachedUp(); 00255 virtual void stopMoveLevelAttachedUp(); 00256 virtual void moveLevelAttachedUp( double meters ); 00258 00260 00261 00262 00263 virtual void startMoveLevelAttachedLeft(); 00264 virtual void stopMoveLevelAttachedLeft(); 00265 virtual void moveLevelAttachedLeft( double meters ); 00267 00269 00270 00271 00272 virtual void startMoveLevelAttachedBack(); 00273 virtual void stopMoveLevelAttachedBack(); 00274 virtual void moveLevelAttachedBack( double meters ); 00276 00278 00279 00280 virtual void startMoveLevelAttachedDown(); 00281 virtual void stopMoveLevelAttachedDown(); 00282 virtual void moveLevelAttachedDown( double meters ); 00284 00286 00287 00288 virtual void startMoveAttachedContextRight(); 00289 virtual void stopMoveAttachedContextRight(); 00290 virtual void moveAttachedContextRight( double meters ); 00292 00294 00295 00296 virtual void startMoveAttachedContextForward(); 00297 virtual void stopMoveAttachedContextForward(); 00298 virtual void moveAttachedContextForward( double meters ); 00300 00302 00303 00304 virtual void startMoveAttachedContextUp(); 00305 virtual void stopMoveAttachedContextUp(); 00306 virtual void moveAttachedContextUp( double meters ); 00308 00310 00311 00312 virtual void startMoveAttachedContextLeft(); 00313 virtual void stopMoveAttachedContextLeft(); 00314 virtual void moveAttachedContextLeft( double meters ); 00316 00318 00319 00320 virtual void startMoveAttachedContextBack(); 00321 virtual void stopMoveAttachedContextBack(); 00322 virtual void moveAttachedContextBack( double meters ); 00324 00326 00327 virtual void startMoveAttachedContextDown(); 00328 virtual void stopMoveAttachedContextDown(); 00329 virtual void moveAttachedContextDown( double meters ); 00331 00333 00334 00335 virtual void startYawLeft(); 00336 virtual void stopYawLeft(); 00338 00340 00341 00342 00343 virtual void startYawRight(); 00344 virtual void stopYawRight(); 00346 00348 00349 00350 virtual void startPitchUp(); 00351 virtual void stopPitchUp(); 00352 virtual void rotatePitchUp( double rads ); 00354 00356 00357 00358 virtual void startPitchDown(); 00359 virtual void stopPitchDown(); 00360 virtual void rotatePitchDown( double rads ); 00362 00364 00365 00366 virtual void startRollLeft(); 00367 virtual void stopRollLeft(); 00369 00371 00372 00373 virtual void startRollRight(); 00374 virtual void stopRollRight(); 00376 00378 00379 00380 virtual void startLevelYawLeft(); 00381 virtual void stopLevelYawLeft(); 00383 00385 00386 00387 00388 virtual void startLevelYawRight(); 00389 virtual void stopLevelYawRight(); 00391 00393 00394 00395 virtual void startLevelPitchUp(); 00396 virtual void stopLevelPitchUp(); 00398 00400 00401 00402 virtual void startLevelPitchDown(); 00403 virtual void stopLevelPitchDown(); 00405 00407 00408 00409 virtual void startLevelRollLeft(); 00410 virtual void stopLevelRollLeft(); 00412 00414 00415 00416 virtual void startLevelRollRight(); 00417 virtual void stopLevelRollRight(); 00419 00420 virtual void rotateLevelYawLeft( double rads ); 00421 virtual void rotateLevelYawRight( double rads ); 00422 00423 virtual void startLookLeft(); 00424 virtual void stopLookLeft(); 00425 virtual void lookLeft( double rads ); 00426 00427 virtual void startLookRight(); 00428 virtual void stopLookRight(); 00429 virtual void lookRight( double rads ); 00430 00431 virtual void startLookUp(); 00432 virtual void stopLookUp(); 00433 virtual void lookUp( double rads ); 00434 00435 virtual void startLookDown(); 00436 virtual void stopLookDown(); 00437 virtual void lookDown( double rads ); 00438 00439 virtual void startLookTiltRight(); 00440 virtual void stopLookTiltRight(); 00441 virtual void lookTiltRight( double rads ); 00442 00443 virtual void startLookTiltLeft(); 00444 virtual void stopLookTiltLeft(); 00445 virtual void lookTiltLeft( double rads ); 00446 00448 00449 00450 virtual void startOrbitingLeft(); 00451 virtual void stopOrbitingLeft(); 00452 virtual void orbitLeft( double rads ); 00454 00456 00457 00458 virtual void startOrbitingRight(); 00459 virtual void stopOrbitingRight(); 00460 virtual void orbitRight( double rads ); 00462 00464 00465 00466 virtual void startOrbitingUp(); 00467 virtual void stopOrbitingUp(); 00468 virtual void orbitUp( double rads ); 00470 00472 00473 00474 virtual void startOrbitingDown(); 00475 virtual void stopOrbitingDown(); 00476 virtual void orbitDown( double rads ); 00478 00480 virtual void setLocation( double x, double y, double z); 00481 00485 virtual void setAttachedLocation( double x, double y, double z ); 00486 00488 virtual void setOrientation( double psi, double theta, double phi ); 00489 00491 virtual void setOrientation( double x, double y, double z, double w); 00492 00494 virtual void setAttachedOrientation( double psi, double theta, double phi ); 00495 00498 void setLocalModelScalingEnabled( bool enabled ); 00499 00502 void setLocalModelScalingAmount( float amount ); 00503 00506 virtual void jumpTo( double x, double y, double z ); 00507 00509 virtual void jumpTo( DtUniqueID elementID ); 00510 00511 virtual void orientTo( double x, double y, double z ); 00512 00514 virtual void dragTerrain( double lastX, double lastY, double lastZ, 00515 double currX, double currY, double currZ ); 00516 00517 virtual void dragTerrain2( double myStartDragX, double myStartDragY, 00518 double myStartDragZ, int deltaMouseX, int deltaMouseY ); 00519 00520 virtual void dragGravityUp( double windowUnits ); 00521 virtual void dragGravityDown( double windowUnits ); 00522 virtual void dragGravityLeft( double windowUnits ); 00523 virtual void dragGravityRight( double windowUnits ); 00524 virtual void scrollObserverForward( int wheelUnits ); 00525 virtual void scrollObserverBack( int wheelUnits ); 00526 virtual void scrollLevelObserverForward( int wheelUnits ); 00527 virtual void scrollLevelObserverBack( int wheelUnits ); 00528 00529 //{@ 00531 virtual void startIncreasingViewResolution(); 00532 virtual void stopIncreasingViewResolution(); 00533 virtual void increaseViewResolution(); 00534 00535 virtual void startDecreasingViewResolution(); 00536 virtual void stopDecreasingViewResolution(); 00537 virtual void decreaseViewResolution(); 00538 00539 // Sets the view resolution in meters per pixel. 00540 virtual void setViewResolution( double resolution); 00541 00542 // Get the current view resolution. 00543 virtual double viewResolution() const; 00544 00546 virtual void setViewMagnification( double mag ); 00547 00549 virtual double viewMagnification() const; 00550 00552 00553 // 00555 // 00556 00558 virtual void setOrbitSpeed( double speed ); 00559 00561 virtual void setLinearSpeed( double speed ); 00562 00564 virtual void setRotationSpeed( double speed ); 00565 00567 virtual void setMinLinearSpeed( double minSpeed ); 00568 00570 virtual void setLinearScaledSpeedGain( double gain ); 00571 00577 virtual void gotoTerrainCenter( DtUniqueID terrainPatch, bool retry ); 00578 00580 virtual void resetAttachment(); 00581 00582 virtual void resetOrientation(); 00583 00585 virtual void resetCamera(); 00586 virtual void level(); 00587 00588 virtual void stopAll(); 00589 00590 virtual void attachToObjects( const std::vector<DtUniqueID>& elementIds ); 00591 virtual void setSecondaryAttachment( const std::vector<DtUniqueID>& elementIds ); 00592 virtual void attachToPart( int partId); 00593 virtual void detach(); 00594 virtual void setAttachType( DtObserverObject::AttachType type ); 00595 virtual void setHideModelOnAttach( bool hide ); 00596 virtual void scaleCurrentAttachments( bool scaled ); 00597 virtual void setOrientToTargetConstraint( bool orient ); 00598 virtual void setOrbiting( bool orbit ); 00599 virtual void setOrientCameraToTargetConstraint( bool orient ); 00600 00601 virtual void setConstrainToTerrain( bool trueFalse ); 00602 virtual void setConstrainToCenter( bool trueFalse ); 00603 00606 virtual void suppressConstrainToTerrain( bool trueFalse ); 00607 00608 virtual void setSpeedScaling( bool trueFalse ); 00609 00611 virtual void setSpeedScaledSpeed( double speed ); 00612 00613 virtual void getLocation( double &x, double &y, double& z ) const; 00614 00615 virtual void getOrientation( double& psi, double& theta, double& phi ) const; 00616 00617 virtual void getOrientation( double& x, double& y, double& z, double& w ) const; 00618 00619 00623 virtual double fixed2DAltitude(); 00624 00627 virtual double heightAboveTerrainFromCurrentZoom(); 00628 00631 virtual double topographicHeading() const; 00632 00634 virtual void getLinearVelocity(double &x, double &y, double &z) const; 00635 00637 virtual void getRotationalVelocity( double& x, double& y, double& z) const; 00638 00642 virtual void setModeSetting( int setting, bool value ); 00643 00644 private: 00645 00647 DtOsgObserverObject( const DtOsgObserverObject& ); 00648 00650 DtOsgObserverObject& operator=( const DtOsgObserverObject& ); 00651 00652 protected: 00653 00654 00657 virtual double altitudeFromCurrentZoom(); 00658 00659 virtual void calcObserverWorldVectors(); 00660 virtual const osg::Vec3d& observerWorldUp() const; 00661 virtual const osg::Vec3d& observerWorldNorth() const; 00662 virtual const osg::Vec3d& observerWorldEast() const; 00663 00664 virtual const osg::Vec3d& attachedWorldUp() const; 00665 00666 virtual osg::Vec3d& observerUp(); 00667 virtual osg::Vec3d& observerFront(); 00668 virtual osg::Vec3d& observerRight(); 00669 00670 virtual osg::Vec3d& attachedUp(); 00671 virtual osg::Vec3d& attachedFront(); 00672 virtual osg::Vec3d& attachedRight(); 00673 00674 virtual osg::Vec3d& attachedOffsetUp(); 00675 virtual osg::Vec3d& attachedOffsetFront(); 00676 virtual osg::Vec3d& attachedOffsetRight(); 00677 00679 virtual osg::Vec3d& levelAttachedUp(); 00680 virtual osg::Vec3d& levelAttachedFront(); 00681 virtual osg::Vec3d& levelAttachedRight(); 00682 00684 virtual osg::Vec3d& levelObserverMimicUp(); 00685 virtual osg::Vec3d& levelObserverMimicFront(); 00686 virtual osg::Vec3d& levelObserverMimicRight(); 00687 00688 virtual osg::Vec3d& cameraUp(); 00689 virtual osg::Vec3d& cameraFront(); 00690 virtual osg::Vec3d& cameraRight(); 00691 00692 virtual osg::Vec3d& levelObserverUp(); 00693 virtual osg::Vec3d& levelObserverFront(); 00694 virtual osg::Vec3d& levelObserverRight(); 00695 00696 virtual void advanceOrbitLeft( double rads ); 00697 virtual void advanceOrbitRight( double rads ); 00698 virtual void advanceOrbitUp( double rads ); 00699 virtual void advanceOrbitDown( double rads ); 00700 00701 virtual void makeLevelObserverMatrix(); 00702 00704 virtual void calculateLevelAttachedRotation(); 00705 00707 virtual void makeLevelObserverMimicMatrix(); 00708 00712 virtual osg::Vec3d calcWorldPositionChange(); 00713 00714 virtual osg::Vec3d calcMimicPositionChange(); 00715 virtual osg::Vec3d calcFollowPositionChange(); 00716 virtual osg::Vec3d calcSpaceFollowPositionChange(); 00717 virtual osg::Vec3d calcTetherPositionChange(); 00718 virtual osg::Vec3d calcTetherTrackPositionChange(); 00719 virtual osg::Vec3d calcTrackPositionChange(); 00720 virtual osg::Quat calcTetherTrackRotation(); 00721 00722 virtual osg::Quat calcWorldOrientationChange(); 00723 virtual osg::Quat calcTetherOrientationChange(); 00724 virtual osg::Quat calcMimicOrientationChange(); 00725 virtual osg::Quat calcFollowOrientationChange(); 00726 00727 virtual void setCurrentAttachmentsVisibility( bool visible ); 00728 00735 00738 virtual void orientTo( const osg::Vec3d& target ); 00739 00741 virtual void orientCameraTo( const osg::Vec3d& target ); 00742 00743 virtual TerrainResult getTerrainCenter( const DtUniqueID& patchID, osg::Vec3d& center ); 00744 00745 virtual DtCoordinateConverter& coordinateConverter(); 00746 virtual const DtCoordinateConverter& coordinateConverter() const; 00747 00748 virtual void initializeAttachment(); 00749 00750 virtual void getScalingIntersection(); 00751 virtual void getViewIntersection(); 00752 00754 virtual double linearSpeed(); 00755 00757 virtual double speedScalingGain() const; 00758 00759 virtual void calcTerrainConstraint( osg::Vec3d prev ); 00760 00766 virtual bool updateAttachPositionAndOrientation(); 00767 00768 virtual bool getSecondaryAttachPosition( osg::Vec3d& position ); 00769 00770 virtual void getObserverOffsetVector( double& x, double& y, double& z ) const; 00771 virtual void setObserverOffsetVector( double x, double y, double z ); 00772 00773 virtual void getAttachedRotationOffset( double& x, double& y, double& z, double& w ) const; 00774 virtual void setAttachedRotationOffset( double x, double y, double z, 00775 double w ); 00776 00777 virtual void getBoundingVolume( DtSceneObject& sceneObject, 00778 osg::Vec3& bvolExtents, osg::Vec3d& bvolCenter ); 00779 00780 virtual void getBoundingVolume( DtTerrainPatchObject& patchObject, 00781 osg::Vec3& bvolExtents, osg::Vec3d& bvolCenter ); 00782 00783 virtual void setLocation( const osg::Vec3d& location, bool suppress=true ); 00784 00785 virtual bool isMoving() const; 00786 virtual bool isRotating() const; 00787 00788 virtual double computeNearClipDistance( DtSceneObject* sceneObject ); 00789 virtual float computeLocalModelScalingAmount( DtSceneObject* sceneObject ); 00790 00792 static void matrixdToTaitBryan( const osg::Matrixd& mat, DtTaitBryan& tb, bool isWorld2D = false ); 00793 static double clampUnity( double x ); 00794 00795 virtual void calcScaledSpeed(); 00796 virtual bool getTerrainOrPropIntersection( const osg::Vec3d& startPos, 00797 const osg::Vec3d& endPos, osg::Vec3d& result ) const; 00798 00800 virtual DtSceneObject* findSceneObjectFromElement(const DtElementID& id); 00801 00803 virtual DtTerrainPatchObject* findTerrainPatchObjectFromElement( const DtElementID& id ); 00804 00805 virtual void getPositionAndOrientation( DtSceneObject& sceneObject, osg::Vec3d& position, 00806 osg::Vec3d& orientToPosition, osg::Quat& orientation ); 00807 00808 virtual void getPositionAndOrientation( DtTerrainPatchObject& patchObject, osg::Vec3d& position, 00809 osg::Vec3d& orientToPosition, osg::Quat& orientation ); 00810 00812 virtual void getPositionFromSceneObject( DtSceneObject& sceneObject, osg::Vec3d& position ) const; 00813 00816 virtual bool getPartPositionOriFromSceneObject( DtSceneObject& sceneObject, 00817 int partId, osg::Vec3d& position, osg::Quat& ori ) const; 00818 00821 virtual void force2D(); 00822 00824 virtual void dimensionChanged( bool is2D ); 00825 virtual void setIs2D( bool is2D ); 00826 00828 virtual double calculate3DAltitude() const; 00829 00831 virtual void calculateAltitude(); 00832 00835 virtual double zoomFromCurrentAltitude(); 00836 00839 virtual double zoomFromAltitude( double altitude ); 00840 00843 virtual double zoomFromHeightAboveTerrain( double hat ); 00844 00845 virtual double calcEarthRadiusAtLocalCoord( const osg::Vec3d& local ) const; 00846 00847 // Sends the location of the observer on the master to all others; only used 00848 // if different 00849 virtual void synchronizeLocation( double x, double y, double z ); 00850 00851 // Sends the orientation of the observer on the master to all others; only used 00852 // if different 00853 virtual void synchronizeOrientation( double x, double y, double z, double w ); 00854 00855 protected: 00856 00857 static const double theZoomAltitudeConstant; 00858 static const double theObserverBoundingSphere; 00859 static const double theSpeedScaleUpdatePeriod; 00860 00861 static const double theMaxTerrainRetryTime; 00862 00863 // below this altitude, ignore myConstrainToCenter 00864 static const double theCenterConstrainHeight; 00865 00866 // Zoom won't get any smaller than this 00867 static const double theMinViewResolution; 00868 00869 // Zoom won't get any larger than this 00870 static const double theMaxViewResolution; 00871 00872 00873 protected: 00874 00875 std::vector<DtUniqueID> myCurrentAttachments; 00876 std::vector<DtUniqueID> mySecondaryAttachments; 00877 int myPartAttachment; 00878 00879 bool myChanged; 00880 double myLastTickTime; 00881 00882 // 00884 // 00886 osg::Vec3d myObserverPositionVector; 00887 osg::Vec3d myLastSpeedPositionVector; 00888 osg::Vec3d myMasterPositionVector; 00889 bool mySyncPending; 00890 bool mySyncSuppressed; 00891 osg::Vec3d myObserverLinearVelocityVector; 00892 osg::Vec3d myObserverRotationalVelocityVector; 00893 00894 bool myLocalModelScalingEnabled; 00895 float myLocalModelScalingAmount; 00896 00898 osg::Vec3d myObserverOffsetVector; 00899 00901 osg::Vec3d mySavedObserverOffsetVector; 00902 00904 osg::Vec3d myObserverPosition; 00905 00907 osg::Vec3d myLevelObserverPosition; 00908 00909 osg::Vec3d myAttachedPosition; 00910 00911 osg::Vec3d myLevelAttachedPosition; 00912 00914 osg::Vec3d myDragMove; 00915 00916 osg::Vec3d myOrientToPosition; 00917 00918 osg::Vec3d myOrbitAdvance; 00919 00924 double myCurrentObserverDistance; 00925 00927 osg::Quat myAttachedRotationOffset; 00928 00930 osg::Quat myObserverRotation; 00931 osg::Quat myMasterRotation; 00932 00934 osg::Quat mySavedObserverRotation; 00935 00939 osg::Quat myPreviousAttachedObserverRotation; 00940 00941 osg::Quat myAttachedRotation; 00942 osg::Quat myLevelAttachedRotation; 00943 00944 osg::Matrixd myLevelObserverMimicRotationMatrix; 00945 osg::Matrixd myLevelObserverRotationMatrix; 00946 00947 osg::Vec3d my2DTo3DCachedObserverOffsetVector; 00948 osg::Quat my2DTo3DCachedRotation; 00949 00953 00954 //bool myGlobeObserverMode; 00955 double myCurrentRadius; 00956 bool myConstrainToCenter; 00957 00960 00961 class MotionState 00962 { 00963 public: 00964 00965 enum Direction 00966 { 00967 Stopped = 0, 00968 Forward = 1, 00969 Backward = 2, 00970 Left = 4, 00971 Right = 8, 00972 Up = 16, 00973 Down = 32 00974 }; 00975 00976 MotionState() 00977 : myState(Stopped) 00978 { 00979 } 00980 00982 inline void applyMovement(double linearDistance) 00983 { 00984 if(moving(Right)) myAdvance[0] += linearDistance; 00985 if(moving(Left)) myAdvance[0] -= linearDistance; 00986 if(moving(Forward)) myAdvance[1] += linearDistance; 00987 if(moving(Backward)) myAdvance[1] -= linearDistance; 00988 if(moving(Up)) myAdvance[2] += linearDistance; 00989 if(moving(Down)) myAdvance[2] -= linearDistance; 00990 } 00991 00993 inline const osg::Vec3d& advance() const 00994 { 00995 return myAdvance; 00996 } 00997 00998 inline void stop() 00999 { 01000 myState = Stopped; 01001 myAdvance.set(0.0,0.0,0.0); 01002 myEuler.set(0.0,0.0,0.0); 01003 } 01004 01005 inline void clearAdvance() 01006 { 01007 myAdvance.set(0.0,0.0,0.0); 01008 } 01009 01010 inline bool stopped() 01011 { 01012 return myState == Stopped; 01013 } 01014 01015 inline bool moving() const 01016 { 01017 return myState != Stopped; 01018 } 01019 01020 inline bool moving(Direction d) const 01021 { 01022 return (myState & d) != 0; 01023 } 01024 01025 inline void setMoving(Direction d, bool moving) 01026 { 01027 myState = moving ? myState | d : myState & ~d; 01028 } 01029 01030 enum Angle 01031 { 01032 YawLeft = 1, 01033 YawRight = 2, 01034 PitchUp = 4, 01035 PitchDown = 8, 01036 RollLeft = 16, 01037 RollRight = 32 01038 }; 01039 01040 inline void applyRotation(double angle) 01041 { 01042 if(rotating(YawRight)) myEuler[0] -= angle; 01043 if(rotating(YawLeft)) myEuler[0] += angle; 01044 if(rotating(PitchUp)) myEuler[1] += angle; 01045 if(rotating(PitchDown)) myEuler[1] -= angle; 01046 if(rotating(RollRight)) myEuler[2] += angle; 01047 if(rotating(RollLeft)) myEuler[2] -= angle; 01048 } 01049 01050 inline const osg::Vec3d& euler() const 01051 { 01052 return myEuler; 01053 } 01054 01055 inline osg::Vec3d& euler() 01056 { 01057 return myEuler; 01058 } 01059 01060 inline void level() 01061 { 01062 myEuler.set(0.0,0.0,0.0); 01063 } 01064 01065 inline bool rotating() const 01066 { 01067 return myState != Stopped; 01068 } 01069 01070 inline bool rotating( Angle d ) const 01071 { 01072 return (myState & d) != 0; 01073 } 01074 01075 inline void setRotating( Angle d, bool rotating ) 01076 { 01077 myState = rotating ? myState | d : myState & ~d; 01078 } 01079 01080 protected: 01081 01085 osg::Vec3d myAdvance; 01086 osg::Vec3d myEuler; 01087 01088 unsigned char myState; 01089 }; 01090 01091 MotionState myObserverState; 01092 MotionState myLevelObserverState; 01093 MotionState myAttachedObserverState; 01094 MotionState myLevelAttachedObserverState; 01095 01096 MotionState myRotatingState; 01097 MotionState myRotatingLevelState; 01098 MotionState myAbsoluteRotatingState; 01099 MotionState myAbsoluteLevelRotatingState; 01100 01101 bool myOrbitingLeft; 01102 bool myOrbitingRight; 01103 bool myOrbitingUp; 01104 bool myOrbitingDown; 01105 01106 double myOrbitSpeed; 01107 double myLinearSpeed; 01108 double myRotationSpeed; 01109 01111 double myMaxLinearSpeed; 01112 double myMinLinearSpeed; 01113 double myLinearScaledSpeedGain; 01114 double mySpeedScaleSpeed; 01115 01116 double mySceneCenterOffsetX; 01117 double mySceneCenterOffsetY; 01118 double mySceneCenterOffsetZ; 01119 01120 // 01123 bool myLookingRight; 01124 bool myLookingLeft; 01125 bool myLookingUp; 01126 bool myLookingDown; 01127 bool myLookingTiltRight; 01128 bool myLookingTiltLeft; 01129 01132 osg::Quat myFinalCameraRotation; 01133 01136 osg::Vec3d myFinalCameraPositionVector; 01137 01139 osg::Vec3d myCameraOffset; 01141 osg::Quat myCameraRotation; 01142 01143 osg::Vec3d myObserverWorldUp; 01144 osg::Vec3d myObserverWorldNorth; 01145 osg::Vec3d myObserverWorldEast; 01146 01147 osg::Vec3d myAttachedWorldUp; 01148 osg::Vec3d myAttachedWorldNorth; 01149 osg::Vec3d myAttachedWorldEast; 01150 01151 osg::Vec3d myObserverUp; 01152 osg::Vec3d myObserverFront; 01153 osg::Vec3d myObserverRight; 01154 01155 osg::Vec3d myLevelObserverUp; 01156 osg::Vec3d myLevelObserverFront; 01157 osg::Vec3d myLevelObserverRight; 01158 01159 osg::Vec3d myAttachedUp; 01160 osg::Vec3d myAttachedFront; 01161 osg::Vec3d myAttachedRight; 01162 01163 osg::Vec3d myLevelAttachedUp; 01164 osg::Vec3d myLevelAttachedFront; 01165 osg::Vec3d myLevelAttachedRight; 01166 01167 osg::Vec3d myLevelObserverMimicUp; 01168 osg::Vec3d myLevelObserverMimicFront; 01169 osg::Vec3d myLevelObserverMimicRight; 01170 01171 osg::Vec3d myAttachedOffsetUp; 01172 osg::Vec3d myAttachedOffsetFront; 01173 osg::Vec3d myAttachedOffsetRight; 01174 01175 osg::Vec3d myCameraUp; 01176 osg::Vec3d myCameraFront; 01177 osg::Vec3d myCameraRight; 01178 01179 DtObserverObject::AttachType myAttachType; 01180 DtObserverObject::AttachType my3DAttachType; 01181 01182 bool myHideModelOnAttach; 01183 bool mySpeedScaling; 01184 double mySpeedScalingTimer; 01185 01186 bool myConstrainToTerrain; 01187 01189 bool myInternalSuppressConstrainToTerrain; 01190 01192 bool myExternalSuppressConstrainToTerrain; 01193 01198 int myOrientToTargetConstraint; 01199 bool myOrientCameraToTargetConstraint; 01200 bool myOrientToOnReset; 01201 bool myOrbiting; 01202 // force an orientation reset AFTER the next time the observer position is updated 01203 // Needed when making large attach jumps 01204 bool myForceOrientReset; 01205 01206 bool myHaveTerrainPivot; 01207 01208 bool myHaveViewIntersect; 01209 osg::Vec3d myViewIntersect; 01210 01211 bool myHaveDownIntersect; 01212 // set to false on reset 01213 bool myHaveDownIntersectEver; 01214 osg::Vec3d myDownIntersect; 01215 01216 osg::Vec3d myAttachPosition; 01217 01218 double myLastAttachedBvolDiameter; 01219 01221 osg::Vec3d myPreviousPositionVector; 01222 osg::Vec3d myPreviousOffsetVector; 01223 01224 double myAltitude; 01225 01227 bool myViewResolutionIncreasingState; 01228 bool myViewResolutionDecreasingState; 01229 double myViewResolution; 01230 01232 double myViewMagnification; 01233 double myLastViewMagnification; 01234 01235 typedef boost::unordered_map<DtElementID, bool> ElementVisibilityMap; 01236 ElementVisibilityMap myPendingVisibilityState; 01237 01238 // Paged terrain initialization 01239 bool myGotoTerrainCenterPending; 01240 double myNextGotoTerrainCenterTime; 01241 double myStartGotoTerrainCenterTime; 01242 DtUniqueID myPendingTerrainPatchId; 01243 osg::Vec3d myPreviousTerrainCenter; 01244 01245 // curvature adjustment 01246 double myCurvatureAdjustment; 01247 01248 }; 01249 01250 }