From 84aff31973667e6bec29915d60971f9a5bb02a44 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 21 Jul 2017 10:42:41 +0200 Subject: [PATCH] MatrixPerspective() angle required in radians Consistent with similar functions in raymath --- src/core.c | 4 ++-- src/raymath.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core.c b/src/core.c index 5cdd8e6b9..fc653195f 100644 --- a/src/core.c +++ b/src/core.c @@ -980,7 +980,7 @@ Ray GetMouseRay(Vector2 mousePosition, Camera camera) TraceLog(LOG_DEBUG, "Device coordinates: (%f, %f, %f)", deviceCoords.x, deviceCoords.y, deviceCoords.z); // Calculate projection matrix (from perspective instead of frustum) - Matrix matProj = MatrixPerspective(camera.fovy, ((double)GetScreenWidth()/(double)GetScreenHeight()), 0.01, 1000.0); + Matrix matProj = MatrixPerspective(camera.fovy*DEG2RAD, ((double)GetScreenWidth()/(double)GetScreenHeight()), 0.01, 1000.0); // Calculate view matrix from camera look at Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); @@ -1033,7 +1033,7 @@ Ray GetMouseRay(Vector2 mousePosition, Camera camera) Vector2 GetWorldToScreen(Vector3 position, Camera camera) { // Calculate projection matrix (from perspective instead of frustum - Matrix matProj = MatrixPerspective(camera.fovy, (double)GetScreenWidth()/(double)GetScreenHeight(), 0.01, 1000.0); + Matrix matProj = MatrixPerspective(camera.fovy*DEG2RAD, (double)GetScreenWidth()/(double)GetScreenHeight(), 0.01, 1000.0); // Calculate view matrix from camera look at (and transpose it) Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); diff --git a/src/raymath.h b/src/raymath.h index c4db0f3f4..70d1bedd9 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -873,9 +873,10 @@ RMDEF Matrix MatrixFrustum(double left, double right, double bottom, double top, } // Returns perspective projection matrix +// NOTE: Angle should be provided in radians RMDEF Matrix MatrixPerspective(double fovy, double aspect, double near, double far) { - double top = near*tan(fovy*PI/360.0); + double top = near*tan(fovy); double right = top*aspect; return MatrixFrustum(-right, right, -top, top, near, far);