From 7ab6868f19b916c55128c6c0edae42a7a89f23cd Mon Sep 17 00:00:00 2001 From: zyb3rwolfi Date: Mon, 6 Oct 2025 12:08:08 +0100 Subject: [PATCH] Completed matricies tests --- TheRepo/TheLabs/MyMatrix.cs | 62 +++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/TheRepo/TheLabs/MyMatrix.cs b/TheRepo/TheLabs/MyMatrix.cs index c2528e6..d3fca66 100644 --- a/TheRepo/TheLabs/MyMatrix.cs +++ b/TheRepo/TheLabs/MyMatrix.cs @@ -80,32 +80,82 @@ public class MyMatrix public static MyMatrix CreateScale(MyVector pScale) { - return null; + return new MyMatrix(1f * pScale.X, 0f, 0f, 0f, + 0f, 1f * pScale.Y, 0f, 0f, + 0f, 0f, 1f * pScale.Z, 0f, + 0f, 0f, 0f, 1f * pScale.W); } public static MyMatrix CreateRotationX(float pAngle) { - return null; + float cos = MathF.Cos(pAngle); + float sin = MathF.Sin(pAngle); + + return new MyMatrix(1f, 0f, 0f, 0f, + 0f, cos, sin, 0f, + 0f, -sin, cos, 0f, + 0f, 0f, 0f, 1f); } public static MyMatrix CreateRotationY(float pAngle) { - return null; + float cos = MathF.Cos(pAngle); + float sin = MathF.Sin(pAngle); + + return new MyMatrix( + cos, 0f, -sin, 0f, + 0f, 1f, 0f, 0f, + sin, 0f, cos, 0f, + 0f, 0f, 0f, 1f + ); } public static MyMatrix CreateRotationZ(float pAngle) { - return null; + float cos = MathF.Cos(pAngle); + float sin = MathF.Sin(pAngle); + + return new MyMatrix( + cos, sin, 0f, 0f, + -sin, cos, 0f, 0f, + 0, 0f, 1f, 0f, + 0f, 0f, 0f, 1f + ); } public MyVector Multiply(MyVector pVector) { - return null; + float x = GetElement(0,0) * pVector.X + GetElement(0,1) * pVector.Y + GetElement(0,2) * pVector.Z + GetElement(0,3) * pVector.W; + float y = GetElement(1,0) * pVector.X + GetElement(1,1) * pVector.Y + GetElement(1,2) * pVector.Z + GetElement(1,3) * pVector.W; + float z = GetElement(2,0) * pVector.X + GetElement(2,1) * pVector.Y + GetElement(2,2) * pVector.Z + GetElement(2,3) * pVector.W; + float w = GetElement(3,0) * pVector.X + GetElement(3,1) * pVector.Y + GetElement(3,2) * pVector.Z + GetElement(3,3) * pVector.W; + + return new MyVector(x, y, z, w); } public MyMatrix Multiply(MyMatrix pMatrix) { - return null; + MyMatrix result = new MyMatrix( + 0,0,0,0, + 0,0,0,0, + 0,0,0,0, + 0,0,0,0 + ); + + for (int row = 0; row < 4; row++) + { + for (int col = 0; col < 4; col++) + { + float sum = 0f; + for (int k = 0; k < 4; k++) + { + sum += GetElement(row, k) * pMatrix.GetElement(k, col); + } + result.SetElement(row, col, sum); + } + } + + return result; } public MyMatrix Inverse()