Sign in to follow this  
ofarooq

[SlimDx] Hit Test (Picking) issues

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this