从Android的加速度方向 [英] Orientation from Android Accelerometer

查看:101
本文介绍了从Android的加速度方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试的加速度计输出的2个不同的设备(Elocity A7和ARCHOS 7家庭平板电脑),但传感器似乎被赋予不同的结果。我有它编程设定为横向模式,但在x和y轴似乎是2设备之间的oppisite。当垂直于地面和爱可视X轴返回0。Elocity平板电脑的Andr​​oid 2.2爱可视是2.1举行x轴返回10。有人能指出我朝着正确的方向怎么走的方向从加速度同步这两个设备之间?

I testing the accelerometer output on 2 different devices(Elocity A7 and Archos 7 Home tablet) but the sensor seems to be giving different results. I have it programmed to set to landscape mode but the x and y axis seem to be the oppisite between the 2 devices. The x axis returns 10 when held perpendicular to the ground and the Archos X axis returns 0. The Elocity tablet is android 2.2 and the Archos is 2.1. Can someone point me in the right direction as how to get orientation from the accelerometer in sync between these 2 devices?

推荐答案

在事实上,所述加速度计轴系是相对于设备的默认取向

In fact, the accelerometer axises are relative to the default orientation of the device.

下面该如何处理它:

static void canonicalOrientationToScreenOrientation(
         int displayRotation, float[] canVec, float[] screenVec) 
{ 
    final int axisSwap[][] = { 
    {  1,  -1,  0,  1  },     // ROTATION_0 
    {-1,  -1,  1,  0  },     // ROTATION_90 
    {-1,    1,  0,  1  },     // ROTATION_180 
    {  1,    1,  1,  0  }  }; // ROTATION_270 

    final int[] as = axisSwap[displayRotation]; 
    screenVec[0]  =  (float)as[0] * canVec[ as[2] ]; 
    screenVec[1]  =  (float)as[1] * canVec[ as[3] ]; 
    screenVec[2]  =  canVec[2]; 
} 

该解决方案由NVIDIA提供的。检查他们白皮书关于Android 加速度计的更多细节。

This solution was provided by NVidia. Check their white paper about Android Accelerometer for more details.

这篇关于从Android的加速度方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆