From 58e9a0894f65a50004e637f7db72bd12da809cd9 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Thu, 29 Jul 2021 21:50:50 +0200 Subject: [PATCH] Reviewed some functions to avoid calling other functions --- src/raymath.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/raymath.h b/src/raymath.h index 3b65e382..ffdd2c27 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -1,6 +1,6 @@ /********************************************************************************************** * -* raymath v1.2 - Math functions to work with Vector3, Matrix and Quaternions +* raymath v1.3 - Math functions to work with Vector3, Matrix and Quaternions * * CONFIGURATION: * @@ -488,14 +488,14 @@ RMDEF Vector3 Vector3Normalize(Vector3 v) { Vector3 result = v; - float length, ilength; - length = Vector3Length(v); + float length, inverseLength; + length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z); if (length == 0.0f) length = 1.0f; - ilength = 1.0f/length; + inverseLength = 1.0f/length; - result.x *= ilength; - result.y *= ilength; - result.z *= ilength; + result.x *= inverseLength; + result.y *= inverseLength; + result.z *= inverseLength; return result; } @@ -1429,8 +1429,9 @@ RMDEF Matrix QuaternionToMatrix(Quaternion q) RMDEF Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle) { Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f }; - - if (Vector3Length(axis) != 0.0f) + float axisLength = sqrtf(axis.x*axis.x + axis.y*axis.y + axis.z*axis.z); + + if (axisLength != 0.0f) { angle *= 0.5f;