glRotate to simulate gluLookAt...and more

I have just switched my method of storing orientations from euler angles to a right vector, up vector, and forward vector (any one of them can actually be computed by taking the cross product of the other two, but I store all three anyway). The idea is that these three vectors make up the object or camera’s local axes.

I have a matrix class which can operate on my point or vector class. It can make roll,pitch and yaw matrices, and also matrices from quaternions.

All of my world updates (objects moving around) are done independent of the gl matrices. The gl matrices are used for doing the view transformation and transformations of objects from local to world coordinates.

When I update my world, I add the velocity to the position, and rotate the object or camera’s orientation vectors by a rotation velocity (again, this is done without the gl matrices). I have verified that my orientation vectors are being rotated properly by using GL_LINES to draw them. (note, when verifying this, I comment out all calls to glRotate. The orientation vectors are rotated without gl matrices, then they SHOULD be used to make a call to glRotate to rotate all vertices when drawing)

The problem is, now that I have the up vector, right vector, and forward vector, I dont know how to call glRotate to rotate the object or camera. I have tried many different methods (remember, i started out with euler angles). I imagine doing this is pretty similar to what gluLookAt does. I dont want to use gluLookAt though, and I’m not sure if that would work for rotating objects as well as cameras. So, can someone offer some help with how to call glRotate to work with the up, right, and forward vectors that I have? (note: only two of the vectors should be needed for the view transformation: the other is needed to ensure proper rotations based on velocities during the world update)

I found the answer to my question, and I’ll post it, in case it might help anyone else. The answer is, that if you have the 3 orientation vectors, you simply make a matrix with each vector being a row. Then just use glMultMatrix, and skip all calls to glRotate and gluLookAt!

I am working with nearly the same basic idea. But for my camera i do things a little diffent to use gluLookAt. For my objects i store a matrix which i just load/multiply before drawing the object so there is no need for glRotate calls.
Perhaps you want to take a look at glLoadMatrix and glMultMatrix.

And of course wait what the real advanced people say, because according to my skills i belong to the beginners forum.

Hope it helped a bit.

Hi

this is right, there are also some other “tricks”.
When you store your matrix as a array of float[16](the matrix is stored in columns first order), the matrix values have following meaning

[xx yx zx posx ]
[xy yy zy posy ]
[xz yz zz posz ]
[0 0 0 1 ]

to convert from (row,col) to the index into the float[16] you can use
(row,col)->index= row*4+col

where xx…xz is the vector of the x axis
where yx…yz is the vector of the y axis
where zx…zz is the vector of the z axis
where posx…posz is the position of the new coordinate system in relation to the last (before multmatrix) so you can move and orient your objects with one single multmatrix.

When you store your matrix as float[4][4], it is stored int row first order and you have to transpose it before you use it using multmatrix. (or you the GL_ARB_transposed_matrix extension)

Bye
ScottManDeath