# DX11 Why is XMMatrixLookAtLH throwing an EyeDirection!= ZeroVector exception?

## Recommended Posts

Hi, can someone please explain why this is giving an assertion EyePosition!=0 exception?

_lightBufferVS->viewMatrix = DirectX::XMMatrixLookAtLH(XMLoadFloat3(&_lightBufferVS->position), XMLoadFloat3(&_lookAt), XMLoadFloat3(&up));


It looks like DirectX doesnt want the 2nd parameter to be a zero vector in the assertion, but I passed in a zero vector with this exact same code in another program and it ran just fine. (Here is the version of the code that worked - note XMLoadFloat3(&m_lookAt) parameter value is (0,0,0) at runtime - I debugged it - but it throws no exceptions.

    m_viewMatrix = DirectX::XMMatrixLookAtLH(XMLoadFloat3(&m_position), XMLoadFloat3(&m_lookAt), XMLoadFloat3(&up));

Here is the repo for the broken code (See LightClass) https://github.com/mister51213/DirectX11Engine/blob/master/DirectX11Engine/LightClass.cpp

and here is the repo with the alternative version of the code that is working with a value of (0,0,0) for the second parameter.

##### Share on other sites

That is an assertion, not an exception. Assertions are disabled by default on Release build, maybe it didn't throw it because the app was compiled in Release mode?

Note, that EyeDirection shouldn't be zero because the math involved in creating a lookat matrix expects a well defined basis transform.

##### Share on other sites

The lights were drawn properly in the version that didnt throw the assertion (used for shadowing render textures, rastertek tutorial 42). If thats the case what valid light matrix could they have produced w an eye direction of 000?

Edited by mister345

##### Share on other sites
9 hours ago, mister345 said:

what valid light matrix could they have produced w an eye direction of 000?

If the eye position is non zero, then the matrix can still be a correct lookat matrix.

##### Share on other sites
2 hours ago, turanszkij said:

If the eye position is non zero, then the matrix can still be a correct lookat matrix.

Oh, so is it just doing view direction - eye position? The variables are really confusingly named!

##### Share on other sites

Yeah basically there are two flavours, a LookAt matrix and LookTo matrix.

With a lookAt matrix you specify a position to be looking at from the eye position. With a lookTo matrix, you specify a view direction. The lookAt matrix is implemented by just a lookTo matrix construction with view direction computed as lookAtVector - EyePositionVector.

The namings can be confusing at first.

##### Share on other sites
2 hours ago, turanszkij said:

Yeah basically there are two flavours, a LookAt matrix and LookTo matrix.

With a lookAt matrix you specify a position to be looking at from the eye position. With a lookTo matrix, you specify a view direction. The lookAt matrix is implemented by just a lookTo matrix construction with view direction computed as lookAtVector - EyePositionVector.

The namings can be confusing at first.

That really clears it up, thanks so much.

## Create an account

Register a new account

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633385
• Total Posts
3011603
• ### Who's Online (See full list)

There are no registered users currently online

×