Example #1
0
 internal static bool CollidePolygonLine(ICollidible polyCollidible, CollisionTypePolygon cTypePoly, CollisionTypeLine cTypeLine)
 {
     // for performance reasons first check the bounding box
     if (CollideBoundingBoxLine(polyCollidible, cTypeLine))
     {
         // transform the polygon to match the positioning, rotation and scale of the node
         Polygon transformedPolygon = ((Polygon)cTypePoly.collisionPolygon.Clone());
         transformedPolygon.TransformAccordingToGameObject(polyCollidible);
         // first check if the polygon contains some of the two line points
         if (transformedPolygon.ContainsPoint(cTypeLine.StartPoint) || transformedPolygon.ContainsPoint(cTypeLine.EndPoint))
         {
             return(true);
         }
         // solve exactly: check for line intersections
         var polyPoints = transformedPolygon.Points;
         int i, j;
         for (i = 0, j = polyPoints.Length - 1; i < polyPoints.Length; j = i++)
         {
             if (CCPoint.SegmentIntersect(cTypeLine.StartPoint, cTypeLine.EndPoint, polyPoints[i], polyPoints[j]))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #2
0
 // dirty
 internal static bool CollidePolygonPolygon(ICollidible polyCollidible1, CollisionTypePolygon cTypePoly1, ICollidible polyCollidible2, CollisionTypePolygon cTypePoly2)
 {
     // first check the bounding boxes of the polygons (for performance)
     if (((CCNode)polyCollidible1).BoundingBoxTransformedToWorld.IntersectsRect(((CCNode)polyCollidible2).BoundingBoxTransformedToWorld))
     {
         // transform the polygon to match the positioning, rotation and scale of the node
         Polygon transformedPolygon1 = ((Polygon)cTypePoly1.collisionPolygon.Clone());
         transformedPolygon1.TransformAccordingToGameObject(polyCollidible1);
         Polygon transformedPolygon2 = ((Polygon)cTypePoly2.collisionPolygon.Clone());
         transformedPolygon2.TransformAccordingToGameObject(polyCollidible2);
         foreach (var point in transformedPolygon1.Points)
         {
             if (transformedPolygon2.ContainsPoint(point))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #3
0
        // dirty as it only checks whether one contains a point of the other
        internal static bool CollideBoundingBoxPolygon(ICollidible boxCollidible, ICollidible polyCollidible, CollisionTypePolygon cTypePoly)
        {
            // first check the bounding box of the polygon (for performance)
            CCRect box = ((CCNode)boxCollidible).BoundingBoxTransformedToWorld;

            if (box.IntersectsRect(((CCNode)polyCollidible).BoundingBoxTransformedToWorld))
            {
                CCPoint[] boxPoints = Constants.CCRectPoints(box);
                // transform the polygon to match the positioning, rotation and scale of the node
                Polygon transformedPolygon = ((Polygon)cTypePoly.collisionPolygon.Clone());
                transformedPolygon.TransformAccordingToGameObject(polyCollidible);
                foreach (var point in boxPoints)
                {
                    if (transformedPolygon.ContainsPoint(point))
                    {
                        return(true);
                    }
                }
                foreach (var point in transformedPolygon.Points)
                {
                    if (box.ContainsPoint(point))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #4
0
        // is dirty, as it only checks whether polygon points are contained in the circle, not whether polygon lines are crossed by it
        internal static bool CollideCirclePolygon(ICollidible circleCollidible, CollisionTypeCircle cTypeCircle, ICollidible polyCollidible, CollisionTypePolygon cTypePoly)
        {
            float   radius = CorrectRadius(circleCollidible, cTypeCircle);
            CCPoint pos    = ((CCNode)circleCollidible).PositionWorldspace;
            // transform the polygon to match the positioning, rotation and scale of the node
            Polygon transformedPolygon = ((Polygon)cTypePoly.collisionPolygon.Clone());

            transformedPolygon.TransformAccordingToGameObject(polyCollidible);
            // for each point of the polygon check whether its contained in the circle
            foreach (var point in transformedPolygon.Points)
            {
                if (point.IsNear(pos, radius))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #5
0
 internal static bool CollidePositionPolygon(ICollidible posCollidible, ICollidible polyCollidible, CollisionTypePolygon cTypePoly)
 {
     // first check for bounding box collision (for efficience)
     if (CollidePositionBoundingBox(posCollidible, polyCollidible))
     {
         // transform the polygon to match the positioning, rotation and scale of the node
         Polygon transformedPolygon = ((Polygon)cTypePoly.collisionPolygon.Clone());
         transformedPolygon.TransformAccordingToGameObject(polyCollidible);
         return(transformedPolygon.ContainsPoint(((CCNode)posCollidible).PositionWorldspace));
     }
     return(false);
 }