나는 이것에 대해 너무 오랫동안 문제를 겪어왔다. 이 코드는 가속도계의 dx, dy, dz 및 dx의 누적 합계를 출력해야합니다. 또한 방위각, 피치 및 롤을 출력해야합니다.안드로이드 2.1에서 getRotationMatrix와 getOrientation 사용하기
I've used the information given here 그러나 아무 소용이 없습니다.
이 코드는 피치, 방위각 또는 롤을 올바르게 출력하지 않습니다. 그것은 마지막 세 textviews 각각 0.0, -0.0, -0.0을 출력합니다.
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 (geomagneticMatrix != null && accelerometerValues != null && sensorReady) {
sensorReady = false;
float[] R = new float[16];
float[] I = new float[16];
SensorManager.getRotationMatrix(R, I, accelerometerValues, geomagneticMatrix);
float[] actual_orientation = new float[3];
SensorManager.getOrientation(R, actual_orientation);
tvXCoordinate.setText(accelerometerValues[0] + "");
tvYCoordinate.setText(accelerometerValues[1] + "");
tvZCoordinate.setText(accelerometerValues[2] + "");
floatXTotal += accelerometerValues[0];
tvXTotal.setText(floatXTotal + "");
tvAzimuth.setText(actual_orientation[0] + "");
tvPitch.setText(actual_orientation[1] + "");
tvRoll.setText(actual_orientation[2] + "");
}