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.11 2008/09/11 15:24:01 martius 00028 * motioncallback resurrected 00029 * noContact substance 00030 * use slider center of the connecting objects for slider drawing 00031 * 00032 * Revision 1.10 2008/05/05 09:35:35 guettler 00033 * hud now displays if in pause mode 00034 * 00035 * Revision 1.9 2008/04/23 07:17:16 martius 00036 * makefiles cleaned 00037 * new also true realtime factor displayed, 00038 * warning if out of sync 00039 * drawinterval in full speed is 10 frames, independent of the speed 00040 * 00041 * Revision 1.8 2008/04/17 15:59:00 martius 00042 * OSG2 port finished 00043 * 00044 * Revision 1.7.2.5 2008/04/11 13:46:50 martius 00045 * quickMP multithreading included 00046 * 00047 * Revision 1.7.2.4 2008/04/11 10:41:35 martius 00048 * config file added 00049 * 00050 * Revision 1.7.2.3 2008/04/09 14:25:35 martius 00051 * shadow cmd line option 00052 * 00053 * Revision 1.7.2.2 2008/04/09 13:57:59 guettler 00054 * New ShadowTechnique added. 00055 * 00056 * Revision 1.7.2.1 2008/04/09 10:18:41 martius 00057 * fullscreen and window options done 00058 * fonts on hud changed 00059 * 00060 * Revision 1.7 2007/09/28 12:31:49 robot3 00061 * The HUDSM is not anymore deduced from StatisticalTools, so the statistics 00062 * can be updated independently from the HUD 00063 * addPhysicsCallbackable and addGraphicsCallbackable now exists in Simulation 00064 * 00065 * Revision 1.6 2007/09/28 10:24:05 robot3 00066 * The WindowStatisticsManager is now called HUDStatisticsManager 00067 * 00068 * Revision 1.5 2007/09/27 10:47:04 robot3 00069 * mathutils: moved abs to selforg/stl_adds.h 00070 * simulation,base: added callbackable support, 00071 * added WSM (HUDStatisticsManager) funtionality 00072 * 00073 * Revision 1.4 2007/08/29 13:07:48 martius 00074 * added HUD 00075 * 00076 * Revision 1.3 2006/09/20 15:30:47 martius 00077 * shadowsize, light 00078 * 00079 * Revision 1.2 2006/07/14 12:23:33 martius 00080 * selforg becomes HEAD 00081 * 00082 * Revision 1.1.2.7 2006/06/29 16:35:56 robot3 00083 * includes cleared up 00084 * 00085 * Revision 1.1.2.6 2006/05/28 22:14:56 martius 00086 * heightfield included 00087 * 00088 * Revision 1.1.2.5 2006/05/18 11:45:51 robot3 00089 * -shadowing the normal scene integrated (first version) 00090 * -note that there is a bug that the shadow disappears 00091 * after some time (e.g. 60 minutes) 00092 * 00093 * Revision 1.1.2.4 2006/01/31 15:45:02 martius 00094 * virtual destructor 00095 * 00096 * Revision 1.1.2.3 2006/01/12 14:21:00 martius 00097 * drawmode, material 00098 * 00099 * Revision 1.1.2.2 2005/12/09 16:54:16 martius 00100 * camera is woring now 00101 * 00102 * Revision 1.1.2.1 2005/12/06 17:40:59 martius 00103 * base class for simulation 00104 * 00105 * * 00106 ***************************************************************************/ 00107 #ifndef __BASE_H 00108 #define __BASE_H 00109 00110 #include<ode/ode.h> 00111 #include<osg/Transform> 00112 #include <osgText/Text> 00113 00114 #include "osghandle.h" 00115 #include "odehandle.h" 00116 00117 #include "hudstatistics.h" 00118 00119 class osg::Node; 00120 class Callbackable; 00121 00122 00123 namespace lpzrobots { 00124 00125 class MoveEarthySkyWithEyePointTransform : public osg::Transform { 00126 public: 00127 /** Get the transformation matrix which moves from local coords to world coords.*/ 00128 virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const; 00129 00130 /** Get the transformation matrix which moves from world coords to local coords.*/ 00131 virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const; 00132 }; 00133 00134 class Base { 00135 public: 00136 Base(const char* caption=0); 00137 00138 virtual osg::Group* makeScene(); 00139 virtual osg::Node* makeSky(); 00140 virtual osg::Node* makeGround(); 00141 virtual osg::Node* createHUD(); 00142 virtual osg::LightSource* makeLights(osg::StateSet* stateset); 00143 virtual osg::Group* createShadowedScene(osg::Node* shadowed, 00144 osg::Vec3 posOfLight, 00145 unsigned int unit); 00146 /** Shadow types: 00147 * 1 - ShadowVolume 00148 * 2 - ShadowTextue 00149 * 3 - ParallelSplitShadowMap 00150 * 4 - SoftShadowMap 00151 * 5 - ShadowMap 00152 */ 00153 virtual osg::Group* createShadowedScene(osg::Node* sceneToShadow); 00154 00155 00156 00157 virtual void setCaption(const char* caption) { 00158 this->caption = caption; 00159 } 00160 00161 /** adds an Callbackable object for getting a callback every step. 00162 * note that the object are not called back in this class. This must 00163 * be done in the deduced class (here: Simulation). 00164 */ 00165 virtual void addGraphicsCallbackable(Callbackable* callbackable); 00166 00167 virtual void addPhysicsCallbackable(Callbackable* callbackable); 00168 00169 virtual HUDStatisticsManager* getHUDSM() { return this->hUDStatisticsManager; } 00170 00171 virtual ~Base(); 00172 00173 protected: 00174 virtual void setTimeStats(double time, double realtimefactor, 00175 double truerealtimefactor,bool pause); 00176 00177 dGeomID ground; 00178 00179 00180 OsgHandle osgHandle; 00181 // ODE globals 00182 OdeHandle odeHandle; 00183 const char* caption; 00184 00185 osg::Group* root; 00186 osg::Node* hud; 00187 osgText::Text* timestats; 00188 osgText::Text* statisticLine; 00189 00190 /// this manager provides methods for displaying statistics on the graphical window! 00191 HUDStatisticsManager* hUDStatisticsManager; 00192 00193 std::list<Callbackable*> graphicsCallbackables; 00194 std::vector<Callbackable*> physicsCallbackables; // vector because we need to parallelise it 00195 00196 int ReceivesShadowTraversalMask; 00197 int CastsShadowTraversalMask; 00198 00199 // the types are double because they are configurable and stored to the cfg file 00200 double shadow; // set by child class Simulation 00201 double shadowTexSize; // set by child class Simulation 00202 double useNVidia; // if 0 use ATI Radeon! 00203 00204 00205 public: 00206 // Helper 00207 /// returns the index+1 if the list contains the given string or 0 if not 00208 static int contains(char **list, int len, const char *str); 00209 00210 00211 }; 00212 } 00213 00214 #endif