From 5c51962090b8a46acd4d3e66bf02c520d00d28ca Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Sun, 21 Feb 2021 16:52:17 +0200 Subject: [PATCH] Tweaked mat4 MakeRotation (-6B). --- size_history.txt | 1 + src/engine/math.h | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/size_history.txt b/size_history.txt index 786ea95..1b84471 100644 --- a/size_history.txt +++ b/size_history.txt @@ -1333,3 +1333,4 @@ 66075,tweaked clampcolor 66023,tweaked mat4 multiplication and transpose 66008,new mat3/mat4 transpose functions +66002,tweaked mat4 makerotation diff --git a/src/engine/math.h b/src/engine/math.h index 55f1447..3f235cc 100644 --- a/src/engine/math.h +++ b/src/engine/math.h @@ -769,25 +769,26 @@ NOINLINE mat4 MakeRotation(const vec3& angles) { 0.f, 0.f, 0.f, 1.f, // column 3 }; } else { - mat4 rot[3]; // yaw, pitch, roll + mat4 result = i4x4; u32 axis = 0; do { - float s = Math::sin(angles[axis]); + u32 i = axis == 2; // 0 0 1 + u32 j = (axis != 0) + 1; // 1 2 2 + + mat4 rot = i4x4; float c = Math::cos(angles[axis]); + rot[i][i] = c; + rot[j][j] = c; - u32 i = axis == 2; // 0 0 1 - u32 j = 2 - (axis == 0); // 1 2 2 + float s = Math::sin(angles[axis]); + rot[j][i] = -s; + rot[i][j] = s; - rot[axis] = i4x4; - rot[axis][i][i] = c; - rot[axis][i][j] = s; - rot[axis][j][i] = -s; - rot[axis][j][j] = c; - + result = result * rot; } while (++axis < 3); - return rot[0] * rot[1] * rot[2]; + return result; } }