b2World.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18 
19 #ifndef B2_WORLD_H
20 #define B2_WORLD_H
21 
22 #include <Box2D/Common/b2Math.h>
28 
29 struct b2AABB;
30 struct b2BodyDef;
31 struct b2Color;
32 struct b2JointDef;
33 class b2Body;
34 class b2Draw;
35 class b2Fixture;
36 class b2Joint;
37 
41 class b2World
42 {
43 public:
46  b2World(const b2Vec2& gravity);
47 
49  ~b2World();
50 
54 
58  void SetContactFilter(b2ContactFilter* filter);
59 
62  void SetContactListener(b2ContactListener* listener);
63 
67  void SetDebugDraw(b2Draw* debugDraw);
68 
72  b2Body* CreateBody(const b2BodyDef* def);
73 
78  void DestroyBody(b2Body* body);
79 
83  b2Joint* CreateJoint(const b2JointDef* def);
84 
87  void DestroyJoint(b2Joint* joint);
88 
94  void Step( float32 timeStep,
95  int32 velocityIterations,
96  int32 positionIterations);
97 
105  void ClearForces();
106 
108  void DrawDebugData();
109 
114  void QueryAABB(b2QueryCallback* callback, const b2AABB& aabb) const;
115 
122  void RayCast(b2RayCastCallback* callback, const b2Vec2& point1, const b2Vec2& point2) const;
123 
127  b2Body* GetBodyList();
128  const b2Body* GetBodyList() const;
129 
134  const b2Joint* GetJointList() const;
135 
142  const b2Contact* GetContactList() const;
143 
145  void SetAllowSleeping(bool flag);
146  bool GetAllowSleeping() const { return m_allowSleep; }
147 
149  void SetWarmStarting(bool flag) { m_warmStarting = flag; }
150  bool GetWarmStarting() const { return m_warmStarting; }
151 
153  void SetContinuousPhysics(bool flag) { m_continuousPhysics = flag; }
154  bool GetContinuousPhysics() const { return m_continuousPhysics; }
155 
157  void SetSubStepping(bool flag) { m_subStepping = flag; }
158  bool GetSubStepping() const { return m_subStepping; }
159 
161  int32 GetProxyCount() const;
162 
164  int32 GetBodyCount() const;
165 
167  int32 GetJointCount() const;
168 
170  int32 GetContactCount() const;
171 
173  int32 GetTreeHeight() const;
174 
176  int32 GetTreeBalance() const;
177 
180  float32 GetTreeQuality() const;
181 
183  void SetGravity(const b2Vec2& gravity);
184 
186  b2Vec2 GetGravity() const;
187 
189  bool IsLocked() const;
190 
192  void SetAutoClearForces(bool flag);
193 
195  bool GetAutoClearForces() const;
196 
200  void ShiftOrigin(const b2Vec2& newOrigin);
201 
203  const b2ContactManager& GetContactManager() const;
204 
206  const b2Profile& GetProfile() const;
207 
210  void Dump();
211 
212 private:
213 
214  // m_flags
215  enum
216  {
217  e_newFixture = 0x0001,
218  e_locked = 0x0002,
219  e_clearForces = 0x0004
220  };
221 
222  friend class b2Body;
223  friend class b2Fixture;
224  friend class b2ContactManager;
225  friend class b2Controller;
226 
227  void Solve(const b2TimeStep& step);
228  void SolveTOI(const b2TimeStep& step);
229 
230  void DrawJoint(b2Joint* joint);
231  void DrawShape(b2Fixture* shape, const b2Transform& xf, const b2Color& color);
232 
235 
237 
239 
242 
245 
248 
251 
252  // This is used to compute the time step ratio to
253  // support a variable time step.
255 
256  // These are for debugging the solver.
260 
262 
264 };
265 
267 {
268  return m_bodyList;
269 }
270 
271 inline const b2Body* b2World::GetBodyList() const
272 {
273  return m_bodyList;
274 }
275 
277 {
278  return m_jointList;
279 }
280 
281 inline const b2Joint* b2World::GetJointList() const
282 {
283  return m_jointList;
284 }
285 
287 {
289 }
290 
291 inline const b2Contact* b2World::GetContactList() const
292 {
294 }
295 
297 {
298  return m_bodyCount;
299 }
300 
302 {
303  return m_jointCount;
304 }
305 
307 {
309 }
310 
311 inline void b2World::SetGravity(const b2Vec2& gravity)
312 {
313  m_gravity = gravity;
314 }
315 
317 {
318  return m_gravity;
319 }
320 
321 inline bool b2World::IsLocked() const
322 {
323  return (m_flags & e_locked) == e_locked;
324 }
325 
326 inline void b2World::SetAutoClearForces(bool flag)
327 {
328  if (flag)
329  {
331  }
332  else
333  {
335  }
336 }
337 
339 inline bool b2World::GetAutoClearForces() const
340 {
341  return (m_flags & e_clearForces) == e_clearForces;
342 }
343 
345 {
346  return m_contactManager;
347 }
348 
349 inline const b2Profile& b2World::GetProfile() const
350 {
351  return m_profile;
352 }
353 
354 #endif
int32 m_bodyCount
Definition: b2World.h:243
b2Joint * GetJointList()
Definition: b2World.h:276
int32 GetBodyCount() const
Get the number of bodies.
Definition: b2World.h:296
void ClearForces()
Definition: b2World.cpp:965
void Step(float32 timeStep, int32 velocityIterations, int32 positionIterations)
Definition: b2World.cpp:897
int32 GetProxyCount() const
Get the number of broad-phase proxies.
Definition: b2World.cpp:1239
bool GetAutoClearForces() const
Get the flag that controls automatic clearing of forces after each time step.
Definition: b2World.h:339
b2ContactManager m_contactManager
Definition: b2World.h:238
void SetAllowSleeping(bool flag)
Enable/disable sleep.
Definition: b2World.cpp:368
Joint definitions are used to construct joints.
Definition: b2Joint.h:74
const b2Profile & GetProfile() const
Get the current profile.
Definition: b2World.h:349
void DrawShape(b2Fixture *shape, const b2Transform &xf, const b2Color &color)
Definition: b2World.cpp:1031
bool GetWarmStarting() const
Definition: b2World.h:150
void SetGravity(const b2Vec2 &gravity)
Change the global gravity vector.
Definition: b2World.h:311
int32 GetJointCount() const
Get the number of joints.
Definition: b2World.h:301
bool GetAllowSleeping() const
Definition: b2World.h:146
bool m_continuousPhysics
Definition: b2World.h:258
b2Draw * g_debugDraw
Definition: b2World.h:250
b2Body * m_bodyList
Definition: b2World.h:240
int32 m_jointCount
Definition: b2World.h:244
float32 GetTreeQuality() const
Definition: b2World.cpp:1254
b2World(const b2Vec2 &gravity)
Definition: b2World.cpp:37
This is an internal structure.
Definition: b2TimeStep.h:38
void SetDebugDraw(b2Draw *debugDraw)
Definition: b2World.cpp:102
void DestroyJoint(b2Joint *joint)
Definition: b2World.cpp:272
bool m_subStepping
Definition: b2World.h:259
void SetSubStepping(bool flag)
Enable/disable single stepped continuous physics. For testing.
Definition: b2World.h:157
A 2D column vector.
Definition: b2Math.h:53
void ShiftOrigin(const b2Vec2 &newOrigin)
Definition: b2World.cpp:1259
int32 GetTreeBalance() const
Get the balance of the dynamic tree.
Definition: b2World.cpp:1249
Color for debug drawing. Each value has the range [0,1].
Definition: b2Draw.h:25
signed int int32
Definition: b2Settings.h:31
float32 m_inv_dt0
Definition: b2World.h:254
void Solve(const b2TimeStep &step)
Definition: b2World.cpp:386
void SolveTOI(const b2TimeStep &step)
Definition: b2World.cpp:577
A rigid body. These are created via b2World::CreateBody.
Definition: b2Body.h:126
Definition: b2Draw.h:35
int32 GetContactCount() const
Get the number of contacts (each may have 0 or more contact points).
Definition: b2World.h:306
void QueryAABB(b2QueryCallback *callback, const b2AABB &aabb) const
Definition: b2World.cpp:986
Profiling data. Times are in milliseconds.
Definition: b2TimeStep.h:25
b2Joint * m_jointList
Definition: b2World.h:241
b2Contact * m_contactList
b2Joint * CreateJoint(const b2JointDef *def)
Definition: b2World.cpp:212
void RayCast(b2RayCastCallback *callback, const b2Vec2 &point1, const b2Vec2 &point2) const
Definition: b2World.cpp:1019
b2Profile m_profile
Definition: b2World.h:263
~b2World()
Destruct the world. All physics entities are destroyed and all heap memory is released.
Definition: b2World.cpp:66
void DrawJoint(b2Joint *joint)
Definition: b2World.cpp:1094
bool m_warmStarting
Definition: b2World.h:257
b2Contact * GetContactList()
Definition: b2World.h:286
void SetContactListener(b2ContactListener *listener)
Definition: b2World.cpp:97
void SetContinuousPhysics(bool flag)
Enable/disable continuous physics. For testing.
Definition: b2World.h:153
bool GetSubStepping() const
Definition: b2World.h:158
void Dump()
Definition: b2World.cpp:1282
b2Body * GetBodyList()
Definition: b2World.h:266
b2StackAllocator m_stackAllocator
Definition: b2World.h:234
void DrawDebugData()
Call this to draw shapes and other debug draw data. This is intentionally non-const.
Definition: b2World.cpp:1135
int32 m_flags
Definition: b2World.h:236
b2Vec2 GetGravity() const
Get the global gravity vector.
Definition: b2World.h:316
An axis aligned bounding box.
Definition: b2Collision.h:162
bool m_allowSleep
Definition: b2World.h:247
b2DestructionListener * m_destructionListener
Definition: b2World.h:249
void SetDestructionListener(b2DestructionListener *listener)
Definition: b2World.cpp:87
bool GetContinuousPhysics() const
Definition: b2World.h:154
friend class b2Controller
Definition: b2World.h:225
void DestroyBody(b2Body *body)
Definition: b2World.cpp:131
b2BlockAllocator m_blockAllocator
Definition: b2World.h:233
const b2ContactManager & GetContactManager() const
Get the contact manager for testing.
Definition: b2World.h:344
void SetAutoClearForces(bool flag)
Set flag to control automatic clearing of forces after each time step.
Definition: b2World.h:326
b2Vec2 m_gravity
Definition: b2World.h:246
int32 GetTreeHeight() const
Get the height of the dynamic tree.
Definition: b2World.cpp:1244
void SetContactFilter(b2ContactFilter *filter)
Definition: b2World.cpp:92
b2Body * CreateBody(const b2BodyDef *def)
Definition: b2World.cpp:107
void SetWarmStarting(bool flag)
Enable/disable warm starting. For testing.
Definition: b2World.h:149
float float32
Definition: b2Settings.h:35
bool m_stepComplete
Definition: b2World.h:261
bool IsLocked() const
Is the world locked (in the middle of a time step).
Definition: b2World.h:321


mvsim
Author(s):
autogenerated on Thu Jun 6 2019 19:36:40