Commit 7ad9b812 authored by hybrid's avatar hybrid

Fixed the quaternion problem. However, getMatrix(m) and m=getMatrix do produce...

Fixed the quaternion problem. However, getMatrix(m) and m=getMatrix do produce different values now, and seem to have made this for quite a long time. This needs some more fixing and testing.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1298 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 2a9ae4be
...@@ -138,16 +138,10 @@ inline quaternion::quaternion(const matrix4& mat) ...@@ -138,16 +138,10 @@ inline quaternion::quaternion(const matrix4& mat)
//! equal operator //! equal operator
inline bool quaternion::operator==(const quaternion& other) const inline bool quaternion::operator==(const quaternion& other) const
{ {
if(X != other.X) return ((X == other.X) &&
return false; (Y == other.Y) &&
if(Y != other.Y) (Z == other.Z) &&
return false; (W == other.W));
if(Z != other.Z)
return false;
if(W != other.W)
return false;
return true;
} }
...@@ -254,8 +248,7 @@ inline quaternion& quaternion::operator*=(f32 s) ...@@ -254,8 +248,7 @@ inline quaternion& quaternion::operator*=(f32 s)
//! multiplication operator //! multiplication operator
inline quaternion& quaternion::operator*=(const quaternion& other) inline quaternion& quaternion::operator*=(const quaternion& other)
{ {
*this = other * (*this); return (*this = other * (*this));
return *this;
} }
//! add operator //! add operator
...@@ -269,7 +262,7 @@ inline quaternion quaternion::operator+(const quaternion& b) const ...@@ -269,7 +262,7 @@ inline quaternion quaternion::operator+(const quaternion& b) const
inline matrix4 quaternion::getMatrix() const inline matrix4 quaternion::getMatrix() const
{ {
core::matrix4 m; core::matrix4 m;
getMatrix(m); getMatrix_transposed(m);
return m; return m;
} }
...@@ -381,19 +374,13 @@ inline quaternion& quaternion::set(const core::vector3df& vec) ...@@ -381,19 +374,13 @@ inline quaternion& quaternion::set(const core::vector3df& vec)
//! normalizes the quaternion //! normalizes the quaternion
inline quaternion& quaternion::normalize() inline quaternion& quaternion::normalize()
{ {
f32 n = X*X + Y*Y + Z*Z + W*W; const f32 n = X*X + Y*Y + Z*Z + W*W;
if (n == 1) if (n == 1)
return *this; return *this;
//n = 1.0f / sqrtf(n); //n = 1.0f / sqrtf(n);
n = reciprocal_squareroot ( n ); return (*this *= reciprocal_squareroot ( n ));
X *= n;
Y *= n;
Z *= n;
W *= n;
return *this;
} }
...@@ -530,15 +517,15 @@ inline core::quaternion& quaternion::rotationFromTo(const vector3df& from, const ...@@ -530,15 +517,15 @@ inline core::quaternion& quaternion::rotationFromTo(const vector3df& from, const
v0.normalize(); v0.normalize();
v1.normalize(); v1.normalize();
vector3df c = v0.crossProduct(v1); const f32 d = v0.dotProduct(v1);
f32 d = v0.dotProduct(v1);
if (d >= 1.0f) // If dot == 1, vectors are the same if (d >= 1.0f) // If dot == 1, vectors are the same
{ {
return (*this=quaternion(0,0,0,1)); //IDENTITY; return makeIdentity();
} }
f32 s = sqrtf( (1+d)*2 ); // optimize inv_sqrt
f32 invs = 1 / s; const vector3df c = v0.crossProduct(v1);
const f32 s = sqrtf( (1+d)*2 ); // optimize inv_sqrt
const f32 invs = 1.f / s;
X = c.X * invs; X = c.X * invs;
Y = c.Y * invs; Y = c.Y * invs;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment