Quaternion Operator *=

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
GuestBR

Quaternion Operator *=

Post by GuestBR »

Hi
I'm not sure but I think the Multiplication order is wrong in that function:
Shouldn't it be "*this * other" instead of "other * *this" ?

Ciao
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post by Baal Cadar »

Not sure, but don't think so. A = B*C means more or less A is C with rotation B applied. So B*=c -> B = B*C would be B is C with rotation B applied. But you probably want B = C*B, B is B with rotation C applied. Thus the order is correct imho. If I got something wrong here, be sure to call on it.
geewee
Posts: 4
Joined: Sun Jun 18, 2006 7:09 pm

Post by geewee »

I agree with the op, imho it is implemented wrong.

a *= b shoul mean a = a * b and it is implemented as a = b * a

That will not work if you want to add a rotation to another one.

E.g.:
If you want to rotate you object over each axis, you may do something like this:

Code: Select all

// Non-rotation unit quaternion
core::quaternion finalRotation = core::quaternion(0.0, 0.0, 0.0, 1.0);

// Rotations for each axis
core::quaternion xRotation, yRotation, zRotation;

// Calculate the quaternions for each axis
...

// Add all rotations to the final rotation
finalRotation = xRotation * yRotation * zRotation;
If it has to be consistent, you should be able to write it this way in exchange for the last line:

Code: Select all

finalRotation *= xRotation;
finalRotation *= yRotation;
finalRotation *= zRotation;
But you can't, cause the *=-operator ist implemented wrong :)
A = B*C means more or less A is C with rotation B applied.
Where did you get that? It may be true, of course. But I've never heared of it (Which in fact means nothing ;))

Man that operator took me some time...
Saturn
Posts: 418
Joined: Mon Sep 25, 2006 5:58 pm

Post by Saturn »

Baal Cadar is correct with the order. There may be multiple standards of course, but at least this order is what I learned at university and what is most often used in practice. A quaternion is in this context just like a matrix and you also write A = M * B, meaning A is B with transform M applied. I understand that it is sometimes used backwards (;)).
Anyway, you can implement it both ways, it is a question of convention, not of "right" or "wrong".

In your example you can change the order of multiplications and it works the same way. Your arbitrarily assumed order left-to-right, but this is not cast into stone. Matrices are usually* applied right to left.

*usually means what one is used. Others may be used to other conventions.
geewee
Posts: 4
Joined: Sun Jun 18, 2006 7:09 pm

Post by geewee »

In your example you can change the order of multiplications and it works the same way. Your arbitrarily assumed order left-to-right, but this is not cast into stone. Matrices are usually* applied right to left.
No I can't change the order, because quaternion-multiplications are not commutative. Nor are matrix-multiplications.

As I said previously, it is inconsistent. If you are right an matrix-multiplications are calculated from right-to-left, then the *-operator ist implemented wrong.

The implementation of the *=-operator makes no sense (maybe only to me) with the current implementatin of the *-operator:

Code: Select all

q1 *= q2
Is implemented as

Code: Select all

q1 = q2 * q1
In words that means:
Rotate something (q1) by a specific rotation (q2) and store the result in the variable for something (q1) (presuming, that quaternion-multiplications are done from right-to-left).
That would be correct and what I want.
But it does not work. It rotates q2 by q1 and stores the result in q1.
Unfortunately the *-operator for quaternions does not work from right-to-left.
If I write

Code: Select all

q1 = q1 * q2
it works correct.

Well, I got that problem by using the *=-operator in my code. Because of that problem, I made some manual tests with numbers and it turned out, that the rotation is apllied in the wrong direction.

The only other possibility would be, that I messed up my code in several situations (Which is possible, of course ;)).


So long


Edit1: Doe! I think quaternions only work well in right-handed coord-systems. Is it possible, that they have to be transformed to work correctly in a left-handed-system?
If true then my quaternions would have the wrong direction for the rotation. That may exactly look like a wrong implementation of the *= and *-operators :)
Maybe it is just the cross-product for vectors, that is the problem.
Now I'm scared and confused :/
geewee
Posts: 4
Joined: Sun Jun 18, 2006 7:09 pm

Bug/Problem still exists

Post by geewee »

Any ideas left?
Post Reply