Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use onSensorChanged sensor data in combination with OpenGL

I couldn't test the code yet (but I will, looks really interesting). One thing that caught my attention is that you don't seem to filter the sensor data in any way.

Sensor readings are very noisy by nature, specially the magnetic sensor. I'd suggest you implement some low pass filtering.

See my previous answer for further reading.


It would be easier to test and debug Method 5 using GLU's lookAt function: http://www.opengl.org/sdk/docs/man2/xhtml/gluLookAt.xml

Also, as villoren suggested it's good to filter your sensor data, but it wouldn't really cause bugs if you move de device slowly. If you want to try, a simple one would be as follows:

newValue = oldValue * 0.9 + sensorValue * 0.1;
oldValue = newValue;

After analyze your code above, in method 5 you are assigning the orientation data as follows,

resultingAngles[1] = orientationData[0]; // orientation z axis to y axis
resultingAngles[2] = orientationData[1]; // orientation x axis to z axis 
resultingAngles[0] = orientationData[2]; // orientation y axis to x axis

You have done rotation in y z x manner. Try to change the orientation..

I think it might be the problem there.. Please check and let me know..

Please refer the documentation for the event values, http://developer.android.com/guide/topics/sensors/sensors_position.html

Thanks for your tough work..