From eb2b1eafb32e4a4ee27016ee590ff349510089a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Garramu=C3=B1o?= Date: Tue, 21 May 2024 18:18:48 -0300 Subject: [PATCH] Fixed matrix calculation. (#138) --- lib/tlCore/MatrixInline.h | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/tlCore/MatrixInline.h b/lib/tlCore/MatrixInline.h index 0efcb70be..ffa7a93a3 100644 --- a/lib/tlCore/MatrixInline.h +++ b/lib/tlCore/MatrixInline.h @@ -240,13 +240,12 @@ namespace tl inline Vector3 operator * (const Matrix4x4& a, const Vector3& v) { Vector3 out; - for (int i = 0; i < 3; ++i) - { - for (int j = 0; j < 3; ++j) - { - out[i] += a.e[i * 4 + j] * v[j]; - } - } + T x = T (v[0] * a.e[0] + v[1] * a.e[4] + v[2] * a.e[8] + a.e[12]); + T y = T (v[0] * a.e[1] + v[1] * a.e[5] + v[2] * a.e[9] + a.e[13]); + T z = T (v[0] * a.e[2] + v[1] * a.e[6] + v[2] * a.e[10] + a.e[14]); + T w = T (v[0] * a.e[3] + v[1] * a.e[7] + v[2] * a.e[11] + a.e[15]); + + out = Vector3 (x / w, y / w, z / w); return out; } @@ -254,13 +253,10 @@ namespace tl inline Vector4 operator * (const Matrix4x4& a, const Vector4& v) { Vector4 out; - for (int i = 0; i < 4; ++i) - { - for (int j = 0; j < 4; ++j) - { - out[i] += a.e[i * 4 + j] * v[j]; - } - } + out.x = T (v[0] * a.e[0] + v[1] * a.e[4] + v[2] * a.e[8] + v[3] * a.e[12]); + out.y = T (v[0] * a.e[1] + v[1] * a.e[5] + v[2] * a.e[9] + v[3] * a.e[13]); + out.z = T (v[0] * a.e[2] + v[1] * a.e[6] + v[2] * a.e[10] + v[3] * a.e[14]); + out.w = T (v[0] * a.e[3] + v[1] * a.e[7] + v[2] * a.e[11] + v[3] * a.e[15]); return out; } };