Exemplo n.º 1
0
        private CollisionCollection DetectCollisions()
        {
            CollisionCollection collisions = new CollisionCollection();

            for (int i = 0; i < objects.Count; i++)
            {
                for (int j = i + 1; j < objects.Count; j++)
                {
                    PhysicsObject obj1 = objects[i];
                    PhysicsObject obj2 = objects[j];

                    Vector2 mtv;
                    if (obj1.IntersectsWith(obj2, out mtv))
                    {
                        Vector2 normal      = mtv.Normalize();
                        float   penetration = mtv.Length;

                        Vector2[] support1 = GetSupportPoints(obj1.Polygon, -normal);
                        Vector2[] support2 = GetSupportPoints(obj2.Polygon, normal);

                        VectorPair[] pairs = GetContactPoints(support1, support2);

                        collisions.AddCollisionPair(obj1, obj2, pairs, -normal, penetration, false);
                        collisions.AddCollisionPair(obj2, obj1, pairs, normal, penetration, true);
                    }
                }
            }

            return(collisions);
        }