Sign in to follow this  
Cacks

Camera matrix rotation

Recommended Posts

Cacks    179
Hi guys, I use a matrix to represent my cameras rotation. Some1 suggested that in order to get it working correctly I needed to use the transpose of my cameras rotation matrix. It works using the transpose, but why does it work? I don't need to use the transpose for any of my other transformations? Thanks for any info given.

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by Cacks
I use a matrix to represent my cameras rotation. Some1 suggested that in order to get it working correctly I needed to use the transpose of my cameras rotation matrix. It works using the transpose, but why does it work? I don't need to use the transpose for any of my other transformations?
It's probably because when you set up the view matrix, you're actually setting up an inverse matrix.

Briefly, the purpose of a model matrix is (usually) to transform geometry from local to world space, while the purpose of a view matrix is to transform geometry from world to local space. Applying some linear algebra, we conclude that a view matrix must be the inverse of its corresponding model matrix. Usually our matrices are composed of two separate transformation matrices R (rotation) and T (translation), composed as T*R. Inverting this gives us R-1*T-1. Since R is orthogonal, R-1 = RT. In code this might look something like:
// Set up view matrix...
glLoadMatrixf(rotation.GetTranspose().GetPtr());
glTranslatef(-pos.x, -pos.y, -pos.z);
Which is most likely why it was suggested that you transpose the camera rotation matrix. 'Hope that helps clear things up.

Share this post


Link to post
Share on other sites
Cacks    179
Hi jyk,

when you say convert from world space to local space, is that the same as saying converting from world space to camera space?

We need to have the inverse of the view matrix because moving the camera in one direction has the same effect of moving the world in the opposite direction. Is that correct?

And because a rotation matrix is orthogonal, we can always say that its inverse is its transpose?

Thanks for the help!

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
when you say convert from world space to local space, is that the same as saying converting from world space to camera space?
Yes; what we commonly call 'view' or 'camera' space is simply the local space of the camera.
Quote:
We need to have the inverse of the view matrix because moving the camera in one direction has the same effect of moving the world in the opposite direction. Is that correct?
Sort of, in that part of what the inverse transform does is move the world by the opposite of the camera translation.

It's better to think of it in more general terms though, I think. The full story would be somewhat lengthy, but what we're talking about here is transforming points and vectors from one space to another (the spaces we're most interested in here being model, world, and view space). An intuitive way to think of matrix inversion is that M-1 does the opposite of whatever M does. So if M transforms from space A to space B, M-1 transforms from space B to space A.

In the case of the camera, the 'model' matrix rotates and then translates, so to reverse the process we translate by the negative of the original translation, and then rotate by the 'reverse' of the original rotation, which is exactly what the inverse camera matrix does.
Quote:
And because a rotation matrix is orthogonal, we can always say that its inverse is its transpose?
Yes :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this