From 276505f40992d4bbacab4ec88a6bf5d5c573eb61 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Mon, 23 May 2016 21:13:57 +0200 Subject: [PATCH] add, sub, mul and div vec4 for specialization --- glm/detail/type_vec4.inl | 102 ++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 61 deletions(-) diff --git a/glm/detail/type_vec4.inl b/glm/detail/type_vec4.inl index 261162a6..cd093916 100644 --- a/glm/detail/type_vec4.inl +++ b/glm/detail/type_vec4.inl @@ -41,6 +41,33 @@ namespace detail return tvec4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); } }; + + template + struct compute_vec4_sub + { + static tvec4 call(tvec4 const & a, tvec4 const & b) + { + return tvec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); + } + }; + + template + struct compute_vec4_mul + { + static tvec4 call(tvec4 const & a, tvec4 const & b) + { + return tvec4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); + } + }; + + template + struct compute_vec4_div + { + static tvec4 call(tvec4 const & a, tvec4 const & b) + { + return tvec4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w); + } + }; }//namespace detail // -- Implicit basic constructors -- @@ -264,131 +291,84 @@ namespace detail template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+=(U scalar) { - this->x += static_cast(scalar); - this->y += static_cast(scalar); - this->z += static_cast(scalar); - this->w += static_cast(scalar); - return *this; + return (*this = detail::compute_vec4_add::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+=(tvec1 const & v) { - T const scalar = static_cast(v.x); - this->x += scalar; - this->y += scalar; - this->z += scalar; - this->w += scalar; - return *this; + return (*this = detail::compute_vec4_add::call(*this, tvec4(v.x))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator+=(tvec4 const & v) { - *this = detail::compute_vec4_add::call(*this, tvec4(v)); - return *this; + return (*this = detail::compute_vec4_add::call(*this, tvec4(v))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator-=(U scalar) { - this->x -= static_cast(scalar); - this->y -= static_cast(scalar); - this->z -= static_cast(scalar); - this->w -= static_cast(scalar); - return *this; + return (*this = detail::compute_vec4_sub::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator-=(tvec1 const & v) { - T const scalar = static_cast(v.x); - this->x -= scalar; - this->y -= scalar; - this->z -= scalar; - this->w -= scalar; - return *this; + return (*this = detail::compute_vec4_sub::call(*this, tvec4(v.x))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator-=(tvec4 const & v) { - this->x -= static_cast(v.x); - this->y -= static_cast(v.y); - this->z -= static_cast(v.z); - this->w -= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_sub::call(*this, tvec4(v))); } template template - GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*=(U v) + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*=(U scalar) { - this->x *= static_cast(v); - this->y *= static_cast(v); - this->z *= static_cast(v); - this->w *= static_cast(v); - return *this; + return (*this = detail::compute_vec4_mul::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*=(tvec1 const & v) { - this->x *= static_cast(v.x); - this->y *= static_cast(v.x); - this->z *= static_cast(v.x); - this->w *= static_cast(v.x); - return *this; + return (*this = detail::compute_vec4_mul::call(*this, tvec4(v.x))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator*=(tvec4 const & v) { - this->x *= static_cast(v.x); - this->y *= static_cast(v.y); - this->z *= static_cast(v.z); - this->w *= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_mul::call(*this, tvec4(v))); } template template - GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/=(U v) + GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/=(U scalar) { - this->x /= static_cast(v); - this->y /= static_cast(v); - this->z /= static_cast(v); - this->w /= static_cast(v); - return *this; + return (*this = detail::compute_vec4_div::call(*this, tvec4(scalar))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/=(tvec1 const & v) { - this->x /= static_cast(v.x); - this->y /= static_cast(v.x); - this->z /= static_cast(v.x); - this->w /= static_cast(v.x); - return *this; + return (*this = detail::compute_vec4_div::call(*this, tvec4(v.x))); } template template GLM_FUNC_QUALIFIER tvec4 & tvec4::operator/=(tvec4 const & v) { - this->x /= static_cast(v.x); - this->y /= static_cast(v.y); - this->z /= static_cast(v.z); - this->w /= static_cast(v.w); - return *this; + return (*this = detail::compute_vec4_div::call(*this, tvec4(v))); } // -- Increment and decrement operators --