Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a 3D mesh Wavefront .obj file.

Is there any algorithm that takes an arbitrary point coordinates as input and determines which face of the mesh that point belongs to ??

The mesh is rendered on the screen, then the user clicks on it, I want to determine which part of the mesh the user has clicked on ?

Here's the code using LibGDX:

Vector3 intersection=new Vector3();
Ray ray=camera.getPickRay(x, y);
//vertices is an array that hold the coordinates of the mesh
boolean ok=Intersector.intersectRayTriangles(ray, vertices, intersection);

Thanks

share|improve this question

1 Answer

For each face in the mesh: test for a ray-triangle intersection using a ray that goes through the pixel the user clicked on.

You can compute the ray using gluUnproject (or the equivalent math). Unproject two points with winX and winY set to where the user clicked: one with winZ=0.0 at the near plane, and one with winZ=1.0 at the far plane. These two points form a line you can use to test for triangle intersections.

share|improve this answer
Thanks for the answer, I'm using LibGDX, I was able to get the intersection vector, but still cann't tell which face this vector is within ? – Mina Samy Nov 28 '12 at 14:00
2  
Test all the faces for intersection with the vector, and you will find out. lighthouse3d.com/tutorials/maths/ray-triangle-intersection – ccxvii Nov 28 '12 at 14:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.