AGX Dynamics  2.37.3.2
SCCameraManipulator.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 
18 #ifndef AGXOSG_SCCAMERA_MANIPULATOR
19 #define AGXOSG_SCCAMERA_MANIPULATOR
20 
21 #include <agxOSG/export.h>
22 
23 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
24 #include <osgGA/StandardManipulator>
25 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
26 
27 #ifdef _MSC_VER
28 # pragma warning(push)
29 # pragma warning( disable : 4251 ) // warning C4251: non dll-interface class
30 #endif
31 
32 namespace agxOSG {
33 
34 
38  class AGXOSG_EXPORT SCCameraManipulator : public osgGA::StandardManipulator
39  {
40 
41  typedef osgGA::StandardManipulator inherited;
42 
43  public:
44 
45  SCCameraManipulator(int flags = DEFAULT_SETTINGS);
47  const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
48 
49  META_Object(agxOSG, SCCameraManipulator);
50 
51  virtual void setByMatrix( const osg::Matrixd& matrix );
52  virtual void setByInverseMatrix( const osg::Matrixd& matrix );
53  virtual osg::Matrixd getMatrix() const;
54  virtual osg::Matrixd getInverseMatrix() const;
55 
56  virtual void setTransformation( const osg::Vec3d& eye, const osg::Quat& rotation );
57  virtual void setTransformation( const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up );
58  virtual void getTransformation( osg::Vec3d& eye, osg::Quat& rotation ) const;
59  virtual void getTransformation( osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up ) const;
60 
61  virtual void setCenter( const osg::Vec3d& center );
62  const osg::Vec3d& getCenter() const;
63  virtual void setRotation( const osg::Quat& rotation );
64  const osg::Quat& getRotation() const;
65  virtual void setDistance( double distance );
66  double getDistance() const;
67 
68  virtual void setTrackballSize( const double& size );
69  inline double getTrackballSize() const;
70  virtual void setWheelZoomFactor( double wheelZoomFactor );
71  inline double getWheelZoomFactor() const;
72 
73  virtual void setMinimumDistance( const double& minimumDistance, bool relativeToModelSize = false );
74  double getMinimumDistance( bool *relativeToModelSize = nullptr ) const;
75 
76  virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const;
77  virtual float getFusionDistanceValue() const;
78 
79  protected:
80 
81  virtual bool handleMousePush(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
82 
83  virtual bool handleMouseWheel( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
84 
85  virtual bool performMovementLeftMouseButton( const double eventTimeDelta, const double dx, const double dy );
86  virtual bool performMovementMiddleMouseButton( const double eventTimeDelta, const double dx, const double dy );
87  virtual bool performMovementRightMouseButton( const double eventTimeDelta, const double dx, const double dy );
88  virtual bool performMouseDeltaMovement( const float dx, const float dy );
89  virtual void applyAnimationStep( const double currentProgress, const double prevProgress );
90 
91  bool handleKeyDown(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
92  bool handleKeyUp(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
93  bool setCenterByMousePointerIntersection(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
94 
95 
96  virtual void rotateTrackball( const float px0, const float py0,
97  const float px1, const float py1, const float scale );
98 
99  bool rotate(const double eventTimeDelta, const double dx, const double dy);
100  virtual void rotateWithFixedVertical( const float dx, const float dy );
101  virtual void rotateWithFixedVertical( const float dx, const float dy, const osg::Vec3f& up );
102  virtual void panModel( const float dx, const float dy, const float dz = 0.f );
103  virtual void zoomModel( const float dy, bool pushForwardIfNeeded = true );
104  void trackball( osg::Vec3d& axis, float& angle, float p1x, float p1y, float p2x, float p2y );
105  float tb_project_to_sphere( float r, float x, float y );
106  virtual bool startAnimationByMousePointerIntersection( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
107 
110  double _distance;
111 
114 
118 
120 
121  class OrbitAnimationData : public AnimationData {
122  public:
124  void start( const osg::Vec3d& movement, const double startTime );
125  };
126  virtual void allocAnimationData() { _animationData = new OrbitAnimationData(); }
127  };
128 
129 
130  //
131  // inline functions
132  //
133 
135  inline double SCCameraManipulator::getTrackballSize() const { return _trackballSize; }
137  inline double SCCameraManipulator::getWheelZoomFactor() const { return _wheelZoomFactor; }
138 
139 }
140 
141 #ifdef _MSC_VER
142 # pragma warning(pop)
143 #endif
144 
145 
146 
147 #endif
double getTrackballSize() const
Get the size of the trackball relative to the model size.
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
#define AGXOSG_EXPORT
Vec3T< Real64 > Vec3d
Definition: Vec3.h:40
AGXMODEL_EXPORT agx::Vec3 getCenter(const agxCollide::Mesh::Triangle &triangle)
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
SCCameraManipulator is base class for camera control based on focal center, distance from the center...
QuatT< Real > Quat
Definition: Quat.h:24
Vec3T< Real32 > Vec3f
Definition: Vec3.h:39
double getWheelZoomFactor() const
Get the mouse wheel zoom factor.