Changed Perspective again

This commit is contained in:
Zak Strange
2016-03-24 15:39:50 -07:00
parent 20ff6d214e
commit 4256034f7f

View File

@@ -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);