LookAt matrix

Started by
1 comment, last by Laval B 12 years, 8 months ago
Hello

I'm working on a simple problem which is giving me some trouble right now. The problem is to build the lookat matrix for a camera in 3D. I ussume a left-handed coordinate system, i.e. z+ is pointing toward the screen. So, Eye being the point where the camera stands, At the point the camera is looking at, i construct an orthonormal basis for this new system like so :

Z = Normalize(At - Eye)
X = Normalize(Up x Z)
Y = Normalize(Z x X)

where x is the cross-product of two vectors and up is the original world ip vector (usually (0,1,0)).


Now, to build the matrix containing the rotation part of the transformation, i just build the matrix (X, Y, Z) where X, Y, X are the column vectors calculates above. This gives the following matrix :

[X.x Y.x Z.x 0]

[X.y Y.y Z.z 0]

[X.z Y.z Z.z 0]

[0 0 0 1]



To takes into account the translation to Eye, i then multiply this matrix by

[1 0 0 -Eye.x]

[0 1 0 -Eye.y]

[0 0 1 -Eye.z]

[0 0 0 1 ]


which gives


[X.x Y.x Z.x -(X.x*Eye.x + Y.x*Eye.y + Z.x*Eye.z)]

[X.y Y.y Z.z -(X.y*Eye.x + Y.y*Eye.y + Z.y*Eye.z)]

[X.z Y.z Z.z -(Z.z*Eye.x + Y.z*Eye.y + Z.z*Eye.z)]

[0 0 0 1 ]


The problem i have is that, when i look at the MSDN page for [font="Consolas, Courier, monospace"][size="4"]D3DXMatrixLookAtLH, [/font]the translation part had dot products. Yes, i'm using column major

matrices with column vectors, but it should be the same. In order to have those dot products, i would need to write my initial rotation matrix this way :


[X.x X.y X.z 0]

[Y.x Y.y Y.z 0]

[Z.x Z.y Z.z 0]

[0 0 0 1]


Did i write my rotation matrix wrong ?




We think in generalities, but we live in details.
- Alfred North Whitehead
Advertisement
your matrix takes the camera axes to world space axes, but you actually want to convert from world to camera space, so you have to invert your matrix, which, since your matrix is orthonormal, is just its transpose (the rotation part that is).
That's right, that's the piece i was missing. Thank you very much.
We think in generalities, but we live in details.
- Alfred North Whitehead

This topic is closed to new replies.

Advertisement