Having trouble with trying to get 3d mouse coords
Hi!
Ive been working on getting a little dot to move around flat 3D terrain that is controlled by a mouse input.
x = e.X;
y = e.Y;
Vector3 near = new Vector3(x, y, 0);
Vector3 far = new Vector3(x, y, 1);
near.Unproject(device.Viewport, projectionMatrix, viewMatrix, Matrix.Identity);
far.Unproject(device.Viewport, projectionMatrix, viewMatrix, Matrix.Identity);
Vector3 ray = near - far;
richTextBox1.Text = near.ToString();
Is this right? Im getting incorrect results and im wondering if anyone can tell me what im doing wrong? thanks:)
h,maybe we can work together,i make that too, and you code maybe is wrong,you need convert to 2d coordenates(you Screem ) to 3d World, next you need detect a collision with you terrain with "D3DXINTERSECTION" function.
check this.
http://www.gamedev.net/community/forums/topic.asp?topic_id=521246.
check this.
http://www.gamedev.net/community/forums/topic.asp?topic_id=521246.
nvm i solved it
x = e.X;
y = e.Y;
Vector3 p1 = new Vector3(x, y, 0);
Vector3 p2 = new Vector3(x, y, 1);
p1.Unproject(device.Viewport, projectionMatrix, viewMatrix, Matrix.Identity);
p2.Unproject(device.Viewport, projectionMatrix, viewMatrix, Matrix.Identity);
Vector3 ray;
float wy = 0;
float wx= ((wy - p1.Y) * (p2.X - p1.X)) / (p2.Y - p1.Y) + p1.X;
float wz = ((wy - p1.Y) * (p2.Z - p1.Z)) / (p2.Y - p1.Y) + p1.Z;
ray = new Vector3(wx, wy, wz);
Thanks anyway!:D
x = e.X;
y = e.Y;
Vector3 p1 = new Vector3(x, y, 0);
Vector3 p2 = new Vector3(x, y, 1);
p1.Unproject(device.Viewport, projectionMatrix, viewMatrix, Matrix.Identity);
p2.Unproject(device.Viewport, projectionMatrix, viewMatrix, Matrix.Identity);
Vector3 ray;
float wy = 0;
float wx= ((wy - p1.Y) * (p2.X - p1.X)) / (p2.Y - p1.Y) + p1.X;
float wz = ((wy - p1.Y) * (p2.Z - p1.Z)) / (p2.Y - p1.Y) + p1.Z;
ray = new Vector3(wx, wy, wz);
Thanks anyway!:D
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement