I am trying to make a 3D model to look at the mouse position. Currently I have this code:
MouseState mouseState = Mouse.GetState();
Matrix world = Matrix.CreateTranslation(0, 0, 0);
Vector3 source = new Vector3((float) mouseState.X, 1f, (float) mouseState.Y);
Vector3 mousePoint = GraphicsDevice.Viewport.Unproject(source, this.game.Camera.Projection, this.game.Camera.View, world);
System.Console.Out.WriteLine("x: " + mousePoint.X + ", Y: " + mousePoint.Y + ", Z: " + mousePoint.Z);
I get output such as this in the console:
x: 0.1787011, Y: 999.7204, Z: 299.7723
x: 0.08917224, Y: 999.8602, Z: 299.8862
x: 0.05908892, Y: 999.9069, Z: 299.9241
x: 0.04422692, Y: 999.9302, Z: 299.9431
x: 0.03303542, Y: 999.9477, Z: 299.9573
x: 0.03109217, Y: 999.9508, Z: 299.9598
x: 0.02930491, Y: 999.9535, Z: 299.9621
x: 0.02770578, Y: 999.9559, Z: 299.9641
x: 0.0263205, Y: 999.9581, Z: 299.9659
The player is positioned at Vector3.Zero
. The camera is positioned at new Vector3(0.0f, 1000.0f, 300.0f)
.
I would like to get output such as X: -300, Y: 0, Z: -300
when moving the mouse to screen top left and when moving the mouse to screen center where the model is located I want to have X: 0, Y: 0, Z: 0
. So I want the world coordinates of the mouse so that I can make the player rotate towards the mouse.
Basically I want to map mouse X into world X, mouse Y to world Z and the world Y coordinate can be 0 at all times.