Sorry, the Forum is closed :(

Unfortunately, the forum is now closed.

Please read the following post for further details.

We apologize for the inconvenience.
The SharpDX team.
Welcome, Guest
Username: Password: Remember me
Welcome to the general discussions!
  • Page:
  • 1

TOPIC: Picking with SharpDX

Picking with SharpDX 2 years 4 months ago #348


  • Posts:7
  • wyrda's Avatar
  • wyrda
  • Fresh Boarder
  • OFFLINE
Hi,

I'm working on a win 8 app with SharpDX and the only thing left to be done is picking.
I found this tutorial www.mdxinfo.com/tutorials/picking.php and this toymaker.info/Games/html/picking.html but because I'm new to DirectX programming and SharpDX I don't know how to do it. How do I create that ray? how do I iterate through all meshes and check for intersection?

In my project I use the CubeRenderer.cs class, a little bit modified, from SharpDx Samples, All I need is to know what face of the cube was piked.
The administrator has disabled public write access.

Re: Picking with SharpDX 2 years 4 months ago #349


  • Posts:56
  • Fadi's Avatar
  • Fadi
  • Senior Boarder
  • OFFLINE
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 pointNear;
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 pointFar;
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 4 months ago #350


  • Posts:7
  • wyrda's Avatar
  • wyrda
  • Fresh Boarder
  • OFFLINE
Thank you for your answer but I still don't know how to select each mesh to create a BoundingBox for it. The cube is built from a vertex buffer and some world transformation are applied.

L.E. Because is a Metro Style App I use DirectX11.
Last Edit: 2 years 4 months ago by wyrda.
The administrator has disabled public write access.

Re: Picking with SharpDX 2 years 4 months ago #351


  • Posts:56
  • Fadi's Avatar
  • Fadi
  • Senior Boarder
  • OFFLINE
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).
Last Edit: 2 years 4 months ago by Fadi.
The administrator has disabled public write access.

Re: Picking with SharpDX 2 years 4 months ago #353


  • Posts:7
  • wyrda's Avatar
  • wyrda
  • Fresh Boarder
  • OFFLINE
Thank you very much! I think that tut is all that I need.
The administrator has disabled public write access.

Re: Picking with SharpDX 2 years 4 months ago #399


  • Posts:7
  • wyrda's Avatar
  • wyrda
  • Fresh Boarder
  • OFFLINE
I tried the method described in the tutorial but it doesn't work if the face of the cube is rotated more than a few degrees. Any ideas?

L.E. Picking doesn't work if user see at least 2 faces of the cube. I only one face is visible than user can pick the face.
Last Edit: 2 years 4 months ago by wyrda. Reason: L.E.
The administrator has disabled public write access.

Re: Picking with SharpDX 2 years 4 months ago #403


  • Posts:7
  • wyrda's Avatar
  • wyrda
  • Fresh Boarder
  • OFFLINE
Problem solved :D.

I have learnt a little bit of math and I rewrite the code for picking.
Useful links:
www.blackpawn.com/texts/pointinpoly/default.html
sharpdx.org/documentation/api/m-sharpdx-plane-intersects-2
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 0.179 seconds