Results 1 to 5 of 5

Thread: Load an .obj and modify it with your own matrix

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2002
    Posts
    11

    Load an .obj and modify it with your own matrix

    Hey, this is a 2-part question, since I think the 2 parts go together.
    Right now, I have this code:
    Code :
    glMultMatrixf(m);	
    glutWireTeapot(1.0);
    m is my own matrix, which modifies the Teapot.

    I need to:
    1. Load an .obj file and use it instead of the teapot, and
    2. Apply my own matrix to the object.

    I think I will figure out how to do part 2, as long as part 1 will give me a matrix with an object. Therefore, my question reduces to this: How can I load the object, so it will fit in my own matrix ? or better yet in GL's matrix, if one exists ? I tried looking around, but haven't been able to find exactly what I was looking for. I'll appreciate any help. (I am trying to find out what I can and what I can't do in OpenGL)

    I'm new to OpenGL, so please be descriptive !

    thanks !
    Dennis

  2. #2
    Junior Member Newbie
    Join Date
    Nov 2002
    Location
    Troy, NY, US
    Posts
    3

    Re: Load an .obj and modify it with your own matrix

    Hmmm, could you make your questions more specific? Anyways, i will try to help as best I can.

    When you say you want to modify the matrix I assume you want to do some sort of transformation and probably a translation, rotation or scaling.
    glTanslatef(float x, float y, float z)
    glRotatef(float angle, float x, float y, float z)
    glScalef(float x, float y, float z)
    Those are the most basic and versatile functions there are. Scale with 0.5 values and your teapot will be half as big. Scale with 2.0 and your teapot will be twice as big. Specify an angle with Rotate and then set one of the three remaining parameters to 1.0 and the rest to 0.0. So if you wanted to rotate the teapot about the y axis by 23 degrees you would use glRotate(23.0, 0.0, 1.0, 0.0). Translate is very straight forward if you understand what the other two functions do.

    Secondly, when you say .obj file i assume you mean from Maya. download the glut library. you can find it somewhere on this site. include glm.h and glm.c Now just use the following code in the suggested functions and you should be all set and remember to set at least one material for te model
    //init function
    GLMmodel* theModel = new GLMmodel;
    theModel = glmReadOBJ("MyFile.obj");
    //rendering function
    glmDraw(theModel, GLM_SMOOTH);
    See the header file for advanced features. Hope this helps

  3. #3
    Member Newbie
    Join Date
    Aug 2002
    Location
    London, England
    Posts
    34

    Re: Load an .obj and modify it with your own matrix

    or are you wanting to morph the imported .obj file into other types of object (e.g. so that the teapot becomes a house)?

  4. #4
    Junior Member Newbie
    Join Date
    Nov 2002
    Posts
    11

    Re: Load an .obj and modify it with your own matrix

    thanks,
    I don't know if it's from Maya or not, I'll look it up.
    What I need to do is to stay away from OpenGL's functions as much as possible. Why ? Because that's our assignment. We need to implement things ourselves as much as possible.
    So, I can't use rotate, scale, etc., unless those are my own functions.
    I will need to implement my own object holder, and its own datastructure.

    The code you had is more like what I'm looking for, except I will need to implement the loading functions myself:
    GLMmodel* theModel = new GLMmodel;
    theModel = glmReadOBJ("MyFile.obj");
    //rendering function
    glmDraw(theModel, GLM_SMOOTH);

    The last line shows how to draw the model, and my question is how do I scale using GL functions ? That's my original question #2, just worded differently. The answer will probably set me on the right way.

    thanks,
    Dennis

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Load an .obj and modify it with your own matrix

    You would scale your OBJ just like any other object. In openGL you define in the matrix the operations to be done before drawing the object.

    LoadOBJ();
    glPushMatrix()
    glTranslatef(.....)
    glRotatef(.....)
    glScalef(.......) // scale object
    DrawOBJ()
    glPopMatrix()

    The same would apply to your own matrix routine.

    My_matrix_call(M)
    Draw_OBJ()


    Originally posted by DennisMV:
    thanks,
    I don't know if it's from Maya or not, I'll look it up.
    What I need to do is to stay away from OpenGL's functions as much as possible. Why ? Because that's our assignment. We need to implement things ourselves as much as possible.
    So, I can't use rotate, scale, etc., unless those are my own functions.
    I will need to implement my own object holder, and its own datastructure.

    The code you had is more like what I'm looking for, except I will need to implement the loading functions myself:
    GLMmodel* theModel = new GLMmodel;
    theModel = glmReadOBJ("MyFile.obj");
    //rendering function
    glmDraw(theModel, GLM_SMOOTH);

    The last line shows how to draw the model, and my question is how do I scale using GL functions ? That's my original question #2, just worded differently. The answer will probably set me on the right way.

    thanks,
    Dennis


    [This message has been edited by nexusone (edited 11-17-2002).]

Similar Threads

  1. Load the current Matrix
    By Zenith in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 09-15-2017, 12:52 PM
  2. Using matrix stack - my code seems to modify the whole stack
    By chromosom in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-04-2014, 03:12 AM
  3. load matrix after glFrustum
    By jack_aerospace in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-30-2013, 07:38 PM
  4. Push Pop matrix VS Load identity??
    By LostInTheWoods in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-01-2002, 02:35 PM
  5. modify tranformation matrix
    By manu in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-04-2001, 02:55 AM

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