Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
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

Refactoring our code


Just like with 2D, we need to refactor our code so it remains clean. We've drawn one model now, but if we were to draw many models and add movement to them, our code would get cluttered. So we will add some classes in the same manner as we did with 2D.

The base class

The base class for all our 3D objects is called GameObject3D . This class will contain the position, rotation, and scale of the object, along with the necessary methods to initialize, update, and draw models. This class is abstract, because we don't need to be able to instantiate it.

Properties

This class will have four properties, of which three are public. The position, rotation, and scale are public, while the World matrix is protected (the World matrix is the compiled version of the position, rotation, and scale, as explained in the previous section). The rotation is of type Quaternion, a structure that has four components, and very suited for holding rotations, because unlike matrices it avoids gimbal lock...

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