using System; using System.Collections.Generic; using System.Text; using OpenTK; namespace Examples.Shapes { public sealed class SlicedSphere: DrawableShape { public enum eSubdivisions { Zero = 0, One = 1, Two = 2, Three = 3, Four = 4, Five=5, Six=6, Seven=7, Eight=8, } public enum eDir { All, FrontTopRight, FrontBottomRight, FrontBottomLeft, FrontTopLeft, BackTopRight, BackBottomRight, BackBottomLeft, BackTopLeft, } public SlicedSphere( double radius, Vector3d offset, eSubdivisions subdivs, eDir[] sides, bool useDL ) : base( useDL ) { double Diameter = radius; PrimitiveMode = OpenTK.Graphics.OpenGL.PrimitiveType.Triangles; if ( sides[0] == eDir.All ) { sides = new eDir[] { eDir.FrontTopRight, eDir.FrontBottomRight, eDir.FrontBottomLeft, eDir.FrontTopLeft, eDir.BackTopRight, eDir.BackBottomRight, eDir.BackBottomLeft, eDir.BackTopLeft,}; } VertexArray = new VertexT2dN3dV3d[sides.Length * 3]; IndexArray = new uint[sides.Length * 3]; uint counter = 0; foreach ( eDir s in sides ) { GetDefaultVertices( s, Diameter, out VertexArray[counter + 0], out VertexArray[counter + 1], out VertexArray[counter + 2] ); IndexArray[counter + 0] = counter + 0; IndexArray[counter + 1] = counter + 1; IndexArray[counter + 2] = counter + 2; counter += 3; } if ( subdivs != eSubdivisions.Zero ) { for ( int s = 0; s < (int)subdivs; s++ ) { #region Assemble Chunks and convert to Arrays List AllChunks = new List(); for ( uint i = 0; i < IndexArray.Length; i += 3 ) { Chunk chu; Subdivide( Diameter, ref VertexArray[IndexArray[i + 0]], ref VertexArray[IndexArray[i + 1]], ref VertexArray[IndexArray[i + 2]], out chu ); AllChunks.Add( chu ); } Chunk.GetArray( ref AllChunks, out VertexArray, out IndexArray ); AllChunks.Clear(); #endregion Assemble Chunks and convert to Arrays } } for (int i=0; i