【问题标题】:Android Vertical and Horizontal Scrolling in OpenGLES 2.0OpenGLES 2.0 中的 Android 垂直和水平滚动
【发布时间】:2013-01-18 19:46:19
【问题描述】:

谁能给我一个关于如何添加垂直和水平滚动直到缩放的 GLSurfaceview 末尾的示例。我尝试过使用 Matrix.Translate 和 Matrix.Rotate 与 0 度角都不起作用。

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

方式一:

@覆盖 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);

}

【问题讨论】:

  • 您在哪些矩阵上应用这些操作,您以什么顺序进行操作?
  • 感谢迈克尔的回复。我尝试为 proj 矩阵和 MVPMatrix 应用翻译。在 Rotation 中,我创建了一个新矩阵并将其与 MVPMatrix 相乘。
  • 嗨 deepe,我在 android 的 opengl es 2.0 中也遇到了这个问题。如果您有任何解决方案,请帮助我..
  • 嗨,Harikrisnan,我已经通过链接回答了我的问题的答案中的问题。如果对您有帮助,请采纳答案。

标签: android scroll opengl-es-2.0


【解决方案1】:

原来 Android OpenGL 示例中的顶点着色器是错误的。它在文档中是正确的,但如果您下载示例,它的着色器代码错误。正如 tim 在以下链接中所建议的那样:

Android OpenGL weirdness with the setLookAtM method

【讨论】:

    猜你喜欢
    • 2016-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-09
    • 1970-01-01
    • 2011-01-03
    相关资源
    最近更新 更多