Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


share|improve this question

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
Test all the faces for intersection with the vector, and you will find out. – ccxvii Nov 28 '12 at 14:12

OBJ format is not meant to reflect how you store things in memory and operate on data. The fact that you're using an OBJ format is hence not relevant. You need to be loading your data into an appropriate in-memory format that makes the operations you need efficient.

In the most general case you store a list of Triangle objects and iterate over each to do a ray-triangle test. You can optimize this heavily by using a smarter data structure, such as a model-local BSP tree (or some other spatial partitioning as appropriate for the kinds of shapes you're using).

share|improve this answer

Your Answer


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.