1

我正在开发一个Android 2.2应用程序。

我想知道用户何时向上或向下移动设备,何时向左或向右移动。垂直安装时,设备将处于静止状态。换句话说,将相机(沿相机轴的 Y 轴)用于需要旋转角度的增强现实应用:

remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR); 

这是我的代码:

public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
        accelValues = event.values;
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
        magneValues = event.values;

  updateOrientation(calculateOrientation());
}

private float[] calculateOrientation() {
    float[] values = new float[3];
    float[] R = new float[9];
    float[] outR = new float[9];

    SensorManager.getRotationMatrix(R, null, accelValues, magneValues);
    SensorManager.remapCoordinateSystem(R, 
                                          SensorManager.AXIS_X, 
                                          SensorManager.AXIS_Z, 
                                          outR);

    SensorManager.getOrientation(outR, values);

    // Convert from Radians to Degrees.
    values[0] = (float) Math.toDegrees(values[0]); // Azimuth, rotation around Z
    values[1] = (float) Math.toDegrees(values[1]); // Pitch, rotation around X
    values[2] = (float) Math.toDegrees(values[2]); // Roll, rotation around Y

    return values;
}

但我不确定如何知道用户是向左还是向右移动设备。

而且,我怎么知道用户是否走路?

有 Azimuth、Pitch 和 Roll,但我不知道如何使用这些值。

有什么建议吗?

4

0 回答 0