Esempio n. 1
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pIterator - 
//-----------------------------------------------------------------------------
void CSplashParticle::SimulateParticles( CParticleSimulateIterator *pIterator )
{
	float timeDelta = pIterator->GetTimeDelta();

	SimpleParticle *pParticle = (SimpleParticle*)pIterator->GetFirst();
	
	while ( pParticle )
	{
		//Update velocity
		UpdateVelocity( pParticle, timeDelta );
		pParticle->m_Pos += pParticle->m_vecVelocity * timeDelta;

		// Clip by height if requested
		if ( m_bUseClipHeight )
		{
			// See if we're below, and therefore need to clip
			if ( pParticle->m_Pos.z + UpdateScale( pParticle ) < m_flClipHeight )
			{
				pIterator->RemoveParticle( pParticle );
				pParticle = (SimpleParticle*)pIterator->GetNext();
				continue;
			}
		}

		//Should this particle die?
		pParticle->m_flLifetime += timeDelta;
		UpdateRoll( pParticle, timeDelta );

		if ( pParticle->m_flLifetime >= pParticle->m_flDieTime )
			pIterator->RemoveParticle( pParticle );

		pParticle = (SimpleParticle*)pIterator->GetNext();
	}
}
//-----------------------------------------------------------------------------
// Purpose: Simulate motion and render all child particles
// Input  : *pInParticle - 
//			*pDraw - 
//			&sortKey - 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CSimpleEmitter::SimulateAndRender( Particle *pInParticle, ParticleDraw *pDraw, float &sortKey)
{
	SimpleParticle *pParticle = (SimpleParticle *) pInParticle;
	float timeDelta = pDraw->GetTimeDelta();

	//Render
	Vector	tPos;

	TransformParticle( g_ParticleMgr.GetModelView(), pParticle->m_Pos, tPos );
	sortKey = (int) tPos.z;

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

	//Update velocity
	UpdateVelocity( pParticle, timeDelta );
	pParticle->m_Pos += pParticle->m_vecVelocity * timeDelta;

	//Should this particle die?
	pParticle->m_flLifetime += timeDelta;

	if ( pParticle->m_flLifetime >= pParticle->m_flDieTime )
		return false;

	return true;
}
bool FXQuad::Update( void )
{
	UpdateRoll();
	UpdateScale();
	UpdateAlpha();
	UpdateRGB();

	return true;
}
bool FXSprite::Update( void )
{
	if (m_start_time > cg.time)
	{//i was created in the future, right after un-pausing
		return false;
	}
	//Move the object
	UpdateOrigin();

	UpdateRoll();
	UpdateScale();
	UpdateAlpha();
	UpdateRGB();

	return true;
}
void CSimpleEmitter::SimulateParticles( CParticleSimulateIterator *pIterator )
{
	float timeDelta = pIterator->GetTimeDelta();

	SimpleParticle *pParticle = (SimpleParticle*)pIterator->GetFirst();
	while ( pParticle )
	{
		//Update velocity
		UpdateVelocity( pParticle, timeDelta );
		pParticle->m_Pos += pParticle->m_vecVelocity * timeDelta;

		//Should this particle die?
		pParticle->m_flLifetime += timeDelta;
		UpdateRoll( pParticle, timeDelta );

		if ( pParticle->m_flLifetime >= pParticle->m_flDieTime )
			pIterator->RemoveParticle( pParticle );

		pParticle = (SimpleParticle*)pIterator->GetNext();
	}
}
//-----------------------------------------------------------------------------
// 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;
}