Android的 - 检测事件后的“X”号绕局部Z轴辊局部、事件、Android、轴辊

2023-09-12 05:48:00 作者:-年少无知才是梦`

我目前挣扎在Android中使用的探测器。我工作的一个应用程序,我想它的用户后执行某些操作使他们的手机'滚'在他们手中。

I'm currently struggling with the use of detectors in Android. I'm working on an app, and I'd like it to perform certain operations after the user make their phone 'roll' in their hand.

要更precise,我希望他们能够推出自己的手机周围的局部Z轴720°(如果我没有记错的话,手机的高度),然后,有应用程序返回什么的。

To be more precise, I'd like them to roll their phone 720° around the local Z Axis (if I'm not mistaken, the 'height' of the phone) and then, have the app return something.

我真的不知道如何做到这一点。到目前为止,最好的我想出了是宣布8布尔变量占每个四分之一制成一卷,设置为true时,滚动值在一定范围内得到。是啊。我就是不顾一切。

I really don't know how to do this. So far, the best I've came up with was to declare 8 boolean variables accounting each for a quarter of a roll made, set to true when roll values gets within a certain range. Yeah. I'm that desperate.

任何帮助是AP preciated!

Any help is appreciated!

推荐答案

您可以积累在滚动角的变化,考虑到当角穿过2 * PI边界。时通知用户的总侧倾角大于4 *圆周或小于-4 *圆周率。

You could accumulate the change in roll angles, taking into account for when the angle crosses the 2*pi boundary. Notify the user when the total roll angle is above 4*pi or less than -4*pi.

void updateTotalRoll(float currentAngle) {
    if ((currentAngle < (pi/2)) && (prevAngle > (3*pi/2))) {
        totalRoll += (currentAngle+2*pi-prevAngle);
    } else if ((currentAngle > (3*pi/2)) && (prevAngle < (pi/2))) {
        totalRoll -= (prevAngle+2*pi-currentAngle);
    } else {
        totalRoll += currentAngle-prevAngle;
    }
}