diff --git a/Source/Examples/Shapes/Cube.cs b/Source/Examples/Shapes/Cube.cs index cb1701c9..6d09067c 100644 --- a/Source/Examples/Shapes/Cube.cs +++ b/Source/Examples/Shapes/Cube.cs @@ -10,61 +10,65 @@ using System.Text; using System.Drawing; using OpenTK.Math; +using System.Runtime.InteropServices; namespace Examples.Shapes { - public static class Cube + public class Cube : Shape { - public static readonly Vector3[] Vertices = new Vector3[8] + public Cube() { - new Vector3(-1.0f, -1.0f, 1.0f), - new Vector3( 1.0f, -1.0f, 1.0f), - new Vector3( 1.0f, 1.0f, 1.0f), - new Vector3(-1.0f, 1.0f, 1.0f), - new Vector3(-1.0f, -1.0f, -1.0f), - new Vector3( 1.0f, -1.0f, -1.0f), - new Vector3( 1.0f, 1.0f, -1.0f), - new Vector3(-1.0f, 1.0f, -1.0f), - }; + Vertices = new Vector3[] + { + new Vector3(-1.0f, -1.0f, 1.0f), + new Vector3( 1.0f, -1.0f, 1.0f), + new Vector3( 1.0f, 1.0f, 1.0f), + new Vector3(-1.0f, 1.0f, 1.0f), + new Vector3(-1.0f, -1.0f, -1.0f), + new Vector3( 1.0f, -1.0f, -1.0f), + new Vector3( 1.0f, 1.0f, -1.0f), + new Vector3(-1.0f, 1.0f, -1.0f) + }; - public static readonly ushort[] Indices = - { - // front face - 0, 1, 2, 2, 3, 0, - // top face - 3, 2, 6, 6, 7, 3, - // back face - 7, 6, 5, 5, 4, 7, - // left face - 4, 0, 3, 3, 7, 4, - // bottom face - 0, 1, 5, 5, 4, 0, - // right face - 1, 5, 6, 6, 2, 1, - }; + Indices = new int[] + { + // front face + 0, 1, 2, 2, 3, 0, + // top face + 3, 2, 6, 6, 7, 3, + // back face + 7, 6, 5, 5, 4, 7, + // left face + 4, 0, 3, 3, 7, 4, + // bottom face + 0, 1, 5, 5, 4, 0, + // right face + 1, 5, 6, 6, 2, 1, + }; - public static readonly Vector3[] Normals = - { - new Vector3(-1.0f, -1.0f, 1.0f), - new Vector3( 1.0f, -1.0f, 1.0f), - new Vector3( 1.0f, 1.0f, 1.0f), - new Vector3(-1.0f, 1.0f, 1.0f), - new Vector3(-1.0f, -1.0f, -1.0f), - new Vector3( 1.0f, -1.0f, -1.0f), - new Vector3( 1.0f, 1.0f, -1.0f), - new Vector3(-1.0f, 1.0f, -1.0f), - }; + Normals = new Vector3[] + { + new Vector3(-1.0f, -1.0f, 1.0f), + new Vector3( 1.0f, -1.0f, 1.0f), + new Vector3( 1.0f, 1.0f, 1.0f), + new Vector3(-1.0f, 1.0f, 1.0f), + new Vector3(-1.0f, -1.0f, -1.0f), + new Vector3( 1.0f, -1.0f, -1.0f), + new Vector3( 1.0f, 1.0f, -1.0f), + new Vector3(-1.0f, 1.0f, -1.0f), + }; - public static readonly int[] Colors = - { - Color.Firebrick.ToArgb(), - Color.Honeydew.ToArgb(), - Color.Moccasin.ToArgb(), - Color.Yellow.ToArgb(), - Color.Crimson.ToArgb(), - Color.DarkGoldenrod.ToArgb(), - Color.ForestGreen.ToArgb(), - Color.Sienna.ToArgb(), - }; + Colors = new int[] + { + Color.Firebrick.ToArgb(), + Color.Honeydew.ToArgb(), + Color.Moccasin.ToArgb(), + Color.Yellow.ToArgb(), + Color.Crimson.ToArgb(), + Color.DarkGoldenrod.ToArgb(), + Color.ForestGreen.ToArgb(), + Color.Sienna.ToArgb(), + }; + } } } diff --git a/Source/Examples/Shapes/Shape.cs b/Source/Examples/Shapes/Shape.cs index 7f8cb484..a52211cd 100644 --- a/Source/Examples/Shapes/Shape.cs +++ b/Source/Examples/Shapes/Shape.cs @@ -9,6 +9,8 @@ using System.Collections.Generic; using System.Text; using OpenTK.Math; +using System.Runtime.InteropServices; +using System.Drawing; namespace Examples.Shapes { @@ -17,22 +19,14 @@ namespace Examples.Shapes private Vector3[] vertices, normals; private Vector2[] texcoords; private int[] indices; - unsafe int* index_ptr; - unsafe float* vertex_ptr, normal_ptr, texcoord_ptr; + private int[] colors; public Vector3[] Vertices { get { return vertices; } protected set { - unsafe - { - vertices = value; - //fixed (float* ptr = (float*)vertices[0]) - { - vertex_ptr = (float*)vertices[0]; - } - } + vertices = value; } } @@ -41,14 +35,7 @@ namespace Examples.Shapes get { return normals; } protected set { - unsafe - { - normals = value; - //fixed (float* ptr = (float*)normals[0]) - { - normal_ptr = (float*)normals[0]; - } - } + normals = value; } } @@ -57,14 +44,7 @@ namespace Examples.Shapes get { return texcoords; } protected set { - unsafe - { - texcoords = value; - //fixed (float* ptr = (float*)texcoords[0]) - { - texcoord_ptr = (float*)texcoords[0]; - } - } + texcoords = value; } } @@ -73,14 +53,16 @@ namespace Examples.Shapes get { return indices; } protected set { - unsafe - { - indices = value; - fixed (int* ptr = indices) - { - index_ptr = ptr; - } - } + indices = value; + } + } + + public int[] Colors + { + get { return colors; } + protected set + { + colors = value; } } }