Book Image

Android NDK: Beginner's Guide

By : Sylvain Ratabouil
Book Image

Android NDK: Beginner's Guide

By: Sylvain Ratabouil

Overview of this book

Table of Contents (18 chapters)
Android NDK Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Probing device sensors


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:

  • X axis points to the right

  • Y points up

  • Z points from back to front

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...