有2种方式获得3个旋转值(方位,俯仰,滚动).
一个是注册TYPE_ORIENTATION类型的侦听器.这是最简单的方法,我从每个轮播获得正确的价值范围,因为文档说:
方位:[0,359]
间距:[-180,180]
卷:[-90,90]
另一个,最准确和复杂的了解你第一次看到它. Android推荐它,所以我想使用它,但我得到不同的值.
方位:[-180,180]. -180 / 180是S,0i N,90E和-90W
音高:[-90,90]. 90是90,-90是-90,0是0,但是-180/180(屏幕向下)是0.
卷:[-180,180].
我应该得到相同的值,但用小数,对吧?
我有以下代码:
aValues = new float[3];
mValues = new float[3];
sensorListener = new SensorEventListener (){
public void onSensorChanged (SensorEvent event){
switch (event.sensor.getType ()){
case Sensor.TYPE_ACCELEROMETER:
aValues = event.values.clone ();
break;
case Sensor.TYPE_MAGNETIC_FIELD:
mValues = event.values.clone ();
break;
}
float[] R = new float[16];
float[] orientationValues = new float[3];
SensorManager.getRotationMatrix (R, null, aValues, mValues);
SensorManager.getOrientation (R, orientationValues);
orientationValues[0] = (float)Math.toDegrees (orientationValues[0]);
orientationValues[1] = (float)Math.toDegrees (orientationValues[1]);
orientationValues[2] = (float)Math.toDegrees (orientationValues[2]);
azimuthText.setText ("azimuth: " + orientationValues[0]);
pitchText.setText ("pitch: " + orientationValues[1]);
rollText.setText ("roll: " + orientationValues[2]);
}
public void onAccuracyChanged (Sensor sensor, int accuracy){}
};
请帮忙.这很令人沮丧.
我必须用这些价值观来对待我吗?
谢谢.