26.11.2013, 16:09
(
Последний раз редактировалось Dragonsaurus; 28.11.2013 в 12:27.
)
I thought about this before I made the function. It won't return more than 90 degrees. Driving backwards would return 180 degrees normally, but further testing shows that this piece of code ain't going to do that mistake.
Edit:
Edit: Made little adjustments.
Edit:
pawn Код:
a[0] = (a[0] >= 360.0) ? (floatsub(a[0], 360.0)) : (a[0] < 0.0) ? (floatadd(a[0], 360.0)) : (a[0]); // Adjusts the angle between 0 and 360 degrees.
a[0] = (a[0] > 180.0) ? (floatsub(0.0, floatsub(360.0, a[0]))) : (a[0]); // Adjusts between -180 and 180 degrees.
a[1] = floatsub(atan2(v[1], v[0]), 90.0); // Gets the heading angle from the speed.
a[1] = (a[1] >= 360.0) ? (floatsub(a[1], 360.0)) : (a[1] < 0.0) ? (floatadd(a[1], 360.0)) : (a[1]); // Same things with heading angle.
a[1] = (a[1] > 180.0) ? (floatsub(0.0, floatsub(360.0, a[1]))) : (a[1]); // Again.
a[2] = floatabs(floatsub(a[0], a[1])); // Gets the difference between the angles.
a[2] = (a[2] > 180.0) ? (floatsub(a[2], 180.0)) : (a[2]); // Sets the value between 0 and 180 degrees.
return (a[2] >= 90.0) ? (floatsub(180.0, a[2])) : (a[2]); // Adjusts the value between 0 and 90 degrees.
// Returns pure drift.