Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2013-01-21 18:37:59 +0000
committerStijn Buys <ingar@osirion.org>2013-01-21 18:37:59 +0000
commit266d0d2cf6648509650bdd490c8e9c64be75b92e (patch)
treedf5fdb640ed09edcf044efdc8784b18a5881a513 /src/render/particleejector.cc
parentd4f9da2f3c19511b028da2569d7b6a8d1371e135 (diff)
Added attached property to draw particle systems in entity space instead of world space,
corrected several bugs in the initial particle system implementation, added impulse key to have particle systems react on impulse drive.
Diffstat (limited to 'src/render/particleejector.cc')
-rw-r--r--src/render/particleejector.cc69
1 files changed, 39 insertions, 30 deletions
diff --git a/src/render/particleejector.cc b/src/render/particleejector.cc
index 5b26d59..091743d 100644
--- a/src/render/particleejector.cc
+++ b/src/render/particleejector.cc
@@ -48,29 +48,36 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat
}
// add new particles
- if ( (ejector_enabled) && (ejector_last_eject + interval() <= now) )
- {
- math::Vector3f particle_location(ps_location);
- math::Axis particle_axis(ps_axis * axis());
-
- if (cone() > 0) {
- particle_axis.change_roll(math::randomf(360.0f));
- particle_axis.change_pitch(math::randomf(cone()) - (cone() * 0.5f) );
- }
- if (spawn_radius() > 0) {
- // FIXME find a faster formula
- math::Axis random_axis(ps_axis);
- random_axis.change_roll(math::randomf(360.0f));
- random_axis.change_pitch(math::randomf(180.0f));
- particle_location += random_axis.forward() * spawn_radius();
+ if (ejector_enabled) {
+ if (ejector_last_eject + interval() <= now) {
+ math::Vector3f particle_location;
+ math::Axis particle_axis;
+ if (!attached()) {
+ particle_location.assign(ps_location);
+ particle_axis.assign(ps_axis);
+ }
+
+ if (cone() > 0) {
+ particle_axis.change_roll(math::randomf(360.0f));
+ particle_axis.change_pitch(math::randomf(cone()) - (cone() * 0.5f) );
+ }
+ if (spawn_radius() > 0) {
+ // FIXME find a faster formula
+ math::Axis random_axis(ps_axis);
+ random_axis.change_roll(math::randomf(360.0f));
+ random_axis.change_pitch(math::randomf(180.0f));
+ particle_location += random_axis.forward() * spawn_radius();
+ }
+
+ Particle *particle = new Particle(particle_location, particle_axis.forward() * speed(), now);
+ particle->set_radius(radius_vec()[0]);
+ particle->set_alpha(alpha_vec()[0]);
+
+ particles().push_front(particle);
+ ejector_last_eject = now;
}
-
- Particle *particle = new Particle(particle_location, particle_axis.forward() * speed(), now);
- particle->set_radius(radius_vec()[0]);
- particle->set_alpha(alpha_vec()[0]);
-
- particles().push_front(particle);
- ejector_last_eject = now;
+ } else {
+ ejector_last_eject = 0;
}
for (Particles::iterator it = particles().begin(); it != particles().end(); ++it) {
@@ -115,11 +122,11 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat
}
if (particles().size()) {
- draw(ps_location);
+ draw(ps_location, ps_axis);
}
}
-void ParticleEjector::draw(const math::Vector3f & ps_location)
+void ParticleEjector::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis)
{
}
@@ -136,7 +143,7 @@ ParticleEjectorSpray::~ParticleEjectorSpray()
}
-void ParticleEjectorSpray::draw(const math::Vector3f & ps_location)
+void ParticleEjectorSpray::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis)
{
math::Vector3f quad[4];
Textures::bind(texture());
@@ -152,19 +159,20 @@ void ParticleEjectorSpray::draw(const math::Vector3f & ps_location)
for (Particles::iterator it = particles().begin(); it != particles().end(); it++) {
Particle *particle = (*it);
+ math::Vector3f l(attached() ? ps_location + ps_axis * particle->location() : particle->location());
const float r = particle->radius();
c.a = particle->alpha();
gl::color(c);
glTexCoord2f(0, 1);
- gl::vertex(particle->location() + quad[0] * r);
+ gl::vertex(l + quad[0] * r);
glTexCoord2f(0, 0);
- gl::vertex(particle->location() + quad[1] * r);
+ gl::vertex(l + quad[1] * r);
glTexCoord2f(1, 0);
- gl::vertex(particle->location() + quad[2] * r);
+ gl::vertex(l + quad[2] * r);
glTexCoord2f(1, 1);
- gl::vertex(particle->location() + quad[3] * r);
+ gl::vertex(l + quad[3] * r);
Stats::quads++;
}
gl::end();
@@ -182,7 +190,7 @@ ParticleEjectorTrail::~ParticleEjectorTrail()
}
-void ParticleEjectorTrail::draw(const math::Vector3f & ps_location)
+void ParticleEjectorTrail::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis)
{
if (!particles().size()) {
return;
@@ -201,6 +209,7 @@ void ParticleEjectorTrail::draw(const math::Vector3f & ps_location)
c.a = (*first)->alpha();
gl::color(c);
+ //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())));
first_normal.normalize();