如何围绕Y轴滚动?,当设备保持平直但当设备保持垂直,面前时我没有工作:(请帮我这个。
float[] gravity = new float[3];
private float[] acceleration = new float[3];
//Above globel variables
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
lowPassFilter.filter(event.values);
System.arraycopy(acceleration, 0, this.acceleration, 0, acceleration.length);
gravity = event.values.clone();
double norm_Of_g = Math.sqrt(gravity[0] * gravity[0] + gravity[1] * gravity[1] + gravity[2] * gravity[2]);
// Normalize the accelerometer vector
gravity[0] = (float) (gravity[0] / norm_Of_g);
gravity[1] = (float) (gravity[1] / norm_Of_g);
gravity[2] = (float) (gravity[2] / norm_Of_g);
int rotation = (int) Math.round(Math.toDegrees(Math.atan2(gravity[0], gravity[1])));
tvXYZ.setText(String.format("X:%.2f, Y:%.2f, Z:%.2f\nArray Size: %d, Position in Array : %d",
gravity[0], gravity[1], gravity[2], list.size(), rotation));
imageView.setRotationY(rotation);
}