Question

I know how to get an orientation vector from the accelerometer and the magnetic field sensor, but I don't understand why data from the magnetic field sensor is needed. Could someone explain why? On a related note, do I need to request updates with SENSOR_DELAY_GAME frequency for both when creating a game or can one (the magnetic field sensor, presumably) be updated less frequently without significantly affecting responsiveness?

Was it helpful?

Solution

The accelerometer data is purely used to detect which way is up and which way is down, whereas the magnetic field sensor is needed for the axis which determines north/south/east west. They are both required. Try using a regular compass while it's not flat, it won't work. The accelerometer essentially tells the orientation code how to translate the x/y/z results from the magnetic field sensors.

If however, you told your user that to use the app, they would have to lie their phone flat on its back, (or on its front, or side, etc) then you wouldn't need the accelerometer.

You don't need to use SENSOR_DELAY_GAME, SENSOR_DELAY_NORMAL might even be enough, it would certainly use less battery. However, if you need really accurate results, use SENSOR_DELAY_FASTEST.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top