From 7e493a5481c72c833d7ba6574a8c07b16141de9d Mon Sep 17 00:00:00 2001 From: dev_dwarf Date: Tue, 24 Jan 2023 22:42:15 -0700 Subject: [PATCH] Fix LH perspective matrix Off by a sign before. --- HandmadeMath.h | 7 ++++--- test/categories/Projection.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/HandmadeMath.h b/HandmadeMath.h index 0148fb1..778bf52 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -1788,9 +1788,10 @@ static inline HMM_Mat4 HMM_Perspective_LH(float FOV, float AspectRatio, float Ne ASSERT_COVERED(HMM_Perspective_LH); HMM_Mat4 Result = HMM_Perspective_RH(FOV, AspectRatio, Near, Far); - Result.Elements[2][3] = +1.0f; - - return Result; + Result.Elements[2][2] = -Result.Elements[2][2]; + Result.Elements[2][3] = -Result.Elements[2][3]; + + return (Result); } COVERAGE(HMM_InvPerspective, 1) diff --git a/test/categories/Projection.h b/test/categories/Projection.h index 6e1f940..0682982 100644 --- a/test/categories/Projection.h +++ b/test/categories/Projection.h @@ -39,11 +39,11 @@ TEST(Projection, Perspective) } { HMM_Mat4 projection = HMM_Perspective_LH(HMM_AngleDeg(90.0f), 2.0f, 5.0f, 15.0f); - HMM_Vec3 original = HMM_V3(5.0f, 5.0f, -15.0f); + HMM_Vec3 original = HMM_V3(5.0f, 5.0f, 15.0f); HMM_Vec4 projected = HMM_MulM4V4(projection, HMM_V4V(original, 1)); EXPECT_FLOAT_EQ(projected.X, 2.5f); EXPECT_FLOAT_EQ(projected.Y, 5.0f); EXPECT_FLOAT_EQ(projected.Z, 15.0f); - EXPECT_FLOAT_EQ(projected.W, -15.0f); + EXPECT_FLOAT_EQ(projected.W, 15.0f); } }