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.

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 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 on other sites
You are correct. Thank you so much! Don't know what I was thinking. It all works now.

1. 1
2. 2
Rutin
13
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• Forum Statistics

• Total Topics
633260
• Total Posts
3011125
• Who's Online (See full list)

There are no registered users currently online

×