CEDRIC  Revision_backup-2009-02
MyCameraManipulator.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright (C) 2008 Boris Iven, Max Hermann
4  *
5  * This file is part of the "CEDRIC Event Display" application.
6  *
7  *****************************************************************************/
8 
9 #ifndef MYCAMERAMANIPULATOR_H
10 #define MYCAMERAMANIPULATOR_H
11 
12 #include <osgGA/MatrixManipulator>
13 #include <osg/Quat>
14 #include <osg/BoundingBox>
15 #include <osg/Node>
16 
17 #include "MyCamera.h"
18 
26 class MyCameraManipulator : public osgGA::MatrixManipulator
27 {
28 public:
29  MyCameraManipulator( MyCamera& myCamera );
30  virtual ~MyCameraManipulator() {}
31 
32  //~ void setRotationEnabled( bool b ) { m_rotationAllowed = b; }
33  //~ void setZoomEnabled( bool b ) { m_zoomAllowed = b; }
34  //~ void setPanEnabled( bool b ) { m_panAllowed = b; }
35  //~ bool rotationEnabled() const { return m_rotationAllowed; }
36  //~ bool zoomEnabled() const { return m_zoomAllowed; }
37  //~ bool panEnabled() const { return m_panAllowed; }
38 
41  virtual const char* className() const { return "MyCameraManipulator"; }
42 
43  virtual void setByMatrix ( const osg::Matrixd& matrix );
44  virtual void setByInverseMatrix( const osg::Matrixd& matrix ) { setByMatrix(osg::Matrixd::inverse(matrix)); }
45 
46  virtual osg::Matrixd getMatrix() const;
47  virtual osg::Matrixd getInverseMatrix() const;
48 
50  virtual void setNode( osg::Node* );
51  virtual const osg::Node* getNode() const { return _node.get(); }
52  virtual osg::Node* getNode() { return _node.get(); }
53 
54  virtual void home( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
55  virtual void home( double );
56 
57  virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
58 
59 // not implemented:
60 // virtual void init(const GUIEventAdapter& ea, GUIActionAdapter& us);
61 // virtual void getUsage(osg::ApplicationUsage& usage) const;
63 
64 protected:
66  virtual bool calcMovement();
67 
69  void flushMouseEventStack() { _ga_t1=NULL; _ga_t0=NULL; }
71  void addMouseEvent( const osgGA::GUIEventAdapter& ea ) { _ga_t1=_ga_t0; _ga_t0=&ea; }
74  osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t1;
75  osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t0;
77 
78 private:
79  MyCamera& _myCamera;
80 
81  /* Defined in base class MatrixManipulator:
82  double _minimumDistance;
83  osg::Vec3d _homeEye;
84  osg::Vec3d _homeCenter;
85  osg::Vec3d _homeUp;
86  */
87 
88  float _radius;
89 
90  osg::ref_ptr<osg::Node> _node;
91 
92  bool m_rotationAllowed, m_panAllowed, m_zoomAllowed;
93 
96  float _trackballSize;
97  void trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y);
98  float tb_project_to_sphere(float r, float x, float y);
99  void setTrackballSize(float size); //--> should be public
101 };
102 
103 #endif
osg::ref_ptr< const osgGA::GUIEventAdapter > _ga_t1
Definition: MyCameraManipulator.h:74
virtual void setByMatrix(const osg::Matrixd &matrix)
Definition: MyCameraManipulator.cpp:208
virtual osg::Matrixd getInverseMatrix() const
Definition: MyCameraManipulator.cpp:220
void addMouseEvent(const osgGA::GUIEventAdapter &ea)
Add the current mouse GUIEvent to internal stack.
Definition: MyCameraManipulator.h:71
virtual void home(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Manage modelview and projection, allows switching between ORTHOGRAPHIC and PERSPECTIVE projection...
Definition: MyCamera.h:44
virtual bool calcMovement()
Helper function called from handle().
Definition: MyCameraManipulator.cpp:61
virtual ~MyCameraManipulator()
Definition: MyCameraManipulator.h:30
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Definition: MyCameraManipulator.cpp:34
Simple trackball which operates on MyCamera.
Definition: MyCameraManipulator.h:26
virtual osg::Matrixd getMatrix() const
Definition: MyCameraManipulator.cpp:215
void flushMouseEventStack()
Reset the internal GUIEvent stack.
Definition: MyCameraManipulator.h:69
virtual void setByInverseMatrix(const osg::Matrixd &matrix)
Definition: MyCameraManipulator.h:44
virtual osg::Node * getNode()
Definition: MyCameraManipulator.h:52
virtual const osg::Node * getNode() const
Definition: MyCameraManipulator.h:51
MyCameraManipulator(MyCamera &myCamera)
Definition: MyCameraManipulator.cpp:22
virtual const char * className() const
Definition: MyCameraManipulator.h:41
virtual void setNode(osg::Node *)
Overrides settings applied by setBoundingBox()
Definition: MyCameraManipulator.cpp:172
osg::ref_ptr< const osgGA::GUIEventAdapter > _ga_t0
Definition: MyCameraManipulator.h:75