Exemple #1
0
void CTrailParticles::RenderParticles(CParticleRenderIterator *pIterator)
{
    const TrailParticle *pParticle = (const TrailParticle*) pIterator->GetFirst();
    while (pParticle)
    {
        //Get our remaining time
        float lifePerc = 1.0f - (pParticle->m_flLifetime / pParticle->m_flDieTime);
        float scale = (pParticle->m_flLength*lifePerc);

        if (scale < 0.01f)
            scale = 0.01f;

        Vector	start, delta;

        //NOTE: We need to do everything in screen space
        TransformParticle(ParticleMgr()->GetModelView(), pParticle->m_Pos, start);
        float sortKey = start.z;

        Vector3DMultiply(ParticleMgr()->GetModelView(), pParticle->m_vecVelocity, delta);

        float	color[4];
        float	ramp = 1.0;

        // Fade in for the first few frames
        if (pParticle->m_flLifetime <= 0.3 && m_fFlags & bitsPARTICLE_TRAIL_FADE_IN)
        {
            ramp = pParticle->m_flLifetime;
        }
        else if (m_fFlags & bitsPARTICLE_TRAIL_FADE)
        {
            ramp = (1.0f - (pParticle->m_flLifetime / pParticle->m_flDieTime));
        }

        color[0] = pParticle->m_color.r * ramp * (1.0f / 255.0f);
        color[1] = pParticle->m_color.g * ramp * (1.0f / 255.0f);
        color[2] = pParticle->m_color.b * ramp * (1.0f / 255.0f);
        color[3] = pParticle->m_color.a * ramp * (1.0f / 255.0f);

        float	flLength = (pParticle->m_vecVelocity * scale).Length();//( delta - pos ).Length();
        float	flWidth = (flLength < pParticle->m_flWidth) ? flLength : pParticle->m_flWidth;

        //See if we should fade
        Vector vecScaledDelta = (delta*scale);
        Tracer_Draw(pIterator->GetParticleDraw(), start, vecScaledDelta, flWidth, color);

        pParticle = (const TrailParticle*) pIterator->GetNext(sortKey);
    }
}
//------------------------------------------------------------------------------
// Purpose :
// Input   :
// Output  :
//------------------------------------------------------------------------------
bool CPlasmaSpray::SimulateAndRender(Particle *pParticle, ParticleDraw *pDraw, float &sortDist )
{
	SimpleParticle* pSimpleParticle = (SimpleParticle*)pParticle;

	//Should this particle die?
	pSimpleParticle->m_flLifetime += pDraw->GetTimeDelta();

	C_PlasmaBeamNode* pNode = (C_PlasmaBeamNode*)((C_BaseEntity*)m_pOwner);
	if ( pSimpleParticle->m_flLifetime >= pSimpleParticle->m_flDieTime )
	{
		return false;
	}
	// If owner is gone or spray off remove me
	else if (pNode == NULL || !pNode->m_bSprayOn)
	{
		return false;
	}

	float scale = random->RandomFloat( 0.02, 0.08 );

	// NOTE: We need to do everything in screen space
	Vector  delta;
	Vector	start;
	TransformParticle(g_ParticleMgr.GetModelView(), pSimpleParticle->m_Pos, start);

	Vector3DMultiply( CurrentWorldToViewMatrix(), pSimpleParticle->m_vecVelocity, delta );

	delta[0] *= scale;
	delta[1] *= scale;
	delta[2] *= scale;

	// See c_tracer.* for this method
	Tracer_Draw( pDraw, start, delta, random->RandomInt( 2, 8 ), 0 );

	//Simulate the movement with collision
	trace_t trace;
	float   timeDelta = pDraw->GetTimeDelta();
	m_ParticleCollision.MoveParticle( pSimpleParticle->m_Pos, pSimpleParticle->m_vecVelocity, NULL, timeDelta, &trace );

	return true;
}
//-----------------------------------------------------------------------------
// Purpose: Update state + render
//-----------------------------------------------------------------------------
bool CBasePlasmaProjectile::SimulateAndRender(Particle *pInParticle, ParticleDraw *pDraw, float &sortKey)
{
	if ( IsDormantPredictable() )
		return true;

	if ( GetMoveType() == MOVETYPE_NONE )
		return true;

	// Update the particle position
	pInParticle->m_Pos = GetAbsOrigin();

	// Add our blended offset
	if ( gpGlobals->curtime < m_Shared.GetSpawnTime() + REMAP_BLEND_TIME )
	{
		float frac = ( gpGlobals->curtime - m_Shared.GetSpawnTime() ) / REMAP_BLEND_TIME;
		frac = 1.0f - clamp( frac, 0.0f, 1.0f );
		Vector scaledOffset;
		VectorScale( m_vecGunOriginOffset, frac, scaledOffset );
		pInParticle->m_Pos += scaledOffset;
	}

	float timeDelta = pDraw->GetTimeDelta();

	// Render the head particle
	if ( pInParticle == m_pHeadParticle )
	{
		SimpleParticle *pParticle = (SimpleParticle *) pInParticle;
		pParticle->m_flLifetime += timeDelta;

		// Render
		Vector tPos, vecOrigin;
		RemapPosition( m_pPreviousPositions[MAX_HISTORY-1].m_Position, m_pPreviousPositions[MAX_HISTORY-1].m_Time, vecOrigin );

		TransformParticle( ParticleMgr()->GetModelView(), vecOrigin, tPos );
		sortKey = (int) tPos.z;

		//Render it
		RenderParticle_ColorSizeAngle(
			pDraw,
			tPos,
			UpdateColor( pParticle, timeDelta ),
			UpdateAlpha( pParticle, timeDelta ) * GetAlphaDistanceFade( tPos, 16, 64 ),
			UpdateScale( pParticle, timeDelta ),
			UpdateRoll( pParticle, timeDelta ) );

		/*
		if ( m_flNextSparkEffect < gpGlobals->curtime )
		{
			// Drop sparks?
			if ( GetTeamNumber() == TEAM_HUMANS )
			{
				g_pEffects->Sparks( pInParticle->m_Pos, 1, 3 );
			}
			else
			{
				g_pEffects->EnergySplash( pInParticle->m_Pos, vec3_origin );
			}
			m_flNextSparkEffect = gpGlobals->curtime + RandomFloat( 0.5, 2 );
		}
		*/

		return true;
	}

	// Render the trail
	TrailParticle *pParticle = (TrailParticle *) pInParticle;
	pParticle->m_flLifetime += timeDelta;
	Vector vecScreenStart, vecScreenDelta;
	sortKey = pParticle->m_Pos.z;

	// NOTE: We need to do everything in screen space
	float flFragmentLength = (MAX_HISTORY > 1) ? 1.0 / (float)(MAX_HISTORY-1) : 1.0;

	for ( int i = 0; i < (MAX_HISTORY-1); i++ )
	{
		Vector vecWorldStart, vecWorldEnd, vecScreenEnd;
		float flStartV, flEndV;

		// Did we just appear?
		if ( m_pPreviousPositions[i].m_Time == 0 )
			continue;

		RemapPosition( m_pPreviousPositions[i+1].m_Position, m_pPreviousPositions[i+1].m_Time, vecWorldStart );
		RemapPosition( m_pPreviousPositions[i].m_Position, m_pPreviousPositions[i].m_Time, vecWorldEnd );

		// Texture wrapping
		flStartV = (flFragmentLength * (i+1));
		flEndV = (flFragmentLength * i);
		
		TransformParticle( ParticleMgr()->GetModelView(), vecWorldStart, vecScreenStart );
		TransformParticle( ParticleMgr()->GetModelView(), vecWorldEnd, vecScreenEnd );
		Vector vecScreenDelta = (vecScreenEnd - vecScreenStart);
		if ( vecScreenDelta == vec3_origin )
			continue;

		/*
		Vector vecForward, vecRight;
		AngleVectors( MainViewAngles(), &vecForward, &vecRight, NULL );
		Vector vecWorldDelta = ( vecWorldEnd - vecWorldStart );
		VectorNormalize( vecWorldDelta );
		float flDot = fabs(DotProduct( vecWorldDelta, vecForward ));
		if ( flDot > 0.99 )
		{
			// Remap alpha
			pParticle->m_flColor[3] = 1.0 - min( 1.0, RemapVal( flDot, 0.99, 1.0, 0, 1 ) );
		}
		*/

		// See if we should fade
		float color[4];
		Color32ToFloat4( color, pParticle->m_color );
		Tracer_Draw( pDraw, vecScreenStart, vecScreenDelta, pParticle->m_flWidth, color, flStartV, flEndV );
	}

	return true;
}