我在opengl es2.0中實現了一個應用程序。我需要使用pushmatrix()和popmatrix()。我們都知道這個功能在opengl es 2.0中不再可用。我試圖遵循並實施給定的方法here。但我ddnt找到了太多的成功。同樣我們也需要實現一些大量的頭文件。有沒有人把它作爲他們項目的一部分來實施?如果可能的話,有人可以發佈一些代碼片段,這將引導我保存和恢復當前矩陣的狀態?OPENGLES 2.0 PUSHMATRIX POP MATRIX實現
0
A
回答
3
假設你有一個簡單的linmath庫,就像這樣:
typedef GLfloat vec4[4];
inline void vec4_add(vec4 a, vec4 b)
{
int i;
for(i=0; i<4; ++i)
a[i] += b[i];
}
inline void vec4_sub(vec4 a, vec4 b)
{
int i;
for(i=0; i<4; ++i)
a[i] -= b[i];
}
inline void vec4_scale(vec4 v, GLfloat s)
{
int i;
for(i=0; i<4; ++i)
v[i] *= s;
}
inline GLfloat vec4_inner_product(vec4 a, vec4 b)
{
GLfloat p = 0.;
int i;
for(i=0; i<4; ++i)
p += b[i]*a[i];
return p;
}
inline GLfloat vec4_length(vec4 v)
{
return sqrtf(vec4_inner_product(v,v));
}
inline void vec4_normalize(vec4 v)
{
GLfloat k = 1.0/vec4_length(v);
vec4_scale(v, k);
}
inline void vec4_cross(vec4 a, vec4 b)
{
vec4 c;
c[0] = a[1]*b[2] - a[2]*b[1];
c[1] = a[2]*b[0] - a[0]*b[2];
c[2] = a[0]*b[1] - a[1]*b[0];
c[3] = 0.;
memcpy(a, c, sizeof(a));
}
typedef vec4 mat4x4[4];
inline void mat4x4_identity(mat4x4 M)
{
int i, j;
M[0][0] = 1; M[1][0] = 0; M[2][0] = 0; M[3][0] = 0;
M[0][1] = 0; M[1][1] = 1; M[2][1] = 0; M[3][1] = 0;
M[0][2] = 0; M[1][2] = 0; M[2][2] = 1; M[3][2] = 0;
M[0][3] = 0; M[1][3] = 0; M[2][3] = 0; M[3][3] = 1;
/*for(j=0; j<4; ++j)
for(i=0; i<4; ++i) {
M[i][j] = i==j ? 1 : 0;
}*/
}
inline void mat4x4_cpy(mat4x4 M, mat4x4 N)
{
int i, j;
for(j=0; j<4; ++j) {
for(i=0; i<4; ++i) {
M[i][j] = N[i][j];
}
}
}
inline void mat4x4_mul(mat4x4 M, mat4x4 b)
{
mat4x4 a;
int i, j, k;
memcpy(a, M, sizeof(a));
for(j=0; j<4; ++j) {
for(i=0; i<4; ++i) {
M[i][j] = 0;
for(k=0; k<4; ++k) {
M[i][j] += a[i][k]*b[k][j];
}
}
}
}
inline void mat4x4_trans(mat4x4 M, GLfloat x, GLfloat y, GLfloat z)
{
mat4x4 T; mat4x4_identity(T);
T[3][0] = x;
T[3][1] = y;
T[3][2] = z;
mat4x4_mul(M, T);
}
inline void mat4x4_rot_X(mat4x4 M, GLfloat angle)
{
GLfloat s = sinf(angle);
GLfloat c = cosf(angle);
mat4x4 R = {
{1, 0, 0, 0},
{0, c, s, 0},
{0,-s, c, 0},
{0, 0, 0, 1}
};
mat4x4_mul(M, R);
}
inline void mat4x4_rot_Y(mat4x4 M, GLfloat angle)
{
GLfloat s = sinf(angle);
GLfloat c = cosf(angle);
mat4x4 R = {
{c, 0, s, 0},
{0, 1, 0, 0},
{-s, 0, c, 0},
{0, 0, 0, 1}
};
mat4x4_mul(M, R);
}
inline void mat4x4_rot_Z(mat4x4 M, GLfloat angle)
{
GLfloat s = sinf(angle);
GLfloat c = cosf(angle);
mat4x4 R = {
{c, s, 0, 0},
{-s, c, 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1}
};
mat4x4_mul(M, R);
}
inline void mat4x4_row(vec4 r, mat4x4 M, int i)
{
int k;
for(k=0; k<4; ++k)
r[k] = M[k][i];
}
inline void mat4x4_col(vec4 r, mat4x4 M, int i)
{
int k;
for(k=0; k<4; ++k)
r[k] = M[i][k];
}
inline void mat4x4_cpy_T(mat4x4 M, mat4x4 N)
{
int i, j;
for(j=0; j<4; ++j) {
for(i=0; i<4; ++i) {
M[i][j] = N[j][i];
}
}
}
而是推動矩陣,您只需創建一個副本,然後繼續工作和使用的那一個。然後,Poping轉爲取消分配副本並切換回您製作副本的矩陣。
+0
感謝您的回覆。會嘗試讓你知道:) – Bharath
相關問題
- 1. opengles 2.0二維場景圖實現
- 2. Android混合OpenGLES 1.0和OpenGLES 2.0
- 3. Opengles 2.0沒有VAO
- 4. Android OpenGLES 2.0按鈕
- 5. OpenGLES 2.0旋轉touchesMoved
- 6. OpenglES 2.0 GL_POINTS消失
- 7. 休眠:實現POP方法
- 8. OpenGLES 2.0組頂點顏色
- 9. 緩存Outputimages在OpenGLES 2.0
- 10. OpenGLES 2.0:gl_VertexID等效嗎?
- 11. Android OpenGLES 2.0 2D渲染
- 12. OpenGLES 2.0紋理渲染
- 13. XPath 2.0實現?
- 14. 從Opengles 1.0到Opengles 2.0的Android移植,紋理?
- 15. 如何在Pascal中實現Matrix操作?
- 16. 實現一個模板Matrix類
- 17. 用遞歸實現Stack的Pop方法
- 18. 在鏈表中實現push/pop(C++)
- 19. GLKit/OpenGLES 2.0:如何訂購基元?
- 20. OpenglES 2.0頂點着色器屬性
- 21. OpenGLES 2.0錯誤的深度緩衝位
- 22. JAVA-SAML 2.0實現
- 23. OpenGLES 1.1和2.0,同時支持
- 24. OpenglES 2.0 PNG阿爾法紋理重疊
- 25. 點不顯示在opengles 2.0中
- 26. 是pushMatrix()/ popMatrix()能夠堆疊嗎?
- 27. OpenGLES 2.0中的Android垂直和水平滾動
- 28. Android opengles 20呈現問題
- 29. Cakephp 2.0實現jQuery UI
- 30. python uwsgi 2.0 websocket實現
也許你應該檢查這個職位嗎? http://stackoverflow.com/questions/2918232/opengl-es-2-0-and-glpushmatrix-glpopmatrix – Marnix