2012-01-05 128 views
0

我知道心不是存在pushmatrix,popmatrix,以及矩陣堆棧,loadidentity,旋轉,平移等Android的OpenGL ES 2.0的glpushmatrix等

我如何重寫我現有的1.0-1.1的發動機與2.0的工作?

我想這第一:

void glRotate(float x, float y, float z) { 
    Matrix.setRotateM(mMMatrix, 0, x, 1, 0, 0); 
    Matrix.setRotateM(mMMatrix, 0, y, 0, 1, 0); 
    Matrix.setRotateM(mMMatrix, 0, z, 0, 0, 1); 

    Matrix.multiplyMM(mMVPMatrix, 0, mVMatrix, 0, mMMatrix, 0); 
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0); 
} 

void glTranslate(float x, float y, float z) { 
    Matrix.translateM(mMMatrix, 0, x, y, z); 

    Matrix.multiplyMM(mMVPMatrix, 0, mVMatrix, 0, mMMatrix, 0); 
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0); 
} 

glTranslate它不工作,我怎麼能在世界上翻譯我的潛行?

glRotate只在Z中旋轉我的對象,x,y根本不起作用。

+ 如何實現矩陣堆棧/ glpush/glpopmatrix?任何人都有這樣的想法嗎?

回答

0

嘗試使用

Matrix.setIdentityM(mMMatrix,0);

在計算矩陣變換之前。

並使用Matrix.rotateM()而不是Matrix.setRotateM()。

0

我在1年前遇到同樣的問題。

我不得不從頭開始編寫大部分這些函數,我可以向你保證這是一個混亂不堪的錯誤。

我建議您從一個非常有效的實現開始,您可以在OpenGL Gold Book(OpenGL ES 2.0編程指南)的samples目錄下的「esTransform.c」文件中找到它。

這本書是這一個: http://opengles-book.com/downloads.html

的代碼可以從谷歌代碼在這裏下載: http://code.google.com/p/opengles-book-samples/

我建議你反正買的書,它成爲快速的OpenGL ES 2.0的聖經它做得非常好。

最後,請在開始生產之前檢查源代碼的使用許可。