Game Development Reference
In-Depth Information
When the device is moved along its x axis (shown in red in
Fig. 15.2 ), which runs across the front of the display from left to
right, it registers negative or positive forces. If you were to hold the
device in a horizontal orientation in front of you with the menu
button on the right, as shown in the top half of Fig. 15.3 ,itwould
show y and z values of 0 and an x value of
1. This represents the
force of gravity moving down the x -axis. Conversely, if you rotated
thedevice180degreesaroundthe z -axis, as shown in the bottom
of Fig. 15.3 , this value would reverse to +1.
Similarly, when the device is held upright with the menu button
on the bottom
the most common orientation when using an
iPhone, shown in Fig. 15.4
the y value is affected. In this position,
the force of gravity is traveling straight down the face of the iPhone
and is thus
1. To get a y value of +1, turn the device so that the
menu button is on top.
Finally, when laid facing up on a flat surface, the device regis-
ters x and y values of 0, while the z value is approximately
1. Flip-
ping the iPhone upside down onto its face will change this z value
acceleration X = 1, acceleration Y = 0, acceleration Z = 0
Figure 15.3 The accelerometer
values for the iPhone when it
is facing you and on its side.
acceleration
X
=
1, acceleration
Y
=
0, acceleration
Z
=
0
Search Nedrilad ::

Custom Search