Skip to content

Commit b46f7c7

Browse files
[release/9.0-staging] Fix Matrix4x4.CreateReflection when D is not zero (#110162)
* Fix Matrix4x4.CreateReflection * Update tests * Use AssertExtensions instead * Update Matrix4x4Tests.cs * Update Matrix4x4Tests.cs * Use AssertExtensions for new test only --------- Co-authored-by: Steve <[email protected]>
1 parent 6124867 commit b46f7c7

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,11 +819,38 @@ public void Matrix4x4CreateReflectionTest01()
819819
Vector3 v = point - pp;
820820
float d = Vector3.Dot(v, plane.Normal);
821821
Vector3 vp = point - 2.0f * d * plane.Normal;
822-
Assert.True(MathHelper.Equal(rp, vp), "Matrix4x4.Reflection did not provide expected value.");
822+
Assert.True(MathHelper.Equal(rp, vp), "Matrix4x4.CreateReflection did not provide expected value.");
823823
}
824824
}
825825
}
826826

827+
[Fact]
828+
public void Matrix4x4CreateReflectionTest02()
829+
{
830+
Plane plane = new Plane(0, 1, 0, 60);
831+
Matrix4x4 actual = Matrix4x4.CreateReflection(plane);
832+
833+
AssertExtensions.Equal(1.0f, actual.M11, 0.0f);
834+
AssertExtensions.Equal(0.0f, actual.M12, 0.0f);
835+
AssertExtensions.Equal(0.0f, actual.M13, 0.0f);
836+
AssertExtensions.Equal(0.0f, actual.M14, 0.0f);
837+
838+
AssertExtensions.Equal(0.0f, actual.M21, 0.0f);
839+
AssertExtensions.Equal(-1.0f, actual.M22, 0.0f);
840+
AssertExtensions.Equal(0.0f, actual.M23, 0.0f);
841+
AssertExtensions.Equal(0.0f, actual.M24, 0.0f);
842+
843+
AssertExtensions.Equal(0.0f, actual.M31, 0.0f);
844+
AssertExtensions.Equal(0.0f, actual.M32, 0.0f);
845+
AssertExtensions.Equal(1.0f, actual.M33, 0.0f);
846+
AssertExtensions.Equal(0.0f, actual.M34, 0.0f);
847+
848+
AssertExtensions.Equal(0.0f, actual.M41, 0.0f);
849+
AssertExtensions.Equal(-120.0f, actual.M42, 0.0f);
850+
AssertExtensions.Equal(0.0f, actual.M43, 0.0f);
851+
AssertExtensions.Equal(1.0f, actual.M44, 0.0f);
852+
}
853+
827854
// A test for CreateRotationZ (float)
828855
[Fact]
829856
public void Matrix4x4CreateRotationZTest()

src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.Impl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ public static Impl CreateReflection(in Plane value)
620620
// https://github.com/microsoft/DirectXMath/blob/master/Inc/DirectXMathMatrix.inl
621621

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

625625
Impl result;
626626

0 commit comments

Comments
 (0)