Rotate Problem
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.
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
glLoadIdentity();
glTranslatef(x,0,speed);
glRotatef(pitch,1,0,0);
glRotatef(yaw,0,1,0);
//Draw terrain
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement