2013-01-18 91 views
0

任何人都可以給我一個關於如何添加垂直和水平滾動直到放大的GLSurfaceview結束的例子。我曾嘗試使用Matrix.Translate和Matrix.Rotate與0deg角度沒有它的作品。OpenGLES 2.0中的Android垂直和水平滾動

我用過的方法。在這裏dx和dy是量滾動這是我從onTouch乘以常數因子得到:

方式1:

@Override 公共無效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:

@覆蓋公共無效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:

@覆蓋公共無效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); 

}

+1

該基質是你申請的操作,以及在什麼樣的順序,你做的操作:如以下鏈接建議由蒂姆? – Michael

+0

感謝您的回覆邁克爾。我試過對proj矩陣和mVPMatrix應用翻譯。在旋轉中,我創建了一個新的矩陣並將其與mVPMatrix相乘。 – deepu

+0

嗨,我也在android中的opengl es 2.0中面臨這個問題。如果你得到任何解決方案,請幫助我.. – harikrishnan

回答