Search icon CANCEL
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
OpenGL Game Development By Example

You're reading from   OpenGL Game Development By Example Design and code your own 2D and 3D games efficiently using OpenGL and C++

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher
ISBN-13 9781783288199
Length 340 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Robert Madsen Robert Madsen
Author Profile Icon Robert Madsen
Robert Madsen
Stephen Madsen Stephen Madsen
Author Profile Icon Stephen Madsen
Stephen Madsen
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Taking control

We now have a framework to load and render game objects. But, we don't have any way to move our ship! The good news is that we already wrote an input class for RoboRacer2D, and we can reuse that code here.

Implementing input

Earlier in the chapter, I had you copy the Input class from RoboRacer2D into the source folder for SpaceRacer3D. Now, we have to simply wire it into our game code.

Open SpaceRacer3D. First, we need to include the input header. Add the following line of code to the headers:

#include "Input.h"

We also need to create a global pointer to manage the Input class. Add the following line just below the model pointers:

Input* m_input;

Next, we need to create an instance of the Input class. Add the following line of code to the top of the StartGame function:

m_input = new Input(hWnd);

Now, we have to create a function to handle our input. Add the following function just above the Update method:

void ProcessInput(const float p_deltaTime)
{
 Vec3 rotation;
...
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