OpenGLES 2.0中的Android垂直和水平滚动

时间:2013-01-18 19:46:20

标签: android scroll opengl-es-2.0

任何人都可以举例说明如何添加垂直和水平滚动直到GLSurfaceview的缩放结束。我尝试过使用Matrix.Translate和Matrix.Rotate,但是没有任何工作。

我用过的方式。在这里,dx和dy是我从onTouch中获得的滚动量乘以常数因子:

方式1:

@覆盖 public void onDrawFrame(GL10 unused){

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 unused){

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 unused){

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);

}

0 个答案:

没有答案
相关问题