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
Quaternion Operator *=
-
- Posts: 377
- Joined: Fri Oct 28, 2005 10:28 am
- Contact:
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:
If it has to be consistent, you should be able to write it this way in exchange for the last line:
But you can't, cause the *=-operator ist implemented wrong
Man that operator took me some time...
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;
Code: Select all
finalRotation *= xRotation;
finalRotation *= yRotation;
finalRotation *= zRotation;
Where did you get that? It may be true, of course. But I've never heared of it (Which in fact means nothing )A = B*C means more or less A is C with rotation B applied.
Man that operator took me some time...
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.
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.
No I can't change the order, because quaternion-multiplications are not commutative. Nor are matrix-multiplications.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.
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
Code: Select all
q1 = q2 * q1
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
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 :/