Hi there! Glad you made it to this second series of 3D XNA Tutorials. We’re going to cover some new XNA features, put them together into one project, and end up with a real flight simulator! Again, the main goal is to show you some principles of XNA, so don’t expect complete realistic flight physics, such as gravity, coriolis and others. This would add too much maths, and draw our attention away from the XNA part.
Initialization of our Project
The sole purpose of this first chapter is to set up our starting code. The code should be very simple to understand if you’ve finished the first series. This is what the starting code does:
- Loading the effect
- Positioning the camera
- Clearing the window and Z buffer in the Draw method
So open a new Windows Game (4.0) project as described in chapter one of the first series, I named my project Series3D2. You’re free to give your project a different name, but then you must replace the namespace of my code with your project name. This line is the first line under your using-block in my code.
If you haven’t done this already, you can download my standard effect file here, which you need to import into your XNA project as explained in “The Effect file” in series 1. This effect file contains all techniques we’re going to need in this second series. Remember, you’ll learn everything you need to know about effect files in the third series. Now simply copy-paste the code below into the Game1.cs file.
Compiling and running the code should give you an empty window, cleared to a color of your choice by XNA:
Click here to go to the forum on this chapter!
Or click on one of the topics on this chapter to go there:
AspectRatio in XNA 1.0
I am basically combinding these 2.0 tutorials with...error
i have detected an error in initialize(). I think ...Doesn'r use Content Pipeline
Hi, first of all I'm really enjoying these tutori...
We’re ready to start our second project.
public class Game1 : Microsoft.Xna.Framework.Game
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
protected override void Initialize()
graphics.PreferredBackBufferWidth = 500;
graphics.PreferredBackBufferHeight = 500;
graphics.IsFullScreen = false;
Window.Title = "Riemer's XNA Tutorials -- 3D Series 2";
protected override void LoadContent()
spriteBatch = new SpriteBatch(GraphicsDevice);
device = graphics.GraphicsDevice;
effect = Content.Load<Effect>
private void SetUpCamera()
viewMatrix = Matrix.CreateLookAt(new Vector3(0, 0, 30), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 0.2f, 500.0f);
protected override void UnloadContent()
protected override void Update(GameTime gameTime)
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
protected override void Draw(GameTime gameTime)
device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.DarkSlateBlue, 1.0f, 0);
- Website design & XNA + DirectX code : Riemer Grootjans -
©2003 - 2011 Riemer Grootjans