Sign in to follow this  
Deebo

OpenGL rotation with quaternions

Recommended Posts

I get a matrix from the rotation camera and apply it to OpenGL and everything works fine. The thing is that the world rotates instead of the camera. Is there something that I must do to the quaternion before getting its matrix so the the rotation will simulate the rotation of the camera (ex. first person camera) instead of rotating the scene?

Share this post


Link to post
Share on other sites
No offence, but it sounds like you need to read up on how opengl handles transforms, particularly on how there is no camera transform.

Simply put, you don't rotate the camera, you rotate the world. So if you want to rotate the non-existant camera 90deg clockwise around the y axis, you simulate this by rotating the world by 90deg anticlockwise around the y.

It follows that doing the inverse of the rotation stored in the quaternion on the world will make it appear to rotate the 'camera'.

Share this post


Link to post
Share on other sites
No matter how you implement it OpenGL ultimately rotates the objects in the scene.

For example:-
-------------
If you are trying to update the parameter in gluLookAt() to simulate the camera motion, OpenGL generates a View matrix and puts it on the GL_MODELVIEW matrix stack. It then uses this matrix to transform the objects into the view space.

If you want to get the effect of the camera movement you need to apply inverse of the Modeling transform that you usually apply to transform objects.

I hope this helps!

Share this post


Link to post
Share on other sites
The camera translation and then rotation should be the first two transformations you apply to the model-view matrix (or load the camera's affine matrix instead of the identity matrix), then everything should work for you.

Share this post


Link to post
Share on other sites
So if I apply the inverse of the quaternion, I will the the 1st person camera instead of the rotating world? I tried that but got the same results. Mabey I missed something, I will try again and see if it works.

Share this post


Link to post
Share on other sites
I tried using various combinations of the pitch, heading, view, and inverse view quaternions. The only thing I have been able to change which way the scene rotates when I move the mouse. Is there an equation that I must use on the quaternion before converting it to a matrix?

Share this post


Link to post
Share on other sites
Has anyone created a working 1st person camera with quaternion in OpenGL without using the glu* functions? I understand completely how transformations work in OpenGL. What I can't do is figure out how to get the "proper" 1st person camera effect. Take a cube for example. If inside of the cube, I will have the effect I need because I am rotating the cube while inside of it and that gives the proper illusion. But if the camera is outside of the cube, all I see is a rotating cube instead of the cube "moving" across the screen. Any advice will be greatly appreciated. This has been annoying me for days now.

Share this post


Link to post
Share on other sites
i use quaternions for my camera (only when u control the camera like a plane though) for a first person camera though i just use pitch and heading limit

dir.x = cos( orientation.heading ) * cos( orientation.pitch );
dir.y = sin( orientation.pitch );
dir.z = sin( orientation.heading ) * cos( orientation.pitch );

Share this post


Link to post
Share on other sites
Sorry for whining about this camera stuff. Turns out I had it right from the get go. It was my test function that was all messed up. I had just about given up on this so I just loaded a map and was ready to test other stuff, then everything was working perfect. Thanks for the help anyway.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this