00001 /*======================================================================= 00002 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00003 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00004 *** *** 00005 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00006 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00007 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00008 *** *** 00009 *** RESTRICTED RIGHTS LEGEND *** 00010 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00011 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00012 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00013 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00014 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00015 *** *** 00016 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : T.MEHAMLI (Jun 2007) 00022 **=======================================================================*/ 00023 00024 #ifndef SO_GUI_CONSTRAINED_VIEWER 00025 #define SO_GUI_CONSTRAINED_VIEWER 00026 00028 // 00029 // Class: SoGuiConstrainedViewer 00030 // 00031 // SoXXViewer implementation class 00032 // 00033 // 00035 00036 #include <Inventor/Gui/viewers/SoGuiFullViewer.h> 00037 00038 #ifndef HIDDEN_FROM_DOC 00039 // Defines 00040 # define MIN_ANGLE ( 5*M_PI/180. ) // minimum angle between look at 00041 // direction and up direction (in rad) 00042 #endif 00043 00044 00045 class SoGuiConstrainedViewer : public SoGuiFullViewer 00046 { 00047 #ifndef HIDDEN_FROM_DOC 00048 SO_FIELDCONTAINER_HEADER( SoGuiConstrainedViewer ); 00049 #endif 00050 00051 private: 00055 SoGuiConstrainedViewer(); 00056 00062 void setUpDirection( const SbVec3f& newUpDirection ); 00063 00067 SbVec3f getUpDirection(); 00068 00069 // Accessor and mutator for the member m_sceneSize; 00070 void setSceneSize( float size ); 00071 float getSceneSize () const; 00072 00073 // Accessor and mutator for the member m_sceneHeight; 00074 void setSceneHeight( float height ); 00075 float getSceneHeight () const; 00076 00077 // ----------------------- Extension usage ----------------------------------- 00078 00079 // 00080 // redefine these to add constrained viewer functionality 00081 // 00082 virtual void setCamera( SoCamera* newCam ); 00083 virtual void saveHomePosition(); 00084 virtual void resetToHomePosition(); 00085 virtual void recomputeSceneSize(); 00086 00087 // Tilts the camera, restraining it to 180 degree rotation from the 00088 // up direction. A positive angle tilts the camera up. 00089 virtual void tiltCamera( float deltaAngle ); 00090 00091 // Moves the camera forward by the given amount 00092 virtual void dollyCamera( float dist ); 00093 00094 // Redefine these to do constrained viewing tasks. 00095 // The bottom wheel rotates the camera around the up direction, the 00096 // left wheel tilts the camera up/down constraning to 180 degree from 00097 // the up direction. The right wheel moves the camera forward/backward 00098 // withough constrain (taking the scene size into account). 00099 virtual void bottomWheelMotion( float newVal ); 00100 virtual void leftWheelMotion( float newVal ); 00101 virtual void rightWheelMotion( float newVal ); 00102 virtual void mouseWheelMotion( float newVal ); 00103 00104 // This is called during a paste. 00105 // We redefine this to keep the right vector of the camera 00106 // in a parallel plane. 00107 virtual void changeCameraValues( SoCamera* newCamera ); 00108 00109 // this routine is called by subclasses to find and set the new 00110 // up direction given the current mouse position. If something is 00111 // picked, the normal to the object picked will be used to specify 00112 // the new up direction. 00113 void findUpDirection( const SbVec2s& mouseLocation ); 00114 00115 // this routine checks the camera orientation and makes sure that the 00116 // current right vector and the ideal right vector (cross between the 00117 // view vector and world up direction) are the same (i.e. no unwanted 00118 // roll), else it fixes it. This keeps the up direction valid. 00119 void checkForCameraUpConstrain(); 00120 00121 // Redefine this to keep the up vector when seeking 00122 virtual void computeSeekFinalOrientation(); 00123 00124 private: 00128 virtual ~SoGuiConstrainedViewer(); 00129 00130 // ----------------------- Private usage ------------------------------------- 00131 00132 private: 00133 00134 SbVec3f m_origUpDirection; // used to save/reset 00135 SbVec3f m_upDirection; 00136 float m_sceneHeight; 00137 00138 float m_sceneSize; 00139 }; 00140 00141 #endif // SO_GUI_CONSTRAINED_VIEWER 00142 00143