# Possible to look straight up/down with D3DXMatrixLookAtLH?

This topic is 3951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 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.

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633674
• Total Posts
3013276
×