回答提伯是好的,但如果你日誌回滾價值,你會期待不規則的號碼。 (卷是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指向天空並垂直於地面。」 除塵幾何課本或谷歌它:),你應該能夠弄清楚。 –