PDA

View Full Version : Applying Matrices to Vertices, and Saving the Transformed Vertices



12-08-2003, 03:20 AM
What should I do if I want to have matrix transformations not only affect vertices as they are drawn, but actually want to store their location in literal modelview space (thus, with the matrix transformation) in an array or something?

Like in skeletal animation. I will have an individual mesh attached to each bone, which will be stored in the communal vertex array. In skeletal animation, each bone has a transformation matrix; when you apply these to each mesh, in order, with pushes and pops when you go backwards, and draw each as you go (with glDrawRangeElements), it will output everything correctly in the model. However, the rest of your program will have no information about where in real space everything in your model is, since you used transformation matrices and don't have real vertices representing where the vertices in your meshes currently are relative to everthing else.

So how do you save a copy of the vertices having been transformed by the matrix?

randomnumbers23
12-08-2003, 05:04 PM
I'm trying to do the same thing as you (but for different reasons.. I need the transformed vertex coordinates for some kinematic analysis software I am writing).

As I understand it (and I may be wrong here), you just need to obtain the modelview matrix once all of your rotations, etc. have been performed, ie:

GLfloat mvmatrix[16];

...
(transformations here)
...
glGetFloatv (GL_MODELVIEW_MATRIX, mvmatrix);

Then just multiply this matrix by your vertex. Note thatthe vertex must be homogenous, ie: (x,y,z,1)

If anyone who knows could confirm that what I have just said is right, it'd be a real help as I am yet to get my code working properly and I'd love to know whether this is down to an error in the thought process or just an error in implementation.

rnd##