I'm trying to do two fingers zoom / pinch unsing glfrustum, I don't want to use scaling!
here is my ontouch method:
public boolean onTouchEvent(View v,MotionEvent event) {
int pointers = 0;
float distance = 0;
switch (event.getAction()) {
case (MotionEvent.ACTION_DOWN):
break;
case (MotionEvent.ACTION_POINTER_2_DOWN):
pointers = 2;
distance = fingerDist(event);
break;
case (MotionEvent.ACTION_MOVE):
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);
}
this is my onsurface method on rendrer:
public void onSurfaceChanged(GL10 gl, int width, int height ) {
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);
}
it does not work, because I do not know how to call the SurfaceChanged method from activity, and when I write a new scaling method there, it does not recognize gl.glfrusrum! any idea how i can fix this?
source
share