diff --git a/src/corelib/math/vec.h b/src/corelib/math/vec.h index 1129da3..082c589 100644 --- a/src/corelib/math/vec.h +++ b/src/corelib/math/vec.h @@ -16,11 +16,11 @@ void clamp_magnitude(float* xx, float* yy, float max_magnitude) { } static inline -void normalize(float* xx, float* yy) { - float x = *xx, y = *yy; +void normalize(float x, float y, float* xx, float* yy) { if(x != 0 || y != 0) { const float m = sqrtf(x*x + y*y); - x /= m; y /= m; + *xx = x / m; *yy = y / m; + } else { *xx = x; *yy = y; } } @@ -40,7 +40,7 @@ int move_towards(float* out_x, float* out_y, float x, float y, float tx, float t const float m = sqrtf(diff_x*diff_x + diff_y*diff_y); const float dir_x = diff_x / m * max_delta, dir_y = diff_y / m * max_delta; - if(fabsf(dir_x) < fabsf(diff_x) && fabsf(dir_y) < fabsf(diff_y)) { + if(fabsf(dir_x) < fabsf(diff_x) || fabsf(dir_y) < fabsf(diff_y)) { *out_x = x + dir_x; *out_y = y + dir_y; return 0;