I have a compass, that returns degrees between 0-360 and a starting position (degrees) of the initial value of the compass, along with a threshold.
degrees = 0-360
initialDegrees = null
threshold = 20
I have this check:
if(degrees > initialDegrees+threshold || initialDegrees == null) { // this is to start the checking
foo();
initialDegrees = degrees
}
for checking if the degrees have changed positively beyond the threshold (i.e. me moving the compass to the right)
However how do i check if it has been moved in the opposite direction (changed negatively beyond the threshold, i.e. me moving the compass to the left).
if(degrees > initialDegrees-thredshold) // this is always true, and doesn't do what i want
Is there a way i can do this? Hopefully you understand what I'm trying to achieve.
Aucun commentaire:
Enregistrer un commentaire