# 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 on other sites
Quote:
 Original post by slugonamissionI 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 on other sites
Thanks very much :) I'll have a look through it :)

##### 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627741
• Total Posts
2978887

• 10
• 10
• 21
• 14
• 14