Jump to content
  • Advertisement
mister345

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.

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

Share this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!