DirectX Unproject troubles

Posted by pivotnig on Game Development See other posts from Game Development or by pivotnig
Published on 2012-12-19T15:36:44Z Indexed on 2012/12/19 17:14 UTC
Read the original article Hit count: 920

Filed under:
|

I have an orthographic projection and I try to unproject a point from screen space.

Following are the view and projection matrices:

var w2 = ScreenWidthInPixels/2;
var h2 = ScreenHeightInPixels/2;

view  = Matrix.LookAtLH(new Vector3(0, 0, -1), new Vector3(0, 0, 0), 
                        Vector3.UnitY);
proj  = Matrix.OrthoOffCenterLH(-w2, w2, -h2, h2, 0.1f, 10f);

Here is how I unproject a Point p, the point is given in screen pixels:

var m = Vector3.Unproject(p, 0, 0, ScreenWidthInPixels, ScreenHeightInPixels, 
                  0.1f, 10f, // znear and zfar
                  view *proj);

My code doesn't work, the matrix m contains only Nan. When I try to invert view * proj I get back a Matrix with only zeros.

So I suspect my problem has something to do with the orthographic projection matrix.

Here are my questions:

  • Could the problem be caused by an underflow due to the large values in the OrthoOffCenterLH projection?
  • What parameters do I have to pass for x,y,width,height in Unproject(...)?
  • What significance has the minZ and maxZ parameter in Unproject(...)?
  • Does it matter what I pass for p.Z in Unproject(...)?

© Game Development or respective owner

Related posts about directx

Related posts about sharpdx