Add approach_angle

This commit is contained in:
Arceveti committed 2021-09-24 18:26:36 -07:00
1 parent cb7d58fff2
commit 05db3dbae2
7 files changed
+39 -33

No files matched your search

+19
View File
@@ -587,6 +587,25 @@ f32 approach_f32(f32 current, f32 target, f32 inc, f32 dec) {
return current;
}
/**
* Similar to approach_s32, but converts to s16 and allows for overflow between 32767 and -32768
*/
s32 approach_angle(s32 current, s32 target, s32 inc) {
s32 dist = (s16)(target - current);
if (dist < 0) {
dist += inc;
if (dist > 0) {
dist = 0;
}
} else if (dist > 0) {
dist -= inc;
if (dist < 0) {
dist = 0;
}
}
return (target - dist);
}
/**
* Helper function for atan2s. Does a look up of the arctangent of y/x assuming
* the resulting angle is in range [0, 0x2000] (1/8 of a circle).
+1
View File
@@ -375,6 +375,7 @@ void vec3f_get_dist_and_angle(Vec3f from, Vec3f to, f32 *dist, s16 *pitch, s16 *
void vec3f_set_dist_and_angle(Vec3f from, Vec3f to, f32 dist, s32 pitch, s32 yaw);
s32 approach_s32(s32 current, s32 target, s32 inc, s32 dec);
f32 approach_f32(f32 current, f32 target, f32 inc, f32 dec);
s32 approach_angle(s32 current, s32 target, s32 inc);
s16 atan2s(f32 y, f32 x);
f32 atan2f(f32 a, f32 b);
void spline_get_weights(Vec4f result, f32 t, UNUSED s32 c);