Exemple #1
0
        /// <summary>
        /// Draws the given polygon.
        /// </summary>
        /// <param name="polygon">The polygon to render.</param>
        /// <param name="color">The color to use when drawing the polygon.</param>
        /// <param name="dashed">If true, the polygon will be "dashed".</param>
        public void DrawPolygon(VectorPolygon polygon, Color color, bool dashed)
        {
            if (polygon == null)
            {
                throw new ArgumentNullException("polygon");
            }
            int step = (dashed == true) ? 2 : 1;

            for (int i = 0; i < polygon.TransformedPoints.Length; i += step)
            {
                if (currentIndex >= vertices.Length - 2)
                {
                    End();
                    Begin();
                }
                vertices[currentIndex].Position.X =
                    polygon.TransformedPoints[i % polygon.TransformedPoints.Length].X;
                vertices[currentIndex].Position.Y =
                    polygon.TransformedPoints[i % polygon.TransformedPoints.Length].Y;
                vertices[currentIndex++].Color    = color;
                vertices[currentIndex].Position.X =
                    polygon.TransformedPoints[(i + 1) %
                                              polygon.TransformedPoints.Length].X;
                vertices[currentIndex].Position.Y =
                    polygon.TransformedPoints[(i + 1) %
                                              polygon.TransformedPoints.Length].Y;
                vertices[currentIndex++].Color = color;
                lineCount++;
            }
        }
Exemple #2
0
        /// <summary>
        /// Draws the given polygon, in defined segments.
        /// </summary>
        /// <param name="aPolygon">The polygon to render.</param>
        /// <param name="aColor">The color to use when drawing the polygon.</param>
        /// <param name="aDashed">If true, the polygon will be "dashed".</param>
        /// <param name="aStartSeg">Start of segment drawing.</param>
        /// <param name="aEndSeg">End of segment drawing.</param>
        public void DrawPolygonSegments(VectorPolygon aPolygon,
                                        Color aColor, bool aDashed, int aStartSeg, int aEndSeg)
        {
            if (aPolygon == null || aEndSeg > aPolygon.TransformedPoints.Length)
            {
                throw new ArgumentNullException("polygon");
            }
            int step = (aDashed == true) ? 2 : 1;

            for (int i = aStartSeg; i < aEndSeg; i += step)
            {
                if (currentIndex >= vertices.Length - 2)
                {
                    End();
                    Begin();
                }
                vertices[currentIndex].Position.X =
                    aPolygon.TransformedPoints[i % aPolygon.TransformedPoints.Length].X;
                vertices[currentIndex].Position.Y =
                    aPolygon.TransformedPoints[i % aPolygon.TransformedPoints.Length].Y;
                vertices[currentIndex++].Color    = aColor;
                vertices[currentIndex].Position.X =
                    aPolygon.TransformedPoints[(i + 1) %
                                               aPolygon.TransformedPoints.Length].X;
                vertices[currentIndex].Position.Y =
                    aPolygon.TransformedPoints[(i + 1) %
                                               aPolygon.TransformedPoints.Length].Y;
                vertices[currentIndex++].Color = aColor;
                lineCount++;
            }
        }
Exemple #3
0
        /// <summary>
        /// Create a polygon shaped like an atom (circle).
        /// </summary>
        /// <param name="radius">The radius of the oxygen.</param>
        /// <returns>A new VectorPolygon object in the shape of an atom.</returns>
        public static VectorPolygon CreateAtom(float radius)
        {
            VectorPolygon polygon = CreateCircle(Vector2.Zero, radius, 12);

            for (int i = 0; i < polygon.Points.Length; ++i)
            {
                Vector2 normal = Vector2.Normalize(polygon.Points[i]);
                polygon.Points[i] += normal * ((radius * 0.2f) *
                                               (float)random.NextDouble() - (radius * 0.1f));
            }

            return(polygon);
        }
Exemple #4
0
 /// <summary>
 /// Draws the given polygon.
 /// </summary>
 /// <param name="polygon">The polygon to render.</param>
 /// <param name="color">The color to use when drawing the polygon.</param>
 public void DrawPolygon(VectorPolygon polygon, Color color)
 {
     DrawPolygon(polygon, color, false);
 }