1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
/* get gravity value arrays from Accelerometer */
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
gravity = event.values;
/* get gravity value arrays from Magnet */
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
geoMagnetic = event.values;
if (gravity != null && geoMagnetic != null) {
/* Rotation matrix and Inclination matrix */
float R[] = new float[9];
float I[] = new float[9];
/*
* Compute the inclination matrix I as well as the rotation matrix R
* transforming a vector from the device coordinate system to the
* world's coordinate system R and I [Length 9] gravity vector
* expressed in the device's coordinate [Length 3] geoMagnetic
* vector expressed in the device's coordinate[Length 3]
*/
boolean success = SensorManager.getRotationMatrix(R, I, gravity, geoMagnetic);
if (success) {
/* Orientation has azimuth, pitch and roll */
float orientation[] = new float[3];
SensorManager.getOrientation(R, orientation);
float azimut = (float) Math.toDegrees(orientation[0]); |
Partager