Advertisement Jump to content
Sign in to follow this  

Help me understand D3DXMatrixLookAtLH

This topic is 2591 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

Here's what I'm trying to do.

I want to position my spot light and have it look in a direction for rendering my shadow map. So for a simple test I have a light positioned directly above my test objects pointing straight down.

To simulate this I setup a matrix like so.

CMatrix testLightPos;
testLightPos.Translate(CPoint(0.f, -250.f, 0.f)); // set pos
testLightPos.Rotate(CPoint(-90.f,0.f,0.f)); // rotate X to face down

So for this test, I setup a matrix at a point above my test objects and rotate x 90 degrees so that the camera is pointing straight down. Shadows on the test objects render correctly and all looks good.

I'm assuming I'll be able to use D3DXMatrixLookAtLH to do the same thing.

&D3DXVECTOR3(0.f, 250.f, 0.f), // eye
&D3DXVECTOR3(0.f, 1.f, 0.f), // target
&D3DXVECTOR3(0.f, 1.f, 0.f)); // Y up

The matrix from D3DXMatrixLookAtLH doesn't work and in comparing the two, the data in each of the matrices are different.

Either I'm not using D3DXMatrixLookAtLH correctly or it's not used in this way. I don't know.

Share this post

Link to post
Share on other sites
Your up vector and your lookAt direction can't be the same direction (or the complete opposite direction). This is because it comes up with right direction by taking the cross product of your up vector and (lookAt - eye), and if those two vectors are the same the cross product will be zero. You should use (0, 0, 1) as your up direction, since that way would be "up" if you rotated 90 degrees downward.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!