private VectorPair[] GetContactPoints_VertexEdge(Vector2 pa, Vector2[] edgeB) { VectorPair[] contacts = new VectorPair[1]; contacts[0].ContactA = pa; contacts[0].ContactB = Edge_GetClosestPoint(pa, edgeB[0], edgeB[1]); return(contacts); }
private VectorPair[] GetContactPoints_VertexVertex(Vector2 pa, Vector2 pb) { VectorPair[] contacts = new VectorPair[1]; contacts[0].ContactA = pa; contacts[0].ContactB = pb; return(contacts); }
private VectorPair[] GetContactPoints_EdgeVertex(Vector2[] edgeA, Vector2 PB) { VectorPair[] contacts = new VectorPair[1]; contacts[0].ContactA = Edge_GetClosestPoint(PB, edgeA[0], edgeA[1]); contacts[0].ContactB = PB; return(contacts); }
private VectorPair[] GetContactPoints_EdgeEdge(Vector2[] edgeA, Vector2[] edgeB) { Vector2 dir = edgeA[1] - edgeA[0]; Vsort[] v = new[] { new Vsort(edgeA[0], dir, 0), new Vsort(edgeA[1], dir, 0), new Vsort(edgeB[0], dir, 1), new Vsort(edgeB[1], dir, 1) }; VectorPair[] contacts = new VectorPair[2]; Array.Sort(v); for (int i = 0; i < 2; i++) { if (v[i + 1].bd == 0) { contacts[i].ContactA = v[i + 1].p; contacts[i].ContactB = Edge_GetClosestPoint(v[i + 1].p, edgeB[0], edgeB[1]); } else { contacts[i].ContactA = Edge_GetClosestPoint(v[i + 1].p, edgeA[0], edgeA[1]); contacts[i].ContactB = v[i + 1].p; } } return(contacts); }
internal void AddCollisionPair(PhysicsObject obj1, PhysicsObject obj2, VectorPair[] points, Vector2 normal, float penetration, bool isSecond) { Collision col = null; for (int i = 0; i < collisions.Count; i++) { if (collisions[i].Object1 == obj1 && collisions[i].Object2 == obj2) { col = collisions[i]; break; } } if (col == null) { col = new Collision(); col.SetCollision(obj1, obj2); collisions.Add(col); } for (int i = 0; i < points.Length; i++) { if (isSecond) col.Points.Add(new CollisionPoint(normal, points[i].ContactB, penetration)); else col.Points.Add(new CollisionPoint(normal, points[i].ContactA, penetration)); } }