elroy

10-04-2000, 09:49 PM

I was having a problem with manipulation matrices in GL that I was hoping someone could help me with.

I have a 3D engine, and I used to move the camera via the orbit method, that is rotating it around the origin of the world.

I decided to play around some and move the camera more like a fly through, similar to a flight simulator, but I wasn't able to get the behavior I want.

I want to have all delta's to rotation apply to the current camera view orienation. That is I want forward motion to be in the direction of the camera as well as have the delta rotations apply to the camera orientation. So I can look up(rotation around camera x-axis) move forward, look to the left and move that direction, rotate the camera around it's z axis etc.

Do do this I intitialize the matrix with gluLookat, grab the matrix and then do the following. (Currently I only include the rotation around the x and y axis...

// Get the current matrix

matrix2 = m_engine_state->GetMatrix();

// now do delta stuff..

glLoadIdentity();

glRotatef(m_engine_state->rotx*180/M_PI, 1, 0, 0);glRotatef(m_engine_state->roty*180/M_PI, 0, 1, 0);

glTranslatef(0,0, m_engine_state->transz);

glMultMatrixf(matrix);

// save current state for next time through

glGetFloatv(GL_MODELVIEW_MATRIX, (float *)matrix);

This doesn't quit work, it seems the rotations are always around the origin of the world not the camera. So I figured, I have the order wrong, so I changed things around, Loaded matrix, then performed the rotations and translation, this actually was worse, I ended up not moving in the direction I was facing,

In the other way I did the following

glLoadMatrixf(matrix)

// then do rotations and translation

Then saved the current matrix for next time.

I assume I'm doing something wrong, any ideas.

One thought I had is to use the second method but change the translation to not be in the z direction but calculate the xyz components, but is seems like I should be able to do this easier. I want the following

1) have all rotations relative to the current camera position

2) movement will be in the direction the camera is facing.

Thanks,

I have a 3D engine, and I used to move the camera via the orbit method, that is rotating it around the origin of the world.

I decided to play around some and move the camera more like a fly through, similar to a flight simulator, but I wasn't able to get the behavior I want.

I want to have all delta's to rotation apply to the current camera view orienation. That is I want forward motion to be in the direction of the camera as well as have the delta rotations apply to the camera orientation. So I can look up(rotation around camera x-axis) move forward, look to the left and move that direction, rotate the camera around it's z axis etc.

Do do this I intitialize the matrix with gluLookat, grab the matrix and then do the following. (Currently I only include the rotation around the x and y axis...

// Get the current matrix

matrix2 = m_engine_state->GetMatrix();

// now do delta stuff..

glLoadIdentity();

glRotatef(m_engine_state->rotx*180/M_PI, 1, 0, 0);glRotatef(m_engine_state->roty*180/M_PI, 0, 1, 0);

glTranslatef(0,0, m_engine_state->transz);

glMultMatrixf(matrix);

// save current state for next time through

glGetFloatv(GL_MODELVIEW_MATRIX, (float *)matrix);

This doesn't quit work, it seems the rotations are always around the origin of the world not the camera. So I figured, I have the order wrong, so I changed things around, Loaded matrix, then performed the rotations and translation, this actually was worse, I ended up not moving in the direction I was facing,

In the other way I did the following

glLoadMatrixf(matrix)

// then do rotations and translation

Then saved the current matrix for next time.

I assume I'm doing something wrong, any ideas.

One thought I had is to use the second method but change the translation to not be in the z direction but calculate the xyz components, but is seems like I should be able to do this easier. I want the following

1) have all rotations relative to the current camera position

2) movement will be in the direction the camera is facing.

Thanks,