Jump to content
  • Advertisement
Sign in to follow this  
howie_007

Help me understand D3DXMatrixLookAtLH

This topic is 2521 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
objectMgr.RenderShadowMap(testLightPos);

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.


D3DXMATRIX test;
D3DXMatrixLookAtLH(&test,
&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
Advertisement
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 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!