Not sure if this is right, but upon checking:
// Pixel Space - ScreenSpace -1 to 1
Vector2 screenSpace;
screenSpace.X = ( ( ( 2.0f * mousePos.X ) / screenSize.X ) - 1 );
screenSpace.Y = -( ( ( 2.0f * mousePos.Y ) / screenSize.Y ) - 1 );
// Inverse View/Proj Matrix
Matrix invMProj = Matrix.Invert(projection);
Matrix invMView = Matrix.Invert(view);
// Near/Far Point
Vector3 nearPos = new Vector3(screenSpace.X, screenSpace.Y, 0);
Vector3 farPos = new Vector3(screenSpace.X, screenSpace.Y, 1);
nearPos = Vector3.Transform(nearPos, invMProj * invMView); /**** My Vals *****/
farPos = Vector3.Transform(farPos, invMProj * invMView); /**** My Vals *****/
// Check some values - compare
Vector3 nearScreenPoint = new Vector3(mousePos.X, mousePos.Y, 0);
Vector3 farScreenPoint = new Vector3(mousePos.X, mousePos.Y, 1);
Vector3 nearWorldPoint = m_device.Viewport.Unproject(nearScreenPoint, projection, view, Matrix.Identity); /*** Check Vals ****/
Vector3 farWorldPoint = m_device.Viewport.Unproject(farScreenPoint, projection, view, Matrix.Identity); /*** Check Vals ****/
If I use the ViewPort unproject - my nearPos I calculate using the inverse matrices and the nearWorldPoint that the Unproject calculates are more or less the same.
But the farWorldPoint and my farPos seem to be out by a factor proportional to the farclip plane...for example, I've got the farview set to 1000...so if I multiply the my farview by a 1000, I get the same as the viewport Unproject.
Anyone give me some light on this?
Thanx,
Ben