android - opengl es position after glRotatef and glTranslatef -
i'am new in opengl es. can helps me calculate world coordinates of cube after rotate , translate. example:
first rotate cube:
gl.glrotatef(90, 1, 0, 0);
change position
gl.gltranslatef(10, 0, 0);
how can calculate "new" world coordinates? read glgetfloatv(gl_modelview_matrix , matrix) not understand it. maybe can provide sample code.
edit:
found solution. android code
float[] matrix = new float[] { answers.
1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1,
};
matrix.rotatem(matrix, 0, rx, 1, 0, 0);
matrix.rotatem(matrix, 0, ry, 0, 1, 0);
matrix.rotatem(matrix, 0, rz, 0, 0, 1);
matrix.translatem(matrix, 0, x, y, z);
x = matrix[12];
y = matrix[13];
z = matrix[14];
although have answer part want, in terms of rest of question, you'd (please forgive me if make java errors, i'm not android person):
float[] matrix = new float[16]; gl.glgetfloatv(gl_modelview_matrix, matrix); // check out matrix[12], matrix[13] , matrix[14] world location // (0, 0, 0) [, 1)] mapped that getfloatv reads current value of modelview matrix float buffer specified. in opengl 4x4 matrices specified index 0 top left, index 3 lowest number in first column , 12 number furthest right in first row. that's referred column-major layout, though opengl faq isn't entirely happy term.
Comments
Post a Comment