Ejemplo n.º 1
0
        public ConvexPolygon2D(Point2[] verts)
        {
            // Ensure valid data
            if (verts.Length < 3)
            {
                throw new Exception("Number of vertices too small.");
            }

            // Store the vertices
            m_Vertices = verts;

            // Calculate the barycenter
            float baryX = 0, baryY = 0;
            float scalar = 1.0f / (float)NumVertices;

            foreach (Point2 vert in m_Vertices)
            {
                baryX += vert.x * scalar;
                baryY += vert.y * scalar;
            }

            // Store the barycenter
            m_Barycenter.Set(baryX, baryY);
        }
Ejemplo n.º 2
0
 ////////////////////////////////////////////////////////////////////////
 /// <summary> Set the box data </summary>
 /// <param name="x"> The x position of the box </param>
 /// <param name="y"> The y position of the box </param>
 /// <param name="width"> The width of the box </param>
 /// <param name="height"> The height of the box </param>
 ////////////////////////////////////////////////////////////////////////
 public void Set(float x, float y, float width, float height)
 {
     pos.Set(x, y);
     dims.Set(width, height);
 }