From 00d2768bc910ca0b6749878f0d142b62d30d55c1 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 22 Jul 2017 10:35:41 +0200 Subject: [PATCH] Corrected bug on MatrixPerspective() Some other tweaks... --- src/core.c | 2 +- src/models.c | 4 ++-- src/raymath.h | 2 +- src/rlgl.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core.c b/src/core.c index 5e7cc811..028d7b14 100644 --- a/src/core.c +++ b/src/core.c @@ -885,7 +885,7 @@ void Begin3dMode(Camera camera) // Setup perspective projection float aspect = (float)screenWidth/(float)screenHeight; - double top = 0.01*tan(camera.fovy*PI/360.0); + double top = 0.01*tan(camera.fovy*0.5*DEG2RAD); double right = top*aspect; // NOTE: zNear and zFar values are important when computing depth buffer values diff --git a/src/models.c b/src/models.c index 7df9a10b..47175b2c 100644 --- a/src/models.c +++ b/src/models.c @@ -120,8 +120,8 @@ void DrawCube(Vector3 position, float width, float height, float length, Color c rlPushMatrix(); // NOTE: Be careful! Function order matters (scale -> rotate -> translate) - rlScalef(1.0f, 3.0f, 1.0f); - rlRotatef(45, 0, 1, 0); + //rlScalef(1.0f, 3.0f, 1.0f); + //rlRotatef(45, 0, 1, 0); rlTranslatef(position.x, position.y, position.z); rlBegin(RL_TRIANGLES); diff --git a/src/raymath.h b/src/raymath.h index 270441a5..93ae90ae 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -882,7 +882,7 @@ RMDEF Matrix MatrixFrustum(double left, double right, double bottom, double top, // NOTE: Angle should be provided in radians RMDEF Matrix MatrixPerspective(double fovy, double aspect, double near, double far) { - double top = near*tan(fovy); + double top = near*tan(fovy*0.5); double right = top*aspect; return MatrixFrustum(-right, right, -top, top, near, far); diff --git a/src/rlgl.c b/src/rlgl.c index 93612896..ac4ad20d 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -3585,7 +3585,7 @@ static void UpdateBuffersDefault(void) // Draw default internal buffers vertex data // NOTE: We draw in this order: lines, triangles, quads -static void DrawBuffersDefault() +static void DrawBuffersDefault(void) { Matrix matProjection = projection; Matrix matModelView = modelview; @@ -3967,9 +3967,9 @@ static void SetStereoConfig(VrDeviceInfo hmd) SetShaderValue(vrConfig.distortionShader, GetShaderLocation(vrConfig.distortionShader, "chromaAbParam"), hmd.chromaAbCorrection, 4); #endif - // Fovy is normally computed with: 2*atan2(hmd.vScreenSize, 2*hmd.eyeToScreenDistance)*RAD2DEG + // Fovy is normally computed with: 2*atan2(hmd.vScreenSize, 2*hmd.eyeToScreenDistance) // ...but with lens distortion it is increased (see Oculus SDK Documentation) - //float fovy = 2.0f*atan2(hmd.vScreenSize*0.5f*distortionScale, hmd.eyeToScreenDistance)*RAD2DEG; // Really need distortionScale? + //float fovy = 2.0f*atan2(hmd.vScreenSize*0.5f*distortionScale, hmd.eyeToScreenDistance); // Really need distortionScale? float fovy = 2.0f*(float)atan2(hmd.vScreenSize*0.5f, hmd.eyeToScreenDistance); // Compute camera projection matrices