O'Reilly logo

Microsoft XNA 4.0 Game Development Cookbook by Luke Drumm

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required