谁能给我一个关于如何添加垂直和水平滚动直到缩放的 GLSurfaceview 末尾的示例。我尝试过使用 Matrix.Translate 和 Matrix.Rotate 与 0 度角,但都不起作用。
我用过的方法。在这里 dx 和 dy 是我从 onTouch 获得的滚动量乘以一个常数因子:
方式1:
@Override public void onDrawFrame(GL10 未使用) {
mOffset = mPositionX + mPositionY;
// Draw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
// Set the camera position (View matrix)
Matrix.setLookAtM(mVMatrix, 0, mOffset, mOffset, -3, mOffset, mOffset, 0f, 0.0f, 1.0f, 0.0f);
// Calculate the projection and view transformation
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
mGraph.draw(mMVPMatrix);
mLine.draw(mMVPMatrix);
}
方式2:
@Override public void onDrawFrame(GL10 未使用) {
mOffset = mPositionX + mPositionY;
Matrix.frustumM(mProjMatrix, 0, mSurfaceRatio * zoomFactor, -mSurfaceRatio * zoomFactor, -1 * (zoomFactor + mOffset), zoomFactor + mOffset, 3, 7);
// Draw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
// Set the camera position (View matrix)
Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0.0f, 1.0f, 0.0f);
// Calculate the projection and view transformation
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
mGraph.draw(mMVPMatrix);
mLine.draw(mMVPMatrix);
}
方式3:
@Override public void onDrawFrame(GL10 未使用) {
mOffset = mPositionX + mPositionY;
// Draw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
Matrix.rotateM(mRotationMatrix, 0, 0, 0, mOffset, 0);
Matrix.multiplyMM(mProjMatrix, 0, mProjMatrix, 0, mRotationMatrix, 0);
// Set the camera position (View matrix)
Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0.0f, 1.0f, 0.0f);
// Calculate the projection and view transformation
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
mGraph.draw(mMVPMatrix);
mLine.draw(mMVPMatrix);
}