rotation with quaternions

Started by
9 comments, last by Deebo 19 years, 4 months ago
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?
Advertisement
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'.
[size="1"]
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!
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.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Check out this tutorial

Edit: fixed linky
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.
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?
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.
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 );
Thanks alot. Im gonna give that a try and see what happens.

This topic is closed to new replies.

Advertisement