James
James

Reputation: 5

Retrieve Vertex Coordinates

My question is:

Is there a way to retrieve the coordinates of a vertex after translations or rotation?

Example: x = 10, y = 10, z = 0

After a series of calls to glTranslate or glRotate how can I know the actual status of x, y and z?

Thanks.

Upvotes: 0

Views: 1980

Answers (1)

fen
fen

Reputation: 10125

this is not possible... opengl sends your vertex data to the GPU and only on GPU you can get them after the transformation.

to get transformed vertices you have to multiply them by the matrix on your own

for each vertex:
   vertex_transformed = matrix * vertex

in old OpenGL:

glGetFloatv(GL_MODELVIEW_MATRIX, m);
x = pos.x*m[0] + pos.y*m[4] + pos.z*m[8] + m[12];
y = pos.x*m[1] + pos.y*m[5] + pos.z*m[9] + m[13];
z = pos.x*m[2] + pos.y*m[6] + pos.z*m[10] + m[14];

some more advanced ways is to use transform feedback and store those transformed vertices into a buffer (but still this buffer will be stored on the GPU).

Upvotes: 4

Related Questions