Using Getrotationmatrix And Getorientation In Android 2.1
Solution 1:
I might be missing something (and you may have solved this already), but to me it looks like your switch statement is incorrect:
switch (event.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
accelerometerValues = event.values.clone();
case Sensor.TYPE_MAGNETIC_FIELD:
geomagneticMatrix = event.values.clone();
sensorReady = true;
break;
default:
break;
}
If your sensor event is TYPE_ACCELEROMETER
the values from the event will be cloned to both accelerometerValues
and geomagneticMatrix
and sensorReady
will be set to true. I think you may need to change the order of this block, or possibly add a break;
after your first case.
Solution 2:
The reason you're getting 0.0, -0.0, -0.0 from getOrientation() is that getRotationMatrix() doesn't always get a valid result. You need to check getRotationMatrix()'s return value, which will be false if the result is invalid, or true if it succeeded.
Added: Actually, that didn't come out right. You're getting an invalid result for the reason aganders pointed out. Checking the return value would simply be an indication that you were in fact getting an invalid result.
Post a Comment for "Using Getrotationmatrix And Getorientation In Android 2.1"