Skip to content

Instantly share code, notes, and snippets.

@pingpoli
Created August 6, 2020 20:16
Show Gist options
  • Save pingpoli/255509cd1d72d9cff54747fe8f8c1009 to your computer and use it in GitHub Desktop.
Save pingpoli/255509cd1d72d9cff54747fe8f8c1009 to your computer and use it in GitHub Desktop.
void SimpleEmitter::update( const float dt )
{
for ( uint i = 0 ; i < this->particles.size() ; ++i )
{
// subtract from the particles lifetime
this->particles[i].lifetime -= dt;
// if the lifetime is below 0 respawn the particle
if ( this->particles[i].lifetime <= 0.0f )
{
this->particles[i].position = lstd_random_between( vec3( -1.0f ) , vec3( 1.0f ) );
this->particles[i].lifetime = lstd_random_between( 1.0f , 2.0f );
}
// move the particle down depending on the delta time
this->particles[i].position -= vec3( 0.0f , dt*2.0f , 0.0f );
// update the position buffer
this->positions[i*4+0] = this->particles[i].position[0];
this->positions[i*4+1] = this->particles[i].position[1];
this->positions[i*4+2] = this->particles[i].position[2];
this->positions[i*4+3] = this->particles[i].lifetime;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment