Jump to content
  • Advertisement
Sign in to follow this  

Mesh Picking in Directx

This topic is 4481 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

Anyone familiar with this? I tried to implement it but I cannot get the intersection checking function to return me true when I click on the mesh. Not sure what went wrong... pls advise. For the code below... the part on conversion of mouse point to 3d point and the calculaation of the world transformation matrix of the 3d mesh should be correct. public void MouseDown(object sender, MouseEventArgs e ) { // The technique used here is to create a ray through the entire // logical 3d space and then perform a bounding box-ray intersection. Matrix proj = m_drawArgs.WorldCamera.ProjectionMatrix; Vector3 v, rayStart, rayDirection; IntersectInformation intInf; // convert mouse pt to 3d point v = convertMousePt(e.X, e.Y); clicked = true; Matrix m = m_drawArgs.WorldCamera.m_ViewMatrix * m_drawArgs.WorldCamera.m_WorldMatrix; m.Invert(); rayDirection.X = v.X * m.M11 + v.Y * m.M21 + v.Z * m.M31; rayDirection.Y = v.X * m.M12 + v.Y * m.M22 + v.Z * m.M32; rayDirection.Z = v.X * m.M13 + v.Y * m.M23 + v.Z * m.M33; rayStart.X = m.M41; rayStart.Y = m.M42; rayStart.Z = m.M43; float minDistance = float.MaxValue; foreach(RenderableObject ro in this.m_children) { if(ro.IsOn) { if (((Shape2Obj)ro).Pick(m_drawArgs, rayStart, rayDirection, out intInf) ) MessageBox.Show("Success"); } } } public bool Pick(DrawArgs drawArgs, Vector3 rayStart, Vector3 rayDirection, out IntersectInformation intInf) { //world matrix of the mesh Matrix World = Matrix.RotationX((float)MathEngine.DegreesToRadians(90-xRotation))* Matrix.RotationZ((float)MathEngine.DegreesToRadians(-Orientation)) * Matrix.Scaling(Scale, Scale, Scale) * Matrix.Translation(0,0,(float)drawArgs.WorldCamera.WorldRadius + Altitude*jpVertExaggeration) * Matrix.RotationY((float)MathEngine.DegreesToRadians(90-Latitude)) * Matrix.RotationZ((float)MathEngine.DegreesToRadians(Longitude)); Matrix inverseWorld = Matrix.Invert(World); Vector3 localStart = Vector3.TransformCoordinate(rayStart, inverseWorld); Vector3 localDirection = Vector3.TransformNormal(rayDirection, inverseWorld); localDirection.Normalize(); return mesh.Intersect(localStart, localDirection, out intInf); }

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!