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 ...

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.