Take the 2-minute tour ×
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 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?

share|improve this question

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)
share|improve this answer

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.

share|improve this answer

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.