void CRagdollProp::CalcRagdollSize( void )
{
	Vector minbox, maxbox;

	ExtractBbox( GetSequence(), minbox, maxbox );
	SetCollisionBounds( minbox, maxbox );

	if ( m_ragdoll.list[0].pObject )
	{
		Vector rootPos, rootWorldPos;
		m_ragdoll.list[0].pObject->GetPosition( &rootWorldPos, NULL );
		WorldToEntitySpace( rootWorldPos, &rootPos );

		// BUGBUG: This doesn't work because the sequence doesn't necessarily include
		//		   the extrema of pose space.
		// An algorithm that should work correctly is to store a radius in each bone
		// Then walk the skeleton away from the root to each leaf, accumulating distance to parent
		// The node or leaf with the largest radius + Sum(dist to parent) is the ragdoll's radius
		// Next rev of the model file format, I'll add bone radius and fix this.
		Vector dist;
		const Vector &center = EntitySpaceCenter();
		int i;
		for ( i = 0; i < 3; i++ )
		{
			if ( rootPos[i] > center[i] )
			{
				dist[i] = rootPos[i] - EntitySpaceMins()[i];
			}
			else
			{
				dist[i] = EntitySpaceMaxs()[i] - rootPos[i];
			}
		}

		float radius = dist.Length();
		Vector curmins( -radius, -radius, -radius );
		Vector curmaxs( radius, radius, radius );
		SetCollisionBounds( curmins, curmaxs );
	}

	m_savedESMins = EntitySpaceMins();
	m_savedESMaxs = EntitySpaceMaxs();
	Relink();
}
Example #2
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CEnvBeam::Spawn( void )
{
	if ( !m_iszSpriteName )
	{
		SetThink( &CEnvBeam::SUB_Remove );
		return;
	}

	BaseClass::Spawn();

	m_noiseAmplitude = MIN(MAX_BEAM_NOISEAMPLITUDE, m_noiseAmplitude);

	// Check for tapering
	if ( HasSpawnFlags( SF_BEAM_TAPEROUT ) )
	{
		SetWidth( m_boltWidth );
		SetEndWidth( 0 );
	}
	else
	{
		SetWidth( m_boltWidth );
		SetEndWidth( GetWidth() );	// Note: EndWidth is not scaled
	}

	// if a non-targetentity endpoint was specified, transform it into local relative space
	// so it can move along with the base
	if (!m_vEndPointWorld.IsZero())
	{
		WorldToEntitySpace( m_vEndPointWorld, &m_vEndPointRelative );
	}
	else
	{
		m_vEndPointRelative.Zero();
	}


	if ( ServerSide() )
	{
		SetThink( &CEnvBeam::UpdateThink );
		SetNextThink( gpGlobals->curtime );
		SetFireTime( gpGlobals->curtime );

		if ( GetEntityName() != NULL_STRING )
		{
			if ( !(m_spawnflags & SF_BEAM_STARTON) )
			{
				AddEffects( EF_NODRAW );
				m_active = 0;
				SetNextThink( TICK_NEVER_THINK );
			}
			else
			{
				m_active = 1;
			}
		}
	}
	else
	{
		m_active = 0;
		if ( !GetEntityName() || FBitSet(m_spawnflags, SF_BEAM_STARTON) )
		{
			SetThink( &CEnvBeam::StrikeThink );
			SetNextThink( gpGlobals->curtime + 1.0f );
		}
	}

}