To find the ray which is equivalent to a specific mouse XY position in the current view or camera:
Vector3 mouseNearVector = new Vector3(mouseX, mouseY, Camera.ZNear);
Vector3.Unproject(ref mouseNearVector, 0, 0, viewport.Width, viewpot.Height, Camera.ZNear, Camera.ZFar, ref camViewProjectionMatrix, out pointNear);
Vector3 mouseFarVector = new Vector3(mouseX, mouseY, Camera.ZFar);
Vector3.Unproject(ref mouseFarVector, 0, 0, viewport.Width, viewpot.Height, Camera.ZNear, Camera.ZFar, ref camViewProjectionMatrix, out pointFar);
Ray ray = new Ray(pointNear, Vector3.Normalize(pointFar - pointNear);
Then you can check each mesh bounding box intersection with this ray:
MeshBoundingBox.Intersects(ref ray,out intersectionPoint)
if the bounding boxes of your meshes are not axis aligned (Contain rotation), then you may need to repeat the above code for each mesh and replace camViewProjectionMatrix matrix with worldViewProjectionMatrix which combines mesh transformation to transform the ray into the local space of the mesh before checking the intersection.
if that works for you, you'll get the point of intersection, and its up to you to find which face was picked.
The administrator has disabled public write access.
Re: Picking with SharpDX
2 years 9 months ago #350
In DirectX11, there is no definition for mesh, so there is no D3DXIntersect function. such things considered as a part of the game logic not the rendering pipeline.
Check this link (Direct3D 11 Picking).