diff options
Diffstat (limited to 'src/render/particleejector.cc')
-rw-r--r-- | src/render/particleejector.cc | 76 |
1 files changed, 43 insertions, 33 deletions
diff --git a/src/render/particleejector.cc b/src/render/particleejector.cc index 29a255d..5fae7d1 100644 --- a/src/render/particleejector.cc +++ b/src/render/particleejector.cc @@ -82,7 +82,10 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat Particle *particle = new Particle(particle_location, particle_axis, now); particle->set_radius(radius_vec()[0]); - particle->set_alpha(alpha_vec()[0]); + + particle->set_color(color()); + particle->get_color().a = alpha_vec()[0]; + particle->set_rotation(math::randomf(2.0f * M_PI)); particle->set_speed(math::randomf(speed_vec()[0], speed_vec()[1])); particles().push_front(particle); @@ -90,7 +93,8 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat if (type() == Streak) { Particle *tail = new Particle(particle_location, particle_axis, now); tail->set_radius(radius_vec()[0]); - tail->set_alpha(alpha_vec()[0]); + tail->set_color(color()); + tail->get_color().a = alpha_vec()[0]; tail->set_rotation(particle->rotation()); tail->set_speed(math::randomf(tailspeed_vec()[0], tailspeed_vec()[1])); particles().push_front(tail); @@ -115,20 +119,32 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat // apply velocity particle->get_location() += (particle->axis().forward() * particle->speed() * seconds); - // set particle radius_vec and alpha_vec + // interpolate particle radius, color and alpha const float age = (float) (now - particle->timestamp()); const float halflife = offset() * (float) lifespan(); + float t; if (age < halflife) { - const float t = age / halflife; + t = age / halflife; particle->set_radius((1.0f - t) * radius_vec()[0] + t * radius_vec()[1]); - particle->set_alpha((1.0f - t) * alpha_vec()[0] + t * alpha_vec()[1]); + particle->get_color().a = ((1.0f - t) * alpha_vec()[0] + t * alpha_vec()[1]); + + t *= 0.5f; + } else { - const float t = (age - halflife) / ((float) lifespan() - halflife); + t = (age - halflife) / ((float) lifespan() - halflife); particle->set_radius((1.0f - t) * radius_vec()[1] + t * radius_vec()[2]); - particle->set_alpha((1.0f - t) * alpha_vec()[1] + t * alpha_vec()[2]); + particle->get_color().a = ((1.0f - t) * alpha_vec()[1] + t * alpha_vec()[2]); + + t = 0.5f + t * 0.5f; + } + + if (color_interpolated()) { + particle->get_color().r = color().r * (1.0f - t) + color_second().r * t; + particle->get_color().g = color().g * (1.0f - t) + color_second().g * t; + particle->get_color().b = color().b * (1.0f - t) + color_second().b * t; } } @@ -183,8 +199,6 @@ void ParticleEjectorSprite::draw(const math::Vector3f & ps_location, const math: quad[2].assign((Camera::axis().up() * -1 + Camera::axis().left())); quad[3].assign((Camera::axis().up() * -1 - Camera::axis().left())); - math::Color c(color()); - for (Particles::iterator it = particles().begin(); it != particles().end(); it++) { Particle *particle = (*it); @@ -194,8 +208,7 @@ void ParticleEjectorSprite::draw(const math::Vector3f & ps_location, const math: math::Vector3f l(attached() ? ps_location + ps_axis * particle->location() : particle->location()); const float r = particle->radius(); - c.a = particle->alpha(); - gl::color(c); + gl::color(particle->color()); glTexCoord2f(0, 1); gl::vertex(l + rotation * quad[0] * r); @@ -226,7 +239,7 @@ void ParticleEjectorFlare::draw(const math::Vector3f & ps_location, const math:: { Textures::bind(texture()); gl::begin(gl::Quads); - math::Color c(color()); + for (Particles::iterator it = particles().begin(); it != particles().end(); it++) { Particle *particle = (*it); @@ -234,8 +247,7 @@ void ParticleEjectorFlare::draw(const math::Vector3f & ps_location, const math:: math::Axis particle_axis(attached() ? ps_axis * particle->axis() : particle->axis()); const float r = particle->radius(); - c.a = particle->alpha(); - gl::color(c); + gl::color(particle->color()); glTexCoord2f(0, 1); gl::vertex(particle_location + (particle_axis.up() - particle_axis.left()) * r); @@ -268,7 +280,7 @@ void ParticleEjectorTrail::draw(const math::Vector3f & ps_location, const math:: return; } - (*particles().rbegin())->set_alpha(0.0f); + (*particles().rbegin())->get_color().a = (0.0f); Particles::iterator first = particles().begin(); Particles::iterator next = first; @@ -277,9 +289,7 @@ void ParticleEjectorTrail::draw(const math::Vector3f & ps_location, const math:: Textures::bind(texture()); gl::begin(gl::Quads); - math::Color c(color()); - c.a = (*first)->alpha(); - gl::color(c); + gl::color((*first)->color()); //math::Vector3f first_location(attached() ? ps_location + ps_axis * (*first)->location() : (*first)->location()); math::Vector3f first_normal(math::crossproduct(((*first)->location() - ps_location), ((*first)->location() - Camera::eye()))); @@ -287,14 +297,17 @@ void ParticleEjectorTrail::draw(const math::Vector3f & ps_location, const math:: math::Vector3f next_normal(first_normal); + const float length = (float) particles().size(); + float position = 1.0f; + glTexCoord2f(1, 0); gl::vertex(ps_location - first_normal * (*first)->radius()); glTexCoord2f(0, 0); gl::vertex(ps_location + first_normal * (*first)->radius()); - glTexCoord2f(0, 1); + glTexCoord2f(0, position / length); gl::vertex((*first)->location() + next_normal * (*first)->radius()); - glTexCoord2f(1, 1); + glTexCoord2f(1, position / length); gl::vertex((*first)->location() - next_normal * (*first)->radius()); Stats::quads++; @@ -302,20 +315,20 @@ void ParticleEjectorTrail::draw(const math::Vector3f & ps_location, const math:: next_normal.assign(math::crossproduct(((*next)->location() - (*first)->location()), ((*next)->location() - Camera::eye()))); next_normal.normalize(); - c.a = (*first)->alpha(); - gl::color(c); + gl::color((*first)->color()); - glTexCoord2f(1, 0); + glTexCoord2f(1, position / length); gl::vertex((*first)->location() - first_normal * (*first)->radius()); - glTexCoord2f(0, 0); + glTexCoord2f(0, position / length); gl::vertex((*first)->location() + first_normal * (*first)->radius()); - c.a = (*next)->alpha(); - gl::color(c); + gl::color((*next)->color()); - glTexCoord2f(0, 1); + position += 1.0f; + + glTexCoord2f(0, position / length); gl::vertex((*next)->location() + next_normal * (*next)->radius()); - glTexCoord2f(1, 1); + glTexCoord2f(1, position / length); gl::vertex((*next)->location() - next_normal * (*next)->radius()); Stats::quads++; @@ -352,7 +365,6 @@ void ParticleEjectorStreak::draw(const math::Vector3f & ps_location, const math: Particles::iterator next = first; math::Vector3f normal; - math::Color c(color()); Textures::bind(texture()); gl::begin(gl::Quads); @@ -368,16 +380,14 @@ void ParticleEjectorStreak::draw(const math::Vector3f & ps_location, const math: normal.assign(math::crossproduct((first_location - Camera::eye()), (next_location - Camera::eye()))); normal.normalize(); - c.a = (*first)->alpha(); - gl::color(c); + gl::color((*first)->color()); glTexCoord2f(1, 0); gl::vertex(first_location - normal * (*first)->radius()); glTexCoord2f(0, 0); gl::vertex(first_location + normal * (*first)->radius()); - c.a = (*next)->alpha(); - gl::color(c); + gl::color((*next)->color()); glTexCoord2f(0, 1); gl::vertex(next_location + normal * (*next)->radius()); |