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 * base.h provides osg stuff for basic environment with sky and so on. * 00025 * * 00026 * $Log: base.h,v $ 00027 * Revision 1.23 2009/09/03 12:53:25 guettler 00028 * reverted changes of revision 1.37: 00029 * - getHUDSM is called without calling createHUDSM before 00030 * if simulation is started with -nographics 00031 * FIX: createHUDSM calls now getHUDSM (fix of HUDSM was not complete) 00032 * 00033 * Revision 1.22 2009/08/10 14:55:13 der 00034 * shadowTexSize and shadow are integer 00035 * 00036 * Revision 1.21 2009/08/10 08:40:10 guettler 00037 * changed güettler to guettler 00038 * 00039 * Revision 1.20 2009/08/10 08:37:17 guettler 00040 * try to set guettler in caption to correct characters 00041 * 00042 * Revision 1.19 2009/08/10 07:54:32 guettler 00043 * - uses new BackCaller implementation 00044 * - bugfix: avoid crash if noGraphics when getting HUDSM 00045 * 00046 * Revision 1.18 2009/08/07 13:27:18 martius 00047 * makePhysicalScene to create phyiscal scene independent of graphical scene 00048 * (to cope with new noGraphics implementation) 00049 * 00050 * Revision 1.17 2009/08/05 23:23:42 martius 00051 * corrected coding in "Guettler" 00052 * 00053 * Revision 1.16 2009/07/30 12:09:12 guettler 00054 * commented out unused variables 00055 * 00056 * Revision 1.15 2009/03/31 15:45:50 martius 00057 * caption is a std::string and can be changed on-line 00058 * 00059 * Revision 1.14 2009/03/27 06:21:31 guettler 00060 * CTRL +S changes now the shadow type in the simulation: cleaned up the code 00061 * 00062 * Revision 1.13 2009/03/25 15:44:23 guettler 00063 * ParallelSplitShadowMap: corrected light direction (using directional light), complete ground is now shadowed 00064 * 00065 * Revision 1.12 2009/01/20 17:27:34 martius 00066 * texture for background changeable from outside 00067 * 00068 * Revision 1.11 2008/09/11 15:24:01 martius 00069 * motioncallback resurrected 00070 * noContact substance 00071 * use slider center of the connecting objects for slider drawing 00072 * 00073 * Revision 1.10 2008/05/05 09:35:35 guettler 00074 * hud now displays if in pause mode 00075 * 00076 * Revision 1.9 2008/04/23 07:17:16 martius 00077 * makefiles cleaned 00078 * new also true realtime factor displayed, 00079 * warning if out of sync 00080 * drawinterval in full speed is 10 frames, independent of the speed 00081 * 00082 * Revision 1.8 2008/04/17 15:59:00 martius 00083 * OSG2 port finished 00084 * 00085 * Revision 1.7.2.5 2008/04/11 13:46:50 martius 00086 * quickMP multithreading included 00087 * 00088 * Revision 1.7.2.4 2008/04/11 10:41:35 martius 00089 * config file added 00090 * 00091 * Revision 1.7.2.3 2008/04/09 14:25:35 martius 00092 * shadow cmd line option 00093 * 00094 * Revision 1.7.2.2 2008/04/09 13:57:59 guettler 00095 * New ShadowTechnique added. 00096 * 00097 * Revision 1.7.2.1 2008/04/09 10:18:41 martius 00098 * fullscreen and window options done 00099 * fonts on hud changed 00100 * 00101 * Revision 1.7 2007/09/28 12:31:49 robot3 00102 * The HUDSM is not anymore deduced from StatisticalTools, so the statistics 00103 * can be updated independently from the HUD 00104 * addPhysicsCallbackable and addGraphicsCallbackable now exists in Simulation 00105 * 00106 * Revision 1.6 2007/09/28 10:24:05 robot3 00107 * The WindowStatisticsManager is now called HUDStatisticsManager 00108 * 00109 * Revision 1.5 2007/09/27 10:47:04 robot3 00110 * mathutils: moved abs to selforg/stl_adds.h 00111 * simulation,base: added callbackable support, 00112 * added WSM (HUDStatisticsManager) funtionality 00113 * 00114 * Revision 1.4 2007/08/29 13:07:48 martius 00115 * added HUD 00116 * 00117 * Revision 1.3 2006/09/20 15:30:47 martius 00118 * shadowsize, light 00119 * 00120 * Revision 1.2 2006/07/14 12:23:33 martius 00121 * selforg becomes HEAD 00122 * 00123 * Revision 1.1.2.7 2006/06/29 16:35:56 robot3 00124 * includes cleared up 00125 * 00126 * Revision 1.1.2.6 2006/05/28 22:14:56 martius 00127 * heightfield included 00128 * 00129 * Revision 1.1.2.5 2006/05/18 11:45:51 robot3 00130 * -shadowing the normal scene integrated (first version) 00131 * -note that there is a bug that the shadow disappears 00132 * after some time (e.g. 60 minutes) 00133 * 00134 * Revision 1.1.2.4 2006/01/31 15:45:02 martius 00135 * virtual destructor 00136 * 00137 * Revision 1.1.2.3 2006/01/12 14:21:00 martius 00138 * drawmode, material 00139 * 00140 * Revision 1.1.2.2 2005/12/09 16:54:16 martius 00141 * camera is woring now 00142 * 00143 * Revision 1.1.2.1 2005/12/06 17:40:59 martius 00144 * base class for simulation 00145 * 00146 * * 00147 ***************************************************************************/ 00148 #ifndef __BASE_H 00149 #define __BASE_H 00150 00151 #include <ode/ode.h> 00152 #include <osg/Transform> 00153 #include <osgText/Text> 00154 00155 #include "osghandle.h" 00156 #include "odehandle.h" 00157 00158 #include "hudstatistics.h" 00159 #include <selforg/backcaller.h> 00160 00161 namespace osgShadow 00162 { 00163 class ShadowedScene; 00164 } 00165 00166 namespace lpzrobots 00167 { 00168 00169 class MoveEarthySkyWithEyePointTransform : public osg::Transform 00170 { 00171 public: 00172 /** Get the transformation matrix which moves from local coords to world coords.*/ 00173 virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const; 00174 00175 /** Get the transformation matrix which moves from world coords to local coords.*/ 00176 virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const; 00177 }; 00178 00179 class Base : public BackCaller 00180 { 00181 public: 00182 Base(const std::string& caption="lpzrobots Simulator Martius, Der, Guettler"); 00183 00184 static const int PHYSICS_CALLBACKABLE = 1; //!< called each ode/physics step 00185 static const int GRAPHICS_CALLBACKABLE = 2; //!< called each osg/draw step 00186 00187 /// create the ground plane 00188 virtual void makePhysicsScene(); 00189 /// create the graphics of the sky and floor 00190 virtual osg::Group* makeScene(); 00191 virtual osg::Node* makeSky(); 00192 virtual osg::Node* makeGround(); 00193 virtual osg::Node* createHUD(); 00194 virtual osg::LightSource* makeLights(osg::StateSet* stateset); 00195 virtual osg::Group* createShadowedScene(osg::Node* shadowed, 00196 osg::Vec3 posOfLight, 00197 unsigned int unit); 00198 /** Shadow types: 00199 * 1 - ShadowVolume 00200 * 2 - ShadowTextue 00201 * 3 - ParallelSplitShadowMap 00202 * 4 - SoftShadowMap 00203 * 5 - ShadowMap 00204 */ 00205 virtual osgShadow::ShadowedScene* createShadowedScene(osg::Node* sceneToShadow, osg::LightSource* lightSource, int shadowType); 00206 00207 virtual void setGroundTexture(const char* filename) { 00208 this->groundTexture = filename; 00209 } 00210 00211 virtual void setCaption(const std::string& caption); 00212 00213 /** 00214 * Create HUDStatisticsManager and register it for being called back every step. 00215 * But do not display if the system is initialised with -nographics. 00216 * @return the actual HUDStatisticsManager 00217 */ 00218 virtual HUDStatisticsManager* getHUDSM(); 00219 00220 virtual ~Base(); 00221 00222 protected: 00223 virtual void setTimeStats(double time, double realtimefactor, 00224 double truerealtimefactor,bool pause); 00225 00226 /** 00227 * Changes the currently used shadow technique. 00228 * The switch is realized between: 00229 * 0 - NoShadow 00230 * 3 - ParallelSplitShadowMap 00231 * 4 - SoftShadowMap 00232 * 5 - ShadowMap (simple) 00233 * Currently not supported by this function: 00234 * 1 - ShadowVolume 00235 * 2 - ShadowTextue 00236 */ 00237 virtual void changeShadowTechnique(); 00238 00239 dGeomID ground; 00240 00241 00242 OsgHandle osgHandle; 00243 // ODE globals 00244 OdeHandle odeHandle; 00245 std::string caption; 00246 std::string groundTexture; 00247 00248 osg::Group* root; 00249 osgShadow::ShadowedScene* shadowedScene; 00250 osg::LightSource* lightSource; 00251 osg::Group* sceneToShadow; 00252 osg::Node* groundScene; 00253 osg::Transform* transform; 00254 osg::Node* hud; 00255 osgText::Text* timestats; 00256 osgText::Text* captionline; 00257 osgText::Text* statisticLine; 00258 00259 Primitive* plane; 00260 00261 /// this manager provides methods for displaying statistics on the graphical window! 00262 HUDStatisticsManager* hUDStatisticsManager; 00263 00264 std::list<Callbackable*> graphicsCallbackables; 00265 std::vector<Callbackable*> physicsCallbackables; // vector because we need to parallelise it 00266 00267 int ReceivesShadowTraversalMask; 00268 int CastsShadowTraversalMask; 00269 00270 // the types are double because they are configurable and stored to the cfg file 00271 int shadow; // set by child class Simulation 00272 int shadowTexSize; // set by child class Simulation 00273 bool useNVidia; // unused: if false use ATI Radeon! 00274 00275 00276 public: 00277 // Helper 00278 /// returns the index+1 if the list contains the given string or 0 if not 00279 static int contains(char **list, int len, const char *str); 00280 00281 }; 00282 } 00283 00284 #endif