From b9c83866ffee62c91b9d1d59c67a65201c7a6018 Mon Sep 17 00:00:00 2001 From: Kyle De'Vir Date: Wed, 8 Jun 2016 00:45:57 +1000 Subject: [PATCH] Revert "Revert "Revert "Corrected errors in Perspective function""" This reverts commit 92f5150a01631a49ccc370188cc04309ea5263c1. --- HandmadeMath.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/HandmadeMath.h b/HandmadeMath.h index f47812e..ad56bd6 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -773,13 +773,11 @@ HMM_Perspective(float FOV, float AspectRatio, float Near, float Far) { hmm_mat4 Result = HMM_Mat4d(1.0f); - float TanThetaOver2 = tanf(FOV * (HMM_PI32 / 360.0f)); - - Result.Elements[0][0] = 1.0f / TanThetaOver2; - Result.Elements[1][1] = AspectRatio / TanThetaOver2; + Result.Elements[0][0] = 1.0f / (AspectRatio * tanf(FOV / 2.0f)); + Result.Elements[1][1] = 1.0f / tanf(FOV / 2.0f); Result.Elements[2][3] = -1.0f; - Result.Elements[2][2] = (Near + Far) / (Near - Far); - Result.Elements[3][2] = (2.0f * Near * Far) / (Near - Far); + Result.Elements[2][2] = -(Far + Near) / (Far - Near); + Result.Elements[3][2] = -(2.0f * Far * Near) / (Far - Near); Result.Elements[3][3] = 0.0f; return (Result);