Skip to main content
gamedev.net
🔒 Locked

Problem understanding view transform

Started by stevenmarky Aug 27, 2006 at 12:47 PM 3 replies 1.4k views
Original Post
stevenmarky
stevenmarky
The translation values of view matrices is not the location of the camera, why is this? DirectX's D3DXMatrixLookAtLH Function is calculated as follows from three vectors, at, eye and up:


zaxis = normal(At - Eye)
xaxis = normal(cross(Up, zaxis))
yaxis = cross(zaxis, xaxis)

 xaxis.x           yaxis.x           zaxis.x          0
 xaxis.y           yaxis.y           zaxis.y          0
 xaxis.z           yaxis.z           zaxis.z          0
-dot(xaxis, eye)  -dot(yaxis, eye)  -dot(zaxis, eye)  1

But why isn't the last row simply (eye.x, eye.y, eye.z, 1)? After thinking about it for a minute it seems like the translation values have been transformed into the world coordinate system from the matrices coordinate system - is that correct? and if so..why?
yaroslavd
yaroslavd
I think it's the camera's position in camera-space. So it's the camera's position along its local X, Y, Z axes instead of the global X, Y, Z axes.
Zakwayda
Zakwayda
The basis vectors are transposed and the translation altered because the matrix is the inverse of the corresponding 'world' matrix. The purpose of the matrix is to transform geometry from world space to local camera space, not the other way around, hence the inversion.
stevenmarky
stevenmarky
Thank-you, that makes more sense to me now. I was previously having trouble translating the camera.
stevenmarky
stevenmarky
Because of this I decided I should not store the actual view matrix in my camera class. Instead I'm storing the at, eye, and up variables (and calculating the view matrix at the end of every frame).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.