• Advertisement
Sign in to follow this  

Having trouble with trying to get 3d mouse coords

This topic is 2880 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:)

Share this post


Link to post
Share on other sites
Advertisement
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.


Share this post


Link to post
Share on other sites
so maybe that http://www.gamedev.net/community/forums/topic.asp?topic_id=397658 can help you

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement