Hello there.

I'm trying to change my HL2 DM's effects to more "21 century" one's.
Here are sparks - since I can't be arsed with switching every single
particle to EP2 particle system, I just wanted to make them bigger, make
them last longer and the thing that's most important - to give them
collision.
The whole collision thing is easy while creating stuff in particle editor.
However, the hardcoded system is not so clear for me, so could someone tell
me what should I add here to make them collidable with world?


Here's the effect that needs collision

//--------------------------------------------------------------------------
---
// Purpose: Ricochet spark on metal
// Input  : &position - origin of effect
//                      &normal - normal of the surface struck
//--------------------------------------------------------------------------
---
#define METAL_SPARK_SPREAD              0.2f
#define METAL_SPARK_MINSPEED    512.0f
#define METAL_SPARK_MAXSPEED    2048.0f
#define METAL_SPARK_GRAVITY             400.0f
#define METAL_SPARK_DAMPEN              2.0f

void FX_MetalSpark( const Vector &position, const Vector &direction, const
Vector &surfaceNormal, int iScale )
{
        VPROF_BUDGET( "FX_MetalSpark", VPROF_BUDGETGROUP_PARTICLE_RENDERING
);

        if ( !fx_drawmetalspark.GetBool() )
                return;

        //
        // Emitted particles
        //

        Vector offset = position + ( surfaceNormal * 1.0f );

        CSmartPtr<CTrailParticles> sparkEmitter = CTrailParticles::Create(
"FX_MetalSpark 1" );

        if ( sparkEmitter == NULL )
                return;

        //Setup our information
        sparkEmitter->SetSortOrigin( offset );
        sparkEmitter->SetFlag( bitsPARTICLE_TRAIL_VELOCITY_DAMPEN );
        sparkEmitter->SetVelocityDampen( 8.0f );
        sparkEmitter->SetGravity( METAL_SPARK_GRAVITY );
        sparkEmitter->SetCollisionDamped( SPARK_ELECTRIC_DAMPEN );
        sparkEmitter->GetBinding().SetBBox( offset - Vector( 32, 32, 32 ),
offset + Vector( 32, 32, 32 ) );

        int     numSparks = random->RandomInt( 16, 32 ) * ( iScale * 2 );
        
        if ( g_Material_Spark == NULL )
        {
                g_Material_Spark = sparkEmitter->GetPMaterial(
"effects/spark" );
        }

        TrailParticle   *pParticle;
        Vector  dir;
        float   length  = 0.1f;

        //Dump out sparks
        for ( int i = 0; i < numSparks; i++ )
        {
                pParticle = (TrailParticle *) sparkEmitter->AddParticle(
sizeof(TrailParticle), g_Material_Spark, offset );

                if ( pParticle == NULL )
                        return;

                pParticle->m_flLifetime = 0.0f;
                
                if( iScale > 1 && i%2 == 0 )
                {
                        // Every third spark goes flying far if we're having
a big batch of sparks.
                        pParticle->m_flDieTime  = random->RandomFloat( 2.0f,
4.0f );
                }
                else
                {
                        pParticle->m_flDieTime  = random->RandomFloat( 2.0f,
4.0f );
                }

                float   spreadOfs = random->RandomFloat( 0.0f, 2.0f );

                dir[0] = direction[0] + random->RandomFloat(
-(METAL_SPARK_SPREAD*spreadOfs), (METAL_SPARK_SPREAD*spreadOfs) );
                dir[1] = direction[1] + random->RandomFloat(
-(METAL_SPARK_SPREAD*spreadOfs), (METAL_SPARK_SPREAD*spreadOfs) );
                dir[2] = direction[2] + random->RandomFloat(
-(METAL_SPARK_SPREAD*spreadOfs), (METAL_SPARK_SPREAD*spreadOfs) );
        
                VectorNormalize( dir );

                pParticle->m_flWidth            = random->RandomFloat( 2.0f,
5.0f );
                pParticle->m_flLength           = random->RandomFloat(
length*0.35f, length );
                
                pParticle->m_vecVelocity        = dir * random->RandomFloat(
(METAL_SPARK_MINSPEED*(2.0f-spreadOfs)),
(METAL_SPARK_MAXSPEED*(2.0f-spreadOfs)) );
                
                Color32Init( pParticle->m_color, 255, 255, 255, 255 );
        
   
        }
        //
        // Impact point glow
        //

        FXQuadData_t data;

        data.SetMaterial( "effects/yellowflare" );
        data.SetColor( 1.0f, 1.0f, 1.0f );
        data.SetOrigin( offset );
        data.SetNormal( surfaceNormal );
        data.SetAlpha( 1.0f, 0.0f );
        data.SetLifeTime( 0.1f );
        data.SetYaw( random->RandomInt( 0, 360 ) );
        
        int scale = random->RandomInt( 24, 28 );
        data.SetScale( scale, 0 );

        FX_AddQuad( data );
}



And here's the effect that has got collision, but I cannot tell where it is
said to collide with stuff, and how can I adapt it to the previous code.


//--------------------------------------------------------------------------
---
// Purpose: Electric spark
// Input  : &pos - origin point of effect
//--------------------------------------------------------------------------
---
#define SPARK_ELECTRIC_SPREAD   0.0f
#define SPARK_ELECTRIC_MINSPEED 64.0f
#define SPARK_ELECTRIC_MAXSPEED 300.0f
#define SPARK_ELECTRIC_GRAVITY  800.0f
#define SPARK_ELECTRIC_DAMPEN   0.3f

void FX_ElectricSpark( const Vector &pos, int nMagnitude, int nTrailLength,
const Vector *vecDir )
{
        VPROF_BUDGET( "FX_ElectricSpark",
VPROF_BUDGETGROUP_PARTICLE_RENDERING );
        CSmartPtr<CTrailParticles> pSparkEmitter        =
CTrailParticles::Create( "FX_ElectricSpark 1" );

        if ( !pSparkEmitter )
        {
                Assert(0);
                return;
        }

        if ( g_Material_Spark == NULL )
        {
                g_Material_Spark = pSparkEmitter->GetPMaterial(
"effects/spark" );
        }

        //Setup our collision information
        pSparkEmitter->Setup( (Vector &) pos, 
                                                        NULL, 
        
SPARK_ELECTRIC_SPREAD, 
        
SPARK_ELECTRIC_MINSPEED, 
        
SPARK_ELECTRIC_MAXSPEED, 
        
SPARK_ELECTRIC_GRAVITY, 
        
SPARK_ELECTRIC_DAMPEN, 
        
bitsPARTICLE_TRAIL_VELOCITY_DAMPEN );

        pSparkEmitter->SetSortOrigin( pos );

        //
        // Big sparks.
        //
        Vector  dir;
        int             numSparks = nMagnitude * nMagnitude *
random->RandomFloat( 2, 4 );

        int i;
        TrailParticle   *pParticle;
        for ( i = 0; i < numSparks; i++ )
        {
                pParticle = (TrailParticle *) pSparkEmitter->AddParticle(
sizeof(TrailParticle), g_Material_Spark, pos );

                if ( pParticle == NULL )
                        return;

                pParticle->m_flLifetime = 0.0f;
                pParticle->m_flDieTime  = nMagnitude * random->RandomFloat(
1.0f, 2.0f );

                dir.Random( -1.0f, 1.0f );
                dir[2] = random->RandomFloat( 0.5f, 1.0f );
        
                if ( vecDir )
                {
                        dir += 2 * (*vecDir);
                        VectorNormalize( dir );
                }
                        
                pParticle->m_flWidth            = random->RandomFloat( 2.0f,
5.0f );
                pParticle->m_flLength           = nTrailLength *
random->RandomFloat( 0.02, 0.05f );
                
                pParticle->m_vecVelocity        = dir * random->RandomFloat(
SPARK_ELECTRIC_MINSPEED, SPARK_ELECTRIC_MAXSPEED );

                Color32Init( pParticle->m_color, 255, 255, 255, 255 );
        }
#else

        //
        // Little sparks
        //
        
        CSmartPtr<CTrailParticles> pSparkEmitter2       =
CTrailParticles::Create( "FX_ElectricSpark 2" );

        if ( !pSparkEmitter2 )
        {
                Assert(0);
                return;
        }

        pSparkEmitter2->SetSortOrigin( pos );
        
        pSparkEmitter2->m_ParticleCollision.SetGravity( 400.0f );
        pSparkEmitter2->SetFlag( bitsPARTICLE_TRAIL_VELOCITY_DAMPEN );

        numSparks = nMagnitude * random->RandomInt( 16, 32 );

        // Dump out sparks
        for ( i = 0; i < numSparks; i++ )
        {
                pParticle = (TrailParticle *) pSparkEmitter2->AddParticle(
sizeof(TrailParticle), g_Material_Spark, pos );

                if ( pParticle == NULL )
                        return;

                pParticle->m_flLifetime = 0.0f;

                dir.Random( -1.0f, 1.0f );
                if ( vecDir )
                {
                        dir += *vecDir;
                        VectorNormalize( dir );
                }
                
                pParticle->m_flWidth            = random->RandomFloat( 2.0f,
4.0f );
                pParticle->m_flLength           = nTrailLength *
random->RandomFloat( 0.02f, 0.03f );
                pParticle->m_flDieTime          = nMagnitude *
random->RandomFloat( 0.1f, 0.2f );
                
                pParticle->m_vecVelocity        = dir * random->RandomFloat(
128, 256 );

                Color32Init( pParticle->m_color, 255, 255, 255, 255 );
        }

        //
        // Caps
        //
        CSmartPtr<CSimpleGlowEmitter> pSimple = CSimpleGlowEmitter::Create(
"FX_ElectricSpark 3", pos, gpGlobals->curtime + 0.2 );

        // NOTE: None of these will render unless the effect is visible!
        //
        // Inner glow
        //
        SimpleParticle *sParticle;

        sParticle = (SimpleParticle *) pSimple->AddParticle( sizeof(
SimpleParticle ), pSimple->GetPMaterial( "effects/yellowflare_noz" ), pos );
                
        if ( sParticle == NULL )
                return;

        sParticle->m_flLifetime         = 0.0f;
        sParticle->m_flDieTime          = 0.2f;
        
        sParticle->m_vecVelocity.Init();

        sParticle->m_uchColor[0]        = 255;
        sParticle->m_uchColor[1]        = 255;
        sParticle->m_uchColor[2]        = 255;
        sParticle->m_uchStartAlpha      = 255;
        sParticle->m_uchEndAlpha        = 255;
        sParticle->m_uchStartSize       = nMagnitude * random->RandomInt( 4,
8 );
        sParticle->m_uchEndSize         = 0;
        sParticle->m_flRoll                     = random->RandomInt( 0, 360
);
        sParticle->m_flRollDelta        = 0.0f;
        
        sParticle = (SimpleParticle *) pSimple->AddParticle( sizeof(
SimpleParticle ), pSimple->GetPMaterial( "effects/yellowflare_noz" ), pos );
                
        if ( sParticle == NULL )
                return;

        sParticle->m_flLifetime         = 0.0f;
        sParticle->m_flDieTime          = 0.2f;
        
        sParticle->m_vecVelocity.Init();

        float   fColor = random->RandomInt( 32, 64 );
        sParticle->m_uchColor[0]        = fColor;
        sParticle->m_uchColor[1]        = fColor;
        sParticle->m_uchColor[2]        = fColor;
        sParticle->m_uchStartAlpha      = fColor;
        sParticle->m_uchEndAlpha        = 0;
        sParticle->m_uchStartSize       = nMagnitude * random->RandomInt(
32, 64 );
        sParticle->m_uchEndSize         = 0;
        sParticle->m_flRoll                     = random->RandomInt( 0, 360
);
        sParticle->m_flRollDelta        = random->RandomFloat( -1.0f, 1.0f
);

        //
        // Smoke
        //
        Vector  sOffs;

        sOffs[0] = pos[0] + random->RandomFloat( -4.0f, 4.0f );
        sOffs[1] = pos[1] + random->RandomFloat( -4.0f, 4.0f );
        sOffs[2] = pos[2];

        sParticle = (SimpleParticle *) pSimple->AddParticle( sizeof(
SimpleParticle ), g_Mat_DustPuff[1], sOffs );
                
        if ( sParticle == NULL )
                return;

        sParticle->m_flLifetime         = 0.0f;
        sParticle->m_flDieTime          = 1.0f;
        
        sParticle->m_vecVelocity.Init();
        
        sParticle->m_vecVelocity[2] = 16.0f;
        
        sParticle->m_vecVelocity[0] = random->RandomFloat( -16.0f, 16.0f );
        sParticle->m_vecVelocity[1] = random->RandomFloat( -16.0f, 16.0f );

        sParticle->m_uchColor[0]        = 255;
        sParticle->m_uchColor[1]        = 255;
        sParticle->m_uchColor[2]        = 200;
        sParticle->m_uchStartAlpha      = random->RandomInt( 16, 32 );
        sParticle->m_uchEndAlpha        = 0;
        sParticle->m_uchStartSize       = random->RandomInt( 4, 8 );
        sParticle->m_uchEndSize         = sParticle->m_uchStartSize*4.0f;
        sParticle->m_flRoll                     = random->RandomInt( 0, 360
);
        sParticle->m_flRollDelta        = random->RandomFloat( -2.0f, 2.0f
);

        //
        // Dlight
        //


        dlight_t *dl= effects->CL_AllocDlight ( 0 );

        dl->origin      = pos;
        dl->color.r = dl->color.g = dl->color.b = 250;
        dl->radius      = random->RandomFloat(16,32);
        dl->die         = gpGlobals->curtime + 0.001;


#endif  // !_XBOX
}



So could anyone help me with this?

Thanks you very much.

Adrian
 

__________ Informacja programu ESET NOD32 Antivirus, wersja bazy sygnatur
wirusow 4798 (20100122) __________

Wiadomosc zostala sprawdzona przez program ESET NOD32 Antivirus.
http://www.eset.pl lub http://www.eset.com 
 


_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to