3

我正在尝试能够执行两指缩放/捏合 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);
        }

这是我在渲染器上的表面方法:

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!知道如何解决这个问题吗?

4

0 回答 0