我成功地检测到手机绕轴旋转 0-360 度(滚动),但现在我很难设计一种有效的算法来检测一整圈。我的工作,但我认为不像我想要的那样优雅和有效的算法是:
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;
}
任何帮助将非常感激。