From 688a1524f13679c76f5c1f2a32d9d56c99980a8f Mon Sep 17 00:00:00 2001
From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08>
Date: Mon, 21 Jun 2010 09:22:58 +0000
Subject: [PATCH] fix broken *= operator of quat

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2421 5a81b35b-ba03-0410-adc8-b2c5c5119f08
---
 modules/geom/src/quat.cc | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/modules/geom/src/quat.cc b/modules/geom/src/quat.cc
index abfa6c80f..4876ad10e 100644
--- a/modules/geom/src/quat.cc
+++ b/modules/geom/src/quat.cc
@@ -316,11 +316,20 @@ Quat& Quat::operator*=(Real s)
 }
 
 Quat& Quat::operator*=(const Quat& q)
-{
-  w = this->w*q.w - this->x*q.x - this->y*q.y - this->z*q.z;
-  x = this->w*q.x + this->x*q.w + this->y*q.z - this->z*q.y;
-  y = this->w*q.y + this->y*q.w - this->x*q.z + this->z*q.x;
-  z = this->w*q.z + this->z*q.w + this->x*q.y - this->y*q.x;
+{  
+  Vec3 v00 (x,y,z);
+  Vec3 v10 (q.x,q.y,q.z);
+
+  Real w2=w*q.w-Dot(v00,v10);
+  Vec3 v2=Cross(v00,v10);
+  Vec3 v3=v10;  v3 *= w;
+  Vec3 v4=v00;  v4 *= q.w;
+  Vec3 v5=v2+v3+v4;
+  
+  w=w2;
+  x=v5[0];
+  y=v5[1];
+  z=v5[2];
   return *this;
 }
 
@@ -447,6 +456,7 @@ Vec3 Quat::Rotate(const Vec3& vec) const {
   Quat tmp(0.0, vec[0], vec[1], vec[2]);
   Quat conj=Conjugate(*this);
   Quat res=*this*tmp*conj;
+  std::cout << *this << "*" << tmp << "*" << conj << std::endl;
   return Vec3(res.x, res.y, res.z);
 }
 
-- 
GitLab