1. ## Quaternion question

I have recently implemented the quaternion tutorial and everything seemed to be rotating ok until:
I wanted to rotate about the X axis and then on the Z axis. But, when I rotate on the X axis the Z axis changes to being the Y axis and my rotation gets messed up (to compensate I would have to rotate on the Y axis).
I didnt think this was supposed to happen with quaternions? Does anybody know how I can get over this problem as it has been slowly driving me mental. 2. you have probably implemented something incorrectly. post the math stuff and maybe ill compare it with mine 3. ## doh!

ok I am officialy a bit daft, I was going by the tutorial that confuted put up about the quaternions and he either got it wrong or deliberatly put a mistake in so that you would be forced to learn about it.
Either way the order of multiplication was wrong when calculating the total rotation, I swapped them over and it works like a dream.
The order of rotation, for how it is specified is:
totalrot = localrot * totalrot, its actually the other way round!
There are also a couple of mistakes in the matrix for conversion from quaternions to rotation matrix which I was able to correct through the medium of paper books (gasp!). Thanks anyway but I am sorted now, this has been a very useful site . 4. i fixed a problem with a quaternion camera tutorial on gamedev.net, it wasn't that site was it? in that case you could blame me 5. ## Quat? What quat was that?

Rotations in Three Dimensions by Confuted and Silvercord.
I worked through it from start to finish but found a couple of mistakes here and there that I had to work out, but I have to say it did me good its much better when you have to work out problems for yourself rather than being given the answer on a plate. 6. Please point out the errors/ inconsistencies so I can fix them.

Thanks 7. No probs.
There were a couple of mistakes in the matrix first of all, I cant remember specifically so I will post the matrix that I am using, there were some numbers wrong and some +/- signs in the wrong place (I dont know how to put in superscripts btw so I just put (x*x) for x squared etc ). Also I am using openGL so this is all right hand coordinate system and openGL is column major.:

M = 1 - 2*(y*y) - 2*(z*z);
M = (2*x*y) - (2*w*z);
M = (2*x*z) + (2*w*y);
M = 0;

M = (2*x*y) + (2*w*z);
M = 1 - 2*(x*x) - 2*(z*z);
M = (2*y*z) - (2*w*x);
M = 0;

M = (2*x*z) - (2*w*y);
M = (2*y*z) + (2*w*x);
M = 1 - 2*(x*x) - 2*(y*y);
M = 0;

M = 0;
M = 0;
M = 0;
M = 1;

Also I overloaded the * operator like sugested and the actual order became totalrot = totalrot * localrot, but i'm sure that can depend on how you actually perform the multiplication in the first place. 8. I'm not sure what's going on because I compared the tutorial quaternion to matrix, and gametutorials.com's quaternion to matrix, and they're equivalent. I don't exactly know what is going on. I'd like to take a look at your project. I wouldn't be surprised if something is flipped around somewhere and you don't know about it. 9. just for the sake of comparison here's my quaternion code (without unit quaternion optimizations for reasons unexplained so diagonal entries will obviously be different.) Even without the unit optimization i have different signage than your tut Silver.

Code:
```  matrix = w2 + x2 - y2 - z2;
matrix = 2*x*y - 2*w*z;
matrix = 2*x*z + 2*w*y;
matrix = 0;
matrix = 2*x*y + 2*w*z;
matrix = w2 - x2 + y2 - z2;
matrix = 2*y*z - 2*w*x;
matrix = 0;
matrix = 2*x*z - 2*w*y;
matrix = 2*y*z + 2*w*x;
matrix = w2 - x2 - y2 + z2;
matrix = 0;
matrix = 0;
matrix = 0;
matrix = 0;
matrix = w2 + x2 + y2 + z2;``` 10. im actually right about this. mathematics for 3d game programming and computer graphics, first edition, page 72 backs up our tutorial (not technically mine). ours is also the same as gametutorial's code, but the book in my lap suffices. that either means
1) you guys don't actually have working code
2) you've flipped something else around somewhere else to compensate
3) somehow they're equivalent 11. strange.

someone at berkley does it the same way as me and Q too.
http://www.cs.berkeley.edu/~laura/cs...uaternion.html

[light_bulb] perhaps this is why.....
The difference is weather or not you want to simulate the rotation of an object or the rotation of the camera around an object. They are simply negations of each other mathematicaly even though they are conceptually different

ex) rotate an object to the right => the object is rotating to the right OR the camera is rotating to the left around the object. 12. I honestly do not know. weird. 13. ## ??

Thats pretty strange, I got my matrix in the end from 3D Game Engine Design by David H. Eberly. I'm not too shabby at maths, but I can only assume that the matrices we are using (assuming we are all using openGL) must be equivalent. All I know, is that the one I am using works, nothing is flipped and the objects rotate.
I blame Microsoft, what can I say?  14. haha, why not, those commies!

(as I am using windows xp )

good luck, post demos when you get something cool that works. 15. Not strange at all.

p' = qp(q*) OR
p' = (q*)pq depending on your definition of quaternion multiplication. I've seen two different forms, and the result is that quaternion concatenation takes place in opposite order.

Firstly, if multiplication is defined as
Code:
```result.w = w*a.w - x*a.x - y*a.y - z*a.z;
result.x = w*a.x + x*a.w + z*a.y - y*a.z;
result.y = w*a.y + y*a.w + x*a.z - z*a.x;
result.z = w*a.z + z*a.w + y*a.x - x*a.y;```
Then p' = (q*)pq
Else, if it's defined as
Code:
```result.w = a.w*w - a.x*x - a.y*y - a.z*z;
result.x = a.w*x + a.x*w + a.y*z - a.z*y;
result.y = a.w*y - a.x*z + a.y*w + a.z*x;
result.z = a.w*z + a.x*y - a.y*x + a.z*w;```
Then p' = qp(q*) Popular pages Recent additions 