Clean up GTX_matrix_transform coding style

This commit is contained in:
Christophe Riccio 2016-03-06 02:28:21 +01:00
parent ecfebe640f
commit a391bc1be6

View File

@ -150,30 +150,24 @@ namespace glm
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> ortho GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> ortho
( (
T left, T left, T right,
T right, T bottom, T top,
T bottom, T zNear, T zFar
T top,
T zNear,
T zFar
) )
{ {
#ifdef GLM_LEFT_HANDED # ifdef GLM_LEFT_HANDED
return orthoLH(left, right, bottom, top, zNear, zFar); return orthoLH(left, right, bottom, top, zNear, zFar);
#else # else
return orthoRH(left, right, bottom, top, zNear, zFar); return orthoRH(left, right, bottom, top, zNear, zFar);
#endif # endif
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> orthoLH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> orthoLH
( (
T left, T left, T right,
T right, T bottom, T top,
T bottom, T zNear, T zFar
T top,
T zNear,
T zFar
) )
{ {
tmat4x4<T, defaultp> Result(1); tmat4x4<T, defaultp> Result(1);
@ -182,25 +176,23 @@ namespace glm
Result[3][0] = - (right + left) / (right - left); Result[3][0] = - (right + left) / (right - left);
Result[3][1] = - (top + bottom) / (top - bottom); Result[3][1] = - (top + bottom) / (top - bottom);
#ifdef GLM_DEPTH_ZERO_TO_ONE # ifdef GLM_DEPTH_ZERO_TO_ONE
Result[2][2] = static_cast<T>(1) / (zFar - zNear); Result[2][2] = static_cast<T>(1) / (zFar - zNear);
Result[3][2] = - zNear / (zFar - zNear); Result[3][2] = - zNear / (zFar - zNear);
#else # else
Result[2][2] = static_cast<T>(2) / (zFar - zNear); Result[2][2] = static_cast<T>(2) / (zFar - zNear);
Result[3][2] = - (zFar + zNear) / (zFar - zNear); Result[3][2] = - (zFar + zNear) / (zFar - zNear);
#endif # endif
return Result; return Result;
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> orthoRH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> orthoRH
( (
T left, T left, T right,
T right, T bottom, T top,
T bottom, T zNear, T zFar
T top,
T zNear,
T zFar
) )
{ {
tmat4x4<T, defaultp> Result(1); tmat4x4<T, defaultp> Result(1);
@ -209,61 +201,54 @@ namespace glm
Result[3][0] = - (right + left) / (right - left); Result[3][0] = - (right + left) / (right - left);
Result[3][1] = - (top + bottom) / (top - bottom); Result[3][1] = - (top + bottom) / (top - bottom);
#ifdef GLM_DEPTH_ZERO_TO_ONE # ifdef GLM_DEPTH_ZERO_TO_ONE
Result[2][2] = - static_cast<T>(1) / (zFar - zNear); Result[2][2] = - static_cast<T>(1) / (zFar - zNear);
Result[3][2] = - zNear / (zFar - zNear); Result[3][2] = - zNear / (zFar - zNear);
#else # else
Result[2][2] = - static_cast<T>(2) / (zFar - zNear); Result[2][2] = - static_cast<T>(2) / (zFar - zNear);
Result[3][2] = - (zFar + zNear) / (zFar - zNear); Result[3][2] = - (zFar + zNear) / (zFar - zNear);
#endif # endif
return Result; return Result;
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> ortho GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> ortho
( (
T left, T left, T right,
T right, T bottom, T top
T bottom,
T top
) )
{ {
tmat4x4<T, defaultp> Result(1); tmat4x4<T, defaultp> Result(1);
Result[0][0] = static_cast<T>(2) / (right - left); Result[0][0] = static_cast<T>(2) / (right - left);
Result[1][1] = static_cast<T>(2) / (top - bottom); Result[1][1] = static_cast<T>(2) / (top - bottom);
Result[2][2] = - static_cast<T>(1); Result[2][2] = - static_cast<T>(1);
Result[3][0] = - (right + left) / (right - left); Result[3][0] = - (right + left) / (right - left);
Result[3][1] = - (top + bottom) / (top - bottom); Result[3][1] = - (top + bottom) / (top - bottom);
return Result; return Result;
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> frustum GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> frustum
( (
T left, T left, T right,
T right, T bottom, T top,
T bottom, T nearVal, T farVal
T top,
T nearVal,
T farVal
) )
{ {
#ifdef GLM_LEFT_HANDED # ifdef GLM_LEFT_HANDED
return frustumLH(left, right, bottom, top, nearVal, farVal); return frustumLH(left, right, bottom, top, nearVal, farVal);
#else # else
return frustumRH(left, right, bottom, top, nearVal, farVal); return frustumRH(left, right, bottom, top, nearVal, farVal);
#endif # endif
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> frustumLH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> frustumLH
( (
T left, T left, T right,
T right, T bottom, T top,
T bottom, T nearVal, T farVal
T top,
T nearVal,
T farVal
) )
{ {
tmat4x4<T, defaultp> Result(0); tmat4x4<T, defaultp> Result(0);
@ -273,25 +258,23 @@ namespace glm
Result[2][1] = (top + bottom) / (top - bottom); Result[2][1] = (top + bottom) / (top - bottom);
Result[2][3] = static_cast<T>(1); Result[2][3] = static_cast<T>(1);
#ifdef GLM_DEPTH_ZERO_TO_ONE # ifdef GLM_DEPTH_ZERO_TO_ONE
Result[2][2] = farVal / (farVal - nearVal); Result[2][2] = farVal / (farVal - nearVal);
Result[3][2] = -(farVal * nearVal) / (farVal - nearVal); Result[3][2] = -(farVal * nearVal) / (farVal - nearVal);
#else # else
Result[2][2] = (farVal + nearVal) / (farVal - nearVal); Result[2][2] = (farVal + nearVal) / (farVal - nearVal);
Result[3][2] = - (static_cast<T>(2) * farVal * nearVal) / (farVal - nearVal); Result[3][2] = - (static_cast<T>(2) * farVal * nearVal) / (farVal - nearVal);
#endif # endif
return Result; return Result;
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> frustumRH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> frustumRH
( (
T left, T left, T right,
T right, T bottom, T top,
T bottom, T nearVal, T farVal
T top,
T nearVal,
T farVal
) )
{ {
tmat4x4<T, defaultp> Result(0); tmat4x4<T, defaultp> Result(0);
@ -301,13 +284,14 @@ namespace glm
Result[2][1] = (top + bottom) / (top - bottom); Result[2][1] = (top + bottom) / (top - bottom);
Result[2][3] = static_cast<T>(-1); Result[2][3] = static_cast<T>(-1);
#ifdef GLM_DEPTH_ZERO_TO_ONE # ifdef GLM_DEPTH_ZERO_TO_ONE
Result[2][2] = farVal / (nearVal - farVal); Result[2][2] = farVal / (nearVal - farVal);
Result[3][2] = -(farVal * nearVal) / (farVal - nearVal); Result[3][2] = -(farVal * nearVal) / (farVal - nearVal);
#else # else
Result[2][2] = - (farVal + nearVal) / (farVal - nearVal); Result[2][2] = - (farVal + nearVal) / (farVal - nearVal);
Result[3][2] = - (static_cast<T>(2) * farVal * nearVal) / (farVal - nearVal); Result[3][2] = - (static_cast<T>(2) * farVal * nearVal) / (farVal - nearVal);
#endif # endif
return Result; return Result;
} }
@ -320,11 +304,11 @@ namespace glm
T zFar T zFar
) )
{ {
#ifdef GLM_LEFT_HANDED # ifdef GLM_LEFT_HANDED
return perspectiveLH(fovy, aspect, zNear, zFar); return perspectiveLH(fovy, aspect, zNear, zFar);
#else # else
return perspectiveRH(fovy, aspect, zNear, zFar); return perspectiveRH(fovy, aspect, zNear, zFar);
#endif # endif
} }
template <typename T> template <typename T>
@ -332,8 +316,7 @@ namespace glm
( (
T fovy, T fovy,
T aspect, T aspect,
T zNear, T zNear, T zFar
T zFar
) )
{ {
assert(abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0)); assert(abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0));
@ -345,24 +328,24 @@ namespace glm
Result[1][1] = static_cast<T>(1) / (tanHalfFovy); Result[1][1] = static_cast<T>(1) / (tanHalfFovy);
Result[2][3] = - static_cast<T>(1); Result[2][3] = - static_cast<T>(1);
#ifdef GLM_DEPTH_ZERO_TO_ONE # ifdef GLM_DEPTH_ZERO_TO_ONE
Result[2][2] = zFar / (zNear - zFar); Result[2][2] = zFar / (zNear - zFar);
Result[3][2] = -(zFar * zNear) / (zFar - zNear); Result[3][2] = -(zFar * zNear) / (zFar - zNear);
#else # else
Result[2][2] = - (zFar + zNear) / (zFar - zNear); Result[2][2] = - (zFar + zNear) / (zFar - zNear);
Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear); Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear);
#endif # endif
return Result; return Result;
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveLH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveLH
( (
T fovy, T fovy,
T aspect, T aspect,
T zNear, T zNear, T zFar
T zFar )
)
{ {
assert(abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0)); assert(abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0));
@ -373,13 +356,14 @@ namespace glm
Result[1][1] = static_cast<T>(1) / (tanHalfFovy); Result[1][1] = static_cast<T>(1) / (tanHalfFovy);
Result[2][3] = static_cast<T>(1); Result[2][3] = static_cast<T>(1);
#ifdef GLM_DEPTH_ZERO_TO_ONE # ifdef GLM_DEPTH_ZERO_TO_ONE
Result[2][2] = zFar / (zFar - zNear); Result[2][2] = zFar / (zFar - zNear);
Result[3][2] = -(zFar * zNear) / (zFar - zNear); Result[3][2] = -(zFar * zNear) / (zFar - zNear);
#else # else
Result[2][2] = (zFar + zNear) / (zFar - zNear); Result[2][2] = (zFar + zNear) / (zFar - zNear);
Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear); Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear);
#endif # endif
return Result; return Result;
} }
@ -387,27 +371,23 @@ namespace glm
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveFov GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveFov
( (
T fov, T fov,
T width, T width, T height,
T height, T zNear, T zFar
T zNear,
T zFar
) )
{ {
#ifdef GLM_LEFT_HANDED # ifdef GLM_LEFT_HANDED
return perspectiveFovLH(fov, width, height, zNear, zFar); return perspectiveFovLH(fov, width, height, zNear, zFar);
#else # else
return perspectiveFovRH(fov, width, height, zNear, zFar); return perspectiveFovRH(fov, width, height, zNear, zFar);
#endif # endif
} }
template <typename T> template <typename T>
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveFovRH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveFovRH
( (
T fov, T fov,
T width, T width, T height,
T height, T zNear, T zFar
T zNear,
T zFar
) )
{ {
assert(width > static_cast<T>(0)); assert(width > static_cast<T>(0));
@ -423,13 +403,14 @@ namespace glm
Result[1][1] = h; Result[1][1] = h;
Result[2][3] = - static_cast<T>(1); Result[2][3] = - static_cast<T>(1);
#ifdef GLM_DEPTH_ZERO_TO_ONE # ifdef GLM_DEPTH_ZERO_TO_ONE
Result[2][2] = zFar / (zNear - zFar); Result[2][2] = zFar / (zNear - zFar);
Result[3][2] = -(zFar * zNear) / (zFar - zNear); Result[3][2] = -(zFar * zNear) / (zFar - zNear);
#else # else
Result[2][2] = - (zFar + zNear) / (zFar - zNear); Result[2][2] = - (zFar + zNear) / (zFar - zNear);
Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear); Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear);
#endif # endif
return Result; return Result;
} }
@ -437,10 +418,8 @@ namespace glm
GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveFovLH GLM_FUNC_QUALIFIER tmat4x4<T, defaultp> perspectiveFovLH
( (
T fov, T fov,
T width, T width, T height,
T height, T zNear, T zFar
T zNear,
T zFar
) )
{ {
assert(width > static_cast<T>(0)); assert(width > static_cast<T>(0));
@ -456,13 +435,13 @@ namespace glm
Result[1][1] = h; Result[1][1] = h;
Result[2][3] = static_cast<T>(1); Result[2][3] = static_cast<T>(1);
#ifdef GLM_DEPTH_ZERO_TO_ONE # ifdef GLM_DEPTH_ZERO_TO_ONE
Result[2][2] = zFar / (zFar - zNear); Result[2][2] = zFar / (zFar - zNear);
Result[3][2] = -(zFar * zNear) / (zFar - zNear); Result[3][2] = -(zFar * zNear) / (zFar - zNear);
#else # else
Result[2][2] = (zFar + zNear) / (zFar - zNear); Result[2][2] = (zFar + zNear) / (zFar - zNear);
Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear); Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear);
#endif # endif
return Result; return Result;
} }
@ -475,11 +454,11 @@ namespace glm
T zNear T zNear
) )
{ {
#ifdef GLM_LEFT_HANDED # ifdef GLM_LEFT_HANDED
return infinitePerspectiveLH(fovy, aspect, zNear); return infinitePerspectiveLH(fovy, aspect, zNear);
#else # else
return infinitePerspectiveRH(fovy, aspect, zNear); return infinitePerspectiveRH(fovy, aspect, zNear);
#endif # endif
} }
template <typename T> template <typename T>
@ -578,12 +557,12 @@ namespace glm
tmp = proj * tmp; tmp = proj * tmp;
tmp /= tmp.w; tmp /= tmp.w;
#ifdef GLM_DEPTH_ZERO_TO_ONE # ifdef GLM_DEPTH_ZERO_TO_ONE
tmp.x = tmp.x * T(0.5) + T(0.5); tmp.x = tmp.x * T(0.5) + T(0.5);
tmp.y = tmp.y * T(0.5) + T(0.5); tmp.y = tmp.y * T(0.5) + T(0.5);
#else # else
tmp = tmp * T(0.5) + T(0.5); tmp = tmp * T(0.5) + T(0.5);
#endif # endif
tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]); tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]);
tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]); tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]);
@ -604,12 +583,12 @@ namespace glm
tvec4<T, P> tmp = tvec4<T, P>(win, T(1)); tvec4<T, P> tmp = tvec4<T, P>(win, T(1));
tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]); tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]);
tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]); tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]);
#ifdef GLM_DEPTH_ZERO_TO_ONE # ifdef GLM_DEPTH_ZERO_TO_ONE
tmp.x = tmp.x * T(2) - T(1); tmp.x = tmp.x * T(2) - T(1);
tmp.y = tmp.y * T(2) - T(1); tmp.y = tmp.y * T(2) - T(1);
#else # else
tmp = tmp * T(2) - T(1); tmp = tmp * T(2) - T(1);
#endif # endif
tvec4<T, P> obj = Inverse * tmp; tvec4<T, P> obj = Inverse * tmp;
obj /= obj.w; obj /= obj.w;
@ -649,11 +628,11 @@ namespace glm
tvec3<T, P> const & up tvec3<T, P> const & up
) )
{ {
#ifdef GLM_LEFT_HANDED # ifdef GLM_LEFT_HANDED
return lookAtLH(eye, center, up); return lookAtLH(eye, center, up);
#else # else
return lookAtRH(eye, center, up); return lookAtRH(eye, center, up);
#endif # endif
} }
template <typename T, precision P> template <typename T, precision P>