Game Development Reference
In-Depth Information
Figure 5.5 Accelerometer (a) and gyroscope (b).
Because an accelerometer measures acceleration, there is one constant that will al-
ways be applied to the device: gravity. This means that if the device is at rest, the
accelerometer can roughly determine the orientation the device is held at based on
which axis is being affected by gravity. So if the device is in a portrait orientation,
gravity should be along the device's y-axis, whereas if it's in a landscape orienta-
tion, gravity would be along the device's x-axis.
A gyroscope , on the other hand, is designed to measure rotation about the device's
principle axes, as illustrated in Figure 5.5(b) . This means that it is possible to get
very precise measurements of the device's orientation with the gyroscope. One
non-gaming example that the gyroscope is well-suited for is a bubble level app
that can determine whether or not a picture on the wall is level.
Trying to derive meaningful information from the raw accelerometer and gyro-
scope data can be challenging, so the device SDKs typically have higher-level
functionality that aggregates it into easy-to-use information. For example, on iOS
it is possible to use CMDeviceMotion to extract information such as the gravity
vector, user acceleration, and attitude (or orientation of the device). And each of
Search WWH ::




Custom Search