From e06056e7be3173c20d8ac2191d0d06a3230e01c8 Mon Sep 17 00:00:00 2001 From: Dries Harnie Date: Sun, 23 Nov 2014 23:10:51 +0100 Subject: [PATCH] EMI: Factor out makeFrustumMatrix --- engines/grim/gfx_opengl_shaders.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/engines/grim/gfx_opengl_shaders.cpp b/engines/grim/gfx_opengl_shaders.cpp index 3cf9f9adf40..1bd21099ef6 100644 --- a/engines/grim/gfx_opengl_shaders.cpp +++ b/engines/grim/gfx_opengl_shaders.cpp @@ -191,6 +191,20 @@ Math::Matrix4 makeRotationMatrix(const Math::Angle& angle, Math::Vector3d axis) return rotate; } +Math::Matrix4 makeFrustumMatrix(double left, double right, double bottom, double top, double nclip, double fclip) { + Math::Matrix4 proj; + proj(0, 0) = (2.0f * nclip) / (right - left); + proj(1, 1) = (2.0f * nclip) / (top - bottom); + proj(2, 0) = (right + left) / (right - left); + proj(2, 1) = (top + bottom) / (top - bottom); + proj(2, 2) = -(fclip + nclip) / (fclip - nclip); + proj(2, 3) = -1.0f; + proj(3, 2) = -(2.0f * fclip * nclip) / (fclip - nclip); + proj(3, 3) = 0.0f; + + return proj; +} + GfxBase *CreateGfxOpenGL() { return new GfxOpenGLS(); } @@ -428,21 +442,9 @@ void GfxOpenGLS::setupCameraFrustum(float fov, float nclip, float fclip) { _fov = fov; _nclip = nclip; _fclip = fclip; float right = nclip * tan(fov / 2 * (LOCAL_PI / 180)); - float left = -right; float top = right * 0.75; - float bottom = -right * 0.75; - Math::Matrix4 proj; - proj(0, 0) = (2.0f * nclip) / (right - left); - proj(1, 1) = (2.0f * nclip) / (top - bottom); - proj(2, 0) = (right + left) / (right - left); - proj(2, 1) = (top + bottom) / (top - bottom); - proj(2, 2) = -(fclip + nclip) / (fclip - nclip); - proj(2, 3) = -1.0f; - proj(3, 2) = -(2.0f * fclip * nclip) / (fclip - nclip); - proj(3, 3) = 0.0f; - - _projMatrix = proj; + _projMatrix = makeFrustumMatrix(-right, right, -top, top, nclip, fclip); } void GfxOpenGLS::positionCamera(const Math::Vector3d &pos, const Math::Vector3d &interest, float roll) {