add, sub, mul and div vec4 for specialization

This commit is contained in:
Christophe Riccio 2016-05-23 21:13:57 +02:00
parent 0e780a5efd
commit 276505f409

View File

@ -41,6 +41,33 @@ namespace detail
return tvec4<T, P>(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); return tvec4<T, P>(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
} }
}; };
template <typename T, precision P>
struct compute_vec4_sub
{
static tvec4<T, P> call(tvec4<T, P> const & a, tvec4<T, P> const & b)
{
return tvec4<T, P>(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
}
};
template <typename T, precision P>
struct compute_vec4_mul
{
static tvec4<T, P> call(tvec4<T, P> const & a, tvec4<T, P> const & b)
{
return tvec4<T, P>(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
}
};
template <typename T, precision P>
struct compute_vec4_div
{
static tvec4<T, P> call(tvec4<T, P> const & a, tvec4<T, P> const & b)
{
return tvec4<T, P>(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
}
};
}//namespace detail }//namespace detail
// -- Implicit basic constructors -- // -- Implicit basic constructors --
@ -264,131 +291,84 @@ namespace detail
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator+=(U scalar) GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator+=(U scalar)
{ {
this->x += static_cast<T>(scalar); return (*this = detail::compute_vec4_add<T, P>::call(*this, tvec4<T, P>(scalar)));
this->y += static_cast<T>(scalar);
this->z += static_cast<T>(scalar);
this->w += static_cast<T>(scalar);
return *this;
} }
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator+=(tvec1<U, P> const & v) GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator+=(tvec1<U, P> const & v)
{ {
T const scalar = static_cast<T>(v.x); return (*this = detail::compute_vec4_add<T, P>::call(*this, tvec4<T, P>(v.x)));
this->x += scalar;
this->y += scalar;
this->z += scalar;
this->w += scalar;
return *this;
} }
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator+=(tvec4<U, P> const & v) GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator+=(tvec4<U, P> const & v)
{ {
*this = detail::compute_vec4_add<T, P>::call(*this, tvec4<T, P>(v)); return (*this = detail::compute_vec4_add<T, P>::call(*this, tvec4<T, P>(v)));
return *this;
} }
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator-=(U scalar) GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator-=(U scalar)
{ {
this->x -= static_cast<T>(scalar); return (*this = detail::compute_vec4_sub<T, P>::call(*this, tvec4<T, P>(scalar)));
this->y -= static_cast<T>(scalar);
this->z -= static_cast<T>(scalar);
this->w -= static_cast<T>(scalar);
return *this;
} }
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator-=(tvec1<U, P> const & v) GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator-=(tvec1<U, P> const & v)
{ {
T const scalar = static_cast<T>(v.x); return (*this = detail::compute_vec4_sub<T, P>::call(*this, tvec4<T, P>(v.x)));
this->x -= scalar;
this->y -= scalar;
this->z -= scalar;
this->w -= scalar;
return *this;
} }
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator-=(tvec4<U, P> const & v) GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator-=(tvec4<U, P> const & v)
{ {
this->x -= static_cast<T>(v.x); return (*this = detail::compute_vec4_sub<T, P>::call(*this, tvec4<T, P>(v)));
this->y -= static_cast<T>(v.y);
this->z -= static_cast<T>(v.z);
this->w -= static_cast<T>(v.w);
return *this;
} }
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator*=(U v) GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator*=(U scalar)
{ {
this->x *= static_cast<T>(v); return (*this = detail::compute_vec4_mul<T, P>::call(*this, tvec4<T, P>(scalar)));
this->y *= static_cast<T>(v);
this->z *= static_cast<T>(v);
this->w *= static_cast<T>(v);
return *this;
} }
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator*=(tvec1<U, P> const & v) GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator*=(tvec1<U, P> const & v)
{ {
this->x *= static_cast<T>(v.x); return (*this = detail::compute_vec4_mul<T, P>::call(*this, tvec4<T, P>(v.x)));
this->y *= static_cast<T>(v.x);
this->z *= static_cast<T>(v.x);
this->w *= static_cast<T>(v.x);
return *this;
} }
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator*=(tvec4<U, P> const & v) GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator*=(tvec4<U, P> const & v)
{ {
this->x *= static_cast<T>(v.x); return (*this = detail::compute_vec4_mul<T, P>::call(*this, tvec4<T, P>(v)));
this->y *= static_cast<T>(v.y);
this->z *= static_cast<T>(v.z);
this->w *= static_cast<T>(v.w);
return *this;
} }
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator/=(U v) GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator/=(U scalar)
{ {
this->x /= static_cast<T>(v); return (*this = detail::compute_vec4_div<T, P>::call(*this, tvec4<T, P>(scalar)));
this->y /= static_cast<T>(v);
this->z /= static_cast<T>(v);
this->w /= static_cast<T>(v);
return *this;
} }
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator/=(tvec1<U, P> const & v) GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator/=(tvec1<U, P> const & v)
{ {
this->x /= static_cast<T>(v.x); return (*this = detail::compute_vec4_div<T, P>::call(*this, tvec4<T, P>(v.x)));
this->y /= static_cast<T>(v.x);
this->z /= static_cast<T>(v.x);
this->w /= static_cast<T>(v.x);
return *this;
} }
template <typename T, precision P> template <typename T, precision P>
template <typename U> template <typename U>
GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator/=(tvec4<U, P> const & v) GLM_FUNC_QUALIFIER tvec4<T, P> & tvec4<T, P>::operator/=(tvec4<U, P> const & v)
{ {
this->x /= static_cast<T>(v.x); return (*this = detail::compute_vec4_div<T, P>::call(*this, tvec4<T, P>(v)));
this->y /= static_cast<T>(v.y);
this->z /= static_cast<T>(v.z);
this->w /= static_cast<T>(v.w);
return *this;
} }
// -- Increment and decrement operators -- // -- Increment and decrement operators --