All pastes #75291 Raw Edit

Miscellany

public text v1 · immutable
#75291 ·published 2006-06-30 00:48 UTC
rendered paste body
        public static bool polyCollision(PhysicsPoly cPoly1, PhysicsPoly cPoly2)
        {
            // Some Values.

            double cPoly1DistanceToFarthestPoint = 0;
            double cPoly2DistanceToFarthestPoint = 0;

            // Get Our center Points
            Point cPoly1CenterPoint = new Point(0, 0);
            Point cPoly2CenterPoint = new Point(0, 0);

            // Calculate our furthest point for Poly1
            for (int i = 0; i < cPoly1.mAttachablePoly.vertices; i++)
            {
                double MyPoint = cPoly1.mAttachablePoly.p[i].DistanceTo(cPoly1CenterPoint);
                if (MyPoint > cPoly1DistanceToFarthestPoint)
                    cPoly1DistanceToFarthestPoint = MyPoint;
            }
            
            // Calculate our furthest point for Poly2
            for (int i = 0; i < cPoly2.mAttachablePoly.vertices; i++)
            {
                double MyPoint = cPoly2.mAttachablePoly.p[i].DistanceTo(cPoly2CenterPoint);
                if (MyPoint > cPoly2DistanceToFarthestPoint)
                    cPoly2DistanceToFarthestPoint = MyPoint;
            }


            // these two are defined above
            differenceX = cPoly2.x - cPoly1.x;
            differenceY = cPoly2.y - cPoly1.y;

            double differenceSquared = differenceX * differenceX + differenceY * differenceY;

            if (Math.Pow(differenceSquared, .5) - cPoly1DistanceToFarthestPoint - cPoly2DistanceToFarthestPoint < 0)
            {

                // More CPU accurate Check.



                return true;

            }
            else
                return false;

        }