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 codingabove the function Mod_LoadAliasFrame int aliasbboxmins[3], aliasbboxmaxs[3]; in the function Mod_LoadAliasFrame 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]; } 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]); } in the function Mod_LoadAliasGroup 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]; } 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]); } in the function Mod_LoadAliasModel // // load the frames // posenum = 0; pframetype = (daliasframetype_t *)&pintriangles[pheader->numtris]; aliasbboxmins[0] = aliasbboxmins[1] = aliasbboxmins[2] = 99999; aliasbboxmaxs[0] = aliasbboxmaxs[1] = aliasbboxmaxs[2] = -99999; 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; 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]; } 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. |