Game Development Reference
In-Depth Information
Accelerometers in Android and iOS devices are exposed by LibGDX using the three
axes x , y , and z , which can be queried via the Gdx.input module. For instance, the
current acceleration value for the x axis can be easily retrieved as follows:
float ax = Gdx.input.getAccelerometerX();
This is great, but what does the value that we just stored in ax actually mean?
Moreover, what will influence it? So, to better understand how sensors work, we
need to know what exactly is measured.
Let's start with the range of values. In the documentations of Android and LibGDX,
the values for accelerometers are said to range between -10.0f and 10.0f . This
roughly resembles a value of what we know as the constant for gravity on earth,
approximately 9.81 meters per square second. However, what we still do not know
about is the internal orientation of the sensor hardware inside a device. This poses
a problem to us because we cannot tell which axis is which. Luckily, LibGDX
comes to the aid and is able to make an educated guess that is also reliable. There
is a blog post by Mario Zechner that describes the issue about the different so-
called native orientations in more detail at http://www.badlogicgames.com/
wordpress/?p=2041 .
All we have to remember is that LibGDX will make sure that the y axis always
coincides with the bigger side while the x axis coincides with the smaller one. The z
axis comes out of the screen.
An image taken from Android's SDK developer website that nicely illustrates the
sensor coordinate system is as follows:
y
x
z
 
Search WWH ::




Custom Search