Cameras

So, now that you understand coordinate systems, let's talk about cameras. As mentioned previously, drawing a scene in 3D is much like recording a movie with a handheld camera. You have to define where the camera is located, what it's pointing at, and various other properties.

These properties are stored in a Matrix object. Matrices are fairly complex mathematical entities that are well beyond the scope of this chapter and the book in general. Suffice it to say that matrices are at the heart of almost everything you do in 3D graphics. Fortunately, XNA handles all the hairy matrix details behind the scenes, and at this point, you really don't need to concern yourself with how it all unfolds. For now, just understand that a matrix or two can represent a camera.

There are two Matrix objects that make up a camera in XNA: the view and projection matrices. The view matrix holds information that determines where the camera sits in the world, what direction it's pointing in, and what its orientation is. The projection matrix holds information that determines properties of the camera based on the angle of the view, how far the camera can see, and so forth. This matrix represents the transformation from the 3D world to the 2D plane of the screen.

To create a view matrix, you use a static method from the Matrix class called CreateLookAt. This method returns a Matrix object and accepts the parameters listed in Table 9-1.

Table 9-1. Parameters of Matrix.CreateLookAt

Parameter

Type

Description ...

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.