ste*_*urt 5 android orientation pitch
我正在开发一个项目,其中包括一个用于控制/转向的Android应用程序.
我已经写了一些似乎工作正常的代码.但是当我仔细观察时,我发现有些价值观很奇怪.
当我向前/向后倾斜手机以处理速度时,它可以完美地运行,我得到了预期的速度和方向值.但是,当我向左/右倾斜手机以处理方向时,它似乎会破坏某些值.当它向左/向右倾斜时,不仅改变方向值(滚动),而且还影响速度值(俯仰).
有关其他信息:
我用来读取传感器值的最相关代码如下:
public void onSensorChanged(SensorEvent sensorEvent)
{
synchronized (this)
{
if (sensorEvent.sensor.getType() == Sensor.TYPE_ORIENTATION)
{
float azimuth = sensorEvent.values[0]; // azimuth rotation around the z-axis
float pitch = sensorEvent.values[1]; // pitch rotation around the x-axis
float roll = sensorEvent.values[2]; // roll rotation around the y-axis
System.out.println("pitch: " + pitch);
System.out.println("roll: " + roll);
System.out.println("--------------------");
// Convert the sensor values to the actual speed and direction values
float speed = (pitch * 2.222f) + 200;
float direction = roll * -2.222f;
Run Code Online (Sandbox Code Playgroud)
因此,当我运行代码时,我会查看打印值.当向左/向右倾斜设备时,它似乎也会影响音高值.怎么会?当'滚动'时,我怎样才能获得纯音高值?因此,将手机向左/向右倾斜不会影响/破坏音高值.
任何帮助深表感谢.
亲切的问候
| 归档时间: |
|
| 查看次数: |
1546 次 |
| 最近记录: |