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: 971
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
inUnproject(...)
? - What significance has the
minZ
andmaxZ
parameter inUnproject(...)
? - Does it matter what I pass for
p.Z
inUnproject(...)
?
© Game Development or respective owner