/// <summary> /// For teleporting a body without considering new contacts immediately. /// Warning: This method is locked during callbacks. /// </summary> /// <param name="position">The position.</param> /// <param name="angle">The angle.</param> /// <exception cref="System.InvalidOperationException">Thrown when the world is Locked/Stepping.</exception> public void SetTransformIgnoreContacts(ref Vector2 position, float angle) { Debug.Assert(World != null); if (World == null) { throw new InvalidOperationException("Could not set the transform of a body (World was null - has the body been removed?)"); } if (World.IsLocked) { throw new WorldLockedException("Cannot modify the transform of a body when the World is locked."); } _xf.q.Phase = angle; _xf.p = position; _sweep.C = Transform.Multiply(ref _sweep.LocalCenter, ref _xf); _sweep.A = angle; _sweep.C0 = _sweep.C; _sweep.A0 = angle; IBroadPhase broadPhase = World.ContactManager.BroadPhase; for (int i = 0; i < FixtureList.Count; i++) { FixtureList[i].Synchronize(broadPhase, ref _xf, ref _xf); } }
private void RegisterFixture() { // Reserve proxy space this.Proxies = new FixtureProxy[this.Shape.ChildCount]; this.ProxyCount = 0; this.FixtureId = _fixtureIdCounter++; if ((this.Body.Flags & BodyFlags.Enabled) == BodyFlags.Enabled) { IBroadPhase broadPhase = this.Body.World.ContactManager.BroadPhase; CreateProxies(broadPhase, ref this.Body.Xf); } this.Body.FixtureList.Add(this); // Adjust mass properties if needed. if (this.Shape._density > 0.0f) { this.Body.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. this.Body.World.Flags |= WorldFlags.NewFixture; if (this.Body.World.FixtureAdded != null) { this.Body.World.FixtureAdded(this); } }
public VoltWorld( int historyLength = 0, FP?damping = null) { this.HistoryLength = historyLength; this.Damping = damping ?? VoltConfig.DEFAULT_DAMPING; this.IterationCount = VoltConfig.DEFAULT_ITERATION_COUNT; this.DeltaTime = VoltConfig.DEFAULT_DELTA_TIME; this.bodies = new CheapList <VoltBody>(); this.manifolds = new List <Manifold>(); this.dynamicBroadphase = new NaiveBroadphase(); this.staticBroadphase = new TreeBroadphase(); this.reusableBuffer = new VoltBuffer <VoltBody>(); this.reusableOutput = new VoltBuffer <VoltBody>(); this.bodyPool = new VoltPool <VoltBody>(); this.circlePool = new VoltPool <VoltShape, VoltCircle>(); this.polygonPool = new VoltPool <VoltShape, VoltPolygon>(); this.contactPool = new VoltPool <Contact>(); this.manifoldPool = new VoltPool <Manifold>(); this.historyPool = new VoltPool <HistoryBuffer>(); }
/// <summary> /// Touch each proxy so that new pairs may be created /// </summary> /// <param name="broadPhase"></param> internal void TouchProxies(IBroadPhase broadPhase) { for (int i = 0; i < ProxyCount; ++i) { broadPhase.TouchProxy(Proxies[i].ProxyId); } }
public VoltWorld( int historyLength = 0, float damping = VoltConfig.DEFAULT_DAMPING) { this.HistoryLength = historyLength; this.Damping = damping; this.IterationCount = VoltConfig.DEFAULT_ITERATION_COUNT; this.DeltaTime = VoltConfig.DEFAULT_DELTA_TIME; this.bodies = new CheapList<VoltBody>(); this.manifolds = new List<Manifold>(); this.dynamicBroadphase = new NaiveBroadphase(); this.staticBroadphase = new TreeBroadphase(); this.reusableBuffer = new VoltBuffer<VoltBody>(); this.reusableOutput = new VoltBuffer<VoltBody>(); this.bodyPool = new VoltPool<VoltBody>(); this.circlePool = new VoltPool<VoltShape, VoltCircle>(); this.polygonPool = new VoltPool<VoltShape, VoltPolygon>(); this.contactPool = new VoltPool<Contact>(); this.manifoldPool = new VoltPool<Manifold>(); this.historyPool = new VoltPool<HistoryBuffer>(); }
private void RegisterFixture() { // Reserve proxy space Proxies = new FixtureProxy[Shape.ChildCount]; ProxyCount = 0; if (Body.Enabled) { IBroadPhase broadPhase = Body._world.ContactManager.BroadPhase; CreateProxies(broadPhase, ref Body._xf); } Body.FixtureList.Add(this); // Adjust mass properties if needed. if (Shape._density > 0.0f) { Body.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. Body._world._worldHasNewFixture = true; if (Body._world.FixtureAdded != null) { Body._world.FixtureAdded(this); } }
private void RegisterFixture() { this.Proxies = new FixtureProxy[this.Shape.ChildCount]; this.ProxyCount = 0; bool enabled = this.Body.Enabled; if (enabled) { IBroadPhase broadPhase = this.Body._world.ContactManager.BroadPhase; this.CreateProxies(broadPhase, ref this.Body._xf); } this.Body.FixtureList.Add(this); bool flag = this.Shape._density > 0f; if (flag) { this.Body.ResetMassData(); } this.Body._world._worldHasNewFixture = true; bool flag2 = this.Body._world.FixtureAdded != null; if (flag2) { this.Body._world.FixtureAdded(this); } }
private void Refilter() { for (ContactEdge contactEdge = this.Body.ContactList; contactEdge != null; contactEdge = contactEdge.Next) { Contact contact = contactEdge.Contact; Fixture fixtureA = contact.FixtureA; Fixture fixtureB = contact.FixtureB; bool flag = fixtureA == this || fixtureB == this; if (flag) { contact.FilterFlag = true; } } World world = this.Body._world; bool flag2 = world == null; if (!flag2) { IBroadPhase broadPhase = world.ContactManager.BroadPhase; for (int i = 0; i < this.ProxyCount; i++) { broadPhase.TouchProxy(this.Proxies[i].ProxyId); } } }
void registerFixture() { // Reserve proxy space proxies = new FixtureProxy[shape.childCount]; proxyCount = 0; if (body.enabled) { IBroadPhase broadPhase = body._world.contactManager.broadPhase; createProxies(broadPhase, ref body._xf); } body.fixtureList.Add(this); // Adjust mass properties if needed. if (shape._density > 0.0f) { body.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. body._world._worldHasNewFixture = true; //FPE: Added event if (body._world.onFixtureAdded != null) { body._world.onFixtureAdded(this); } }
public void DestroyFixture(Fixture fixture) { Debug.Assert(fixture.Body == this); Debug.Assert(this.FixtureList.Count > 0); Debug.Assert(this.FixtureList.Contains(fixture)); ContactEdge contactEdge = this.ContactList; while (contactEdge != null) { Contact contact = contactEdge.Contact; contactEdge = contactEdge.Next; Fixture fixtureA = contact.FixtureA; Fixture fixtureB = contact.FixtureB; bool flag = fixture == fixtureA || fixture == fixtureB; if (flag) { this._world.ContactManager.Destroy(contact); } } bool enabled = this._enabled; if (enabled) { IBroadPhase broadPhase = this._world.ContactManager.BroadPhase; fixture.DestroyProxies(broadPhase); } this.FixtureList.Remove(fixture); fixture.Destroy(); fixture.Body = null; this.ResetMassData(); }
/// <summary> /// Contacts are persistant and will keep being persistant unless they are /// flagged for filtering. /// This methods flags all contacts associated with the body for filtering. /// </summary> private void Refilter() { // Flag associated contacts for filtering. ContactEdge edge = Body.ContactList; while (edge != null) { Contact contact = edge.Contact; Fixture fixtureA = contact.FixtureA; Fixture fixtureB = contact.FixtureB; if (fixtureA == this || fixtureB == this) { contact.FilterFlag = true; } edge = edge.Next; } World world = Body._world; if (world == null) { return; } // Touch each proxy so that new pairs may be created IBroadPhase broadPhase = world.ContactManager.BroadPhase; for (int i = 0; i < ProxyCount; ++i) { broadPhase.TouchProxy(Proxies[i].ProxyId); } }
/** * This supports body activation/deactivation. */ public void CreateProxy(IBroadPhase broadPhase, b2Transform xf) { //b2Assert(m_proxyId == b2BroadPhase::e_nullProxy); // Create proxy in the broad-phase. m_shape.ComputeAABB(m_aabb, xf); m_proxy = broadPhase.CreateProxy(m_aabb, this); }
internal ContactManager(IBroadPhase broadPhase) { ContactList = new ContactListHead(); ContactCount = 0; BroadPhase = broadPhase; OnBroadphaseCollision = AddPair; }
/// <summary> /// Destroy a fixture. This removes the fixture from the broad-phase and /// destroys all contacts associated with this fixture. This will /// automatically adjust the mass of the body if the body is dynamic and the /// fixture has positive density. /// All fixtures attached to a body are implicitly destroyed when the body is destroyed. /// Warning: This method is locked during callbacks. /// </summary> /// <param name="fixture">The fixture to be removed.</param> /// <exception cref="System.InvalidOperationException">Thrown when the world is Locked/Stepping.</exception> public virtual void Remove(Fixture fixture) { if (World != null && World.IsLocked) { throw new InvalidOperationException("The World is locked."); } if (fixture == null) { throw new ArgumentNullException("fixture"); } if (fixture.Body != this) { throw new ArgumentException("You are removing a fixture that does not belong to this Body.", "fixture"); } // Destroy any contacts associated with the fixture. ContactEdge edge = ContactList; while (edge != null) { Contact c = edge.Contact; edge = edge.Next; Fixture fixtureA = c.FixtureA; Fixture fixtureB = c.FixtureB; if (fixture == fixtureA || fixture == fixtureB) { // This destroys the contact and removes it from // this body's contact list. World.ContactManager.Destroy(c); } } if (Enabled) { IBroadPhase broadPhase = World.ContactManager.BroadPhase; fixture.DestroyProxies(broadPhase); } fixture.Body = null; FixtureList._list.Remove(fixture); FixtureList._generationStamp++; #if DEBUG if (fixture.Shape.ShapeType == ShapeType.Polygon) { ((PolygonShape)fixture.Shape).Vertices.AttachedToBody = false; } #endif var fixtureRemovedHandler = World.FixtureRemoved; if (fixtureRemovedHandler != null) { fixtureRemovedHandler(World, this, fixture); } ResetMassData(); }
///<summary> /// Warning: This method is locked during callbacks. /// </summary>> /// <exception cref="System.InvalidOperationException">Thrown when the world is Locked/Stepping.</exception> public void Add(Fixture fixture) { if (World != null && World.IsLocked) { throw new InvalidOperationException("The World is locked."); } if (fixture == null) { throw new ArgumentNullException("fixture"); } if (fixture.Body != null) { if (fixture.Body == this) { throw new ArgumentException("You are adding the same fixture more than once.", "fixture"); } else { throw new ArgumentException("fixture belongs to another body.", "fixture"); } } fixture.Body = this; FixtureList._list.Add(fixture); FixtureList._generationStamp++; #if DEBUG if (fixture.Shape.ShapeType == ShapeType.Polygon) { ((PolygonShape)fixture.Shape).Vertices.AttachedToBody = true; } #endif // Adjust mass properties if needed. if (fixture.Shape._density > 0.0f) { ResetMassData(); } if (World != null) { if (Enabled) { IBroadPhase broadPhase = World.ContactManager.BroadPhase; fixture.CreateProxies(broadPhase, ref _xf); } // 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. World._worldHasNewFixture = true; var fixtureAddedHandler = World.FixtureAdded; if (fixtureAddedHandler != null) { fixtureAddedHandler(World, this, fixture); } } }
internal void DestroyProxies(IBroadPhase broadPhase) { for (int i = 0; i < this.ProxyCount; i++) { broadPhase.RemoveProxy(this.Proxies[i].ProxyId); this.Proxies[i].ProxyId = -1; } this.ProxyCount = 0; }
/// <summary> /// Create all proxies. /// </summary> internal void CreateProxies() { IBroadPhase broadPhase = World.ContactManager.BroadPhase; for (int i = 0; i < FixtureList.Count; i++) { FixtureList[i].CreateProxies(broadPhase, ref _xf); } }
/// Destroy proxies in the broad-phase. internal void DestroyProxies(IBroadPhase broadPhase) { for (int i = 0; i < ProxyCount; ++i) { broadPhase.RemoveProxy(Proxies[i].ProxyId); Proxies[i].ProxyId = -1; } ProxyCount = 0; }
/// <summary> /// Destroy all proxies. /// </summary> internal void DestroyProxies() { IBroadPhase broadPhase = World.ContactManager.BroadPhase; for (int i = 0; i < FixtureList.Count; i++) { FixtureList[i].DestroyProxies(broadPhase); } }
internal ContactManager(IBroadPhase <BodyProxy> broadPhase) { ContactList = new ContactListHead(); ContactCount = 0; _contactPoolList = new ContactListHead(); BroadPhase = broadPhase; OnBroadphaseCollision = AddPairBroadPhase; OnFixturePhaseCollision = AddPairFixturePhase; }
internal void DestroyProxies(IBroadPhase broadPhase) { // Destroy proxies in the broad-phase. for (int i = 0; i < this.ProxyCount; ++i) { broadPhase.RemoveProxy(this.Proxies[i].ProxyId); this.Proxies[i].ProxyId = -1; } this.ProxyCount = 0; }
internal void destroyProxies(IBroadPhase broadPhase) { // Destroy proxies in the broad-phase. for (int i = 0; i < proxyCount; ++i) { broadPhase.removeProxy(proxies[i].proxyId); proxies[i].proxyId = -1; } proxyCount = 0; }
public ConservativeAdvancement() { var parameters = new CollisionEngineParameters(); var physicsEngineParams = new PhysicsEngineParameters(); parameters.SetManifoldPoints(0); collisionDetectionEngine = new NarrowPhase(parameters); broadPhaseEngine = new AABBBroadPhase(parameters); integratePosition = new IntegratePosition(physicsEngineParams); }
/** * This supports body activation/deactivation. */ public void DestroyProxy(IBroadPhase broadPhase) { if (m_proxy == null) { return; } // Destroy proxy in the broad-phase. broadPhase.DestroyProxy(m_proxy); m_proxy = null; }
internal void SynchronizeFixtures() { Transform xf1 = new Transform(Vector2.Zero, _sweep.A0); xf1.p = _sweep.C0 - Complex.Multiply(ref _sweep.LocalCenter, ref xf1.q); IBroadPhase broadPhase = World.ContactManager.BroadPhase; for (int i = 0; i < FixtureList.Count; i++) { FixtureList[i].Synchronize(broadPhase, ref xf1, ref _xf); } }
internal void SynchronizeFixtures() { Transform transform = default(Transform); transform.q.Set(this._sweep.A0); transform.p = this._sweep.C0 - MathUtils.Mul(transform.q, this._sweep.LocalCenter); IBroadPhase broadPhase = this._world.ContactManager.BroadPhase; for (int i = 0; i < this.FixtureList.Count; i++) { this.FixtureList[i].Synchronize(broadPhase, ref transform, ref this._xf); } }
internal void CreateProxies(IBroadPhase broadPhase, ref Transform xf) { Debug.Assert(this.ProxyCount == 0); this.ProxyCount = this.Shape.ChildCount; for (int i = 0; i < this.ProxyCount; i++) { FixtureProxy fixtureProxy = default(FixtureProxy); this.Shape.ComputeAABB(out fixtureProxy.AABB, ref xf, i); fixtureProxy.Fixture = this; fixtureProxy.ChildIndex = i; fixtureProxy.ProxyId = broadPhase.AddProxy(ref fixtureProxy); this.Proxies[i] = fixtureProxy; } }
internal void SynchronizeFixtures() { Transform xf1 = new Transform(); xf1.q.Set(_sweep.A0); xf1.p = _sweep.C0 - MathUtils.Mul(xf1.q, _sweep.LocalCenter); IBroadPhase broadPhase = _world.ContactManager.BroadPhase; for (int i = 0; i < FixtureList.Count; i++) { FixtureList[i].Synchronize(broadPhase, ref xf1, ref _xf); } }
public void SetTransformIgnoreContacts(ref TSVector2 position, FP angle) { this._xf.q.Set(angle); this._xf.p = position; this._sweep.C = MathUtils.Mul(ref this._xf, this._sweep.LocalCenter); this._sweep.A = angle; this._sweep.C0 = this._sweep.C; this._sweep.A0 = angle; IBroadPhase broadPhase = this._world.ContactManager.BroadPhase; for (int i = 0; i < this.FixtureList.Count; i++) { this.FixtureList[i].Synchronize(broadPhase, ref this._xf, ref this._xf); } }
internal ContactManager(IBroadPhase broadPhase) { if (World.Multithreaded) { ThreadsToUse = Environment.ProcessorCount * 2; ThreadPool.SetMaxThreads(ThreadsToUse, ThreadsToUse); } ContactList = new ContactListHead(); ContactCount = 0; _contactPoolList = new ContactListHead(); BroadPhase = broadPhase; OnBroadphaseCollision += AddPair; }
/// <summary> /// Destroy a fixture. This removes the fixture from the broad-phase and /// destroys all contacts associated with this fixture. This will /// automatically adjust the mass of the body if the body is dynamic and the /// fixture has positive density. /// All fixtures attached to a body are implicitly destroyed when the body is destroyed. /// Warning: This function is locked during callbacks. /// </summary> /// <param name="fixture">The fixture to be removed.</param> public void DestroyFixture(Fixture fixture) { if (fixture == null) { return; } Debug.Assert(fixture.Body == this); // Remove the fixture from this body's singly linked list. Debug.Assert(FixtureList.Count > 0); // You tried to remove a fixture that not present in the fixturelist. Debug.Assert(FixtureList.Contains(fixture)); // Destroy any contacts associated with the fixture. ContactEdge edge = ContactList; while (edge != null) { Contact c = edge.Contact; edge = edge.Next; Fixture fixtureA = c.FixtureA; Fixture fixtureB = c.FixtureB; if (fixture == fixtureA || fixture == fixtureB) { // This destroys the contact and removes it from // this body's contact list. _world.ContactManager.Destroy(c); } } if (Enabled) { IBroadPhase broadPhase = _world.ContactManager.BroadPhase; fixture.DestroyProxies(broadPhase); } FixtureList.Remove(fixture); fixture.Destroy(); fixture.Body = null; ResetMassData(); }
// These support body activation/deactivation. internal void CreateProxies(IBroadPhase broadPhase, ref Transform xf) { Debug.Assert(ProxyCount == 0); // Create proxies in the broad-phase. ProxyCount = Shape.ChildCount; for (int i = 0; i < ProxyCount; ++i) { FixtureProxy proxy = new FixtureProxy(); Shape.ComputeAABB(out proxy.AABB, ref xf, i); proxy.Fixture = this; proxy.ChildIndex = i; //FPE note: This line needs to be after the previous two because FixtureProxy is a struct proxy.ProxyId = broadPhase.AddProxy(ref proxy); Proxies[i] = proxy; } }
// These support body activation/deactivation. internal void CreateProxies(IBroadPhase broadPhase, ref Transform xf) { Debug.Assert(ProxyCount == 0); // Create proxies in the broad-phase. ProxyCount = Shape.ChildCount; for (int i = 0; i < ProxyCount; ++i) { FixtureProxy proxy = new FixtureProxy(); Shape.ComputeAABB(out proxy.AABB, ref xf, i); proxy.Fixture = this; proxy.ChildIndex = i; proxy.ProxyId = broadPhase.AddProxy(ref proxy); Proxies[i] = proxy; } }
internal void Synchronize(IBroadPhase broadPhase, ref Transform transform1, ref Transform transform2) { if (ProxyCount == 0) { return; } for (int i = 0; i < ProxyCount; ++i) { FixtureProxy proxy = Proxies[i]; // Compute an AABB that covers the swept Shape (may miss some rotation effect). AABB 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); Vector2 displacement = transform2.Position - transform1.Position; broadPhase.MoveProxy(proxy.ProxyId, ref proxy.AABB, displacement); } }
internal void DestroyProxies(IBroadPhase broadPhase) { // Destroy proxies in the broad-phase. for (int i = 0; i < ProxyCount; ++i) { broadPhase.RemoveProxy(Proxies[i].ProxyId); Proxies[i].ProxyId = -1; } ProxyCount = 0; }
internal ContactManager(IBroadPhase broadPhase) { BroadPhase = broadPhase; OnBroadphaseCollision = AddPair; }
internal ContactManager( IBroadPhase broadPhase ) { this.broadPhase = broadPhase; onBroadphaseCollision = addPair; }