Robotsystem from Robot Group Leipzig: cameramanipulator.h Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

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