小编dim*_*ima的帖子

使用旋转矢量传感器

我想知道如何正确使用"旋转矢量传感器"的输出.目前我想出了以下内容并且想要计算偏航和俯仰result[],以便知道设备指向的位置(处于横向模式).但我的结果有问题.偏航计算非常精确但是音高表现得很奇怪.也许任何人都可以指出我如何使用数据的正确方向.我还想知道的另一件事是设备方向(横向或纵向)是否对此传感器的输出有任何影响.提前致谢.

private double max = Math.PI / 2 - 0.01;
private double min = -max;

private float[] rotationVectorAction(float[] values) {
    float[] result = new float[3];
    float vec[] = values;
    float quat[] = new float[4];
    float[] orientation = new float[3];
    SensorManager.getQuaternionFromVector(quat, vec);
    float[] rotMat = new float[9];
    SensorManager.getRotationMatrixFromVector(rotMat, quat);
    SensorManager.getOrientation(rotMat, orientation);
    result[0] = (float) orientation[0];
    result[1] = (float) orientation[1];
    result[2] = (float) orientation[2];     
    return result;
}

private void main () {
    float[] result = rotationVectorAction(sensorInput);
    yaw = result[0];
    pitch …
Run Code Online (Sandbox Code Playgroud)

java rotation orientation opengl-es-2.0 android-sensors

6
推荐指数
1
解决办法
7905
查看次数