Modeling discs
Discs don't represent a particularly difficult exercise in terms of modeling programmatically, but if you're anything like me, you'll find yourself using them as a basis for a whole lot of other, more complex modeling tasks such as cylinders, tori, and hemispheres. Therefore, having a reference implementation at hand can be useful.
Getting ready
This example was written with the GeometricBuffer
class, and related ones demonstrated in the Modeling triangles recipe covered earlier in this chapter, but is equally applicable for use with any mesh building framework.
How to do it...
To create a disc programmatically:
1. Create some variables to hold the specifications of the disc:
var discRadius = 0.5f; var segmentCount = 16; var segmentAngle = MathHelper.TwoPi / (float)segmentCount;
2. Create a loop to iterate around the circle in steps equaling one segment:
for (var segmentIndex = 0f; segmentIndex < segmentCount; segmentIndex++) discsmodeling{
3. Calculate the left- and right...