Matrix Camera Problems

Started by
4 comments, last by Cacks 18 years, 1 month ago
Hi guys, I have a camera class, with 2 4x4Matrices, 1 to hold it's position and 1 for it's rotation. I am having problems rotating my camera then translating it. It won't translate in the direction it is pointed. My Matrices are made for OpenGL and have indices 0 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15 I must not be getting the correct axes. To get the camera's x-axis I extract values at indices 1,2&3 of the rotation matrix and place them in a vector, then normalise that vector, does that sound correct? The direction my camera is moving seems to be the direction perpendicular to the intended direction. Any ideas why this would be happening? Thanks for any help given!
Reject the basic asumption of civialisation especially the importance of material possessions
Advertisement
Quote:Original post by Cacks
Hi guys,

I have a camera class, with 2 4x4Matrices, 1 to hold it's position and 1 for it's rotation.

I am having problems rotating my camera then translating it. It won't translate in the direction it is pointed.

My Matrices are made for OpenGL and have indices

0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15

I must not be getting the correct axes. To get the camera's x-axis I extract values at indices 1,2&3 of the rotation matrix and place them in a vector, then normalise that vector, does that sound correct?
If the matrix is a proper rotation matrix, the normalization step shouldn't be necessary.

Here's a guess as to the problem. It's true that the basis vectors of the rotation are in the columns of the matrix, that is, x is (0, 1, 2), as you noted. However, in setting up the view matrix the basis vectors at some point have to be transposed, in which case x is (0, 4, 8).

From your post, it's not clear whether you're extracting the basis vectors before or after this transposition takes place. If it's after, that would probably explain the incorrect results. If you're not sure, you might post some of your code. Or, just as an experiment, you could try getting the basis vectors from the rows rather than columns and see if that solves the problem.
Hi jyk,

This is my code for setting up my camera:

void Camera::setCamera(){glMatrixMode(GL_MODELVIEW);	// set modelview matrixglLoadIdentity();		// reset modelview matrixglMultMatrixf(rotationMatrix.matrix);		// Rotate CameraglMultMatrixf(translationMatrix.matrix);	// Translate camera}


Should I transpose my rotation matrix befor passing it into glMultMatrixf?

What is the purpose of transpose?

Thanks
Reject the basic asumption of civialisation especially the importance of material possessions
Quote:Original post by Cacks
Hi jyk,

This is my code for setting up my camera:

*** Source Snippet Removed ***

Should I transpose my rotation matrix befor passing it into glMultMatrixf?

What is the purpose of transpose?

Thanks
The above suggests that your matrices are already inverted at this point (that is, the rotation matrix is transposed and the translation is negated). Since we still don't know how the actual matrices are being constructed, or at what point you're extracting the basis vectors, it's hard to say what's really going on.

If you want to post some more of your code, I'll be happy to take a look at it and see if I can spot anything.
this just popped in my head right now, haven't given it much thought...


Are your [3],[7] and [11] members, simply the negative of the desired position of the camera?
e.g. mat[3] = -cameraPos.x ?

If yes, they should be the negatives of the dot product of the vector position, with the respective camera axis.

E.g. mat[3] = -dot( camera pos, camera X axis )
mat[7] = -dot( camera pos, camera Y axis ), etc...

edit:
I meant the [12],[13] and [14] members.
(The [3],[7],[11] should be zeros(?))
Yeah,

using the transpose rotation matrix makes the camera translate in the direction it is pointing:

void Camera::setCamera(){glMatrixMode(GL_MODELVIEW);	// set modelview matrixglLoadIdentity();		// reset modelview matrixglMultMatrixf(rotationMatrix.transpose().matrix);	glMultMatrixf(translationMatrix.matrix);	// Translate camera}


Tyk, when you said:

Quote:
The above suggests that your matrices are already inverted at this point (that is, the rotation matrix is transposed and the translation is negated)


What does that mean?

Should I also be using the transpose of my translation matrix? I am having to negate my translation values at the minute?

Thanks for the help!
Reject the basic asumption of civialisation especially the importance of material possessions

This topic is closed to new replies.

Advertisement