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

Moving Around an Object by Dragging

Now that we’re able to test if the mallet has been touched, we’ll work on solving the next part of the puzzle: Where does the mallet go when we drag it around? We can think of things in this way: the mallet lies flat on the table, so when we move our finger around, the mallet should move with our finger and continue to lie flat on the table. We can figure out the right position by doing a ray-plane intersection test.

Let’s complete the definition for handleTouchDrag:

AirHockeyTouch/src/com/airhockey/android/AirHockeyRenderer.java
 
public​ ​void​ handleTouchDrag(​float​ normalizedX, ​float​ normalizedY) {
 
if​ (malletPressed) {
 
Ray ray = convertNormalized2DPointToRay(normalizedX, normalizedY);
 
// Define ...

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