我正在尝试能够执行两个手指缩放/捏捏没有glfrustum,我不想使用缩放!
这是我的ontouch方法:
public boolean onTouchEvent(View v,MotionEvent event) {
int pointers = 0;
float distance = 0;
switch (event.getAction()) {
case (MotionEvent.ACTION_DOWN): // Touch screen pressed
break;
case (MotionEvent.ACTION_POINTER_2_DOWN):
pointers = 2;
distance = fingerDist(event);
break;
case (MotionEvent.ACTION_MOVE): // Contact has moved across screen
if( pointers == 2 ){
float newDist = fingerDist(event);
float d = distance/newDist;
renderer.onSurfaceChanged();
distance = newDist;
}
}
return true;
}
protected final float fingerDist(MotionEvent event){
float x = event.getX(0) - event.getX(1);
float y = event.getY(0) - event.getY(1);
return FloatMath.sqrt(x * x + y * y);
}
这是我在rendrer上的onsurface方法:
public void onSurfaceChanged(GL10 gl, int width, int height ) {
// TODO Auto-generated method stub
gl.glViewport(0, 0, width, height);
float ratio = (float) width / height;
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustumf(-ratio, ratio, -1, 1, 1*d, 25*d);
}
它不起作用,因为我不知道如何从活动中调用onSurfaceChanged方法,当我在那里写一个新的缩放方法时,它无法识别gl.glfrusrum!任何想法如何解决这个问题?