Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Matrix4x4.CreateReflection when D is not zero #110057

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading