UTIL_BloodDecalTrace

From Valve Developer Community
Jump to: navigation, search

UTIL_BloodDecalTrace is a UTIL provided in the Source code for creating Blood decals. Currently, this only directly supports Red blood ( bloodColor = 0, or BLOOD_COLOR_RED), which will create a red blood decal. Any other blood color will result in a yellow blood decal.

Usage

//-----------------------------------------------------------------------------
// Purpose: 
//          
// Input  : trace_t - *pTrace | trace_t class that has been configured with a trace.
// Input  : int - bloodColor | Type of blood to create. Only supports 0, otherwise yellow blood
// Output : 
//-----------------------------------------------------------------------------
void UTIL_BloodDecalTrace( trace_t *pTrace, int bloodColor )


Examples

trace_t	tr;	

CBasePlayer *pPlayer;
pPlayer = ToBasePlayer( GetOwnerEntity() );

Vector forward;
AngleVectors( GetAbsAngles(), &forward );
UTIL_TraceLine ( GetAbsOrigin(), GetAbsOrigin() + forward * 128, 
	MASK_SOLID_BRUSHONLY, pPlayer, COLLISION_GROUP_NONE, & tr);

//Now that we have a trace set up, create a BloodDecal at the end.
UTIL_BloodDecalTrace( &tr, BLOOD_COLOR_RED );
//Create 8 yellow blood decals within +/- 16 units of the object.
//This is from the npc_antliongrub.
trace_t tr;
Vector	vecStart;
Vector	vecTraceDir;

//GetVectors appears to take world-relative values
//And make them relative to the entity.
//So in this case, it's changing the value of vecTraceDir to
//be 'straight up' from the entity.
GetVectors( NULL, NULL, &vecTraceDir );

//Makes all of the values negative -- in this case
//It's taking the current "up" vector, and turning it into
//a "down" vector, or 'below' the entity.
vecTraceDir.Negate(); 

//Create 8 random decals that are within +/- 16 units of the 'down' vector we just got.
for ( int i = 0 ; i < 8; i++ )
{
	vecStart.x = vecOrigin.x + random->RandomFloat( -16.0f, 16.0f );
	vecStart.y = vecOrigin.y + random->RandomFloat( -16.0f, 16.0f );
	vecStart.z = vecOrigin.z + 4;

	UTIL_TraceLine( vecStart, vecStart + ( vecTraceDir * (5*12) ), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr );

	if ( tr.fraction != 1.0 )
	{
		UTIL_BloodDecalTrace( &tr, BLOOD_COLOR_YELLOW );
	}
}