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:

public​ ​void​ handleTouchDrag(​float​ normalizedX, ​float​ normalizedY) {
if​ (malletPressed) {
Ray ray = convertNormalized2DPointToRay(normalizedX, normalizedY);
// Define ...

Get OpenGL ES 2 for Android now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.