• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Problem with D3DXMatrixLookAtLH

## Recommended Posts

First of a general question: Am I right, when I use the World Matrix to translate and rotate objects in my scene and the function "D3DXMatrixLookAtLH" for moving and panning my camera? Now to my problem: I can’t rotate my camera 360°. If I insert values between 0 and 100 for the second parameter of D3DXMatrixLookAtLH (vAt) everything is fine, but I can’t rotate more than 100° or so. Just imagine you are standing in front of a wall. You move your mouse to the left, your camera view turns left. Now, if you are at 90° or so you see the wall at the right side. But then you can’t rotate anymore. For example you can’t turn around, because you cannot rotate 180°. Even if I insert 5000 for the second parameter. Maybe I’m wrong with using D3DXMatrixLookAtLH for this task. If not, does anyone know, what I might have done wrong? Thanks ClassifiedOne

#### Share this post

##### Share on other sites
The second parameter is a vector, not a number. It is the position the camera is facing towards. To face 90 degrees right, you would find a point to the right of the camera and use that as the vAt position. How are you currently using the function?

My guess is you''re setting it like D3DVECTOR(5000,0,0) which would make the camera face almost 90 degrees right (as the X component reaches infinity, the camera''s angle approaches 90 degrees). That is not how to use the function.

~CGameProgrammer( );

#### Share this post

##### Share on other sites
Yes I use the function with D3DVECTOR(5000,0,0).
Oh, but I think I understand what you mean. Now the camera looks at a point (5000,0,0). And that is of course not behind the camera. I guess, to turn the camera around, I should use something like (0,0,0) -> (90,0,-90) -> (0,0,-100), right?

However, I will try...

Greetings
ClassifiedOne

#### Share this post

##### Share on other sites
Assuming you don''t want to look up or down (only left/right), then you should have:
D3DVECTOR(cos(angle), 0, sin(angle))

Something like that anyway.

John B

#### Share this post

##### Share on other sites
D3DMATRIX matTemp;

D3DXMatrixIdentity(matView); // reset the view matrix
D3DXMatrixIdentity(matTemp); // and the temp

D3DXMatrixLookAtLH(matTemp, camVEye, camVAt, D3DVector(0,1,0));
D3DXMatrixMultiply(matView, matView, matTemp);
D3DXMatrixRotationY(matTemp, dCamYAngle);
D3DXMatrixMultiply(matView, matView, matTemp);
D3DXMatrixRotationX(matTemp, dCamXAngle);
D3DXMatrixMultiply(matView, matView, matTemp);
D3DXMatrixRotationZ(matTemp, dCamZAngle);
D3DXMatrixMultiply(matView, matView, matTemp);
D3DDevice->SetTransform(D3DTS_VIEW, matView);

Change dCam?Angle for the angle and camVAt+camVEye for camera position.

• ### Forum Statistics

• Total Topics
628275
• Total Posts
2981759

• 10
• 11
• 17
• 10
• 9