Browse Source

added: quat::op+=(quat) and quat::op*=(quat)

jan p springer 12 years ago
parent
commit
e299af614f
3 changed files with 42 additions and 11 deletions
  1. 2 0
      glm/gtc/quaternion.hpp
  2. 31 11
      glm/gtc/quaternion.inl
  3. 9 0
      test/gtc/gtc_quaternion.cpp

+ 2 - 0
glm/gtc/quaternion.hpp

@@ -106,6 +106,8 @@ namespace detail
 		GLM_FUNC_DECL T const & operator[](int i) const;
 		GLM_FUNC_DECL T const & operator[](int i) const;
 
 
 		// Operators
 		// Operators
+    GLM_FUNC_DECL tquat<T, P> & operator+=(tquat<T, P> const & q);
+    GLM_FUNC_DECL tquat<T, P> & operator*=(tquat<T, P> const & q);
 		GLM_FUNC_DECL tquat<T, P> & operator*=(T const & s);
 		GLM_FUNC_DECL tquat<T, P> & operator*=(T const & s);
 		GLM_FUNC_DECL tquat<T, P> & operator/=(T const & s);
 		GLM_FUNC_DECL tquat<T, P> & operator/=(T const & s);
 	};
 	};

+ 31 - 11
glm/gtc/quaternion.inl

@@ -182,6 +182,34 @@ namespace detail
 	//////////////////////////////////////////////////////////////
 	//////////////////////////////////////////////////////////////
 	// tquat<valType> operators
 	// tquat<valType> operators
 
 
+  template <typename T, precision P>
+  GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator +=
+  (
+   tquat<T, P> const & q
+  )
+  {
+    this->w += q.w;
+		this->x += q.x;
+		this->y += q.y;
+		this->z += q.z;
+		return *this;
+  }
+
+  template <typename T, precision P>
+  GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator *=
+  (
+   tquat<T, P> const & q
+  )
+  {
+    tquat<T, P> const p(*this);
+    
+    this->w = p.w * q.w - p.x * q.x - p.y * q.y - p.z * q.z;
+		this->x = p.w * q.x + p.x * q.w + p.y * q.z - p.z * q.y;
+		this->y = p.w * q.y + p.y * q.w + p.z * q.x - p.x * q.z;
+		this->z = p.w * q.z + p.z * q.w + p.x * q.y - p.y * q.x;
+		return *this;
+  }
+    
 	template <typename T, precision P> 
 	template <typename T, precision P> 
 	GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator *=
 	GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator *=
 	(
 	(
@@ -194,7 +222,7 @@ namespace detail
 		this->z *= s;
 		this->z *= s;
 		return *this;
 		return *this;
 	}
 	}
-
+    
 	template <typename T, precision P> 
 	template <typename T, precision P> 
 	GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator /=
 	GLM_FUNC_QUALIFIER tquat<T, P> & tquat<T, P>::operator /=
 	(
 	(
@@ -227,11 +255,7 @@ namespace detail
 		detail::tquat<T, P> const & p
 		detail::tquat<T, P> const & p
 	)
 	)
 	{
 	{
-		return detail::tquat<T, P>(
-			q.w + p.w,
-			q.x + p.x,
-			q.y + p.y,
-			q.z + p.z);
+		return detail::tquat<T, P>(q) += p;
 	}
 	}
 
 
 	template <typename T, precision P>
 	template <typename T, precision P>
@@ -241,11 +265,7 @@ namespace detail
 		detail::tquat<T, P> const & p
 		detail::tquat<T, P> const & p
 	)
 	)
 	{
 	{
-		return detail::tquat<T, P>(
-			q.w * p.w - q.x * p.x - q.y * p.y - q.z * p.z,
-			q.w * p.x + q.x * p.w + q.y * p.z - q.z * p.y,
-			q.w * p.y + q.y * p.w + q.z * p.x - q.x * p.z,
-			q.w * p.z + q.z * p.w + q.x * p.y - q.y * p.x);
+		return detail::tquat<T, P>(q) *= p;
 	}
 	}
 
 
 	// Transformation
 	// Transformation

+ 9 - 0
test/gtc/gtc_quaternion.cpp

@@ -210,6 +210,15 @@ int test_quat_mul()
 	glm::quat temp5 = glm::normalize(temp1 * temp2);
 	glm::quat temp5 = glm::normalize(temp1 * temp2);
 	glm::vec3 temp6 = temp5 * glm::vec3(0.0, 1.0, 0.0) * glm::inverse(temp5);
 	glm::vec3 temp6 = temp5 * glm::vec3(0.0, 1.0, 0.0) * glm::inverse(temp5);
 
 
+  {
+    glm::quat temp7;
+
+    temp7 *= temp5;
+    temp7 *= glm::inverse(temp5);
+
+    Error += temp7 != glm::quat();
+  }
+  
 	return Error;
 	return Error;
 }
 }