- Main Page
- Classes
- Files

- File List
- File Members

# Box2D/Box2D/Dynamics/b2World.h

Go to the documentation of this file.

    00001 /*
    00002 * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
    00003 *
    00004 * This software is provided 'as-is', without any express or implied
    00005 * warranty.  In no event will the authors be held liable for any damages
    00006 * arising from the use of this software.
    00007 * Permission is granted to anyone to use this software for any purpose,
    00008 * including commercial applications, and to alter it and redistribute it
    00009 * freely, subject to the following restrictions:
    00010 * 1. The origin of this software must not be misrepresented; you must not
    00011 * claim that you wrote the original software. If you use this software
    00012 * in a product, an acknowledgment in the product documentation would be
    00013 * appreciated but is not required.
    00014 * 2. Altered source versions must be plainly marked as such, and must not be
    00015 * misrepresented as being the original software.
    00016 * 3. This notice may not be removed or altered from any source distribution.
    00017 */
    00018
    00019 #ifndef B2_WORLD_H
    00020 #define B2_WORLD_H
    00021
    00022 #include <Box2D/Common/b2Math.h>
    00023 #include <Box2D/Common/b2BlockAllocator.h>
    00024 #include <Box2D/Common/b2StackAllocator.h>
    00025 #include <Box2D/Dynamics/b2ContactManager.h>
    00026 #include <Box2D/Dynamics/b2WorldCallbacks.h>
    00027
    00028 struct b2AABB;
    00029 struct b2BodyDef;
    00030 struct b2JointDef;
    00031 struct b2TimeStep;
    00032 class b2Body;
    00033 class b2Fixture;
    00034 class b2Joint;
    00035
    00039 class b2World
    00040 {
    00041 public:
    00045         b2World(const b2Vec2& gravity, bool doSleep);
    00046
    00048         ~b2World();
    00049
    00052         void SetDestructionListener(b2DestructionListener* listener);
    00053
    00057         void SetContactFilter(b2ContactFilter* filter);
    00058
    00061         void SetContactListener(b2ContactListener* listener);
    00062
    00066         void SetDebugDraw(b2DebugDraw* debugDraw);
    00067
    00071         b2Body* CreateBody(const b2BodyDef* def);
    00072
    00077         void DestroyBody(b2Body* body);
    00078
    00082         b2Joint* CreateJoint(const b2JointDef* def);
    00083
    00086         void DestroyJoint(b2Joint* joint);
    00087
    00093         void Step(      float32 timeStep,
    00094                                 int32 velocityIterations,
    00095                                 int32 positionIterations);
    00096
    00101         void ClearForces();
    00102
    00104         void DrawDebugData();
    00105
    00110         void QueryAABB(b2QueryCallback* callback, const b2AABB& aabb) const;
    00111
    00118         void RayCast(b2RayCastCallback* callback, const b2Vec2& point1, const b2Vec2& point2) const;
    00119
    00123         b2Body* GetBodyList();
    00124
    00128         b2Joint* GetJointList();
    00129
    00134         b2Contact* GetContactList();
    00135
    00137         void SetWarmStarting(bool flag) { m_warmStarting = flag; }
    00138
    00140         void SetContinuousPhysics(bool flag) { m_continuousPhysics = flag; }
    00141
    00143         int32 GetProxyCount() const;
    00144
    00146         int32 GetBodyCount() const;
    00147
    00149         int32 GetJointCount() const;
    00150
    00152         int32 GetContactCount() const;
    00153
    00155         void SetGravity(const b2Vec2& gravity);
    00156
    00158         b2Vec2 GetGravity() const;
    00159
    00161         bool IsLocked() const;
    00162
    00164         void SetAutoClearForces(bool flag);
    00165
    00167         bool GetAutoClearForces() const;
    00168
    00169 private:
    00170
    00171         // m_flags
    00172         enum
    00173         {
    00174                 e_newFixture    = 0x0001,
    00175                 e_locked                = 0x0002,
    00176                 e_clearForces   = 0x0004,
    00177         };
    00178
    00179         friend class b2Body;
    00180         friend class b2ContactManager;
    00181         friend class b2Controller;
    00182
    00183         void Solve(const b2TimeStep& step);
    00184         void SolveTOI();
    00185         void SolveTOI(b2Body* body);
    00186
    00187         void DrawJoint(b2Joint* joint);
    00188         void DrawShape(b2Fixture* shape, const b2Transform& xf, const b2Color& color);
    00189
    00190         b2BlockAllocator m_blockAllocator;
    00191         b2StackAllocator m_stackAllocator;
    00192
    00193         int32 m_flags;
    00194
    00195         b2ContactManager m_contactManager;
    00196
    00197         b2Body* m_bodyList;
    00198         b2Joint* m_jointList;
    00199
    00200         int32 m_bodyCount;
    00201         int32 m_jointCount;
    00202
    00203         b2Vec2 m_gravity;
    00204         bool m_allowSleep;
    00205
    00206         b2Body* m_groundBody;
    00207
    00208         b2DestructionListener* m_destructionListener;
    00209         b2DebugDraw* m_debugDraw;
    00210
    00211         // This is used to compute the time step ratio to
    00212         // support a variable time step.
    00213         float32 m_inv_dt0;
    00214
    00215         // This is for debugging the solver.
    00216         bool m_warmStarting;
    00217
    00218         // This is for debugging the solver.
    00219         bool m_continuousPhysics;
    00220 };
    00221
    00222 inline b2Body* b2World::GetBodyList()
    00223 {
    00224         return m_bodyList;
    00225 }
    00226
    00227 inline b2Joint* b2World::GetJointList()
    00228 {
    00229         return m_jointList;
    00230 }
    00231
    00232 inline b2Contact* b2World::GetContactList()
    00233 {
    00234         return m_contactManager.m_contactList;
    00235 }
    00236
    00237 inline int32 b2World::GetBodyCount() const
    00238 {
    00239         return m_bodyCount;
    00240 }
    00241
    00242 inline int32 b2World::GetJointCount() const
    00243 {
    00244         return m_jointCount;
    00245 }
    00246
    00247 inline int32 b2World::GetContactCount() const
    00248 {
    00249         return m_contactManager.m_contactCount;
    00250 }
    00251
    00252 inline void b2World::SetGravity(const b2Vec2& gravity)
    00253 {
    00254         m_gravity = gravity;
    00255 }
    00256
    00257 inline b2Vec2 b2World::GetGravity() const
    00258 {
    00259         return m_gravity;
    00260 }
    00261
    00262 inline bool b2World::IsLocked() const
    00263 {
    00264         return (m_flags & e_locked) == e_locked;
    00265 }
    00266
    00267 inline void b2World::SetAutoClearForces(bool flag)
    00268 {
    00269         if (flag)
    00270         {
    00271                 m_flags |= e_clearForces;
    00272         }
    00273         else
    00274         {
    00275                 m_flags &= ~e_clearForces;
    00276         }
    00277 }
    00278
    00280 inline bool b2World::GetAutoClearForces() const
    00281 {
    00282         return (m_flags & e_clearForces) == e_clearForces;
    00283 }
    00284
    00285 #endif