3

我有在 OpenGL 中绘制一个简单的纹理立方体的代码。

同样成功地实现了平移(平移)和旋转功能。

现在我有以下代码来实现立方体模型的捏缩放。我不知道问题出在哪里,当我点击多维数据集时什么都没有发生。

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在这卡了这么多天,也检查了一些d链接实现多点触控,但还是没有得到满意的回应。提前致谢。

4

0 回答 0