direction property
JoystickDirection
get
direction
Implementation
JoystickDirection get direction {
if (delta.isZero()) {
return JoystickDirection.idle;
}
var knobAngle = delta.screenAngle();
// Since screenAngle and angleTo doesn't care about "direction" of the angle
// we have to use angleToSigned and create an only increasing angle by
// removing negative angles from 2*pi.
knobAngle = knobAngle < 0 ? 2 * pi + knobAngle : knobAngle;
if (knobAngle >= 0 && knobAngle <= _eighthOfPi) {
return JoystickDirection.up;
} else if (knobAngle > 1 * _eighthOfPi && knobAngle <= 3 * _eighthOfPi) {
return JoystickDirection.upRight;
} else if (knobAngle > 3 * _eighthOfPi && knobAngle <= 5 * _eighthOfPi) {
return JoystickDirection.right;
} else if (knobAngle > 5 * _eighthOfPi && knobAngle <= 7 * _eighthOfPi) {
return JoystickDirection.downRight;
} else if (knobAngle > 7 * _eighthOfPi && knobAngle <= 9 * _eighthOfPi) {
return JoystickDirection.down;
} else if (knobAngle > 9 * _eighthOfPi && knobAngle <= 11 * _eighthOfPi) {
return JoystickDirection.downLeft;
} else if (knobAngle > 11 * _eighthOfPi && knobAngle <= 13 * _eighthOfPi) {
return JoystickDirection.left;
} else if (knobAngle > 13 * _eighthOfPi && knobAngle <= 15 * _eighthOfPi) {
return JoystickDirection.upLeft;
} else if (knobAngle > 15 * _eighthOfPi) {
return JoystickDirection.up;
} else {
return JoystickDirection.idle;
}
}