Hello everyone,
I am currently working on a Live Wallpaper app for android that uses OpenGLES. I have come across some trouble though. I drew a cube and added motion to it, but know I want to add a touch event so when the user touches/drags their finger on the screen the cube will rotate with their finger. I have been following some example code in a book I have been reading but it doesn't seem to work, whenever I run my app and try to drag my finger across the screen nothing happens. So first it tells me to make an onTouch() or in the renderer class, like this:
@Override
public boolean onTouch(View v, MotionEvent event) {
for (int i = 0; i < event.getPointerCount(); i++)
{
if (event.getPointerId(i) == 0) {
touchX = (event.getX(i) / surfaceWidth) * 480;
touchY = (event.getY(i) / surfaceHeight) * 800;
}
}
return true;
}
btw here are the float variables:
float surfaceWidth;
float surfaceHeight;
float touchX;
float touchY;
then it tells me to set the surfaceWidth/Height as the dimensions in the onSurfaceChanged() like this:
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
surfaceWidth = width;
surfaceHeight = height;
}
That is all it tells me to do, but I cant help but thinking that I should add something to the onDrawFrame() since moving an object requires redrawing the frames. If it is helpful here is a little snippet from my onDrawFrame():
@Override
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
GLU.gluLookAt(gl, 0, 0, 3, 0, 0, 0, 0, 2, 0);
gl.glPushMatrix();
square.draw(gl);
gl.glPopMatrix();
Thank you to anyone who can help me, I know this may seem like a pretty simple problem but I do not really have any experience with the onTouch() or OpenGL, which is why I am reading this book, thanks again!