Use atan2f instead of atan and weird adjustments.

This should keep the angle values in [0, 360]
just as apparently intended before.
This commit is contained in:
Ryan Pavlik
2012-06-28 16:21:02 -05:00
parent 2db3dd3a03
commit 29e5fabeac

View File

@@ -172,12 +172,9 @@ void calc_joystick_state(struct joystick_t* js, float x, float y) {
rx = applyCalibration(x, js->min.x, js->max.x, js->center.x); rx = applyCalibration(x, js->min.x, js->max.x, js->center.x);
ry = applyCalibration(y, js->min.y, js->max.y, js->center.y); ry = applyCalibration(y, js->min.y, js->max.y, js->center.y);
/* calculate the joystick angle and magnitude */ /* calculate the joystick angle and magnitude */
ang = RAD_TO_DEGREE(atanf(ry / rx)); ang = RAD_TO_DEGREE(atan2f(ry, rx));
ang -= 90.0f;
if (rx < 0.0f)
ang -= 180.0f;
js->ang = absf(ang);
js->mag = (float) sqrt((rx * rx) + (ry * ry)); js->mag = (float) sqrt((rx * rx) + (ry * ry));
js->ang = ang + 180.0f;
} }