O'Reilly logo

Learning XNA 4.0 by Aaron Reed

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

Digging In

Now let’s get to the actual code. Developing a game for Windows Phone 7 is nearly identical to creating a game for Windows or Xbox 360. In this case, we’re developing a 3D game, and just as in Windows and Xbox 360, you’ll need a camera and some classes to handle your models. Add a Camera.cs class to your project and modify it to use the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;namespace PhoneAsteroids
{

    public class Camera : Microsoft.Xna.Framework.GameComponent
    {
        //Camera matrices
        public Matrix view { get; protected set; }
        public Matrix projection { get; protected set; }



        public Camera(Game game)
            : base(game)
        {
            // Build camera view matrix
            view = Matrix.CreateLookAt(new Vector3(0, 0, 200),
                Vector3.Zero, Vector3.Up);


            // Build camera projection matrix
            projection = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.ToRadians(45.0f),
                1.6666f,
                1, 3000);

        }

        public override void Initialize()
        {

            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {


            base.Update(gameTime);
        }

    }
}

This code is basically the same as all the 3D camera code you’ve created several times already in this book, and so none of this should be too much of a surprise at this point.

Next, add a BasicModel.cs ...

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