我有以下使用陀螺仪传感器的代码,但它不符合我的需要,因为它只给我在特定时间内的xyz变化。有没有办法获得绝对xyz旋转坐标。就像我的智能手机正在铺设在地面上一样,它有x = 0°,当它倾斜时,它有类似于34°
SensorManager sensorManager =
(SensorManager) getSystemService(SENSOR_SERVICE);
Sensor gyroscopeSensor =
sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
SensorEventListener gyroscopeSensorListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
float dx = sensorEvent.values[0];
float dy = sensorEvent.values[1];
float dz = sensorEvent.values[2];
Log.e("COORD",dx + " " + dy + " " + dz);
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int i) {
}
};
sensorManager.registerListener(gyroscopeSensorListener,
gyroscopeSensor, SensorManager.SENSOR_DELAY_FASTEST);