Skip to content

Commit

Permalink
Fix Matrix4x4.CreateReflection when D is not zero (dotnet#110057)
Browse files Browse the repository at this point in the history
* Fix Matrix4x4.CreateReflection

* Update tests

* Use AssertExtensions instead

* Update Matrix4x4Tests.cs

* Update Matrix4x4Tests.cs

* Use AssertExtensions for new test only

---------

Co-authored-by: Tanner Gooding <[email protected]>
  • Loading branch information
2 people authored and mikelle-rogers committed Dec 4, 2024
1 parent 94477eb commit bef67e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 28 additions & 1 deletion src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -819,11 +819,38 @@ public void Matrix4x4CreateReflectionTest01()
Vector3 v = point - pp;
float d = Vector3.Dot(v, plane.Normal);
Vector3 vp = point - 2.0f * d * plane.Normal;
Assert.True(MathHelper.Equal(rp, vp), "Matrix4x4.Reflection did not provide expected value.");
Assert.True(MathHelper.Equal(rp, vp), "Matrix4x4.CreateReflection did not provide expected value.");
}
}
}

[Fact]
public void Matrix4x4CreateReflectionTest02()
{
Plane plane = new Plane(0, 1, 0, 60);
Matrix4x4 actual = Matrix4x4.CreateReflection(plane);

AssertExtensions.Equal(1.0f, actual.M11, 0.0f);
AssertExtensions.Equal(0.0f, actual.M12, 0.0f);
AssertExtensions.Equal(0.0f, actual.M13, 0.0f);
AssertExtensions.Equal(0.0f, actual.M14, 0.0f);

AssertExtensions.Equal(0.0f, actual.M21, 0.0f);
AssertExtensions.Equal(-1.0f, actual.M22, 0.0f);
AssertExtensions.Equal(0.0f, actual.M23, 0.0f);
AssertExtensions.Equal(0.0f, actual.M24, 0.0f);

AssertExtensions.Equal(0.0f, actual.M31, 0.0f);
AssertExtensions.Equal(0.0f, actual.M32, 0.0f);
AssertExtensions.Equal(1.0f, actual.M33, 0.0f);
AssertExtensions.Equal(0.0f, actual.M34, 0.0f);

AssertExtensions.Equal(0.0f, actual.M41, 0.0f);
AssertExtensions.Equal(-120.0f, actual.M42, 0.0f);
AssertExtensions.Equal(0.0f, actual.M43, 0.0f);
AssertExtensions.Equal(1.0f, actual.M44, 0.0f);
}

// A test for CreateRotationZ (float)
[Fact]
public void Matrix4x4CreateRotationZTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ public static Impl CreateReflection(in Plane value)
// https://github.com/microsoft/DirectXMath/blob/master/Inc/DirectXMathMatrix.inl

Vector4 p = Plane.Normalize(value).AsVector4();
Vector4 s = p * -2.0f;
Vector4 s = p * Vector4.Create(-2.0f, -2.0f, -2.0f, 0.0f);

Impl result;

Expand Down

0 comments on commit bef67e1

Please sign in to comment.