Help me understand D3DXMatrixLookAtLH

Started by
1 comment, last by howie_007 12 years, 4 months ago
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.
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.
You are correct. Thank you so much! Don't know what I was thinking. It all works now.

This topic is closed to new replies.

Advertisement