Android轨迹球在Open GL Surface View中协调问题

时间:2015-06-03 13:05:27

标签: android opengl-es

我们正在使用TrackBall Events在OpenGL中绘制线条,形状,但它无法正常工作。我们已经厌倦了在Canvas中实现Trackball事件并且工作正常。但是TrackBall事件在OpenGL GLSurfaceView中无效。但我们可以使用Touch Event绘制线条。请指导我在轨迹球赛事中实施。

画布代码:

@Override 
public boolean onTrackballEvent (MotionEvent motionEvent) 
{ 

        int action = motionEvent.getAction() & MotionEvent.ACTION_MASK;     
        float scaleX = motionEvent.getXPrecision()* TRACKBALL_SCALE ;
        float scaleY = motionEvent.getYPrecision()* TRACKBALL_SCALE;
        int N = motionEvent.getHistorySize();

        switch (motionEvent.getAction()) {            
        case MotionEvent.ACTION_MOVE:

          mCurX += motionEvent.getRawX() * scaleX;
             mCurY += motionEvent.getRawY() * scaleY;

         for (int i=0; i<N; i++) { 
          Log.i("ACTION_MOVE", "N="+N);   
                mCurX += motionEvent.getHistoricalX(i) * scaleX;   
                mCurY += motionEvent.getHistoricalY(i) * scaleY;
                touch_move(mCurX, mCurY);
            }             
          touch_move(mCurX,mCurY);
            invalidate();
            break;            
    }            
}  

OpenGL代码:

ScaleGestureDetector mScaleDetector;

@Override 
 public CustomGLView(Context context) {
        super(context);
        setFocusable(true);
        this.mContext = context;
        mGestureDetector = new GestureDetector(getContext(), 
    new GestureListener(context));
        setupOpenGL();
    }

  @Override
    public boolean onTrackballEvent (MotionEvent motionEvent) 

{           
        int fingers = motionEvent.getPointerCount();
        GestureHandler.getInstance().mGestureMotionEventHistory.put(motionEvent.getAction(), motionEvent);
       for(int i = 0; i < fingers; i ++) {
            MotionEvent.PointerCoords coords = 
    new MotionEvent.PointerCoords();
            motionEvent.getPointerCoords(i, coords);
            GestureHandler.getInstance().setGesturePointerNumAndLocation(i, coords.x, coords.y);
     GestureHandler.getInstance().mXYPointerCoordsByIndex.put(i, 
        new float[]{coords.x, coords.y});
        }  
  mScaleDetector.onTouchEvent(motionEvent);  
        return true;
    }

0 个答案:

没有答案