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
This commit is contained in:
Jesse Talavera-Greenberg 2015-10-01 21:41:03 -04:00
parent daaf86dcef
commit 067e1f546d
5 changed files with 43 additions and 9 deletions

View File

@ -107,6 +107,11 @@ namespace glm
GLM_FUNC_DECL explicit tquat(T const & s, tvec3<T, P> const & v);
GLM_FUNC_DECL tquat(T const & w, T const & x, T const & y, T const & z);
# ifdef GLM_META_PROG_HELPERS
template <typename W, typename X, typename Y = X>
GLM_FUNC_DECL tquat(W const& w, X const& x, Y const& y = Y());
# endif
// -- Conversion constructors --
template <typename U, precision Q>

View File

@ -196,6 +196,14 @@ namespace detail
*this = quat_cast(m);
}
# ifdef GLM_META_PROG_HELPERS
template <typename T, precision P>
template <typename W, typename X, typename Y>
GLM_FUNC_QUALIFIER tquat<T, P>::tquat(W const& w, X const& x, Y const& y)
: x(static_cast<T>(x)), y(static_cast<T>(y)), z(static_cast<T>(0)), w(static_cast<T>(w))
{}
# endif
# if GLM_HAS_EXPLICIT_CONVERSION_OPERATORS
template <typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P>::operator tmat3x3<T, P>()

View File

@ -113,6 +113,10 @@ namespace detail
explicit fquatSIMD(
vec3 const & eulerAngles);
# ifdef GLM_META_PROG_HELPERS
template <typename W, typename X, typename Y = X>
GLM_FUNC_DECL fquatSIMD(W const& w, X const& x, Y const& y = Y());
# endif
//////////////////////////////////////
// Unary arithmetic operators

View File

@ -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 <typename W, typename X, typename Y>
GLM_FUNC_QUALIFIER fquatSIMD::fquatSIMD(W const& w, X const& x, Y const& y)
: fquatSIMD(static_cast<float>(w), static_cast<float>(x), static_cast<float>(y), 0.0f)
{}
# endif
//////////////////////////////////////
// Unary arithmetic operators

View File

@ -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<float>() * 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<float>() * 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<glm::quat>::value ? 0 : 1;
// Error += std::is_trivially_default_constructible<glm::dquat>::value ? 0 : 1;