Merge branch '0.9.5'

This commit is contained in:
Christophe Riccio 2014-06-20 22:17:32 +02:00
commit dec4db0b15
5 changed files with 124 additions and 68 deletions

View File

@ -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.
///

View File

@ -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;
}

View File

@ -59,6 +59,9 @@ GLM 0.9.5.4: 2014-0X-XX
- Fixed lerp when cosTheta is close to 1 in quaternion slerp #210
- Added GTX_io for io with <iostream> #144
- Fixed fastDistance ambiguity #215
- Fixed tweakedInfinitePerspective #208 and added user-defined epsilon to
tweakedInfinitePerspective
- Fixed std::copy and std::vector with GLM types #214
================================================================================
GLM 0.9.5.3: 2014-04-02

View File

@ -93,29 +93,42 @@ int test_std_copy()
{
int Error = 0;
{
std::vector<int> High;
High.resize(64);
std::vector<int> Medium(High.size());
std::copy(High.begin(), High.end(), Medium.begin());
*Medium.begin() = *High.begin();
}
{
std::vector<glm::dvec4> High4;
High4.resize(64);
std::vector<glm::vec4> Medium4(High4.size());
std::copy(&High4.begin()[0], &High4.end()[0], Medium4.begin());
std::copy(High4.begin(), High4.end(), Medium4.begin());
*Medium4.begin() = *High4.begin();
}
{
std::vector<glm::dvec3> High3;
High3.resize(64);
std::vector<glm::vec3> Medium3(High3.size());
std::copy(&High3.begin()[0], &High3.end()[0], Medium3.begin());
std::copy(High3.begin(), High3.end(), Medium3.begin());
*Medium3.begin() = *High3.begin();
}
{
std::vector<glm::dvec2> High2;
High2.resize(64);
std::vector<glm::vec2> Medium2(High2.size());
std::copy(&High2.begin()[0], &High2.end()[0], Medium2.begin());
std::copy(High2.begin(), High2.end(), Medium2.begin());
*Medium2.begin() = *High2.begin();
}

View File

@ -11,16 +11,54 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/constants.hpp>
int main()
int test_perspective()
{
int Error = 0;
glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f);
return Error;
}
int test_pick()
{
int Error = 0;
glm::mat4 Pick = glm::pickMatrix(glm::vec2(1, 2), glm::vec2(3, 4), glm::ivec4(0, 0, 320, 240));
return Error;
}
int test_tweakedInfinitePerspective()
{
int Error = 0;
glm::mat4 ProjectionA = glm::tweakedInfinitePerspective(45.f, 640.f/480.f, 1.0f);
glm::mat4 ProjectionB = glm::tweakedInfinitePerspective(45.f, 640.f/480.f, 1.0f, 0.001f);
return Error;
}
int test_translate()
{
int Error = 0;
glm::lowp_vec3 v(1.0);
glm::lowp_mat4 m(0);
glm::lowp_mat4 t = glm::translate(m, v);
return Error;
}
int main()
{
int Error = 0;
Error += test_translate();
Error += test_tweakedInfinitePerspective();
Error += test_pick();
Error += test_perspective();
return Error;
}