在设备不平的情况下使用 Android 加速计

发布于 2024-10-03 12:20:23 字数 279 浏览 7 评论 0原文

我最近一直在摩托罗拉 Droid 上使用 Android SDK 和 Adob​​e AIR for Android SDK 来玩弄 Android 加速计。我注意到加速度计工作得很好,但我想知道是否可以以某种方式进行补偿,这样我就不必在水平位置使用该设备。换句话说,我想使用加速计来控制我的视觉显示,但要对其进行初始化(或以某种方式进行修改),这样我就不必将其完全放平(必须靠在手机上没有太多乐趣)。

有谁知道如何才能将设备舒适地握在手中(例如 45 度),同时仍然利用加速度计提供向前/向后读数?这可能吗?有这方面的例子吗?

I've been playing around with the Android Accelerometer of late using the Android SDK and the Adobe AIR for Android SDK on my Motorola Droid. What I've noticed is that the accelerometer works just fine, but I was wondering if it is possible to compensate in some fashion so that I don't have to use the device in a horizontal position. In other words, I want to use the accelerometer to control my visual display, but initialize it(or modify in some way) so that I don't have to hold it perfectly flat (not much fun having to lean over the phone).

Does anyone know how I can hold the device comfortably in my hand, say 45 degrees, and still utilize the accelerometer to provide forward/backwards readings? Is this possible? Any examples of this this available?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你的往事 2024-10-10 12:20:23

为此,您需要一些简单的矩阵乘法数学。通过在启动应用程序时获取当前矩阵并将其反转,然后将所有后续矩阵与其相乘来“校准”旋转 - 这将为您提供起始位置的增量。

You'll need some simple matrix multiplication math for that. "Calibrate" the rotation by taking the current matrix when you start the app and invert it, then multiply all subsequent matrices with it - that will give you the delta to the starting position.

生生不灭 2024-10-10 12:20:23

我很久以前就编写了一个处理相对旋转的应用程序。我已经忘记了代码的作用,但从我所看到的来看,似乎 -

1)我使用 - SensorManager.getRotationMatrix(R, I,gravity.clone(), geoMagnetic.clone()) 获得初始旋转矩阵; (重力和地磁分别是加速度和地磁矩阵。不知道为什么我使用克隆,但一定有某种原因。)
2)现在在任意阶段,获取当前的旋转矩阵并将其称为R。
3)计算初始矩阵的逆,并将其称为“initialInverse”。
4)将R与initialInverse相乘(或者反过来,你必须弄清楚)。
5)使用 SensorManager.getOrientation(delta, value) 获取最终方向

很抱歉,我完全忘记了上面代码的作用。我想我记得在编写这个应用程序时在某个地方读过“欧拉变换”这个词,所以这就是它可能要做的事情。不幸的是,我无法给您完整的代码,因为我可能会在市场上发布这个应用程序。但是,如果您需要更多信息,请告诉我 - 我会查看代码并回复您。

I had written an application long long ago which dealt with relative rotations. I've forgotten what the code did, but from what I can see, it seems like -

1) I get the initial rotation matrix using - SensorManager.getRotationMatrix(R, I, gravity.clone(), geomagnetic.clone()); (gravity and geomagnetic are the respective accleration and geomagnetic matrices. Dunno why I use clones but there must be some reason.)
2) Now at any stage, get the current rotation matrix and call it R.
3)Calculate the inverse of the initial matrix and call it "initialInverse".
4)Multiply R with initialInverse (or the other way round, you'll have to figure it out).
5) Get your final orientation using SensorManager.getOrientation(delta, values)

I'm sorry but I've totally forgotten what the above code does. I think I remember reading the words Euler Transform somewhere when I wrote this app, so thats what it might be doing. Unfortunately I cannot give you the complete code since I'll probably release this app in the market. However, if you need some more information, please let me know - I'll look into the code and get back to you.

天涯离梦残月幽梦 2024-10-10 12:20:23

我正在从事一个具有类似性质的项目,其中加速度计功能不受位置限制。我的处理方法很简单,用当前读数作为默认值来初始化加速度计。换句话说,一旦您将手机放在正确的位置,您就可以按下一个按钮,按下按钮后,加速度计的当前读数(G 的测量值)将作为您的参考(零值),并在以下情况下进行更改:你高于或低于这些读数...希望这对任何人都有帮助...干杯

I am working in a project with similar nature where the accelerometer function is not restricted by the position. My way of handling it is very simple, initialize the accelerometer with the current reading as the default. In other words, you have a button that you press once you have the phone in the proper position, upon pressing the button, the current readings of the accelerometer (measures of G) will be your reference (zero values), and make changes when you go above or below those readings... Hope this helps anyone... cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文