Scaling down MD2 models

Started by
14 comments, last by WoolyUK 22 years, 9 months ago
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
Advertisement
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!
Thanks for the reply, but that seems to make no difference
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....
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!

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)

Celeron ][ 566 @ 850256MB PC-100 CAS2 RAMDFI PA-61 Mainboard (250MB memory bandwidth sucks, it should be 500MB)ATI Radeon 32MB DDR LEWindows 98SE
Hi does your MD2 loader support animation/movement? Cus it loads the model then sits there, or am I missing some keys?

Thanks

Adam
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.a_t)/(float)textures[MOD_SOLDIER1].height);<br>					glVertex3f (models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list.a].x / scale,<br>								models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list.a].y / scale,<br>								models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list.a].z / scale);<br><br>					glTexCoord2f((models[MD2_SOLDIER].m_index_list.b_s)/(float)textures[MOD_SOLDIER1].width, (models[MD2_SOLDIER].m_index_list.b_t)/(float)textures[MOD_SOLDIER1].height);<br>					glVertex3f (models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list.b].x / scale,<br>								models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list.b].y / scale,<br>								models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list.b].z / scale);<br><br>					glTexCoord2f((models[MD2_SOLDIER].m_index_list.c_s)/(float)textures[MOD_SOLDIER1].width, (models[MD2_SOLDIER].m_index_list.c_t)/(float)textures[MOD_SOLDIER1].height);<br>					glVertex3f (models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list.c].x / scale,<br>								models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list.c].y / scale,<br>								models[MD2_SOLDIER].m_frame_list[models[MD2_SOLDIER].frame].vertex[models[MD2_SOLDIER].m_index_list.c].z / scale);<br><br>					glEnd();<br>} </pre> <br>scale is 35.0f in my program…<br>Hope that helps.<br>  </i>   <br><br> <a href="http://www.snake-programming.net">SnAkE''s Programming Resources</a>    
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
Celeron ][ 566 @ 850256MB PC-100 CAS2 RAMDFI PA-61 Mainboard (250MB memory bandwidth sucks, it should be 500MB)ATI Radeon 32MB DDR LEWindows 98SE
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
http://trigger.xenyon.net/

This topic is closed to new replies.

Advertisement