Handling input devices is essential to any application, but probing sensors is important for the smartest one! The most spread sensor among Android game applications is the accelerometer.
An accelerometer, as its name suggests, measures the linear acceleration applied to a device. When moving a device up, down, left, or right, the accelerometer gets excited and indicates an acceleration vector in 3D space. Vector is expressed in relation to the screen's default orientation. The coordinate system is relative to the device's natural orientation:
Axes become inverted if the device is rotated (for example, Y points left if the device is rotated 90 degrees clockwise).
A very interesting feature of accelerometers is that they undergo a constant acceleration: gravity, around 9.8m/s2 on earth. For example, when lying flat on a table, acceleration vector indicates -9.8 on the Z-axis. When straight, it indicates the same value on Y axis. So assuming the device position is fixed, device orientation on two axes in space can be deduced from the gravity acceleration vector. A magnetometer is still required to get full device orientation in 3D space.
So we can use the device orientation deduced from the accelerometer to compute a direction. Let's now see how to apply this process in DroidBlaster
.
3.143.228.40