   Calculating world coordinates
  Hello everybody,I've got a problem calculating world coordinates out of screen coordinates. I've already been reading quite a lot about this topic, but I couldn't find a solution so far.In my application I draw a rectangle, which lies on the xy-plane. Hence its z-coordinates are set to 0, all other coordinates are different from 0. The drawing matrices are defined as follows:  device.Transform.World = Matrix.Identity;  device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-5), new Vector3(0,0,0), new Vector3(0,1,0));  device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI/4, 1.0f, 0.0f, 1.0f);In this way I look orthogonally onto the scene... it's kept very simple.Now, when moving the mouse cursor over it, I want to calculate the corresponding world coordinates, i.e. the intersection point with the xy-plane. I read about determining a direction vector, so I tried this out:  //x and y are the screen coordinates, for example x=175, y=300  Vector3 near = new Vector3(x, y, 0);    near.Unproject(device.Viewport,    device.Transform.Projection,    device.Transform.View,    device.Transform.World);  Vector3 far = new Vector3(x, y, 1);  far.Unproject(device.Viewport,    device.Transform.Projection,    device.Transform.View,    device.Transform.World);  Vector3 dir = far - near;The problem here is, that the near and the far vector have both the same z-value (i.e. 1). Thus the direction vector is parallel to the xy-plane and there's no intersection point at all. What do I do wrong? How can I compute the intersection with the xy-plane?Thanks very much in advance!Chris   
  I'm wondering if the real cause is this:PerspectiveFovLH( (float)Math.PI/4, 1.0f, 0.0f, 1.0f)Technically it should be valid to have Znear = 0.0, but you're effectively zeroing out the (4,3)th element in the perspective matrix.Try something like Znear = 1.0 and Zfar = 10.0 and see if you get better results.Otherwise, the unproject function isn't difficult to implement yourself - and you could step through the code and debug it yourself.hthJack   ;  try this:D3DVIEWPORT9 viewport;m_pD3DDEVICE->GetViewport(&viewport);// Compute the vector of the pick ray in screen spaceJVEC3 v;v.x =  ( ( ( 2.0f * x ) / viewport.Width  ) - 1 ) / matProj._11;v.y = -( ( ( 2.0f * y ) / viewport.Height ) - 1 ) / matProj._22;v.z =  1.0f;D3DXMATRIX m;D3DXMatrixInverse( &m, NULL, &matView );// Transform the screen space pick ray into 3D spaceRayDir.x  = v.x*m._11 + v.y*m._21 + v.z*m._31;RayDir.y  = v.x*m._12 + v.y*m._22 + v.z*m._32;RayDir.z  = v.x*m._13 + v.y*m._23 + v.z*m._33;RayOrigin.x = m._41;RayOrigin.y = m._42;RayOrigin.z = m._43;RayOrigin.x += (RayDir.x * Distance);RayOrigin.y += (RayDir.y * Distance);RayOrigin.z += (RayDir.z * Distance);where 'x' and 'y' are your 2D screen positions, 'Distance' is the amount of pushing the final 3D position into Z+ and 'matProj' is your projection matrix.The 'RayOrigin' is the 3D position you want at the end.You can create a 'matView' from a D3DXMatrixLookAtLH or similar.I hope i helped.   ;  That was the point... I changed the projection matrix to this:device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI/4, 1, 1, 10);... now it works fine. Thank you very much!