My GL "skillz" are a little rusty, but there are a few ways I still
remember.
1 - This is a "trick".
Draw your objects one by one with a solid color, call glReadPixels after
each to read a few pixels around the touch point.
Use the color information you get from glReadPixels to check if the last
object you rendered covered the touch point.
Do not flip the buffers at the end (so your scene doesn't show with
wrong colors).
Pros: easy to do
Cons: glReadPixels can be slow.
2 - Test in screen coordinates.
Go through objects one by one, project their bounding sphere into screen
coordinates, use math to see if the touch point is within the projected
area.
Pros: still easy to do
Cons: projects each object into screen coordinates.
3 - Test in world coordinates
Two points define a line. One is the camera position, the other is the
touch point converted into world coordinates. This gives you a ray that
"shoots forward" into the scene.
Go through objects one by one, check if the ray intersects the object's
bounding box.
Pros: faster
Cons: somewhat harder to do
There are utility functions for converting coordinates between screen
space and world space: glProject and glUnProject.
They are part of the GL Utility library that's not included in Android.
However, you can easily find sample implementations of these.
Here is one place:
http://www.opengl.org/wiki/GluProject_and_gluUnProject_code
Here is another:
http://oss.sgi.com/cgi-bin/cvsweb.cgi/projects/ogl-sample/main/gfx/lib/glu/libutil/
(look in project.c)
-- Kostya
29.11.2010 16:19, pedr0 пишет:
I have the same issue, any suggestion?
On 29 Nov, 13:24, Paolo<[email protected]> wrote:
Hi there!
I have developed an Augmented Reality App using OpenGL ES 1.1. It's
really cool and I'm very happy for that, because Im' an opengl
beginner.
Now I have a problem... :( I'd like to detect touch events on some
opengl objects. I know I can't use View.EventListener with those,
because these objects don't inherit from View class. They are simply
subclasses of Object that implement an opengl draw function.
I've read about "picking" in OpenGL, but before to take this way, I
want to understand if there are other solutions.
So, which can the solution be to do that?
Thanks in advance.
Paolo
--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en