From fa1045daf59f3990e3e942ede66586a80cbb45c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Sat, 26 May 2018 18:04:43 +0200 Subject: [PATCH] use right handed projection matrix from https://github.com/PacktPublishing/Vulkan-Cookbook/ --- glm/gtc/matrix_transform.inl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/glm/gtc/matrix_transform.inl b/glm/gtc/matrix_transform.inl index 12623d79..76ddbe11 100644 --- a/glm/gtc/matrix_transform.inl +++ b/glm/gtc/matrix_transform.inl @@ -322,20 +322,23 @@ namespace glm return frustumRH_NO(left, right, bottom, top, nearVal, farVal); # endif } - + //projection matrix code from Vulkan-CookBook + // Author: Pawel Lapinski + // LinkedIn: https://www.linkedin.com/in/pawel-lapinski-84522329 template GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveRH_ZO(T fovy, T aspect, T zNear, T zFar) { assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); - T const tanHalfFovy = tan(fovy / static_cast(2)); + T const f = static_cast(1) / tan(static_cast(0.5) * fovy); mat<4, 4, T, defaultp> Result(static_cast(0)); - Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); - Result[1][1] = static_cast(1) / (tanHalfFovy); + Result[0][0] = f / aspect; + Result[1][1] = -f; Result[2][2] = zFar / (zNear - zFar); Result[2][3] = - static_cast(1); - Result[3][2] = -(zFar * zNear) / (zFar - zNear); + Result[3][2] = (zNear * zFar) / (zNear - zFar); + return Result; }