public void SolveCollision() { Body a = new Body(); Body b = new Body(); a.shape = new Circle(); b.shape = new Circle(); Pair _pair = new Pair(a, b); _pair.SolveCollision(); }
//creates pairs between possible collision objects public void CreatePairs() { for (int i = 0; i < drawBodies.Count; i++) { Body bodyA = drawBodies[i]; for (int j = i + 1; j < drawBodies.Count; j++) { Body bodyB = drawBodies[j]; //check if object is moving, if it isn't ignore it Pair pairs = new Pair(bodyA, bodyB); contactingBodies.Add(pairs); } } }
private void CircleVsCircle(Pair m, Body a, Body b) { /* Vector2 distance = b.transform.position - a.transform.position; Circle circleColA = a.shape as Circle; Circle circleColB = b.shape as Circle; float radius = circleColA.radius + circleColB.radius; //Math.Pow((a.position.x + b.position.x), 2) + Math.Pow((a.position.y + b.position.y), 2) if (distance.SquareMagnitude() > radius * radius) return; double aDistance = distance.Magnitude(); //m->contact_count = 1; m.contact_count = 1; if (aDistance == 0) { //distance is difference between radius and distance m.penetration = radius - aDistance; m.normal = new Vector2(1, 0); m.contacts[0] = a.transform.position; //utilise aDistance //points from A to B and is a unit vector } else { m.penetration = radius - aDistance; m.normal = distance / aDistance; //faster then normalise //vec2 to double m.contacts[0] = m.normal * circleColA.radius + a.transform.position; } */ //Circles have collided //compute manifold //float aDistance = distance //float sumRadi = a.radius + b.radius; //sumRadi *= sumRadi; //instead of sqrt in distance since sqrt is very expensive //return sumRadi < Math.Pow((a.position.x + b.position.x), 2) + Math.Pow((a.position.y + b.position.y), 2); return; }
public void GenerateCollisionPairs() { Body bodyA = new Body(); Body bodyB = new Body(); pair = new Pair(bodyA, bodyB); }