Archived

This topic is now archived and is closed to further replies.

Scaling down MD2 models

This topic is 6018 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello again! I have just got a copy of the "OpenGL game programming" book and am trying to implement the MD2 quake 2 model loading code from it into my own game. I can sucessfuly load and display the models, but they are WAY too big for the rest of my world and I cant figure out their code enuff to work out how to make em smaller! Anyone else got/read the book and can explain how I could make them smaller please? Or are there standard scaling techniques I could use? Could I just make the rest of my world much bigger and zoom out? But I would prefer to be able to scale the models themselves for more control. Thanks loads for any suggestions/help! Adam

Share this post


Link to post
Share on other sites
Hi there!

Surely this is just a case of using glScalef().

As I remember, just push your matrix, rescale (using said function), draw your MD2 model, then pop the matrix.

Hope this helps!

Share this post


Link to post
Share on other sites
What values are you using for the scale?

Remember that 1.0f will leave the model at its original size. 0.5f will reduce the model by half. Try a value like 0.1f, let me know what happens....

Share this post


Link to post
Share on other sites
Thanks again

Right, I tried glScalef in the original MD2 source code and it *does* reduce the size of the model. But when I use it in the source code for my game (including the MD2 code) it *doesn''t* work. Im calling it in the same place too!

Share this post


Link to post
Share on other sites
quote:
Original post by WoolyUK
Hello again!

I have just got a copy of the "OpenGL game programming" book and am trying to implement the MD2 quake 2 model loading code from it into my own game.

I can sucessfuly load and display the models, but they are WAY too big for the rest of my world and I cant figure out their code enuff to work out how to make em smaller!

Anyone else got/read the book and can explain how I could make them smaller please? Or are there standard scaling techniques I could use?

Could I just make the rest of my world much bigger and zoom out? But I would prefer to be able to scale the models themselves for more control.

Thanks loads for any suggestions/help!

Adam


My MD2 code generates Vertex Normals, and scales the model.

http://www.nitrogl.com (it''s on the Code page)

Share this post


Link to post
Share on other sites
got some source for you...
That''s at least what I did
for (int i = 0; i < models[MD2_SOLDIER].m_iTriangles; i++) {
glBegin(GL_TRIANGLES);

glTexCoord2f((models[MD2_SOLDIER].m_index_list.a_s)/(float)textures[MOD_SOLDIER1].width, (models[MD2_SOLDIER].m_index_list[i].a_t)/(float)textures[MOD_SOLDIER1].height);
glVertex3f (models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list[i].a].x / scale,
models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list[i].a].y / scale,
models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list[i].a].z / scale);

glTexCoord2f((models[MD2_SOLDIER].m_index_list[i].b_s)/(float)textures[MOD_SOLDIER1].width, (models[MD2_SOLDIER].m_index_list[i].b_t)/(float)textures[MOD_SOLDIER1].height);
glVertex3f (models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list[i].b].x / scale,
models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list[i].b].y / scale,
models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list[i].b].z / scale);

glTexCoord2f((models[MD2_SOLDIER].m_index_list[i].c_s)/(float)textures[MOD_SOLDIER1].width, (models[MD2_SOLDIER].m_index_list[i].c_t)/(float)textures[MOD_SOLDIER1].height);
glVertex3f (models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list[i].c].x / scale,
models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list[i].c].y / scale,
models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list[i].c].z / scale);

glEnd();
}

scale is 35.0f in my program...
Hope that helps.


SnAkE''s Programming Resources

Share this post


Link to post
Share on other sites
quote:
Original post by WoolyUK
Hi does your MD2 loader support animation/movement? Cus it loads the model then sits there, or am I missing some keys?

Thanks

Adam


Yup, it supports animation.


Here how you animate it (put this in your render loop):

// i is increased every render (advance it by about 0.01 for now

i+=0.01f

// If i is greater than 1.0, reset it to 0.0, and advance Frame
if(i>1.0f)
{
i=0;
Frame++;
}

// If Frame is more than the total number of frames, reset Frame to 0, so it loops through all of the frames
if(Frame=MD2.header.numFrames-1) //Accual number of frames is numFrames-1
Frame=0;

// Render the MD2 model's frame (Frame is the first frame, Frame+1 is the next frame to interpolate to, i is the linear advancement of the interpolation)
MD2_DrawFrame(&MD2, Frame, Frame+1, i)

Edit:
The 'Frame' varible is an int, and 'i' is a float

Edit #2:

if(Frame=MD2.header.numFrames-1) //Accual number of frames is numFrames-1

should be:

if(Frame=MD2.header.numFrames-2) //Accual number of frames is numFrames-1

and

MD2_DrawFrame should be MD2_DrawFramei


Sorry about all the corrections (I haven't had a very good day)


Edited by - NitroGL on June 23, 2001 2:57:25 PM

Edited by - NitroGL on June 23, 2001 4:15:51 PM

Share this post


Link to post
Share on other sites
hi WoolyUK!

first of all i wanna say that this post is not thought to be
impolite. i say this coz in the past some arrogant wannabe elite
coders made fun about others on this forum.

>I have just got a copy of the "OpenGL game programming" book
>and am trying to implement the MD2 quake 2 model loading code
>from it into my own game.

>I can sucessfuly load and display the models, but they are WAY
>too big for the rest of my world and I cant figure out their
>code enuff to work out how to make em smaller!

this seems to be the "cut and paste" way of coding. so here
is an advice: "try to understand the code! read the book.
its not generaly bad to cut and paste stuff like most ppl say.
everybody does it, but some ppl more and others less. but
remember the most important thing is to understand what you are
doing. hope you understand what i mean ."

have fun coding!!
best regards
trigger

Share this post


Link to post
Share on other sites
Thanks for the comments/help guys Im working on it now

And trigger, I have read the code and mostly understand it. I just wanted to try and get it working before I spent time learning the ins and outs of it But yeah I know what u mean, and I do generally write my own code or rewrite existing code so that I understand it.

Cya!
Adam

Share this post


Link to post
Share on other sites
Yay!

Just to let u guys know I fixed the scale problem. I managed to get scalef (thanks!) working. - I was calling LoadIdentity before it, so I guess this prevented it from having anything to scale against which is why the model stayed the same size. Am I right? Cus when I removed it, it worked fine!

Anyway thanks everyone!

Adam

Share this post


Link to post
Share on other sites
Perhaps I should have been more explicit, but I didn''t say to use glLoadIdentity(), - loading a fresh matrix resets everything. I''m glad it works now!!!

Share this post


Link to post
Share on other sites
LoadIdentity() was there from something else - I forgot to delete it last time lol

And yeah Im enjoying the book it''s really helpful!

Thanks
Adam

Share this post


Link to post
Share on other sites
You probally did something vaguely like this

glscalef(...);
DrawModel(...);

and in your drawmodel function you did this:

glLoadIdentity();
.. draw model ..


LoadIdentity resets the matrix. Bye bye scales... :D

- Twilight Terror of Syntesis

Share this post


Link to post
Share on other sites