How do I determine what is touched in 3D space from the screen?

后端 未结 4 909
萌比男神i
萌比男神i 2020-12-30 13:58

How do I use gl.gluUnproject in my OpenGL ES 1.1 android app to determine what is selected when the user touches the screen?

My understanding is that the touch event

4条回答
  •  Happy的楠姐
    2020-12-30 14:33

    I think for most applications you should go for the correct 3D-approach: Ray casting.

    Take the location in 2D screen coordinates selected by the user and project them into your world space. This gives a 3D ray that originates at the camera and points into the scene. Now you need to perform collision testing in 3D. In most cases, this can be accomplished by reducing the objects to a set of simple geometries such as ellipsoids, spheres and boxes for speedup.

    Given the precision of handheld devices, that should be sufficient precision already. Note that depending on the form of the object, you might need to use more than one basic primitive. Also, it is pointless to always use the same primitive: A bounding sphere is a very bad approximation for a very long rod, obviously.

提交回复
热议问题