void C_SmokeStack::QueueLightParametersInRenderer()
{
	m_Renderer.SetBaseColor( Vector( m_clrRender->r / 255.0f, m_clrRender->g / 255.0f, m_clrRender->b / 255.0f ) );
	m_Renderer.SetAmbientLight( m_AmbientLight );
	m_Renderer.SetDirectionalLight( m_DirLight );
	m_flAlphaScale = (float)m_clrRender->a;
} 
void C_SmokeStack::RenderParticles( CParticleRenderIterator *pIterator )
{
	const SmokeStackParticle *pParticle = (const SmokeStackParticle*)pIterator->GetFirst();
	while ( pParticle )
	{
		// Transform.						   
		Vector tPos;
		TransformParticle( m_pParticleMgr->GetModelView(), pParticle->m_Pos, tPos );

		// Figure out its alpha. Squaring it after it gets halfway through its lifetime
		// makes it get translucent and fade out for a longer time.
		//float alpha = cosf( -M_PI_F + tLifetime * M_PI_F * 2.f ) * 0.5f + 0.5f;
		float tLifetime = pParticle->m_Lifetime * m_InvLifetime;
		float alpha = TableCos( -M_PI_F + tLifetime * M_PI_F * 2.f ) * 0.5f + 0.5f;
		if( tLifetime > 0.5f )
			alpha *= alpha;

		m_Renderer.RenderParticle(
			pIterator->GetParticleDraw(),
			pParticle->m_Pos,
			tPos,
			alpha * m_flAlphaScale,
			FLerp(m_StartSize, m_EndSize, tLifetime),
			DEG2RAD( pParticle->m_flAngle )
		);
		
		pParticle = (const SmokeStackParticle*)pIterator->GetNext( pParticle->m_flSortPos );
	}
}
//-----------------------------------------------------------------------------
// Purpose: Starts the effect
// Input  : *pParticleMgr - 
//			*pArgs - 
//-----------------------------------------------------------------------------
void C_SmokeStack::Start(CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs)
{
	pParticleMgr->AddEffect( &m_ParticleEffect, this );
	
	// Figure out the material name.
	char str[512] = "unset_material";
	const model_t *pModel = modelinfo->GetModel( m_iMaterialModel );
	if ( pModel )
	{
		Q_strncpy( str, modelinfo->GetModelName( pModel ), sizeof( str ) );

		// Get rid of the extension because the material system doesn't want it.
		char *pExt = Q_stristr( str, ".vmt" );
		if ( pExt )
			pExt[0] = 0;
	}

	m_MaterialHandle[0] = m_ParticleEffect.FindOrAddMaterial( str );

	int iCount = 1;
	char szNames[512];

	int iLength = Q_strlen( str );
	str[iLength-1] = '\0';

	Q_snprintf( szNames, sizeof( szNames ), "%s%d.vmt", str, iCount );

	while ( filesystem->FileExists( VarArgs( "materials/%s", szNames ) ) && iCount < SMOKESTACK_MAX_MATERIALS )
	{
		char *pExt = Q_stristr( szNames, ".vmt" );
		if ( pExt )
			pExt[0] = 0;

		m_MaterialHandle[iCount] = m_ParticleEffect.FindOrAddMaterial( szNames );
		iCount++;
	}

	m_iMaxFrames = iCount-1;

	m_ParticleSpawn.Init( mat_reduceparticles.GetBool() ? m_Rate / 4 : m_Rate ); // Obey mat_reduceparticles in episodic

	m_InvLifetime = m_Speed / m_JetLength;

	m_pParticleMgr = pParticleMgr;

	// Figure out how we need to draw.
	IMaterial *pMaterial = pParticleMgr->PMaterialToIMaterial( m_MaterialHandle[0] );
	if( pMaterial )
	{
		m_Renderer.Init( pParticleMgr, pMaterial );
	}
	
	QueueLightParametersInRenderer();

	// For the first N seconds, always simulate so it can build up the smokestack.
	// Afterwards, we set it to freeze when it's not being rendered.
	m_ParticleEffect.SetAlwaysSimulate( true );
	SetNextClientThink( gpGlobals->curtime + 5 );
}
Beispiel #4
0
//-----------------------------------------------------------------------------
// Purpose: Starts the effect
// Input  : *pParticleMgr - 
//			*pArgs - 
//-----------------------------------------------------------------------------
void C_SmokeStack::Start(CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs)
{
    pParticleMgr->AddEffect(&m_ParticleEffect, this);

    // Figure out the material name.
    char str[512] = "unset_material";
    const model_t *pModel = modelinfo->GetModel(m_iMaterialModel);
    if (pModel)
    {
        Q_strncpy(str, modelinfo->GetModelName(pModel), sizeof(str));

        // Get rid of the extension because the material system doesn't want it.
        char *pExt = Q_stristr(str, ".vmt");
        if (pExt)
            pExt[0] = 0;
    }

    m_MaterialHandle[0] = m_ParticleEffect.FindOrAddMaterial(str);

    m_ParticleSpawn.Init( m_Rate );

    m_InvLifetime = m_Speed / m_JetLength;

    m_pParticleMgr = pParticleMgr;

    // Figure out how we need to draw.
    IMaterial *pMaterial = pParticleMgr->PMaterialToIMaterial( m_MaterialHandle[0] );
    if( pMaterial )
    {
        m_Renderer.Init( pParticleMgr, pMaterial );
    }

    QueueLightParametersInRenderer();

    // For the first N seconds, always simulate so it can build up the smokestack.
    // Afterwards, we set it to freeze when it's not being rendered.
    m_ParticleEffect.SetAlwaysSimulate( true );
    SetNextClientThink( gpGlobals->curtime + 5 );
}
void C_SmokeStack::StartRender( VMatrix &effectMatrix )
{
	m_Renderer.StartRender( effectMatrix );
}