O'Reilly logo

3D Graphics with XNA Game Studio 4.0 by Sean James

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

Creating a Camera class

Much like we did with the CModel class, let's create a reusable Camera class. We'll start with a base class that represents a camera at its lowest level: simply the view and projection matrices. We use a base class that all camera types will inherit from because we want to be able to use all camera types interchangeably. This Camera base class will also take care of calculating the projection matrix unless derived classes choose to do so themselves.

public abstract class Camera { public Matrix View { get; set; } public Matrix Projection { get; set; } protected GraphicsDevice GraphicsDevice { get; set; } public Camera(GraphicsDevice graphicsDevice) { this.GraphicsDevice = graphicsDevice; generatePerspectiveProjectionMatrix(MathHelper.PiOver4); ...

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