簡體   English   中英

在Android中翻譯OpenGL ES 2.0 Shapes

[英]Translation of OpenGL ES 2.0 Shapes in Android

我最近查看了developers.android.com提供的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的float數組。 我的問題是,我該如何用x和y位置進行平移,並用sam進行縮放(帶刻度的浮點數)? 似乎有mo setTranslateM方法,當我嘗試其他方法時,我無法使它們起作用。 我該怎么辦?

要平移/縮放/旋轉對象,應將這些操作應用於“模型矩陣”。

例:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM