Modeling spheres
Spheres tend to a be a popular choice for modeling programmatically, as they tend to appear in a lot of places in games where manually modeling them would be an exercise in tedium, such as particle effects and planetary bodies.
The method demonstrated here is a personal favorite as it generates a mesh similar in look to a geodesic dome, with its surface being built up from a collection of identical triangles woven together as opposed to other techniques, which can result in squashed and irregular triangles near the poles or equator.
Getting ready
This example was written with the GeometricBuffer
classes in mind, presented in the Modeling triangles recipe, but should be equally applicable with any mesh building framework.
How to do it...
To create a disc programmatically:
1. Add a new
Triangle
class to hold the triangle data during the sphere creation calculations:class Triangle { public Vector3 One; public Vector3 Two; public Vector3 Three; public Vector2 OneTexture; public...