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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access