Archived

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

Eber Kain

Rotate Problem

Recommended Posts

Eber Kain    130
I consider myself fluent in OpenGL. But I have hit a problem with a little demo I am working up to show how to do First Person with my GLH library. I define a matrix for the transposed view. m[16]; then i setup a routine to modify the matrix. glLoadMatrix(m); glTranslatef(x,0,speed); glRotatef(pitch,1,0,0); glRotatef(yaw,0,1,0); glGetFloatv(GL_MODELVIEW_MATRIX,m); then the draw code. glLoadIdentity(); glMultMatrix(m); //Draw terrain the problem is that the pitch plane dose not move, so when i turn to the side, and try to look down the screen just spins, cause the pitch plane is focused to my side. It shouldn''t do that when i load the matrix, rotate it, then save it back. the order of the glRotatef()''s makes no difference.

Share this post


Link to post
Share on other sites
Obelix    122
I guess your code should work if you clear the variables but what is wrong with
glLoadIdentity();
glTranslatef(x,0,speed);
glRotatef(pitch,1,0,0);
glRotatef(yaw,0,1,0);
//Draw terrain

Share this post


Link to post
Share on other sites
Eber Kain    130
because speed, x, pitch, and yaw are not describeing the final location of the viewpoint, they are showing how much change has occured some the last update to the view point.


I have another thing im working on that uses this same system to move objects around, but its not working right when i try to use it for the viewpoint, mabey i just need a little more time to think about it.

Share this post


Link to post
Share on other sites
Digicube    122
I suggest you implement something called a "Vector Camera". A Vector Camera has three local coordinates UVN, similar to XYZ. U is a right vector, V is the up vector of your camera, and N is the "Lookat" vector. You can implement this using either glLookAt or my forming a matrix and loading it before you draw anything.

When you want to rotate you apply a rotation matrix (or use quaternions if you''re up to it) to your vectors to "permanently" transform them. So you will be doing incremental changes of degrees instead of glRotate''s change once then reset.

Just to go www.google.com and search for Vector Camera''s and you can find more info about it. Once you learn it, it''s very handy especially when you don''t have API''s to help you rotate.

Share this post


Link to post
Share on other sites