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に使用されています。
だから、私の問題2倍:
- はパンが数秒間連続してパン(画面上で円を作り、いくつかの時点で、デバイスの画面
- 上の指の動きの2倍遅く発生し、例えば、地図が「揺れ」始めます。この揺れの振幅はますます大きくなっています。 handlePan反復でいくつかの値が加算され、この効果が生じるように見えます。
これらの問題が発生する理由はありますか。
ありがとう、グレッグ。