Brush up on your geometry. :=)

Map from a two dimensional coordinate (screen) to a 3 dimensional one
(model):

(ScreenX, ScreenY, 0) --gluUnproject--> (ModelX1, ModelY1, ModelZ1)
(ScreenX, ScreenY, 1) --gluUnproject--> (ModelX2, ModelY2, ModelZ2)

Now you 'draw' an invisible line from (ModelX1, ModelY1, ModelZ1) to
(ModelX2, ModelY2, ModelZ2) and find first intersection point of this
line with a cube. This cube is the one that has been touched.

I found that the gluUnproject that came with the SDK is buggy. I wrote
my own:
http://groups.google.com/group/android-developers/browse_frm/thread/9d2bf53e3a798cb6/c722628acdf6e2d9?lnk=gst&q=gluUnproject#c722628acdf6e2d9
(go to message #8)

On Feb 24, 2:31 am, Louis Huh <avatar....@gmail.com> wrote:
> I drew cubes using opengl,
>
> GLSurfaceView has onTouchEvent method. but I'd like to know
>
> what cube was touched ?
>
> cubes can move anywhere in the viewport...

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to