Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gfx/TrackballManipulator

Go to the documentation of this file.
00001 /* **-*-c++-*-**************************************************************
00002  * This was ripped from OSG and modified.
00003  *
00004  * OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield 
00005  *
00006  * This library is open source and may be redistributed and/or modified under  
00007  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
00008  * (at your option) any later version.  The full license is in LICENSE file
00009  * included with this distribution, and on the openscenegraph.org website.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00014  * OpenSceneGraph Public License for more details.
00015 */
00016 
00017 #ifndef GFX_TRACKBALLMANIPULATOR
00018 #define GFX_TRACKBALLMANIPULATOR 
00019 
00020 #include <gfx/gfx>
00021 
00022 #include <osgGA/MatrixManipulator>
00023 #include <osg/Quat>
00024 
00025 namespace gfx {
00026 
00027 class TrackballManipulator : public osgGA::MatrixManipulator
00028 {
00029     public:
00030 
00031         TrackballManipulator();
00032 
00033         virtual const char* className() const { return "TrackballManipulator"; }
00034 
00035         /** set the position of the matrix manipulator using a 4x4 Matrix.*/
00036         virtual void setByMatrix(const osg::Matrixd& matrix);
00037 
00038         /** set the position of the matrix manipulator using a 4x4 Matrix.*/
00039         virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
00040 
00041         /** get the position of the manipulator as 4x4 Matrix.*/
00042         virtual osg::Matrixd getMatrix() const;
00043 
00044         /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
00045         virtual osg::Matrixd getInverseMatrix() const;
00046 
00047         /** Get the FusionDistanceMode. Used by SceneView for setting up setereo convergence.*/
00048         virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE; }
00049 
00050         /** Get the FusionDistanceValue. Used by SceneView for setting up setereo convergence.*/
00051         virtual float getFusionDistanceValue() const { return _distance; }
00052 
00053         /** Attach a node to the manipulator. 
00054             Automatically detaches previously attached node.
00055             setNode(NULL) detaches previously nodes.
00056             Is ignored by manipulators which do not require a reference model.*/
00057         virtual void setNode(osg::Node*);
00058 
00059         /** Return node if attached.*/
00060         virtual const osg::Node* getNode() const;
00061 
00062         /** Return node if attached.*/
00063         virtual osg::Node* getNode();
00064 
00065         /** Move the camera to the default position. 
00066             May be ignored by manipulators if home functionality is not appropriate.*/
00067         virtual void home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
00068 
00069         void setModelScale(float scale) { _modelScale = scale; }
00070         
00071         /** Start/restart the manipulator.*/
00072         virtual void init(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
00073 
00074         /** handle events, return true if handled, false otherwise.*/
00075         virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
00076 
00077         /** Get the keyboard and mouse usage of this manipulator.*/
00078         virtual void getUsage(osg::ApplicationUsage& usage) const;
00079 
00080         void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
00081     protected:
00082 
00083         virtual ~TrackballManipulator();
00084 
00085         /** Reset the internal GUIEvent stack.*/
00086         void flushMouseEventStack();
00087         /** Add the current mouse GUIEvent to internal stack.*/
00088         void addMouseEvent(const osgGA::GUIEventAdapter& ea);
00089 
00090         /** For the give mouse movement calculate the movement of the camera.
00091             Return true is camera has moved and a redraw is required.*/
00092         bool calcMovement();
00093         
00094         void trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y);
00095         float tb_project_to_sphere(float r, float x, float y);
00096 
00097 
00098         /** Check the speed at which the mouse is moving.
00099             If speed is below a threshold then return false, otherwise return true.*/
00100         bool isMouseMoving();
00101 
00102         // Internal event stack comprising last three mouse events.
00103         osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t1;
00104         osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t0;
00105 
00106         osg::ref_ptr<osg::Node>       _node;
00107 
00108         float _modelScale;
00109         float _minimumZoomScale;
00110 
00111         bool _thrown;
00112         
00113         osg::Vec3   _center;
00114         osg::Quat   _rotation;
00115         float       _distance;
00116 
00117 };
00118 
00119 } // gfx
00120 
00121 #endif
00122 

Generated on Thu Jul 29 15:56:19 2004 for OpenSim by doxygen 1.3.6