我正在使用 getRotationMatrix() 在 onSensorChanged() 方法中计算 v[0]、v[1]、v[2] 和相应的方位角、俯仰角和横滚值。我想知道当布尔检测方位角变为真时,如何仅将第一个 v[0] (或相应的方位角)值保存到 firstAzimuth 中?
private boolean detectAzimuth = false;
private float firstAzimuth;
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
accValues = event.values.clone();
}
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
geoValues = event.values.clone();
}
boolean success = SensorManager.getRotationMatrix(r, i, accValues,
geoValues);
if (success) {
SensorManager.getOrientation(r, v);
if (detectAzimuth) {
azimuth = v[0] * (180 / Math.PI);
}
pitch = v[1] * (180 / Math.PI);
roll = v[2] * (180 / Math.PI);
}
}