Android getOrientation()俯仰反射关于地平线的信息
我注意到,当我把手机举到地平线以下时,手机显示>-90。当我开始倾斜手机使其指向天空时,它会反射大约-90,所以,-88,-90,-88。因为它从地面向天空倾斜 以前有人经历过这种情况吗。(它似乎与剩余协调系统无关)。(我以前把它注释掉了)。当手机摄像头指向地面时,俯仰读数为零。当它指向天花板时,它也为零 谢谢你的帮助Android getOrientation()俯仰反射关于地平线的信息,android,sensors,compass-geolocation,pitch,Android,Sensors,Compass Geolocation,Pitch,我注意到,当我把手机举到地平线以下时,手机显示>-90。当我开始倾斜手机使其指向天空时,它会反射大约-90,所以,-88,-90,-88。因为它从地面向天空倾斜 以前有人经历过这种情况吗。(它似乎与剩余协调系统无关)。(我以前把它注释掉了)。当手机摄像头指向地面时,俯仰读数为零。当它指向天花板时,它也为零 谢谢你的帮助 @Override public void onSensorChanged(SensorEvent event) { synchronized (
@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 && 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);
}
}
}
在调用get-orientation之前,需要临时修复矩阵
Matrix.rotateM(R, 0, 90, 0, 1, 0);
无论你怎么做一个完整的翻转,它都会遇到同样的问题。(这应该通过增加方位角来解决)但这不是一个很好的解决方案
因此,如果其他人正在阅读这篇文章,并试图使地平线为0度。之前旋转矩阵,而不是旋转显示器(我使用OpenGL)最终将应用程序锁定在横向中并应用以下内容
SensorManager.getRotationMatrix(R, null, mAccelerometerValues, mMagneticValues);
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Z, R);//shouldnt be the same R in and out
float[] orientation = new float[3];
SensorManager.getOrientation(R, orientation);
最终在横向锁定应用程序并应用以下内容
SensorManager.getRotationMatrix(R, null, mAccelerometerValues, mMagneticValues);
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Z, R);//shouldnt be the same R in and out
float[] orientation = new float[3];
SensorManager.getOrientation(R, orientation);
你得到的方位角/横摇读数是多少?当你穿过水平面时,它们会翻转吗?当手机背面朝向地面时为0-当背部朝向地平线时。到那时为止的所有值都与预期值一样-45升了一半。这些值用于俯仰,并已使用math LIB转换为度数。但弧度也会出现同样的模式。在调用getOrientation之前,我可能有一个旋转方向矩阵的解决方法。它在水平面上翻转。谢谢你的评论。你得到了什么方位角/滚动读数?当你穿过水平面时,它们会翻转吗?当手机背面朝向地面时为0-当背部朝向地平线时。到那时为止的所有值都与预期值一样-45升了一半。这些值用于俯仰,并已使用math LIB转换为度数。但弧度也会出现同样的模式。在调用getOrientation之前,我可能有一个旋转方向矩阵的解决方法。它在水平面上翻转。谢谢你的评论。