1

The question is simple, how can I identify which object has been touched by the user in OpenGL. I've tried the utilizat envento onTouchEvent but this only returns the possição X, Y screen.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Luciano
  • 21
  • 1
  • 2
  • possible duplicate of [Android OpenGL 3D picking](http://stackoverflow.com/questions/6699387/android-opengl-3d-picking) – genpfault Jul 28 '11 at 15:26

1 Answers1

2

A similar question was asked (& answered) in this thread: Detect user's touches over an OpenGL square

Basically there are 2 methods: 1 rendering all objects to a buffer in all different colours and then looking at the colour information at the specified 'pick coordinate' to identify your object. The other (and I think less resource intensive) is retrieving the 'ray' and then doing a hit test with bounding boxes you provide for all your objects currently rendered on the screen.

edit: If you're doing your rendering orthographically/2d then this somewhat simplifies things. You can do a simple hit Test with the point you touched and a rectangle (or circle or polygon perhaps) you provide for the image that you've drawn.

Hope this helps.

Community
  • 1
  • 1