3

I have the code to draw a simple textured cube in OpenGl.

Successfully implemented panning(translation) and rotation features also in the same.

Now I have the following code for implementing pinch zoom for the cube model. I dont know where's the problem, when m clicking on cube nothing is happening.

private float mLastTouchX;
private float mLastTouchY;
private static final int INVALID_POINTER_ID = -1;
private int mActivePointerId = INVALID_POINTER_ID;

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        final float x = event.getX();
        final float y = event.getY();
        mLastTouchX = x;
        mLastTouchY = y;
        mActivePointerId = event.getPointerId(0);
        break;
    }
    case MotionEvent.ACTION_MOVE: {
        final int pointerIndex = event.findPointerIndex(mActivePointerId);
        final float x = event.getX(pointerIndex);
        final float y = event.getY(pointerIndex);
        final float dx = x - mLastTouchX;
        final float dy = y - mLastTouchY;
        mPosX += dx;
        mPosY += dy;
        mLastTouchX = x;
        mLastTouchY = y;
        invalidate();
        break;
    }
    case MotionEvent.ACTION_UP: {
        mActivePointerId = INVALID_POINTER_ID;
        break;
    }
    case MotionEvent.ACTION_CANCEL: {
        mActivePointerId = INVALID_POINTER_ID;
        break;
    }
    case MotionEvent.ACTION_POINTER_UP: {
        final int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
        final int pointerId = event.getPointerId(pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mLastTouchX = event.getX(newPointerIndex);
            mLastTouchY = event.getY(newPointerIndex);
            mActivePointerId = event.getPointerId(newPointerIndex);
        }
        break;
    }
    }
    return true;
}

M stuck in this for so many days, also cheked some of d links for implementing multi-touch gesture but stil not getting any satisfactory response. Thanks in advance.

Martin Berger
  • 1,639
  • 3
  • 18
  • 39
Manroop
  • 301
  • 1
  • 3
  • 16
  • 2
    See [here](http://stackoverflow.com/q/10630373/1262542) (a _related_ link). You'll need to adapt the solution, but generally the code looks OK. – Stefan Hanke Jun 25 '12 at 15:40
  • i have already tried this part which works on the saved matrix state, but the matrix concept works on images (on how to zoom a particular image), my issue is regarding with the opengl model-- zooming a cube :( – Manroop Jun 26 '12 at 04:14
  • @Manroop are you sure your touch events are firing? If nothing happens that could be the issue. Check if your recognizers are working. – Martin Berger Apr 10 '13 at 15:08

0 Answers0