Fix vector2angle

This commit is contained in:
Antonis Geralis 2022-12-15 12:39:26 +02:00 committed by GitHub
parent c2b56c583a
commit 5d4f17da3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -307,9 +307,13 @@ 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;
float t = dotProduct < -1 ? -1 : dotProduct;
float result = acos(t > max ? max : t;);
return result;
}