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

Generated on Mon Aug 7 16:40:14 2006 for Robotsystem of the Robot Group Leipzig by  doxygen 1.4.7