I have a scene, in which I am drawing few different objects - each one has the same vertices and each one is translated to proper place before being drawn.

While using libgdx (but I think that this question should be generic enough to work with other libraries), I try to do ray picking, casting ray and trying to find intersections of given ray with triangles, from meshes of each object. My problem is, that because they all share the same set of vertices, how should I find which one exactly was pointed by user?

As I have no experience in this, I was thinking about translating the vertices for each object and getting rid of glTranslate(x, y, z) called before each one, but in that situation I won't be able to use one copy of mesh to work with all objects.

May I ask for a few hints / links to articles how this should be done?


2 Answers 2


Are you using bounding volumes for your objects?

If yes then you could do something like this:

boundingVolumes = GetBVIntersection(ray)
foreach boundingVolume in boundingVolues
    (the model associated with the boundingVolume).Transform = boundingVolume.Transform
    triangles = GetTriangleIntersection(ray, model)

Translate the ray to be in the origin of the model (inverse transformation used to render the models) and then test the ray.

Keep the closest point of each hit (if any) and return the point/instance with the smallest distance.

No need to transform every point of the models or to move the transformation off the GPU.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .