回答提伯是好的,但如果你日志回滚价值,你会期待不规则的号码。 (卷是AR浏览器很重要)
这是由于
SensorManager.remapCoordinateSystem(mRotationMatrix,
SensorManager.AXIS_X, SensorManager.AXIS_Z,
mRotationMatrix);
你必须使用不同的矩阵进出重映射的。以下代码适用于我的滚动值正确:
@Override
public void onSensorChanged(SensorEvent event)
{
// It is good practice to check that we received the proper sensor event
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR)
{
// Convert the rotation-vector to a 4x4 matrix.
SensorManager.getRotationMatrixFromVector(mRotationMatrixFromVector, event.values);
SensorManager.remapCoordinateSystem(mRotationMatrixFromVector,
SensorManager.AXIS_X, SensorManager.AXIS_Z,
mRotationMatrix);
SensorManager.getOrientation(mRotationMatrix, orientationVals);
// Optionally convert the result from radians to degrees
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 (not used): "
+ orientationVals[2]);
}
}
好吧,那么有没有任何示例如何使用此传感器?我得到x * sin(θ/ 2),y * sin(θ/ 2)和z * sin(θ/ 2)的值。但是,我如何获得价值,我需要建立我的指南针。我应该再次使用getRotationMatrix吗?谢谢你的帮助。 –
“X被定义为矢量积Y.Z(它与设备当前位置的地面相切,大致指向东)。 Y在设备当前位置与地面相切并指向磁北。“ Z指向天空并垂直于地面。” 除尘几何课本或谷歌它:),你应该能够弄清楚。 –