@ -192,87 +192,87 @@ namespace glm
return Result;
return Result;
}
}
template <typename val Type >
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<val Type , defaultp> frustum
GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> frustum
(
(
val Type const & left,
T const & left,
val Type const & right,
T const & right,
val Type const & bottom,
T const & bottom,
val Type const & top,
T const & top,
val Type const & nearVal,
T const & nearVal,
val Type const & farVal
T const & farVal
)
)
{
{
detail::tmat4x4<val Type , defaultp> Result(0);
detail::tmat4x4<T, defaultp> Result(0);
Result[0][0] = (valType (2) * nearVal) / (right - left);
Result[0][0] = (static_cast<T> (2) * nearVal) / (right - left);
Result[1][1] = (valType (2) * nearVal) / (top - bottom);
Result[1][1] = (static_cast<T> (2) * nearVal) / (top - bottom);
Result[2][0] = (right + left) / (right - left);
Result[2][0] = (right + left) / (right - left);
Result[2][1] = (top + bottom) / (top - bottom);
Result[2][1] = (top + bottom) / (top - bottom);
Result[2][2] = -(farVal + nearVal) / (farVal - nearVal);
Result[2][2] = -(farVal + nearVal) / (farVal - nearVal);
Result[2][3] = valType (-1);
Result[2][3] = static_cast<T> (-1);
Result[3][2] = -(valType (2) * farVal * nearVal) / (farVal - nearVal);
Result[3][2] = -(static_cast<T> (2) * farVal * nearVal) / (farVal - nearVal);
return Result;
return Result;
}
}
template <typename val Type >
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<val Type , defaultp> perspective
GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> perspective
(
(
val Type const & fovy,
T const & fovy,
val Type const & aspect,
T const & aspect,
val Type const & zNear,
T const & zNear,
val Type const & zFar
T const & zFar
)
)
{
{
assert(aspect != valType (0));
assert(aspect != static_cast<T> (0));
assert(zFar != zNear);
assert(zFar != zNear);
#ifdef GLM_FORCE_RADIANS
#ifdef GLM_FORCE_RADIANS
val Type const rad = fovy;
T const rad = fovy;
#else
#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.")
# pragma message("GLM: perspective function taking degrees as a parameter is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.")
val Type const rad = glm::radians(fovy);
T const rad = glm::radians(fovy);
#endif
#endif
valType tanHalfFovy = tan(rad / valType (2));
T tanHalfFovy = tan(rad / static_cast<T> (2));
detail::tmat4x4<valType, defaultp> Result(valType (0));
detail::tmat4x4<T, defaultp> Result(static_cast<T> (0));
Result[0][0] = valType (1) / (aspect * tanHalfFovy);
Result[0][0] = static_cast<T> (1) / (aspect * tanHalfFovy);
Result[1][1] = valType (1) / (tanHalfFovy);
Result[1][1] = static_cast<T> (1) / (tanHalfFovy);
Result[2][2] = - (zFar + zNear) / (zFar - zNear);
Result[2][2] = - (zFar + zNear) / (zFar - zNear);
Result[2][3] = - valType (1);
Result[2][3] = - static_cast<T> (1);
Result[3][2] = - (valType (2) * zFar * zNear) / (zFar - zNear);
Result[3][2] = - (static_cast<T> (2) * zFar * zNear) / (zFar - zNear);
return Result;
return Result;
}
}
template <typename val Type >
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<val Type , defaultp> perspectiveFov
GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> perspectiveFov
(
(
val Type const & fov,
T const & fov,
val Type const & width,
T const & width,
val Type const & height,
T const & height,
val Type const & zNear,
T const & zNear,
val Type const & zFar
T const & zFar
)
)
{
{
assert(width > valType (0));
assert(width > static_cast<T> (0));
assert(height > valType (0));
assert(height > static_cast<T> (0));
assert(fov > valType (0));
assert(fov > static_cast<T> (0));
#ifdef GLM_FORCE_RADIANS
#ifdef GLM_FORCE_RADIANS
val Type rad = fov;
T rad = fov;
#else
#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.")
# pragma message("GLM: perspectiveFov function taking degrees as a parameter is deprecated. #define GLM_FORCE_RADIANS before including GLM headers to remove this message.")
val Type rad = glm::radians(fov);
T rad = glm::radians(fov);
#endif
#endif
valType h = glm::cos(valType(0.5) * rad) / glm::sin(valType (0.5) * rad);
T h = glm::cos(static_cast<T>(0.5) * rad) / glm::sin(static_cast<T> (0.5) * rad);
val Type w = h * height / width; ///todo max(width , Height) / min(width , Height)?
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[0][0] = w;
Result[1][1] = h;
Result[1][1] = h;
Result[2][2] = - (zFar + zNear) / (zFar - zNear);
Result[2][2] = - (zFar + zNear) / (zFar - zNear);
Result[2][3] = - valType (1);
Result[2][3] = - static_cast<T> (1);
Result[3][2] = - (valType (2) * zFar * zNear) / (zFar - zNear);
Result[3][2] = - (static_cast<T> (2) * zFar * zNear) / (zFar - zNear);
return Result;
return Result;
}
}
@ -304,12 +304,14 @@ namespace glm
return Result;
return Result;
}
}
// Infinite projection matrix: http://www.terathon.com/gdc07_lengyel.pdf
template <typename T>
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> tweakedInfinitePerspective
GLM_FUNC_QUALIFIER detail::tmat4x4<T, defaultp> tweakedInfinitePerspective
(
(
T fovy,
T fovy,
T aspect,
T aspect,
T zNear
T zNear,
T epsilon
)
)
{
{
#ifdef GLM_FORCE_RADIANS
#ifdef GLM_FORCE_RADIANS
@ -324,11 +326,11 @@ namespace glm
T top = range;
T top = range;
detail::tmat4x4<T, defaultp> Result(T(0));
detail::tmat4x4<T, defaultp> Result(T(0));
Result[0][0] = (T(2) * zNear) / (right - left);
Result[0][0] = (static_cast< T> (2) * zNear) / (right - left);
Result[1][1] = (T(2) * zNear) / (top - bottom);
Result[1][1] = (static_cast< T> (2) * zNear) / (top - bottom);
Result[2][2] = static_cast<T>(0.0001) - T (1);
Result[2][2] = epsilon - static_cast<T>(1);
Result[2][3] = 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;
return Result;
}
}