summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRay <[email protected]>2023-07-02 17:27:38 +0200
committerRay <[email protected]>2023-07-02 17:27:38 +0200
commit5361d498c33deeb1e1ad44aed24a53a4f9e97618 (patch)
tree3aa30c320614a07435b560cd047ad768e5bbb1be /src
parent4fc5e82e3087b5a9df21db86f6dc4588e5d629b4 (diff)
downloadraylib-5361d498c33deeb1e1ad44aed24a53a4f9e97618.tar.gz
raylib-5361d498c33deeb1e1ad44aed24a53a4f9e97618.zip
WARNING: REDESIGN: `Vector2Angle()`<-->`Vector2LineAngle()` #2887
Diffstat (limited to 'src')
-rw-r--r--src/raymath.h27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/raymath.h b/src/raymath.h
index 47728ff6..6a929cf6 100644
--- a/src/raymath.h
+++ b/src/raymath.h
@@ -314,8 +314,19 @@ RMAPI float Vector2DistanceSqr(Vector2 v1, Vector2 v2)
// NOTE: Angle is calculated from origin point (0, 0)
RMAPI float Vector2Angle(Vector2 v1, Vector2 v2)
{
- float result = atan2f(v2.y - v1.y, v2.x - v1.x);
+ float result = 0.0f;
+
+ float dot = v1.x*v2.x + v1.y*v2.y; // Dot product
+ float dotClamp = (dot < -1.0f)? -1.0f : dot; // Clamp
+ if (dotClamp > 1.0f) dotClamp = 1.0f;
+ result = acosf(dotClamp);
+
+ // Alternative implementation, more costly
+ //float v1Length = sqrtf((v1.x*v1.x) + (v1.y*v1.y));
+ //float v2Length = sqrtf((v2.x*v2.x) + (v2.y*v2.y));
+ //float result = -acosf((v1.x*v2.x + v1.y*v2.y)/(v1Length*v2Length));
+
return result;
}
@@ -325,18 +336,8 @@ RMAPI float Vector2Angle(Vector2 v1, Vector2 v2)
RMAPI float Vector2LineAngle(Vector2 start, Vector2 end)
{
float result = 0.0f;
-
- float dot = start.x*end.x + start.y*end.y; // Dot product
-
- float dotClamp = (dot < -1.0f)? -1.0f : dot; // Clamp
- if (dotClamp > 1.0f) dotClamp = 1.0f;
-
- result = acosf(dotClamp);
-
- // Alternative implementation, more costly
- //float v1Length = sqrtf((start.x*start.x) + (start.y*start.y));
- //float v2Length = sqrtf((end.x*end.x) + (end.y*end.y));
- //float result = -acosf((start.x*end.x + start.y*end.y)/(v1Length*v2Length));
+
+ result = atan2f(end.y - start.y, end.x - start.x);
return result;
}