From 136b049106f4bce180d952ea3faec2e0fe827a6b Mon Sep 17 00:00:00 2001 From: Kyle De'Vir Date: Sat, 28 May 2016 23:54:08 +1000 Subject: [PATCH] Corrected errors in Perspective function --- HandmadeMath.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/HandmadeMath.h b/HandmadeMath.h index b25fab6..97899d0 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -729,11 +729,13 @@ HMM_Perspective(float FOV, float AspectRatio, float Near, float Far) { hmm_mat4 Result = HMM_Mat4d(1.0f); - Result.Elements[0][0] = 1.0f / (AspectRatio * tanf(FOV / 2.0f)); - Result.Elements[1][1] = 1.0f / tanf(FOV / 2.0f); + float TanThetaOver2 = tanf(FOV * (HMM_PI32 / 360.0f)); + + Result.Elements[0][0] = 1.0f / TanThetaOver2; + Result.Elements[1][1] = AspectRatio / TanThetaOver2; Result.Elements[2][3] = -1.0f; - Result.Elements[2][2] = -(Far + Near) / (Far - Near); - Result.Elements[3][2] = -(2.0f * Far * Near) / (Far - Near); + Result.Elements[2][2] = (Near + Far) / (Near - Far); + Result.Elements[3][2] = (2.0f * Near * Far) / (Near - Far); Result.Elements[3][3] = 0.0f; return (Result);