I want to get the android sensors to work with opengl to rotate the opengl\'s camera to wherever the phone is pointing to.
To elaborate: if the player is looking at
You're supplying null
for the inclination matrix - that's not correct.
SensorManager.getRotationMatrix(rotationMatrix, null, gravity, geomag);
There are lots of examples on how to use the SensorManager's getRotationMatrix(...)
.
float[] R = new float[16];
float[] I = new float[16];
if (SensorManager.getRotationMatrix(R, I, accelerometerValues, geomagneticValues)) {
float[] anglesInRadians = new float[3];
SensorManager.getOrientation(R, anglesInRadians);
...
}
Also "rotate the opengl's camera to wherever the phone is pointing to" is rather ambiguous. For instance, if you meant some sort of a augmented reality approach, then you should be mapping AXIS_X
to AXIS_Z
. Note that remapping might not even be necessary, e.g. when you already fix your activity to landscape mode. More details here.
Some example codes involving sensor data and OpenGL ES: