From 5325d8d2bab019dece92115939932ce4440cdf19 Mon Sep 17 00:00:00 2001 From: Dan Bechard Date: Tue, 23 Mar 2021 03:32:25 -0700 Subject: [PATCH] Don't call sqrtf when axis already normalized (#1672) --- src/raymath.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/raymath.h b/src/raymath.h index b9ced952..7fc1df6c 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -856,14 +856,14 @@ RMDEF Matrix MatrixRotate(Vector3 axis, float angle) float x = axis.x, y = axis.y, z = axis.z; - float length = sqrtf(x*x + y*y + z*z); + float lengthSquared = x*x + y*y + z*z; - if ((length != 1.0f) && (length != 0.0f)) + if ((lengthSquared != 1.0f) && (lengthSquared != 0.0f)) { - length = 1.0f/length; - x *= length; - y *= length; - z *= length; + float inverseLength = 1.0f/sqrtf(lengthSquared); + x *= inverseLength; + y *= inverseLength; + z *= inverseLength; } float sinres = sinf(angle);