From 28168667ea9a0addd16dfb82253c4f5dfef0e927 Mon Sep 17 00:00:00 2001
From: Tomas Jakobsson <tompsson@hotmail.com>
Date: Thu, 8 Aug 2019 17:45:11 +0200
Subject: [PATCH] Fix Transform4x4f which was broken in many, many ways, but
 just out of pure luck worked anyway

---
 es-core/src/math/Transform4x4f.cpp | 130 ++++++++++++++---------------
 1 file changed, 65 insertions(+), 65 deletions(-)

diff --git a/es-core/src/math/Transform4x4f.cpp b/es-core/src/math/Transform4x4f.cpp
index b26e5a2fc..4944c0845 100644
--- a/es-core/src/math/Transform4x4f.cpp
+++ b/es-core/src/math/Transform4x4f.cpp
@@ -8,21 +8,21 @@ const Transform4x4f Transform4x4f::operator*(const Transform4x4f& _other) const
 	return
 	{
 		{
-			tm[ 0] * om[ 0] + tm[ 1] * om[ 4] + tm[ 2] * om[ 8],
-			tm[ 0] * om[ 1] + tm[ 1] * om[ 5] + tm[ 2] * om[ 9],
-			tm[ 0] * om[ 2] + tm[ 1] * om[ 6] + tm[ 2] * om[10],
+			tm[ 0] * om[ 0] + tm[ 4] * om[ 1] + tm[ 8] * om[ 2],
+			tm[ 1] * om[ 0] + tm[ 5] * om[ 1] + tm[ 9] * om[ 2],
+			tm[ 2] * om[ 0] + tm[ 6] * om[ 1] + tm[10] * om[ 2],
 			0
 		},
 		{
-			tm[ 4] * om[ 0] + tm[ 5] * om[ 4] + tm[ 6] * om[ 8],
-			tm[ 4] * om[ 1] + tm[ 5] * om[ 5] + tm[ 6] * om[ 9],
-			tm[ 4] * om[ 2] + tm[ 5] * om[ 6] + tm[ 6] * om[10],
+			tm[ 0] * om[ 4] + tm[ 4] * om[ 5] + tm[ 8] * om[ 6],
+			tm[ 1] * om[ 4] + tm[ 5] * om[ 5] + tm[ 9] * om[ 6],
+			tm[ 2] * om[ 4] + tm[ 6] * om[ 5] + tm[10] * om[ 6],
 			0
 		},
 		{
-			tm[ 8] * om[ 0] + tm[ 9] * om[ 4] + tm[10] * om[ 8],
-			tm[ 8] * om[ 1] + tm[ 9] * om[ 5] + tm[10] * om[ 9],
-			tm[ 8] * om[ 2] + tm[ 9] * om[ 6] + tm[10] * om[10],
+			tm[ 0] * om[ 8] + tm[ 4] * om[ 9] + tm[ 8] * om[10],
+			tm[ 1] * om[ 8] + tm[ 5] * om[ 9] + tm[ 9] * om[10],
+			tm[ 2] * om[ 8] + tm[ 6] * om[ 9] + tm[10] * om[10],
 			0
 		},
 		{
@@ -91,9 +91,9 @@ Transform4x4f& Transform4x4f::invert(const Transform4x4f& _other)
 	tm[15] =  1;
 
 	float Determinant = om[ 0] * tm[ 0] +
-		                om[ 4] * tm[ 1] +
-		                om[ 8] * tm[ 2] +
-		                om[12] * tm[ 3];
+	                    om[ 4] * tm[ 1] +
+	                    om[ 8] * tm[ 2] +
+	                    om[12] * tm[ 3];
 
 	if(Determinant != 0)
 		Determinant = 1 / Determinant;
@@ -121,13 +121,13 @@ Transform4x4f& Transform4x4f::scale(const Vector3f& _scale)
 	const float* sv = (float*)&_scale;
 
 	tm[ 0] *= sv[0];
-	tm[ 1] *= sv[1];
-	tm[ 2] *= sv[2];
-	tm[ 4] *= sv[0];
+	tm[ 1] *= sv[0];
+	tm[ 2] *= sv[0];
+	tm[ 4] *= sv[1];
 	tm[ 5] *= sv[1];
-	tm[ 6] *= sv[2];
-	tm[ 8] *= sv[0];
-	tm[ 9] *= sv[1];
+	tm[ 6] *= sv[1];
+	tm[ 8] *= sv[2];
+	tm[ 9] *= sv[2];
 	tm[10] *= sv[2];
 
 	return *this;
@@ -151,23 +151,23 @@ Transform4x4f& Transform4x4f::rotate(const float _angle, const Vector3f& _axis)
 	const float  sy      = s * y;
 	const float  sz      = s * z;
 	const float  r[9]    = { tx * x + c,
-		                        tx * y - sz,
-		                        tx * z + sy,
-		                        ty * x + sz,
-		                        ty * y + c,
-		                        ty * z - sx,
-		                        tz * x - sy,
-		                        tz * y + sx,
-		                        tz * z + c };
-	const float  temp[9] = { tm[ 0] * r[0] + tm[ 1] * r[3] + tm[ 2] * r[6],
-		                        tm[ 0] * r[1] + tm[ 1] * r[4] + tm[ 2] * r[7],
-		                        tm[ 0] * r[2] + tm[ 1] * r[5] + tm[ 2] * r[8],
-		                        tm[ 4] * r[0] + tm[ 5] * r[3] + tm[ 6] * r[6],
-		                        tm[ 4] * r[1] + tm[ 5] * r[4] + tm[ 6] * r[7],
-		                        tm[ 4] * r[2] + tm[ 5] * r[5] + tm[ 6] * r[8],
-		                        tm[ 8] * r[0] + tm[ 9] * r[3] + tm[10] * r[6],
-		                        tm[ 8] * r[1] + tm[ 9] * r[4] + tm[10] * r[7],
-		                        tm[ 8] * r[2] + tm[ 9] * r[5] + tm[10] * r[8] };
+	                         tx * y - sz,
+	                         tx * z + sy,
+	                         ty * x + sz,
+	                         ty * y + c,
+	                         ty * z - sx,
+	                         tz * x - sy,
+	                         tz * y + sx,
+	                         tz * z + c };
+	const float  temp[9] = { tm[ 0] * r[0] + tm[ 4] * r[1] + tm[ 8] * r[2],
+	                         tm[ 1] * r[0] + tm[ 5] * r[1] + tm[ 9] * r[2],
+	                         tm[ 2] * r[0] + tm[ 6] * r[1] + tm[10] * r[2],
+	                         tm[ 0] * r[3] + tm[ 4] * r[4] + tm[ 8] * r[5],
+	                         tm[ 1] * r[3] + tm[ 5] * r[4] + tm[ 9] * r[5],
+	                         tm[ 2] * r[3] + tm[ 6] * r[4] + tm[ 0] * r[5],
+	                         tm[ 0] * r[6] + tm[ 4] * r[7] + tm[ 8] * r[8],
+	                         tm[ 1] * r[6] + tm[ 5] * r[7] + tm[ 9] * r[8],
+	                         tm[ 2] * r[6] + tm[ 6] * r[7] + tm[10] * r[8] };
 
 	tm[ 0] = temp[0];
 	tm[ 1] = temp[1];
@@ -188,17 +188,17 @@ Transform4x4f& Transform4x4f::rotateX(const float _angle)
 	float*      tm      = (float*)this;
 	const float s       = Math::sinf(-_angle);
 	const float c       = Math::cosf(-_angle);
-	const float temp[6] = { tm[ 1] *  c + tm[ 2] * s,
-		                    tm[ 1] * -s + tm[ 2] * c,
-		                    tm[ 5] *  c + tm[ 6] * s,
-		                    tm[ 5] * -s + tm[ 6] * c,
-		                    tm[ 9] *  c + tm[10] * s,
-		                    tm[ 9] * -s + tm[10] * c };
+	const float temp[6] = { tm[ 4] * c + tm[ 8] * -s,
+	                        tm[ 5] * c + tm[ 9] * -c,
+	                        tm[ 6] * c + tm[10] * -s,
+	                        tm[ 4] * s + tm[ 8] *  c,
+	                        tm[ 5] * s + tm[ 9] *  c,
+	                        tm[ 6] * s + tm[10] *  c };
 
-	tm[ 1] = temp[0];
-	tm[ 2] = temp[1];
-	tm[ 5] = temp[2];
-	tm[ 6] = temp[3];
+	tm[ 4] = temp[0];
+	tm[ 5] = temp[1];
+	tm[ 6] = temp[2];
+	tm[ 8] = temp[3];
 	tm[ 9] = temp[4];
 	tm[10] = temp[5];
 
@@ -211,18 +211,18 @@ Transform4x4f& Transform4x4f::rotateY(const float _angle)
 	float*      tm      = (float*)this;
 	const float s       = Math::sinf(-_angle);
 	const float c       = Math::cosf(-_angle);
-	const float temp[6] = { tm[ 0] * c + tm[ 2] * -s,
-		                    tm[ 0] * s + tm[ 2] *  c,
-		                    tm[ 4] * c + tm[ 6] * -s,
-		                    tm[ 4] * s + tm[ 6] *  c,
-		                    tm[ 8] * c + tm[10] * -s,
-		                    tm[ 8] * s + tm[10] *  c };
+	const float temp[6] = { tm[ 0] *  c + tm[ 8] * s,
+	                        tm[ 1] *  c + tm[ 9] * s,
+	                        tm[ 2] *  c + tm[10] * s,
+	                        tm[ 0] * -s + tm[ 8] * c,
+	                        tm[ 1] * -s + tm[ 9] * c,
+	                        tm[ 2] * -s + tm[10] * c };
 
 	tm[ 0] = temp[0];
-	tm[ 2] = temp[1];
-	tm[ 4] = temp[2];
-	tm[ 6] = temp[3];
-	tm[ 8] = temp[4];
+	tm[ 1] = temp[1];
+	tm[ 2] = temp[2];
+	tm[ 8] = temp[3];
+	tm[ 9] = temp[4];
 	tm[10] = temp[5];
 
 	return *this;
@@ -234,19 +234,19 @@ Transform4x4f& Transform4x4f::rotateZ(const float _angle)
 	float*      tm      = (float*)this;
 	const float s       = Math::sinf(-_angle);
 	const float c       = Math::cosf(-_angle);
-	const float temp[6] = { tm[ 0] *  c + tm[ 1] * s,
-		                    tm[ 0] * -s + tm[ 1] * c,
-		                    tm[ 4] *  c + tm[ 5] * s,
-		                    tm[ 4] * -s + tm[ 5] * c,
-		                    tm[ 8] *  c + tm[ 9] * s,
-		                    tm[ 8] * -s + tm[ 9] * c };
+	const float temp[6] = { tm[ 0] * c + tm[ 4] * -s,
+	                        tm[ 1] * c + tm[ 5] * -s,
+	                        tm[ 2] * c + tm[ 6] * -s,
+	                        tm[ 0] * s + tm[ 4] *  c,
+	                        tm[ 1] * s + tm[ 5] *  c,
+	                        tm[ 2] * s + tm[ 6] *  c };
 
 	tm[ 0] = temp[0];
 	tm[ 1] = temp[1];
-	tm[ 4] = temp[2];
-	tm[ 5] = temp[3];
-	tm[ 8] = temp[4];
-	tm[ 9] = temp[5];
+	tm[ 2] = temp[2];
+	tm[ 4] = temp[3];
+	tm[ 5] = temp[4];
+	tm[ 6] = temp[5];
 
 	return *this;