Adding Intersection Tests
Now that we have the touched area of the screen in normalized device coordinates, we’ll need to determine if that touched area contains the mallet. We’ll need to perform an intersection test, a very important operation when working with 3D games and applications. Here’s what we’ll need to do:
-
First we’ll need to convert the 2D screen coordinate back into 3D space and see what we’re touching. We’ll do this by casting the touched point into a ray that spans the 3D scene from our point of view.
-
We’ll then need to check to see if this ray intersects with the mallet. To make things easier, we’ll pretend that the mallet is actually a bounding sphere of around the same size and then we’ll test against that sphere.
Let’s start ...
Get OpenGL ES 2 for Android now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.