Fixed bug #15, added missing roll, pitch and yaw functions; Fixed half implicit conversions

master
Christophe Riccio ago%!(EXTRA string=13 years)
parent 931b7bcdd6
commit 841f91e830
  1. 8
      glm/core/func_exponential.inl
  2. 20
      glm/core/func_trigonometric.inl
  3. 5
      glm/core/type_half.hpp
  4. 8
      glm/core/type_half.inl
  5. 21
      glm/gtc/quaternion.hpp
  6. 39
      glm/gtc/quaternion.inl
  7. 28
      glm/gtx/quaternion.hpp
  8. 39
      glm/gtx/quaternion.inl
  9. 21
      test/gtc/gtc_constants.cpp
  10. 36
      test/gtc/gtc_quaternion.cpp
  11. 24
      test/gtx/gtx_quaternion.cpp

@ -38,7 +38,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'pow' only accept floating-point input");
return ::std::pow(x, y);
return genType(::std::pow(x, y));
}
VECTORIZE_VEC_VEC(pow)
@ -52,7 +52,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'exp' only accept floating-point input");
return ::std::exp(x);
return genType(::std::exp(x));
}
VECTORIZE_VEC(exp)
@ -66,7 +66,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'log' only accept floating-point input");
return ::std::log(x);
return genType(::std::log(x));
}
VECTORIZE_VEC(log)
@ -80,7 +80,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'exp2' only accept floating-point input");
return ::std::exp(genType(0.69314718055994530941723212145818) * x);
return genType(::std::exp(genType(0.69314718055994530941723212145818) * x));
}
VECTORIZE_VEC(exp2)

@ -67,7 +67,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sin' only accept floating-point input");
return ::std::sin(angle);
return genType(::std::sin(angle));
}
VECTORIZE_VEC(sin)
@ -78,7 +78,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'cos' only accept floating-point input");
return ::std::cos(angle);
return genType(::std::cos(angle));
}
VECTORIZE_VEC(cos)
@ -92,7 +92,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'tan' only accept floating-point input");
return ::std::tan(angle);
return genType(::std::tan(angle));
}
VECTORIZE_VEC(tan)
@ -106,7 +106,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'asin' only accept floating-point input");
return ::std::asin(x);
return genType(::std::asin(x));
}
VECTORIZE_VEC(asin)
@ -120,7 +120,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'acos' only accept floating-point input");
return ::std::acos(x);
return genType(::std::acos(x));
}
VECTORIZE_VEC(acos)
@ -135,7 +135,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atan' only accept floating-point input");
return ::std::atan2(y, x);
return genType(::std::atan2(y, x));
}
VECTORIZE_VEC_VEC(atan)
@ -148,7 +148,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'atan' only accept floating-point input");
return ::std::atan(x);
return genType(::std::atan(x));
}
VECTORIZE_VEC(atan)
@ -162,7 +162,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'sinh' only accept floating-point input");
return std::sinh(angle);
return genType(std::sinh(angle));
}
VECTORIZE_VEC(sinh)
@ -176,7 +176,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'cosh' only accept floating-point input");
return std::cosh(angle);
return genType(std::cosh(angle));
}
VECTORIZE_VEC(cosh)
@ -190,7 +190,7 @@ namespace glm
{
GLM_STATIC_ASSERT(detail::type<genType>::is_float, "'tanh' only accept floating-point input");
return std::tanh(angle);
return genType(std::tanh(angle));
}
VECTORIZE_VEC(tanh)

@ -50,8 +50,9 @@ namespace detail
GLM_FUNC_DECL explicit half(U const & s);
// Cast
template <typename U>
GLM_FUNC_DECL operator U() const;
//template <typename U>
//GLM_FUNC_DECL operator U() const;
GLM_FUNC_DECL operator float() const;
// Unary updatable operators
GLM_FUNC_DECL half& operator= (half const & s);

@ -266,12 +266,18 @@ namespace detail
GLM_FUNC_QUALIFIER half::half(U const & s) :
data(toFloat16(float(s)))
{}
/*
template <typename U>
GLM_FUNC_QUALIFIER half::operator U() const
{
return static_cast<U>(toFloat32(this->data));
}
*/
GLM_FUNC_QUALIFIER half::operator float() const
{
return toFloat32(this->data);
}
// Unary updatable operators
GLM_FUNC_QUALIFIER half& half::operator= (half const & s)

@ -212,6 +212,27 @@ namespace detail
detail::tvec3<T> eulerAngles(
detail::tquat<T> const & x);
/// Returns roll value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
///
/// @see gtx_quaternion
template <typename valType>
valType roll(
detail::tquat<valType> const & x);
/// Returns pitch value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
///
/// @see gtx_quaternion
template <typename valType>
valType pitch(
detail::tquat<valType> const & x);
/// Returns yaw value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
///
/// @see gtx_quaternion
template <typename valType>
valType yaw(
detail::tquat<valType> const & x);
/// Converts a quaternion to a 3 * 3 matrix.
///
/// @see gtc_quaternion

@ -513,6 +513,45 @@ namespace detail
return detail::tvec3<T>(pitch(x), yaw(x), roll(x));
}
template <typename valType>
GLM_FUNC_QUALIFIER valType roll
(
detail::tquat<valType> const & q
)
{
#ifdef GLM_FORCE_RADIANS
return valType(atan2(valType(2) * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z));
#else
return glm::degrees(atan(valType(2) * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z));
#endif
}
template <typename valType>
GLM_FUNC_QUALIFIER valType pitch
(
detail::tquat<valType> const & q
)
{
#ifdef GLM_FORCE_RADIANS
return valType(atan2(valType(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
#else
return glm::degrees(atan(valType(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
#endif
}
template <typename valType>
GLM_FUNC_QUALIFIER valType yaw
(
detail::tquat<valType> const & q
)
{
#ifdef GLM_FORCE_RADIANS
return asin(valType(-2) * (q.x * q.z - q.w * q.y));
#else
return glm::degrees(asin(valType(-2) * (q.x * q.z - q.w * q.y)));
#endif
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat3x3<T> mat3_cast
(

@ -142,34 +142,6 @@ namespace glm
valType extractRealComponent(
detail::tquat<valType> const & q);
/// Returns roll value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
///
/// @see gtx_quaternion
template <typename valType>
valType roll(
detail::tquat<valType> const & x);
/// Returns pitch value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
///
/// @see gtx_quaternion
template <typename valType>
valType pitch(
detail::tquat<valType> const & x);
/// Returns yaw value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
///
/// @see gtx_quaternion
template <typename valType>
valType yaw(
detail::tquat<valType> const & x);
/// Returns euler angles, yitch as x, yaw as y, roll as z.
///
/// @see gtx_quaternion
template <typename valType>
detail::tvec3<valType> eulerAngles(
detail::tquat<valType> const & x);
/// Converts a quaternion to a 3 * 3 matrix.
///
/// @see gtx_quaternion

@ -154,45 +154,6 @@ namespace glm
return -sqrt(w);
}
template <typename valType>
GLM_FUNC_QUALIFIER valType roll
(
detail::tquat<valType> const & q
)
{
#ifdef GLM_FORCE_RADIANS
return atan2(valType(2) * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z);
#else
return glm::degrees(atan2(valType(2) * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z));
#endif
}
template <typename valType>
GLM_FUNC_QUALIFIER valType pitch
(
detail::tquat<valType> const & q
)
{
#ifdef GLM_FORCE_RADIANS
return atan2(valType(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z);
#else
return glm::degrees(atan2(valType(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z));
#endif
}
template <typename valType>
GLM_FUNC_QUALIFIER valType yaw
(
detail::tquat<valType> const & q
)
{
#ifdef GLM_FORCE_RADIANS
return asin(valType(-2) * (q.x * q.z - q.w * q.y));
#else
return glm::degrees(asin(valType(-2) * (q.x * q.z - q.w * q.y)));
#endif
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tquat<T> shortMix
(

@ -2,7 +2,7 @@
// OpenGL Mathematics Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2012-09-19
// Updated : 2012-09-19
// Updated : 2012-12-13
// Licence : This source is under MIT licence
// File : test/gtc/constants.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -10,6 +10,25 @@
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>
int test_epsilon()
{
int Error(0);
{
glm::half Test = glm::epsilon<glm::half>();
}
{
float Test = glm::epsilon<float>();
}
{
double Test = glm::epsilon<double>();
}
return Error;
}
int main()
{
int Error(0);

@ -89,7 +89,7 @@ int test_quat_precision()
int test_quat_normalize()
{
int Error = 0;
int Error(0);
{
glm::quat Q = glm::angleAxis(45.0f, glm::vec3(0, 0, 1));
@ -113,6 +113,37 @@ int test_quat_normalize()
return Error;
}
int test_quat_euler()
{
int Error(0);
{
glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
float Roll = glm::roll(q);
float Pitch = glm::pitch(q);
float Yaw = glm::yaw(q);
glm::vec3 Angles = glm::eulerAngles(q);
}
{
glm::dquat q(1.0f, 0.0f, 0.0f, 1.0f);
double Roll = glm::roll(q);
double Pitch = glm::pitch(q);
double Yaw = glm::yaw(q);
glm::dvec3 Angles = glm::eulerAngles(q);
}
{
glm::hquat q(glm::half(1.0f), glm::half(0.0f), glm::half(0.0f), glm::half(1.0f));
glm::half Roll = glm::roll(q);
glm::half Pitch = glm::pitch(q);
glm::half Yaw = glm::yaw(q);
glm::hvec3 Angles = glm::eulerAngles(q);
}
return Error;
}
int test_quat_type()
{
glm::quat A;
@ -123,7 +154,7 @@ int test_quat_type()
int main()
{
int Error = 0;
int Error(0);
Error += test_quat_precision();
Error += test_quat_type();
@ -131,6 +162,7 @@ int main()
Error += test_quat_angleAxis();
Error += test_quat_mix();
Error += test_quat_normalize();
Error += test_quat_euler();
return Error;
}

@ -30,7 +30,7 @@ int test_quat_fastMix()
int test_quat_shortMix()
{
int Error = 0;
int Error(0);
glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1));
glm::quat B = glm::angleAxis(90.0f, glm::vec3(0, 0, 1));
@ -45,6 +45,28 @@ int test_quat_shortMix()
return Error;
}
int test_orientation()
{
int Error(0);
{
glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
float p = glm::roll(q);
}
{
glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
float p = glm::pitch(q);
}
{
glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
float p = glm::yaw(q);
}
return Error;
}
int main()
{
int Error = 0;

Loading…
Cancel
Save