Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cameramanipulator.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __CAMERAMANIPULATOR_H
25 #define __CAMERAMANIPULATOR_H
26 
27 #include "osgforwarddecl.h"
28 
29 #include <osg/Version>
30 #if OPENSCENEGRAPH_MAJOR_VERSION >= 3
31 #include <osgGA/CameraManipulator>
32 #define OSGCameraManipulator osgGA::CameraManipulator
33 #else
34 #include <osgGA/MatrixManipulator>
35 #define OSGCameraManipulator osgGA::MatrixManipulator
36 #endif
37 #include "globaldata.h"
38 #include <selforg/position.h>
39 #include <selforg/callbackable.h>
40 #include "camerahandle.h"
41 
42 namespace lpzrobots {
43  // forward declaration
44  class OSGPrimitive;
45 
46  /**
47  CameraManipulator is a MatrixManipulator which provides a flying camera
48  updating of the camera position & orientation.
49  Left mouse button: Pan and tilt
50  Right mouse button: forward and sideways
51  Middle mouse button: up and sideways
52 
53  It also enables to manipulate agents with forces
54  */
56  {
57  public:
58 
59  CameraManipulator(osg::Node* node, GlobalData& global, CameraHandle& cameraHandle);
60 
61 
62  /** returns the classname of the manipulator
63  it's NECCESSARY to define this funtion, otherwise
64  the new manipulator WON'T WORK! (but ask me not why)
65  */
66  virtual const char* className() const { return "Default Camera"; }
67 
68  /** set the position of the matrix manipulator using a 4x4 Matrix.*/
69  virtual void setByMatrix(const osg::Matrixd& matrix);
70 
71  /** set the position of the matrix manipulator using a 4x4 Matrix.*/
72  virtual void setByInverseMatrix(const osg::Matrixd& matrix) {
73  setByMatrix(osg::Matrixd::inverse(matrix));
74  }
75 
76  /** get the position of the manipulator as 4x4 Matrix.*/
77  virtual osg::Matrixd getMatrix() const;
78 
79  /** get the position of the manipulator as a inverse matrix of the manipulator,
80  typically used as a model view matrix.*/
81  virtual osg::Matrixd getInverseMatrix() const;
82 
83 
84  /**
85  * is called every time the draw is updated. computes the
86  * movement of the camera, which is a difference between
87  * the desired pos and view and the actual pos and view.
88  */
89  /*
90  virtual void computeMovement();*/
91 
92  virtual void setNode(osg::Node*);
93 
94  virtual const osg::Node* getNode() const;
95 
96  virtual osg::Node* getNode();
97 
98  /// set the home position of the camera. (and place it there)
99  virtual void setHome(const osg::Vec3& eye, const osg::Vec3& view);
100 
101  /// place the camera at its home position
102  virtual void home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
103 
104  virtual void init(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
105 
106  virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
107 
108  /** Get the keyboard and mouse usage of this manipulator.*/
109  virtual void getUsage(osg::ApplicationUsage& usage) const;
110 
111  /** updates the camera module at every drawstep
112  should be called from the simulation loop
113  */
114  virtual void update();
115 
116  /** manipulate agent if Manipulation is active
117  (should be called every simulation step)
118  */
119  virtual void manipulateAgent( OsgHandle& osgHandle);
120 
121  /**
122  * Sets the agent to be watched with the camera.
123  * @param agent to set
124  */
125  virtual void setWatchedAgent(OdeAgent* agent);
126 
127  /// returns watched agent
128  virtual OdeAgent* getWatchedAgent();
129 
130  /// called if agents list changed
131  virtual void doOnCallBack(BackCaller* source, BackCaller::CallbackableType type
133 
134  protected:
135 
136  virtual ~CameraManipulator();
137 
138  /** Reset the internal GUIEvent stack.*/
139  virtual void flushMouseEventStack();
140  /** Add the current mouse GUIEvent to internal stack.*/
141  virtual void addMouseEvent(const osgGA::GUIEventAdapter& ea);
142 
143  virtual void computeMatrix();
144 
145  /** For the give mouse movement calculate the movement of the camera.
146  Return true is camera has moved and a redraw is required.*/
147  virtual bool calcMovement();
148 
149  /**
150  * Checks if an agent is selected and if this agent is available.
151  * This agent must be listed in the global agent list.
152  * @return true if defined, otherwise false
153  */
154  virtual bool isWatchingAgentDefined();
155 
156  // Internal event stack comprising last three mouse events.
157  osg::ref_ptr<const osgGA::GUIEventAdapter> event_old;
158  osg::ref_ptr<const osgGA::GUIEventAdapter> event;
159 
160  osg::ref_ptr<osg::Node> node;
161 
162  float modelScale;
163  osg::Matrixd pose; // complete pose (updated by computeMatrix()
164 
166 
167  GlobalData& globalData; // the global environment variables
168 
169 
170  double degreeSmoothness; // smoothness factor for the view
171  double lengthSmoothness; // smoothness factor for the eye
172  double degreeAccuracy; // accuracy factor for the view-smoothness
173  double lengthAccuracy; // accuracy factor for the eye-smoothness
174 
175 
176  /** This manages the robots, switching between them and so on
177  Is normally called from handle(...)
178  */
179  virtual void manageAgents(const int& fkey);
180 
181 
182  /** This handles robot movements, so that the camera movemenent is right affected.
183  should normally be overwritten by new cameramanipulator
184  */
185  virtual void calcMovementByAgent();
186 
187 
188  /** Sets the right view and eye if the robot has changed.
189  Is called from manageRobots();
190  should be overwritten by new cameramanipulator (if needed)
191  */
192  virtual void setHomeViewByAgent();
193  virtual void setHomeEyeByAgent();
194 
195 
196  /** moves behind the robot which is actually watched
197  */
198  virtual void moveBehindAgent();
199 
200  /** centers on the robot which is actually watched
201  */
202  virtual void centerOnAgent();
203 
204  /** manipulates Agent by forces. The given points are screen coords (-1 to 1) normalized.
205  */
206  virtual void calcManipulationPointHorizontal(float x, float y);
207 
208  virtual void calcManipulationPointVertical(float x, float y);
209 
210  virtual void calcManipulationPoint(float x, float y);
211 
212 
213  };
214 
215 }
216 
217 #endif
osg::ref_ptr< const osgGA::GUIEventAdapter > event
Definition: cameramanipulator.h:158
CameraManipulator is a MatrixManipulator which provides a flying camera updating of the camera positi...
Definition: cameramanipulator.h:55
virtual void addMouseEvent(const osgGA::GUIEventAdapter &ea)
Add the current mouse GUIEvent to internal stack.
Definition: cameramanipulator.cpp:268
Interface class for a class which wants to be callback on a certain action.
Definition: callbackable.h:39
#define OSGCameraManipulator
Definition: cameramanipulator.h:35
virtual void calcManipulationPointHorizontal(float x, float y)
manipulates Agent by forces.
Definition: cameramanipulator.cpp:556
virtual void manipulateAgent(OsgHandle &osgHandle)
manipulate agent if Manipulation is active (should be called every simulation step) ...
Definition: cameramanipulator.cpp:604
GlobalData & globalData
Definition: cameramanipulator.h:167
osg::ref_ptr< const osgGA::GUIEventAdapter > event_old
Definition: cameramanipulator.h:157
virtual void setHomeEyeByAgent()
Definition: cameramanipulator.cpp:505
virtual bool calcMovement()
For the give mouse movement calculate the movement of the camera.
Definition: cameramanipulator.cpp:376
osg::ref_ptr< osg::Node > node
Definition: cameramanipulator.h:160
virtual void getUsage(osg::ApplicationUsage &usage) const
Get the keyboard and mouse usage of this manipulator.
Definition: cameramanipulator.cpp:253
double degreeSmoothness
Definition: cameramanipulator.h:170
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
virtual void update()
updates the camera module at every drawstep should be called from the simulation loop ...
Definition: cameramanipulator.cpp:300
virtual OdeAgent * getWatchedAgent()
returns watched agent
Definition: cameramanipulator.cpp:672
osg::Matrixd pose
Definition: cameramanipulator.h:163
virtual void setHome(const osg::Vec3 &eye, const osg::Vec3 &view)
set the home position of the camera. (and place it there)
Definition: cameramanipulator.cpp:79
virtual void setByMatrix(const osg::Matrixd &matrix)
set the position of the matrix manipulator using a 4x4 Matrix.
Definition: cameramanipulator.cpp:275
Class which holds all data used by CameraManipulators.
Definition: camerahandle.h:54
virtual const char * className() const
returns the classname of the manipulator it's NECCESSARY to define this funtion, otherwise the new ma...
Definition: cameramanipulator.h:66
virtual ~CameraManipulator()
Definition: cameramanipulator.cpp:63
virtual void setWatchedAgent(OdeAgent *agent)
Sets the agent to be watched with the camera.
Definition: cameramanipulator.cpp:660
double lengthSmoothness
Definition: cameramanipulator.h:171
static const CallbackableType DEFAULT_CALLBACKABLE_TYPE
This is the default Callbackable type.
Definition: backcaller.h:51
unsigned long CallbackableType
Definition: backcaller.h:45
virtual void setByInverseMatrix(const osg::Matrixd &matrix)
set the position of the matrix manipulator using a 4x4 Matrix.
Definition: cameramanipulator.h:72
virtual void calcManipulationPointVertical(float x, float y)
Definition: cameramanipulator.cpp:526
Vec3f Vec3
Definition: osgforwarddecl.h:42
double lengthAccuracy
Definition: cameramanipulator.h:173
virtual void manageAgents(const int &fkey)
This manages the robots, switching between them and so on Is normally called from handle(...
Definition: cameramanipulator.cpp:407
virtual void calcMovementByAgent()
This handles robot movements, so that the camera movemenent is right affected.
Definition: cameramanipulator.cpp:492
virtual void moveBehindAgent()
moves behind the robot which is actually watched
Definition: cameramanipulator.cpp:415
double degreeAccuracy
Definition: cameramanipulator.h:172
Data structure holding all essential global information.
Definition: globaldata.h:57
Specialised agent for ode robots.
Definition: odeagent.h:62
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Definition: cameramanipulator.cpp:123
virtual void setNode(osg::Node *)
is called every time the draw is updated.
Definition: cameramanipulator.cpp:66
float modelScale
Definition: cameramanipulator.h:162
virtual void init(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Definition: cameramanipulator.cpp:112
virtual void doOnCallBack(BackCaller *source, BackCaller::CallbackableType type=BackCaller::DEFAULT_CALLBACKABLE_TYPE)
called if agents list changed
Definition: cameramanipulator.cpp:677
virtual const osg::Node * getNode() const
Definition: cameramanipulator.cpp:70
virtual bool isWatchingAgentDefined()
Checks if an agent is selected and if this agent is available.
Definition: cameramanipulator.cpp:583
virtual osg::Matrixd getInverseMatrix() const
get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model...
Definition: cameramanipulator.cpp:356
virtual void home(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
place the camera at its home position
Definition: cameramanipulator.cpp:91
CameraManipulator(osg::Node *node, GlobalData &global, CameraHandle &cameraHandle)
Definition: cameramanipulator.cpp:46
Class prototype which provides functions to handle callbackable classes.
Definition: backcaller.h:42
virtual void setHomeViewByAgent()
Sets the right view and eye if the robot has changed.
Definition: cameramanipulator.cpp:500
virtual osg::Matrixd getMatrix() const
get the position of the manipulator as 4x4 Matrix.
Definition: cameramanipulator.cpp:296
virtual void centerOnAgent()
centers on the robot which is actually watched
Definition: cameramanipulator.cpp:465
virtual void computeMatrix()
Definition: cameramanipulator.cpp:360
virtual void flushMouseEventStack()
Reset the internal GUIEvent stack.
Definition: cameramanipulator.cpp:264
CameraHandle & camHandle
Definition: cameramanipulator.h:165
virtual void calcManipulationPoint(float x, float y)
Definition: cameramanipulator.cpp:510