从Android的加速度方向加速度、方向、Android

由网友(资深狗友i)分享简介:我测试的加速度计输出的2个不同的设备(Elocity A7和ARCHOS 7家庭平板电脑),但传感器似乎被赋予不同的结果。我有它编程设定为横向模式,但在x和y轴似乎是2设备之间的oppisite。当垂直于地面和爱可视X轴返回0。Elocity平板电脑的Andr​​oid 2.2爱可视是2.1举行x轴返回10。有人能指出...

我测试的加速度计输出的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.

阅读全文

相关推荐

最新文章