O'Reilly logo

OpenGL ES 2 for Android by Kevin Brothaler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding Collision Detection

Now that you’ve had a chance to have a bit of fun and drag the mallet around, you’ve probably noticed our first problem: the mallet can go way out of bounds, as seen in Figure 46, An out-of-bounds mallet. In this section, we’ll add some basic collision detection to keep our mallet where it belongs. We’ll also add some really basic physics to let us smack the puck around the table.

images/Touch/MalletOutOfBounds.png
Figure 46. An out-of-bounds mallet

Keeping the Player’s Mallet Within Bounds

Let’s start off by adding the following bounds definitions to AirHockeyRenderer:

AirHockeyTouch/src/com/airhockey/android/AirHockeyRenderer.java
 
private​ ​final

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required