diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 86f2f05d..b86b2f51 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -65,14 +65,14 @@ namespace detail template GLM_FUNC_QUALIFIER T & tquat::operator[] (length_t i) { - assert(i >= 0 && i < this->length()); + assert(i >= 0 && static_cast(i) < detail::component_count(*this)); return (&x)[i]; } template GLM_FUNC_QUALIFIER T const & tquat::operator[] (length_t i) const { - assert(i >= 0 && i < this->length()); + assert(i >= 0 && static_cast(i) < detail::component_count(*this)); return (&x)[i]; } @@ -94,7 +94,7 @@ namespace detail template template GLM_FUNC_QUALIFIER tquat::tquat(tquat const & q) - : x(q.x), y(q.y), z(q.z), w(q.w) + : x(q.x), y(q.y), z(q.z), w(q.w) {} ////////////////////////////////////// diff --git a/glm/gtx/dual_quaternion.inl b/glm/gtx/dual_quaternion.inl index 5672ec6d..31b2c8d9 100644 --- a/glm/gtx/dual_quaternion.inl +++ b/glm/gtx/dual_quaternion.inl @@ -35,13 +35,13 @@ namespace glm template GLM_FUNC_QUALIFIER GLM_CONSTEXPR size_t tdualquat::size() const { - return 8; + return 2; } #else template GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t tdualquat::length() const { - return 8; + return 2; } #endif @@ -54,16 +54,14 @@ namespace glm {} template - GLM_FUNC_QUALIFIER tdualquat::tdualquat(tdualquat const & d) : - real(d.real), - dual(d.dual) + GLM_FUNC_QUALIFIER tdualquat::tdualquat(tdualquat const & d) + : real(d.real), dual(d.dual) {} template template - GLM_FUNC_QUALIFIER tdualquat::tdualquat(tdualquat const & d) : - real(d.real), - dual(d.dual) + GLM_FUNC_QUALIFIER tdualquat::tdualquat(tdualquat const & d) + : real(d.real), dual(d.dual) {} ////////////////////////////////////// @@ -74,19 +72,13 @@ namespace glm {} template - GLM_FUNC_QUALIFIER tdualquat::tdualquat(tquat const & r) : - real(r), - dual(tquat(0, 0, 0, 0)) + GLM_FUNC_QUALIFIER tdualquat::tdualquat(tquat const & r) + : real(r), dual(tquat(0, 0, 0, 0)) {} template - GLM_FUNC_QUALIFIER tdualquat::tdualquat - ( - tquat const & q, - tvec3 const& p - ) : - real(q), - dual( + GLM_FUNC_QUALIFIER tdualquat::tdualquat(tquat const & q, tvec3 const& p) + : real(q), dual( T(-0.5) * ( p.x*q.x + p.y*q.y + p.z*q.z), T(+0.5) * ( p.x*q.w + p.y*q.z - p.z*q.y), T(+0.5) * (-p.x*q.z + p.y*q.w + p.z*q.x), @@ -94,31 +86,20 @@ namespace glm {} template - GLM_FUNC_QUALIFIER tdualquat::tdualquat - ( - tquat const & r, - tquat const & d - ) : - real(r), - dual(d) + GLM_FUNC_QUALIFIER tdualquat::tdualquat(tquat const & r, tquat const & d) + : real(r), dual(d) {} ////////////////////////////////////////////////////////////// // tdualquat conversions template - GLM_FUNC_QUALIFIER tdualquat::tdualquat - ( - tmat2x4 const & m - ) + GLM_FUNC_QUALIFIER tdualquat::tdualquat(tmat2x4 const & m) { *this = dualquat_cast(m); } template - GLM_FUNC_QUALIFIER tdualquat::tdualquat - ( - tmat3x4 const & m - ) + GLM_FUNC_QUALIFIER tdualquat::tdualquat(tmat3x4 const & m) { *this = dualquat_cast(m); } @@ -127,16 +108,16 @@ namespace glm // tdualquat accesses template - GLM_FUNC_QUALIFIER typename tdualquat::part_type & tdualquat::operator [] (int i) + GLM_FUNC_QUALIFIER typename tdualquat::part_type & tdualquat::operator[](length_t i) { - assert(i >= 0 && i < this->length()); + assert(i >= 0 && static_cast(i) < detail::component_count(*this)); return (&real)[i]; } template - GLM_FUNC_QUALIFIER typename tdualquat::part_type const & tdualquat::operator [] (int i) const + GLM_FUNC_QUALIFIER typename tdualquat::part_type const & tdualquat::operator[](length_t i) const { - assert(i >= 0 && i < this->length()); + assert(i >= 0 && static_cast(i) < detail::component_count(*this)); return (&real)[i]; } @@ -144,10 +125,7 @@ namespace glm // tdualquat operators template - GLM_FUNC_QUALIFIER tdualquat & tdualquat::operator *= - ( - T const & s - ) + GLM_FUNC_QUALIFIER tdualquat & tdualquat::operator*=(T const & s) { this->real *= s; this->dual *= s; @@ -155,10 +133,7 @@ namespace glm } template - GLM_FUNC_QUALIFIER tdualquat & tdualquat::operator /= - ( - T const & s - ) + GLM_FUNC_QUALIFIER tdualquat & tdualquat::operator/=(T const & s) { this->real /= s; this->dual /= s; @@ -169,41 +144,26 @@ namespace glm // tquat external operators template - GLM_FUNC_QUALIFIER tdualquat operator- - ( - tdualquat const & q - ) + GLM_FUNC_QUALIFIER tdualquat operator-(tdualquat const & q) { return tdualquat(-q.real,-q.dual); } template - GLM_FUNC_QUALIFIER tdualquat operator+ - ( - tdualquat const & q, - tdualquat const & p - ) + GLM_FUNC_QUALIFIER tdualquat operator+(tdualquat const & q, tdualquat const & p) { return tdualquat(q.real + p.real,q.dual + p.dual); } template - GLM_FUNC_QUALIFIER tdualquat operator* - ( - tdualquat const & p, - tdualquat const & o - ) + GLM_FUNC_QUALIFIER tdualquat operator*(tdualquat const & p, tdualquat const & o) { return tdualquat(p.real * o.real,p.real * o.dual + p.dual * o.real); } // Transformation template - GLM_FUNC_QUALIFIER tvec3 operator* - ( - tdualquat const & q, - tvec3 const & v - ) + GLM_FUNC_QUALIFIER tvec3 operator*(tdualquat const & q, tvec3 const & v) { tvec3 const real_v3(q.real.x,q.real.y,q.real.z); tvec3 const dual_v3(q.dual.x,q.dual.y,q.dual.z); @@ -211,61 +171,37 @@ namespace glm } template - GLM_FUNC_QUALIFIER tvec3 operator* - ( - tvec3 const & v, - tdualquat const & q - ) + GLM_FUNC_QUALIFIER tvec3 operator*(tvec3 const & v, tdualquat const & q) { return glm::inverse(q) * v; } template - GLM_FUNC_QUALIFIER tvec4 operator* - ( - tdualquat const & q, - tvec4 const & v - ) + GLM_FUNC_QUALIFIER tvec4 operator*(tdualquat const & q, tvec4 const & v) { return tvec4(q * tvec3(v), v.w); } template - GLM_FUNC_QUALIFIER tvec4 operator* - ( - tvec4 const & v, - tdualquat const & q - ) + GLM_FUNC_QUALIFIER tvec4 operator*(tvec4 const & v, tdualquat const & q) { return glm::inverse(q) * v; } template - GLM_FUNC_QUALIFIER tdualquat operator* - ( - tdualquat const & q, - T const & s - ) + GLM_FUNC_QUALIFIER tdualquat operator*(tdualquat const & q, T const & s) { return tdualquat(q.real * s, q.dual * s); } template - GLM_FUNC_QUALIFIER tdualquat operator* - ( - T const & s, - tdualquat const & q - ) + GLM_FUNC_QUALIFIER tdualquat operator*(T const & s, tdualquat const & q) { return q * s; } template - GLM_FUNC_QUALIFIER tdualquat operator/ - ( - tdualquat const & q, - T const & s - ) + GLM_FUNC_QUALIFIER tdualquat operator/(tdualquat const & q, T const & s) { return tdualquat(q.real / s, q.dual / s); } @@ -273,42 +209,26 @@ namespace glm ////////////////////////////////////// // Boolean operators template - GLM_FUNC_QUALIFIER bool operator== - ( - tdualquat const & q1, - tdualquat const & q2 - ) + GLM_FUNC_QUALIFIER bool operator==(tdualquat const & q1, tdualquat const & q2) { return (q1.real == q2.real) && (q1.dual == q2.dual); } template - GLM_FUNC_QUALIFIER bool operator!= - ( - tdualquat const & q1, - tdualquat const & q2 - ) + GLM_FUNC_QUALIFIER bool operator!=(tdualquat const & q1, tdualquat const & q2) { return (q1.real != q2.dual) || (q1.real != q2.dual); } //////////////////////////////////////////////////////// template - GLM_FUNC_QUALIFIER tdualquat normalize - ( - tdualquat const & q - ) + GLM_FUNC_QUALIFIER tdualquat normalize(tdualquat const & q) { return q / length(q.real); } template - GLM_FUNC_QUALIFIER tdualquat lerp - ( - tdualquat const & x, - tdualquat const & y, - T const & a - ) + GLM_FUNC_QUALIFIER tdualquat lerp(tdualquat const & x, tdualquat const & y, T const & a) { // Dual Quaternion Linear blend aka DLB: // Lerp is only defined in [0, 1] @@ -320,10 +240,7 @@ namespace glm } template - GLM_FUNC_QUALIFIER tdualquat inverse - ( - tdualquat const & q - ) + GLM_FUNC_QUALIFIER tdualquat inverse(tdualquat const & q) { const glm::tquat real = conjugate(q.real); const glm::tquat dual = conjugate(q.dual); @@ -331,19 +248,13 @@ namespace glm } template - GLM_FUNC_QUALIFIER tmat2x4 mat2x4_cast - ( - tdualquat const & x - ) + GLM_FUNC_QUALIFIER tmat2x4 mat2x4_cast(tdualquat const & x) { return tmat2x4( x[0].x, x[0].y, x[0].z, x[0].w, x[1].x, x[1].y, x[1].z, x[1].w ); } template - GLM_FUNC_QUALIFIER tmat3x4 mat3x4_cast - ( - tdualquat const & x - ) + GLM_FUNC_QUALIFIER tmat3x4 mat3x4_cast(tdualquat const & x) { tquat r = x.real / length2(x.real); @@ -379,10 +290,7 @@ namespace glm } template - GLM_FUNC_QUALIFIER tdualquat dualquat_cast - ( - tmat2x4 const & x - ) + GLM_FUNC_QUALIFIER tdualquat dualquat_cast(tmat2x4 const & x) { return tdualquat( tquat( x[0].w, x[0].x, x[0].y, x[0].z ), @@ -390,15 +298,12 @@ namespace glm } template - GLM_FUNC_QUALIFIER tdualquat dualquat_cast - ( - tmat3x4 const & x - ) + GLM_FUNC_QUALIFIER tdualquat dualquat_cast(tmat3x4 const & x) { - tquat real; + tquat real(uninitialize); T const trace = x[0].x + x[1].y + x[2].z; - if(trace > T(0)) + if(trace > static_cast(0)) { T const r = sqrt(T(1) + trace); T const invr = static_cast(0.5) / r; @@ -435,12 +340,11 @@ namespace glm real.w = (x[1].x - x[0].y) * invr; } - tquat dual; - dual.x = T(0.5) * ( x[0].w * real.w + x[1].w * real.z - x[2].w * real.y); - dual.y = T(0.5) * (-x[0].w * real.z + x[1].w * real.w + x[2].w * real.x); - dual.z = T(0.5) * ( x[0].w * real.y - x[1].w * real.x + x[2].w * real.w); - dual.w = -T(0.5) * ( x[0].w * real.x + x[1].w * real.y + x[2].w * real.z); + tquat dual(uninitialize); + dual.x = static_cast(0.5) * ( x[0].w * real.w + x[1].w * real.z - x[2].w * real.y); + dual.y = static_cast(0.5) * (-x[0].w * real.z + x[1].w * real.w + x[2].w * real.x); + dual.z = static_cast(0.5) * ( x[0].w * real.y - x[1].w * real.x + x[2].w * real.w); + dual.w = -static_cast(0.5) * ( x[0].w * real.x + x[1].w * real.y + x[2].w * real.z); return tdualquat(real, dual); } - }//namespace glm