From 9e1058acf1dc22a0cfd0c760b867913d1e479076 Mon Sep 17 00:00:00 2001 From: Andrea Fontana Date: Thu, 9 Dec 2021 20:21:28 +0100 Subject: [PATCH] Unrolled everything. --- src/raymath.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/raymath.h b/src/raymath.h index 7538670af..352c29e5c 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -99,7 +99,8 @@ // Types and Structures Definition //---------------------------------------------------------------------------------- #if !defined(RL_VECTOR2_TYPE) -// Vector2 type +// +type typedef struct Vector2 { float x; float y; @@ -281,7 +282,9 @@ RMAPI float Vector2Distance(Vector2 v1, Vector2 v2) // Calculate angle from two vectors RMAPI float Vector2Angle(Vector2 v1, Vector2 v2) { - return atan2f(v2.y, v2.x) - atan2f(v1.y, v1.x); + float result = atan2f(v2.y, v2.x) - atan2f(v1.y, v1.x); + + return result; } // Scale vector (multiply by value) @@ -531,7 +534,12 @@ RMAPI float Vector3Distance(Vector3 v1, Vector3 v2) // Calculate angle between two vectors RMAPI float Vector3Angle(Vector3 v1, Vector3 v2) { - return atan2f(Vector3Length(Vector3CrossProduct(v1, v2)), Vector3DotProduct(v1, v2)); + Vector3 cross = { v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x }; + float len = sqrtf(cross.x*cross.x + cross.y*cross.y + cross.z*cross.z); + float dot = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z); + float result = atan2f(len, dot); + + return result; } // Negate provided vector (invert direction)