Quaternions from HELL
Hi everyone..
I am trying (and trying, and trying) to get rotations (and velocity in the direction of camera orientation) working using Quaternions.
I have looked at Nehe's and Vic's Quat examples, but I need my camera to be able to "roll" around the Z axis as well as rotate around the X and Y axes. I am developing a 3D space combat type game so I need to have full freedom of movement including roll.
At any point in space, I would like to be able to change my heading (rotate around Y axis), change my "pitch" (or yaw, or whatever you wanna call it, meaning look up or down), and (very importantly) "roll" around the Z axis. Also, if I apply thrust in the direction I am pointing, I want to move forward. (Oh Lord please let it move forward.) As you might be able to tell, I have been spending a lot of time on this and I can't seem to get it right.
Any help would be greatly appreciated.
There can be only one.
It's possible that the overall design of your camera class is causing you as many problems as quaternions are. I would think of the camera as 3 unit vectors -right, up, and forward vectors (although you only really need the forward and the right, because the top is just a cross-product of the other two).
In your camera class, include functions like:
rotAroundForwardVec(float angle), rotAroundRightVec(float angle), and rotAroundUpVec(float angle).
Inside those functions, convert your rotation into a quaternion using the angle and the vector you are rotating around (if your quaternion class doesn't have a function that does this, you should make one), and use it to rotate the camera's directional vectors (your quaternion class should be able to rotate vectors as well).
Now when you need to move your camera forward, simply move it along your forward vector
ex: cameraPos +=(cameraForward *cameraSpeed);
You could accomplish moving vertically and strafing using the same technique.
If you need to take a look at a quaternion class, to verify that your code/math is correct, I know of two good places to look: Magic-Software (look at the WmlQuaternion files) and the quaternion code inside the Ogre engine (which I believe is adapted from the Magic-Software code).
Anyway, I hope that helped. Good luck -don't give up!
In your camera class, include functions like:
rotAroundForwardVec(float angle), rotAroundRightVec(float angle), and rotAroundUpVec(float angle).
Inside those functions, convert your rotation into a quaternion using the angle and the vector you are rotating around (if your quaternion class doesn't have a function that does this, you should make one), and use it to rotate the camera's directional vectors (your quaternion class should be able to rotate vectors as well).
Now when you need to move your camera forward, simply move it along your forward vector
ex: cameraPos +=(cameraForward *cameraSpeed);
You could accomplish moving vertically and strafing using the same technique.
If you need to take a look at a quaternion class, to verify that your code/math is correct, I know of two good places to look: Magic-Software (look at the WmlQuaternion files) and the quaternion code inside the Ogre engine (which I believe is adapted from the Magic-Software code).
Anyway, I hope that helped. Good luck -don't give up!
In the articles section on math, there's a Matrix & Quatnerion FAQ. That's more then you'll need to know to get quaternions working how you want.
[s] [/s]
I can see the fnords.
I can see the fnords.
odious; dude; thanks for the replies.
odious wow, thanks for introducing me to that link. that site is very useful.
i'll try your suggestion as well. my quat class only had functions to create from euler angles, or from axis∠, and to normalize itself. i'll add the other stuff you suggested and give it a shot.
on another note; would it be easier to do without using quats?
odious wow, thanks for introducing me to that link. that site is very useful.
i'll try your suggestion as well. my quat class only had functions to create from euler angles, or from axis∠, and to normalize itself. i'll add the other stuff you suggested and give it a shot.
on another note; would it be easier to do without using quats?
There can be only one.
Try using matrices. They are a lot easier and suit your problem more.
Download the program in my sig. It uses the movement you seek. [smile]
And the best thing is that it's extremly simple to boot :)
[Edited by - RipTorn on December 13, 2004 4:38:24 PM]
Download the program in my sig. It uses the movement you seek. [smile]
And the best thing is that it's extremly simple to boot :)
[Edited by - RipTorn on December 13, 2004 4:38:24 PM]
Riptorn,
I looked at your website a couple of days ago; found the link via gamedev as well. I have to say that your website looks really cool (I like the X logo:) and it certainly seems that you know what you're doing. I appreciate your help! Just one thing - I don't see a link to anything in your sig?
Thanks again!
I looked at your website a couple of days ago; found the link via gamedev as well. I have to say that your website looks really cool (I like the X logo:) and it certainly seems that you know what you're doing. I appreciate your help! Just one thing - I don't see a link to anything in your sig?
Thanks again!
There can be only one.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement