Skip to content Skip to sidebar Skip to footer

Android - Event After Detecting 'x' Number Of Rolls Around Local Z Axis

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

Solution 1:

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;
    }
}

Post a Comment for "Android - Event After Detecting 'x' Number Of Rolls Around Local Z Axis"