2016-08-15 8 views
0

지도를 표시하는 앱을 쓰고 있습니다. 사용자는 확대/축소 및 이동이 가능합니다. 지도는 자력계의 값에 따라 회전합니다 (지도가 기기 회전의 반대 방향으로 회전 함).Android. OpenGL ES. 패닝/스크롤

스케일링에 대해서는 ScaleGestureDetector를 사용하고 스케일 인자를 Matrix.scaleM에 전달합니다. 패닝

이 코드를 사용하고 있습니다 :

GlSurfaceView 측 :

private void handlePanAndZoom(MotionEvent event) { 
    int action = MotionEventCompat.getActionMasked(event); 
    // Get the index of the pointer associated with the action. 
    int index = MotionEventCompat.getActionIndex(event); 
    int xPos = (int) MotionEventCompat.getX(event, index); 
    int yPos = (int) MotionEventCompat.getY(event, index); 

    mScaleDetector.onTouchEvent(event); 

    switch (action) { 
     case MotionEvent.ACTION_DOWN: 
      mRenderer.handleStartPan(xPos, yPos); 
      break; 
     case MotionEvent.ACTION_MOVE: 
      if (!mScaleDetector.isInProgress()) { 
       mRenderer.handlePan(xPos, yPos); 
      } 
      break; 
    } 
} 

렌더러 측 :

private static final PointF mPanStart = new PointF(); 
public void handleStartPan(final int x, final int y) { 
    runOnGlThread(new Runnable() { 
     @Override 
     public void run() { 
      windowToWorld(x, y, mPanStart); 
     } 
    }); 
} 

private static final PointF mCurrentPan = new PointF(); 
public void handlePan(final int x, final int y) { 
    runOnGlThread(new Runnable() { 
     @Override 
     public void run() { 
      windowToWorld(x, y, mCurrentPan); 
      float dx = mCurrentPan.x - mPanStart.x; 
      float dy = mCurrentPan.y - mPanStart.y; 
      mOffsetX += dx; 
      mOffsetY += dy; 
      updateModelMatrix(); 
      mPanStart.set(mCurrentPan); 
     } 
    }); 
} 

windowToWorld 기능이 gluUnProject를 사용하고 나는 그것을 사용하고 있기 때문에 작동 다른 많은 작업. UpdateModelMatrix는 :

private void updateModelMatrix() { 
    Matrix.setIdentityM(mScaleMatrix,0); 
    Matrix.scaleM(mScaleMatrix, 0, mScale, mScale, mScale); 

    Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, 1.0f); 

    Matrix.setIdentityM(mTranslationMatrix,0); 
    Matrix.translateM(mTranslationMatrix, 0, mOffsetX, mOffsetY, 0); 

    // Model = Scale * Rotate * Translate 
    Matrix.multiplyMM(mIntermediateMatrix, 0, mScaleMatrix, 0, mRotationMatrix, 0); 
    Matrix.multiplyMM(mModelMatrix, 0, mIntermediateMatrix, 0, mTranslationMatrix, 0); 
} 

같은 mModelMatrix는 점 번역 windowToWorld 기능의 gluUnproject에 사용됩니다.

그래서 내 문제가 두 가지 : 화면에 원을 (몇 초 동안 지속적으로 패닝 할 때 패닝은 어떤 시점에서 장치의 화면

  • 에 손가락의 움직임에 비해 두 배 느린 발생

    1. , 예를 들어지도가 '흔들 리기'시작합니다. 이 떨림의 진폭은 점점 더 커지고 있습니다. handlePan 반복에서 일부 값이 합쳐지고이 효과가 발생하는 것처럼 보입니다.

    이러한 문제가 발생하는 이유는 무엇입니까?

    미리 감사드립니다. Greg.

  • 답변

    0

    글쎄, 내 코드의 문제는이 라인이다 : 나는 세계 좌표에 드래그 간단하기 때문에

     mPanStart.set(mCurrentPan); 
    

    , 오프셋 갱신하지만, 현재 위치는 동일하게 유지됩니다. 이건 내 벌레 야.

    이 줄을 제거하면 모든 것이 수정됩니다.