Sign in to follow this  
slugonamission

DirectX View Matrix

Recommended Posts

I understand that it is possible to get the current camera position from the inverse view matrix. The problem is, what do the elements in the view/inverse view matrix "mean". I know about matrix transformations, I just don't understand what each element of the view/inverse view matrix means in relation to the camera :( Thanks - Jamie

Share this post


Link to post
Share on other sites
Quote:
Original post by slugonamission
I understand that it is possible to get the current camera position from the inverse view matrix. The problem is, what do the elements in the view/inverse view matrix "mean". I know about matrix transformations, I just don't understand what each element of the view/inverse view matrix means in relation to the camera :(

Thanks - Jamie
Let's start with the object/model/world transform for the camera (that is, prior to inversion). Conceptually this matrix is the result of the transformation sequence rotate->translate. Using row-vector notation, the matrix product that represents this sequence is:
[ xx xy xz 0 ][ 1  0  0  0 ]   [ xx xy xz 0 ]
[ yx yy yz 0 ][ 0 1 0 0 ] = [ yx yy yz 0 ]
[ zx zy zz 0 ][ 0 0 1 0 ] [ zx zy zz 0 ]
[ 0 0 0 1 ][ tx ty tz 1 ] [ tx ty tz 1 ]
Where (xx,xy,xz) is the local side/x basis vector of the object (similarly with up/y and forward/z), and (tx,ty,tz) is the object translation.

To use this matrix as a 'view' matrix, we must invert it (the desired effect of the view matrix is to transform geometry from world space to the local space of the camera, not the other way around).

A property of matrix inversion is that (AB)^-1 = B^-1A^-1. Let R be the rotation matrix (the first matrix in the matrix product shown above), and T be the translation matrix (the second matrix in the product). Each of these has a trivial inverse. R is orthogonal, therefore its inverse is R^T. It can also be shown that to invert T we need only negate the translation elements.

Now to write out the matrix product T^-1R^-1:
[  1   0   0  0 ][ xx yx zx 0 ]   [  xx   yx   zx  0 ]
[ 0 1 0 0 ][ xy yy zy 0 ] = [ xy yy zy 0 ]
[ 0 0 1 0 ][ xz yz zz 0 ] [ xz yz zz 0 ]
[ -tx -ty -tz 1 ][ 0 0 0 1 ] [ -t.x -t.y -t.z 1 ]
Where '.' is the dot product (e.g. -t.x is the dot product of the negated translation vector with the local x basis vector).

If we know the view matrix has been constructed as in the above example, we can reverse the process and extract the actual, untransformed camera position from the matrix. However, in most cases, if you yourself constructed the camera matrix in the first place you should already have the position of the camera object available.

Share this post


Link to post
Share on other sites
Quote:
Original post by slugonamission
... The problem is, what do the elements in the view/inverse view matrix "mean"...


First, the individual elements in a matrix don't "mean" anything. They are just numbers. However, in a model-to-world matrix (a.k.a. "world" matrix), you can find the translation in the bottom row and the orientation and scaling (if any) in the upper-left 3x3 submatrix.

A world-to-view matrix (a.k.a. "view" matrix) can be inverted to get a view-to-world matrix (and vice-versa), which is effectively the equivalent of a model-to-world matrix. So, as you already know, you can get the camera's translation and orientation as described above from the camera's model/view-to-world matrix.

Finally, in an environment where a camera moves and orients in the world, you generally don't manipulate the view matrix directly. Instead, you move and orient the camera through its model-to-world matrix and then invert that to get the view matrix. In that case, as jyk already stated, there is no reason to invert the view matrix to get the camera's position and orientation, since you already know them.

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