Exemple #1
0
 /// <summary>
 /// Draws a polygon12
 /// </summary>
 /// <param name="sb"></param>
 /// <param name="r"></param>
 /// <param name="c"></param>
 static public void drawPolygon12(SpriteBatch sb, Polygon12 r, Color c)
 {
     for (int i = 0; i < r.numOfPoints - 1; i++)
     {
         drawLine(sb, c, new Vector2(r.point[i].X, r.point[i].Y), new Vector2(r.point[i + 1].X, r.point[i + 1].Y), 0);
     }
     drawLine(sb, c, new Vector2(r.point[r.numOfPoints - 1].X, r.point[r.numOfPoints - 1].Y), new Vector2(r.point[0].X, r.point[0].Y), 0);
 }
Exemple #2
0
 /// <summary>
 /// Copy Constructor
 /// </summary>
 /// <param name="r"></param>
 public Polygon12(Polygon12 r)
 {
     point       = new Vector2[maxNumOfPoints];
     numOfPoints = r.numOfPoints;
     for (int i = 0; i < numOfPoints; i++)
     {
         point[i].X = r.point[i].X;
         point[i].Y = r.point[i].Y;
     }
 }
        public static bool collisionPolygon12(Polygon12 r0, Polygon12 r1)
        {
            // bool rc = false;
            Rectangle rr0 = r0.getAABoundingRect();
            Rectangle rr1 = r1.getAABoundingRect();

            if (!rr0.Intersects(rr1))
            {
                return(false);                      // they cant colide the aa's dont collide
            }
            if (insidePoly(r1.point[0], r0.point, r0.numOfPoints))
            {
                return(true);
            }
            if (insidePoly(r0.point[0], r1.point, r1.numOfPoints))
            {
                return(true);
            }

            for (int i0 = 0; i0 < r0.numOfPoints; i0++)
            {
                int j0 = i0 + 1;
                if (j0 >= r0.numOfPoints)
                {
                    j0 = 0;
                }
                for (int i1 = 0; i1 < r1.numOfPoints; i1++)
                {
                    // construct a line for r0 point i to j

                    int j1 = i1 + 1;
                    if (j1 >= r1.numOfPoints)
                    {
                        j1 = 0;
                    }
                    Vector2 cp  = new Vector2(0, 0);
                    int     rc0 = intersect2D(ref cp, r0.point[i0], r0.point[j0], r1.point[i1], r1.point[j1]); if (rc0 != 3)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }