public virtual void SetTransform(b2Vec2 position, float angle) { if (m_world.IsLocked == true) { return; } m_xf.q.Set(angle); m_xf.p = position; Sweep.c = b2Math.b2Mul(m_xf, Sweep.localCenter); Sweep.a = angle; Sweep.c0 = Sweep.c; Sweep.a0 = angle; b2BroadPhase broadPhase = m_world.ContactManager.BroadPhase; for (b2Fixture f = m_fixtureList; f != null; f = f.Next) { f.Synchronize(broadPhase, m_xf, m_xf); } m_world.ContactManager.FindNewContacts(); }
public virtual b2Fixture CreateFixture(b2FixtureDef def) { if (m_world.IsLocked == true) { return(null); } b2Fixture fixture = new b2Fixture(); fixture.Create(this, def); if (m_flags.HasFlag(b2BodyFlags.e_activeFlag)) { b2BroadPhase broadPhase = m_world.ContactManager.BroadPhase; fixture.CreateProxies(broadPhase, m_xf); } fixture.Next = m_fixtureList; m_fixtureList = fixture; ++m_fixtureCount; fixture.Body = this; // Adjust mass properties if needed. if (fixture.Density > 0.0f) { ResetMassData(); } // Let the world know we have a new fixture. This will cause new contacts // to be created at the beginning of the next time step. m_world.Flags |= b2WorldFlags.e_newFixture; return(fixture); }
public virtual void SynchronizeFixtures() { /* * b2Transform xf1 = b2Transform.Identity; * xf1.q.Set(Sweep.a0); * xf1.p = Sweep.c0 - b2Math.b2Mul(xf1.q, Sweep.localCenter); * * b2BroadPhase broadPhase = World.ContactManager.BroadPhase; * for (b2Fixture f = FixtureList; f != null; f = f.Next) * { * f.Synchronize(broadPhase, ref xf1, ref Transform); * } */ b2Transform xf1; xf1.q.s = (float)Math.Sin(Sweep.a0); xf1.q.c = (float)Math.Cos(Sweep.a0); xf1.p.x = Sweep.c0.x - (xf1.q.c * Sweep.localCenter.x - xf1.q.s * Sweep.localCenter.y); xf1.p.y = Sweep.c0.y - (xf1.q.s * Sweep.localCenter.x + xf1.q.c * Sweep.localCenter.y); b2BroadPhase broadPhase = World.ContactManager.BroadPhase; for (b2Fixture f = FixtureList; f != null; f = f.Next) { f.Synchronize(broadPhase, ref xf1, ref Transform); } }
public virtual void Synchronize(b2BroadPhase broadPhase, ref b2Transform transform1, ref b2Transform transform2) { if (m_proxyCount == 0) { return; } for (int i = 0, count = m_proxyCount; i < count; ++i) { b2FixtureProxy proxy = m_proxies[i]; // Compute an AABB that covers the swept shape (may miss some rotation effect). b2AABB aabb1, aabb2; Shape.ComputeAABB(out aabb1, ref transform1, proxy.childIndex); Shape.ComputeAABB(out aabb2, ref transform2, proxy.childIndex); proxy.aabb.Combine(ref aabb1, ref aabb2); b2Vec2 displacement; displacement.x = transform2.p.x - transform1.p.x; displacement.y = transform2.p.y - transform1.p.y; broadPhase.MoveProxy(proxy.proxyId, ref proxy.aabb, ref displacement); } }
public b2ContactManager() { m_contactList = null; m_contactCount = 0; m_contactFilter = b2ContactFilter.b2_defaultFilter; m_contactListener = b2ContactListener.b2_defaultListener; m_broadPhase = new b2BroadPhase(); }
public b2ContactManager() { m_contactList = null; m_contactCount = 0; m_contactFilter = b2ContactFilter.b2_defaultFilter; m_contactListener = b2ContactListener.b2_defaultListener; m_broadPhase = new b2BroadPhase(); }
/// Set the type of this body. This may alter the mass and velocity. public void SetType(BodyType type) { Debug.Assert(m_world.IsLocked() == false); if (m_world.IsLocked() == true) { return; } if (m_type == type) { return; } m_type = type; ResetMassData(); if (m_type == BodyType.b2_staticBody) { m_linearVelocity.SetZero(); m_angularVelocity = 0.0f; m_sweep.a0 = m_sweep.a; m_sweep.c0 = m_sweep.c; SynchronizeFixtures(); } SetAwake(true); m_force.SetZero(); m_torque = 0.0f; // Delete the attached contacts. b2ContactEdge ce = m_contactList; while (ce != null) { b2ContactEdge ce0 = ce; ce = ce.next; m_world.m_contactManager.Destroy(ce0.contact); } m_contactList = null; // Touch the proxies so that new contacts will be created (when appropriate) b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase; for (b2Fixture f = m_fixtureList; f != null; f = f.m_next) { int proxyCount = f.m_proxyCount; for (int i = 0; i < proxyCount; ++i) { broadPhase.TouchProxy(f.m_proxies[i].proxyId); } } }
public virtual void DestroyProxies(b2BroadPhase broadPhase) { // Destroy proxies in the broad-phase. for (int i = 0; i < m_proxyCount; ++i) { broadPhase.DestroyProxy(m_proxies[i].proxyId); m_proxies[i].proxyId = b2BroadPhase.e_nullProxy; } m_proxyCount = 0; }
internal void DestroyProxies(b2BroadPhase broadPhase) { // Destroy proxies in the broad-phase. for (int i = 0; i < m_proxyCount; ++i) { b2FixtureProxy proxy = m_proxies[i]; broadPhase.DestroyProxy(proxy.proxyId); proxy.proxyId = (int)b2BroadPhase.AnonymousEnum.e_nullProxy; } m_proxyCount = 0; }
public virtual void DestroyProxies(b2BroadPhase broadPhase) { // Destroy proxies in the broad-phase. for (int i = 0; i < m_proxyCount; ++i) { b2FixtureProxy proxy = m_proxies[i]; broadPhase.DestroyProxy(proxy.proxyId); proxy.proxyId = b2BroadPhase.e_nullProxy; } m_proxies.Clear(); m_proxyCount = 0; }
public virtual void CreateProxies(b2BroadPhase broadPhase, b2Transform xf) { // Create proxies in the broad-phase. m_proxyCount = m_shape.GetChildCount(); for (int i = 0; i < m_proxyCount; ++i) { b2FixtureProxy proxy = m_proxies[i]; proxy.aabb = m_shape.ComputeAABB(xf, i); proxy.proxyId = broadPhase.CreateProxy(proxy.aabb, proxy); proxy.fixture = this; proxy.childIndex = i; } }
internal void SynchronizeFixtures() { b2Transform xf1 = new b2Transform(); xf1.q.Set(m_sweep.a0); xf1.p = m_sweep.c0 - Utils.b2Mul(xf1.q, m_sweep.localCenter); b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase; for (b2Fixture f = m_fixtureList; f != null; f = f.m_next) { f.Synchronize(broadPhase, xf1, m_xf); } }
public virtual void SynchronizeFixtures() { b2Transform xf1 = b2Transform.Create(); xf1.q.Set(Sweep.a0); xf1.p = Sweep.c0 - b2Math.b2Mul(xf1.q, Sweep.localCenter); b2BroadPhase broadPhase = m_world.ContactManager.BroadPhase; for (b2Fixture f = m_fixtureList; f != null; f = f.Next) { f.Synchronize(broadPhase, xf1, m_xf); } }
// These support body activation/deactivation. internal void CreateProxies(b2BroadPhase broadPhase, b2Transform xf) { Debug.Assert(m_proxyCount == 0); // Create proxies in the broad-phase. m_proxyCount = m_shape.GetChildCount(); for (int i = 0; i < m_proxyCount; ++i) { b2FixtureProxy proxy = m_proxies[i]; m_shape.ComputeAABB(ref proxy.aabb, xf, i); proxy.proxyId = broadPhase.CreateProxy(ref proxy.aabb, proxy); proxy.fixture = this; proxy.childIndex = i; } }
/// Set the active state of the body. An inactive body is not /// simulated and cannot be collided with or woken up. /// If you pass a flag of true, all fixtures will be added to the /// broad-phase. /// If you pass a flag of false, all fixtures will be removed from /// the broad-phase and all contacts will be destroyed. /// Fixtures and joints are otherwise unaffected. You may continue /// to create/destroy fixtures and joints on inactive bodies. /// Fixtures on an inactive body are implicitly inactive and will /// not participate in collisions, ray-casts, or queries. /// Joints connected to an inactive body are implicitly inactive. /// An inactive body is still owned by a b2World object and remains /// in the body list. public void SetActive(bool flag) { Debug.Assert(m_world.IsLocked() == false); if (flag == IsActive()) { return; } if (flag) { m_flags |= BodyFlags.e_activeFlag; // Create all proxies. b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase; for (b2Fixture f = m_fixtureList; f != null; f = f.m_next) { f.CreateProxies(broadPhase, m_xf); } // Contacts are created the next time step. } else { m_flags &= ~BodyFlags.e_activeFlag; // Destroy all proxies. b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase; for (b2Fixture f = m_fixtureList; f != null; f = f.m_next) { f.DestroyProxies(broadPhase); } // Destroy the attached contacts. b2ContactEdge ce = m_contactList; while (ce != null) { b2ContactEdge ce0 = ce; ce = ce.next; m_world.m_contactManager.Destroy(ce0.contact); } m_contactList = null; } }
public virtual void SetActive(bool flag) { if (flag == IsActive()) { return; } if (flag) { m_flags |= b2BodyFlags.e_activeFlag; // Create all proxies. b2BroadPhase broadPhase = m_world.ContactManager.BroadPhase; for (b2Fixture f = m_fixtureList; f != null; f = f.Next) { f.CreateProxies(broadPhase, m_xf); } // Contacts are created the next time step. } else { m_flags &= ~b2BodyFlags.e_activeFlag; // Destroy all proxies. b2BroadPhase broadPhase = m_world.ContactManager.BroadPhase; for (b2Fixture f = m_fixtureList; f != null; f = f.Next) { f.DestroyProxies(broadPhase); } // Destroy the attached contacts. b2ContactEdge ce = m_contactList; while (ce != null) { b2ContactEdge ce0 = ce; ce = ce.Next; m_world.ContactManager.Destroy(ce0.Contact); } m_contactList = null; } }
public virtual void Refilter() { if (m_body == null) { return; } // Flag associated contacts for filtering. b2ContactEdge edge = m_body.ContactList; while (edge != null) { b2Contact contact = edge.Contact; b2Fixture fixtureA = contact.GetFixtureA(); b2Fixture fixtureB = contact.GetFixtureB(); if (fixtureA == this || fixtureB == this) { contact.FlagForFiltering(); } edge = edge.Next; } b2World world = m_body.World; if (world == null) { return; } // Touch each proxy so that new pairs may be created b2BroadPhase broadPhase = world.ContactManager.BroadPhase; for (int i = 0; i < m_proxyCount; ++i) { broadPhase.TouchProxy(m_proxies[i].proxyId); } }
public virtual void Synchronize(b2BroadPhase broadPhase, b2Transform transform1, b2Transform transform2) { if (m_proxyCount == 0) { return; } for (int i = 0; i < m_proxyCount; ++i) { b2FixtureProxy proxy = m_proxies[i]; // Compute an AABB that covers the swept shape (may miss some rotation effect). b2AABB aabb1, aabb2; aabb1 = m_shape.ComputeAABB(transform1, proxy.childIndex); aabb2 = m_shape.ComputeAABB(transform2, proxy.childIndex); proxy.aabb.Combine(aabb1, aabb2); b2Vec2 displacement = transform2.p - transform1.p; broadPhase.MoveProxy(proxy.proxyId, proxy.aabb, displacement); } }
/// Set the position of the body's origin and rotation. /// Manipulating a body's transform may cause non-physical behavior. /// Note: contacts are updated on the next call to b2World::Step. /// @param position the world position of the body's local origin. /// @param angle the world rotation in radians. public void SetTransform(b2Vec2 position, float angle) { Debug.Assert(m_world.IsLocked() == false); if (m_world.IsLocked() == true) { return; } m_xf.q.Set(angle); m_xf.p = position; m_sweep.c = Utils.b2Mul(m_xf, m_sweep.localCenter); m_sweep.a = angle; m_sweep.c0 = m_sweep.c; m_sweep.a0 = angle; b2BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase; for (b2Fixture f = m_fixtureList; f != null; f = f.m_next) { f.Synchronize(broadPhase, m_xf, m_xf); } }
public virtual void DestroyProxies(b2BroadPhase broadPhase) { // Destroy proxies in the broad-phase. for (int i = 0; i < m_proxyCount; ++i) { broadPhase.DestroyProxy(m_proxies[i].proxyId); m_proxies[i].proxyId = b2BroadPhase.e_nullProxy; } m_proxyCount = 0; }
public virtual void DestroyFixture(b2Fixture fixture) { b2Assert(m_world.IsLocked() == false); if (m_world.IsLocked() == true) { return; } b2Assert(fixture.m_body == this); // Remove the fixture from this body's singly linked list. b2Assert(m_fixtureCount > 0); b2Fixture *node = &m_fixtureList; bool found = false; while (*node != null) { if (*node == fixture) { *node = fixture.Next; found = true; break; } node = &(*node).Next; } // You tried to remove a shape that is not attached to this body. b2Assert(found); // Destroy any contacts associated with the fixture. b2ContactEdge *edge = m_contactList; while (edge) { b2Contact *c = edge.contact; edge = edge.next; b2Fixture fixtureA = c.GetFixtureA(); b2Fixture fixtureB = c.GetFixtureB(); if (fixture == fixtureA || fixture == fixtureB) { // This destroys the contact and removes it from // this body's contact list. m_world.ContactManager.Destroy(c); } } b2BlockAllocator *allocator = m_world.m_blockAllocator; if (m_flags & e_activeFlag) { b2BroadPhase broadPhase = m_world.ContactManager.BroadPhase; fixture.DestroyProxies(broadPhase); } fixture.Destroy(allocator); fixture.m_body = null; fixture.Next = null; fixture.~b2Fixture(); allocator.Free(fixture, sizeof(b2Fixture)); --m_fixtureCount; // Reset the mass data. ResetMassData(); }
public virtual void DestroyFixture(b2Fixture fixture) { Debug.Assert(m_world.IsLocked == false); if (m_world.IsLocked) { return; } Debug.Assert(fixture.Body == this); // Remove the fixture from this body's singly linked list. Debug.Assert(m_fixtureCount > 0); b2Fixture node = m_fixtureList; bool found = false; while (node != null) { if (node == fixture) { node = fixture.Next; found = true; break; } node = node.Next; } // You tried to remove a shape that is not attached to this body. Debug.Assert(found); // Destroy any contacts associated with the fixture. b2ContactEdge edge = m_contactList; while (edge != null) { b2Contact c = edge.Contact; edge = edge.Next; b2Fixture fixtureA = c.FixtureA; b2Fixture fixtureB = c.FixtureB; if (fixture == fixtureA || fixture == fixtureB) { // This destroys the contact and removes it from // this body's contact list. m_world.ContactManager.Destroy(c); } } if (m_flags.HasFlag(b2BodyFlags.e_activeFlag)) { b2BroadPhase broadPhase = m_world.ContactManager.BroadPhase; fixture.DestroyProxies(broadPhase); } fixture.Body = null; fixture.Next = null; --m_fixtureCount; // Reset the mass data. ResetMassData(); }
public virtual void Synchronize(b2BroadPhase broadPhase, ref b2Transform transform1, ref b2Transform transform2) { if (m_proxyCount == 0) { return; } for (int i = 0, count = m_proxyCount; i < count; ++i) { b2FixtureProxy proxy = m_proxies[i]; // Compute an AABB that covers the swept shape (may miss some rotation effect). b2AABB aabb1, aabb2; Shape.ComputeAABB(out aabb1, ref transform1, proxy.childIndex); Shape.ComputeAABB(out aabb2, ref transform2, proxy.childIndex); proxy.aabb.Combine(ref aabb1, ref aabb2); b2Vec2 displacement; displacement.x = transform2.p.x - transform1.p.x; displacement.y = transform2.p.y - transform1.p.y; broadPhase.MoveProxy(proxy.proxyId, ref proxy.aabb, ref displacement); } }
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 virtual void CreateProxies(b2BroadPhase broadPhase, b2Transform xf) { // Create proxies in the broad-phase. m_proxyCount = m_shape.GetChildCount(); for (int i = 0; i < m_proxyCount; ++i) { b2FixtureProxy proxy = m_proxies[i]; proxy.aabb = m_shape.ComputeAABB(xf, i); proxy.fixture = this; proxy.childIndex = i; proxy.proxyId = broadPhase.CreateProxy(proxy.aabb, ref proxy); m_proxies[i] = proxy; } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(b2BroadPhase obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
public virtual void Synchronize(b2BroadPhase broadPhase, b2Transform transform1, b2Transform transform2) { if (m_proxyCount == 0) { return; } for (int i = 0; i < m_proxyCount; ++i) { b2FixtureProxy proxy = m_proxies[i]; // Compute an AABB that covers the swept shape (may miss some rotation effect). b2AABB aabb1, aabb2; aabb1 = m_shape.ComputeAABB(transform1, proxy.childIndex); aabb2 = m_shape.ComputeAABB(transform2, proxy.childIndex); proxy.aabb.Combine(aabb1, aabb2); b2Vec2 displacement = transform2.p - transform1.p; broadPhase.MoveProxy(proxy.proxyId, proxy.aabb, displacement); } }
public virtual void DestroyProxies(b2BroadPhase broadPhase) { // Destroy proxies in the broad-phase. for (int i = 0; i < m_proxyCount; ++i) { b2FixtureProxy proxy = m_proxies[i]; broadPhase.DestroyProxy(proxy.proxyId); proxy.proxyId = b2BroadPhase.e_nullProxy; m_proxies[i] = proxy; } m_proxies.Clear(); m_proxyCount = 0; }