|
@@ -1,46 +1,52 @@
|
|
|
-/*
|
|
|
-* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
|
|
|
-*
|
|
|
-* This software is provided 'as-is', without any express or implied
|
|
|
-* warranty. In no event will the authors be held liable for any damages
|
|
|
-* arising from the use of this software.
|
|
|
-* Permission is granted to anyone to use this software for any purpose,
|
|
|
-* including commercial applications, and to alter it and redistribute it
|
|
|
-* freely, subject to the following restrictions:
|
|
|
-* 1. The origin of this software must not be misrepresented; you must not
|
|
|
-* claim that you wrote the original software. If you use this software
|
|
|
-* in a product, an acknowledgment in the product documentation would be
|
|
|
-* appreciated but is not required.
|
|
|
-* 2. Altered source versions must be plainly marked as such, and must not be
|
|
|
-* misrepresented as being the original software.
|
|
|
-* 3. This notice may not be removed or altered from any source distribution.
|
|
|
-*/
|
|
|
-
|
|
|
-#include <Box2D/Dynamics/b2World.h>
|
|
|
-#include <Box2D/Dynamics/b2Body.h>
|
|
|
-#include <Box2D/Dynamics/b2Fixture.h>
|
|
|
-#include <Box2D/Dynamics/b2Island.h>
|
|
|
-#include <Box2D/Dynamics/Joints/b2PulleyJoint.h>
|
|
|
-#include <Box2D/Dynamics/Contacts/b2Contact.h>
|
|
|
-#include <Box2D/Dynamics/Contacts/b2ContactSolver.h>
|
|
|
-#include <Box2D/Collision/b2Collision.h>
|
|
|
-#include <Box2D/Collision/b2BroadPhase.h>
|
|
|
-#include <Box2D/Collision/Shapes/b2CircleShape.h>
|
|
|
-#include <Box2D/Collision/Shapes/b2EdgeShape.h>
|
|
|
-#include <Box2D/Collision/Shapes/b2ChainShape.h>
|
|
|
-#include <Box2D/Collision/Shapes/b2PolygonShape.h>
|
|
|
-#include <Box2D/Collision/b2TimeOfImpact.h>
|
|
|
-#include <Box2D/Common/b2Draw.h>
|
|
|
-#include <Box2D/Common/b2Timer.h>
|
|
|
+// MIT License
|
|
|
+
|
|
|
+// Copyright (c) 2019 Erin Catto
|
|
|
+
|
|
|
+// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
+// of this software and associated documentation files (the "Software"), to deal
|
|
|
+// in the Software without restriction, including without limitation the rights
|
|
|
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
+// copies of the Software, and to permit persons to whom the Software is
|
|
|
+// furnished to do so, subject to the following conditions:
|
|
|
+
|
|
|
+// The above copyright notice and this permission notice shall be included in all
|
|
|
+// copies or substantial portions of the Software.
|
|
|
+
|
|
|
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
+// SOFTWARE.
|
|
|
+
|
|
|
+#include "b2_contact_solver.h"
|
|
|
+#include "b2_island.h"
|
|
|
+
|
|
|
+#include "box2d/b2_body.h"
|
|
|
+#include "box2d/b2_broad_phase.h"
|
|
|
+#include "box2d/b2_chain_shape.h"
|
|
|
+#include "box2d/b2_circle_shape.h"
|
|
|
+#include "box2d/b2_collision.h"
|
|
|
+#include "box2d/b2_contact.h"
|
|
|
+#include "box2d/b2_draw.h"
|
|
|
+#include "box2d/b2_edge_shape.h"
|
|
|
+#include "box2d/b2_fixture.h"
|
|
|
+#include "box2d/b2_polygon_shape.h"
|
|
|
+#include "box2d/b2_pulley_joint.h"
|
|
|
+#include "box2d/b2_time_of_impact.h"
|
|
|
+#include "box2d/b2_timer.h"
|
|
|
+#include "box2d/b2_world.h"
|
|
|
+
|
|
|
#include <new>
|
|
|
|
|
|
b2World::b2World(const b2Vec2& gravity)
|
|
|
{
|
|
|
- m_destructionListener = NULL;
|
|
|
- g_debugDraw = NULL;
|
|
|
+ m_destructionListener = nullptr;
|
|
|
+ m_debugDraw = nullptr;
|
|
|
|
|
|
- m_bodyList = NULL;
|
|
|
- m_jointList = NULL;
|
|
|
+ m_bodyList = nullptr;
|
|
|
+ m_jointList = nullptr;
|
|
|
|
|
|
m_bodyCount = 0;
|
|
|
m_jointCount = 0;
|
|
@@ -54,7 +60,9 @@ b2World::b2World(const b2Vec2& gravity)
|
|
|
m_allowSleep = true;
|
|
|
m_gravity = gravity;
|
|
|
|
|
|
- m_flags = e_clearForces;
|
|
|
+ m_newContacts = false;
|
|
|
+ m_locked = false;
|
|
|
+ m_clearForces = true;
|
|
|
|
|
|
m_inv_dt0 = 0.0f;
|
|
|
|
|
@@ -101,7 +109,7 @@ void b2World::SetContactListener(b2ContactListener* listener)
|
|
|
|
|
|
void b2World::SetDebugDraw(b2Draw* debugDraw)
|
|
|
{
|
|
|
- g_debugDraw = debugDraw;
|
|
|
+ m_debugDraw = debugDraw;
|
|
|
}
|
|
|
|
|
|
b2Body* b2World::CreateBody(const b2BodyDef* def)
|
|
@@ -109,14 +117,14 @@ b2Body* b2World::CreateBody(const b2BodyDef* def)
|
|
|
b2Assert(IsLocked() == false);
|
|
|
if (IsLocked())
|
|
|
{
|
|
|
- return NULL;
|
|
|
+ return nullptr;
|
|
|
}
|
|
|
|
|
|
void* mem = m_blockAllocator.Allocate(sizeof(b2Body));
|
|
|
b2Body* b = new (mem) b2Body(def, this);
|
|
|
|
|
|
// Add to world doubly linked list.
|
|
|
- b->m_prev = NULL;
|
|
|
+ b->m_prev = nullptr;
|
|
|
b->m_next = m_bodyList;
|
|
|
if (m_bodyList)
|
|
|
{
|
|
@@ -153,7 +161,7 @@ void b2World::DestroyBody(b2Body* b)
|
|
|
|
|
|
b->m_jointList = je;
|
|
|
}
|
|
|
- b->m_jointList = NULL;
|
|
|
+ b->m_jointList = nullptr;
|
|
|
|
|
|
// Delete the attached contacts.
|
|
|
b2ContactEdge* ce = b->m_contactList;
|
|
@@ -163,7 +171,7 @@ void b2World::DestroyBody(b2Body* b)
|
|
|
ce = ce->next;
|
|
|
m_contactManager.Destroy(ce0->contact);
|
|
|
}
|
|
|
- b->m_contactList = NULL;
|
|
|
+ b->m_contactList = nullptr;
|
|
|
|
|
|
// Delete the attached fixtures. This destroys broad-phase proxies.
|
|
|
b2Fixture* f = b->m_fixtureList;
|
|
@@ -185,7 +193,7 @@ void b2World::DestroyBody(b2Body* b)
|
|
|
b->m_fixtureList = f;
|
|
|
b->m_fixtureCount -= 1;
|
|
|
}
|
|
|
- b->m_fixtureList = NULL;
|
|
|
+ b->m_fixtureList = nullptr;
|
|
|
b->m_fixtureCount = 0;
|
|
|
|
|
|
// Remove world body list.
|
|
@@ -214,13 +222,13 @@ b2Joint* b2World::CreateJoint(const b2JointDef* def)
|
|
|
b2Assert(IsLocked() == false);
|
|
|
if (IsLocked())
|
|
|
{
|
|
|
- return NULL;
|
|
|
+ return nullptr;
|
|
|
}
|
|
|
|
|
|
b2Joint* j = b2Joint::Create(def, &m_blockAllocator);
|
|
|
|
|
|
// Connect to the world list.
|
|
|
- j->m_prev = NULL;
|
|
|
+ j->m_prev = nullptr;
|
|
|
j->m_next = m_jointList;
|
|
|
if (m_jointList)
|
|
|
{
|
|
@@ -232,14 +240,14 @@ b2Joint* b2World::CreateJoint(const b2JointDef* def)
|
|
|
// Connect to the bodies' doubly linked lists.
|
|
|
j->m_edgeA.joint = j;
|
|
|
j->m_edgeA.other = j->m_bodyB;
|
|
|
- j->m_edgeA.prev = NULL;
|
|
|
+ j->m_edgeA.prev = nullptr;
|
|
|
j->m_edgeA.next = j->m_bodyA->m_jointList;
|
|
|
if (j->m_bodyA->m_jointList) j->m_bodyA->m_jointList->prev = &j->m_edgeA;
|
|
|
j->m_bodyA->m_jointList = &j->m_edgeA;
|
|
|
|
|
|
j->m_edgeB.joint = j;
|
|
|
j->m_edgeB.other = j->m_bodyA;
|
|
|
- j->m_edgeB.prev = NULL;
|
|
|
+ j->m_edgeB.prev = nullptr;
|
|
|
j->m_edgeB.next = j->m_bodyB->m_jointList;
|
|
|
if (j->m_bodyB->m_jointList) j->m_bodyB->m_jointList->prev = &j->m_edgeB;
|
|
|
j->m_bodyB->m_jointList = &j->m_edgeB;
|
|
@@ -319,8 +327,8 @@ void b2World::DestroyJoint(b2Joint* j)
|
|
|
bodyA->m_jointList = j->m_edgeA.next;
|
|
|
}
|
|
|
|
|
|
- j->m_edgeA.prev = NULL;
|
|
|
- j->m_edgeA.next = NULL;
|
|
|
+ j->m_edgeA.prev = nullptr;
|
|
|
+ j->m_edgeA.next = nullptr;
|
|
|
|
|
|
// Remove from body 2
|
|
|
if (j->m_edgeB.prev)
|
|
@@ -338,8 +346,8 @@ void b2World::DestroyJoint(b2Joint* j)
|
|
|
bodyB->m_jointList = j->m_edgeB.next;
|
|
|
}
|
|
|
|
|
|
- j->m_edgeB.prev = NULL;
|
|
|
- j->m_edgeB.next = NULL;
|
|
|
+ j->m_edgeB.prev = nullptr;
|
|
|
+ j->m_edgeB.next = nullptr;
|
|
|
|
|
|
b2Joint::Destroy(j, &m_blockAllocator);
|
|
|
|
|
@@ -420,7 +428,7 @@ void b2World::Solve(const b2TimeStep& step)
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if (seed->IsAwake() == false || seed->IsActive() == false)
|
|
|
+ if (seed->IsAwake() == false || seed->IsEnabled() == false)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
@@ -442,12 +450,9 @@ void b2World::Solve(const b2TimeStep& step)
|
|
|
{
|
|
|
// Grab the next body off the stack and add it to the island.
|
|
|
b2Body* b = stack[--stackCount];
|
|
|
- b2Assert(b->IsActive() == true);
|
|
|
+ b2Assert(b->IsEnabled() == true);
|
|
|
island.Add(b);
|
|
|
|
|
|
- // Make sure the body is awake.
|
|
|
- b->SetAwake(true);
|
|
|
-
|
|
|
// To keep islands as small as possible, we don't
|
|
|
// propagate islands across static bodies.
|
|
|
if (b->GetType() == b2_staticBody)
|
|
@@ -455,6 +460,9 @@ void b2World::Solve(const b2TimeStep& step)
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
+ // Make sure the body is awake (without resetting sleep timer).
|
|
|
+ b->m_flags |= b2Body::e_awakeFlag;
|
|
|
+
|
|
|
// Search all contacts connected to this body.
|
|
|
for (b2ContactEdge* ce = b->m_contactList; ce; ce = ce->next)
|
|
|
{
|
|
@@ -507,8 +515,8 @@ void b2World::Solve(const b2TimeStep& step)
|
|
|
|
|
|
b2Body* other = je->other;
|
|
|
|
|
|
- // Don't simulate joints connected to inactive bodies.
|
|
|
- if (other->IsActive() == false)
|
|
|
+ // Don't simulate joints connected to diabled bodies.
|
|
|
+ if (other->IsEnabled() == false)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
@@ -599,8 +607,8 @@ void b2World::SolveTOI(const b2TimeStep& step)
|
|
|
for (;;)
|
|
|
{
|
|
|
// Find the first TOI.
|
|
|
- b2Contact* minContact = NULL;
|
|
|
- float32 minAlpha = 1.0f;
|
|
|
+ b2Contact* minContact = nullptr;
|
|
|
+ float minAlpha = 1.0f;
|
|
|
|
|
|
for (b2Contact* c = m_contactManager.m_contactList; c; c = c->m_next)
|
|
|
{
|
|
@@ -616,7 +624,7 @@ void b2World::SolveTOI(const b2TimeStep& step)
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- float32 alpha = 1.0f;
|
|
|
+ float alpha = 1.0f;
|
|
|
if (c->m_flags & b2Contact::e_toiFlag)
|
|
|
{
|
|
|
// This contact has a valid cached TOI.
|
|
@@ -660,7 +668,7 @@ void b2World::SolveTOI(const b2TimeStep& step)
|
|
|
|
|
|
// Compute the TOI for this contact.
|
|
|
// Put the sweeps onto the same time interval.
|
|
|
- float32 alpha0 = bA->m_sweep.alpha0;
|
|
|
+ float alpha0 = bA->m_sweep.alpha0;
|
|
|
|
|
|
if (bA->m_sweep.alpha0 < bB->m_sweep.alpha0)
|
|
|
{
|
|
@@ -690,7 +698,7 @@ void b2World::SolveTOI(const b2TimeStep& step)
|
|
|
b2TimeOfImpact(&output, &input);
|
|
|
|
|
|
// Beta is the fraction of the remaining portion of the .
|
|
|
- float32 beta = output.t;
|
|
|
+ float beta = output.t;
|
|
|
if (output.state == b2TOIOutput::e_touching)
|
|
|
{
|
|
|
alpha = b2Min(alpha0 + (1.0f - alpha0) * beta, 1.0f);
|
|
@@ -712,7 +720,7 @@ void b2World::SolveTOI(const b2TimeStep& step)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (minContact == NULL || 1.0f - 10.0f * b2_epsilon < minAlpha)
|
|
|
+ if (minContact == nullptr || 1.0f - 10.0f * b2_epsilon < minAlpha)
|
|
|
{
|
|
|
// No more TOI events. Done!
|
|
|
m_stepComplete = true;
|
|
@@ -894,18 +902,18 @@ void b2World::SolveTOI(const b2TimeStep& step)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void b2World::Step(float32 dt, int32 velocityIterations, int32 positionIterations)
|
|
|
+void b2World::Step(float dt, int32 velocityIterations, int32 positionIterations)
|
|
|
{
|
|
|
b2Timer stepTimer;
|
|
|
|
|
|
// If new fixtures were added, we need to find the new contacts.
|
|
|
- if (m_flags & e_newFixture)
|
|
|
+ if (m_newContacts)
|
|
|
{
|
|
|
m_contactManager.FindNewContacts();
|
|
|
- m_flags &= ~e_newFixture;
|
|
|
+ m_newContacts = false;
|
|
|
}
|
|
|
|
|
|
- m_flags |= e_locked;
|
|
|
+ m_locked = true;
|
|
|
|
|
|
b2TimeStep step;
|
|
|
step.dt = dt;
|
|
@@ -952,12 +960,12 @@ void b2World::Step(float32 dt, int32 velocityIterations, int32 positionIteration
|
|
|
m_inv_dt0 = step.inv_dt;
|
|
|
}
|
|
|
|
|
|
- if (m_flags & e_clearForces)
|
|
|
+ if (m_clearForces)
|
|
|
{
|
|
|
ClearForces();
|
|
|
}
|
|
|
|
|
|
- m_flags &= ~e_locked;
|
|
|
+ m_locked = false;
|
|
|
|
|
|
m_profile.step = stepTimer.GetMilliseconds();
|
|
|
}
|
|
@@ -993,7 +1001,7 @@ void b2World::QueryAABB(b2QueryCallback* callback, const b2AABB& aabb) const
|
|
|
|
|
|
struct b2WorldRayCastWrapper
|
|
|
{
|
|
|
- float32 RayCastCallback(const b2RayCastInput& input, int32 proxyId)
|
|
|
+ float RayCastCallback(const b2RayCastInput& input, int32 proxyId)
|
|
|
{
|
|
|
void* userData = broadPhase->GetUserData(proxyId);
|
|
|
b2FixtureProxy* proxy = (b2FixtureProxy*)userData;
|
|
@@ -1004,7 +1012,7 @@ struct b2WorldRayCastWrapper
|
|
|
|
|
|
if (hit)
|
|
|
{
|
|
|
- float32 fraction = output.fraction;
|
|
|
+ float fraction = output.fraction;
|
|
|
b2Vec2 point = (1.0f - fraction) * input.p1 + fraction * input.p2;
|
|
|
return callback->ReportFixture(fixture, point, output.normal, fraction);
|
|
|
}
|
|
@@ -1037,10 +1045,10 @@ void b2World::DrawShape(b2Fixture* fixture, const b2Transform& xf, const b2Color
|
|
|
b2CircleShape* circle = (b2CircleShape*)fixture->GetShape();
|
|
|
|
|
|
b2Vec2 center = b2Mul(xf, circle->m_p);
|
|
|
- float32 radius = circle->m_radius;
|
|
|
+ float radius = circle->m_radius;
|
|
|
b2Vec2 axis = b2Mul(xf.q, b2Vec2(1.0f, 0.0f));
|
|
|
|
|
|
- g_debugDraw->DrawSolidCircle(center, radius, axis, color);
|
|
|
+ m_debugDraw->DrawSolidCircle(center, radius, axis, color);
|
|
|
}
|
|
|
break;
|
|
|
|
|
@@ -1049,7 +1057,13 @@ void b2World::DrawShape(b2Fixture* fixture, const b2Transform& xf, const b2Color
|
|
|
b2EdgeShape* edge = (b2EdgeShape*)fixture->GetShape();
|
|
|
b2Vec2 v1 = b2Mul(xf, edge->m_vertex1);
|
|
|
b2Vec2 v2 = b2Mul(xf, edge->m_vertex2);
|
|
|
- g_debugDraw->DrawSegment(v1, v2, color);
|
|
|
+ m_debugDraw->DrawSegment(v1, v2, color);
|
|
|
+
|
|
|
+ if (edge->m_oneSided == false)
|
|
|
+ {
|
|
|
+ m_debugDraw->DrawPoint(v1, 4.0f, color);
|
|
|
+ m_debugDraw->DrawPoint(v2, 4.0f, color);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
|
|
@@ -1063,8 +1077,7 @@ void b2World::DrawShape(b2Fixture* fixture, const b2Transform& xf, const b2Color
|
|
|
for (int32 i = 1; i < count; ++i)
|
|
|
{
|
|
|
b2Vec2 v2 = b2Mul(xf, vertices[i]);
|
|
|
- g_debugDraw->DrawSegment(v1, v2, color);
|
|
|
- g_debugDraw->DrawCircle(v1, 0.05f, color);
|
|
|
+ m_debugDraw->DrawSegment(v1, v2, color);
|
|
|
v1 = v2;
|
|
|
}
|
|
|
}
|
|
@@ -1082,64 +1095,23 @@ void b2World::DrawShape(b2Fixture* fixture, const b2Transform& xf, const b2Color
|
|
|
vertices[i] = b2Mul(xf, poly->m_vertices[i]);
|
|
|
}
|
|
|
|
|
|
- g_debugDraw->DrawSolidPolygon(vertices, vertexCount, color);
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void b2World::DrawJoint(b2Joint* joint)
|
|
|
-{
|
|
|
- b2Body* bodyA = joint->GetBodyA();
|
|
|
- b2Body* bodyB = joint->GetBodyB();
|
|
|
- const b2Transform& xf1 = bodyA->GetTransform();
|
|
|
- const b2Transform& xf2 = bodyB->GetTransform();
|
|
|
- b2Vec2 x1 = xf1.p;
|
|
|
- b2Vec2 x2 = xf2.p;
|
|
|
- b2Vec2 p1 = joint->GetAnchorA();
|
|
|
- b2Vec2 p2 = joint->GetAnchorB();
|
|
|
-
|
|
|
- b2Color color(0.5f, 0.8f, 0.8f);
|
|
|
-
|
|
|
- switch (joint->GetType())
|
|
|
- {
|
|
|
- case e_distanceJoint:
|
|
|
- g_debugDraw->DrawSegment(p1, p2, color);
|
|
|
- break;
|
|
|
-
|
|
|
- case e_pulleyJoint:
|
|
|
- {
|
|
|
- b2PulleyJoint* pulley = (b2PulleyJoint*)joint;
|
|
|
- b2Vec2 s1 = pulley->GetGroundAnchorA();
|
|
|
- b2Vec2 s2 = pulley->GetGroundAnchorB();
|
|
|
- g_debugDraw->DrawSegment(s1, p1, color);
|
|
|
- g_debugDraw->DrawSegment(s2, p2, color);
|
|
|
- g_debugDraw->DrawSegment(s1, s2, color);
|
|
|
+ m_debugDraw->DrawSolidPolygon(vertices, vertexCount, color);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
- case e_mouseJoint:
|
|
|
- // don't draw this
|
|
|
- break;
|
|
|
-
|
|
|
default:
|
|
|
- g_debugDraw->DrawSegment(x1, p1, color);
|
|
|
- g_debugDraw->DrawSegment(p1, p2, color);
|
|
|
- g_debugDraw->DrawSegment(x2, p2, color);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void b2World::DrawDebugData()
|
|
|
+void b2World::DebugDraw()
|
|
|
{
|
|
|
- if (g_debugDraw == NULL)
|
|
|
+ if (m_debugDraw == nullptr)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- uint32 flags = g_debugDraw->GetFlags();
|
|
|
+ uint32 flags = m_debugDraw->GetFlags();
|
|
|
|
|
|
if (flags & b2Draw::e_shapeBit)
|
|
|
{
|
|
@@ -1148,7 +1120,12 @@ void b2World::DrawDebugData()
|
|
|
const b2Transform& xf = b->GetTransform();
|
|
|
for (b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext())
|
|
|
{
|
|
|
- if (b->IsActive() == false)
|
|
|
+ if (b->GetType() == b2_dynamicBody && b->m_mass == 0.0f)
|
|
|
+ {
|
|
|
+ // Bad body
|
|
|
+ DrawShape(f, xf, b2Color(1.0f, 0.0f, 0.0f));
|
|
|
+ }
|
|
|
+ else if (b->IsEnabled() == false)
|
|
|
{
|
|
|
DrawShape(f, xf, b2Color(0.5f, 0.5f, 0.3f));
|
|
|
}
|
|
@@ -1176,7 +1153,7 @@ void b2World::DrawDebugData()
|
|
|
{
|
|
|
for (b2Joint* j = m_jointList; j; j = j->GetNext())
|
|
|
{
|
|
|
- DrawJoint(j);
|
|
|
+ j->Draw(m_debugDraw);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1185,13 +1162,14 @@ void b2World::DrawDebugData()
|
|
|
b2Color color(0.3f, 0.9f, 0.9f);
|
|
|
for (b2Contact* c = m_contactManager.m_contactList; c; c = c->GetNext())
|
|
|
{
|
|
|
- //b2Fixture* fixtureA = c->GetFixtureA();
|
|
|
- //b2Fixture* fixtureB = c->GetFixtureB();
|
|
|
-
|
|
|
- //b2Vec2 cA = fixtureA->GetAABB().GetCenter();
|
|
|
- //b2Vec2 cB = fixtureB->GetAABB().GetCenter();
|
|
|
-
|
|
|
- //g_debugDraw->DrawSegment(cA, cB, color);
|
|
|
+ b2Fixture* fixtureA = c->GetFixtureA();
|
|
|
+ b2Fixture* fixtureB = c->GetFixtureB();
|
|
|
+ int32 indexA = c->GetChildIndexA();
|
|
|
+ int32 indexB = c->GetChildIndexB();
|
|
|
+ b2Vec2 cA = fixtureA->GetAABB(indexA).GetCenter();
|
|
|
+ b2Vec2 cB = fixtureB->GetAABB(indexB).GetCenter();
|
|
|
+
|
|
|
+ m_debugDraw->DrawSegment(cA, cB, color);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1202,7 +1180,7 @@ void b2World::DrawDebugData()
|
|
|
|
|
|
for (b2Body* b = m_bodyList; b; b = b->GetNext())
|
|
|
{
|
|
|
- if (b->IsActive() == false)
|
|
|
+ if (b->IsEnabled() == false)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
@@ -1219,7 +1197,7 @@ void b2World::DrawDebugData()
|
|
|
vs[2].Set(aabb.upperBound.x, aabb.upperBound.y);
|
|
|
vs[3].Set(aabb.lowerBound.x, aabb.upperBound.y);
|
|
|
|
|
|
- g_debugDraw->DrawPolygon(vs, 4, color);
|
|
|
+ m_debugDraw->DrawPolygon(vs, 4, color);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1231,7 +1209,7 @@ void b2World::DrawDebugData()
|
|
|
{
|
|
|
b2Transform xf = b->GetTransform();
|
|
|
xf.p = b->GetWorldCenter();
|
|
|
- g_debugDraw->DrawTransform(xf);
|
|
|
+ m_debugDraw->DrawTransform(xf);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1251,15 +1229,15 @@ int32 b2World::GetTreeBalance() const
|
|
|
return m_contactManager.m_broadPhase.GetTreeBalance();
|
|
|
}
|
|
|
|
|
|
-float32 b2World::GetTreeQuality() const
|
|
|
+float b2World::GetTreeQuality() const
|
|
|
{
|
|
|
return m_contactManager.m_broadPhase.GetTreeQuality();
|
|
|
}
|
|
|
|
|
|
void b2World::ShiftOrigin(const b2Vec2& newOrigin)
|
|
|
{
|
|
|
- b2Assert((m_flags & e_locked) == 0);
|
|
|
- if ((m_flags & e_locked) == e_locked)
|
|
|
+ b2Assert(m_locked == false);
|
|
|
+ if (m_locked)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
@@ -1281,16 +1259,19 @@ void b2World::ShiftOrigin(const b2Vec2& newOrigin)
|
|
|
|
|
|
void b2World::Dump()
|
|
|
{
|
|
|
- if ((m_flags & e_locked) == e_locked)
|
|
|
+ if (m_locked)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- b2Log("b2Vec2 g(%.15lef, %.15lef);\n", m_gravity.x, m_gravity.y);
|
|
|
- b2Log("m_world->SetGravity(g);\n");
|
|
|
+ b2OpenDump("box2d_dump.inl");
|
|
|
+
|
|
|
+ b2Dump("b2Vec2 g(%.9g, %.9g);\n", m_gravity.x, m_gravity.y);
|
|
|
+ b2Dump("m_world->SetGravity(g);\n");
|
|
|
+
|
|
|
+ b2Dump("b2Body** bodies = (b2Body**)b2Alloc(%d * sizeof(b2Body*));\n", m_bodyCount);
|
|
|
+ b2Dump("b2Joint** joints = (b2Joint**)b2Alloc(%d * sizeof(b2Joint*));\n", m_jointCount);
|
|
|
|
|
|
- b2Log("b2Body** bodies = (b2Body**)b2Alloc(%d * sizeof(b2Body*));\n", m_bodyCount);
|
|
|
- b2Log("b2Joint** joints = (b2Joint**)b2Alloc(%d * sizeof(b2Joint*));\n", m_jointCount);
|
|
|
int32 i = 0;
|
|
|
for (b2Body* b = m_bodyList; b; b = b->m_next)
|
|
|
{
|
|
@@ -1314,9 +1295,9 @@ void b2World::Dump()
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- b2Log("{\n");
|
|
|
+ b2Dump("{\n");
|
|
|
j->Dump();
|
|
|
- b2Log("}\n");
|
|
|
+ b2Dump("}\n");
|
|
|
}
|
|
|
|
|
|
// Second pass on joints, only gear joints.
|
|
@@ -1327,13 +1308,15 @@ void b2World::Dump()
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- b2Log("{\n");
|
|
|
+ b2Dump("{\n");
|
|
|
j->Dump();
|
|
|
- b2Log("}\n");
|
|
|
+ b2Dump("}\n");
|
|
|
}
|
|
|
|
|
|
- b2Log("b2Free(joints);\n");
|
|
|
- b2Log("b2Free(bodies);\n");
|
|
|
- b2Log("joints = NULL;\n");
|
|
|
- b2Log("bodies = NULL;\n");
|
|
|
+ b2Dump("b2Free(joints);\n");
|
|
|
+ b2Dump("b2Free(bodies);\n");
|
|
|
+ b2Dump("joints = nullptr;\n");
|
|
|
+ b2Dump("bodies = nullptr;\n");
|
|
|
+
|
|
|
+ b2CloseDump();
|
|
|
}
|