From 614e2748af964fcadc54d8c24ed7591eb4776682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=AD=E8=8F=AF=E5=A4=A7=E5=B8=9D?= Date: Sat, 3 Dec 2022 23:42:02 +0800 Subject: [PATCH] Update matrix_transform.hpp fix --- glm/gtc/matrix_transform.hpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/glm/gtc/matrix_transform.hpp b/glm/gtc/matrix_transform.hpp index 3ef6a83..56b7814 100644 --- a/glm/gtc/matrix_transform.hpp +++ b/glm/gtc/matrix_transform.hpp @@ -96,12 +96,25 @@ class matrix_transform : public constants zero, zero, -(two * zFar * zNear) / d, zero); } + static GLM_API mat<4, 4, T> frustumZO(value_type left, value_type right, value_type bottom, value_type top, value_type zNear, value_type zFar) + { + T w = right - left; + T h = top - bottom; + T d = zFar - zNear; + + return mat<4, 4, T>( + (2.0f * zNear) / w, 0.0f, 0.0f, 0.0f, + 0.0f, (2.0f * zNear) / h, 0.0f, 0.0f, + (right + left) / w, (top + bottom) / h, zFar / (zNear - zFar), -1.0f, + 0.0f, 0.0f, -(zFar * zNear) / d, 0.0f); + } + static GLM_API mat<4, 4, T> perspective(T fovY, T aspect, T zNear, T zFar) { #if 0 T h = tan(fovY * half) * zNear; T w = h * aspect; - return frustum(-w, w, -h, h, zNear, zFar); + return frustumZO(-w, w, -h, h, zNear, zFar); #else const T tanHalfFovy = tan(fovY * half); mat<4, 4, T> m(zero);