Drawing Primitives

Now that you have a camera set up and ready to go, you need to draw something on the screen. The root of all 3D drawings is the triangle. If you draw enough triangles, you can render almost any shape possible. Put enough triangles next to each other and make them all small enough, and you can even get a smooth, round surface.

Tip

This actually isn't that unlike the world in which we live. If you took a perfectly smooth surface and looked at it on a microscopic level, the surface would not be smooth at all: it would be full of microscopic ridges and valleys. Our computers aren't powerful enough to mimic that level of detail, but they're definitely improving. Curved and shiny surfaces are amazingly more detailed and realistic today than they were even a few years ago.

Actually, while we're on the subject, much of 3D graphics is built to mimic real life. Lighting effects are meant to act as much like real-world light (or at least, real-world light as far as we currently understand it) as possible, and so on. For the most part, games in general are more enjoyable the more they act and feel like real life. For example, games like Half-Life 2 have greatly benefited from having advanced physics engines that allow players to interact with objects in ways that conform as much as possible to the real-world laws of physics.

To draw your first triangle, you need to define some points, or vertices, to represent each of the corners of the triangle. In your Game1 class, create an ...

Get Learning XNA 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.