Game Development Reference
In-Depth Information
Note
For more details on matrices and rotation in 3D, see the Appendix , Adding the
Third Dimension .
This particular class is designed to help make game development using the sensors
easier by providing the rotation information in a form that is useful to game deve-
lopers—particularly those working in 3D. The representations provided by this class
aren't as useful to us for a 2D game so we won't use them however, if you're working
with a 3D game, this is an excellent system that provides readymade data for you to
use.
Practice makes perfect
Now we'll take the most relevant sensor for our needs, the inclinometer, and use it to
add in a new input method that uses the pitch of the device to move the ship up and
down on the screen. We'll use the inclinometer because it provides the basic angles
that we need to implement this input method, and this sensor is available on tablets
like the Surface RT. The key thing to remember is that this is an optional input meth-
od, and you need to ensure you do the appropriate checks to not have any problems
if the player is on a machine that does not support the sensor. You can restrict this if
your game relies on the sensor—we will cover this in a later chapter.
We will start by creating a new trigger implementation that we will call the Inclino-
meterTrigger . This will act similarly to our other triggers and will handle the polling
of the inclinometer to get the latest values. This is shown in the code snippet that
follows:
typedef enum
{
Pitch,
Roll,
Yaw
} RotationAxis;
class InclinometerTrigger :
Search WWH ::




Custom Search