Problem with D3DXMatrixLookAtLH

Started by
3 comments, last by ClassifiedOne 21 years, 11 months ago
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
Advertisement
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( );

~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
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
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
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
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.

This topic is closed to new replies.

Advertisement