From e0a1404d15fc93d0d75097801daa461adb979c28 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Wed, 26 Sep 2007 16:14:32 +0000 Subject: [PATCH] Added IsoSphere.cs which creates a sphere Shape using theta ad phi coordinates. --- Source/Examples/Shapes/IsoSphere.cs | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Source/Examples/Shapes/IsoSphere.cs diff --git a/Source/Examples/Shapes/IsoSphere.cs b/Source/Examples/Shapes/IsoSphere.cs new file mode 100644 index 00000000..47d46870 --- /dev/null +++ b/Source/Examples/Shapes/IsoSphere.cs @@ -0,0 +1,54 @@ +#region --- License --- +/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos + * See license.txt for license info + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using OpenTK.Math; + +namespace Examples.Shapes +{ + class IsoSphere : Shape + { + const double DoublePI = System.Math.PI * 2.0; + + public IsoSphere(int s_steps, int t_steps, float x_scale, float y_scale, float z_scale) + { + int count = 4 * s_steps * t_steps ; + + Vertices = new Vector3[count]; + Normals = new Vector3[count]; + Texcoords = new Vector2[count]; + Indices = new int[6 * count / 4]; + + int i = 0; + for (double t = -System.Math.PI; (float)t < (float)System.Math.PI - Single.Epsilon; t += System.Math.PI / (double)t_steps) + { + for (double s = 0.0; (float)s < (float)DoublePI; s += System.Math.PI / (double)s_steps) + { + Vertices[i].X = x_scale * (float)(System.Math.Cos(s) * System.Math.Sin(t)); + Vertices[i].Y = y_scale * (float)(System.Math.Sin(s) * System.Math.Sin(t)); + Vertices[i].Z = z_scale * (float)System.Math.Cos(t); + //vertices[i] = vertices[i].Scale(x_scale, y_scale, z_scale); + Normals[i] = Vertices[i].Normalize(); + + ++i; + } + } + + for (i = 0; i < 6*count/4; i+=6) + { + Indices[i] = i; + Indices[i + 1] = i + 1; + Indices[i + 2] = i + 2 * s_steps + 1; + Indices[i + 3] = i + 2 * s_steps; + Indices[i + 4] = i; + Indices[i + 5] = i + 2 * s_steps + 1; + } + } + } +}