Ejemplo n.º 1
0
        public static List<PointHits> TestCollisionPoint(PrimitiveShape shape1, int shape1ID, PrimitiveShape shape2, int shape2ID)
        {
            List<PointHits> hits = new List<PointHits>();

            if (shape1.Bounds.Intersects(shape2.Bounds))
            {
                //return hits;
                //simple check if the first polygon contains any points from the second
                for (int i = 0; i < shape2.transformedVertices.Length; i++)
                    if (shape1.ContainsPoint(shape2.transformedVertices[i]))
                        hits.Add(new PointHits(shape2.vertices[i], shape1ID, shape2ID));

                //switch around and test the other way
                for (int i = 0; i < shape1.transformedVertices.Length; i++)
                    if (shape2.ContainsPoint(shape1.transformedVertices[i]))
                        hits.Add(new PointHits(shape1.vertices[i], shape1ID, shape2ID));
            }

            return hits;
        }
Ejemplo n.º 2
0
        public static bool TestCollision(PrimitiveShape shape1, PrimitiveShape shape2)
        {
            if (shape1.Bounds.Intersects(shape2.Bounds))
            {
                //return false;
                //simple check if the first polygon contains any points from the second
                for (int i = 0; i < shape2.transformedVertices.Length; i++)
                    if (shape1.ContainsPoint(shape2.transformedVertices[i]))
                        return true;

                //switch around and test the other way
                for (int i = 0; i < shape1.transformedVertices.Length; i++)
                    if (shape2.ContainsPoint(shape1.transformedVertices[i]))
                        return true;

                return false;
                //now we have to check for line segment intersections
                for (int i = 0; i < shape1.transformedVertices.Length; i++)
                {
                    //get the two points from a segment on shape 1
                    Vector2 a = shape1.transformedVertices[i];
                    Vector2 b = shape1.transformedVertices[(i + 1) % shape1.transformedVertices.Length];

                    for (int j = 0; j < shape2.transformedVertices.Length; j++)
                    {
                        //get two points from a segment on shape 2
                        Vector2 c = shape2.transformedVertices[j];
                        Vector2 d = shape2.transformedVertices[(j + 1) % shape2.transformedVertices.Length];

                        //figure out of we have an intersection
                        if (segmentsIntersect(a, b, c, d))
                            return true;
                    }
                }
            }

            return false;
        }