View Full Version : Vertices and modelling transformations

addict_fanatic

07-12-2006, 08:12 AM

I'm new/beginner to opengl and can somebody please enlighten me regarding vertices and the modelling transformations? I'm using c++. What I'm trying to do is create several layers of the model for my preliminary computations.

Question 1: Lets say I have a set of vertices from a 3D mesh, (imported from 3DS, a wireframe mesh), what happens if I try to scale the model up by let's say 2 units, will the vertex coordinate values change to it's proper and correpsonding location? Or some other matrix might be able to record these changes?

Question 2: Any idea how to keep track the transformed vertex coordinates? When I try to scale the model up, I would like to record the "scaled-up" coordinates of the new mesh into an array of structured vertices. Is this possible? How?

Hoping for a reply soon.

Thanks.

Zengar

07-12-2006, 09:44 AM

I don't really understand what you are asking.

:-/

Are you scaling using the glScale operation? If so, you shoudl know that all vertices are being transformed my the modelview matrix when submitted. The glScale operation just modifiers the matrix to apply the scaling. This way, every vertex passed to the GL after the glScale call will be automatically scaled (provided you don't alter the matrix with other calls, like glLoadIdentity)

You can (theoretically) store the transformed vertex coordinates by writing some shaders and rendering to a vertex array, but this may be a bit of an overkill if you are still new to GL. You are better of by scaling the model manually (just copy the vertex data and multiply every vertex by a factor, or apply a matrix to it).

Hope it helps

addict_fanatic

07-12-2006, 10:22 PM

Thanks it sure did. What I'm trying to do is I'm trying to create several "layers" (lets say 3 layers) of wireframed mesh by applying the glScale operation. And these "layers" (1,2,3) are recognized as different meshes that can be transformed independently. In doing so, the vertices should be saved into a structured vertex array. So that's what I'm trying to do.

I have a question though. "You are better of by scaling the model manually (just copy the vertex data and multiply every vertex by a factor, or apply a matrix to it)."

How am I going to do this, any ideas? Thanks ^_^

RigidBody

07-13-2006, 01:31 AM

first create the transformation matrix:

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glScalef(2.0, 2.0, 2.0);

then read the transformation matrix:

GLfloat mm[4][4];

glGetFloatv(GL_MODELVIEW_MATRIX, mm);

finally, transform the originally geometry:

typedef struct { float x, y, z; } Node;

Node N[1000], Ntrans[1000];

// INITIALIZE ORIGINAL NODES

N[i].x = ...

N[i].y = ...

N[i].z = ...

...

// TRANSFORM NODES

Ntrans[i].x = mm[0][0]*N[i].x + mm[0][1]*N[i].y + mm[0][2]*N[i].z + mm[0][3];

Ntrans[i].y = mm[1][0]*N[i].x + mm[1][1]*N[i].y + mm[1][2]*N[i].z + mm[1][3];

Ntrans[i].z = mm[2][0]*N[i].x + mm[2][1]*N[i].y + mm[2][2]*N[i].z + mm[2][3];

like always, i'm not quite sure about the matrix indices. maybe you have to exchange them mm[i][j]->mm[j][i]...

addict_fanatic

07-13-2006, 07:56 AM

thanks a lot. I will try this ^_^

Zengar

07-13-2006, 09:09 AM

Or muuuch simpler, something like(pseudocode):

array rescalevertices(arary vertices, double scale)

{

array r = copy(vertices)

for(i=0; i<r.length; i++) {

r.x = r.x*scale;

r.y = r.y*scale;

r.z = r.z*scale;

}

return r

}

If you insist on using matrices(more flexible as they can store ANY transformation, but much slower), do a search in google. There are plenty good articles and tutorials on it, like the "Matrix FAQ"

RigidBody

07-13-2006, 09:12 AM

of course. but if you use the modelview matrix, it works with an arbitrary combination of scales, rotations and translations.

addict_fanatic

07-14-2006, 10:14 AM

Thanks all and I think zengar's pseudocode already solved my problem. Thanks so much!

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