View Full Version : Load an .obj and modify it with your own matrix

DennisMV

11-15-2002, 09:03 PM

Hey, this is a 2-part question, since I think the 2 parts go together.

Right now, I have this 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

herhjg

11-15-2002, 10:56 PM

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

ribot

11-16-2002, 04:47 AM

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

DennisMV

11-16-2002, 09:26 PM

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

nexusone

11-17-2002, 02:12 AM

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

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