AnimatLab  2
Test
OsgTrackballManipulator.h
1 #pragma once
2 
3 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
4  *
5  * This library is open source and may be redistributed and/or modified under
6  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
7  * (at your option) any later version. The full license is in LICENSE file
8  * included with this distribution, and on the openscenegraph.org website.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * OpenSceneGraph Public License for more details.
14 */
15 
16 #include <osgGA/CameraManipulator>
17 #include <osg/Quat>
18 
19 namespace OsgAnimatSim
20 {
21  namespace Visualization
22  {
23 
24 class ANIMAT_OSG_PORT OsgTrackballManipulator : public osgGA::CameraManipulator
25 {
26  public:
28 
29  virtual const char* className() const { return "Trackball"; }
30 
32  virtual void setByMatrix(const osg::Matrixd& matrix);
33 
35  virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
36 
38  virtual osg::Matrixd getMatrix() const;
39 
41  virtual osg::Matrixd getInverseMatrix() const;
42 
44  virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE; }
45 
47  virtual float getFusionDistanceValue() const { return _distance; }
48 
53  virtual void setNode(osg::Node*);
54 
56  virtual const osg::Node* getNode() const;
57 
59  virtual osg::Node* getNode();
60 
63  virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
64  virtual void home(double);
65 
67  virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
68 
70  virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
71 
73  virtual void getUsage(osg::ApplicationUsage& usage) const;
74 
75 
78  void setMinimumZoomScale(double minimumZoomScale) { _minimumZoomScale=minimumZoomScale; }
79 
81  double getMinimumZoomScale() const { return _minimumZoomScale; }
82 
84  void setCenter(const osg::Vec3d& center) { _center = center; }
85 
87  const osg::Vec3d& getCenter() const { return _center; }
88 
90  void setRotation(const osg::Quat& rotation) { _rotation = rotation; }
91 
93  const osg::Quat& getRotation() const { return _rotation; }
94 
96  void setDistance(double distance) { _distance = distance; }
97 
99  double getDistance() const { return _distance; }
100 
102  void setTrackballSize(float size);
103 
105  float getTrackballSize() const { return _trackballSize; }
106  protected:
107 
108  virtual ~OsgTrackballManipulator();
109 
111  void flushMouseEventStack();
113  void addMouseEvent(const GUIEventAdapter& ea);
114 
115  void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
116 
119  bool calcMovement();
120 
121  void trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y);
122  float tb_project_to_sphere(float r, float x, float y);
123 
124 
127  bool isMouseMoving();
128 
129  // Internal event stack comprising last two mouse events.
130  osg::ref_ptr<const GUIEventAdapter> _ga_t1;
131  osg::ref_ptr<const GUIEventAdapter> _ga_t0;
132 
133  osg::ref_ptr<osg::Node> _node;
134 
135  double _modelScale;
136  double _minimumZoomScale;
137 
138  bool _thrown;
139 
140  osg::Vec3d _center;
141  osg::Quat _rotation;
142  double _distance;
143  float _trackballSize;
144 
145 };
146 
147 
148 
149  } // Visualization
150 }
virtual void setByInverseMatrix(const osg::Matrixd &matrix)
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const