I've looked at a few tutorials about picking and the method Unproject, so I have an idea of how getting the mouse in 3d space is done. The code I have does display a mouse position, but it is way off of the actual position the mouse is at.
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;
}
This code is from another thread I found on here. I'm guessing the problem is the near and far world variables.
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);
}
The variables are grabbed from my camera class, but I don't know why it isn't working. A point that's supposed to be at 0, 0, 0 ends up being at something like 36, -1, 57