Exemple #1
0
        /// <summary>
        /// Draws a filled oval.
        /// </summary>
        /// <param name="centerX">The center X.</param>
        /// <param name="centerY">The center Y.</param>
        /// <param name="centerZ">The center Z.</param>
        /// <param name="halfWidth">Half of the width.</param>
        /// <param name="halfHeight">Half of the height.</param>
        /// <param name="edges">The number of edges to draw the oval width.</param>
        private void drawOvalFilled(float centerX, float centerY, float centerZ, float halfWidth, float halfHeight, int edges)
        {
            var vertices = new PrimitiveVertexData[edges];

            Matrix2 rotation = Matrix2.CreateRotation(MathHelper.TwoPi / edges);

            Vector2 xy = new Vector2(0, -1);

            Color argb = this.Color;

            vertices[0] = new PrimitiveVertexData(
                centerX + xy.X * halfWidth, centerY + xy.Y * halfHeight, centerZ, argb);

            for (int i = 1; i < edges; i++)
            {
                xy = rotation.Times(xy);

                vertices[i] = new PrimitiveVertexData(
                    centerX + xy.X * halfWidth, centerY + xy.Y * halfHeight, centerZ, argb);
            }

            ushort offset = this.surface.AddVertices(vertices);

            var ids = new ushort[(edges - 2) * 3];

            for (int i = 0; i < edges - 2; i++)
            {
                int o = i * 3;
                ids[o++] = offset;
                ids[o++] = (ushort)(offset + i + 1);
                ids[o]   = (ushort)(offset + i + 2);
            }

            this.surface.AddIndices(ids);
        }
Exemple #2
0
        /// <summary>
        /// Draws an unfilled oval.
        /// </summary>
        /// <param name="centerX">The center X.</param>
        /// <param name="centerY">The center Y.</param>
        /// <param name="centerZ">The center Z.</param>
        /// <param name="halfWidth">Half of the width.</param>
        /// <param name="halfHeight">Half of the height.</param>
        /// <param name="edges">The number of edges to draw the oval width.</param>
        private void drawOvalUnfilled(float centerX, float centerY, float centerZ, float halfWidth, float halfHeight, int edges)
        {
            var vertices = new PrimitiveVertexData[edges * 2];

            Matrix2 rotation = Matrix2.CreateRotation(MathHelper.TwoPi / edges);

            Vector2 xy = new Vector2(0, -1);

            Color argb = this.Color;

            float innerW = halfWidth - this.LineWidth;
            float innerH = halfHeight - this.LineWidth;

            vertices[0] = new PrimitiveVertexData(
                centerX + xy.X * halfWidth, centerY + xy.Y * halfHeight, centerZ, argb);

            vertices[1] = new PrimitiveVertexData(
                centerX + xy.X * innerW, centerY + xy.Y * innerH, centerZ, argb);

            for (int i = 1; i < edges; i++)
            {
                xy = rotation.Times(xy);

                vertices[2 * i] = new PrimitiveVertexData(
                    centerX + xy.X * halfWidth, centerY + xy.Y * halfHeight, centerZ, argb);

                vertices[2 * i + 1] = new PrimitiveVertexData(
                    centerX + xy.X * innerW, centerY + xy.Y * innerH, centerZ, argb);
            }

            ushort offset = this.surface.AddVertices(vertices);

            var ids = new ushort[edges * 6];

            for (int i = 0; i < edges - 1; i++)
            {
                int j = i * 6;
                int o = i * 2;
                ids[j]     = (ushort)(offset + o);
                ids[j + 1] = (ushort)(offset + o + 2);
                ids[j + 2] = (ushort)(offset + o + 1);

                ids[j + 3] = (ushort)(offset + o + 1);
                ids[j + 4] = (ushort)(offset + o + 2);
                ids[j + 5] = (ushort)(offset + o + 3);
            }

            int lastJ = edges * 6 - 6;

            ids[lastJ]     = (ushort)(offset + edges * 2 - 2);
            ids[lastJ + 1] = (ushort)(offset);
            ids[lastJ + 2] = (ushort)(offset + edges * 2 - 1);

            ids[lastJ + 3] = (ushort)(offset + edges * 2 - 1);
            ids[lastJ + 4] = (ushort)(offset);
            ids[lastJ + 5] = (ushort)(offset + 1);

            this.surface.AddIndices(ids);
        }
Exemple #3
0
 /// <summary>
 /// Returns the vertex' <see cref="VertexAttributes" />
 /// </summary>
 /// <returns>
 /// Array of <see cref="VertexAttribute" />
 /// </returns>
 public         VertexAttribute[] VertexAttributes()
 {
     if (PrimitiveVertexData.vertexAttributes == null)
     {
         PrimitiveVertexData.setVertexAttributes();
     }
     return(PrimitiveVertexData.vertexAttributes);
 }
Exemple #4
0
        /// <summary>
        /// Draws a rectangle.
        /// </summary>
        /// <param name="x">The x coordinate of the rectangle's corner.</param>
        /// <param name="y">The y coordinate of the rectangle's corner.</param>
        /// <param name="z">The z coordinate of the rectangle's corner.</param>
        /// <param name="w">The width of the rectangle.</param>
        /// <param name="h">The height of the rectangle.</param>
        public void DrawRectangle(float x, float y, float z, float w, float h, bool filled = true)
        {
            var v0 = new PrimitiveVertexData(x, y, z, Color);
            var v1 = new PrimitiveVertexData(x + w, y, z, Color);
            var v2 = new PrimitiveVertexData(x + w, y + h, z, Color);
            var v3 = new PrimitiveVertexData(x, y + h, z, Color);

            if (filled || LineWidth * 2 > w || LineWidth * 2 > h)
            {
                surface.AddQuad(v0, v1, v2, v3);
            }
            else
            {
                var v0i = new PrimitiveVertexData(x + LineWidth, y + LineWidth, z, Color);
                var v1i = new PrimitiveVertexData(x + w - LineWidth, y + LineWidth, z, Color);
                var v2i = new PrimitiveVertexData(x + w - LineWidth, y + h - LineWidth, z, Color);
                var v3i = new PrimitiveVertexData(x + LineWidth, y + h - LineWidth, z, Color);

                surface.AddQuad(v0, v1, v1i, v0i);
                surface.AddQuad(v1, v2, v2i, v1i);
                surface.AddQuad(v2, v3, v3i, v2i);
                surface.AddQuad(v3, v0, v0i, v3i);
            }
        }
        /// <summary>
        /// Draws an unfilled oval.
        /// </summary>
        /// <param name="centerX">The center X.</param>
        /// <param name="centerY">The center Y.</param>
        /// <param name="centerZ">The center Z.</param>
        /// <param name="halfWidth">Half of the width.</param>
        /// <param name="halfHeight">Half of the height.</param>
        /// <param name="edges">The number of edges to draw the oval width.</param>
        private void drawOvalUnfilled(float centerX, float centerY, float centerZ, float halfWidth, float halfHeight, int edges)
        {
            var vertices = new PrimitiveVertexData[edges * 2];

            Matrix2 rotation = Matrix2.CreateRotation(MathHelper.TwoPi / edges);

            Vector2 xy = new Vector2(0, -1);

            Color argb = this.Color;

            float innerW = halfWidth - this.LineWidth;
            float innerH = halfHeight - this.LineWidth;

            vertices[0] = new PrimitiveVertexData(
                centerX + xy.X * halfWidth, centerY + xy.Y * halfHeight, centerZ, argb);

            vertices[1] = new PrimitiveVertexData(
                centerX + xy.X * innerW, centerY + xy.Y * innerH, centerZ, argb);

            for (int i = 1; i < edges; i++)
            {
                xy = rotation.Times(xy);

                vertices[2 * i] = new PrimitiveVertexData(
                    centerX + xy.X * halfWidth, centerY + xy.Y * halfHeight, centerZ, argb);

                vertices[2 * i + 1] = new PrimitiveVertexData(
                    centerX + xy.X * innerW, centerY + xy.Y * innerH, centerZ, argb);
            }

            ushort offset = this.surface.AddVertices(vertices);

            var ids = new ushort[edges * 6];

            for (int i = 0; i < edges - 1; i++)
            {
                int j = i * 6;
                int o = i * 2;
                ids[j] = (ushort)(offset + o);
                ids[j + 1] = (ushort)(offset + o + 2);
                ids[j + 2] = (ushort)(offset + o + 1);

                ids[j + 3] = (ushort)(offset + o + 1);
                ids[j + 4] = (ushort)(offset + o + 2);
                ids[j + 5] = (ushort)(offset + o + 3);
            }

            int lastJ = edges * 6 - 6;

            ids[lastJ] = (ushort)(offset + edges * 2 - 2);
            ids[lastJ + 1] = (ushort)(offset);
            ids[lastJ + 2] = (ushort)(offset + edges * 2 - 1);

            ids[lastJ + 3] = (ushort)(offset + edges * 2 - 1);
            ids[lastJ + 4] = (ushort)(offset);
            ids[lastJ + 5] = (ushort)(offset + 1);

            this.surface.AddIndices(ids);
        }
        /// <summary>
        /// Draws a filled oval.
        /// </summary>
        /// <param name="centerX">The center X.</param>
        /// <param name="centerY">The center Y.</param>
        /// <param name="centerZ">The center Z.</param>
        /// <param name="halfWidth">Half of the width.</param>
        /// <param name="halfHeight">Half of the height.</param>
        /// <param name="edges">The number of edges to draw the oval width.</param>
        private void drawOvalFilled(float centerX, float centerY, float centerZ, float halfWidth, float halfHeight, int edges)
        {
            var vertices = new PrimitiveVertexData[edges];

            Matrix2 rotation = Matrix2.CreateRotation(MathHelper.TwoPi / edges);

            Vector2 xy = new Vector2(0, -1);

            Color argb = this.Color;

            vertices[0] = new PrimitiveVertexData(
                centerX + xy.X * halfWidth, centerY + xy.Y * halfHeight, centerZ, argb);

            for (int i = 1; i < edges; i++)
            {
                xy = rotation.Times(xy);

                vertices[i] = new PrimitiveVertexData(
                    centerX + xy.X * halfWidth, centerY + xy.Y * halfHeight, centerZ, argb);
            }

            ushort offset = this.surface.AddVertices(vertices);

            var ids = new ushort[(edges - 2) * 3];

            for (int i = 0; i < edges - 2; i++)
            {
                int o = i * 3;
                ids[o++] = offset;
                ids[o++] = (ushort)(offset + i + 1);
                ids[o] = (ushort)(offset + i + 2);
            }

            this.surface.AddIndices(ids);
        }