I've looked at a few tutorials on picking and the Unproject method, so I have an idea of how this is supposed to work. My method does give me back a mouse position, it's just incredibly wrong. A position at 0, 0, 0 would end up to be something like 36, -1, 65.
public Vector3 FindWhereClicked(MouseState ms)
{
Vector3 nearScreen = new Vector3(ms.X, ms.Y, 0);
Vector3 farScreen = new Vector3(ms.X, ms.Y, 1);
Vector3 nearWorld = device.Viewport.Unproject(nearScreen, cam.proj, cam.view, Matrix.Identity);
Vector3 farWorld = device.Viewport.Unproject(farScreen, cam.proj, cam.view, Matrix.Identity);
Vector3 direction = farWorld - nearWorld;
float zFactor = -nearWorld.Y / direction.Y;
Vector3 zeroWorldPoint = nearWorld + direction * zFactor;
return zeroWorldPoint;
}
Variables grabbed from the camera method
public ThirdPersonCam()
{
proj = Matrix.CreatePerspectiveFieldOfView(0.78f, 1.7777f, 1f, 10000f);
}
public void CameraUpdate(Matrix objectToFollow)
{
Vector3 camPosition = objectToFollow.Translation + (objectToFollow.Backward * 10) + (objectToFollow.Up * 2);
Vector3 camTarget = objectToFollow.Translation;
view = Matrix.CreateLookAt(camPosition, camTarget, Vector3.Up);
}
Is the problem coming from my camera? Or from my FindWhereClicked method?