I'm successfully detecting 0-360 degrees rotation (roll) of phone around an axis, but now I am having hard times designing an effective algorithm to detect one full turn. My working but I think not elegant and as effective algorithm as I would like is:
private boolean detectRoll;
private boolean[] checkpointsR = new boolean[4];
private boolean fullRollTurn;
public void detectingRoll() {
setDetectRoll(true);
checkpointsR[0] = true;
for (int i = 1; i < 4; i++) {
if (roll > 90 * i && roll < 90 * (i + 1)
&& checkpointsR[i - 1] == true) {
checkpointsR[i] = true;
}
}
if (areAllTrue(checkpointsR) && roll > 0 && roll < 45) {
fullRollTurn = true;
// reset rollCheckpoints
for (int i = 1; i < 4; i++) {
checkpointsR[i] = false;
}
}
}
public static boolean areAllTrue(boolean[] array) {
for (boolean b : array)
if (!b)
return false;
return true;
}
public void setDetectRoll(boolean detectRoll) {
this.detectRoll = detectRoll;
}
Any help would be really appreciated.