Hi, I am trying to setup picking in my project, but there is strange issue, which not let me do this. Vecto3.Unproject returns NAN always.

I found out that its because of Matrix.Inverse inside that method and as a result inversed matrix have 0 in all fields.

All transmitted parameters are correct.

So, I wonder isis that correct that from WVP matrix during inversion I always receive Zero matrix?

I leave here some code to be sure I transfer parameters correct:

ZNear = 0.01;

ZFar = 10000000000000;

mouse coords and ViewPort also correct;

But both vectors receive NAN as a result value;

private void Pick(int mouseX, int mouseY, ref Matrix wvpMatrix, BoundingBox boundingBox) { Vector3 mouseNearVector = new Vector3(mouseX, mouseY, basicCamera.ZNear); Matrix m = Matrix.Identity; m = Matrix.Invert(wvpMatrix); Vector3 pointNear = Vector3.Unproject(mouseNearVector, 0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, basicCamera.ZNear, basicCamera.ZFar, wvpMatrix); Vector3 mouseFarVector = new Vector3(mouseX, mouseY, basicCamera.ZFar); Vector3 pointFar = Vector3.Unproject(mouseFarVector, 0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, basicCamera.ZNear, basicCamera.ZFar, wvpMatrix); Ray ray = new Ray(pointNear, Vector3.Normalize(pointFar - pointNear)); float distance = 0; bool intersect = boundingBox.Intersects(ref ray, out distance); D2DText = "Intersect: " + intersect.ToString() + " distance = "+distance; intersect = false; }

Does Vector3.Unproject() method working correct or I am missing something?

Also it works really strange - sometime it returns true if no model under mouse and in the same time returns NAN for distance or return true and real distance value when no model under cursor is present.

It very strange that sometime picking is working at least somehow and the other time its not working at all.

**Edited by BlackJoker, 24 August 2014 - 10:18 AM.**