public override void AddEntity(IBroadphaseEntity body) { JBBox bb = body.BoundingBox; body.BroadphaseTag = dt.AddProxy(ref bb, body); proxyBuffer.Add(body.BroadphaseTag); ++proxyCount; }
public override bool RemoveEntity(IBroadphaseEntity body) { proxyBuffer.Remove(body.BroadphaseTag); --proxyCount; dt.RemoveProxy(body.BroadphaseTag); return(true); }
public override bool RemoveEntity(IBroadphaseEntity body) { proxyBuffer.Remove(body.BroadphaseTag); --proxyCount; dt.RemoveProxy(body.BroadphaseTag); return true; }
public bool CheckBoundingBoxes(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { TSBBox boundingBox = entity1.BoundingBox; TSBBox boundingBox2 = entity2.BoundingBox; return(boundingBox.max.z >= boundingBox2.min.z && boundingBox.min.z <= boundingBox2.max.z && boundingBox.max.y >= boundingBox2.min.y && boundingBox.min.y <= boundingBox2.max.y && boundingBox.max.x >= boundingBox2.min.x && boundingBox.min.x <= boundingBox2.max.x); }
public override bool RemoveEntity(IBroadphaseEntity body) { int count; count = 0; for (int i = 0; i < axis1.Count; i++) { if (axis1[i].Body == body) { count++; axis1.RemoveAt(i); if (count == 2) { break; } i--; } } count = 0; for (int i = 0; i < axis2.Count; i++) { if (axis2[i].Body == body) { count++; axis2.RemoveAt(i); if (count == 2) { break; } i--; } } count = 0; for (int i = 0; i < axis3.Count; i++) { if (axis3[i].Body == body) { count++; axis3.RemoveAt(i); if (count == 2) { break; } i--; } } foreach (var pair in fullOverlaps) { if (pair.Entity1 == body || pair.Entity2 == body) { depricated.Push(pair); } } while (depricated.Count > 0) { fullOverlaps.Remove(depricated.Pop()); } bodyList.Remove(body); return(true); }
/// <summary> /// Checks the AABB of the two rigid bodies. /// </summary> /// <param name="entity1">The first body.</param> /// <param name="entity2">The second body.</param> /// <returns>Returns true if an intersection occours.</returns> public bool CheckBoundingBoxes(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { JBBox box1 = entity1.BoundingBox; JBBox box2 = entity2.BoundingBox; return(((box1.Max.Y >= box2.Min.Y) && (box1.Min.Y <= box2.Max.Y)) && ((box1.Max.X >= box2.Min.X) && (box1.Min.X <= box2.Max.X))); }
/// <summary> /// Add a body to the collision system. Adding a body to the world /// does automatically add it to the collision system. /// </summary> /// <param name="body">The body to remove.</param> public override void AddEntity(IBroadphaseEntity body) { if (bodyList.Contains(body)) throw new ArgumentException("The body was already added to the collision system.", "body"); // just keep our internal list in sync bodyList.Add(body); }
private bool CheckBroadphase(IBroadphaseEntity e1, IBroadphaseEntity e2) { // Ghost objects have "Ghost" tag, so we skip them during the broadphase var tag1 = (BodyTags) (e1.BroadphaseTag); var tag2 = (BodyTags) (e2.BroadphaseTag); if ((tag1 & tag2 & BodyTags.Projectile) == BodyTags.Projectile) return false; return ((tag1 | tag2) & BodyTags.Ghost) == BodyTags.None; }
public override void AddEntity(IBroadphaseEntity body) { bodyList.Add(body); axis1.Add(new SweepPoint(body, true, 0)); axis1.Add(new SweepPoint(body, false, 0)); axis2.Add(new SweepPoint(body, true, 1)); axis2.Add(new SweepPoint(body, false, 1)); addCounter++; }
/// <summary> /// Add a body to the collision system. Adding a body to the world /// does automatically add it to the collision system. /// </summary> /// <param name="body">The body to remove.</param> public override void AddEntity(IBroadphaseEntity body) { if (bodyList.Contains(body)) { throw new ArgumentException("The body was already added to the collision system.", "body"); } bodyList.Add(body); }
/// <summary> /// Checks the AABB of the two rigid bodies. /// </summary> /// <param name="entity1">The first body.</param> /// <param name="entity2">The second body.</param> /// <returns>Returns true if an intersection occours.</returns> public bool CheckBoundingBoxes(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { TSBBox box1 = entity1.BoundingBox; TSBBox box2 = entity2.BoundingBox; return((((box1.max.z >= box2.min.z) && (box1.min.z <= box2.max.z)) && ((box1.max.y >= box2.min.y) && (box1.min.y <= box2.max.y))) && ((box1.max.x >= box2.min.x) && (box1.min.x <= box2.max.x))); }
/// <summary> /// Raises the PassedBroadphase event. /// </summary> /// <param name="entity1">The first body.</param> /// <param name="entity2">The second body.</param> /// <returns>Returns false if the collision information /// should be dropped</returns> public bool RaisePassedBroadphase(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { if (this.PassedBroadphase != null) { return(this.PassedBroadphase(entity1, entity2)); } // allow this detection by default return(true); }
private void AddToActiveMultithreaded(IBroadphaseEntity body) { float xmin = body.BoundingBox.Min.X; int n = active.Count; bool thisInactive = body.IsStaticOrInactive; JBBox acBox, bodyBox; for (int i = 0; i != n;) { var ac = active[i]; acBox = ac.BoundingBox; if (acBox.Max.X < xmin) { n--; active.RemoveAt(i); } else { bodyBox = body.BoundingBox; if (!(thisInactive && ac.IsStaticOrInactive) && (bodyBox.Max.Z >= acBox.Min.Z) && (bodyBox.Min.Z <= acBox.Max.Z) && (bodyBox.Max.Y >= acBox.Min.Y) && (bodyBox.Min.Y <= acBox.Max.Y) && RaisePassedBroadphase(ac, body)) { var pair = BroadphasePair.Pool.GetNew(); if (swapOrder) { pair.Entity1 = body; pair.Entity2 = ac; } else { pair.Entity2 = body; pair.Entity1 = ac; } swapOrder = !swapOrder; threadManager.AddTask(detectCallback, pair); } i++; } } active.Add(body); }
private bool CheckBroadphase(IBroadphaseEntity e1, IBroadphaseEntity e2) { // Ghost objects have "Ghost" tag, so we skip them during the broadphase var tag1 = (BodyTags)(e1.BroadphaseTag); var tag2 = (BodyTags)(e2.BroadphaseTag); if ((tag1 & tag2 & BodyTags.Projectile) == BodyTags.Projectile) { return(false); } return(((tag1 | tag2) & BodyTags.Ghost) == BodyTags.None); }
private void AddToActiveMultithreaded(IBroadphaseEntity body, bool addToList) { float xmin = body.BoundingBox.Min.x; int n = active.Count; bool thisInactive = body.IsStaticOrInactive; BBox acBox, bodyBox; for (int i = 0; i != n;) { IBroadphaseEntity ac = active[i]; acBox = ac.BoundingBox; if (acBox.Max.x < xmin) { n--; active.RemoveAt(i); } else { bodyBox = body.BoundingBox; if (!(thisInactive && ac.IsStaticOrInactive) && (((bodyBox.Max.z >= acBox.Min.z) && (bodyBox.Min.z <= acBox.Max.z)) && ((bodyBox.Max.y >= acBox.Min.y) && (bodyBox.Min.y <= acBox.Max.y)))) { if (base.RaisePassedBroadphase(ac, body)) { BroadphasePair pair = BroadphasePair.Pool.GetNew(); if (swapOrder) { pair.Entity1 = body; pair.Entity2 = ac; } else { pair.Entity2 = body; pair.Entity1 = ac; } swapOrder = !swapOrder; threadManager.AddTask(detectCallback, pair); } } i++; } } active.Add(body); }
private void AddToActive(IBroadphaseEntity body) { float xmin = body.BoundingBox.Min.X; int n = active.Count; bool thisInactive = body.IsStaticOrInactive; JBBox acBox, bodyBox; for (int i = 0; i != n;) { var ac = active[i]; acBox = ac.BoundingBox; if (acBox.Max.X < xmin) { n--; active.RemoveAt(i); } else { bodyBox = body.BoundingBox; if (!(thisInactive && ac.IsStaticOrInactive) && (bodyBox.Max.Z >= acBox.Min.Z) && (bodyBox.Min.Z <= acBox.Max.Z) && (bodyBox.Max.Y >= acBox.Min.Y) && (bodyBox.Min.Y <= acBox.Max.Y) && RaisePassedBroadphase(ac, body)) { if (swapOrder) { Detect(body, ac); } else { Detect(ac, body); } swapOrder = !swapOrder; } i++; } } active.Add(body); }
private void AddToActiveMultithreaded(IBroadphaseEntity body, bool addToList) { FP x = body.BoundingBox.min.x; int num = this.active.Count; bool isStaticOrInactive = body.IsStaticOrInactive; int num2 = 0; while (num2 != num) { IBroadphaseEntity broadphaseEntity = this.active[num2]; TSBBox boundingBox = broadphaseEntity.BoundingBox; bool flag = boundingBox.max.x < x; if (flag) { num--; this.active.RemoveAt(num2); } else { TSBBox boundingBox2 = body.BoundingBox; bool flag2 = (!isStaticOrInactive || !broadphaseEntity.IsStaticOrInactive) && (boundingBox2.max.z >= boundingBox.min.z && boundingBox2.min.z <= boundingBox.max.z) && boundingBox2.max.y >= boundingBox.min.y && boundingBox2.min.y <= boundingBox.max.y; if (flag2) { bool flag3 = base.RaisePassedBroadphase(broadphaseEntity, body); if (flag3) { CollisionSystem.BroadphasePair @new = CollisionSystem.BroadphasePair.Pool.GetNew(); bool flag4 = this.swapOrder; if (flag4) { @new.Entity1 = body; @new.Entity2 = broadphaseEntity; } else { @new.Entity2 = body; @new.Entity1 = broadphaseEntity; } this.swapOrder = !this.swapOrder; this.threadManager.AddTask(this.detectCallback, @new); } } num2++; } } this.active.Add(body); }
private void AddToActive(IBroadphaseEntity body, bool addToList) { FP xmin = body.BoundingBox.min.x; int n = active.Count; bool thisInactive = body.IsStaticOrInactive; TSBBox acBox, bodyBox; for (int i = 0; i != n;) { IBroadphaseEntity ac = active[i]; acBox = ac.BoundingBox; if (acBox.max.x < xmin) { n--; active.RemoveAt(i); } else { bodyBox = body.BoundingBox; if (!(thisInactive && ac.IsStaticOrInactive) && (((bodyBox.max.z >= acBox.min.z) && (bodyBox.min.z <= acBox.max.z)) && ((bodyBox.max.y >= acBox.min.y) && (bodyBox.min.y <= acBox.max.y)))) { if (base.RaisePassedBroadphase(ac, body)) { if (swapOrder) { Detect(body, ac); } else { Detect(ac, body); } swapOrder = !swapOrder; } } i++; } } active.Add(body); }
public virtual void Detect(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { RigidBody rigidBody = entity1 as RigidBody; RigidBody rigidBody2 = entity2 as RigidBody; bool flag = rigidBody != null; if (flag) { bool flag2 = rigidBody2 != null; if (flag2) { this.DetectRigidRigid(rigidBody, rigidBody2); } else { SoftBody softBody = entity2 as SoftBody; bool flag3 = softBody != null; if (flag3) { this.DetectSoftRigid(rigidBody, softBody); } } } else { SoftBody softBody2 = entity1 as SoftBody; bool flag4 = rigidBody2 != null; if (flag4) { bool flag5 = softBody2 != null; if (flag5) { this.DetectSoftRigid(rigidBody2, softBody2); } } else { SoftBody softBody3 = entity2 as SoftBody; bool flag6 = softBody2 != null && softBody3 != null; if (flag6) { this.DetectSoftSoft(softBody2, softBody3); } } } }
/// <summary> /// Checks two bodies for collisions using narrowphase. /// </summary> /// <param name="body1">The first body.</param> /// <param name="body2">The second body.</param> #region public void Detect(IBroadphaseEntity body1, IBroadphaseEntity body2) public void Detect(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { Debug.Assert(entity1 != entity2, "CollisionSystem reports selfcollision. Something is wrong."); RigidBody rigidBody1 = entity1 as RigidBody; RigidBody rigidBody2 = entity2 as RigidBody; if (rigidBody1 != null) { if (rigidBody2 != null) { // most common DetectRigidRigid(rigidBody1, rigidBody2); } else { SoftBody softBody2 = entity2 as SoftBody; if (softBody2 != null) { DetectSoftRigid(rigidBody1, softBody2); } } } else { SoftBody softBody1 = entity1 as SoftBody; if (rigidBody2 != null) { if (softBody1 != null) { DetectSoftRigid(rigidBody2, softBody1); } } else { // less common SoftBody softBody2 = entity2 as SoftBody; if (softBody1 != null && softBody2 != null) { DetectSoftSoft(softBody1, softBody2); } } } }
public bool CheckCollision(IBroadphaseEntity rigidBody1, IBroadphaseEntity rigidBody2) { collisionDetected = false; collisionSystem.AddEntity(rigidBody1); collisionSystem.AddEntity(rigidBody2); collisionSystem.CollisionDetected += CollisionSystem_CollisionDetected; collisionSystem.Detect(true); collisionSystem.CollisionDetected -= CollisionSystem_CollisionDetected; collisionSystem.RemoveEntity(rigidBody1); collisionSystem.RemoveEntity(rigidBody2); return(collisionDetected); }
private void AddToActive(IBroadphaseEntity body) { var n = active.Count; var thisInactive = body.IsStaticOrInactive; for (var i = 0; i != n;) { var ac = active[i]; var acBox = ac.BoundingBox; if (acBox.Max.X < body.BoundingBox.Min.X) { n--; active.RemoveAt(i); } else { var bodyBox = body.BoundingBox; if (!(thisInactive && ac.IsStaticOrInactive) && (((bodyBox.Max.Z >= acBox.Min.Z) && (bodyBox.Min.Z <= acBox.Max.Z)) && ((bodyBox.Max.Y >= acBox.Min.Y) && (bodyBox.Min.Y <= acBox.Max.Y)))) { if (RaisePassedBroadphase(ac, body)) { if (swapOrder) { Detect(body, ac); } else { Detect(ac, body); } swapOrder = !swapOrder; } } i++; } } active.Add(body); }
private void AddToActive(IBroadphaseEntity body, bool addToList) { FP x = body.BoundingBox.min.x; int num = this.active.Count; bool isStaticOrInactive = body.IsStaticOrInactive; int num2 = 0; while (num2 != num) { IBroadphaseEntity broadphaseEntity = this.active[num2]; TSBBox boundingBox = broadphaseEntity.BoundingBox; bool flag = boundingBox.max.x < x; if (flag) { num--; this.active.RemoveAt(num2); } else { TSBBox boundingBox2 = body.BoundingBox; bool flag2 = (!isStaticOrInactive || !broadphaseEntity.IsStaticOrInactive) && (boundingBox2.max.z >= boundingBox.min.z && boundingBox2.min.z <= boundingBox.max.z) && boundingBox2.max.y >= boundingBox.min.y && boundingBox2.min.y <= boundingBox.max.y; if (flag2) { bool flag3 = base.RaisePassedBroadphase(broadphaseEntity, body); if (flag3) { bool flag4 = this.swapOrder; if (flag4) { this.Detect(body, broadphaseEntity); } else { this.Detect(broadphaseEntity, body); } this.swapOrder = !this.swapOrder; } } num2++; } } this.active.Add(body); }
public override void AddEntity(IBroadphaseEntity body) { if (body.BroadphaseTag < bodyList.Count && bodyList[body.BroadphaseTag] == body) { return; } body.BroadphaseTag = bodyList.Count; bodyList.Add(body); axis1.Add(new SweepPoint(body, true, 0)); axis1.Add(new SweepPoint(body, false, 0)); axis2.Add(new SweepPoint(body, true, 1)); axis2.Add(new SweepPoint(body, false, 1)); axis3.Add(new SweepPoint(body, true, 2)); axis3.Add(new SweepPoint(body, false, 2)); ResizeMatrix(MatrixGrowFactor); addCounter++; }
/// <summary> /// Checks two bodies for collisions using narrowphase. /// </summary> /// <param name="body1">The first body.</param> /// <param name="body2">The second body.</param> #region public virtual void Detect(IBroadphaseEntity body1, IBroadphaseEntity body2) public virtual void Detect(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { var rigidBody1 = entity1 as RigidBody; var rigidBody2 = entity2 as RigidBody; if (rigidBody1 != null) { if (rigidBody2 != null) { DetectRigidRigid(rigidBody1, rigidBody2); } else { var softBody2 = entity2 as SoftBody; if (softBody2 != null) { DetectSoftRigid(rigidBody1, softBody2); } } } else { var softBody1 = entity1 as SoftBody; if (rigidBody2 != null) { if (softBody1 != null) { DetectSoftRigid(rigidBody2, softBody1); } } else { var softBody2 = entity2 as SoftBody; if (softBody1 != null && softBody2 != null) { DetectSoftSoft(softBody1, softBody2); } } } }
/// <summary> /// Checks two bodies for collisions using narrowphase. /// </summary> /// <param name="body1">The first body.</param> /// <param name="body2">The second body.</param> #region public void Detect(IBroadphaseEntity body1, IBroadphaseEntity body2) public void Detect(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { //Debug.Assert(entity1 != entity2, "CollisionSystem reports self collision. Something is wrong."); RigidBody rigidBody1 = entity1 as RigidBody; RigidBody rigidBody2 = entity2 as RigidBody; if (rigidBody1 != null) { if (rigidBody2 != null) { // most common - currently we should always end up here. DetectRigidRigid(rigidBody1, rigidBody2); } else { //SoftBody softBody2 = entity2 as SoftBody; //if (softBody2 != null) DetectSoftRigid(rigidBody1, softBody2); } } else { //SoftBody softBody1 = entity1 as SoftBody; if (rigidBody2 != null) { //if (softBody1 != null) DetectSoftRigid(rigidBody2, softBody1); } else { // less common //SoftBody softBody2 = entity2 as SoftBody; //if (softBody1 != null && softBody2 != null) DetectSoftSoft(softBody1, softBody2); } } }
public OverlapPair() { this.Entity1 = null; this.Entity2 = null; }
public void Clone(SweepPoint sp) { body = sp.Body; begin = sp.Begin; axis = sp.Axis; }
/// <summary> /// Raises the PassedBroadphase event. /// </summary> /// <param name="entity1">The first body.</param> /// <param name="entity2">The second body.</param> /// <returns>Returns false if the collision information /// should be dropped</returns> public bool RaisePassedBroadphase(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { if (this.PassedBroadphase != null) return this.PassedBroadphase(entity1, entity2); // allow this detection by default return true; }
public void CleanUp() { this.Entity1 = null; this.Entity2 = null; }
/// <summary> /// Checks the state of two bodies. /// </summary> /// <param name="entity1">The first body.</param> /// <param name="entity2">The second body.</param> /// <returns>Returns true if both are static or inactive.</returns> public bool CheckBothStaticOrInactive(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { return (entity1.IsStaticOrInactive && entity2.IsStaticOrInactive); }
/// <summary> /// Checks the AABB of the two rigid bodies. /// </summary> /// <param name="entity1">The first body.</param> /// <param name="entity2">The second body.</param> /// <returns>Returns true if an intersection occours.</returns> public bool CheckBoundingBoxes(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { JBBox box1 = entity1.BoundingBox; JBBox box2 = entity2.BoundingBox; return ((((box1.Max.Z >= box2.Min.Z) && (box1.Min.Z <= box2.Max.Z)) && ((box1.Max.Y >= box2.Min.Y) && (box1.Min.Y <= box2.Max.Y))) && ((box1.Max.X >= box2.Min.X) && (box1.Min.X <= box2.Max.X))); }
/// <summary> /// Initializes a new instance of the BodyPair class. /// </summary> /// <param name="entity1"></param> /// <param name="entity2"></param> public OverlapPair(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { this.Entity1 = entity1; this.Entity2 = entity2; }
/// <summary> /// Remove a body from the collision system. Removing a body from the world /// does automatically remove it from the collision system. /// </summary> /// <param name="body">The body to remove.</param> /// <returns>Returns true if the body was successfully removed, otherwise false.</returns> public override bool RemoveEntity(IBroadphaseEntity body) { // just keep our internal list in sync return bodyList.Remove(body); }
public void Detect(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { Debug.Assert(entity1 != entity2, "CollisionSystem reports self collision. Something is wrong."); RigidBody rigidBody1 = entity1 as RigidBody; RigidBody rigidBody2 = entity2 as RigidBody; if (rigidBody1 != null) { if (rigidBody2 != null) { // most common - currently we should always end up here. DetectRigidRigid(rigidBody1, rigidBody2); } else { //SoftBody softBody2 = entity2 as SoftBody; //if (softBody2 != null) DetectSoftRigid(rigidBody1, softBody2); } } else { //SoftBody softBody1 = entity1 as SoftBody; if (rigidBody2 != null) { //if (softBody1 != null) DetectSoftRigid(rigidBody2, softBody1); } else { // less common //SoftBody softBody2 = entity2 as SoftBody; //if (softBody1 != null && softBody2 != null) DetectSoftSoft(softBody1, softBody2); } } }
/// <summary> /// Remove a body from the collision system. Removing a body from the world /// does automatically remove it from the collision system. /// </summary> /// <param name="body">The body to remove.</param> /// <returns>Returns true if the body was successfully removed, otherwise false.</returns> public override bool RemoveEntity(IBroadphaseEntity body) { // just keep our internal list in sync return(bodyList.Remove(body)); }
public virtual void Detect(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { var rigidBody1 = entity1 as RigidBody; var rigidBody2 = entity2 as RigidBody; if (rigidBody1 != null) { if(rigidBody2 != null) { DetectRigidRigid(rigidBody1, rigidBody2); } else { var softBody2 = entity2 as SoftBody; if(softBody2 != null) DetectSoftRigid(rigidBody1,softBody2); } } else { var softBody1 = entity1 as SoftBody; if (rigidBody2 != null) { if (softBody1 != null) DetectSoftRigid(rigidBody2, softBody1); } else { var softBody2 = entity2 as SoftBody; if (softBody1 != null && softBody2 != null) DetectSoftSoft(softBody1, softBody2); } } }
public SweepPoint(IBroadphaseEntity body, bool begin, int axis) { this.Body = body; this.Begin = begin; this.Axis = axis; }
public override void AddEntity(IBroadphaseEntity body) { if (body.BroadphaseTag < bodyList.Count && bodyList[body.BroadphaseTag] == body) return; body.BroadphaseTag = bodyList.Count; bodyList.Add(body); axis1.Add(new SweepPoint(body, true, 0)); axis1.Add(new SweepPoint(body, false, 0)); axis2.Add(new SweepPoint(body, true, 1)); axis2.Add(new SweepPoint(body, false, 1)); axis3.Add(new SweepPoint(body, true, 2)); axis3.Add(new SweepPoint(body, false, 2)); ResizeMatrix(MatrixGrowFactor); addCounter++; }
/// <summary> /// Don't call this, while the key is used in the arbitermap. /// It changes the hashcode of this object. /// </summary> /// <param name="entity1">The first body.</param> /// <param name="entity2">The second body.</param> internal void SetBodies(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { this.Entity1 = entity1; this.Entity2 = entity2; }
/// <summary> /// Initializes a new instance of the BodyPair class. /// </summary> /// <param name="body1"></param> /// <param name="body2"></param> public BodyPair(IBroadphaseEntity body1, IBroadphaseEntity body2) { this.body1 = body1; this.body2 = body2; }
public override bool RemoveEntity(IBroadphaseEntity body) { if (body.BroadphaseTag > bodyList.Count || bodyList[body.BroadphaseTag] != body) return false; int count; count = 0; for (int i = 0; i < axis1.Count; i++) { if (axis1[i].Body == body) { count++; axis1.RemoveAt(i); if (count == 2) break; i--; } } count = 0; for (int i = 0; i < axis2.Count; i++) { if (axis2[i].Body == body) { count++; axis2.RemoveAt(i); if (count == 2) break; i--; } } count = 0; for (int i = 0; i < axis3.Count; i++) { if (axis3[i].Body == body) { count++; axis3.RemoveAt(i); if (count == 2) break; i--; } } foreach (var pair in fullOverlaps) if (pair.body1 == body || pair.body2 == body) depricated.Push(pair); while (depricated.Count > 0) fullOverlaps.Remove(depricated.Pop()); IBroadphaseEntity lastBody = bodyList[bodyList.Count - 1]; if (body == lastBody) { for (int i = 0; i < bodyList.Count; i++) { t2bM.SetValue(body.BroadphaseTag, i, 0); } bodyList.RemoveAt(body.BroadphaseTag); } else { for (int i = 0; i < bodyList.Count; i++) { int value = t2bM.GetValue(lastBody.BroadphaseTag, i); t2bM.SetValue(body.BroadphaseTag, i, value); } bodyList.RemoveAt(lastBody.BroadphaseTag); bodyList[body.BroadphaseTag] = lastBody; lastBody.BroadphaseTag = body.BroadphaseTag; } ResizeMatrix(MatrixGrowFactor); return true; }
/// <summary> /// Remove a body from the collision system. Removing a body from the world /// does automatically remove it from the collision system. /// </summary> /// <param name="body">The body to remove.</param> /// <returns>Returns true if the body was successfully removed, otherwise false.</returns> public abstract bool RemoveEntity(IBroadphaseEntity body);
public override bool RemoveEntity(IBroadphaseEntity body) { int count; count = 0; for (int i = 0; i < axis1.Count; i++) { if (axis1[i].Body == body) { count++; axis1.RemoveAt(i); if (count == 2) break; i--; } } count = 0; for (int i = 0; i < axis2.Count; i++) { if (axis2[i].Body == body) { count++; axis2.RemoveAt(i); if (count == 2) break; i--; } } foreach (var pair in fullOverlaps) if (pair.Entity1 == body || pair.Entity2 == body) depricated.Push(pair); while (depricated.Count > 0) fullOverlaps.Remove(depricated.Pop()); bodyList.Remove(body); return true; }
/// <summary> /// Add a body to the collision system. Adding a body to the world /// does automatically add it to the collision system. /// </summary> /// <param name="body">The body to remove.</param> public abstract void AddEntity(IBroadphaseEntity body);
/// <summary> /// Checks two bodies for collisions using narrowphase. /// </summary> /// <param name="body1">The first body.</param> /// <param name="body2">The second body.</param> #region public virtual void Detect(IBroadphaseEntity body1, IBroadphaseEntity body2) public virtual void Detect(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { Debug.Assert(entity1 != entity2, "CollisionSystem reports selfcollision. Something is wrong."); RigidBody rigidBody1 = entity1 as RigidBody; RigidBody rigidBody2 = entity2 as RigidBody; if (rigidBody1 != null) { if(rigidBody2 != null) { // most common DetectRigidRigid(rigidBody1, rigidBody2); } else { SoftBody softBody2 = entity2 as SoftBody; if(softBody2 != null) DetectSoftRigid(rigidBody1,softBody2); } } else { SoftBody softBody1 = entity1 as SoftBody; if(rigidBody2 != null) { if(softBody1 != null) DetectSoftRigid(rigidBody2,softBody1); } else { // less common SoftBody softBody2 = entity2 as SoftBody; if(softBody1 != null && softBody2 != null) DetectSoftSoft(softBody1,softBody2); } } }
/// <summary> /// Don't call this, while the key is used in the arbitermap. /// It changes the hashcode of this object. /// </summary> /// <param name="body1">The first body.</param> /// <param name="body2">The second body.</param> internal void SetBodies(RigidBody body1, RigidBody body2) { this.body1 = body1; this.body2 = body2; }
/// <summary> /// Raises the PassedBroadphase event. /// </summary> /// <param name="entity1">The first body.</param> /// <param name="entity2">The second body.</param> /// <returns>Returns false if the collision information /// should be dropped</returns> public bool RaisePassedBroadphase(IBroadphaseEntity entity1, IBroadphaseEntity entity2) { return PassedBroadphase == null || PassedBroadphase(entity1, entity2); // allow this detection by default }