Robotsystem of the Robot Group Leipzig: cameramanipulator.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# cameramanipulator.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
    00003  *    martius@informatik.uni-leipzig.de                                    *
    00004  *    fhesse@informatik.uni-leipzig.de                                     *
    00005  *    der@informatik.uni-leipzig.de                                        *
    00006  *    frankguettler@gmx.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  *  Camera Manipulation by mouse and keyboard                              *
    00025  *                                                                         *
    00026  *   $Log: cameramanipulator.h,v $
    00027  *   Revision 1.3  2007/07/03 13:15:17  martius
    00028  *   odehandle.h in cpp files included
    00029  *
    00030  *   Revision 1.2  2006/07/14 12:23:34  martius
    00031  *   selforg becomes HEAD
    00032  *
    00033  *   Revision 1.1.2.12  2006/06/29 16:35:56  robot3
    00034  *   includes cleared up
    00035  *
    00036  *   Revision 1.1.2.11  2006/05/29 20:00:33  robot3
    00037  *   added pos1 (center on agent) and end (move behind agent)
    00038  *
    00039  *   Revision 1.1.2.10  2006/03/19 13:32:12  robot3
    00040  *   race mode now works
    00041  *
    00042  *   Revision 1.1.2.9  2006/03/08 13:19:13  robot3
    00043  *   basic modifications, follow mode now works
    00044  *
    00045  *   Revision 1.1.2.8  2006/03/06 16:57:01  robot3
    00046  *   -more stable version
    00047  *   -code optimized
    00048  *   -some static variables used by all cameramanipulators
    00049  *
    00050  *   Revision 1.1.2.7  2006/03/05 15:02:24  robot3
    00051  *   camera moves now smooth
    00052  *
    00053  *   Revision 1.1.2.6  2006/03/04 15:04:33  robot3
    00054  *   cameramanipulator is now updated with every draw intervall
    00055  *
    00056  *   Revision 1.1.2.5  2006/03/03 12:08:50  robot3
    00057  *   preparations made for new cameramanipulators
    00058  *
    00059  *   Revision 1.1.2.4  2006/02/01 10:24:34  robot3
    00060  *   new camera manipulator added
    00061  *
    00062  *   Revision 1.1.2.3  2005/12/29 12:56:12  martius
    00063  *   setHome
    00064  *
    00065  *   Revision 1.1.2.2  2005/12/15 17:03:42  martius
    00066  *   cameramanupulator setPose is working
    00067  *   joints have setter and getter parameters
    00068  *   Primitives are not longer inherited from OSGPrimitive, moreover
    00069  *   they aggregate them
    00070  *
    00071  *   Revision 1.1.2.1  2005/12/09 16:56:21  martius
    00072  *   camera is working now
    00073  *
    00074  *   Revision 1.1.2.1  2005/12/06 17:38:21  martius
    00075  *   *** empty log message ***
    00076  *
    00077  *                                                                 *
    00078  ***************************************************************************/
    00079 #ifndef __CAMERAMANIPULATOR_H
    00080 #define __CAMERAMANIPULATOR_H
    00081
    00082 #include "osgforwarddecl.h"
    00083 #include <osgGA/MatrixManipulator>
    00084 #include "globaldata.h"
    00085 #include <selforg/position.h>
    00086
    00087 namespace lpzrobots {
    00088
    00089   /**
    00090      CameraManipulator is a MatrixManipulator which provides Flying simulator-like
    00091      updating of the camera position & orientation.
    00092      Left mouse button: Pan and tilt
    00093      Right mouse button: forward and sideways
    00094      Middle mouse button: up and sideways
    00095   */
    00096
    00097   class CameraManipulator : public osgGA::MatrixManipulator
    00098     {
    00099     public:
    00100
    00101       CameraManipulator(osg::Node* node, GlobalData& global);
    00102
    00103
    00104       /** returns the classname of the manipulator
    00105           it's NECCESSARY to define this funtion, otherwise
    00106           the new manipulator WON'T WORK! (but ask me not why)
    00107       */
    00108       virtual const char* className() const { return "Default Camera"; }
    00109
    00110       /** set the position of the matrix manipulator using a 4x4 Matrix.*/
    00111       virtual void setByMatrix(const osg::Matrixd& matrix);
    00112
    00113       /** set the position of the matrix manipulator using a 4x4 Matrix.*/
    00114       virtual void setByInverseMatrix(const osg::Matrixd& matrix) {
    00115         setByMatrix(osg::Matrixd::inverse(matrix));
    00116       }
    00117
    00118       /** get the position of the manipulator as 4x4 Matrix.*/
    00119       virtual osg::Matrixd getMatrix() const;
    00120
    00121       /** get the position of the manipulator as a inverse matrix of the manipulator,
    00122           typically used as a model view matrix.*/
    00123       virtual osg::Matrixd getInverseMatrix() const;
    00124
    00125
    00126       /**
    00127        * is called every time the draw is updated. computes the
    00128        * movement of the camera, which is a difference between
    00129        * the desired pos and view and the actual pos and view.
    00130        */
    00131       /*
    00132         virtual void computeMovement();*/
    00133
    00134       virtual void setNode(osg::Node*);
    00135
    00136       virtual const osg::Node* getNode() const;
    00137
    00138       virtual osg::Node* getNode();
    00139
    00140       /// set the home position of the camera. (and place it there)
    00141       virtual void setHome(const osg::Vec3& eye, const osg::Vec3& view);
    00142
    00143       /// place the camera at its home position
    00144       virtual void home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
    00145
    00146       virtual void init(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
    00147
    00148       virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
    00149
    00150       /** Get the keyboard and mouse usage of this manipulator.*/
    00151       virtual void getUsage(osg::ApplicationUsage& usage) const;
    00152
    00153       /** updates the camera module at every drawstep
    00154           should be called from the simulation loop
    00155       */
    00156       virtual void update();
    00157
    00158     protected:
    00159
    00160       virtual ~CameraManipulator();
    00161
    00162       /** Reset the internal GUIEvent stack.*/
    00163       virtual void flushMouseEventStack();
    00164       /** Add the current mouse GUIEvent to internal stack.*/
    00165       virtual void addMouseEvent(const osgGA::GUIEventAdapter& ea);
    00166
    00167       virtual void computeMatrix();
    00168
    00169       /** For the give mouse movement calculate the movement of the camera.
    00170           Return true is camera has moved and a redraw is required.*/
    00171       virtual bool calcMovement();
    00172
    00173       // Internal event stack comprising last three mouse events.
    00174       osg::ref_ptr<const osgGA::GUIEventAdapter> event_old;
    00175       osg::ref_ptr<const osgGA::GUIEventAdapter> event;
    00176
    00177       osg::ref_ptr<osg::Node> node;
    00178
    00179       float modelScale;
    00180       osg::Matrixd  pose;  // complete pose (updated by computeMatrix()
    00181
    00182       static osg::Vec3   eye;      // position of the camera
    00183       static osg::Vec3   view;     // view angles in degree (pan, tilt, yaw)
    00184       static osg::Vec3   home_eye;  // home position of the camera
    00185       static osg::Vec3   home_view; // home view angles in degree (pan, tilt, yaw)
    00186       static bool home_externally_set;
    00187
    00188       static osg::Vec3   desiredEye;      // desired position of the camera
    00189       static osg::Vec3   desiredView;     // desired view angles in degree (pan, tilt, yaw)
    00190
    00191       static OdeAgent* watchingAgent; // the robot which is actually watched
    00192       static bool watchingAgentDefined;
    00193
    00194       static Position oldPositionOfAgent; // because the return of getSpeed() seems not to be useful
    00195       static bool oldPositionOfAgentDefined;
    00196
    00197       GlobalData& globalData; // the global environment variables
    00198
    00199
    00200       double degreeSmoothness; // smoothness factor for the view
    00201       double lengthSmoothness; // smoothness factor for the eye
    00202       double degreeAccuracy; // accuracy factor for the view-smoothness
    00203       double lengthAccuracy; // accuracy factor for the eye-smoothness
    00204
    00205
    00206       /** This manages the robots, switching between them and so on
    00207           Is normally called from handle(...)
    00208       */
    00209       virtual void manageAgents(const int& fkey);
    00210
    00211
    00212       /** This handles robot movements, so that the camera movemenent is right affected.
    00213           should normally be overwritten by new cameramanipulator
    00214       */
    00215       virtual void calcMovementByAgent();
    00216
    00217
    00218       /** Sets the right view and eye if the robot has changed.
    00219           Is called from manageRobots();
    00220           should be overwritten by new cameramanipulator (if needed)
    00221       */
    00222       virtual void setHomeViewByAgent();
    00223       virtual void setHomeEyeByAgent();
    00224
    00225
    00226       /** moves behind the robot which is actually watched
    00227        */
    00228       virtual void moveBehindAgent();
    00229
    00230       /** centers on the robot which is actually watched
    00231        */
    00232       virtual void centerOnAgent();
    00233
    00234       static int i;
    00235
    00236
    00237     };
    00238
    00239 }
    00240
    00241 #endif