user2583144
user2583144

Reputation: 35

Zoom in/out and Move Object in OpengGL Es

I have drawn the 3D object. Now I want to do the Zoom in/out and Move object through 2 fingers gesture.

I've checked many links to do gesture in opengl but did not get much help.

Code:

@Override
public boolean onTouchEvent(MotionEvent event) {
    //
    float x = event.getX();
    float y = event.getY();

    //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;

        //Rotate around the axis otherwise
        } else {                
            xrot += dy * TOUCH_SCALE;
            yrot += dx * TOUCH_SCALE;
        }        
    //A press on the screen
    } else if(event.getAction() == MotionEvent.ACTION_UP) {

    }

    //Remember the values
    oldX = x;
    oldY = y;

    //We handled the event
    return true;
}

Please help me thanks in advance.

Upvotes: 0

Views: 96

Answers (1)

datenwolf
datenwolf

Reputation: 162327

OpenGL sole purpose is drawing things. It's like pencil and pens to draw on a piece of paper provided by the operating system. OpenGL does not provide user input handling. Also OpenGL is not a scene graph, i.e. it doesn't manage a scene with objects in it. It draws points, lines or triangles to a framebuffer, and that's it.

So you must use the usual Android user interaction interfaces to change some internal state of your program and trigger a full redraw of the scene to reflect the changes.

Upvotes: 1

Related Questions