//----------------------------------------------------------------------------- // Purpose: // Input : bool - //----------------------------------------------------------------------------- void C_TEShowLine::PostDataUpdate( DataUpdateType_t updateType ) { Vector vec; float len; StandardParticle_t *p; int dec; static int tracercount; VectorSubtract (m_vecEnd, m_vecOrigin, vec); len = VectorNormalize (vec); dec = 3; VectorScale(vec, dec, vec); CSmartPtr<CTEParticleRenderer> pRen = CTEParticleRenderer::Create( "TEShowLine", m_vecOrigin ); if( !pRen ) return; while (len > 0) { len -= dec; p = pRen->AddParticle(); if ( p ) { p->m_Velocity.Init(); pRen->SetParticleLifetime(p, 30); p->SetColor(0, 1, 1); p->SetAlpha(1); pRen->SetParticleType(p, pt_static); p->m_Pos = m_vecOrigin; m_vecOrigin += vec; } } }
void CTEParticleRenderer::SimulateParticles( CParticleSimulateIterator *pIterator ) { StandardParticle_t *pParticle = (StandardParticle_t*)pIterator->GetFirst(); while ( pParticle ) { // Remove the particle? SetParticleLifetime(pParticle, GetParticleLifetime(pParticle) - pIterator->GetTimeDelta()); if(GetParticleLifetime(pParticle) < 0) { pIterator->RemoveParticle( pParticle ); } else { float ft = pIterator->GetTimeDelta(); float time3 = 15.0 * ft; float time2 = 10.0 * ft; float time1 = 5.0 * ft; float dvel = 4* ft ; float grav = ft * sv_gravity.GetFloat() * 0.05f; int (*colorIndex)[3]; int iRamp; switch(GetParticleType(pParticle)) { case pt_static: break; case pt_fire: pParticle->m_EffectDataWord += (unsigned short)(time1 * (1 << SIMSHIFT)); iRamp = pParticle->m_EffectDataWord >> SIMSHIFT; if(iRamp >= 6) { pParticle->m_Lifetime = -1; } else { colorIndex = &ramp3[ iRamp ]; pParticle->SetColor((float)(*colorIndex)[0] / 255.0f, (float)(*colorIndex)[1] / 255.0f, (float)(*colorIndex)[2] / 255.0f); } pParticle->m_Velocity[2] += grav; break; case pt_explode: pParticle->m_EffectDataWord += (unsigned short)(time2 * (1 << SIMSHIFT)); iRamp = pParticle->m_EffectDataWord >> SIMSHIFT; if(iRamp >= 8) { pParticle->m_Lifetime = -1; } else { colorIndex = &ramp1[ iRamp ]; pParticle->SetColor((float)(*colorIndex)[0] / 255.0f, (float)(*colorIndex)[1] / 255.0f, (float)(*colorIndex)[2] / 255.0f); } pParticle->m_Velocity = pParticle->m_Velocity + pParticle->m_Velocity * dvel; pParticle->m_Velocity[2] -= grav; break; case pt_explode2: pParticle->m_EffectDataWord += (unsigned short)(time3 * (1 << SIMSHIFT)); iRamp = pParticle->m_EffectDataWord >> SIMSHIFT; if(iRamp >= 8) { pParticle->m_Lifetime = -1; } else { colorIndex = &ramp2[ iRamp ]; pParticle->SetColor((float)(*colorIndex)[0] / 255.0f, (float)(*colorIndex)[1] / 255.0f, (float)(*colorIndex)[2] / 255.0f); } pParticle->m_Velocity = pParticle->m_Velocity - pParticle->m_Velocity * ft; pParticle->m_Velocity[2] -= grav; break; case pt_grav: pParticle->m_Velocity[2] -= grav * 20; break; case pt_slowgrav: pParticle->m_Velocity[2] = grav; break; case pt_vox_grav: pParticle->m_Velocity[2] -= grav * 8; break; case pt_vox_slowgrav: pParticle->m_Velocity[2] -= grav * 4; break; case pt_blob: case pt_blob2: pParticle->m_EffectDataWord += (unsigned short)(time2 * (1 << SIMSHIFT)); iRamp = pParticle->m_EffectDataWord >> SIMSHIFT; if(iRamp >= SPARK_COLORCOUNT) { pParticle->m_EffectDataWord = 0; iRamp = 0; } colorIndex = &gSparkRamp[ iRamp ]; pParticle->SetColor((float)(*colorIndex)[0] / 255.0f, (float)(*colorIndex)[1] / 255.0f, (float)(*colorIndex)[2] / 255.0f); pParticle->m_Velocity[0] -= pParticle->m_Velocity[0]*0.5*ft; pParticle->m_Velocity[1] -= pParticle->m_Velocity[1]*0.5*ft; pParticle->m_Velocity[2] -= grav * 5; if ( random->RandomInt(0,3) ) { SetParticleType(pParticle, pt_blob); pParticle->SetAlpha(0); } else { SetParticleType(pParticle, pt_blob2); pParticle->SetAlpha(255.9f); } break; } // Update position. pParticle->m_Pos = pParticle->m_Pos + pParticle->m_Velocity * ft; } pParticle = (StandardParticle_t*)pIterator->GetNext(); } }
void TE_BloodStream( IRecipientFilter& filter, float delay, const Vector* org, const Vector* direction, int r, int g, int b, int a, int amount ) { CSmartPtr<CTEParticleRenderer> pRen = CTEParticleRenderer::Create( "TEBloodStream", *org ); if( !pRen ) return; // Add our particles. Vector dirCopy; float arc = 0.05; int count, count2; float num; int speedCopy = amount; Vector dir; VectorCopy( *direction, dir ); VectorNormalize( dir ); for (count=0 ; count<100 ; count++) { StandardParticle_t *p = pRen->AddParticle(); if(p) { p->SetColor(r * random->RandomFloat(0.7, 1.0), g, b); p->SetAlpha(a); p->m_Pos = *org; pRen->SetParticleLifetime(p, 2); pRen->SetParticleType(p, pt_vox_grav); VectorCopy (dir, dirCopy); dirCopy[2] -= arc; arc -= 0.005; VectorScale (dirCopy, speedCopy, p->m_Velocity); speedCopy -= 0.00001;// so last few will drip } } // now a few rogue voxels arc = 0.075; for (count = 0 ; count < (amount/5); count ++) { StandardParticle_t *p = pRen->AddParticle(); if(p) { pRen->SetParticleLifetime(p, 3); p->SetColor(r * random->RandomFloat(0.7, 1.0), g, b); p->SetAlpha(a); p->m_Pos = *org; pRen->SetParticleType(p, pt_vox_slowgrav); VectorCopy (dir, dirCopy); dirCopy[2] -= arc; arc -= 0.005; num = random->RandomFloat(0,1); speedCopy = amount * num; num *= 1.7; VectorScale (dirCopy, num, dirCopy);// randomize a bit p->m_Velocity = dirCopy * speedCopy; // add a few extra voxels directly adjacent to this one to give a // 'chunkier' appearance. for (count2 = 0; count2 < 2; count2++) { StandardParticle_t *p = pRen->AddParticle(); if(p) { pRen->SetParticleLifetime(p, 3); p->SetColor(random->RandomFloat(0.7, 1.0), g, b); p->SetAlpha(a); p->m_Pos.Init( (*org)[0] + random->RandomFloat(-1,1), (*org)[1] + random->RandomFloat(-1,1), (*org)[2] + random->RandomFloat(-1,1)); pRen->SetParticleType(p, pt_vox_slowgrav); VectorCopy (dir, dirCopy); dirCopy[2] -= arc; VectorScale (dirCopy, num, dirCopy);// randomize a bit p->m_Velocity = dirCopy * speedCopy; } } } } }