Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building your First Mobile Game using XNA 4.0

You're reading from   Building your First Mobile Game using XNA 4.0 A fast-paced, hands-on guide to building a 3D game for the Windows Phone 7 platform using XNA 4.0

Arrow left icon
Product type Paperback
Published in Jan 2013
Publisher Packt
ISBN-13 9781849687744
Length 158 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Thomas Goussaert Thomas Goussaert
Author Profile Icon Thomas Goussaert
Thomas Goussaert
Brecht Kets Brecht Kets
Author Profile Icon Brecht Kets
Brecht Kets
Arrow right icon
View More author details
Toc

Drawing models


There are several steps we need to take when drawing 3D models. Start by downloading the start files and open the MainGame class. Once this is done, we need to declare our View and Projection matrices. As these contain our camera settings, they will be the same for all 3D models. For each model, we'll need to add fields, load the model, and then draw it.

Adding fields

We'll create three fields: a field for the hero of type Model, and fields for the View and Projection matrices of type Matrix.

Model _hero;
Matrix _view, _projection;

Initialize

In the Initialize method, we will set the values for our View and Projection matrices.

  1. We can create the View matrix by using the static Matrix.CreateLookAt method. It has three arguments. The first is the position of the camera, the second what it's looking at, and the third the up vector. We will place the camera 20 units along the positive z axis, pointed back at the origin.

  2. For the Projection matrix we will use an orthographic projection...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image