dsfml.window.sensor

$(U Sensor) provides an interface to the state of the various sensors that a device provides. It only contains static functions, so it's not meant to be instantiated.

This class allows users to query the sensors values at any time and directly, without having to deal with a window and its events. Compared to the SensorChanged event, Sensor can retrieve the state of a sensor at any time (you don't need to store and update its current value on your side).

Depending on the OS and hardware of the device (phone, tablet, ...), some sensor types may not be available. You should always check the availability of a sensor before trying to read it, with the Sensor.isAvailable function.

You may wonder why some sensor types look so similar, for example Accelerometer and Gravity / UserAcceleration. The first one is the raw measurement of the acceleration, and takes into account both the earth gravity and the user movement. The others are more precise: they provide these components separately, which is usually more useful. In fact they are not direct sensors, they are computed internally based on the raw acceleration and other sensors. This is exactly the same for Gyroscope vs Orientation.

Because sensors consume a non-negligible amount of current, they are all disabled by default. You must call Sensor.setEnabled for each sensor in which you are interested.

Members

Classes

Sensor
class Sensor

Give access to the real-time state of the sensors.

Examples

1 if (Sensor.isAvailable(Sensor.Type.Gravity))
2 {
3    // gravity sensor is available
4 }
5 
6 // enable the gravity sensor
7 Sensor.setEnabled(Sensor.Type.Gravity, true);
8 
9 // get the current value of gravity
10 Vector3f gravity = Sensor.getValue(Sensor.Type.Gravity);

Meta