diff --git a/glm/detail/func_geometric.inl b/glm/detail/func_geometric.inl index 05c18d6b..488a216a 100644 --- a/glm/detail/func_geometric.inl +++ b/glm/detail/func_geometric.inl @@ -180,7 +180,7 @@ namespace detail { return detail::compute_cross::value>::call(x, y); } - +/* // normalize template GLM_FUNC_QUALIFIER genType normalize(genType const& x) @@ -189,7 +189,7 @@ namespace detail return x < genType(0) ? genType(-1) : genType(1); } - +*/ template GLM_FUNC_QUALIFIER vec normalize(vec const& x) { diff --git a/glm/detail/type_quat.hpp b/glm/detail/type_quat.hpp index b08b3c3f..5b6f7872 100644 --- a/glm/detail/type_quat.hpp +++ b/glm/detail/type_quat.hpp @@ -19,6 +19,7 @@ #include "../detail/type_vec3.hpp" #include "../detail/type_vec4.hpp" #include "../ext/vector_relational.hpp" +#include "../ext/quaternion_relational.hpp" #include "../gtc/constants.hpp" #include "../gtc/matrix_transform.hpp" diff --git a/glm/detail/type_quat.inl b/glm/detail/type_quat.inl index e10fa0a0..0e7b1c40 100644 --- a/glm/detail/type_quat.inl +++ b/glm/detail/type_quat.inl @@ -1,8 +1,6 @@ -/// @ref gtc_quaternion - #include "../trigonometric.hpp" -#include "../geometric.hpp" #include "../exponential.hpp" +#include "../ext/quaternion_geometric.hpp" #include namespace glm{ @@ -170,7 +168,7 @@ namespace detail t = cross(u, v); } - *this = normalize(qua(real_part, t.x, t.y, t.z)); + *this = normalize(qua(real_part, t.x, t.y, t.z)); } template diff --git a/glm/ext/quaternion_geometric.hpp b/glm/ext/quaternion_geometric.hpp new file mode 100644 index 00000000..cc209aa2 --- /dev/null +++ b/glm/ext/quaternion_geometric.hpp @@ -0,0 +1,71 @@ +/// @ref ext_quaternion_geometric +/// @file glm/ext/quaternion_geometric.hpp +/// +/// @see core (dependence) +/// +/// @defgroup ext_quaternion_geometric GLM_EXT_quaternion_geometric +/// @ingroup gtx +/// +/// Include to use the features of this extension. +/// +/// Defines a templated quaternion type and several quaternion operations. + +#pragma once + +// Dependency: +#include "../gtc/constants.hpp" +#include "../gtc/matrix_transform.hpp" +#include "../ext/vector_relational.hpp" +#include "../ext/quaternion_float.hpp" +#include "../ext/quaternion_float_precision.hpp" +#include "../ext/quaternion_double.hpp" +#include "../ext/quaternion_double_precision.hpp" +#include "../ext/quaternion_relational.hpp" +#include "../detail/type_mat3x3.hpp" +#include "../detail/type_mat4x4.hpp" +#include "../detail/type_vec3.hpp" +#include "../detail/type_vec4.hpp" + +#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_GTC_quaternion extension included") +#endif + +namespace glm +{ + /// @addtogroup ext_quaternion_geometric + /// @{ + + /// Returns the length of the quaternion. + /// + /// @tparam T Floating-point scalar types. + /// + /// @see ext_quaternion_geometric + template + GLM_FUNC_DECL T length(qua const& q); + + /// Returns the normalized quaternion. + /// + /// @tparam T Floating-point scalar types. + /// + /// @see ext_quaternion_geometric + template + GLM_FUNC_DECL qua normalize(qua const& q); + + /// Returns dot product of q1 and q2, i.e., q1[0] * q2[0] + q1[1] * q2[1] + ... + /// + /// @tparam T Floating-point scalar types. + /// + /// @see ext_quaternion_geometric + template + GLM_FUNC_DECL T dot(qua const& x, qua const& y); + + /// Compute a cross product between a quaternion and a vector. + /// + /// @see ext_quaternion_geometric + template + GLM_FUNC_QUALIFIER qua cross(qua const& q1, qua const& q2); + + /// @} +} //namespace glm + +#include "quaternion_geometric.inl" diff --git a/glm/ext/quaternion_geometric.inl b/glm/ext/quaternion_geometric.inl new file mode 100644 index 00000000..9f084e5d --- /dev/null +++ b/glm/ext/quaternion_geometric.inl @@ -0,0 +1,42 @@ +#include "../geometric.hpp" +#include "../exponential.hpp" +#include + +namespace glm +{ + // -- Operations -- + + template + GLM_FUNC_QUALIFIER T dot(qua const& x, qua const& y) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'dot' accepts only floating-point inputs"); + return detail::compute_dot, T, detail::is_aligned::value>::call(x, y); + } + + template + GLM_FUNC_QUALIFIER T length(qua const& q) + { + return glm::sqrt(dot(q, q)); + } + + template + GLM_FUNC_QUALIFIER qua normalize(qua const& q) + { + T len = length(q); + if(len <= static_cast(0)) // Problem + return qua(static_cast(1), static_cast(0), static_cast(0), static_cast(0)); + T oneOverLen = T(1) / len; + return qua(q.w * oneOverLen, q.x * oneOverLen, q.y * oneOverLen, q.z * oneOverLen); + } + + template + GLM_FUNC_QUALIFIER qua cross(qua const& q1, qua const& q2) + { + return qua( + q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z, + q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y, + q1.w * q2.y + q1.y * q2.w + q1.z * q2.x - q1.x * q2.z, + q1.w * q2.z + q1.z * q2.w + q1.x * q2.y - q1.y * q2.x); + } +}//namespace glm + diff --git a/glm/ext/quaternion_relational.hpp b/glm/ext/quaternion_relational.hpp new file mode 100644 index 00000000..e5dd2318 --- /dev/null +++ b/glm/ext/quaternion_relational.hpp @@ -0,0 +1,100 @@ +/// @ref ext_quaternion_relational +/// @file glm/ext/quaternion_relational.hpp +/// +/// @defgroup ext_quaternion_relational GLM_EXT_quaternion_relational +/// @ingroup gtc +/// +/// Include to use the features of this extension. +/// +/// Defines a templated quaternion type and several quaternion operations. + +#pragma once + +// Dependency: +#include "../detail/qualifier.hpp" + +#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_EXT_quaternion_relational extension included") +#endif + +namespace glm +{ + /// @addtogroup ext_quaternion_relational + /// @{ + + /// Returns the component-wise comparison result of x < y. + /// + /// @tparam T Floating-point scalar types + /// @tparam Q Value from qualifier enum + /// + /// @see ext_quaternion_relational + template + GLM_FUNC_DECL vec<4, bool, Q> lessThan(qua const& x, qua const& y); + + /// Returns the component-wise comparison of result x <= y. + /// + /// @tparam T Floating-point scalar types + /// @tparam Q Value from qualifier enum + /// + /// @see ext_quaternion_relational + template + GLM_FUNC_DECL vec<4, bool, Q> lessThanEqual(qua const& x, qua const& y); + + /// Returns the component-wise comparison of result x > y. + /// + /// @tparam T Floating-point scalar types + /// @tparam Q Value from qualifier enum + /// + /// @see ext_quaternion_relational + template + GLM_FUNC_DECL vec<4, bool, Q> greaterThan(qua const& x, qua const& y); + + /// Returns the component-wise comparison of result x >= y. + /// + /// @tparam T Floating-point scalar types + /// @tparam Q Value from qualifier enum + /// + /// @see ext_quaternion_relational + template + GLM_FUNC_DECL vec<4, bool, Q> greaterThanEqual(qua const& x, qua const& y); + + /// Returns the component-wise comparison of result x == y. + /// + /// @tparam T Floating-point scalar types + /// @tparam Q Value from qualifier enum + /// + /// @see ext_quaternion_relational + template + GLM_FUNC_DECL vec<4, bool, Q> equal(qua const& x, qua const& y); + + /// Returns the component-wise comparison of |x - y| < epsilon. + /// + /// @tparam T Floating-point scalar types + /// @tparam Q Value from qualifier enum + /// + /// @see ext_quaternion_relational + template + GLM_FUNC_DECL vec<4, bool, Q> equal(qua const& x, qua const& y, T epsilon); + + /// Returns the component-wise comparison of result x != y. + /// + /// @tparam T Floating-point scalar types + /// @tparam Q Value from qualifier enum + /// + /// @see ext_quaternion_relational + template + GLM_FUNC_DECL vec<4, bool, Q> notEqual(qua const& x, qua const& y); + + /// Returns the component-wise comparison of |x - y| >= epsilon. + /// + /// @tparam T Floating-point scalar types + /// @tparam Q Value from qualifier enum + /// + /// @see ext_quaternion_relational + template + GLM_FUNC_DECL vec<4, bool, Q> notEqual(qua const& x, qua const& y, T epsilon); + + /// @} +} //namespace glm + +#include "quaternion_relational.inl" diff --git a/glm/ext/quaternion_relational.inl b/glm/ext/quaternion_relational.inl new file mode 100644 index 00000000..286a8e39 --- /dev/null +++ b/glm/ext/quaternion_relational.inl @@ -0,0 +1,71 @@ +namespace glm +{ + template + GLM_FUNC_QUALIFIER vec<4, bool, Q> lessThan(qua const& x, qua const& y) + { + vec<4, bool, Q> Result; + for(length_t i = 0; i < x.length(); ++i) + Result[i] = x[i] < y[i]; + return Result; + } + + template + GLM_FUNC_QUALIFIER vec<4, bool, Q> lessThanEqual(qua const& x, qua const& y) + { + vec<4, bool, Q> Result; + for(length_t i = 0; i < x.length(); ++i) + Result[i] = x[i] <= y[i]; + return Result; + } + + template + GLM_FUNC_QUALIFIER vec<4, bool, Q> greaterThan(qua const& x, qua const& y) + { + vec<4, bool, Q> Result; + for(length_t i = 0; i < x.length(); ++i) + Result[i] = x[i] > y[i]; + return Result; + } + + template + GLM_FUNC_QUALIFIER vec<4, bool, Q> greaterThanEqual(qua const& x, qua const& y) + { + vec<4, bool, Q> Result; + for(length_t i = 0; i < x.length(); ++i) + Result[i] = x[i] >= y[i]; + return Result; + } + + template + GLM_FUNC_QUALIFIER vec<4, bool, Q> equal(qua const& x, qua const& y) + { + vec<4, bool, Q> Result; + for(length_t i = 0; i < x.length(); ++i) + Result[i] = detail::compute_equal::is_iec559>::call(x[i], y[i]); + return Result; + } + + template + GLM_FUNC_QUALIFIER vec<4, bool, Q> equal(qua const& x, qua const& y, T epsilon) + { + vec<4, T, Q> v(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w); + return lessThan(abs(v), vec<4, T, Q>(epsilon)); + } + + template + GLM_FUNC_QUALIFIER vec<4, bool, Q> notEqual(qua const& x, qua const& y) + { + vec<4, bool, Q> Result; + for(length_t i = 0; i < x.length(); ++i) + Result[i] = !detail::compute_equal::is_iec559>::call(x[i], y[i]); + return Result; + } + + template + GLM_FUNC_QUALIFIER vec<4, bool, Q> notEqual(qua const& x, qua const& y, T epsilon) + { + vec<4, T, Q> v(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w); + return greaterThanEqual(abs(v), vec<4, T, Q>(epsilon)); + } +}//namespace glm + diff --git a/glm/ext/vector_relational.hpp b/glm/ext/vector_relational.hpp index eaf22494..a78e96a0 100644 --- a/glm/ext/vector_relational.hpp +++ b/glm/ext/vector_relational.hpp @@ -13,7 +13,6 @@ #pragma once // Dependencies -#include "../detail/setup.hpp" #include "../detail/qualifier.hpp" #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index e8a398c8..e326ff4f 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -21,6 +21,8 @@ #include "../ext/quaternion_float_precision.hpp" #include "../ext/quaternion_double.hpp" #include "../ext/quaternion_double_precision.hpp" +#include "../ext/quaternion_relational.hpp" +#include "../ext/quaternion_geometric.hpp" #include "../detail/type_mat3x3.hpp" #include "../detail/type_mat4x4.hpp" #include "../detail/type_vec3.hpp" @@ -35,14 +37,6 @@ namespace glm /// @addtogroup gtc_quaternion /// @{ - // -- Boolean operators -- - - template - GLM_FUNC_DECL GLM_CONSTEXPR bool operator==(qua const& q1, qua const& q2); - - template - GLM_FUNC_DECL GLM_CONSTEXPR bool operator!=(qua const& q1, qua const& q2); - /// Builds an identity quaternion. template GLM_FUNC_DECL GLM_CONSTEXPR genType identity(); diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index cdc27db4..1a0c4f2c 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -9,39 +9,6 @@ namespace glm { // -- Operations -- - - template - GLM_FUNC_QUALIFIER T dot(qua const& x, qua const& y) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'dot' accepts only floating-point inputs"); - return detail::compute_dot, T, detail::is_aligned::value>::call(x, y); - } - - template - GLM_FUNC_QUALIFIER T length(qua const& q) - { - return glm::sqrt(dot(q, q)); - } - - template - GLM_FUNC_QUALIFIER qua normalize(qua const& q) - { - T len = length(q); - if(len <= T(0)) // Problem - return qua(static_cast(1), static_cast(0), static_cast(0), static_cast(0)); - T oneOverLen = T(1) / len; - return qua(q.w * oneOverLen, q.x * oneOverLen, q.y * oneOverLen, q.z * oneOverLen); - } - - template - GLM_FUNC_QUALIFIER qua cross(qua const& q1, qua const& q2) - { - return qua( - q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z, - q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y, - q1.w * q2.y + q1.y * q2.w + q1.z * q2.x - q1.x * q2.z, - q1.w * q2.z + q1.z * q2.w + q1.x * q2.y - q1.y * q2.x); - } /* // (x * sin(1 - a) * angle / sin(angle)) + (y * sin(a) * angle / sin(angle)) template @@ -354,74 +321,6 @@ namespace glm return Result; } - template - GLM_FUNC_QUALIFIER vec<4, bool, Q> lessThan(qua const& x, qua const& y) - { - vec<4, bool, Q> Result; - for(length_t i = 0; i < x.length(); ++i) - Result[i] = x[i] < y[i]; - return Result; - } - - template - GLM_FUNC_QUALIFIER vec<4, bool, Q> lessThanEqual(qua const& x, qua const& y) - { - vec<4, bool, Q> Result; - for(length_t i = 0; i < x.length(); ++i) - Result[i] = x[i] <= y[i]; - return Result; - } - - template - GLM_FUNC_QUALIFIER vec<4, bool, Q> greaterThan(qua const& x, qua const& y) - { - vec<4, bool, Q> Result; - for(length_t i = 0; i < x.length(); ++i) - Result[i] = x[i] > y[i]; - return Result; - } - - template - GLM_FUNC_QUALIFIER vec<4, bool, Q> greaterThanEqual(qua const& x, qua const& y) - { - vec<4, bool, Q> Result; - for(length_t i = 0; i < x.length(); ++i) - Result[i] = x[i] >= y[i]; - return Result; - } - - template - GLM_FUNC_QUALIFIER vec<4, bool, Q> equal(qua const& x, qua const& y) - { - vec<4, bool, Q> Result; - for(length_t i = 0; i < x.length(); ++i) - Result[i] = detail::compute_equal::is_iec559>::call(x[i], y[i]); - return Result; - } - - template - GLM_FUNC_QUALIFIER vec<4, bool, Q> equal(qua const& x, qua const& y, T epsilon) - { - vec<4, T, Q> v(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w); - return lessThan(abs(v), vec<4, T, Q>(epsilon)); - } - - template - GLM_FUNC_QUALIFIER vec<4, bool, Q> notEqual(qua const& x, qua const& y) - { - vec<4, bool, Q> Result; - for(length_t i = 0; i < x.length(); ++i) - Result[i] = !detail::compute_equal::is_iec559>::call(x[i], y[i]); - return Result; - } - - template - GLM_FUNC_QUALIFIER vec<4, bool, Q> notEqual(qua const& x, qua const& y, T epsilon) - { - vec<4, T, Q> v(x.x - y.x, x.y - y.y, x.z - y.z, x.w - y.w); - return greaterThanEqual(abs(v), vec<4, T, Q>(epsilon)); - } - template GLM_FUNC_QUALIFIER vec<4, bool, Q> isnan(qua const& q) { diff --git a/test/ext/CMakeLists.txt b/test/ext/CMakeLists.txt index df749a69..181a7ba1 100644 --- a/test/ext/CMakeLists.txt +++ b/test/ext/CMakeLists.txt @@ -1,4 +1,6 @@ glmCreateTestGTC(ext_matrix_relational) +glmCreateTestGTC(ext_quaternion_relational) +glmCreateTestGTC(ext_quaternion_type) glmCreateTestGTC(ext_scalar_relational) glmCreateTestGTC(ext_vec1) glmCreateTestGTC(ext_vector_vec1) diff --git a/test/ext/ext_quaternion_relational.cpp b/test/ext/ext_quaternion_relational.cpp new file mode 100644 index 00000000..7d7fae14 --- /dev/null +++ b/test/ext/ext_quaternion_relational.cpp @@ -0,0 +1,127 @@ +#include +#include +#include +#include +#include +#include +#include + +template +static int test_operators() +{ + int Error = 0; + + { + genType const A(1); + genType const B(1); + + genType const C = A + B; + Error += glm::all(glm::equal(C, genType(2), glm::epsilon())) ? 0 : 1; + + genType const D = A - B; + Error += glm::all(glm::equal(D, genType(0), glm::epsilon())) ? 0 : 1; + + genType const E = A * B; + Error += glm::all(glm::equal(E, genType(1), glm::epsilon())) ? 0 : 1; + + genType const F = A / B; + Error += glm::all(glm::equal(F, genType(1), glm::epsilon())) ? 0 : 1; + } + + return Error; +} + +template +static int test_ctor() +{ + int Error = 0; + + glm::vec1 const A = genType(1); + + glm::vec1 const E(genType(1)); + Error += glm::all(glm::equal(A, E, glm::epsilon())) ? 0 : 1; + + glm::vec1 const F(E); + Error += glm::all(glm::equal(A, F, glm::epsilon())) ? 0 : 1; + + genType const B = genType(1); + genType const G(glm::vec2(1)); + Error += glm::all(glm::equal(B, G, glm::epsilon())) ? 0 : 1; + + genType const H(glm::vec3(1)); + Error += glm::all(glm::equal(B, H, glm::epsilon())) ? 0 : 1; + + genType const I(glm::vec4(1)); + Error += glm::all(glm::equal(B, I, glm::epsilon())) ? 0 : 1; + + return Error; +} + +template +static int test_size() +{ + int Error = 0; + + Error += sizeof(glm::vec1) == sizeof(genType) ? 0 : 1; + Error += genType().length() == 1 ? 0 : 1; + Error += genType::length() == 1 ? 0 : 1; + + return Error; +} + +template +static int test_relational() +{ + int Error = 0; + + genType const A(1); + genType const B(1); + genType const C(0); + + Error += all(equal(A, B, glm::epsilon())) ? 0 : 1; + Error += any(notEqual(A, C, glm::epsilon())) ? 0 : 1; + + return Error; +} + +template +static int test_constexpr() +{ +# if GLM_CONFIG_CONSTEXP == GLM_ENABLE + static_assert(genType::length() == 1, "GLM: Failed constexpr"); +# endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + Error += test_operators(); + + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + Error += test_ctor(); + + Error += test_size(); + Error += test_size(); + Error += test_size(); + Error += test_size(); + + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + Error += test_relational(); + + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + Error += test_constexpr(); + + return Error; +} diff --git a/test/ext/ext_quaternion_type.cpp b/test/ext/ext_quaternion_type.cpp new file mode 100644 index 00000000..7e611496 --- /dev/null +++ b/test/ext/ext_quaternion_type.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +static int test_ctr() +{ + int Error(0); + +# if GLM_HAS_TRIVIAL_QUERIES + // Error += std::is_trivially_default_constructible::value ? 0 : 1; + // Error += std::is_trivially_default_constructible::value ? 0 : 1; + // Error += std::is_trivially_copy_assignable::value ? 0 : 1; + // Error += std::is_trivially_copy_assignable::value ? 0 : 1; + Error += std::is_trivially_copyable::value ? 0 : 1; + Error += std::is_trivially_copyable::value ? 0 : 1; + + Error += std::is_copy_constructible::value ? 0 : 1; + Error += std::is_copy_constructible::value ? 0 : 1; +# endif + +# if GLM_HAS_INITIALIZER_LISTS + { + glm::quat A{0, 1, 2, 3}; + + std::vector B{ + {0, 1, 2, 3}, + {0, 1, 2, 3}}; + } +# endif//GLM_HAS_INITIALIZER_LISTS + + return Error; +} + +static int test_two_axis_ctr() +{ + int Error = 0; + + glm::quat const q1(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0)); + glm::vec3 const v1 = q1 * glm::vec3(1, 0, 0); + Error += glm::all(glm::equal(v1, glm::vec3(0, 1, 0), 0.0001f)) ? 0 : 1; + + glm::quat const q2 = q1 * q1; + glm::vec3 const v2 = q2 * glm::vec3(1, 0, 0); + Error += glm::all(glm::equal(v2, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1; + + glm::quat const q3(glm::vec3(1, 0, 0), glm::vec3(-1, 0, 0)); + glm::vec3 const v3 = q3 * glm::vec3(1, 0, 0); + Error += glm::all(glm::equal(v3, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1; + + glm::quat const q4(glm::vec3(0, 1, 0), glm::vec3(0, -1, 0)); + glm::vec3 const v4 = q4 * glm::vec3(0, 1, 0); + Error += glm::all(glm::equal(v4, glm::vec3(0, -1, 0), 0.0001f)) ? 0 : 1; + + glm::quat const q5(glm::vec3(0, 0, 1), glm::vec3(0, 0, -1)); + glm::vec3 const v5 = q5 * glm::vec3(0, 0, 1); + Error += glm::all(glm::equal(v5, glm::vec3(0, 0, -1), 0.0001f)) ? 0 : 1; + + return Error; +} + +static int test_size() +{ + int Error = 0; + + std::size_t const A = sizeof(glm::quat); + Error += 16 == A ? 0 : 1; + std::size_t const B = sizeof(glm::dquat); + Error += 32 == B ? 0 : 1; + Error += glm::quat().length() == 4 ? 0 : 1; + Error += glm::dquat().length() == 4 ? 0 : 1; + Error += glm::quat::length() == 4 ? 0 : 1; + Error += glm::dquat::length() == 4 ? 0 : 1; + + return Error; +} + +static int test_precision() +{ + int Error = 0; + + Error += sizeof(glm::lowp_quat) <= sizeof(glm::mediump_quat) ? 0 : 1; + Error += sizeof(glm::mediump_quat) <= sizeof(glm::highp_quat) ? 0 : 1; + + return Error; +} + +static int test_constexpr() +{ +#if GLM_HAS_CONSTEXPR + static_assert(glm::quat::length() == 4, "GLM: Failed constexpr"); + static_assert(glm::quat(1.0f, glm::vec3(0.0f)).w > 0.0f, "GLM: Failed constexpr"); +#endif + + return 0; +} + +int main() +{ + int Error = 0; + + Error += test_ctr(); + Error += test_two_axis_ctr(); + Error += test_size(); + Error += test_precision(); + Error += test_constexpr(); + + return Error; +} diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index f7ad13e2..65f3b44a 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -73,16 +73,6 @@ int test_quat_mix() return Error; } -int test_quat_precision() -{ - int Error = 0; - - Error += sizeof(glm::lowp_quat) <= sizeof(glm::mediump_quat) ? 0 : 1; - Error += sizeof(glm::mediump_quat) <= sizeof(glm::highp_quat) ? 0 : 1; - - return Error; -} - int test_quat_normalize() { int Error(0); @@ -204,57 +194,7 @@ int test_quat_slerp() return Error; } -int test_quat_mul() -{ - int Error = 0; - - glm::quat temp1 = glm::normalize(glm::quat(1.0f, glm::vec3(0.0, 1.0, 0.0))); - glm::quat temp2 = glm::normalize(glm::quat(0.5f, glm::vec3(1.0, 0.0, 0.0))); - - glm::vec3 transformed0 = (temp1 * glm::vec3(0.0, 1.0, 0.0) * glm::inverse(temp1)); - glm::vec3 temp4 = temp2 * transformed0 * glm::inverse(temp2); - - glm::quat temp5 = glm::normalize(temp1 * temp2); - glm::vec3 temp6 = temp5 * glm::vec3(0.0, 1.0, 0.0) * glm::inverse(temp5); - - glm::quat temp7(1.0f, glm::vec3(0.0, 1.0, 0.0)); - - temp7 *= temp5; - temp7 *= glm::inverse(temp5); - - Error += glm::any(glm::notEqual(temp7, glm::quat(1.0f, glm::vec3(0.0, 1.0, 0.0)), glm::epsilon())) ? 1 : 0; - - return Error; -} - -int test_quat_two_axis_ctr() -{ - int Error = 0; - - glm::quat const q1(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0)); - glm::vec3 const v1 = q1 * glm::vec3(1, 0, 0); - Error += glm::all(glm::equal(v1, glm::vec3(0, 1, 0), 0.0001f)) ? 0 : 1; - - glm::quat const q2 = q1 * q1; - glm::vec3 const v2 = q2 * glm::vec3(1, 0, 0); - Error += glm::all(glm::equal(v2, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1; - - glm::quat const q3(glm::vec3(1, 0, 0), glm::vec3(-1, 0, 0)); - glm::vec3 const v3 = q3 * glm::vec3(1, 0, 0); - Error += glm::all(glm::equal(v3, glm::vec3(-1, 0, 0), 0.0001f)) ? 0 : 1; - - glm::quat const q4(glm::vec3(0, 1, 0), glm::vec3(0, -1, 0)); - glm::vec3 const v4 = q4 * glm::vec3(0, 1, 0); - Error += glm::all(glm::equal(v4, glm::vec3(0, -1, 0), 0.0001f)) ? 0 : 1; - - glm::quat const q5(glm::vec3(0, 0, 1), glm::vec3(0, 0, -1)); - glm::vec3 const v5 = q5 * glm::vec3(0, 0, 1); - Error += glm::all(glm::equal(v5, glm::vec3(0, 0, -1), 0.0001f)) ? 0 : 1; - - return Error; -} - -int test_quat_mul_vec() +static int test_quat_mul_vec() { int Error(0); @@ -268,61 +208,29 @@ int test_quat_mul_vec() return Error; } -int test_quat_ctr() +static int test_mul() { - int Error(0); - -# if GLM_HAS_TRIVIAL_QUERIES - // Error += std::is_trivially_default_constructible::value ? 0 : 1; - // Error += std::is_trivially_default_constructible::value ? 0 : 1; - // Error += std::is_trivially_copy_assignable::value ? 0 : 1; - // Error += std::is_trivially_copy_assignable::value ? 0 : 1; - Error += std::is_trivially_copyable::value ? 0 : 1; - Error += std::is_trivially_copyable::value ? 0 : 1; + int Error = 0; - Error += std::is_copy_constructible::value ? 0 : 1; - Error += std::is_copy_constructible::value ? 0 : 1; -# endif + glm::quat temp1 = glm::normalize(glm::quat(1.0f, glm::vec3(0.0, 1.0, 0.0))); + glm::quat temp2 = glm::normalize(glm::quat(0.5f, glm::vec3(1.0, 0.0, 0.0))); -# if GLM_HAS_INITIALIZER_LISTS - { - glm::quat A{0, 1, 2, 3}; + glm::vec3 transformed0 = (temp1 * glm::vec3(0.0, 1.0, 0.0) * glm::inverse(temp1)); + glm::vec3 temp4 = temp2 * transformed0 * glm::inverse(temp2); - std::vector B{ - {0, 1, 2, 3}, - {0, 1, 2, 3}}; - } -# endif//GLM_HAS_INITIALIZER_LISTS + glm::quat temp5 = glm::normalize(temp1 * temp2); + glm::vec3 temp6 = temp5 * glm::vec3(0.0, 1.0, 0.0) * glm::inverse(temp5); - return Error; -} + glm::quat temp7(1.0f, glm::vec3(0.0, 1.0, 0.0)); -int test_size() -{ - int Error = 0; + temp7 *= temp5; + temp7 *= glm::inverse(temp5); - std::size_t const A = sizeof(glm::quat); - Error += 16 == A ? 0 : 1; - std::size_t const B = sizeof(glm::dquat); - Error += 32 == B ? 0 : 1; - Error += glm::quat().length() == 4 ? 0 : 1; - Error += glm::dquat().length() == 4 ? 0 : 1; - Error += glm::quat::length() == 4 ? 0 : 1; - Error += glm::dquat::length() == 4 ? 0 : 1; + Error += glm::any(glm::notEqual(temp7, glm::quat(1.0f, glm::vec3(0.0, 1.0, 0.0)), glm::epsilon())) ? 1 : 0; return Error; } -static int test_constexpr() -{ -#if GLM_HAS_CONSTEXPR - static_assert(glm::quat::length() == 4, "GLM: Failed constexpr"); - static_assert(glm::quat(1.0f, glm::vec3(0.0f)).w > 0.0f, "GLM: Failed constexpr"); -#endif - - return 0; -} - int test_identity() { int Error = 0; @@ -344,19 +252,14 @@ int main() { int Error = 0; - Error += test_quat_ctr(); + Error += test_mul(); Error += test_quat_mul_vec(); - Error += test_quat_two_axis_ctr(); - Error += test_quat_mul(); - Error += test_quat_precision(); Error += test_quat_angle(); Error += test_quat_angleAxis(); Error += test_quat_mix(); Error += test_quat_normalize(); Error += test_quat_euler(); Error += test_quat_slerp(); - Error += test_size(); - Error += test_constexpr(); Error += test_identity(); return Error;