Oengl es Android 双击屏幕效果实现

主要就是让你的View 实现onTouchListener。我这里设置GLSurfaceView 的一个对象名为mGLView.

红色加粗为关键性语句,是主要应用到的。而且GestureDetector不只是有onDoubleTap方法,还有以下这些方法可以实现。

 

mGLView.setOnTouchListener(new OnTouchListener(){
            
            private GestureDetector gestureDetector  = new  GestureDetector(MainActivity.this, new GestureDetector.SimpleOnGestureListener() {

                @Override
                public boolean onDoubleTap(MotionEvent e) {
                    // TODO Auto-generated method stub
                    Log.d("double", "double");
                    mGLView.mAngleX = 0;
                    mGLView.mAngleY = 0;
                    mGLView.setArray();
                    mGLView.requestRender();
                    return super.onDoubleTap(e);
                }
                
            });

            @Override
            public boolean onTouch(View v, MotionEvent e) {
                // TODO Auto-generated method stub
                gestureDetector.onTouchEvent(e);
                ypos = e.getY();  
                xpos = e.getX();
                 switch (e.getAction()) {  
                   // case MotionEvent.ACTION_DOWN:
                         
                       // return true;
                    
                    case MotionEvent.ACTION_MOVE:  
                        float dy = ypos - mPreviousY;//计算触控笔Y位移  
                        float dx = xpos - mPreviousX;//计算触控笔X位移  
                        Log.d("dx", "dx"+dx+dy);
                        mGLView.mAngleX = dy * TOUCH_SCALE_FACTOR;//设置沿x轴旋转角度  
                        mGLView.mAngleY = dx * TOUCH_SCALE_FACTOR;//设置沿y轴旋转角度  
                        mGLView.setArray();
                        mGLView.requestRender();//重绘画面
                        return true;
                    } 
                 mPreviousX = xpos;
                 mPreviousY = ypos;
                return true;
            }
            
        });

 

posted @ 2016-10-25 19:52  风吹来的砂  阅读(406)  评论(0编辑  收藏  举报