Android opengl 触摸事件

Android opengl Touch Event

我正在尝试制作一个程序,根据我在 screen.That 上触摸的位置创建信号,这意味着我可以用手指从水平线上更改每个点。
但是我不能让你那样做,因为这对你来说会很复杂,所以我想要一个圆圈跟随我的手指。
我提到我没有使用 MyGLSurfaceView class,我只使用 MyGLRenderer class(名为 GL_Render.java):

public class GL_Render implements Renderer
{
    private Context context;


    private Polygon myPoly = new Polygon();
    private desen myDesen= new desen();

    private MainActivity mySignal = new MainActivity();
    private MainActivity myAngle = new MainActivity();
    private MainActivity myZoom = new MainActivity();



    public GL_Render(Context context)
    {
        this.context = context;
    }


    public void onDrawFrame(GL10 gl) 
    {       
        float ZOOM =myZoom.zoom;
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();   // reset the matrix to its default state

        // When using GL_MODELVIEW, you must set the view point
        GLU.gluLookAt(gl, 0f,     0,   -3,      0f,    0f,      0f,    0f,  1.0f, 0.0f);
      //GLU.gluLookAt(gl, eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY,   upZ);


     //   float ratio = (float)( width / height  ) ;
        gl.glMatrixMode(GL10.GL_PROJECTION);        // set matrix to projection mode
        gl.glLoadIdentity();                        // reset the matrix to its default state
        if(ZOOM==0){
        gl.glFrustumf(0f, -1f, -1, 1, 3, 7);  // apply the projection matrix
        //gl.glFrustumf(left, right, bottom, top, zNear, zFar);
        }
        else
        {
              gl.glFrustumf(0f, -1f/(2*ZOOM), -1, 1, 3, 7);  // apply the projection matrix
            //gl.glFrustumf(left, right, bottom, top, zNear, zFar);

        }

        myDesen.Desen(gl);



        if(ZOOM!=0)
        {
        float l2[] =
            {
                (float)0.5/(2*ZOOM),  0.5f, 0.0f,
                (float)0.5/(2*ZOOM), -0.5f, 0.0f 
            };


        myPoly.Polygon(l2);
        myPoly.draw(gl,1,0,0);
        }
        else{
            float l2[] =
                {
                    0.5f,  0.5f, 0.0f, 
                    0.5f, -0.5f, 0.0f 
                };              
            myPoly.Polygon(l2);
            myPoly.draw(gl,1,0,0);
        }

                    // Create the moving Circle here if possible:



        }



    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) 
    {

        // Adjust the viewport based on geometry changes
        // such as screen rotations
        gl.glViewport(0, 0, width, height);

        // make adjustments for screen ratio
        float ratio = (float)( width / height  ) ;
        gl.glMatrixMode(GL10.GL_PROJECTION);        // set matrix to projection mode
        gl.glLoadIdentity();                        // reset the matrix to its default state

        gl.glFrustumf(0f, -1f, -1, 1, 3, 7);  // apply the projection matrix
        //gl.glFrustumf(left, right, bottom, top, zNear, zFar);


    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig arg1) 
    {
        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

        myPoly=new Polygon();
    }

    private void GL_Prepare(GL10 gl)
    {
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        gl.glFrontFace(GL10.GL_CW);
        gl.glEnable(GL10.GL_DEPTH_TEST);
        gl.glEnable(GL10.GL_BLEND);
        gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);     
    }

    private void GL_Finish(GL10 gl)
    {
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    }


}

无论您使用什么视图,无论是 GlSurfaceView 还是其他视图,您都需要一个 Touch Listener。然后,您可以以标准方式使用 Touch Listener,唯一的区别是您需要将触摸点从屏幕坐标转换为 opengl 场景坐标。