2013-01-06 176 views
0

我最近查看了由developers.android.com提供的OpenGL ES 2.0教程。我成功完成了它(即使它不是很清楚),但后来我遇到了一个问题。一旦我完成它,我从来没有被告知如何翻译或缩放对象。我尝试了目前看起来合乎逻辑的不同选项,但他们没有奏效。我在android的OpenGL ES 2.0中并不是很熟悉。Android中的OpenGL ES 2.0形状的翻译

Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); 
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0); 

long time = SystemClock.uptimeMillis() % 4000L; 
mAngle = 0.090f * ((int) time); 
Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f); 

Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0); 

t.draw(mMVPMatrix); 

所有这些矩阵的大小为16浮点数组。我的问题是,我怎么能用x和y的位置来做翻译,并且用sam来进行缩放(一个有比例的浮动)?似乎有mo setTranslateM方法,当我尝试了其他方法时,我无法使它们工作。我该怎么办?

回答

3

要翻译/缩放/旋转对象,应将这些操作应用于模型矩阵。

例子:

Matrix.setIdentityM(mMMatrix, 0); // reset transformations 
Matrix.setRotateM(mMMatrix, 0, 0, 1.0f, 0, 0); // set rotation 
Matrix.translateM(mMMatrix, 0, 10.0f, 20.0f, 0); // apply translation 
Matrix.scaleM(mMMatrix, 0, 0.25f, 0.25f, 0.25f); // apply scale 

请注意Matrix类的某些静态方法做内存分配,所以如果你的对象,你可能想不使用它们每一帧上的转变。在这里阅读更多关于http://groups.google.com/group/android-developers/browse_thread/thread/b30dd2a437cfb076?pli=1和我的博客文章http://androidworks-kea.blogspot.com/2012/05/developers-notes-about-opengl-es.html