From 4256034f7f96f2fe3357590f070257299e7dd731 Mon Sep 17 00:00:00 2001 From: Zak Strange Date: Thu, 24 Mar 2016 15:39:50 -0700 Subject: [PATCH] Changed Perspective again --- HandmadeMath.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/HandmadeMath.h b/HandmadeMath.h index 9de3261..370be31 100644 --- a/HandmadeMath.h +++ b/HandmadeMath.h @@ -711,18 +711,13 @@ Orthographic(float Left, float Right, float Bottom, float Top, float Near, float HMMDEF mat4 Perspective(float FOV, float AspectRatio, float Near, float Far) { - double Radians = FOV / 2 * HMM_PI / 180; - double Sine = sin(Radians); - double Cotangent = cos(Radians) / Sine; - - double DeltaZ = Far - Near; - mat4 Result = Mat4d(1.0f); - Result.Elements[0][0] = (float)Cotangent / AspectRatio; - Result.Elements[1][1] = (float)Cotangent; - Result.Elements[2][2] = (float)(-(Far + Near) / DeltaZ); - Result.Elements[2][3] = (float)-1; - Result.Elements[3][2] = (float)(-2 * Near * Far / DeltaZ); + + Result.Elements[0][0] = 1.0f / (AspectRatio * tan(FOV / 2.0f)); + Result.Elements[1][1] = 1.0f / tan(FOV / 2.0f); + 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[3][3] = 0; return(Result);