Robot Simulator of the Robotics Group for Self-Organization of Control: cameramanipulator.h Source File

# cameramanipulator.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
    00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
    00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
    00007  *                                                                         *
    00008  *   This program is free software; you can redistribute it and/or modify  *
    00009  *   it under the terms of the GNU General Public License as published by  *
    00010  *   the Free Software Foundation; either version 2 of the License, or     *
    00011  *   (at your option) any later version.                                   *
    00012  *                                                                         *
    00013  *   This program is distributed in the hope that it will be useful,       *
    00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00016  *   GNU General Public License for more details.                          *
    00017  *                                                                         *
    00018  *   You should have received a copy of the GNU General Public License     *
    00019  *   along with this program; if not, write to the                         *
    00020  *   Free Software Foundation, Inc.,                                       *
    00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00022  *                                                                         *
    00023  ***************************************************************************/
    00024 #ifndef __CAMERAMANIPULATOR_H
    00025 #define __CAMERAMANIPULATOR_H
    00026
    00027 #include "osgforwarddecl.h"
    00028
    00029 #include <osg/Version>
    00030 #if OPENSCENEGRAPH_MAJOR_VERSION >= 3
    00031 #include <osgGA/CameraManipulator>
    00032 #define OSGCameraManipulator osgGA::CameraManipulator
    00033 #else
    00034 #include <osgGA/MatrixManipulator>
    00035 #define OSGCameraManipulator osgGA::MatrixManipulator
    00036 #endif
    00037 #include "globaldata.h"
    00038 #include <selforg/position.h>
    00039 #include <selforg/callbackable.h>
    00040 #include "camerahandle.h"
    00041
    00042 namespace lpzrobots {
    00043   // forward declaration
    00044   class OSGPrimitive;
    00045
    00046   /**
    00047      CameraManipulator is a MatrixManipulator which provides a flying camera
    00048      updating of the camera position & orientation.
    00049      Left mouse button: Pan and tilt
    00050      Right mouse button: forward and sideways
    00051      Middle mouse button: up and sideways
    00052
    00053      It also enables to manipulate agents with forces
    00054   */
    00055   class CameraManipulator : public OSGCameraManipulator, public Callbackable
    00056     {
    00057     public:
    00058
    00059       CameraManipulator(osg::Node* node, GlobalData& global, CameraHandle& cameraHandle);
    00060
    00061
    00062       /** returns the classname of the manipulator
    00063           it's NECCESSARY to define this funtion, otherwise
    00064           the new manipulator WON'T WORK! (but ask me not why)
    00065       */
    00066       virtual const char* className() const { return "Default Camera"; }
    00067
    00068       /** set the position of the matrix manipulator using a 4x4 Matrix.*/
    00069       virtual void setByMatrix(const osg::Matrixd& matrix);
    00070
    00071       /** set the position of the matrix manipulator using a 4x4 Matrix.*/
    00072       virtual void setByInverseMatrix(const osg::Matrixd& matrix) {
    00073         setByMatrix(osg::Matrixd::inverse(matrix));
    00074       }
    00075
    00076       /** get the position of the manipulator as 4x4 Matrix.*/
    00077       virtual osg::Matrixd getMatrix() const;
    00078
    00079       /** get the position of the manipulator as a inverse matrix of the manipulator,
    00080           typically used as a model view matrix.*/
    00081       virtual osg::Matrixd getInverseMatrix() const;
    00082
    00083
    00084       /**
    00085        * is called every time the draw is updated. computes the
    00086        * movement of the camera, which is a difference between
    00087        * the desired pos and view and the actual pos and view.
    00088        */
    00089       /*
    00090         virtual void computeMovement();*/
    00091
    00092       virtual void setNode(osg::Node*);
    00093
    00094       virtual const osg::Node* getNode() const;
    00095
    00096       virtual osg::Node* getNode();
    00097
    00098       /// set the home position of the camera. (and place it there)
    00099       virtual void setHome(const osg::Vec3& eye, const osg::Vec3& view);
    00100
    00101       /// place the camera at its home position
    00102       virtual void home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
    00103
    00104       virtual void init(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
    00105
    00106       virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
    00107
    00108       /** Get the keyboard and mouse usage of this manipulator.*/
    00109       virtual void getUsage(osg::ApplicationUsage& usage) const;
    00110
    00111       /** updates the camera module at every drawstep
    00112           should be called from the simulation loop
    00113       */
    00114       virtual void update();
    00115
    00116       /** manipulate agent if Manipulation is active
    00117           (should be called every simulation step)
    00118       */
    00119       virtual void manipulateAgent( OsgHandle& osgHandle);
    00120
    00121       /**
    00122        * Sets the agent to be watched with the camera.
    00123        * @param agent to set
    00124        */
    00125       virtual void setWatchedAgent(OdeAgent* agent);
    00126
    00127       /// returns watched agent
    00128       virtual OdeAgent* getWatchedAgent();
    00129
    00130       /// called if agents list changed
    00131       virtual void doOnCallBack(BackCaller* source, BackCaller::CallbackableType type
    00132                                 = BackCaller::DEFAULT_CALLBACKABLE_TYPE);
    00133
    00134     protected:
    00135
    00136       virtual ~CameraManipulator();
    00137
    00138       /** Reset the internal GUIEvent stack.*/
    00139       virtual void flushMouseEventStack();
    00140       /** Add the current mouse GUIEvent to internal stack.*/
    00141       virtual void addMouseEvent(const osgGA::GUIEventAdapter& ea);
    00142
    00143       virtual void computeMatrix();
    00144
    00145       /** For the give mouse movement calculate the movement of the camera.
    00146           Return true is camera has moved and a redraw is required.*/
    00147       virtual bool calcMovement();
    00148
    00149       /**
    00150        * Checks if an agent is selected and if this agent is available.
    00151        * This agent must be listed in the global agent list.
    00152        * @return true if defined, otherwise false
    00153        */
    00154       virtual bool isWatchingAgentDefined();
    00155
    00156       // Internal event stack comprising last three mouse events.
    00157       osg::ref_ptr<const osgGA::GUIEventAdapter> event_old;
    00158       osg::ref_ptr<const osgGA::GUIEventAdapter> event;
    00159
    00160       osg::ref_ptr<osg::Node> node;
    00161
    00162       float modelScale;
    00163       osg::Matrixd  pose;  // complete pose (updated by computeMatrix()
    00164
    00165       CameraHandle& camHandle;
    00166
    00167       GlobalData& globalData; // the global environment variables
    00168
    00169
    00170       double degreeSmoothness; // smoothness factor for the view
    00171       double lengthSmoothness; // smoothness factor for the eye
    00172       double degreeAccuracy; // accuracy factor for the view-smoothness
    00173       double lengthAccuracy; // accuracy factor for the eye-smoothness
    00174
    00175
    00176       /** This manages the robots, switching between them and so on
    00177           Is normally called from handle(...)
    00178       */
    00179       virtual void manageAgents(const int& fkey);
    00180
    00181
    00182       /** This handles robot movements, so that the camera movemenent is right affected.
    00183           should normally be overwritten by new cameramanipulator
    00184       */
    00185       virtual void calcMovementByAgent();
    00186
    00187
    00188       /** Sets the right view and eye if the robot has changed.
    00189           Is called from manageRobots();
    00190           should be overwritten by new cameramanipulator (if needed)
    00191       */
    00192       virtual void setHomeViewByAgent();
    00193       virtual void setHomeEyeByAgent();
    00194
    00195
    00196       /** moves behind the robot which is actually watched
    00197        */
    00198       virtual void moveBehindAgent();
    00199
    00200       /** centers on the robot which is actually watched
    00201        */
    00202       virtual void centerOnAgent();
    00203
    00204       /** manipulates Agent by forces. The given points are screen coords (-1 to 1) normalized.
    00205       */
    00206       virtual void calcManipulationPointHorizontal(float x, float y);
    00207
    00208       virtual void calcManipulationPointVertical(float x, float y);
    00209
    00210       virtual void calcManipulationPoint(float x, float y);
    00211
    00212
    00213     };
    00214
    00215 }
    00216
    00217 #endif