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