Reputation: 145
Can any one give me a example on how to add vertical and horizontal scroll till the end of the GLSurfaceview which is zoomed. I have tried using Matrix.Translate and Matrix.Rotate with 0deg angle none of it works.
The ways i have used. In here dx and dy are the amount scrolled which i get from onTouch multiplied by a constant factor:
way 1:
@Override 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);
}
way 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);
}
way 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);
}
Upvotes: 0
Views: 949
Reputation: 145
Turns Out that the vertex shader in the Android OpenGL example is wrong. Its correct in the docs but if you download the example it has wrong shader code. As suggested by tim in the following link:
Android OpenGL weirdness with the setLookAtM method
Upvotes: 0