From a391bc1be61dcd1ee89542c376e2c3bc429f150c Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 6 Mar 2016 02:28:21 +0100 Subject: [PATCH] Clean up GTX_matrix_transform coding style --- glm/gtc/matrix_transform.inl | 289 ++++++++++++++++------------------- 1 file changed, 134 insertions(+), 155 deletions(-) diff --git a/glm/gtc/matrix_transform.inl b/glm/gtc/matrix_transform.inl index c79f822a..e8c13d6b 100644 --- a/glm/gtc/matrix_transform.inl +++ b/glm/gtc/matrix_transform.inl @@ -150,30 +150,24 @@ namespace glm template GLM_FUNC_QUALIFIER tmat4x4 ortho ( - T left, - T right, - T bottom, - T top, - T zNear, - T zFar + T left, T right, + T bottom, T top, + T zNear, T zFar ) { - #ifdef GLM_LEFT_HANDED +# ifdef GLM_LEFT_HANDED return orthoLH(left, right, bottom, top, zNear, zFar); - #else +# else return orthoRH(left, right, bottom, top, zNear, zFar); - #endif +# endif } template GLM_FUNC_QUALIFIER tmat4x4 orthoLH ( - T left, - T right, - T bottom, - T top, - T zNear, - T zFar + T left, T right, + T bottom, T top, + T zNear, T zFar ) { tmat4x4 Result(1); @@ -182,25 +176,23 @@ namespace glm Result[3][0] = - (right + left) / (right - left); Result[3][1] = - (top + bottom) / (top - bottom); -#ifdef GLM_DEPTH_ZERO_TO_ONE - Result[2][2] = static_cast(1) / (zFar - zNear); - Result[3][2] = - zNear / (zFar - zNear); -#else - Result[2][2] = static_cast(2) / (zFar - zNear); - Result[3][2] = - (zFar + zNear) / (zFar - zNear); -#endif +# ifdef GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = static_cast(1) / (zFar - zNear); + Result[3][2] = - zNear / (zFar - zNear); +# else + Result[2][2] = static_cast(2) / (zFar - zNear); + Result[3][2] = - (zFar + zNear) / (zFar - zNear); +# endif + return Result; } template GLM_FUNC_QUALIFIER tmat4x4 orthoRH ( - T left, - T right, - T bottom, - T top, - T zNear, - T zFar + T left, T right, + T bottom, T top, + T zNear, T zFar ) { tmat4x4 Result(1); @@ -209,61 +201,54 @@ namespace glm Result[3][0] = - (right + left) / (right - left); Result[3][1] = - (top + bottom) / (top - bottom); -#ifdef GLM_DEPTH_ZERO_TO_ONE - Result[2][2] = - static_cast(1) / (zFar - zNear); - Result[3][2] = - zNear / (zFar - zNear); -#else - Result[2][2] = - static_cast(2) / (zFar - zNear); - Result[3][2] = - (zFar + zNear) / (zFar - zNear); -#endif +# ifdef GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = - static_cast(1) / (zFar - zNear); + Result[3][2] = - zNear / (zFar - zNear); +# else + Result[2][2] = - static_cast(2) / (zFar - zNear); + Result[3][2] = - (zFar + zNear) / (zFar - zNear); +# endif + return Result; } template GLM_FUNC_QUALIFIER tmat4x4 ortho ( - T left, - T right, - T bottom, - T top + T left, T right, + T bottom, T top ) { - tmat4x4 Result(1); - Result[0][0] = static_cast(2) / (right - left); - Result[1][1] = static_cast(2) / (top - bottom); - Result[2][2] = - static_cast(1); - Result[3][0] = - (right + left) / (right - left); - Result[3][1] = - (top + bottom) / (top - bottom); - return Result; + tmat4x4 Result(1); + Result[0][0] = static_cast(2) / (right - left); + Result[1][1] = static_cast(2) / (top - bottom); + Result[2][2] = - static_cast(1); + Result[3][0] = - (right + left) / (right - left); + Result[3][1] = - (top + bottom) / (top - bottom); + return Result; } template GLM_FUNC_QUALIFIER tmat4x4 frustum ( - T left, - T right, - T bottom, - T top, - T nearVal, - T farVal + T left, T right, + T bottom, T top, + T nearVal, T farVal ) { -#ifdef GLM_LEFT_HANDED - return frustumLH(left, right, bottom, top, nearVal, farVal); -#else - return frustumRH(left, right, bottom, top, nearVal, farVal); -#endif +# ifdef GLM_LEFT_HANDED + return frustumLH(left, right, bottom, top, nearVal, farVal); +# else + return frustumRH(left, right, bottom, top, nearVal, farVal); +# endif } template GLM_FUNC_QUALIFIER tmat4x4 frustumLH ( - T left, - T right, - T bottom, - T top, - T nearVal, - T farVal + T left, T right, + T bottom, T top, + T nearVal, T farVal ) { tmat4x4 Result(0); @@ -273,25 +258,23 @@ namespace glm Result[2][1] = (top + bottom) / (top - bottom); Result[2][3] = static_cast(1); -#ifdef GLM_DEPTH_ZERO_TO_ONE - Result[2][2] = farVal / (farVal - nearVal); - Result[3][2] = -(farVal * nearVal) / (farVal - nearVal); -#else - Result[2][2] = (farVal + nearVal) / (farVal - nearVal); - Result[3][2] = - (static_cast(2) * farVal * nearVal) / (farVal - nearVal); -#endif +# ifdef GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = farVal / (farVal - nearVal); + Result[3][2] = -(farVal * nearVal) / (farVal - nearVal); +# else + Result[2][2] = (farVal + nearVal) / (farVal - nearVal); + Result[3][2] = - (static_cast(2) * farVal * nearVal) / (farVal - nearVal); +# endif + return Result; } template GLM_FUNC_QUALIFIER tmat4x4 frustumRH ( - T left, - T right, - T bottom, - T top, - T nearVal, - T farVal + T left, T right, + T bottom, T top, + T nearVal, T farVal ) { tmat4x4 Result(0); @@ -301,13 +284,14 @@ namespace glm Result[2][1] = (top + bottom) / (top - bottom); Result[2][3] = static_cast(-1); -#ifdef GLM_DEPTH_ZERO_TO_ONE - Result[2][2] = farVal / (nearVal - farVal); - Result[3][2] = -(farVal * nearVal) / (farVal - nearVal); -#else - Result[2][2] = - (farVal + nearVal) / (farVal - nearVal); - Result[3][2] = - (static_cast(2) * farVal * nearVal) / (farVal - nearVal); -#endif +# ifdef GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = farVal / (nearVal - farVal); + Result[3][2] = -(farVal * nearVal) / (farVal - nearVal); +# else + Result[2][2] = - (farVal + nearVal) / (farVal - nearVal); + Result[3][2] = - (static_cast(2) * farVal * nearVal) / (farVal - nearVal); +# endif + return Result; } @@ -320,11 +304,11 @@ namespace glm T zFar ) { - #ifdef GLM_LEFT_HANDED +# ifdef GLM_LEFT_HANDED return perspectiveLH(fovy, aspect, zNear, zFar); - #else +# else return perspectiveRH(fovy, aspect, zNear, zFar); - #endif +# endif } template @@ -332,8 +316,7 @@ namespace glm ( T fovy, T aspect, - T zNear, - T zFar + T zNear, T zFar ) { assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); @@ -345,24 +328,24 @@ namespace glm Result[1][1] = static_cast(1) / (tanHalfFovy); Result[2][3] = - static_cast(1); -#ifdef GLM_DEPTH_ZERO_TO_ONE - Result[2][2] = zFar / (zNear - zFar); - Result[3][2] = -(zFar * zNear) / (zFar - zNear); -#else - Result[2][2] = - (zFar + zNear) / (zFar - zNear); - Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); -#endif +# ifdef GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = zFar / (zNear - zFar); + Result[3][2] = -(zFar * zNear) / (zFar - zNear); +# else + Result[2][2] = - (zFar + zNear) / (zFar - zNear); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); +# endif + return Result; } template GLM_FUNC_QUALIFIER tmat4x4 perspectiveLH - ( + ( T fovy, T aspect, - T zNear, - T zFar - ) + T zNear, T zFar + ) { assert(abs(aspect - std::numeric_limits::epsilon()) > static_cast(0)); @@ -373,13 +356,14 @@ namespace glm Result[1][1] = static_cast(1) / (tanHalfFovy); Result[2][3] = static_cast(1); -#ifdef GLM_DEPTH_ZERO_TO_ONE - Result[2][2] = zFar / (zFar - zNear); - Result[3][2] = -(zFar * zNear) / (zFar - zNear); -#else - Result[2][2] = (zFar + zNear) / (zFar - zNear); - Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); -#endif +# ifdef GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = zFar / (zFar - zNear); + Result[3][2] = -(zFar * zNear) / (zFar - zNear); +# else + Result[2][2] = (zFar + zNear) / (zFar - zNear); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); +# endif + return Result; } @@ -387,27 +371,23 @@ namespace glm GLM_FUNC_QUALIFIER tmat4x4 perspectiveFov ( T fov, - T width, - T height, - T zNear, - T zFar + T width, T height, + T zNear, T zFar ) { - #ifdef GLM_LEFT_HANDED +# ifdef GLM_LEFT_HANDED return perspectiveFovLH(fov, width, height, zNear, zFar); - #else +# else return perspectiveFovRH(fov, width, height, zNear, zFar); - #endif +# endif } template GLM_FUNC_QUALIFIER tmat4x4 perspectiveFovRH ( T fov, - T width, - T height, - T zNear, - T zFar + T width, T height, + T zNear, T zFar ) { assert(width > static_cast(0)); @@ -423,13 +403,14 @@ namespace glm Result[1][1] = h; Result[2][3] = - static_cast(1); -#ifdef GLM_DEPTH_ZERO_TO_ONE - Result[2][2] = zFar / (zNear - zFar); - Result[3][2] = -(zFar * zNear) / (zFar - zNear); -#else - Result[2][2] = - (zFar + zNear) / (zFar - zNear); - Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); -#endif +# ifdef GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = zFar / (zNear - zFar); + Result[3][2] = -(zFar * zNear) / (zFar - zNear); +# else + Result[2][2] = - (zFar + zNear) / (zFar - zNear); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); +# endif + return Result; } @@ -437,10 +418,8 @@ namespace glm GLM_FUNC_QUALIFIER tmat4x4 perspectiveFovLH ( T fov, - T width, - T height, - T zNear, - T zFar + T width, T height, + T zNear, T zFar ) { assert(width > static_cast(0)); @@ -456,13 +435,13 @@ namespace glm Result[1][1] = h; Result[2][3] = static_cast(1); -#ifdef GLM_DEPTH_ZERO_TO_ONE - Result[2][2] = zFar / (zFar - zNear); - Result[3][2] = -(zFar * zNear) / (zFar - zNear); -#else - Result[2][2] = (zFar + zNear) / (zFar - zNear); - Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); -#endif +# ifdef GLM_DEPTH_ZERO_TO_ONE + Result[2][2] = zFar / (zFar - zNear); + Result[3][2] = -(zFar * zNear) / (zFar - zNear); +# else + Result[2][2] = (zFar + zNear) / (zFar - zNear); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); +# endif return Result; } @@ -475,11 +454,11 @@ namespace glm T zNear ) { -#ifdef GLM_LEFT_HANDED - return infinitePerspectiveLH(fovy, aspect, zNear); -#else - return infinitePerspectiveRH(fovy, aspect, zNear); -#endif +# ifdef GLM_LEFT_HANDED + return infinitePerspectiveLH(fovy, aspect, zNear); +# else + return infinitePerspectiveRH(fovy, aspect, zNear); +# endif } template @@ -578,12 +557,12 @@ namespace glm tmp = proj * tmp; tmp /= tmp.w; -#ifdef GLM_DEPTH_ZERO_TO_ONE - tmp.x = tmp.x * T(0.5) + T(0.5); - tmp.y = tmp.y * T(0.5) + T(0.5); -#else - tmp = tmp * T(0.5) + T(0.5); -#endif +# ifdef GLM_DEPTH_ZERO_TO_ONE + tmp.x = tmp.x * T(0.5) + T(0.5); + tmp.y = tmp.y * T(0.5) + T(0.5); +# else + tmp = tmp * T(0.5) + T(0.5); +# endif tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]); tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]); @@ -604,12 +583,12 @@ namespace glm tvec4 tmp = tvec4(win, T(1)); tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]); tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]); -#ifdef GLM_DEPTH_ZERO_TO_ONE - tmp.x = tmp.x * T(2) - T(1); - tmp.y = tmp.y * T(2) - T(1); -#else - tmp = tmp * T(2) - T(1); -#endif +# ifdef GLM_DEPTH_ZERO_TO_ONE + tmp.x = tmp.x * T(2) - T(1); + tmp.y = tmp.y * T(2) - T(1); +# else + tmp = tmp * T(2) - T(1); +# endif tvec4 obj = Inverse * tmp; obj /= obj.w; @@ -649,11 +628,11 @@ namespace glm tvec3 const & up ) { - #ifdef GLM_LEFT_HANDED +# ifdef GLM_LEFT_HANDED return lookAtLH(eye, center, up); - #else +# else return lookAtRH(eye, center, up); - #endif +# endif } template