Sign in to follow this  

Possible to look straight up/down with D3DXMatrixLookAtLH?

This topic is 3586 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

Just a quick question. Whenever I try to look straight up or down using D3DXMatrixLookAtLH, things get glitchy. Is it possible to look straight up or down in a DirectX application using this function? If not, is there a way around it? Thanks!

Share this post


Link to post
Share on other sites
That's happening because your target vector is tending towards the same direction as your up vector. When they're both <0,1,0> the calculations that the function performs don't come out correctly and you get weird results. A solution for this could be to also rotate your up vector backwards, so when your target vector is <0,1,0> your up vector would be <0,0,-1>.

Share this post


Link to post
Share on other sites
Great, thank you! Using that information I was able to fix it. Here's what I ended up doing (for anyone out there who might have the same problem):


if (<the camera is pointing straight up>)
v3dUp = D3DXVECTOR3 (-sin(<camera angle>), 0.0f, -cos(<camera angle>));
else if (<the camera is pointing straight down>)
v3dUp = D3DXVECTOR3 (sin(<camera angle>), 0.0f, cos(<camera angle>));
else
v3dUp = D3DXVECTOR3 (0.0f,1.0f,0.0f );

Share this post


Link to post
Share on other sites
What your experiencing there is called 'Gimbal Lock'. Do a google on the term for a full explanation.

The best way to solve it is to recalculate the Up vector by taking the cross product of the forward and right(or left) vectors.

Share this post


Link to post
Share on other sites

This topic is 3586 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this