Modeling triangles
XNA comes with a number of classes to help deal with the construction and use of vertex arrays, but it can sometimes be beneficial to build our own, so we can customize things according to what we need.
In this recipe, we'll be creating what I've called a Geometry Buffer, and a corresponding factory to help with their construction. Geometry Buffers are really just a container for the vertex and index buffers used in communication with the GPU. They can be thought of as a simplified substitute for XNA's Model
and Mesh
classes.
Getting ready
In order to draw a Geometric Buffer onscreen, an instance of a BasicEffect
will be required. Although texture coordinate handling has been included, using BasicEffect
without textures should work just as well.
How to do it...
To create a disc programmatically:
1. Create a new
GeometricBuffer
class to manage the vertex and index buffers, and add the start of a constructor to populate the various instance-level variables:public class GeometricBuffer...