From a201b8092e2d1cafc13aab9d168f28fd6fb56fc4 Mon Sep 17 00:00:00 2001 From: "SND\\rene87_cp" Date: Thu, 17 Nov 2011 14:34:49 +0000 Subject: [PATCH] fix Matrix.Divide(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) fix MathHelpers.WrapAngle(float angle) add MatrixTest.Invert() Modified GamePaddPadTest --- .../Input/GamePadDPadTest.cs | 26 +++++++----------- .../Strukturen/MatrixTest.cs | 10 +++++++ ANX.Framework/MathHelper.cs | 18 ++++++------- ANX.Framework/Matrix.cs | 27 ++++++++++++++----- 4 files changed, 49 insertions(+), 32 deletions(-) diff --git a/ANX.Framework.TestCenter/Input/GamePadDPadTest.cs b/ANX.Framework.TestCenter/Input/GamePadDPadTest.cs index dc9fe628..36b00ffb 100644 --- a/ANX.Framework.TestCenter/Input/GamePadDPadTest.cs +++ b/ANX.Framework.TestCenter/Input/GamePadDPadTest.cs @@ -152,14 +152,11 @@ namespace ANX.Framework.TestCenter.Input ANXGamePadDPad anx = new ANXGamePadDPad(upValue, downValue, leftValue, rightValue); ANXGamePadDPad anx2 = new ANXGamePadDPad(upValue, downValue, leftValue, rightValue); - if (anx.Equals(anx2)) - { - Assert.Pass("Pass Equal"); - } - else - { - Assert.Fail("Fail Equal"); - } + XNAGamePadDPad xna = new XNAGamePadDPad(upValue2, downValue2, leftValue2, rightValue2); + XNAGamePadDPad xna2 = new XNAGamePadDPad(upValue2, downValue2, leftValue2, rightValue2); + + AssertHelper.ConvertEquals(xna.Equals(xna2), anx.Equals(anx2),"Equal"); + } [Test] public void Equal2() @@ -182,14 +179,11 @@ namespace ANX.Framework.TestCenter.Input ANXGamePadDPad anx = new ANXGamePadDPad(upValue, downValue, leftValue, rightValue); ANXGamePadDPad anx2 = new ANXGamePadDPad(upValue, downValue, leftValue, rightValue); - if (!(anx != anx2)) - { - Assert.Pass("Pass !="); - } - else - { - Assert.Fail("Fail !="); - } + XNAGamePadDPad xna = new XNAGamePadDPad(upValue2, downValue2, leftValue2, rightValue2); + XNAGamePadDPad xna2 = new XNAGamePadDPad(upValue2, downValue2, leftValue2, rightValue2); + + AssertHelper.ConvertEquals(xna != xna2, anx != anx2, "OperatorNoEqual"); + } } } diff --git a/ANX.Framework.TestCenter/Strukturen/MatrixTest.cs b/ANX.Framework.TestCenter/Strukturen/MatrixTest.cs index d7205f1d..5620ce70 100644 --- a/ANX.Framework.TestCenter/Strukturen/MatrixTest.cs +++ b/ANX.Framework.TestCenter/Strukturen/MatrixTest.cs @@ -207,7 +207,17 @@ namespace ANX.Framework.TestCenter.Strukturen AssertHelper.ConvertEquals(xnaM1 / xnaM2, anxM1 / anxM2, "DivideOperator"); } + [Test, TestCaseSource("sixteenfloats")] + public void Invert(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) + { + XNAMatrix xnaM1 = new XNAMatrix(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44); + XNAMatrix xnaM2 = new XNAMatrix(); + ANXMatrix anxM1 = new ANXMatrix(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44); + ANXMatrix anxM2 = new ANXMatrix(); + + AssertHelper.ConvertEquals(xnaM2, anxM2, "DivideOperator"); + } [Test, TestCaseSource("sixteenfloats")] public void CreateRotationX(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) { diff --git a/ANX.Framework/MathHelper.cs b/ANX.Framework/MathHelper.cs index b33928be..0c188a61 100644 --- a/ANX.Framework/MathHelper.cs +++ b/ANX.Framework/MathHelper.cs @@ -177,15 +177,15 @@ namespace ANX.Framework public static float WrapAngle(float angle) { angle = (float)Math.IEEERemainder((double)angle, 6.2831854820251465); //2xPi precission is double - if (angle <= -3.141593f) - { - angle += 6.283185f; - return angle; - } - if (angle > 3.141593f) - { - angle -= 6.283185f; - } + //if (angle <= -3.141593f) + //{ + // angle += 6.283185f; + // return angle; + //} + //if (angle > 3.141593f) + //{ + // angle -= 6.283185f; + //} return angle; } diff --git a/ANX.Framework/Matrix.cs b/ANX.Framework/Matrix.cs index b2ff4a2b..c84159ec 100644 --- a/ANX.Framework/Matrix.cs +++ b/ANX.Framework/Matrix.cs @@ -282,9 +282,25 @@ namespace ANX.Framework public static void Divide(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) { - Matrix invMatrix2; - Invert(ref matrix2, out invMatrix2); - Multiply(ref matrix1, ref invMatrix2, out result); + result.M11 = matrix1.M11 / matrix2.M11; + result.M21 = matrix1.M21 / matrix2.M21; + result.M31 = matrix1.M31 / matrix2.M31; + result.M41 = matrix1.M41 / matrix2.M41; + + result.M12 = matrix1.M12 / matrix2.M12; + result.M22 = matrix1.M22 / matrix2.M22; + result.M32 = matrix1.M32 / matrix2.M32; + result.M42 = matrix1.M42 / matrix2.M42; + + result.M13 = matrix1.M13 / matrix2.M13; + result.M23 = matrix1.M23 / matrix2.M23; + result.M33 = matrix1.M33 / matrix2.M33; + result.M43 = matrix1.M43 / matrix2.M43; + + result.M14 = matrix1.M14 / matrix2.M14; + result.M24 = matrix1.M24 / matrix2.M24; + result.M34 = matrix1.M34 / matrix2.M34; + result.M44 = matrix1.M44 / matrix2.M44; } public static Matrix Divide(Matrix matrix1, float divider) @@ -366,10 +382,7 @@ namespace ANX.Framework return result; } - public static void Lerp(ref Matrix matrix1, - ref Matrix matrix2, - float amount, - out Matrix result) + public static void Lerp(ref Matrix matrix1, ref Matrix matrix2, float amount,out Matrix result) { throw new NotImplementedException(); }