I have a simple problem that I am trying to figure out for the NeHe port lesson 7... all i want to do is be able to drag the cube around the screen ONLY when the user touches the cube... i have sucessfully gotten the cube to move but the user can be anywhere on the screen... how can I distinguish whether the persons finger is on the cube or not...
my variables xp and yp are my representation of the cubes x and y position on the screen gl.glTranslatef(xp,yp,z);
i have very little expierience in java but a bit in C/C++ so I may be on the wrong track completely... any help would be great.
/**
* Override the touch screen listener.
*
* React to moves and presses on the touchscreen.
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
//
float x = event.getRawX(); //<- should this be getRawX or just getX ??
float y = event.getRawY(); // <-- same as above
//If a touch is moved on the screen
if(event.getAction() == MotionEvent.ACTION_MOVE) {
//Calculate the change
float dx = x - oldX;
float dy = y - oldY;
//Define an upper area of 10% on the screen
int upperArea = this.getHeight() / 10;
//Zoom in/out if the touch move has been made in the upper
if(y < upperArea) {
z -= dx * TOUCH_SCALE / 2;
} else {
if (y >= yp+0.1f || y <= yp-0.1f ) //<-- here is where i think the code should be corrected
{
yp -= dy * TOUCH_SCALE;
}
}
//A press on the screen
} else if(event.getAction() == MotionEvent.ACTION_UP) {
//Define an upper area of 10% to define a lower area
int upperArea = this.getHeight() / 10;
int lowerArea = this.getHeight() - upperArea;
//Change the light setting if the lower area has been pressed
if(y > lowerArea) {
if(light) {
//light = false;
} else {
//light = true;
}
}
}


