protected void Triangulate()
{
float stackHeight = Length / Stacks;
float radianIncr = MathUtils.DegreesToRadians(fArcDegrees / Slices);
// Construct the collections we'll use
List<Vector3f> vertices = new List<Vector3f>();
List<Vector3f> normals = new List<Vector3f>();
List<int> indices = new List<int>();
List<TextureCoordinates> textures = new List<TextureCoordinates>();
// Length of the cylinder: Fill in the collections.
for (int stack = 0; stack <= Stacks; stack++)
{
double y = Length - stack * stackHeight;
int top = (stack + 0) * (Slices + 1);
int bot = (stack + 1) * (Slices + 1);
double theta = MathUtils.DegreesToRadians(180 - ((float)fArcDegrees / 2));
for (int slice = 0; slice <= Slices; slice++)
{
double x = Radius * Math.Sin(theta);
double z = Radius * Math.Cos(theta) + Radius;
vertices.Add(new Vector3f((float)x, (float)y, (float)z));
float txCoord = fTextureShard.Right - fTextureShard.Width * (float)slice/Slices;
float tyCoord = 1.0f - (fTextureShard.Height * (float)stack / Stacks);
textures.Add(new TextureCoordinates(txCoord, tyCoord));
normals.Add(new Vector3f((float)x, (float)y, (float)-z));
if (stack < Stacks && slice < Slices)
{
indices.Add(top + slice);
indices.Add(bot + slice);
indices.Add(top + slice + 1);
indices.Add(top + slice + 1);
indices.Add(bot + slice);
indices.Add(bot + slice + 1);
}
theta += radianIncr;
}
}
this.Vertices = vertices.ToArray();
this.Normals = normals.ToArray();
this.Indices = indices.ToArray();
this.TexCoords = textures.ToArray();
}
}