Note that there are some explanatory texts on larger screens.

plurals
  1. PODifferent values between sensors TYPE_ACCELEROMETER/TYPE_MAGNETIC_FIELD and TYPE_ORIENTATION
    text
    copied!<p>There are 2 ways to get the 3 rotation values (azimuth, pitch, roll).</p> <p>One is registering a listener of a type TYPE_ORIENTATION. It's the easiest way and I get a correct range of values from every rotation as the documentation says: azimuth: [0, 359] pitch: [-180, 180] roll: [-90, 90]</p> <p>The other one, the most precise and complex to understand the first time you see it. Android recommends it, so I want to use it, but I get different values.</p> <p>azimuth: [-180, 180]. -180/180 is S, 0 i N, 90 E and -90 W.<br/> pitch: [-90, 90]. 90 is 90, -90 is -90, 0 is 0 but -180/180 (lying with the screen downwards) is 0.<br/> roll: [-180, 180].</p> <p>I should get the same values but with decimals, right?</p> <p>I have the following code:</p> <pre><code>aValues = new float[3]; mValues = new float[3]; sensorListener = new SensorEventListener (){ public void onSensorChanged (SensorEvent event){ switch (event.sensor.getType ()){ case Sensor.TYPE_ACCELEROMETER: aValues = event.values.clone (); break; case Sensor.TYPE_MAGNETIC_FIELD: mValues = event.values.clone (); break; } float[] R = new float[16]; float[] orientationValues = new float[3]; SensorManager.getRotationMatrix (R, null, aValues, mValues); SensorManager.getOrientation (R, orientationValues); orientationValues[0] = (float)Math.toDegrees (orientationValues[0]); orientationValues[1] = (float)Math.toDegrees (orientationValues[1]); orientationValues[2] = (float)Math.toDegrees (orientationValues[2]); azimuthText.setText ("azimuth: " + orientationValues[0]); pitchText.setText ("pitch: " + orientationValues[1]); rollText.setText ("roll: " + orientationValues[2]); } public void onAccuracyChanged (Sensor sensor, int accuracy){} }; </code></pre> <p>Please help. It's very frustrating.</p> <p>Do I have to treat with those values or I'm doing something wrong?</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload