[1919] | 1 | #ifndef _OGREODEWORLD_H_ |
---|
| 2 | #define _OGREODEWORLD_H_ |
---|
| 3 | |
---|
| 4 | #include "OgreOdePreReqs.h" |
---|
| 5 | |
---|
| 6 | #include <map> |
---|
[1923] | 7 | #include <OgreVector3.h> |
---|
[1919] | 8 | |
---|
[1923] | 9 | #include "OgreOdeMaintainedList.h" |
---|
| 10 | #include "OgreOdeBody.h" |
---|
| 11 | #include "OgreOdeJoint.h" |
---|
| 12 | #include "OgreOdeGeometry.h" |
---|
| 13 | #include "OgreOdeSpace.h" |
---|
| 14 | |
---|
[1919] | 15 | namespace OgreOde |
---|
| 16 | { |
---|
| 17 | /** The main class which you will use to simulate your world. |
---|
| 18 | * |
---|
| 19 | * This is the core class of OgreOde, it is directly analogous to the ODE world except that |
---|
| 20 | * in OgreOde you can have only one world, which is why it is Singleton. |
---|
| 21 | * |
---|
| 22 | * A World is a container for all the bodies and geometries in you simulation. You also |
---|
| 23 | * use it to set global options for things like gravity, ERP, CFM and automatic sleeping. |
---|
| 24 | * Also, the World is what you step when you want to advance your simulation by a certain time |
---|
| 25 | * period. |
---|
| 26 | */ |
---|
| 27 | class _OgreOdeExport World |
---|
| 28 | { |
---|
| 29 | friend class Body; |
---|
| 30 | friend class JointGroup; |
---|
| 31 | friend class Joint; |
---|
| 32 | friend class Space; |
---|
| 33 | friend class Geometry; |
---|
| 34 | friend class StepHandler; |
---|
| 35 | |
---|
| 36 | public: |
---|
| 37 | /** Construct a new World. |
---|
| 38 | * |
---|
| 39 | * You will need to call this to create the World into which you cabn place your physical objects. |
---|
| 40 | * The World requires a reference to the scene manager you are using in order to create things |
---|
| 41 | * like nodes for debug objects and to obtain configuration options for world geometry. |
---|
| 42 | * |
---|
| 43 | * \param manager The scene manager you are using. |
---|
| 44 | */ |
---|
| 45 | World(Ogre::SceneManager* manager); |
---|
| 46 | ~World(); |
---|
| 47 | |
---|
| 48 | void setGravity(const Ogre::Vector3& gravity = Ogre::Vector3::ZERO); |
---|
| 49 | const Ogre::Vector3& getGravity(); |
---|
| 50 | |
---|
| 51 | void setHistorySize (size_t historySize); |
---|
| 52 | size_t getHistorySize () const; |
---|
| 53 | |
---|
| 54 | void setERP(Ogre::Real erp = 0.2); |
---|
| 55 | Ogre::Real getERP(); |
---|
| 56 | void setCFM(Ogre::Real cfm = 10e-5); |
---|
| 57 | Ogre::Real getCFM(); |
---|
| 58 | |
---|
| 59 | void setContactCorrectionVelocity(Ogre::Real velocity = 0.1); |
---|
| 60 | void setContactSurfaceLayer(Ogre::Real layer = 0.001); |
---|
| 61 | |
---|
| 62 | void setAutoSleep(bool auto_sleep = false); |
---|
| 63 | bool getAutoSleep(); |
---|
| 64 | void setAutoSleepLinearThreshold(Ogre::Real linear_threshold = 0.01); |
---|
| 65 | Ogre::Real getAutoSleepLinearThreshold(); |
---|
| 66 | void setAutoSleepAngularThreshold(Ogre::Real angular_threshold = 0.01); |
---|
| 67 | Ogre::Real getAutoSleepAngularThreshold(); |
---|
| 68 | void setAutoSleepSteps(int steps = 10); |
---|
| 69 | int getAutoSleepSteps(); |
---|
| 70 | void setAutoSleepTime(Ogre::Real time = 0); |
---|
| 71 | Ogre::Real getAutoSleepTime(); |
---|
| 72 | void setAutoSleepAverageSamplesCount(unsigned int time = 10); |
---|
| 73 | size_t getAutoSleepAverageSamplesCount(); |
---|
| 74 | inline void step(Ogre::Real stepsize); |
---|
| 75 | inline void quickStep(Ogre::Real stepsize); |
---|
| 76 | inline void fastStep(Ogre::Real stepsize); |
---|
| 77 | |
---|
| 78 | void setQuickStepIterations(int iterations); |
---|
| 79 | int getQuickStepIterations(); |
---|
| 80 | |
---|
| 81 | Body* findBody(Ogre::SceneNode* node); |
---|
| 82 | Body* findBody(const Ogre::String& name); |
---|
| 83 | |
---|
| 84 | inline void clearContacts(); |
---|
| 85 | |
---|
| 86 | void setCollisionListener(CollisionListener* collision_listener); |
---|
| 87 | CollisionListener* getCollisionListener(); |
---|
| 88 | |
---|
| 89 | void setShowDebugGeometries(bool show); |
---|
| 90 | bool getShowDebugGeometries(){return _show_debug_geoms;} |
---|
| 91 | |
---|
| 92 | void setShowDebugContact(bool show); |
---|
| 93 | bool getShowDebugContact(){return _show_debug_contact;} |
---|
| 94 | |
---|
| 95 | inline void notifyGeometry(Body* body); |
---|
| 96 | |
---|
| 97 | Space* getDefaultSpace(){return _default_space;} |
---|
| 98 | void setDefaultSpace(Space* space); |
---|
| 99 | |
---|
| 100 | inline Ogre::SceneManager* getSceneManager(){return _manager;} |
---|
| 101 | |
---|
| 102 | void setDamping(Ogre::Real linear_damping,Ogre::Real angular_damping); |
---|
| 103 | Ogre::Real getLinearDamping(); |
---|
| 104 | Ogre::Real getAngularDamping(); |
---|
| 105 | |
---|
| 106 | inline void synchronise(); |
---|
| 107 | |
---|
| 108 | inline void updateDrawState(); |
---|
| 109 | inline void updatePreviousState(); |
---|
| 110 | inline void updateCurrentState(); |
---|
| 111 | inline void interpolateDrawState(const Ogre::Real alpha); |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | inline MaintainedList<Body> &getBodyList() {return _body_list;} |
---|
| 115 | inline MaintainedList<Joint> &getJointList() {return _joint_list;} |
---|
| 116 | inline MaintainedList<JointGroup> &getJointGroupList(){return _joint_group_list;} |
---|
| 117 | inline MaintainedList<Geometry> &getGeometryList() {return _geometry_list;} |
---|
| 118 | inline MaintainedList<Space> &getSpaceList() {return _space_list;} |
---|
| 119 | |
---|
| 120 | inline dWorldID getWorldID(); |
---|
| 121 | protected: |
---|
| 122 | |
---|
| 123 | inline dJointGroupID getContactGroupID(); |
---|
| 124 | static void collisionCallback(void *data, |
---|
| 125 | dGeomID geom_a, |
---|
| 126 | dGeomID geom_b); |
---|
| 127 | |
---|
| 128 | protected: |
---|
| 129 | dWorldID _world; |
---|
| 130 | dJointGroupID _contacts; |
---|
| 131 | |
---|
| 132 | Space* _default_space; |
---|
| 133 | |
---|
| 134 | static CollisionListener* _collision_listener; |
---|
| 135 | |
---|
| 136 | MaintainedList<Body> _body_list; |
---|
| 137 | MaintainedList<Joint> _joint_list; |
---|
| 138 | MaintainedList<JointGroup> _joint_group_list; |
---|
| 139 | MaintainedList<Geometry> _geometry_list; |
---|
| 140 | MaintainedList<Space> _space_list; |
---|
| 141 | |
---|
| 142 | bool _show_debug_geoms; |
---|
| 143 | bool _show_debug_contact; |
---|
| 144 | |
---|
| 145 | Ogre::SceneManager* _manager; |
---|
| 146 | |
---|
| 147 | Ogre::Vector3 _gravity; |
---|
| 148 | dReal _linear_damping,_angular_damping; |
---|
| 149 | size_t _history_size; |
---|
| 150 | }; |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | //------------------------------------------------------------------------------------------------ |
---|
| 154 | //INLINED Methods |
---|
| 155 | //------------------------------------------------------------------------------------------------ |
---|
| 156 | //------------------------------------------------------------------------------------------------ |
---|
| 157 | inline dWorldID World::getWorldID() |
---|
| 158 | { |
---|
| 159 | return _world; |
---|
| 160 | } |
---|
| 161 | //------------------------------------------------------------------------------------------------ |
---|
| 162 | inline dJointGroupID World::getContactGroupID() |
---|
| 163 | { |
---|
| 164 | return _contacts; |
---|
| 165 | } |
---|
| 166 | //------------------------------------------------------------------------------------------------ |
---|
| 167 | inline void World::notifyGeometry(Body* body) |
---|
| 168 | { |
---|
| 169 | _geometry_list.notify(body); |
---|
| 170 | } |
---|
| 171 | //------------------------------------------------------------------------------------------------ |
---|
| 172 | inline void World::synchronise() |
---|
| 173 | { |
---|
| 174 | _body_list.synchronise (); |
---|
| 175 | } |
---|
| 176 | //------------------------------------------------------------------------------------------------ |
---|
| 177 | inline void World::updateDrawState() |
---|
| 178 | { |
---|
| 179 | _body_list.updateDrawState (); |
---|
| 180 | if (_show_debug_contact) |
---|
| 181 | _geometry_list.updateDebugContact(); |
---|
| 182 | } |
---|
| 183 | //------------------------------------------------------------------------------------------------ |
---|
| 184 | inline void World::interpolateDrawState(const Ogre::Real alpha) |
---|
| 185 | { |
---|
| 186 | _body_list.interpolateDrawState(alpha); |
---|
| 187 | if (_show_debug_contact) |
---|
| 188 | _geometry_list.updateDebugContact(); |
---|
| 189 | } |
---|
| 190 | //------------------------------------------------------------------------------------------------ |
---|
| 191 | inline void World::updatePreviousState() |
---|
| 192 | { |
---|
| 193 | _body_list.updatePreviousState(); |
---|
| 194 | } |
---|
| 195 | //------------------------------------------------------------------------------------------------ |
---|
| 196 | inline void World::updateCurrentState() |
---|
| 197 | { |
---|
| 198 | _body_list.updateCurrentState (); |
---|
| 199 | } |
---|
| 200 | //------------------------------------------------------------------------------------------------ |
---|
| 201 | inline void World::clearContacts() |
---|
| 202 | { |
---|
| 203 | dJointGroupEmpty(_contacts); |
---|
| 204 | } |
---|
| 205 | //------------------------------------------------------------------------------------------------ |
---|
| 206 | inline void World::step(Ogre::Real stepsize) |
---|
| 207 | { |
---|
| 208 | dWorldStep(_world,(dReal)stepsize); |
---|
| 209 | } |
---|
| 210 | //------------------------------------------------------------------------------------------------ |
---|
| 211 | inline void World::quickStep(Ogre::Real stepsize) |
---|
| 212 | { |
---|
| 213 | dWorldQuickStep(_world,(dReal)stepsize); |
---|
| 214 | } |
---|
| 215 | //------------------------------------------------------------------------------------------------ |
---|
| 216 | inline void World::fastStep(Ogre::Real stepsize) |
---|
| 217 | { |
---|
| 218 | dWorldStepFast1(_world,(dReal)stepsize,20); |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | #endif |
---|