summaryrefslogtreecommitdiffhomepage
path: root/src/raymath.h
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-05-01 18:04:47 +0200
committerraysan5 <[email protected]>2020-05-01 18:04:47 +0200
commitaf744b07c31444930dca75b432a650b5519c38a2 (patch)
tree53dc17cd5a3fdf8d7c9dadcb22d75b7cc352e971 /src/raymath.h
parent4583987fb937bd3f1ff1409d10e015fa460a37d9 (diff)
downloadraylib-af744b07c31444930dca75b432a650b5519c38a2.tar.gz
raylib-af744b07c31444930dca75b432a650b5519c38a2.zip
Review latest PR formatting
Diffstat (limited to 'src/raymath.h')
-rw-r--r--src/raymath.h19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/raymath.h b/src/raymath.h
index acf97fb9..e021b932 100644
--- a/src/raymath.h
+++ b/src/raymath.h
@@ -283,15 +283,22 @@ RMDEF Vector2 Vector2Rotate(Vector2 v, float degs)
return result;
}
-// Move towards Target.
-RMDEF Vector2 Vector2MoveTowards( Vector2 v, Vector2 target, float maxDistance)
+// Move Vector towards target
+RMDEF Vector2 Vector2MoveTowards(Vector2 v, Vector2 target, float maxDistance)
{
+ Vector2 result = { 0 }
float dx = target.x - v.x;
float dy = target.y - v.y;
- float value = ( dx * dx ) + ( dy * dy );
- if ( value == 0 || ( maxDistance >= 0 && value <= maxDistance * maxDistance )) return target;
- float result = sqrtf( value );
- return (Vector2){ v.x + dx / result * maxDistance, v.y + dy / result * maxDistance };
+ float value = (dx*dx) + (dy*dy);
+
+ if ((value == 0) || ((maxDistance >= 0) && (value <= maxDistance*maxDistance))) result = target;
+
+ float dist = sqrtf(value);
+
+ result.x = v.x + dx/dist*maxDistance;
+ result.y = v.y + dy/dist*maxDistance;
+
+ return result;
}
//----------------------------------------------------------------------------------