Hi,
I have just discovered the hard way that unproject doesn't return the right results... it seems to be missing a transform or something in there. My resulting mouse ray seems to always go through the origin (starting at the correct position, to an extent).
I tried using the connect link to vote (above) but I got a page not found.
I think it might be time to pull out my old matrix class and try and get its unproject working... Unless the xna unproject can be fixed..?
public
static Vector3 Unproject(Camera camera, Vector3 screenSpace)
{
return
camera.Viewport.Unproject(screenSpace, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity);
}
Vector3 screenNear = new Vector3((float)x, (float)y, 0f);
Vector3 screenFar = new Vector3((float)x, (float)y, 1f);
Vector3 worldNear = Unproject(camera, screenNear);
Vector3 worldFar = Unproject(camera, screenFar);
Vector3 direction = worldFar - worldNear;
direction.Normalize();
linee.Start = worldNear;
linee.End = worldNear + (direction * 1000f);
in theory the line that this code draws should be invisible, under the mouse cursor. Instead, it can be seen to always pass through the origin.
-dexy