summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAntonis Geralis <[email protected]>2022-12-17 13:13:40 +0200
committerGitHub <[email protected]>2022-12-17 12:13:40 +0100
commitd1a104bba46d2918c2a521e255edee07ea2e5f3f (patch)
tree264d1b133c0a42929c9da0cd8c44cc09ab0163e9
parentc2b56c583aa94ed6afeb501acc502534e6d36920 (diff)
downloadraylib-d1a104bba46d2918c2a521e255edee07ea2e5f3f.tar.gz
raylib-d1a104bba46d2918c2a521e255edee07ea2e5f3f.zip
Fix vector2angle (#2832)
* Fix vector2angle * Fix ; * use acosf * need a break * add comments
-rw-r--r--src/raymath.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/raymath.h b/src/raymath.h
index 34db2d88..d3130750 100644
--- a/src/raymath.h
+++ b/src/raymath.h
@@ -307,9 +307,15 @@ RMAPI float Vector2DistanceSqr(Vector2 v1, Vector2 v2)
}
// Calculate angle from two vectors
+// Parameters need to be normalized
RMAPI float Vector2Angle(Vector2 v1, Vector2 v2)
{
- float result = -acos(v1.x*v2.x + v1.y*v2.y);
+ float dotProduct = v1.x*v2.x + v1.y*v2.y; // Dot product
+
+ float t = dotProduct < -1 ? -1 : dotProduct; // Clamp
+ if (t > 1) t = 1;
+
+ float result = acosf(t);
return result;
}