Jump to content
  • Advertisement
Sign in to follow this  
Pirosan

Camera rotation

This topic is 4684 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello,i have a matrix from my quaternion class that rotates objects in my scene... i was wondering if i could use the very same matrix to rotate my camera. do i have to change the matrix mode and then load it into the glmatrix? cheers, chris

Share this post


Link to post
Share on other sites
Advertisement
What are you trying to accomplish?
are you asking if, instead of rotating all the objects in the scene
can you rotate just the camera, and get the same results?

If so, then the answer is yes, you can.
However, it is by no means different than the previous solution.
Every vertex you draw to the screen will be multiplaied by the MODELVIEW
matrix - you cant escape that.

Instead of using the matrix your using, you need to compute the inverse
(which i think is the transpose of the MODELVIEW matrix in most cases), and
apply it to the position of your camera. Once you have the position, you can
use gluLookAt() from the new position of the eye.


Share this post


Link to post
Share on other sites
here's the thing. i am using quaternions to effect the rotation of a ship in a simulator... in space there is no up or down, and i can get a vector describing the direction the ship is facing and the position of the ship... but see since the camera has the cameraUp variable, the camera never goes "upside down"... i want to be able to freely apply the quaternion matrix to my camera to make it be oriented in any way i want, right side up or not.

Share this post


Link to post
Share on other sites
Quote:
here's the thing. i am using quaternions to effect the rotation of a ship in a simulator... in space there is no up or down, and i can get a vector describing the direction the ship is facing and the position of the ship... but see since the camera has the cameraUp variable, the camera never goes "upside down"... i want to be able to freely apply the quaternion matrix to my camera to make it be oriented in any way i want, right side up or not.
Which direction is 'up' only matters when using gluLookAt(), and you don't have to use gluLookAt() to set the view matrix.

Let's say 'm' is the rotation matrix derived from your quaternion, and 'pos' is your position vector. The following code should set up your OpenGL view matrix:

float mt[16];
TransposeMatrix(m, mt);
glMatrixMode(GL_MODELVIEW);
glLoadMatrix(mt);
glTranslatef(-pos.x, -pos.y, -pos.z);

There are other ways to do it, but they all amount to basically the same thing.

You may have missed it, but I posted some code to one of your earlier threads that does all the things you're asking for - rotation with no gimbal lock, setting the OpenGL model or camera matrix, keeping track of direction vectors, etc. If you're still having trouble with any of this, you might go back and take a look at it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
jyk,

it was just a matter of getting rid of some horrible camera view code that i had gotten from the tutorial i so blindly followed... all is fixed, your code works beautifully... thank you very much

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!