Using getRotationMatrix and getOrientation in Android 2.1

前端 未结 2 1943
误落风尘
误落风尘 2020-12-30 12:40

I\'ve been having issues with this for far too long. This code should output dx,dy,dz for the accelerometer, and a running total of the dx. It should also output azimuth,

2条回答
  •  庸人自扰
    2020-12-30 13:00

    I might be missing something (and you may have solved this already), but to me it looks like your switch statement is incorrect:

    switch (event.sensor.getType()) {
            case Sensor.TYPE_ACCELEROMETER:
                accelerometerValues = event.values.clone();
            case Sensor.TYPE_MAGNETIC_FIELD:
                geomagneticMatrix = event.values.clone();
                sensorReady = true;
                break;
            default:
                break;
        }
    

    If your sensor event is TYPE_ACCELEROMETER the values from the event will be cloned to both accelerometerValues and geomagneticMatrix and sensorReady will be set to true. I think you may need to change the order of this block, or possibly add a break; after your first case.

提交回复
热议问题