OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CameraManipulator.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 
14 #ifndef OSGGA_CameraManipulator
15 #define OSGGA_CameraManipulator 1
16 
17 #include <osg/Node>
18 #include <osg/Matrixd>
19 #include <osg/CoordinateSystemNode>
20 
21 #include <osgUtil/SceneView>
22 
23 #include <osgGA/Export>
24 #include <osgGA/GUIEventHandler>
25 #include <osgGA/GUIEventAdapter>
26 #include <osgGA/GUIActionAdapter>
27 
28 namespace osgGA{
29 
30 #define NEW_HOME_POSITION
31 
40 {
41  typedef GUIEventHandler inherited;
42 
43  public:
44 
45  // We are not using META_Object as this is abstract class.
46  // Use META_Object(osgGA,YourManipulator); in your descendant non-abstract classes.
47  virtual const char* className() const { return "CameraManipulator"; }
48 
51  {
52  public:
53  virtual osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const = 0;
54  protected:
56  };
57 
59  virtual void setCoordinateFrameCallback(CoordinateFrameCallback* cb) { _coordinateFrameCallback = cb; }
60 
62  CoordinateFrameCallback* getCoordinateFrameCallback() { return _coordinateFrameCallback.get(); }
63 
65  const CoordinateFrameCallback* getCoordinateFrameCallback() const { return _coordinateFrameCallback.get(); }
66 
69  {
70  if (_coordinateFrameCallback.valid()) return _coordinateFrameCallback->getCoordinateFrame(position);
71  return osg::CoordinateFrame();
72  }
73 
74  osg::Vec3d getSideVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(0,0),cf(0,1),cf(0,2)); }
75  osg::Vec3d getFrontVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(1,0),cf(1,1),cf(1,2)); }
76  osg::Vec3d getUpVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(2,0),cf(2,1),cf(2,2)); }
77 
79  virtual void setByMatrix(const osg::Matrixd& matrix) = 0;
80 
82  virtual void setByInverseMatrix(const osg::Matrixd& matrix) = 0;
83 
85  virtual osg::Matrixd getMatrix() const = 0;
86 
88  virtual osg::Matrixd getInverseMatrix() const = 0;
89 
92  virtual void updateCamera(osg::Camera& camera) { camera.setViewMatrix(getInverseMatrix()); }
93 
96 
98  virtual float getFusionDistanceValue() const { return 1.0f; }
99 
102  void setIntersectTraversalMask(unsigned int mask) { _intersectTraversalMask = mask; }
103 
105  unsigned int getIntersectTraversalMask() const { return _intersectTraversalMask; }
106 
112  virtual void setNode(osg::Node*) {}
113 
115  virtual const osg::Node* getNode() const { return NULL; }
116 
118  virtual osg::Node* getNode() { return NULL; }
119 
121  virtual void setHomePosition(const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up, bool autoComputeHomePosition=false)
122  {
123  setAutoComputeHomePosition(autoComputeHomePosition);
124  _homeEye = eye;
125  _homeCenter = center;
126  _homeUp = up;
127  }
128 
130  virtual void getHomePosition(osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up) const
131  {
132  eye = _homeEye;
133  center = _homeCenter;
134  up = _homeUp;
135  }
136 
138  virtual void setAutoComputeHomePosition(bool flag) { _autoComputeHomePosition = flag; }
139 
141  bool getAutoComputeHomePosition() const { return _autoComputeHomePosition; }
142 
144  virtual void computeHomePosition(const osg::Camera *camera = NULL, bool useBoundingBox = false);
145 
147  virtual void finishAnimation() {}
148 
153  virtual void home(const GUIEventAdapter& ,GUIActionAdapter&) {}
154 
161  virtual void home(double /*currentTime*/) {}
162 
167  virtual void init(const GUIEventAdapter& ,GUIActionAdapter&) {}
168 
170  virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv) { return GUIEventHandler::handle(event, object, nv); }
171 
173  virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
174 
175  protected:
176 
179 
180  virtual ~CameraManipulator();
181 
182  std::string getManipulatorName() const;
183 
185 
187 
191 
193 
194 };
195 
196 }
197 
198 #endif
osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d &position) const
bool getAutoComputeHomePosition() const
unsigned int _intersectTraversalMask
#define NULL
Definition: Export.h:59
virtual void setNode(osg::Node *)
virtual void updateCamera(osg::Camera &camera)
virtual const osg::Node * getNode() const
virtual void home(double)
osg::Vec3d getUpVector(const osg::CoordinateFrame &cf) const
virtual void setCoordinateFrameCallback(CoordinateFrameCallback *cb)
osg::ref_ptr< CoordinateFrameCallback > _coordinateFrameCallback
void setViewMatrix(const osg::Matrixf &matrix)
Definition: Camera.h:244
virtual float getFusionDistanceValue() const
virtual const char * className() const
virtual void setHomePosition(const osg::Vec3d &eye, const osg::Vec3d &center, const osg::Vec3d &up, bool autoComputeHomePosition=false)
#define OSGGA_EXPORT
Definition: Export.h:40
virtual bool handle(osgGA::Event *event, osg::Object *object, osg::NodeVisitor *nv)
virtual void setAutoComputeHomePosition(bool flag)
void setIntersectTraversalMask(unsigned int mask)
CoordinateFrameCallback * getCoordinateFrameCallback()
osg::Vec3d getFrontVector(const osg::CoordinateFrame &cf) const
virtual osg::Node * getNode()
osg::Vec3d getSideVector(const osg::CoordinateFrame &cf) const
Definition: Node.h:71
virtual bool handle(osgGA::Event *event, osg::Object *object, osg::NodeVisitor *nv)
unsigned int getIntersectTraversalMask() const
virtual void getHomePosition(osg::Vec3d &eye, osg::Vec3d &center, osg::Vec3d &up) const
const CoordinateFrameCallback * getCoordinateFrameCallback() const
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const
Matrixd CoordinateFrame
virtual void home(const GUIEventAdapter &, GUIActionAdapter &)
virtual void init(const GUIEventAdapter &, GUIActionAdapter &)