Edit: You replied while I was replying JohnBolton. Thanks for the help :) I'll have to look into the matrix inverse, I wonder if doing the quaternion conjugate does the same thing. And I made a note below about the memory leak, I knew someone was going to say that. My quatToMatrix code is different now and it doesn't allocate memory. I have all leaks dumped at the end, so I can see it :) Thanks!
Woo! It works. I am
so glad that I understand how this all works now. Thank you all.
Quote:Original post by jyk
Hey,
I'm off to bed now but am interested in the problem and will look at it tomorrow. If you or someone else hasn't solved it by then, I'll try to post something useful :-)
Thanks man! You've been a great help. Made me think about every little detail about it. Hope we both learned something from this (I know I did!).
Two key things were wrong.
AP said this early on, wish I had paid more attention to it. Wasn't exactly sure what he meant then, but now I know:
" (yaw happens around world y-axis, pitch happens around local x-axis)."
Basically my functions look like this now. Notice the change in the y-axis one, change it around the global one. I was rotating it all weird by doing it around the local one.
void camera::rotateXAxis(float ang) { float *m = quatToMatrix(quatView); quatView = axisAngleToQuat(m[0], m[1], m[2], ang) * quatView;}void camera::rotateYAxis(float ang) { quatView = axisAngleToQuat(0.0f, 1.0f, 0.0f, ang) * quatView;}void camera::rotateZAxis(float ang) { float *m = quatToMatrix(quatView); quatView = axisAngleToQuat(m[8], m[9], m[10], ang) * quatView;}
(a memory leak isn't created here in the real app because quatToMatrix is different)
The other thing, which was my main problem I believe, was that I needed to conjugate the quaternion. I'm guessing this "converts" it to work in the right-handed coordinate system. So my "view" code looks like this now:
void camera::view() { //TODO: don't normalize every frame, do a check to see if floating point error is too big quatView = normalize(quatView); float *mat = quatToMatrix(conjugate(quatView)); glLoadMatrixf(mat);}
This works great. I haven't implemented translation yet but it shouldn't be too difficult. There may be a couple orientation problems when I start to translate too but I should be able to handle it now.