2

我正在使用 android 的 TYPE_ROTATION_VECTOR 传感器来确定围绕 x、y 和 z 的旋转,并以某种方式在我的应用程序中使用这些度量。但是当我围绕 X 轴旋转手机时,滚动值(围绕 Y 轴旋转)也会发生变化。我不希望那样。当我绕 X 旋转时,如何忽略滚动的变化?这是我的一段代码

private final float[] mRotationMatrix = new float[16];
private float[] orientationVals = new float[3];

if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {

             SensorManager.getRotationMatrixFromVector(
                     mRotationMatrix , event.values);
             SensorManager.getOrientation(mRotationMatrix, orientationVals);

             azimuthVal =  (Math.round((Math.toDegrees(orientationVals[0]))*100.0)/100.0);
             pitchVal= (Math.round((Math.toDegrees(orientationVals[1]))*100.0)/100.0);
             rollVal = (Math.round((Math.toDegrees(orientationVals[2]))*100.0)/100.0);
             }
4

0 回答 0