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

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

问题描述

我在 2 个不同的设备(Elocity A7 和 Archos 7 Home 平板电脑)上测试了加速度计输出,但传感器似乎给出了不同的结果.我已将其编程为设置为横向模式,但 x 轴和 y 轴似乎是两个设备之间的相反方向.垂直于地面时 x 轴返回 10,Archos X 轴返回 0.Elocity 平板电脑是 android 2.2,Archos 是 2.1.有人可以指出我如何在这两个设备之间同步从加速度计获取方向的正确方向吗?

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天全站免登陆