engine/EngineModel.c
/*	Update the model's clipmins and clipmaxs based on each node's plane.

	This works because of the way brushes are expanded in hull generation.
	Each brush will include all six axial planes, which bound that brush.
	Therefore, the bounding box of the hull can be constructed entirely
	from axial planes found in the clipnodes for that hull.
*/
Update the model's clipmins and clipmaxs based on each node's plane.
This works because of the way brushes are expanded in hull generation.
Each brush will include all six axial planes, which bound that brush.
Therefore, the bounding box of the hull can be constructed entirely
from axial planes found in the clipnodes for that hull.
Update the model ' s clipmins and clipmaxs based on each node ' s plane . This works because of the way brushes are expanded in hull generation . Each brush will include all six axial planes which bound that brush . Therefore the bounding box of the hull can be constructed entirely from axial planes found in the clipnodes for that hull .
void Mod_BoundsFromClipNode (model_t *mod, int hull, int nodenum)
{
	mplane_t		*plane;
	BSPClipNode_t	*node;
	if (nodenum < 0)
		return; 
	node = &mod->clipnodes[nodenum];
	plane = mod->hulls[hull].planes + node->iPlaneNum;
	switch (plane->type)
	{
	case PLANE_X:
		if (plane->signbits == 1)
			mod->clipmins[0] = Math_Min (mod->clipmins[0], -plane->dist - mod->hulls[hull].clip_mins[0]);
		else
			mod->clipmaxs[0] = Math_Max (mod->clipmaxs[0], plane->dist - mod->hulls[hull].clip_maxs[0]);
		break;
	case PLANE_Y:
		if (plane->signbits == 2)
			mod->clipmins[1] = Math_Min (mod->clipmins[1], -plane->dist - mod->hulls[hull].clip_mins[1]);
		else
			mod->clipmaxs[1] = Math_Max (mod->clipmaxs[1], plane->dist - mod->hulls[hull].clip_maxs[1]);
		break;
	case PLANE_Z:
		if (plane->signbits == 4)
			mod->clipmins[2] = Math_Min (mod->clipmins[2], -plane->dist - mod->hulls[hull].clip_mins[2]);
		else
			mod->clipmaxs[2] = Math_Max (mod->clipmaxs[2], plane->dist - mod->hulls[hull].clip_maxs[2]);
		break;
	default:
		break;
	}
	Mod_BoundsFromClipNode (mod, hull, node->iChildren[0]);
	Mod_BoundsFromClipNode (mod, hull, node->iChildren[1]);
}
void Mod_BoundsFromClipNode ( model_t * mod , int hull , int nodenum ) { mplane_t * plane ; BSPClipNode_t * node ; if ( nodenum < 0 ) return ; node = & mod -> clipnodes [ nodenum ] ; plane = mod -> hulls [ hull ] . planes + node -> iPlaneNum ; switch ( plane -> type ) { case PLANE_X : if ( plane -> signbits == 1 ) mod -> clipmins [ 0 ] = Math_Min ( mod -> clipmins [ 0 ] , - plane -> dist - mod -> hulls [ hull ] . clip_mins [ 0 ] ) ; else mod -> clipmaxs [ 0 ] = Math_Max ( mod -> clipmaxs [ 0 ] , plane -> dist - mod -> hulls [ hull ] . clip_maxs [ 0 ] ) ; break ; case PLANE_Y : if ( plane -> signbits == 2 ) mod -> clipmins [ 1 ] = Math_Min ( mod -> clipmins [ 1 ] , - plane -> dist - mod -> hulls [ hull ] . clip_mins [ 1 ] ) ; else mod -> clipmaxs [ 1 ] = Math_Max ( mod -> clipmaxs [ 1 ] , plane -> dist - mod -> hulls [ hull ] . clip_maxs [ 1 ] ) ; break ; case PLANE_Z : if ( plane -> signbits == 4 ) mod -> clipmins [ 2 ] = Math_Min ( mod -> clipmins [ 2 ] , - plane -> dist - mod -> hulls [ hull ] . clip_mins [ 2 ] ) ; else mod -> clipmaxs [ 2 ] = Math_Max ( mod -> clipmaxs [ 2 ] , plane -> dist - mod -> hulls [ hull ] . clip_maxs [ 2 ] ) ; break ; default : break ; } Mod_BoundsFromClipNode ( mod , hull , node -> iChildren [ 0 ] ) ; Mod_BoundsFromClipNode ( mod , hull , node -> iChildren [ 1 ] ) ; }
Update the model's clipmins and clipmaxs based on each node's plane.
Update the model ' s clipmins and clipmaxs based on each node ' s plane .
//hit a leafnode //skip nonaxial planes; don't need them