[英]Android Sensor Upright Rotation
我知道有关于此的主题,而且我已经阅读了好几天。
我认为我的问题更具体。 我正在尝试使设备绕y轴旋转。
如果我是正确的,那就叫做方位角
当我运行应用程序时,在调试记录值[0],值[1]和值[2]后,它在logcat中返回0.0
码:
mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE);
accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
SensorEventListener SEL = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
mSensorManager.getRotationMatrix(rotationMatrix, I, gravity, geomagnetic);
mSensorManager.getOrientation(rotationMatrix, values);
accy = values[0];
System.out.println(accy);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
int rate = SensorManager.SENSOR_DELAY_GAME;
mSensorManager.registerListener(SEL, accelerometer, rate);
mSensorManager.registerListener(SEL, magnetometer, rate);
logcat的:
09-05 17:34:02.622 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.642 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.642 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.662 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.662 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.682 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.682 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.702 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.702 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.722 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.722 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.742 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.742 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.762 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.762 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.782 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.782 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.802 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
09-05 17:34:02.802 6421-6421/com.ahewdev.eataround I/System.out﹕ 0.0
从上面的参数的代码gravity
和geomagnetic
在mSensorManager.getRotationMatrix(rotationMatrix, I, gravity, geomagnetic);
可能zero array
,因此您的accy
始终zero
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.