Results 1 to 8 of 8

Thread: Vertices and modelling transformations

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2006
    Location
    Manila
    Posts
    7

    Vertices and modelling transformations

    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.

  2. #2
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,931

    Re: Vertices and modelling transformations

    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

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2006
    Location
    Manila
    Posts
    7

    Re: Vertices and modelling transformations

    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 ^_^

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659

    Re: Vertices and modelling transformations

    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]...

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2006
    Location
    Manila
    Posts
    7

    Re: Vertices and modelling transformations

    thanks a lot. I will try this ^_^

  6. #6
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,931

    Re: Vertices and modelling transformations

    Or muuuch simpler, something like(pseudocode):

    Code :
     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"

  7. #7
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659

    Re: Vertices and modelling transformations

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

  8. #8
    Junior Member Newbie
    Join Date
    Jul 2006
    Location
    Manila
    Posts
    7

    Re: Vertices and modelling transformations

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

Similar Threads

  1. Hardware Transformations vs Software Transformations
    By killersquirrelz in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 12-05-2004, 04:43 AM
  2. Replies: 1
    Last Post: 12-08-2003, 05:04 PM
  3. 3D modelling
    By tony_ee81 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-24-2002, 12:13 AM
  4. Replies: 1
    Last Post: 08-30-2000, 10:54 AM
  5. Modelling
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 08-19-2000, 09:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean