Get vertex information after transformation

Say I have a vertex at (1.0, 1.0, 1.0).
Its coordinates are recorded in variables:

float x=1.0;
float y=1.0;
float z=1.0;

Then I rotate the ModelView Matrix by 45 degree to y axis.

glRotatef(45.0, 0.0, 1.0, 0.0);
glVertex3f(x, y, z);

How could I get the information about the transformed coordinates in OpenGL? In this example, I want to get the values of x, y and z after rotate.
Because I want to create some moving cubes which would interact with the ball in a game, I need to know the new positions of the vertices of the cube then recalculate the surfaces for collision detection.

One method (which might not be the best, but just came into my head) would be to get the current modelview and projection matrices and then do the multiplication yourself.
Each vertex as it goes down the pipeline, is multiplied by these two matrices. The problem is I can’t remember in which turn. You might want to check out the OpenGL Programming Guide. An old version should be lying around over the 'net.

you should do mathematics for that. Just know where are the center of rotations, the axis and the angle to rotate. And do some cos and sin regarding the plane on which you are rotating. There are many documentation about this over the net.
You can use other mathematics means but they are more complicated.

Hi! I agree with moucard, you could do that by multiplying the vertex by the matrixes, but I don’t know what of them and in what order… :slight_smile: I think this must be the best way to do that, since that must be the way Opengl performs to calculate the new vertex position. See ya!!

Ah, and I thought that multiplying by the modelview matrix after the rotation, you’ll be indirectly applying the mathematical formulas that jide talked about… That’s it:

Xu = Xo * cos(angle) - Yo * sin(angle)
Yu = Yo * cos(angle) + Xo * sin(angle)

If translation were around the z-axis…

See ya!!