Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogreode/include/OgreOdeWorld.h @ 21

Last change on this file since 21 was 21, checked in by nicolasc, 16 years ago

added ogreode and Colladaplugin

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