Modeling tori
I suspect the world of gaming would be a far poorer place without the wonders of doughnuts, inner tubes and other torus related items, so it seems only right to explore how to construct one programmatically.
Getting ready
As with all the other recipes in this chapter, a mesh building framework, such as the one described in the Modeling triangles recipe of this chapter, is required. However, the choice isn't limited to any particular one.
How to do it...
To create a disc programmatically:
1. Create an instance of a
VertexPositionTextureNormalGeometricBufferFactory: var factory = new VertexPositionNormalTextureGeometricBufferFactory();
2. Define the dimensions of the torus you wish to create:
var majorRadius = 2f; var majorSegmentCount = 16; var majorSegmentAngle = MathHelper.TwoPi / (float)majorSegmentCount; var majorTranslation = Matrix.CreateTranslation( Vector3.UnitX * majorRadius); var minorRadius = 0.5f; var minorSegmentCount = 16; var minorSegmentAngle = MathHelper.TwoPi...