Note that there are some explanatory texts on larger screens.

plurals
  1. POgetOrientation() Pitch reflects about horizon
    text
    copied!<p>Ive notice when I hold my phone just below the horizon I get > -90. When I begin to tilt the phone so its pointing towards the sky it reflects around -90 so, -88, -90, -88. As its tilted from the ground to the sky.</p> <p>Has anyone experienced this before. (It doesnt seem to be related to the remapCoordinateSystem). (Ive previously commented it out). When the phone camera is pointed towards the ground the pitch reading is zero. When its pointed towards the ceiling its also zero.</p> <p>Thanks for any help. </p> <pre><code> @Override public void onSensorChanged(SensorEvent event) { synchronized (MainActivity.this) { // TilteController switch (event.sensor.getType()) { case Sensor.TYPE_MAGNETIC_FIELD: mMagneticValues = event.values.clone(); break; case Sensor.TYPE_ACCELEROMETER: mAccelerometerValues = event.values.clone(); break; } if (mMagneticValues != null &amp;&amp; mAccelerometerValues != null) { SensorManager.getRotationMatrix(R, null, mAccelerometerValues, mMagneticValues); Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int rotation = display.getRotation(); switch (rotation) { case Configuration.ORIENTATION_LANDSCAPE: SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_MINUS_X, R);//shouldnt be the same R in and out case Configuration.ORIENTATION_PORTRAIT: SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_Y, SensorManager.AXIS_X, R);//shouldnt be the same R in and out } float[] orientation = new float[3]; SensorManager.getOrientation(R, orientation); mAzimuth = orientation[0]; mPitch = orientation[1]; mRoll = orientation[2]; dirText.setText("Azimuth, Pitch, Roll || " + radStr(mAzimuth) +", "+ radStr(mPitch) +", "+ radStr(mRoll)); glView.rotate((float)Math.toDegrees(mAzimuth),(float)Math.toDegrees(mPitch),(float)Math.toDegrees(mRoll)); //glView.azimuth=(float)Math.toDegrees(smooth(mAzimuth)); glView.pitch=(float)(Math.toDegrees(smooth(mPitch)));//-90 makes it cenetr //glView.roll=(float)Math.toDegrees(smooth(-mRoll)); //Log.i("Azimuth, Pitch, Roll", mAzimuth+", "+mPitch+", "+mRoll); } } } </code></pre> <hr> <p>A temporary fix for my needs involves rotating the matrix before calling get orientation.</p> <pre><code>Matrix.rotateM(R, 0, 90, 0, 1, 0); </code></pre> <p>How ever you do a complete flip, it experiences the same issue. (This should be solved by adding in Azimuth) But it isnt a brilliant solution.</p> <p>So if others are reading this and are trying to make the horizon 0 degrees. Rotate the matrix before, as oppose to rotating your display (Im using OpenGL) </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