diff --git a/glm/gtc/matrix_transform.hpp b/glm/gtc/matrix_transform.hpp index 2eb24cbf..1a9f0bac 100644 --- a/glm/gtc/matrix_transform.hpp +++ b/glm/gtc/matrix_transform.hpp @@ -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 - GLM_FUNC_DECL detail::tmat4x4 frustum( + template + GLM_FUNC_DECL detail::tmat4x4 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 - GLM_FUNC_DECL detail::tmat4x4 perspective( + template + GLM_FUNC_DECL detail::tmat4x4 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 - GLM_FUNC_DECL detail::tmat4x4 perspectiveFov( + template + GLM_FUNC_DECL detail::tmat4x4 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 - GLM_FUNC_DECL detail::tmat4x4 infinitePerspective( + template + GLM_FUNC_DECL detail::tmat4x4 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 - GLM_FUNC_DECL detail::tmat4x4 tweakedInfinitePerspective( - T fovy, T aspect, T near); + template + GLM_FUNC_DECL detail::tmat4x4 tweakedInfinitePerspective( + T fovy, T aspect, T near, T epsilon = epsilon()); /// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates. /// diff --git a/glm/gtc/matrix_transform.inl b/glm/gtc/matrix_transform.inl index 25f13751..03d201c6 100644 --- a/glm/gtc/matrix_transform.inl +++ b/glm/gtc/matrix_transform.inl @@ -192,87 +192,87 @@ namespace glm return Result; } - template - GLM_FUNC_QUALIFIER detail::tmat4x4 frustum + template + GLM_FUNC_QUALIFIER detail::tmat4x4 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 Result(0); - Result[0][0] = (valType(2) * nearVal) / (right - left); - Result[1][1] = (valType(2) * nearVal) / (top - bottom); + detail::tmat4x4 Result(0); + Result[0][0] = (static_cast(2) * nearVal) / (right - left); + Result[1][1] = (static_cast(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(-1); + Result[3][2] = -(static_cast(2) * farVal * nearVal) / (farVal - nearVal); return Result; } - template - GLM_FUNC_QUALIFIER detail::tmat4x4 perspective + template + GLM_FUNC_QUALIFIER detail::tmat4x4 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(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(2)); - detail::tmat4x4 Result(valType(0)); - Result[0][0] = valType(1) / (aspect * tanHalfFovy); - Result[1][1] = valType(1) / (tanHalfFovy); + detail::tmat4x4 Result(static_cast(0)); + Result[0][0] = static_cast(1) / (aspect * tanHalfFovy); + Result[1][1] = static_cast(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(1); + Result[3][2] = - (static_cast(2) * zFar * zNear) / (zFar - zNear); return Result; } - template - GLM_FUNC_QUALIFIER detail::tmat4x4 perspectiveFov + template + GLM_FUNC_QUALIFIER detail::tmat4x4 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(0)); + assert(height > static_cast(0)); + assert(fov > static_cast(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(0.5) * rad) / glm::sin(static_cast(0.5) * rad); + T w = h * height / width; ///todo max(width , Height) / min(width , Height)? - detail::tmat4x4 Result(valType(0)); + detail::tmat4x4 Result(static_cast(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(1); + Result[3][2] = - (static_cast(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 GLM_FUNC_QUALIFIER detail::tmat4x4 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 Result(T(0)); - Result[0][0] = (T(2) * zNear) / (right - left); - Result[1][1] = (T(2) * zNear) / (top - bottom); - Result[2][2] = static_cast(0.0001) - T(1); + Result[0][0] = (static_cast(2) * zNear) / (right - left); + Result[1][1] = (static_cast(2) * zNear) / (top - bottom); + Result[2][2] = epsilon - static_cast(1); Result[2][3] = static_cast(-1); - Result[3][2] = - (T(0.0001) - T(2)) * zNear; + Result[3][2] = (epsilon - static_cast(2)) * zNear; return Result; } diff --git a/readme.txt b/readme.txt index 8016adc5..83a0bb45 100644 --- a/readme.txt +++ b/readme.txt @@ -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 #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 diff --git a/test/core/core_type_cast.cpp b/test/core/core_type_cast.cpp index f33972c6..97e2fdd6 100644 --- a/test/core/core_type_cast.cpp +++ b/test/core/core_type_cast.cpp @@ -94,28 +94,41 @@ int test_std_copy() int Error = 0; { - std::vector High4; - std::vector Medium4(High4.size()); + std::vector High; + High.resize(64); + std::vector Medium(High.size()); + + std::copy(High.begin(), High.end(), Medium.begin()); - std::copy(&High4.begin()[0], &High4.end()[0], Medium4.begin()); + *Medium.begin() = *High.begin(); + } + + { + std::vector High4; + High4.resize(64); + std::vector Medium4(High4.size()); + + std::copy(High4.begin(), High4.end(), Medium4.begin()); *Medium4.begin() = *High4.begin(); } { std::vector High3; + High3.resize(64); std::vector 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 High2; + High2.resize(64); std::vector 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(); } diff --git a/test/gtc/gtc_matrix_transform.cpp b/test/gtc/gtc_matrix_transform.cpp index 05d5f50e..0ea54598 100644 --- a/test/gtc/gtc_matrix_transform.cpp +++ b/test/gtc/gtc_matrix_transform.cpp @@ -11,16 +11,54 @@ #include #include -int main() +int test_perspective() { int Error = 0; - + glm::mat4 Projection = glm::perspective(glm::pi() * 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; +}