Browse Source

Use FromAxes() in Quaternion::FromLookRotation() to fix problem with negative coordinates. Fixes #388.

Lasse Öörni 11 years ago
parent
commit
ce97cba5c1
1 changed files with 3 additions and 7 deletions
  1. 3 7
      Source/Engine/Math/Quaternion.cpp

+ 3 - 7
Source/Engine/Math/Quaternion.cpp

@@ -148,17 +148,13 @@ void Quaternion::FromRotationMatrix(const Matrix3& matrix)
 bool Quaternion::FromLookRotation(const Vector3& direction, const Vector3& upDirection)
 {
     Vector3 forward = direction.Normalized();
-    Vector3 v = forward.CrossProduct(upDirection).Normalized(); 
+    Vector3 v = forward.CrossProduct(upDirection).Normalized();
     Vector3 up = v.CrossProduct(forward);
     Vector3 right = up.CrossProduct(forward);
 
     Quaternion ret;
-    ret.w_ = sqrtf(1.0f + right.x_ + up.y_ + forward.z_) * 0.5f;
-    float w4Recip = 1.0f / (4.0f * ret.w_);
-    ret.x_ = (up.z_ - forward.y_) * w4Recip;
-    ret.y_ = (forward.x_ - right.z_) * w4Recip;
-    ret.z_ = (right.y_ - up.x_) * w4Recip;
-
+    ret.FromAxes(right, up, forward);
+    
     if (!ret.IsNaN())
     {
         (*this) = ret;