Clean up coding style

This commit is contained in:
Christophe Riccio 2014-10-19 18:15:03 +02:00
parent f2383340cf
commit 790f520488
2 changed files with 49 additions and 145 deletions

View File

@ -65,14 +65,14 @@ namespace detail
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER T & tquat<T, P>::operator[] (length_t i) GLM_FUNC_QUALIFIER T & tquat<T, P>::operator[] (length_t i)
{ {
assert(i >= 0 && i < this->length()); assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
return (&x)[i]; return (&x)[i];
} }
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER T const & tquat<T, P>::operator[] (length_t i) const GLM_FUNC_QUALIFIER T const & tquat<T, P>::operator[] (length_t i) const
{ {
assert(i >= 0 && i < this->length()); assert(i >= 0 && static_cast<detail::component_count_t>(i) < detail::component_count(*this));
return (&x)[i]; return (&x)[i];
} }
@ -94,7 +94,7 @@ namespace detail
template <typename T, precision P> template <typename T, precision P>
template <precision Q> template <precision Q>
GLM_FUNC_QUALIFIER tquat<T, P>::tquat(tquat<T, Q> const & q) GLM_FUNC_QUALIFIER tquat<T, P>::tquat(tquat<T, Q> 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)
{} {}
////////////////////////////////////// //////////////////////////////////////

View File

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