engine/EngineModel.c
/*	Calculate bounds of alias model for nonrotated, yawrotated, and fullrotated cases
*/
Calculate bounds of alias model for nonrotated, yawrotated, and fullrotated cases
Calculate bounds of alias model for nonrotated yawrotated and fullrotated cases
void Model_CalculateMD2Bounds(model_t *mModel, MD2_t *mMD2Model)
{
	int i, j;
	MD2Frame_t *mFrame;
	for (i = 0; i < 3; i++)
	{
		loadmodel->mins[i] = loadmodel->ymins[i] = loadmodel->rmins[i] = 999999.0f;
		loadmodel->maxs[i] = loadmodel->ymaxs[i] = loadmodel->rmaxs[i] = -999999.0f;
	}
	mFrame = (MD2Frame_t*)((uint8_t*)mMD2Model + mMD2Model->ofs_frames + mMD2Model->framesize);
	if(!mFrame)
		Sys_Error("Invalid frame encountered when calculating MD2 bounds! (%s)\n", mModel->name);
#if 1
	MathVector3f_t
		mvMins = { 0, 0, 0 }, mvMaxs = { 0, 0, 0 },
		mvCurMins, mvCurMaxs;
	for (j = 0; j < mMD2Model->num_frames; j++)
	{
		for (i = 0; i < 3; i++)
		{
			mvCurMins[i] = mFrame->translate[i];
			mvCurMaxs[i] = mvCurMins[i] + mFrame->scale[i] * 255;
			if (mvCurMins[i] < mvMins[i])
				mvMins[i] = mvCurMins[i];
			if (mvCurMaxs[i] > mvMaxs[i])
				mvMaxs[i] = mvCurMaxs[i];
		}
		mFrame++;
	}
#else
	MathVector3f_t mvMins, mvMaxs;
	for (i = 0; i < 3; i++)
	{
		mvMins[i] = mFrame->translate[i];
		mvMaxs[i] = mvMins[i] + mFrame->scale[i] * 255;
	}
#endif
	if (Math_VectorCompare(mvMins, g_mvOrigin3f) &&	Math_VectorCompare(mvMaxs, g_mvOrigin3f))
	{
		Con_Warning("Suspicious model size! (%s)\n", mModel->name);
		Math_VectorSet(-32, mvMins);
		Math_VectorSet(32, mvMaxs);
	}
	Math_VectorCopy(mvMins, loadmodel->mins);
	Math_VectorCopy(mvMaxs, loadmodel->maxs);
	Math_VectorCopy(loadmodel->mins, loadmodel->rmins);
	Math_VectorCopy(loadmodel->maxs, loadmodel->rmaxs);
	Math_VectorCopy(loadmodel->mins, loadmodel->ymins);
	Math_VectorCopy(loadmodel->maxs, loadmodel->ymaxs);
}
void Model_CalculateMD2Bounds ( model_t * mModel , MD2_t * mMD2Model ) { int i , j ; MD2Frame_t * mFrame ; for ( i = 0 ; i < 3 ; i ++ ) { loadmodel -> mins [ i ] = loadmodel -> ymins [ i ] = loadmodel -> rmins [ i ] = 999999.0f ; loadmodel -> maxs [ i ] = loadmodel -> ymaxs [ i ] = loadmodel -> rmaxs [ i ] = -999999.0f ; } mFrame = ( MD2Frame_t * ) ( ( uint8_t * ) mMD2Model + mMD2Model -> ofs_frames + mMD2Model -> framesize ) ; if ( ! mFrame ) Sys_Error ( " \n " , mModel -> name ) ; #if 1 MathVector3f_t mvMins = { 0 , 0 , 0 } , mvMaxs = { 0 , 0 , 0 } , mvCurMins , mvCurMaxs ; for ( j = 0 ; j < mMD2Model -> num_frames ; j ++ ) { for ( i = 0 ; i < 3 ; i ++ ) { mvCurMins [ i ] = mFrame -> translate [ i ] ; mvCurMaxs [ i ] = mvCurMins [ i ] + mFrame -> scale [ i ] * 255 ; if ( mvCurMins [ i ] < mvMins [ i ] ) mvMins [ i ] = mvCurMins [ i ] ; if ( mvCurMaxs [ i ] > mvMaxs [ i ] ) mvMaxs [ i ] = mvCurMaxs [ i ] ; } mFrame ++ ; } #else MathVector3f_t mvMins , mvMaxs ; for ( i = 0 ; i < 3 ; i ++ ) { mvMins [ i ] = mFrame -> translate [ i ] ; mvMaxs [ i ] = mvMins [ i ] + mFrame -> scale [ i ] * 255 ; } #endif if ( Math_VectorCompare ( mvMins , g_mvOrigin3f ) && Math_VectorCompare ( mvMaxs , g_mvOrigin3f ) ) { Con_Warning ( " \n " , mModel -> name ) ; Math_VectorSet ( -32 , mvMins ) ; Math_VectorSet ( 32 , mvMaxs ) ; } Math_VectorCopy ( mvMins , loadmodel -> mins ) ; Math_VectorCopy ( mvMaxs , loadmodel -> maxs ) ; Math_VectorCopy ( loadmodel -> mins , loadmodel -> rmins ) ; Math_VectorCopy ( loadmodel -> maxs , loadmodel -> rmaxs ) ; Math_VectorCopy ( loadmodel -> mins , loadmodel -> ymins ) ; Math_VectorCopy ( loadmodel -> maxs , loadmodel -> ymaxs ) ; }
Calculate bounds of alias model for nonrotated, yawrotated, and fullrotated cases
Calculate bounds of alias model for nonrotated yawrotated and fullrotated cases
// Reset everything to its maximum size. // Go through all the frames and figure out the best sizing. // Check that the size is valid. // This should never happen, but if it does, give a warning. // Then give us a default size.