• Advertisement
Sign in to follow this  

[SlimDx] Hit Test (Picking) issues

This topic is 2977 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 All, I have a a sphere in a 3d window, and I am trying to move it with the mouse. The good old conversion from 2d to 3d space. Problem is that @ the first time the hit test succeeds but fails after that. The code is as follows... Any ideas/suggestions... thanks private void MyControl_MouseDown(object sender, MouseEventArgs e) { if ( ctrl && e.Button == MouseButtons.Left) { Device d = myMesh.Device; Matrix world = d.GetTransform(TransformState.World); Vector3 near = new Vector3(e.X, e.Y, 0); Vector3 far = new Vector3(e.X, e.Y, 1); near = Vector3.Unproject(near, d.Viewport, m_cam.Proj, cam.View, world); far = Vector3.Unproject(far, d.Viewport, m_cam.Proj, m_cam.View, world); far = Vector3.Subtract(far, near); m_isSphereHit = myMesh.Intersects(new Ray(near, far)); } } private void MyControl_MouseMove(object sender, MouseEventArgs e) { if (m_isSphereHit) { Device d = myMesh.Device; Matrix world = d.GetTransform(TransformState.World); Vector3 position = SpherePosition; position = Vector3.Project(position, d.Viewport, m_cam.Proj, m_cam.View, world); position.X = e.X; position.Y = e.Y; position = Vector3.Unproject(position, d.Viewport, m_cam.Proj, m_cam.View, world); SpherePosition = position; }

Share this post


Link to post
Share on other sites
Advertisement
I'd suggest setting a breakpoint inside MyControl_MouseDown and looking at the values you get there and the kind of processing you do. If of two clicks at the same point only the first works then it's likely to be apparent when debugging where the difference is.

Share this post


Link to post
Share on other sites
I just double checked. The only reason it works the first time is because the spehere starts off @ the origin...
If I start the sphere off @ at any other location, the hit test fails the first time...

Share this post


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

  • Advertisement