From 067e1f546d3e2f6530d8309c89660d26a65a4144 Mon Sep 17 00:00:00 2001 From: Jesse Talavera-Greenberg Date: Thu, 1 Oct 2015 21:41:03 -0400 Subject: [PATCH] Add metaprogramming-helper constructors for quat and fquatSIMD - Also removed all degree symbols from test/gtc/gtc_quaternion.cpp - It made editing it a pain in the ass - Oh, added tests for the new constructors for quat, too --- glm/gtc/quaternion.hpp | 5 +++++ glm/gtc/quaternion.inl | 8 ++++++++ glm/gtx/simd_quat.hpp | 4 ++++ glm/gtx/simd_quat.inl | 7 +++++++ test/gtc/gtc_quaternion.cpp | 28 +++++++++++++++++++--------- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index 25df0f22..9c4807d1 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -107,6 +107,11 @@ namespace glm GLM_FUNC_DECL explicit tquat(T const & s, tvec3 const & v); GLM_FUNC_DECL tquat(T const & w, T const & x, T const & y, T const & z); +# ifdef GLM_META_PROG_HELPERS + template + GLM_FUNC_DECL tquat(W const& w, X const& x, Y const& y = Y()); +# endif + // -- Conversion constructors -- template diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 4c8565bc..510a6ef0 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -196,6 +196,14 @@ namespace detail *this = quat_cast(m); } +# ifdef GLM_META_PROG_HELPERS + template + template + GLM_FUNC_QUALIFIER tquat::tquat(W const& w, X const& x, Y const& y) + : x(static_cast(x)), y(static_cast(y)), z(static_cast(0)), w(static_cast(w)) + {} +# endif + # if GLM_HAS_EXPLICIT_CONVERSION_OPERATORS template GLM_FUNC_QUALIFIER tquat::operator tmat3x3() diff --git a/glm/gtx/simd_quat.hpp b/glm/gtx/simd_quat.hpp index 97075ba6..a70bcd2d 100644 --- a/glm/gtx/simd_quat.hpp +++ b/glm/gtx/simd_quat.hpp @@ -113,6 +113,10 @@ namespace detail explicit fquatSIMD( vec3 const & eulerAngles); +# ifdef GLM_META_PROG_HELPERS + template + GLM_FUNC_DECL fquatSIMD(W const& w, X const& x, Y const& y = Y()); +# endif ////////////////////////////////////// // Unary arithmetic operators diff --git a/glm/gtx/simd_quat.inl b/glm/gtx/simd_quat.inl index 2fcc7fe4..ad872423 100644 --- a/glm/gtx/simd_quat.inl +++ b/glm/gtx/simd_quat.inl @@ -96,6 +96,13 @@ GLM_FUNC_QUALIFIER fquatSIMD::fquatSIMD(vec3 const & eulerAngles) (s.x * c.y * c.z) - (c.x * s.y * s.z)); } +# ifdef GLM_META_PROG_HELPERS + template + GLM_FUNC_QUALIFIER fquatSIMD::fquatSIMD(W const& w, X const& x, Y const& y) + : fquatSIMD(static_cast(w), static_cast(x), static_cast(y), 0.0f) + {} +# endif + ////////////////////////////////////// // Unary arithmetic operators diff --git a/test/gtc/gtc_quaternion.cpp b/test/gtc/gtc_quaternion.cpp index 2f006f34..db757e7b 100644 --- a/test/gtc/gtc_quaternion.cpp +++ b/test/gtc/gtc_quaternion.cpp @@ -177,39 +177,39 @@ int test_quat_slerp() Error += glm::all(glm::epsilonEqual(id, id2, Epsilon)) ? 0 : 1; // Testing a == 1 - // Must be 90° rotation on Y : 0 0.7 0 0.7 + // Must be 90deg rotation on Y : 0 0.7 0 0.7 glm::quat Y90rot2 = glm::slerp(id, Y90rot, 1.0f); Error += glm::all(glm::epsilonEqual(Y90rot, Y90rot2, Epsilon)) ? 0 : 1; // Testing standard, easy case - // Must be 45° rotation on Y : 0 0.38 0 0.92 + // Must be 45deg rotation on Y : 0 0.38 0 0.92 glm::quat Y45rot1 = glm::slerp(id, Y90rot, 0.5f); // Testing reverse case - // Must be 45° rotation on Y : 0 0.38 0 0.92 + // Must be 45deg rotation on Y : 0 0.38 0 0.92 glm::quat Ym45rot2 = glm::slerp(Y90rot, id, 0.5f); // Testing against full circle around the sphere instead of shortest path - // Must be 45° rotation on Y - // certainly not a 135° rotation + // Must be 45deg rotation on Y + // certainly not a 135deg rotation glm::quat Y45rot3 = glm::slerp(id , -Y90rot, 0.5f); float Y45angle3 = glm::angle(Y45rot3); Error += glm::epsilonEqual(Y45angle3, glm::pi() * 0.25f, Epsilon) ? 0 : 1; Error += glm::all(glm::epsilonEqual(Ym45rot2, Y45rot3, Epsilon)) ? 0 : 1; // Same, but inverted - // Must also be 45° rotation on Y : 0 0.38 0 0.92 + // Must also be 45deg rotation on Y : 0 0.38 0 0.92 // -0 -0.38 -0 -0.92 is ok too glm::quat Y45rot4 = glm::slerp(-Y90rot, id, 0.5f); Error += glm::all(glm::epsilonEqual(Ym45rot2, -Y45rot4, Epsilon)) ? 0 : 1; // Testing q1 = q2 - // Must be 90° rotation on Y : 0 0.7 0 0.7 + // Must be 90deg rotation on Y : 0 0.7 0 0.7 glm::quat Y90rot3 = glm::slerp(Y90rot, Y90rot, 0.5f); Error += glm::all(glm::epsilonEqual(Y90rot, Y90rot3, Epsilon)) ? 0 : 1; - // Testing 180° rotation - // Must be 90° rotation on almost any axis that is on the XZ plane + // Testing 180deg rotation + // Must be 90deg rotation on almost any axis that is on the XZ plane glm::quat XZ90rot = glm::slerp(id, -Y90rot, 0.5f); float XZ90angle = glm::angle(XZ90rot); // Must be PI/4 = 0.78; Error += glm::epsilonEqual(XZ90angle, glm::pi() * 0.25f, Epsilon) ? 0 : 1; @@ -298,6 +298,16 @@ int test_quat_ctr() { int Error(0); +# ifdef GLM_META_PROG_HELPERS + { + glm::quat a(0, 1, 0, 0), b(0, 1, 0), c(0, 1); + + Error += (a == b) ? 0 : 1; + Error += (b == c) ? 0 : 1; + Error += (a == c) ? 0 : 1; + } +# endif + # if GLM_HAS_TRIVIAL_QUERIES // Error += std::is_trivially_default_constructible::value ? 0 : 1; // Error += std::is_trivially_default_constructible::value ? 0 : 1;