Tutorial *71*

This "short" tutorial is about how to give mdl models correct bounding boxes. (Fixes the bug with disapearing Shamblers at the edge of the screen)

The code is "borrowed" from DarkPlace by Forest "LordHavoc" Hale and was showed to me by Victor "Vic" Luchits".

All changes are made in gl_model.c

Now lets get coding
above the function


	Mod_LoadAliasFrame

add


	int	aliasbboxmins[3], aliasbboxmaxs[3];

This will be our temporary holders for the fixed bounding box.

in the function


	Mod_LoadAliasFrame

replace


	for (i=0 ; i<3 ; i++)

	{

		// these are byte values, so we don't have to worry about

		// endianness

		frame->bboxmin.v[i] = pdaliasframe->bboxmin.v[i];

		frame->bboxmin.v[i] = pdaliasframe->bboxmax.v[i];

	}

with


	for (i=0 ; i<3 ; i++)

	{

		// these are byte values, so we don't have to worry about

		// endianness

		frame->bboxmin.v[i] = pdaliasframe->bboxmin.v[i];

		frame->bboxmax.v[i] = pdaliasframe->bboxmax.v[i];



		aliasbboxmins[i] = min (frame->bboxmin.v[i], aliasbboxmins[i]);

		aliasbboxmaxs[i] = max (frame->bboxmax.v[i], aliasbboxmaxs[i]);

	}

This is where we set the fixed bounding box to all "normal" models

in the function


	Mod_LoadAliasGroup

replace


	for (i=0 ; i<3 ; i++)

	{

		// these are byte values, so we don't have to worry about endianness

		frame->bboxmin.v[i] = pingroup->bboxmin.v[i];

		frame->bboxmin.v[i] = pingroup->bboxmax.v[i];

	}

with


	for (i=0 ; i<3 ; i++)

	{

		// these are byte values, so we don't have to worry about endianness

		frame->bboxmin.v[i] = pingroup->bboxmin.v[i];

		frame->bboxmax.v[i] = pingroup->bboxmax.v[i];



		aliasbboxmins[i] = min (frame->bboxmin.v[i], aliasbboxmins[i]);

		aliasbboxmaxs[i] = max (frame->bboxmax.v[i], aliasbboxmaxs[i]);

	}

This is where we set the fixed bounding box to all models using group animations.

in the function


	Mod_LoadAliasModel

after


	//

	// load the frames

	//



	posenum = 0;

	pframetype = (daliasframetype_t *)&pintriangles[pheader->numtris];

add


	aliasbboxmins[0] = aliasbboxmins[1] = aliasbboxmins[2] =  99999;

	aliasbboxmaxs[0] = aliasbboxmaxs[1] = aliasbboxmaxs[2] = -99999;

This is to reset our temporary holder for the bounding box.

a bit further down
replace


	mod->mins[0] = mod->mins[1] = mod->mins[2] = -16;

	mod->maxs[0] = mod->maxs[1] = mod->maxs[2] = 16;

with


	for (i = 0; i < 3; i++)

	{

		mod->mins[i] = aliasbboxmins[i] * pheader->scale[i] + pheader->scale_origin[i];

		mod->maxs[i] = aliasbboxmaxs[i] * pheader->scale[i] + pheader->scale_origin[i];

	}

This is where the model actually gets the fixed bounding box.

There we go. This was all that was needed. Now compile and go to end.bsp using notarget. Notice how Shub-Niggurath (not sure on the spelling) now is visible to the very last inch of its tentacles. Same with the shamblers. Stay tuned for more small but important tutorials in the future.



 
Sign up
Login:
Passwd:
[Remember Me]