class CDustParticle : public CSimpleEmitter { public: void SetGravity(float gravity) {m_flGravity = gravity;} CDustParticle( const char *pDebugName ) : CSimpleEmitter( pDebugName ) {} //Create static CDustParticle *Create( const char *pDebugName="dust" ) { return new CDustParticle( pDebugName ); } //Roll virtual float UpdateRoll( SimpleParticle *pParticle, float timeDelta ) { pParticle->m_flRoll += pParticle->m_flRollDelta * timeDelta; pParticle->m_flRollDelta += pParticle->m_flRollDelta * ( timeDelta * -8.0f ); if ( fabs( pParticle->m_flRollDelta ) < 0.5f ) { pParticle->m_flRollDelta = ( pParticle->m_flRollDelta > 0.0f ) ? 0.5f : -0.5f; } return pParticle->m_flRoll; } //Velocity virtual void UpdateVelocity( SimpleParticle *pParticle, float timeDelta ) { Vector saveVelocity = pParticle->m_vecVelocity; //Decellerate static float dtime; static float decay; if ( dtime != timeDelta ) { dtime = timeDelta; float expected = 0.5; decay = exp( log( 0.0001f ) * dtime / expected ); } pParticle->m_vecVelocity = pParticle->m_vecVelocity * decay; //Cap the minimum speed if ( pParticle->m_vecVelocity.LengthSqr() < (32.0f*32.0f) ) { VectorNormalize( saveVelocity ); pParticle->m_vecVelocity = saveVelocity * 32.0f; } //factor in gravity!!! pParticle->m_vecVelocity[2] -= m_flGravity * timeDelta; Vector vecWind; GetWindspeedAtTime(gpGlobals->curtime, vecWind); VectorNormalize( vecWind ); //and factor in wind! pParticle->m_vecVelocity += vecWind; } //Alpha virtual float UpdateAlpha( const SimpleParticle *pParticle ) { float tLifetime = pParticle->m_flLifetime / pParticle->m_flDieTime; float ramp = 1.0f - tLifetime; //Non-linear fade if ( ramp < 0.75f ) ramp *= ramp; return ramp; } private: CDustParticle( const CDustParticle & ); // not defined, not accessible float m_flGravity; };