0

I am working on a multi-agent application. During a simulation I display the agents present at any timestep. This agent have their own specific id.

I want to identify and interact with those object by using picking. My picking method is working but I cannot get the id of the agent (I only get the id of the geometry that is not correllated wit the one of the agent). So I need to find the way to assign to any new drawn geometry the corresponding id of the agent.

Is there a way in opengl to assign an id when you draw an object (maybe between glBegin() and glEnd()) ?

arno69
  • 41
  • 1
  • 4

1 Answers1

1

I have had success in the past with painting each object a different colour in a backbuffer/FBO, doing the pick, reading the pixel at that point, and then rendering the actual frame in the proper colours for the human to see it. With a shader you can do both at the same time.

Then you just look up the colour in a table to figure out what the object is. This method is very slow.

A better (faster) alternative is to cast a ray from the position you clicked at to see which objects in the scene it intersects. You can do some primitive frustum culling to reduce the set of potential pickable objects as well.

ravuya
  • 8,205
  • 4
  • 29
  • 33
  • Thank you for the answer,I have no problem with picking the object. I can pick it and display it in red for example but what I want to do is to obtain the id of my agent from the picked geometry. Actually what I have is an arbitrary id that is created by default in OpenGL (not the one of my agent) but I don't know where this id is created and if it's possible to define my own id (the one of the agent). – arno69 Nov 14 '12 at 03:37