OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
ViewManipulator.h
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12 *
13 * ViewManipulator code Copyright (C) 2010 PCJohn (Jan Peciva)
14 * while some pieces of code were taken from OSG.
15 * Thanks to company Cadwork (www.cadwork.ch) and
16 * Brno University of Technology (www.fit.vutbr.cz) for open-sourcing this work.
17*/
18
19#ifndef OSGGA_VIEW_MANIPULATOR
20#define OSGGA_VIEW_MANIPULATOR 1
21
22#include <osgGA/StandardManipulator>
23#include <osgViewer/View>
24
25namespace osgGA {
26
27
31 class ViewManipulator : public StandardManipulator
32 {
33 typedef StandardManipulator inherited;
34
35 public:
36
37 ViewManipulator(int flags = DEFAULT_SETTINGS);
39 const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY);
40
41 //META_Object(osgGA, ViewManipulator);
42
43 virtual void setByMatrix(const osg::Matrixd& matrix);
44 virtual void setByInverseMatrix(const osg::Matrixd& matrix);
45 virtual osg::Matrixd getMatrix() const;
46 virtual osg::Matrixd getInverseMatrix() const;
47
48 virtual void setTransformation(const osg::Vec3d& eye, const osg::Quat& rotation);
49 virtual void setTransformation(const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up);
50 virtual void getTransformation(osg::Vec3d& eye, osg::Quat& rotation) const;
51 virtual void getTransformation(osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up) const;
52
53 void setHeading(double azimuth);
54 double getHeading() const;
55 void setElevation(double elevation);
56 double getElevation() const;
57
58 virtual void setCenter(const osg::Vec3d& center);
59 const osg::Vec3d& getCenter() const;
60 virtual void setRotation(const osg::Quat& rotation);
61 const osg::Quat& getRotation() const;
62 virtual void setDistance(double distance);
63 double getDistance() const;
64
65 virtual void setTrackballSize(const double& size);
66 inline double getTrackballSize() const;
67 virtual void setWheelZoomFactor(double wheelZoomFactor);
68 inline double getWheelZoomFactor() const;
69
70 virtual void setMinimumDistance(const double& minimumDistance, bool relativeToModelSize = false);
71 double getMinimumDistance(bool *relativeToModelSize = NULL) const;
72
73 virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const;
74 virtual float getFusionDistanceValue() const;
75
76 void setHandleMouseMovement(bool flag) { handleMouseMovement = flag; }
77
78 protected:
79
80 virtual bool handleMouseWheel(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
81
82 virtual bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy);
83 virtual bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy);
84 virtual bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy);
85 virtual bool performMouseDeltaMovement(const float dx, const float dy);
86 virtual void applyAnimationStep(const double currentProgress, const double prevProgress);
87
88 virtual void rotateTrackball(const float px0, const float py0,
89 const float px1, const float py1, const float scale);
90 virtual void rotateWithFixedVertical(const float dx, const float dy);
91 virtual void rotateWithFixedVertical(const float dx, const float dy, const osg::Vec3f& up);
92 virtual void panModel(const float dx, const float dy, const float dz = 0.f);
93 virtual void zoomModel(const float dy, bool pushForwardIfNeeded = true);
94 void trackball(osg::Vec3d& axis, float& angle, float p1x, float p1y, float p2x, float p2y);
95 float tb_project_to_sphere(float r, float x, float y);
96 virtual bool startAnimationByMousePointerIntersection(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
97
98 osg::Vec3d _center;
99 osg::Quat _rotation;
100 double _distance;
101
104
107
109
110 class OrbitAnimationData : public AnimationData {
111 public:
112 osg::Vec3d _movement;
113 void start(const osg::Vec3d& movement, const double startTime);
114 };
115 virtual void allocAnimationData() { _animationData = new OrbitAnimationData(); }
116 };
117
118
119
120 //
121 // inline functions
122 //
123
125 inline double ViewManipulator::getTrackballSize() const { return _trackballSize; }
128
129
130}
131
132#endif /* OSGGA_ORBIT_MANIPULATOR */
axis
Definition SourceTarget.h:5
Definition ViewManipulator.h:110
osg::Vec3d _movement
Definition ViewManipulator.h:112
void start(const osg::Vec3d &movement, const double startTime)
Definition ViewManipulator.cpp:380
Definition ViewManipulator.h:32
virtual float getFusionDistanceValue() const
Definition ViewManipulator.cpp:556
double _minimumDistance
Definition ViewManipulator.h:105
ViewManipulator(const ViewManipulator &om, const osg::CopyOp &copyOp=osg::CopyOp::SHALLOW_COPY)
virtual void allocAnimationData()
Definition ViewManipulator.h:115
virtual void setDistance(double distance)
Definition ViewManipulator.cpp:591
virtual void rotateWithFixedVertical(const float dx, const float dy)
Definition ViewManipulator.cpp:409
const osg::Vec3d & getCenter() const
Definition ViewManipulator.cpp:570
void setHandleMouseMovement(bool flag)
Definition ViewManipulator.h:76
virtual void rotateWithFixedVertical(const float dx, const float dy, const osg::Vec3f &up)
virtual void rotateTrackball(const float px0, const float py0, const float px1, const float py1, const float scale)
Definition ViewManipulator.cpp:393
virtual bool handleMouseWheel(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Definition ViewManipulator.cpp:227
virtual bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy)
Definition ViewManipulator.cpp:287
virtual osg::Matrixd getMatrix() const
Definition ViewManipulator.cpp:86
double _distance
Definition ViewManipulator.h:100
virtual void zoomModel(const float dy, bool pushForwardIfNeeded=true)
Definition ViewManipulator.cpp:444
static int _minimumDistanceFlagIndex
Definition ViewManipulator.h:106
virtual void setTransformation(const osg::Vec3d &eye, const osg::Quat &rotation)
Definition ViewManipulator.cpp:105
virtual bool startAnimationByMousePointerIntersection(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Definition ViewManipulator.cpp:358
double getElevation() const
Returns the elevation in radians.
Definition ViewManipulator.cpp:210
osg::Vec3d _center
Definition ViewManipulator.h:98
double getDistance() const
Definition ViewManipulator.cpp:598
virtual osg::Matrixd getInverseMatrix() const
Definition ViewManipulator.cpp:96
void trackball(osg::Vec3d &axis, float &angle, float p1x, float p1y, float p2x, float p2y)
Definition ViewManipulator.cpp:490
bool handleMouseMovement
Definition ViewManipulator.h:108
const osg::Quat & getRotation() const
Definition ViewManipulator.cpp:584
double getWheelZoomFactor() const
Definition ViewManipulator.h:127
double _trackballSize
Definition ViewManipulator.h:102
ViewManipulator(int flags=DEFAULT_SETTINGS)
Constructor.
Definition ViewManipulator.cpp:34
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const
Definition ViewManipulator.cpp:550
virtual void panModel(const float dx, const float dy, const float dz=0.f)
Definition ViewManipulator.cpp:427
virtual void setRotation(const osg::Quat &rotation)
Definition ViewManipulator.cpp:577
double getTrackballSize() const
Definition ViewManipulator.h:125
virtual void setByMatrix(const osg::Matrixd &matrix)
Definition ViewManipulator.cpp:67
osg::Quat _rotation
Definition ViewManipulator.h:99
virtual void setWheelZoomFactor(double wheelZoomFactor)
Definition ViewManipulator.cpp:624
virtual bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy)
Definition ViewManipulator.cpp:303
virtual void setByInverseMatrix(const osg::Matrixd &matrix)
Definition ViewManipulator.cpp:79
double getHeading() const
Returns the heading in radians.
Definition ViewManipulator.cpp:176
virtual void applyAnimationStep(const double currentProgress, const double prevProgress)
Definition ViewManipulator.cpp:333
virtual bool performMouseDeltaMovement(const float dx, const float dy)
Definition ViewManipulator.cpp:321
virtual void setTrackballSize(const double &size)
Definition ViewManipulator.cpp:605
void setElevation(double elevation)
Definition ViewManipulator.cpp:197
double _wheelZoomFactor
Definition ViewManipulator.h:103
virtual bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy)
Definition ViewManipulator.cpp:313
virtual void getTransformation(osg::Vec3d &eye, osg::Quat &rotation) const
Definition ViewManipulator.cpp:117
double getMinimumDistance(bool *relativeToModelSize=NULL) const
Definition ViewManipulator.cpp:641
virtual void setMinimumDistance(const double &minimumDistance, bool relativeToModelSize=false)
Definition ViewManipulator.cpp:632
float tb_project_to_sphere(float r, float x, float y)
Definition ViewManipulator.cpp:530
void setHeading(double azimuth)
Definition ViewManipulator.cpp:163
virtual void setCenter(const osg::Vec3d &center)
Definition ViewManipulator.cpp:563
Definition Viewer.h:29