private void ProcessRemovedItems() { //Remove any new geometries for (int i = 0; i < geomRemoveList.Count; i++) { geomRemoveList[i].isRemoved = true; geomList.Remove(geomRemoveList[i]); //Remove any arbiters associated with the geometries being removed for (int j = arbiterList.Count; j > 0; j--) { if (arbiterList[j - 1].GeometryA == geomRemoveList[i] || arbiterList[j - 1].GeometryB == geomRemoveList[i]) { arbiterList.Remove(arbiterList[j - 1]); } } } if (geomRemoveList.Count > 0) { _broadPhaseCollider.ProcessRemovedGeoms(); } geomRemoveList.Clear(); //Remove any new bodies for (int i = 0; i < bodyRemoveList.Count; i++) { bodyList.Remove(bodyRemoveList[i]); } bodyRemoveList.Clear(); //Remove any new controllers for (int i = 0; i < controllerRemoveList.Count; i++) { controllerList.Remove(controllerRemoveList[i]); } controllerRemoveList.Clear(); //Remove any new joints for (int i = 0; i < jointRemoveList.Count; i++) { jointList.Remove(jointRemoveList[i]); } jointRemoveList.Clear(); //Remove any new springs for (int i = 0; i < springRemoveList.Count; i++) { springList.Remove(springRemoveList[i]); } springRemoveList.Clear(); }
private void ProcessRemovedJoints() { if (_jointRemoveList.Count > 0) { foreach (var joint in _jointRemoveList) { var collideConnected = joint.CollideConnected; // Remove from the world list. JointList.Remove(joint); // Disconnect from island graph. var bodyA = joint.BodyA; var bodyB = joint.BodyB; // Wake up connected bodies. bodyA.Awake = true; // WIP David if (!joint.IsFixedType()) { bodyB.Awake = true; } // Remove from body 1. if (joint.EdgeA.Prev != null) { joint.EdgeA.Prev.Next = joint.EdgeA.Next; } if (joint.EdgeA.Next != null) { joint.EdgeA.Next.Prev = joint.EdgeA.Prev; } if (joint.EdgeA == bodyA.JointList) { bodyA.JointList = joint.EdgeA.Next; } joint.EdgeA.Prev = null; joint.EdgeA.Next = null; // WIP David if (!joint.IsFixedType()) { // Remove from body 2 if (joint.EdgeB.Prev != null) { joint.EdgeB.Prev.Next = joint.EdgeB.Next; } if (joint.EdgeB.Next != null) { joint.EdgeB.Next.Prev = joint.EdgeB.Prev; } if (joint.EdgeB == bodyB.JointList) { bodyB.JointList = joint.EdgeB.Next; } joint.EdgeB.Prev = null; joint.EdgeB.Next = null; // If the joint prevents collisions, then flag any contacts for filtering. if (collideConnected == false) { var edge = bodyB.ContactList; while (edge != null) { if (edge.Other == bodyA) { // Flag the contact for filtering at the next time step (where either // body is awake). edge.Contact._flags |= ContactFlags.FilterFlag; } edge = edge.Next; } } } JointRemoved?.Invoke(joint); } _jointRemoveList.Clear(); } }
private void ProcessRemovedJoints() { if (_jointRemoveList.Count > 0) { foreach (Joint joint in _jointRemoveList) { bool collideConnected = joint.CollideConnected; // Remove from the world list. JointList.Remove(joint); // Disconnect from island graph. Body bodyA = joint.BodyA; Body bodyB = joint.BodyB; // Wake up connected bodies. bodyA.Awake = true; // WIP David if (!joint.IsFixedType()) { bodyB.Awake = true; } // Remove from body 1. bodyA.JointList.Remove(joint); // WIP David if (!joint.IsFixedType()) { // Remove from body 2 bodyB.JointList.Remove(joint); } // WIP David if (!joint.IsFixedType()) { // If the joint prevents collisions, then flag any contacts for filtering. if (collideConnected == false) { ContactEdge edge = bodyB.ContactList; while (edge != null) { if (edge.Other == bodyA) { // Flag the contact for filtering at the next time step (where either // body is awake). edge.Contact.FlagForFiltering(); } edge = edge.Next; } } } if (JointRemoved != null) { JointRemoved(joint); } } _jointRemoveList.Clear(); } }
public void RemoveJoint(Joint joint) { _jointList.Remove(joint); }
/// <summary> /// Destroy a joint. This may cause the connected bodies to begin colliding. /// Warning: This function is locked during callbacks. /// </summary> /// <param name="joint">The joint.</param> public void RemoveJoint(Joint joint) { Debug.Assert(!IsLocked); if (IsLocked) { return; } bool collideConnected = joint.CollideConnected; // Remove from the world list. JointList.Remove(joint); // Disconnect from island graph. Body bodyA = joint.BodyA; Body bodyB = joint.BodyB; // Wake up connected bodies. bodyA.Awake = true; // WIP David if (!joint.IsFixedType()) { bodyB.Awake = true; } // Remove from body 1. if (joint.EdgeA.Prev != null) { joint.EdgeA.Prev.Next = joint.EdgeA.Next; } if (joint.EdgeA.Next != null) { joint.EdgeA.Next.Prev = joint.EdgeA.Prev; } if (joint.EdgeA == bodyA.JointList) { bodyA.JointList = joint.EdgeA.Next; } joint.EdgeA.Prev = null; joint.EdgeA.Next = null; // WIP David if (!joint.IsFixedType()) { // Remove from body 2 if (joint.EdgeB.Prev != null) { joint.EdgeB.Prev.Next = joint.EdgeB.Next; } if (joint.EdgeB.Next != null) { joint.EdgeB.Next.Prev = joint.EdgeB.Prev; } if (joint.EdgeB == bodyB.JointList) { bodyB.JointList = joint.EdgeB.Next; } joint.EdgeB.Prev = null; joint.EdgeB.Next = null; } // WIP David if (!joint.IsFixedType()) { // If the joint prevents collisions, then flag any contacts for filtering. if (collideConnected == false) { ContactEdge edge = bodyB.ContactList; while (edge != null) { if (edge.Other == bodyA) { // Flag the contact for filtering at the next time step (where either // body is awake). edge.Contact.FlagForFiltering(); } edge = edge.Next; } } } if (JointRemoved != null) { JointRemoved(joint); } }
/// <summary> /// Processes the removed geometries (and their arbiters), bodies, controllers, joints and springs. /// </summary> private void ProcessRemovedItems() { //Remove any new geometries _tempCount = _geomRemoveList.Count; for (int i = 0; i < _tempCount; i++) { _geomRemoveList[i].InSimulation = false; GeomList.Remove(_geomRemoveList[i]); //Remove any arbiters associated with the geometries being removed for (int j = ArbiterList.Count; j > 0; j--) { if (ArbiterList[j - 1].GeometryA == _geomRemoveList[i] || ArbiterList[j - 1].GeometryB == _geomRemoveList[i]) { //TODO: Should we create a RemoveComplete method and remove all Contacts associated //with the arbiter? arbiterPool.Insert(ArbiterList[j - 1]); ArbiterList.Remove(ArbiterList[j - 1]); } } } if (_geomRemoveList.Count > 0) { _broadPhaseCollider.ProcessRemovedGeoms(); } _geomRemoveList.Clear(); //Remove any new bodies _tempCount = _bodyRemoveList.Count; for (int i = 0; i < _tempCount; i++) { BodyList.Remove(_bodyRemoveList[i]); } _bodyRemoveList.Clear(); //Remove any new controllers _tempCount = _controllerRemoveList.Count; for (int i = 0; i < _tempCount; i++) { ControllerList.Remove(_controllerRemoveList[i]); } _controllerRemoveList.Clear(); //Remove any new joints int jointRemoveCount = _jointRemoveList.Count; for (int i = 0; i < jointRemoveCount; i++) { JointList.Remove(_jointRemoveList[i]); } _jointRemoveList.Clear(); //Remove any new springs _tempCount = _springRemoveList.Count; for (int i = 0; i < _tempCount; i++) { SpringList.Remove(_springRemoveList[i]); } _springRemoveList.Clear(); }