Jump to content
  • Advertisement
Sign in to follow this  
Laval B

LookAt matrix

This topic is 2552 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?




Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!