我正在实现一个简单的 Android 应用程序,我需要在其中识别北方。
所以我已经实现SensorEventListener
并使用了这样的东西:
@Override
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR)
{
SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values);
SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, orientationVals);
SensorManager.getOrientation(mRotationMatrix, orientationVals);
orientationVals[0] = (float) Math.toDegrees(orientationVals[0]);
orientationVals[1] = (float) Math.toDegrees(orientationVals[1]);
orientationVals[2] = (float) Math.toDegrees(orientationVals[2]);
tv.setText(" Yaw: "+ orientationVals[0] +"\n Pitch: "+ orientationVals[1]+"\n Roll: "+ orientationVals[2]);
}
}
问题是代码行
SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, orientationVals);
似乎不起作用,因为在这两种情况下(有或没有此代码行),Yaw(方位角)的值取决于手机头部的方向(让它放在背面)
我的预期是,使用我的重新映射,Yaw 会根据手机背面(后置摄像头)的方向而改变。
为什么我的重新映射不起作用?