GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


A Paste by eMCee
1
 
//---------------------------------------------------------------
// update_particles
//---------------------------------------------------------------
void update_particles()
{
    int i;
    for(i=0; i<NUM_PARTICLES; i++)
    {
        // particle is dead so re-generate it
        if(_g_particles[i].life<0)
        {
            set_particle(i);
        }
        _g_particles[i].life -=_g_particles[i].fade_rate;
        _g_particles[i].x +=_g_particles[i].x_speed;
        _g_particles[i].y +=_g_particles[i].y_speed;
        _g_particles[i].z +=_g_particles[i].z_speed;
    }
}
//---------------------------------------------------------------
// set_particle
//---------------------------------------------------------------
void set_particle(int i)
{
    int i_positive;

    // 1
    _g_particles[i].life = 1.0f;

    // 2
    _g_particles[i].fade_rate = rand()%100; 
    _g_particles[i].fade_rate = (0.2f+ _g_particles[i].fade_rate) / 10.0f;

    // 3
    _g_particles[i].size = rand()%100; 
    _g_particles[i].size = (25+_g_particles[i].size) / 1000.0f;

    // 4
    _g_particles[i].color_brightness = rand()%50; 
    _g_particles[i].color_brightness = (50+_g_particles[i].color_brightness) /100; 

    // 5
    _g_particles[i].x = rand()%400 - 200; 
    _g_particles[i].y = 10;
    _g_particles[i].z = rand()%400 - 200;

    // 6
    _g_particles[i].y_speed = rand()%50; 
    _g_particles[i].y_speed = (50 + _g_particles[i].y_speed) /300; 

    // 7
    _g_particles[i].x_speed = rand()%50;
    _g_particles[i].x_speed = ( _g_particles[i].x_speed) / 3000; 
    if(rand()%2)
    {
        _g_particles[i].x_speed = -_g_particles[i].x_speed;
    }

    // 8
    _g_particles[i].z_speed = rand()%50;
    _g_particles[i].z_speed = (_g_particles[i].z_speed) / 3000; 
    if(rand()%2)
    {
        _g_particles[i].z_speed = -_g_particles[i].z_speed;
    }
}