# load 3ds max models into opengl program

54 replies to this topic

### #21chingching

Member

• Members
• 38 posts

Posted 22 February 2006 - 12:57 AM

Anudhyan, really thanks you a lot!! I'll send my email address to you via email.
Hope that can help me a lot...:yes:

A lot of thanks.:worthy: Your kindness is appreciated.

### #22Anudhyan

New Member

• Members
• 15 posts

Posted 22 February 2006 - 04:13 AM

chingching,
I have sent the sample.
I hope you have recieved it...

### #23chingching

Member

• Members
• 38 posts

Posted 22 February 2006 - 07:05 AM

Hie all,
Regarding to the lib3ds, I had tried, but I blurrr with this
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
if (argc!=2) {
puts("***ERROR*** No 3DS file specified");
exit(1);
}
filename=argv[1];
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

And I blurrr with where to put the argument to load model.:sad:
Can someone kindly tell me about these? I'm so stuck.
Thanks a lot.

### #24chingching

Member

• Members
• 38 posts

Posted 22 February 2006 - 07:08 AM

Any other information are appreciated.

### #25Anudhyan

New Member

• Members
• 15 posts

Posted 22 February 2006 - 08:44 AM

To calculate the normals of the loaded object:

class object{

public:

char name[20];

int numVerts,numPolys;

vertex v[3000];

polygon p[3000];

mapcoord m[3000];

vertex n[3000];         //the normals

};

//-----------------------------------------------------------------------------

// Name: DotProduct(vertex,vertex)

// Desc: Returns the dot product of two vertices

//-----------------------------------------------------------------------------

vertex DotProduct(vertex v1,vertex v2)

{

vertex final;

final.x=(v1.y*v2.z)-(v1.z*v2.y);

final.y=(v1.z*v2.x)-(v1.x*v2.z);

final.z=(v1.x*v2.y)-(v1.y*v2.x);

return final;

}

//-----------------------------------------------------------------------------

// Name: Normalize(vertex)

// Desc: Normalizes a vertex

//-----------------------------------------------------------------------------

vertex Normalize(vertex v)

{

vertex result=v;

float l;

l=(sqrt(v.x*v.x +v.y*v.y +v.z*v.z));;

if(l==0)l=1;

result.x/=l;

result.y/=l;

result.z/=l;

return result;

}

//-----------------------------------------------------------------------------

// Name: CalculateNormals(object *)

// Desc: Calculates the normals of an object

//-----------------------------------------------------------------------------

void CalculateNormals(object *o)

{

int i;

vertex v1,v2,v3,b1,b2,normal;

int con[3000];

for(i=0;i<o->numPolys;i++)

{

v1.x=o->v[o->p[i].a].x;

v1.y=o->v[o->p[i].a].y;

v1.z=o->v[o->p[i].a].z;

v2.x=o->v[o->p[i].b].x;

v2.y=o->v[o->p[i].b].y;

v2.z=o->v[o->p[i].b].z;

v3.x=o->v[o->p[i].c].x;

v3.y=o->v[o->p[i].c].y;

v3.z=o->v[o->p[i].c].z;

b1.x=v2.x-v1.x;

b1.y=v2.y-v1.y;

b1.z=v2.z-v1.z;

b2.x=v3.x-v1.x;

b2.y=v3.y-v1.y;

b2.z=v3.z-v1.z;

normal = DotProduct(b1,b2);

normal = Normalize(normal);

con[o->p[i].a]+=1;

con[o->p[i].b]+=1;

con[o->p[i].c]+=1;

o->n[o->p[i].a].x+=normal.x;

o->n[o->p[i].a].y+=normal.y;

o->n[o->p[i].a].z+=normal.z;

o->n[o->p[i].b].x+=normal.x;

o->n[o->p[i].b].y+=normal.y;

o->n[o->p[i].b].z+=normal.z;

o->n[o->p[i].c].x+=normal.x;

o->n[o->p[i].c].y+=normal.y;

o->n[o->p[i].c].z+=normal.z;

}

for (i=0;i<o->numVerts;i++)

{

if(con[i]>0)

{

o->n[i].x/=con[i];

o->n[i].y/=con[i];

o->n[i].z/=con[i];

}

}

}

### #26monjardin

Senior Member

• Members
• 1033 posts

Posted 22 February 2006 - 02:26 PM

http://en.wikipedia...._line_interface
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

### #27chingching

Member

• Members
• 38 posts

Posted 22 February 2006 - 03:29 PM

Anudhyan, I'd tried your sample code, there is no compile error, but there are linking errors:

LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Trial.exe : fatal error LNK1120: 1 unresolved externals

Is there any problem with lib?

Since I haven't put any texture in my model, thus I comment the segments of loading texture.

Well, my model is a house, and the house is build up with a number of polygons plus furnitures inside, will that a problem when loading it? And I'll have more houses in my project.

Thanks a lot for helping me.:worthy:

### #28chingching

Member

• Members
• 38 posts

Posted 22 February 2006 - 03:32 PM

Well, Monjardin, thanks for providing me those info...

### #29Anudhyan

New Member

• Members
• 15 posts

Posted 22 February 2006 - 05:01 PM

chingching,
I forgot to tell you that all the geometry should be attached together.
As for the link error...I have never seen it. I use MVC++ 6. Did you use the .dsp file I provided? I had it linked to only these libs:
opengl32.lib glu32.lib glaux.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
And if your model has more than 3000 polys,increase the array sizes in the object class.

### #30Reedbeta

DevMaster Staff

• 5307 posts
• LocationBellevue, WA

Posted 22 February 2006 - 06:27 PM

The link error means the main() function is missing...chingching, did you compile the code Anudhyan posted all by itself? It's just a couple of functions, so you need to have your own application around it...
reedbeta.com - developer blog, OpenGL demos, and other projects

### #31chingching

Member

• Members
• 38 posts

Posted 23 February 2006 - 10:32 AM

Anudhyan, I'd already solve those linking errors, erm...too sad that no model displayed. Well, I'll try to change the coding to win32 console application style, coz I always used to that. But, your sample code really helps me a lot. Thanks. I'll trial and trial to check why the model didn't displayed as there is no error. If you got any idea, kindly give me ya~~:lol:
Thanks.

### #32chingching

Member

• Members
• 38 posts

Posted 23 February 2006 - 10:36 AM

Yes, Reedbeta, I got run whole sample coding given by Anudhyan. Anyway, thanks for telling me that.
Well, can you tell me what're these about?

glutInit(&argc, argv);
if (argc!=2) {
puts("***ERROR*** No 3DS file specified");
exit(1);
}
filename=argv[1];

Thanks!!

### #33chingching

Member

• Members
• 38 posts

Posted 23 February 2006 - 10:46 AM

Hi all,
I'm here really appreciate the warmer hands from all of you.
As the time goes by, I really nervous and scare that I can't complete my project on time, as I can't even load a model into my openGL program. Well, I got 4 house models to be loaded, plus some furnitures inside the houses. :sad:
After loading models, I have to do navigation somemore, and the hardest part for me -- Collision Detection .:wacko:
So, really thanks you all for lending me your warmest hands. Hope to get more info or idea from you all during my project going on.
Really thanks a lot.:worthy:

### #34Anudhyan

New Member

• Members
• 15 posts

Posted 23 February 2006 - 12:49 PM

Chingching,
Do you want another sample made by me -- its all about collision detection and response ?
I am happy to know that you could compile it. But 90% of the times you won't
be able to see the models - if you randomly just send in a model with no planning. First, there is the scale factor. Your model could either be too small or too big. Second, your model could be far away from the origin. Make sure
its centres around 0,0,0.
My advice is to use the model I provided and use the exact gluLookAt coordinates in my original code.
Next, go to 3ds max and centre and scale your model so it resembles my box.
And then use your model in place of the box.
Didn't you see the box when you first compile and run the unaltered code ?
First use a simple model.Then move on to better things.
Note that everything should be attached together and be 1 object.
If you model has more than 3000 verts/polys increase the values in the object
class.

### #35chingching

Member

• Members
• 38 posts

Posted 23 February 2006 - 03:06 PM

Anudhyan, a lot of thanks here if you can send me the sample code via email.:yes:
And I'll check my model's coord and its centre.
Ya, the box is displayed while I compile your original code.
Somemore,you said that all geometry must be attached together become one object, but my model is house with some furniture inside, is it possible to do? Or maybe I can't what you mean...coz I more on coding part, and my partner is more on modeling.:wacko:

### #36Anudhyan

New Member

• Members
• 15 posts

Posted 23 February 2006 - 04:54 PM

Um... It is of course possible to attach all the geometry together (why not ?) The only problem is that you have to use only one texture for one object.
There is nothing preventing you from exporting every object as a different file using export selected. Then importing every object differently. If the furniture are similar then you should load only the chair/table and scatter them around the house...
Remember that without any view transformations in opengl, the eye position will be at 3ds max's 0,0,0 and will be looking towards the z- axis. i.e. downward in 3ds max.
If you keep having trouble displaying your model, you could mail me your house model and I will transform it as required.

### #37Reedbeta

DevMaster Staff

• 5307 posts
• LocationBellevue, WA

Posted 23 February 2006 - 04:54 PM

chingching said:

Yes, Reedbeta, I got run whole sample coding given by Anudhyan. Anyway, thanks for telling me that.
Well, can you tell me what're these about?

glutInit(&argc, argv);
if (argc!=2) {
puts("***ERROR*** No 3DS file specified");
exit(1);
}
filename=argv[1];

Thanks!!

Chingching, there have already been several links posted in this thread that should enable you to figure out what the above does. argc and argv are references to the command-line arguments provided to the program. You have to execute the program from a command line like this (suppose the program is called 3dsview): 3dsview my3dsfile.3ds. This provides the filename "my3dsfile.3ds" as a command-line argument.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #38chingching

Member

• Members
• 38 posts

Posted 24 February 2006 - 05:44 AM

Anudhyan, thanks you. I'd already mail to you.

### #39chingching

Member

• Members
• 38 posts

Posted 24 February 2006 - 05:44 AM

Reedbeta, thanks for telling me that. I'll try again.

### #40geon

Senior Member

• Members
• 939 posts

Posted 24 February 2006 - 11:47 AM

chingching said:

(...) And I blurrr with where to put the argument to load model.:sad:
Can someone kindly tell me about these? I'm so stuck.
Thanks a lot.

when you succuessfully compiled your model, open up a console and tyupe in the name of your executable, followed by your .3DS-file.

Alternatively, on windows, just drag-n-drop your 3DS-file onto the executable.

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users