Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/render/particle.cc13
-rw-r--r--src/render/particle.h39
-rw-r--r--src/render/particleejector.cc53
-rw-r--r--src/render/particleejector.h14
-rw-r--r--src/render/particleejectorscript.cc4
-rw-r--r--src/render/particleejectorscript.h21
-rw-r--r--src/render/particlesystem.cc4
-rw-r--r--src/render/particlesystemscript.cc13
8 files changed, 140 insertions, 21 deletions
diff --git a/src/render/particle.cc b/src/render/particle.cc
index ddd8abd..5925ba5 100644
--- a/src/render/particle.cc
+++ b/src/render/particle.cc
@@ -16,13 +16,22 @@ Particle::Particle(const math::Vector3f &location, const unsigned long timestamp
particle_location(location)
{
particle_timestamp = timestamp;
+
+ particle_speed = 0.0f;
+ particle_radius = 0.0f;
+ particle_alpha = 0.0f;
+
}
-Particle::Particle(const math::Vector3f &location, const math::Vector3f &velocity, const unsigned long timestamp) :
+Particle::Particle(const math::Vector3f &location, const math::Axis &axis, const unsigned long timestamp) :
particle_location(location),
- particle_velocity(velocity)
+ particle_axis(axis)
{
particle_timestamp = timestamp;
+
+ particle_speed = 0.0f;
+ particle_radius = 0.0f;
+ particle_alpha = 0.0f;
}
} //namespace render
diff --git a/src/render/particle.h b/src/render/particle.h
index 0370660..c259dbc 100644
--- a/src/render/particle.h
+++ b/src/render/particle.h
@@ -22,7 +22,7 @@ class Particle
{
public:
Particle(const math::Vector3f &location, const unsigned long timestamp);
- Particle(const math::Vector3f &location, const math::Vector3f &velocity, const unsigned long timestamp);
+ Particle(const math::Vector3f &location, const math::Axis &axis, const unsigned long timestamp);
/* ---- inspectors ----------------------------------------- */
@@ -36,10 +36,18 @@ public:
}
/**
- * @brief velocity vector of the particle
+ * @brief axis vector of the particle
* */
- inline const math::Vector3f &velocity() const {
- return particle_velocity;
+ inline const math::Axis &axis() const {
+ return particle_axis;
+ }
+
+ /**
+ * @brief speed of the particle
+ * */
+ const float speed() const
+ {
+ return particle_speed;
}
/**
@@ -83,10 +91,10 @@ public:
}
/**
- * @brief reference velocity vector of the particle
+ * @brief reference axis vector of the particle
* */
- inline math::Vector3f &get_velocity() {
- return particle_velocity;
+ inline math::Axis &get_axis() {
+ return particle_axis;
}
/**
@@ -98,11 +106,19 @@ public:
}
/**
- * @brief set the velocity of the particle
+ * @brief set the axis of the particle
+ * */
+ inline void set_axis(const math::Axis &axis)
+ {
+ particle_axis.assign(axis);
+ }
+
+ /**
+ * @brief set the speed of the particle
* */
- inline void set_velocity(const math::Vector3f &velocity)
+ inline void set_speed(const float speed)
{
- particle_velocity.assign(velocity);
+ particle_speed = speed;
}
/**
@@ -132,10 +148,11 @@ public:
protected:
math::Vector3f particle_location;
- math::Vector3f particle_velocity;
+ math::Axis particle_axis;
float particle_radius;
float particle_alpha;
float particle_rotation;
+ float particle_speed;
unsigned long particle_timestamp;
};
diff --git a/src/render/particleejector.cc b/src/render/particleejector.cc
index c697e8f..92b8d8f 100644
--- a/src/render/particleejector.cc
+++ b/src/render/particleejector.cc
@@ -59,9 +59,8 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat
particle_location.assign(ps_location);
particle_axis.assign(ps_axis);
}
-
+ particle_axis.change_roll(math::randomf(360.0f));
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) {
@@ -72,11 +71,11 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat
particle_location += random_axis.forward() * spawn_radius();
}
- Particle *particle = new Particle(particle_location, particle_axis.forward() * speed(), now);
+ Particle *particle = new Particle(particle_location, particle_axis, now);
particle->set_radius(radius_vec()[0]);
particle->set_alpha(alpha_vec()[0]);
particle->set_rotation(math::randomf(2.0f * M_PI));
-
+ particle->set_speed(speed());
particles().push_front(particle);
ejector_last_eject = now;
}
@@ -87,8 +86,12 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat
for (Particles::iterator it = particles().begin(); it != particles().end(); ++it) {
Particle *particle = (*it);
if (particle->timestamp() < now) {
+ // apply acceleration
+ if (acceleration()) {
+ particle->set_speed(particle->speed() + acceleration() * seconds);
+ }
// apply velocity
- particle->get_location() += (particle->velocity() * seconds);
+ particle->get_location() += (particle->axis().forward() * particle->speed() * seconds);
// set particle radius_vec and alpha_vec
const float age = (float) (now - particle->timestamp());
@@ -185,6 +188,46 @@ void ParticleEjectorSprite::draw(const math::Vector3f & ps_location, const math:
gl::end();
}
+/* ---- class ParticleEjectorFlare --------------------------------- */
+
+ParticleEjectorFlare::ParticleEjectorFlare(const ParticleEjectorScript &script) : ParticleEjector(script)
+{
+
+}
+
+ParticleEjectorFlare::~ParticleEjectorFlare()
+{
+
+}
+
+void ParticleEjectorFlare::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis)
+{
+ Textures::bind(texture());
+ gl::begin(gl::Quads);
+ math::Color c(color());
+ for (Particles::iterator it = particles().begin(); it != particles().end(); it++) {
+ Particle *particle = (*it);
+
+ math::Vector3f particle_location(attached() ? ps_location + ps_axis * particle->location() : particle->location());
+ math::Axis particle_axis(attached() ? ps_axis * particle->axis() : particle->axis());
+ const float r = particle->radius();
+
+ c.a = particle->alpha();
+ gl::color(c);
+
+ glTexCoord2f(0, 1);
+ gl::vertex(particle_location + (particle_axis.up() - particle_axis.left()) * r);
+ glTexCoord2f(0, 0);
+ gl::vertex(particle_location + (particle_axis.up() + particle_axis.left()) * r);
+ glTexCoord2f(1, 0);
+ gl::vertex(particle_location + (particle_axis.up() * -1 + particle_axis.left()) * r);
+ glTexCoord2f(1, 1);
+ gl::vertex(particle_location + (particle_axis.up() * -1 - particle_axis.left()) * r);
+ Stats::quads++;
+ }
+ gl::end();
+}
+
/* ---- class ParticleEjectorTrail --------------------------------- */
ParticleEjectorTrail::ParticleEjectorTrail(const ParticleEjectorScript &script) : ParticleEjector(script)
diff --git a/src/render/particleejector.h b/src/render/particleejector.h
index 4d3ace9..17e4688 100644
--- a/src/render/particleejector.h
+++ b/src/render/particleejector.h
@@ -76,6 +76,7 @@ private:
/**
* @brief Sprite particles
+ * Sprites are rendered facing the camera
* */
class ParticleEjectorSprite : public ParticleEjector {
public:
@@ -87,6 +88,19 @@ protected:
};
/**
+ * @brief Flare particles
+ * Flare are rendered along the particle axis
+ * */
+class ParticleEjectorFlare : public ParticleEjector {
+public:
+ ParticleEjectorFlare(const ParticleEjectorScript &script);
+ virtual ~ParticleEjectorFlare();
+
+protected:
+ virtual void draw(const math::Vector3f & ps_location, const math::Axis & ps_axis);
+};
+
+/**
* @brief Trail particles
* */
class ParticleEjectorTrail : public ParticleEjector {
diff --git a/src/render/particleejectorscript.cc b/src/render/particleejectorscript.cc
index 1aabbe7..a37ab9d 100644
--- a/src/render/particleejectorscript.cc
+++ b/src/render/particleejectorscript.cc
@@ -18,6 +18,7 @@ ParticleEjectorScript::ParticleEjectorScript()
script_offset = 0.5f;
script_lifespan = 1000;
script_speed = 0;
+ script_acceleration = 0.0f;
script_entity = false;
script_entity_second = false;
script_engine = false;
@@ -25,7 +26,7 @@ ParticleEjectorScript::ParticleEjectorScript()
script_thrust = false;
script_cull = model::CullNone;
script_spawn_radius = 0.0f;
- script_attached = false;
+ script_attached = false;
}
ParticleEjectorScript::ParticleEjectorScript(const ParticleEjectorScript &other)
@@ -37,6 +38,7 @@ ParticleEjectorScript::ParticleEjectorScript(const ParticleEjectorScript &other)
script_offset = other.offset();
script_lifespan = other.lifespan();
script_speed = other.speed();
+ script_acceleration = other.acceleration();
script_entity = other.entity();
script_entity_second = other.entity_second();
script_engine = other.engine();
diff --git a/src/render/particleejectorscript.h b/src/render/particleejectorscript.h
index 03f7294..e7c135f 100644
--- a/src/render/particleejectorscript.h
+++ b/src/render/particleejectorscript.h
@@ -20,7 +20,7 @@ public:
/**
* @brief definition for type of ejector
* */
- enum Type { Sprite = 0, Flare = 1, Trail = 2, Flame = 3 };
+ enum Type { Sprite = 0, Flare = 1, Trail = 2, Flame = 3 , Streak = 4 };
ParticleEjectorScript();
ParticleEjectorScript(const ParticleEjectorScript & other);
@@ -166,6 +166,14 @@ public:
return script_speed;
}
+ /**
+ * @brief acceleration of ejected particles, in gameunits per second squared
+ * */
+ inline const float acceleration() const
+ {
+ return script_acceleration;
+ }
+
/**
* @brief spawn radius
* radius within wich particles are spawn
@@ -234,6 +242,14 @@ public:
}
/**
+ * @brief set the acceleration of ejected particles, in gameunits per second squared
+ * */
+ inline void set_acceleration(const float acceleration)
+ {
+ script_acceleration = acceleration;
+ }
+
+ /**
* @brief set ejector cone, in degrees
* */
inline void set_cone(const float cone)
@@ -373,7 +389,8 @@ private:
/// speed of ejected particles, in gameunits per second
float script_speed;
-
+ /// acceleration of ejected particles, in gameunits per second squared
+ float script_acceleration;
/// spawn radius
float script_spawn_radius;
diff --git a/src/render/particlesystem.cc b/src/render/particlesystem.cc
index e6f8ccc..8fe0e13 100644
--- a/src/render/particlesystem.cc
+++ b/src/render/particlesystem.cc
@@ -36,6 +36,10 @@ ParticleSystem::ParticleSystem(const ParticleSystemScript *script, const core::E
ejector = new ParticleEjectorSprite(*(*it));
break;
+ case ParticleEjector::Flare:
+ ejector = new ParticleEjectorFlare(*(*it));
+ break;
+
case ParticleEjector::Trail:
ejector = new ParticleEjectorTrail(*(*it));
break;
diff --git a/src/render/particlesystemscript.cc b/src/render/particlesystemscript.cc
index ff75093..7344aab 100644
--- a/src/render/particlesystemscript.cc
+++ b/src/render/particlesystemscript.cc
@@ -38,6 +38,9 @@ void ParticleSystemScript::list()
case ParticleEjectorScript::Flame:
strval.append(" flame");
break;
+ case ParticleEjectorScript::Streak:
+ strval.append(" streak");
+ break;
}
}
con_print << " " << script->label() << strval << " " << script->script_ejectors.size() << " " << aux::plural("ejector", script->script_ejectors.size()) << std::endl;
@@ -124,6 +127,8 @@ ParticleSystemScript *ParticleSystemScript::load(const std::string &label)
ejector->set_type(ParticleEjectorScript::Trail);
} else if (strval.compare("flame") == 0) {
ejector->set_type(ParticleEjectorScript::Flame);
+ } else if (strval.compare("streak") == 0) {
+ ejector->set_type(ParticleEjectorScript::Streak);
} else {
inifile.unknown_value();
}
@@ -152,6 +157,11 @@ ParticleSystemScript *ParticleSystemScript::load(const std::string &label)
ejector->set_speed(f * 0.01f);
continue;
+ } else if (inifile.got_key_float("acceleration", f)) {
+ // convert speed from meters/second to game units/second
+ ejector->set_acceleration(f * 0.01f);
+ continue;
+
} else if (inifile.got_key_float("offset", f)) {
math::clamp(f, 0.0f, 1.0f);
ejector->set_offset(f);
@@ -278,6 +288,9 @@ ParticleSystemScript *ParticleSystemScript::load(const std::string &label)
case ParticleEjectorScript::Flame:
strval.append(" flame");
break;
+ case ParticleEjectorScript::Streak:
+ strval.append(" streak");
+ break;
}
}
con_debug << " " << script->label() << strval << " " << script->script_ejectors.size() << " " << aux::plural("ejector", script->script_ejectors.size()) << std::endl;