public virtual void Step(Settings settings) { float timeStep = settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f; if (settings.pause) { if (settings.singleStep) { settings.singleStep = false; } else { timeStep = 0.0f; } m_debugDraw.DrawString(5, m_textLine, "****PAUSED****"); m_textLine += 15; } b2DrawFlags flags = 0; if (settings.drawShapes) { flags |= b2DrawFlags.e_shapeBit; } if (settings.drawJoints) { flags |= b2DrawFlags.e_jointBit; } if (settings.drawAABBs) { flags |= b2DrawFlags.e_aabbBit; } if (settings.drawPairs) { flags |= b2DrawFlags.e_pairBit; } if (settings.drawCOMs) { flags |= b2DrawFlags.e_centerOfMassBit; } m_debugDraw.SetFlags(flags); m_world.SetWarmStarting(settings.enableWarmStarting > 0); m_world.SetContinuousPhysics(settings.enableContinuous > 0); m_world.SetSubStepping(settings.enableSubStepping > 0); m_pointCount = 0; m_world.Step(timeStep, settings.velocityIterations, settings.positionIterations); if (timeStep > 0.0f) { ++m_stepCount; } }
/// Clear flags from the current flags. public void ClearFlags(b2DrawFlags flags) { m_drawFlags &= ~flags; }
/// Append flags to the current flags. public void AppendFlags(b2DrawFlags flags) { m_drawFlags |= flags; }
/// Set the drawing flags. public void SetFlags(b2DrawFlags flags) { m_drawFlags = flags; }
public void DrawDebugData() { if (m_debugDraw == null) { return; } b2DrawFlags flags = m_debugDraw.GetFlags(); if (flags & b2DrawFlags.e_shapeBit) { for (b2Body b = m_bodyList; b; b = b.Next) { b2Transform xf = b.Transform; for (b2Fixture f = b.FixtureList; f != null; f = f.Next) { if (b.IsActive() == false) { DrawShape(f, xf, new b2Color(0.5f, 0.5f, 0.3f)); } else if (b.GetType() == b2BodyType.b2_staticBody) { DrawShape(f, xf, new b2Color(0.5f, 0.9f, 0.5f)); } else if (b.GetType() == b2BodyType.b2_kinematicBody) { DrawShape(f, xf, new b2Color(0.5f, 0.5f, 0.9f)); } else if (b.IsAwake() == false) { DrawShape(f, xf, new b2Color(0.6f, 0.6f, 0.6f)); } else { DrawShape(f, xf, new b2Color(0.9f, 0.7f, 0.7f)); } } } } if (flags.HasFlag(b2DrawFlags.e_jointBit)) { for (b2Joint j = m_jointList; j != null; j = j.GetNext()) { DrawJoint(j); } } if (flags.HasFlag(b2DrawFlags.e_pairBit)) { b2Color color = new b2Color(0.3f, 0.9f, 0.9f); for (b2Contact c = m_contactManager.ContactList; c != null; c = c.Next) { //b2Fixture fixtureA = c.GetFixtureA(); //b2Fixture fixtureB = c.GetFixtureB(); //b2Vec2 cA = fixtureA.GetAABB().GetCenter(); //b2Vec2 cB = fixtureB.GetAABB().GetCenter(); //m_debugDraw.DrawSegment(cA, cB, color); } } if (flags.HasFlag(b2DrawFlags.e_aabbBit)) { b2Color color(0.9f, 0.3f, 0.9f); b2BroadPhase bp = m_contactManager.BroadPhase; for (b2Body b = m_bodyList; b != null; b = b.Next) { if (b.IsActive() == false) { continue; } for (b2Fixture f = b.FixtureList; f != null; f = f.Next) { for (int i = 0; i < f.ProxyCount; ++i) { b2FixtureProxy proxy = f.Proxies[i]; b2AABB aabb = bp.GetFatAABB(proxy.proxyId); b2Vec2[] vs = new b2Vec2[4]; vs[0].Set(aabb.lowerBound.x, aabb.lowerBound.y); vs[1].Set(aabb.upperBound.x, aabb.lowerBound.y); vs[2].Set(aabb.upperBound.x, aabb.upperBound.y); vs[3].Set(aabb.lowerBound.x, aabb.upperBound.y); m_debugDraw.DrawPolygon(vs, 4, color); } } } } if (flags.HasFlag(b2DrawFlags.e_centerOfMassBit)) { for (b2Body b = m_bodyList; b != null; b = b.Next) { b2Transform xf = b.Transform; xf.p = b.WorldCenter; m_debugDraw.DrawTransform(xf); } } }
public static bool HasFlag(this b2DrawFlags flag, b2DrawFlags testFlag) { return ((flag & testFlag) == testFlag); }
public static bool HasFlag(this b2DrawFlags flag, b2DrawFlags testFlag) { return((flag & testFlag) == testFlag); }