Esempio n. 1
0
        public Segment(List<Vector2> vertices, int id, int parentID, int parentFace, SegmentType type)
        {
            this.vertices = new List<Vector2>(vertices);
            this.id = id;
            this.parentID = parentID;
            this.parentFace = parentFace;
            this.faces = new Dictionary<int, int>();
            this.type = type;

            collidable = false;

            // Set up the faces
            for (int i = 1; i < this.vertices.Count; i++)
            {
                faces.Add(i, -1);
            }

            this.alive = true;

            this.volume = Symet.CalculateArea(vertices);

            shape = new PrimitiveShape(this.vertices.ToArray(), Color.White, DrawType.LineStrip);

            maxHitPoints = Convert.ToInt32(volume * 5);
            hitPoints = maxHitPoints;
        }
Esempio n. 2
0
 public SegmentShape(int arm, int segment, SegmentType type, PrimitiveShape shape)
 {
     this.arm = arm;
     this.segment = segment;
     this.type = type;
     this.shape = shape;
 }
Esempio n. 3
0
 public static bool TestCollisionSimple(PrimitiveShape shape1, PrimitiveShape shape2)
 {
     if (shape1.Bounds.Intersects(shape2.Bounds))
         return true;
     return false;
 }
Esempio n. 4
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;
        }
Esempio n. 5
0
        public static List<LineHits> TestCollisionFull(PrimitiveShape shape1, int shape1ID, PrimitiveShape shape2, int shape2ID)
        {
            List<LineHits> hitVertices = new List<LineHits>();

            if (shape1.Bounds.Intersects(shape2.Bounds))
            {
                //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))
                        {
                            hitVertices.Add(new LineHits(a, b, shape1ID, c, d, shape2ID));
                            return hitVertices;
                        }
                    }
                }
            }

            return hitVertices;
        }
Esempio n. 6
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;
        }