Archived

This topic is now archived and is closed to further replies.

shaobohou

Quaternion Camera class?

Recommended Posts

I am currently trying to code a Quaternion based Camera class that will offer full 3d movement (like in a space sim) in first and third person. However I am having a strange problem, in first person, if one tries to move the orientation of the camera (say using the mouse) by making circular motion on the screen then the camera startx to slowly rotate the around the -z axis and will continue to do so if the winding of the motion is consistent. Reverse the winding and you will rotate the otherway!. I have already the mathematics of my Quaternion class and can't find any problems and it works in all its other used. In fact, nothing I change seems to affect it at all. Please help me. Just because it is not nice, doesn''t mean it is not miraculous. [edited by - shaobohou on October 24, 2003 8:01:42 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You mean that the rotation continues even after the mouse is not moving? Assuming that you are setting and resetting the variables correctly could it perhaps be the mouse input itself. Have you checked the input values?

I dont think its the quaternions.

Share this post


Link to post
Share on other sites
I''m not shure, but I thinck it is normal using quartinions. There are space games in first person that does the same!
Now, if you don''t like thar efect and want to make cameras like in Quake freecams, use trigonometry! It''s easy to do. You use 2 angles, alpha and beta, being the alpha the horizontal and beta the vertical. Then, you aply the sphere formula to calculate the target:
being the y the up vector
t.x = p.x + cos(alpha)*cos(beta)
t.y = p.y + sin(beta)
t.z = p.z + sin(alpha)*cos(beta)
Now, you must be aware of one thing, beta must be -pi/2 > beta > pi/2...! And, if beta is pi/2 or -pi/2, every thing gones. If it is greater, comands will switch!

Share this post


Link to post
Share on other sites
I don't have an up vector as such, as I get axis and angle from the quaternion and use glRotatef, I never use glLookAt. I think it is the camera been turned upside down, i got the printout of the the value of the camera quaternion and it seems the x,y,z stays roughtly the same but the w value which evetually translate into the angle of rotation keeps on increasing until it reaches 360 degrees then it go back do the same at 0 degrees.

The thing is I am sure you can use quaternion and not have this effect, as i seems to remember a nehe tutorial from last year that used quaternion for a space sim like navigation and I don't remember it having this problem, unfortunately i can no longer find it on nehe's website

I am familiar with the polar coordinate system that 1st person shooter uses, but i would like to get this one working in similar ways, isn't there someway around it?

Also could anyone give an example of a first person space game that does the same, I'd like to try it out.

[edited by - shaobohou on October 27, 2003 9:33:25 AM]

Share this post


Link to post
Share on other sites
I had the same problem... When I rotated it on the x- and y-axis, it started rotating on the z-axis as well... But I think it has to do with quaternions, and that a single quaternion has several equivalent euler angles, or axis-angle coordinates.

Share this post


Link to post
Share on other sites