Fixed tweakedInfinitePerspective #208 and added user-defined epsilon to tweakedInfinitePerspective
This commit is contained in:
@@ -164,8 +164,8 @@ namespace glm
|
||||
/// @param far
|
||||
/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
|
||||
/// @see gtc_matrix_transform
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL detail::tmat4x4<T, P> frustum(
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL detail::tmat4x4<T, defaultp> frustum(
|
||||
T const & left,
|
||||
T const & right,
|
||||
T const & bottom,
|
||||
@@ -181,8 +181,8 @@ namespace glm
|
||||
/// @param far
|
||||
/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
|
||||
/// @see gtc_matrix_transform
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL detail::tmat4x4<T, P> perspective(
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL detail::tmat4x4<T, defaultp> perspective(
|
||||
T const & fovy,
|
||||
T const & aspect,
|
||||
T const & near,
|
||||
@@ -197,8 +197,8 @@ namespace glm
|
||||
/// @param far
|
||||
/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
|
||||
/// @see gtc_matrix_transform
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL detail::tmat4x4<T, P> perspectiveFov(
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL detail::tmat4x4<T, defaultp> perspectiveFov(
|
||||
T const & fov,
|
||||
T const & width,
|
||||
T const & height,
|
||||
@@ -212,8 +212,8 @@ namespace glm
|
||||
/// @param near
|
||||
/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
|
||||
/// @see gtc_matrix_transform
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL detail::tmat4x4<T, P> infinitePerspective(
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL detail::tmat4x4<T, defaultp> infinitePerspective(
|
||||
T fovy, T aspect, T near);
|
||||
|
||||
/// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite for graphics hardware that doesn't support depth clamping.
|
||||
@@ -223,9 +223,9 @@ namespace glm
|
||||
/// @param near
|
||||
/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
|
||||
/// @see gtc_matrix_transform
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL detail::tmat4x4<T, P> tweakedInfinitePerspective(
|
||||
T fovy, T aspect, T near);
|
||||
template <typename T>
|
||||
GLM_FUNC_DECL detail::tmat4x4<T, defaultp> tweakedInfinitePerspective(
|
||||
T fovy, T aspect, T near, T epsilon = epsilon<T>());
|
||||
|
||||
/// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates.
|
||||
///
|
||||
|
||||
@@ -192,87 +192,87 @@ namespace glm
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
GLM_FUNC_QUALIFIER detail::tmat4x4<valType, defaultp> frustum
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> frustum
|
||||
(
|
||||
valType const & left,
|
||||
valType const & right,
|
||||
valType const & bottom,
|
||||
valType const & top,
|
||||
valType const & nearVal,
|
||||
valType const & farVal
|
||||
T const & left,
|
||||
T const & right,
|
||||
T const & bottom,
|
||||
T const & top,
|
||||
T const & nearVal,
|
||||
T const & farVal
|
||||
)
|
||||
{
|
||||
detail::tmat4x4<valType, defaultp> Result(0);
|
||||
Result[0][0] = (valType(2) * nearVal) / (right - left);
|
||||
Result[1][1] = (valType(2) * nearVal) / (top - bottom);
|
||||
detail::tmat4x4<T, defaultp> Result(0);
|
||||
Result[0][0] = (static_cast<T>(2) * nearVal) / (right - left);
|
||||
Result[1][1] = (static_cast<T>(2) * nearVal) / (top - bottom);
|
||||
Result[2][0] = (right + left) / (right - left);
|
||||
Result[2][1] = (top + bottom) / (top - bottom);
|
||||
Result[2][2] = -(farVal + nearVal) / (farVal - nearVal);
|
||||
Result[2][3] = valType(-1);
|
||||
Result[3][2] = -(valType(2) * farVal * nearVal) / (farVal - nearVal);
|
||||
Result[2][3] = static_cast<T>(-1);
|
||||
Result[3][2] = -(static_cast<T>(2) * farVal * nearVal) / (farVal - nearVal);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
GLM_FUNC_QUALIFIER detail::tmat4x4<valType, defaultp> perspective
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> perspective
|
||||
(
|
||||
valType const & fovy,
|
||||
valType const & aspect,
|
||||
valType const & zNear,
|
||||
valType const & zFar
|
||||
T const & fovy,
|
||||
T const & aspect,
|
||||
T const & zNear,
|
||||
T const & zFar
|
||||
)
|
||||
{
|
||||
assert(aspect != valType(0));
|
||||
assert(aspect != static_cast<T>(0));
|
||||
assert(zFar != zNear);
|
||||
|
||||
#ifdef GLM_FORCE_RADIANS
|
||||
valType const rad = fovy;
|
||||
T const rad = fovy;
|
||||
#else
|
||||
# pragma message("GLM: perspective function taking degrees as a parameter is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.")
|
||||
valType const rad = glm::radians(fovy);
|
||||
T const rad = glm::radians(fovy);
|
||||
#endif
|
||||
|
||||
valType tanHalfFovy = tan(rad / valType(2));
|
||||
T tanHalfFovy = tan(rad / static_cast<T>(2));
|
||||
|
||||
detail::tmat4x4<valType, defaultp> Result(valType(0));
|
||||
Result[0][0] = valType(1) / (aspect * tanHalfFovy);
|
||||
Result[1][1] = valType(1) / (tanHalfFovy);
|
||||
detail::tmat4x4<T, defaultp> Result(static_cast<T>(0));
|
||||
Result[0][0] = static_cast<T>(1) / (aspect * tanHalfFovy);
|
||||
Result[1][1] = static_cast<T>(1) / (tanHalfFovy);
|
||||
Result[2][2] = - (zFar + zNear) / (zFar - zNear);
|
||||
Result[2][3] = - valType(1);
|
||||
Result[3][2] = - (valType(2) * zFar * zNear) / (zFar - zNear);
|
||||
Result[2][3] = - static_cast<T>(1);
|
||||
Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
GLM_FUNC_QUALIFIER detail::tmat4x4<valType, defaultp> perspectiveFov
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> perspectiveFov
|
||||
(
|
||||
valType const & fov,
|
||||
valType const & width,
|
||||
valType const & height,
|
||||
valType const & zNear,
|
||||
valType const & zFar
|
||||
T const & fov,
|
||||
T const & width,
|
||||
T const & height,
|
||||
T const & zNear,
|
||||
T const & zFar
|
||||
)
|
||||
{
|
||||
assert(width > valType(0));
|
||||
assert(height > valType(0));
|
||||
assert(fov > valType(0));
|
||||
assert(width > static_cast<T>(0));
|
||||
assert(height > static_cast<T>(0));
|
||||
assert(fov > static_cast<T>(0));
|
||||
|
||||
#ifdef GLM_FORCE_RADIANS
|
||||
valType rad = fov;
|
||||
T rad = fov;
|
||||
#else
|
||||
# pragma message("GLM: perspectiveFov function taking degrees as a parameter is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.")
|
||||
valType rad = glm::radians(fov);
|
||||
T rad = glm::radians(fov);
|
||||
#endif
|
||||
valType h = glm::cos(valType(0.5) * rad) / glm::sin(valType(0.5) * rad);
|
||||
valType w = h * height / width; ///todo max(width , Height) / min(width , Height)?
|
||||
T h = glm::cos(static_cast<T>(0.5) * rad) / glm::sin(static_cast<T>(0.5) * rad);
|
||||
T w = h * height / width; ///todo max(width , Height) / min(width , Height)?
|
||||
|
||||
detail::tmat4x4<valType, defaultp> Result(valType(0));
|
||||
detail::tmat4x4<valType, defaultp> Result(static_cast<T>(0));
|
||||
Result[0][0] = w;
|
||||
Result[1][1] = h;
|
||||
Result[2][2] = - (zFar + zNear) / (zFar - zNear);
|
||||
Result[2][3] = - valType(1);
|
||||
Result[3][2] = - (valType(2) * zFar * zNear) / (zFar - zNear);
|
||||
Result[2][3] = - static_cast<T>(1);
|
||||
Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear);
|
||||
return Result;
|
||||
}
|
||||
|
||||
@@ -304,12 +304,14 @@ namespace glm
|
||||
return Result;
|
||||
}
|
||||
|
||||
// Infinite projection matrix: http://www.terathon.com/gdc07_lengyel.pdf
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> tweakedInfinitePerspective
|
||||
(
|
||||
T fovy,
|
||||
T aspect,
|
||||
T zNear
|
||||
T zNear,
|
||||
T epsilon
|
||||
)
|
||||
{
|
||||
#ifdef GLM_FORCE_RADIANS
|
||||
@@ -324,11 +326,11 @@ namespace glm
|
||||
T top = range;
|
||||
|
||||
detail::tmat4x4<T, defaultp> Result(T(0));
|
||||
Result[0][0] = (T(2) * zNear) / (right - left);
|
||||
Result[1][1] = (T(2) * zNear) / (top - bottom);
|
||||
Result[2][2] = static_cast<T>(0.0001) - T(1);
|
||||
Result[0][0] = (static_cast<T>(2) * zNear) / (right - left);
|
||||
Result[1][1] = (static_cast<T>(2) * zNear) / (top - bottom);
|
||||
Result[2][2] = epsilon - static_cast<T>(1);
|
||||
Result[2][3] = static_cast<T>(-1);
|
||||
Result[3][2] = - (T(0.0001) - T(2)) * zNear;
|
||||
Result[3][2] = (epsilon - static_cast<T>(2)) * zNear;
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user