【问题标题】:Using Accelerometer and getting a stable azimuth使用加速度计并获得稳定的方位角
【发布时间】:2014-09-16 05:33:16
【问题描述】:

我一直在寻找如何使用设备硬件(指南针、加速度计)旋转 3D 对象

以下指南很棒: http://ibuzzlog.blogspot.co.uk/2012/08/how-to-use-android-sensors.html?showComment=1409868331799#c665801926070707020

但是,方位角在多个设备上令人难以置信。 (想象一下这是绑在你脸上的,左右看)

@Override
    public void onSensorChanged(SensorEvent event) {

        int type = event.sensor.getType();

        //Log.i("TAG", "Sensor " + type);

        if(event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
        {
            MagneticFieldValues_last[0] = event.values[0];
            MagneticFieldValues_last[1] = event.values[1];
            MagneticFieldValues_last[2] = event.values[2];

            bHaveMagneticField = true;
        }
        if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
        {
            AccelerometerValues_last[0] = event.values[0];
            AccelerometerValues_last[1] = event.values[1];
            AccelerometerValues_last[2] = event.values[2];

            bHaveAccelerometer = true;
        }
        if(bHaveMagneticField && bHaveAccelerometer)
        {
            if(SensorManager.getRotationMatrix(R, null, AccelerometerValues_last, MagneticFieldValues_last))
            {
                SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, remapR);
                SensorManager.getOrientation(remapR, orientationValues);

                Matrix.multiplyMV(orientationVector, 0, remapR, 0, sZVector, 0);
                pitch2 = (float) (-Math.atan2(orientationVector[1], orientationVector[2]) * RADIANS_TO_DEGREES);

                Matrix.multiplyMV(orientationVector, 0, remapR, 0, sZVector, 0);
                orientation = (float) (-Math.atan2(orientationVector[0], orientationVector[1]) * RADIANS_TO_DEGREES);

                Matrix.invertM(remapR_inv, 0, remapR, 0);
                Matrix.multiplyMV(azimuthVector, 0, remapR_inv, 0, sZVector, 0);
                azimuth = (float) (180 + Math.atan2(azimuthVector[0], azimuthVector[1]) * RADIANS_TO_DEGREES);
            }
        }
    }

更新

发现这似乎可以解决问题 http://blog.thomnichols.org/2011/08/smoothing-sensor-data-with-a-low-pass-filter

更新 2

遗憾的是它并没有起到作用,仍然需要一种方法来平滑值。其他人是怎么做到的?

【问题讨论】:

    标签: android accelerometer android-sensors sensormanager


    【解决方案1】:

    如果有人发现这个,只需使用 Google Cardboard 头部跟踪,它完美且易于使用

    https://github.com/MasDennis/RajawaliVR

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-15
      • 1970-01-01
      • 2013-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多