我的增强现实应用需要相机视图的指南针方位,有很多获取传感器管理器方向的例子。然而,我发现结果值取决于手机方向,右侧旋转的横向与左侧旋转的横向相比,大约会有10度的差异(ROTATION_0和ROTATION_180之间的差异较小,但仍不同)。这种差异足以破坏任何AR效果。
这是校准问题吗?(我不确定自己是否正确地进行了8字形操作——我已经尝试了在YouTube上找到的各种方法)。
为什么会有这样的差别?旋转矩阵的问题吗?我可以将应用限制为单一方向,但仍然担心指南针读数不太准确(即使经过滤波后它相对稳定)。
这是校准问题吗?(我不确定自己是否正确地进行了8字形操作——我已经尝试了在YouTube上找到的各种方法)。
为什么会有这样的差别?旋转矩阵的问题吗?我可以将应用限制为单一方向,但仍然担心指南针读数不太准确(即使经过滤波后它相对稳定)。
public void onSensorChanged(SensorEvent event) {
if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
return;
}
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) mGravity = event.values;
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) mGeomagnetic = event.values;
if (mGravity != null && mGeomagnetic != null) {
float[] rotationMatrixA = mRotationMatrixA;
if (SensorManager.getRotationMatrix(rotationMatrixA, null, mGravity, mGeomagnetic)) {
float[] rotationMatrixB = mRotationMatrixB;
Display display = getWindowManager().getDefaultDisplay();
int deviceRot = display.getRotation();
switch (deviceRot)
{
// portrait - normal
case Surface.ROTATION_0: SensorManager.remapCoordinateSystem(rotationMatrixA,
SensorManager.AXIS_X, SensorManager.AXIS_Z,
rotationMatrixB);
break;
// rotated left (landscape - keys to bottom)
case Surface.ROTATION_90: SensorManager.remapCoordinateSystem(rotationMatrixA,
SensorManager.AXIS_Z, SensorManager.AXIS_MINUS_X,
rotationMatrixB);
break;
// upside down
case Surface.ROTATION_180: SensorManager.remapCoordinateSystem(rotationMatrixA,
SensorManager.AXIS_X, SensorManager.AXIS_Z,
rotationMatrixB);
break;
// rotated right
case Surface.ROTATION_270: SensorManager.remapCoordinateSystem(rotationMatrixA,
SensorManager.AXIS_MINUS_Z, SensorManager.AXIS_X,
rotationMatrixB);
break;
default: break;
}
float[] dv = new float[3];
SensorManager.getOrientation(rotationMatrixB, dv);
// add to smoothing filter
fd.AddLatest((double)dv[0]);
}
mDraw.invalidate();
}
}
SensorManager.remapCoordinateSystem
是解决方案。谢谢。 - Douglas Nassif Roma Junior