我对开放式GL的开发相当新。我试图找出如何旋转视图,以便我可以在视图上看到对象的所有边。类似于谷歌地图的旋转方式。有什么建议?这是我目前的代码。
@Override
public boolean onTouchEvent(MotionEvent e) {
float x = e.getX();
float y = e.getY();
switch (e.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mode = 0; //safety precaution for screen taps vs swiping
mPreviousX = x;//safety precaution for screen taps vs swiping
mPreviousY = y;//safety precaution for screen taps vs swiping
case MotionEvent.ACTION_POINTER_DOWN:
if(e.getPointerCount() == 2) {//two fingers down
oldDist = distance(e);//old distance equals the new distance from the motion event
mode = 1;
}
break;
case MotionEvent.ACTION_MOVE:
if (mode == 1) {
newDist = distance(e);
if (newDist > oldDist) { // distance increasing
mRenderer.increaseScale(Math.abs(oldDist - newDist) / 100);
} else if (newDist < oldDist) { // distance decreasing
mRenderer.decreaseScale(Math.abs(oldDist - newDist) / 100);
}
//Matrix.rotateM(m, mOffset, a, x, y, z);
oldDist = newDist;
} else if(mode == 0) {
float dx = x - mPreviousX;
float dy = y - mPreviousY;
// reverse direction of rotation above the mid-line
if (y < mView.getHeight() / 2) {
dx = dx * -1;
}
// reverse direction of rotation to left of the mid-line
if (x > mView.getWidth() / 2) {
dy = dy * -1;
}
mRenderer.xAngle += dx * TOUCH_SCALE_FACTOR;
mRenderer.yAngle += dy * TOUCH_SCALE_FACTOR;
x = e.getX();
y = e.getY();
float distanceX = x - mPreviousX;
float distanceY = y - mPreviousY;
mRenderer.moveLeftRight(distanceX/100);
mRenderer.moveUpDown(distanceY/100);
mView.requestRender();
mPreviousX = x;
mPreviousY = y;
}
break;
case MotionEvent.ACTION_POINTER_UP:
mode = 0;
break;
default:
super.onTouchEvent(e);
}
return true;
}