Advertisement

Why is XMMatrixLookAtLH throwing an EyeDirection!= ZeroVector exception?

Started by January 18, 2018 02:09 PM
6 comments, last by mister345 7 years ago

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.

https://github.com/mister51213/DX11Port_SoftShadows/blob/master/Engine/lightclass.cpp

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.

Advertisement

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?

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.

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!

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.

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

This topic is closed to new replies.

Advertisement