View Full Version : getting vertice values after transformtions

eckiller

04-27-2000, 07:36 PM

Hi,

I am making a 3D map editor. The user has options to create a variety of 3D models and place them in the scene as he likes. When designing this i saw a potential problem. When the user does some transformations on the models and he sets things up in the scene how he likes, how do i get the models vertice points??? I need the vertice points after the transformations so that i can save them to file.

Thanks.

Easy. You know the untransformed point v, and the matrix M to transform the point, then you want to store the vector Mv.

i'm guessing you know the untransformed vertex, because you have to be describing it to opengl somewhere along the line, and i'm also guessing you know how you want to move the object with translation and rotation. so... the easiest soln would be to set up your modelview matrix for an object, suck it into an array, and multiply each vertex manually (or, at least, use gluProject with an identity projection matrix).

make sense?

cheers,

john

Another solution is to save the original vertices coordinates (that you have) with the transformation matrix (that you must have as you display !).

If you are only interested in the transformed vertices then, yes, just multiply the original by the transformation matrix...

Eric

eckiller

04-28-2000, 08:29 AM

Is this as easy as;

new_x = current_x * transformation_matrix;

new_y = current_y * transformation_matrix;

new_z = current_z * transformation_matrix;

???

no; it's v'=Tv http://www.opengl.org/discussion_boards/ubb/tongue.gif

but the idea is the same: since you know the original vertex, v, and you know the transform matrix, T, (because the user is playing with it, and you're carefully making note of what happens), then yo ucan work out v' (the NEW vertex!) by multiplying T and v. you can do this yourelf ('cause I'm guessing you know about matrix multiplication and homogeneous coordinates), but you can just as easily use gluProject and save yourself the effort.

SpaceCadet

05-01-2000, 08:30 PM

for x rotations,

point[1] = (point[1] * cos(angle)) - (point[2] * sin(angle)); // new y position

point[2] = (point[1] * sin(angle)) + (point[2] * cos(angle)); // new z position

for y rotations,

point[0] = (point[0] * cos(angle)) + (point[2] * sin(angle)); // new x position

point[2] = (point[0] * -sin(angle)) + (point[2] * cos(angle)); // new z position

for z rotations,

point[0] = (point[0] * cos(angle)) - (point[1] * sin(angle)); // new x position

point[1] = (point[0] * sin(angle)) + (point[1] * cos(angle)); // new y position

this isn't as effiecent as using the built in gl matrix stuff, but it is easy to understand, at least from my point of view http://www.opengl.org/discussion_boards/ubb/smile.gif. I'm not that experienced with gl yet.

[This message has been edited by SpaceCadet (edited 05-01-2000).]

er... yes... and the code to rasterise that polygon for a VGA card is as follows... ;>

hmm. suppose you have a vertex you know is at [1,2,3], and you do some arbitary transformations to it, and you want to know the world coordinates of the vertex after these transformations so you can save it to your file. Here's some code to do it. It's not neccessarily the BEST way of doing this, and it's written off the top of my head, but here goes.

gldouble modelview[16], vprime[4], v[4]={1.0, 2.0, 3.0, 1.0};

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glRotatef(1.0, 2.0, 3.0, 4.0);

glTranslatef(5.0, 6.0, 7.0);

/* now we have the transformation matrix T... */

glGetDoublev(GL_MODELVIEW_MATRIX, modelview);

/* now we have to transform the point... */

int i, j;

for(i=0; i<4; i++) {

vprime[i]=0.0;

for(j=0; j<4; j++) {

vprime[i]+=modelview[j*4+i]*v[i];

}

}

/* convert the transformed pt from homogeneous to cartisian pt */

for(i=0; i<3; i++)

vprime[i]/=vprime[3];

and now our transformed point v[] is in vprime[]. veeeeery laborious, but you should get the idea..

hope this helps!

cheers,

John

i THINK the matrix is column major... but i could be wrong.

bug fix:

the inner statement in the inner for loop shuold read

vprime[i]+= ... *v[j];

^

not i. but it's just matrix multiplication, so you should be able to figure it out ;-)

cheers,

John

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.