quaternion and matrix multiplication is wrong

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
kean
Posts: 2
Joined: Wed Jul 31, 2013 7:13 am

quaternion and matrix multiplication is wrong

Post by kean »

seems that yr quaternion multiplication is wrong. i include the corrected formula

inline quaternion quaternion::operator*(const quaternion& other) const
{
quaternion tmp;
//wrong
//tmp.W = (other.W * W) - (other.X * X) - (other.Y * Y) - (other.Z * Z);
//tmp.X = (other.W * X) + (other.X * W) + (other.Y * Z) - (other.Z * Y);
//tmp.Y = (other.W * Y) + (other.Y * W) + (other.Z * X) - (other.X * Z);
//tmp.Z = (other.W * Z) + (other.Z * W) + (other.X * Y) - (other.Y * X);

//correct
tmp.W = (other.W * W) - (other.X * X) - (other.Y * Y) - (other.Z * Z);
tmp.X = (other.W * X) + (other.X * W) - (other.Y * Z) + (other.Z * Y);
tmp.Y = (other.W * Y) + (other.X * Z) + (other.Y * W) - (other.Z * X);
tmp.Z = (other.W * Z) - (other.X * Y) + (other.Y * X) + (other.Z * W);
return tmp;
}


same goes for yr matrix multiplication, the left matrix should use the row * column of the right matrix
if i want to do a matrix A *= B, it wont work
i have to do A = B*A;
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: quaternion and matrix multiplication is wrong

Post by hendu »

Sounds like you're confused by the row/column-major issue with the matrices? It's correct for doing the other way around, B *= A.
Post Reply