Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/render/draw.cc4
-rw-r--r--src/render/particles.cc129
-rw-r--r--src/render/particles.h28
-rw-r--r--src/render/renderext.cc33
-rw-r--r--src/render/renderext.h1
5 files changed, 117 insertions, 78 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 88a08b9..3d71ad4 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -966,10 +966,10 @@ void draw_pass_model_fx(float elapsed)
for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) {
core::Entity *entity = (*it);
- if (entity->model() && ext_render(entity)->detailvisible() && ext_render(entity)->power()) {
+ if (entity->model() && ext_render(entity)->detailvisible()) {
// draw lights and flares
- if (draw_lights) {
+ if (ext_render(entity)->power() && draw_lights) {
const float modelscale = entity->radius() / entity->model()->radius();
draw_model_lights(entity->model(), modelscale,
diff --git a/src/render/particles.cc b/src/render/particles.cc
index 40b79ad..2cc1b1a 100644
--- a/src/render/particles.cc
+++ b/src/render/particles.cc
@@ -135,6 +135,8 @@ ParticleScript *ParticleScript::load(const std::string &label)
script->particlescript_type = ParticleScript::Jet;
} else if (strval.compare("trail") == 0) {
script->particlescript_type = ParticleScript::Trail;
+ } else if (strval.compare("spray") == 0) {
+ script->particlescript_type = ParticleScript::Spray;
} else {
inifile.unknown_value();
}
@@ -387,7 +389,16 @@ void ParticleSystem::draw(const float elapsed)
// add new particles
if (ejector_active && (particlesystem_last_eject + particlesystem_script->eject() <= now)) {
- particlesystem_stream.push_front(new Particle(ejector_location, particlesystem_entity->axis() * particlesystem_axis, now));
+ math::Axis particle_axis(particlesystem_entity->axis() * particlesystem_axis);
+ math::Vector3f particle_location(ejector_location);
+
+ if (particlesystem_script->type() == ParticleScript::Spray) {
+ particle_axis.change_direction(math::randomf(180));
+ particle_axis.change_pitch(math::randomf(180));
+ particle_axis.change_roll(math::randomf(180));
+ particle_location += particle_axis.forward() * particlesystem_entity->radius() * 0.5f;
+ }
+ particlesystem_stream.push_front(new Particle(particle_location, particle_axis, now));
particlesystem_last_eject = now;
}
}
@@ -453,68 +464,6 @@ void Jet::draw(const float elapsed)
gl::end();
}
}
-/* ---- class Spray ------------------------------------------------ */
-
-Spray::Spray(const ParticleScript *script, const core::Entity *entity, const model::Particles *modelclass) :
- ParticleSystem(script, entity, modelclass)
-{
-}
-
-Spray::~Spray()
-{}
-
-void Spray::draw(const float elapsed)
-{
- if (!particlesystem_script)
- return;
-
- ParticleSystem::draw(elapsed);
-
- math::Vector3f quad[4];
-
- if (particlesystem_stream.size()) {
- Textures::bind(particlesystem_texture);
- gl::begin(gl::Quads);
-
- for (Stream::iterator it = particlesystem_stream.begin(); it != particlesystem_stream.end(); it++) {
- Particle *particle = (*it);
-
- quad[0].assign(Camera::axis().up() - Camera::axis().left());
- quad[1].assign(Camera::axis().up() + Camera::axis().left());
- quad[2].assign(Camera::axis().up() * -1 + Camera::axis().left());
- quad[3].assign(Camera::axis().up() * -1 - Camera::axis().left());
-
- float t = now - particle->time();
- float f = 0;
-
- if (t < particlesystem_script->timeout() * 0.1f) {
- f = t / (0.1f * particlesystem_script->timeout());
- } else {
- t = t - particlesystem_script->timeout() * 0.1f;
- f = t / (0.9f * particlesystem_script->timeout());
- f = 1.0 - f;
- }
-
- f *= f;
- float radius = particlesystem_radius * f;
- particlesystem_color.a = f * particlesystem_script->alpha();
- gl::color(particlesystem_color);
-
- glTexCoord2f(0, 1);
- gl::vertex(particle->location() + quad[0] * radius);
- glTexCoord2f(0, 0);
- gl::vertex(particle->location() + quad[1] * radius);
- glTexCoord2f(1, 0);
- gl::vertex(particle->location() + quad[2] * radius);
- glTexCoord2f(1, 1);
- gl::vertex(particle->location() + quad[3] * radius);
- Stats::quads++;
- }
-
- gl::end();
- }
-}
-
/* ---- class Trail ------------------------------------------------ */
@@ -799,4 +748,58 @@ void Flame::draw(const float elapsed)
}
}
+/* ---- class Spray ------------------------------------------------ */
+
+Spray::Spray(const ParticleScript *script, const core::Entity *entity, const model::Particles *modelclass) :
+ ParticleSystem(script, entity, modelclass)
+{
+}
+
+Spray::~Spray()
+{
+}
+
+void Spray::draw(const float elapsed)
+{
+ if (!particlesystem_script)
+ return;
+
+ ParticleSystem::draw(elapsed);
+
+ math::Vector3f quad[4];
+
+ if (particlesystem_stream.size()) {
+ Textures::bind(particlesystem_texture);
+ gl::begin(gl::Quads);
+
+ quad[0].assign((Camera::axis().up() - Camera::axis().left()));
+ quad[1].assign((Camera::axis().up() + Camera::axis().left()));
+ quad[2].assign((Camera::axis().up() * -1 + Camera::axis().left()));
+ quad[3].assign((Camera::axis().up() * -1 - Camera::axis().left()));
+
+ for (Stream::iterator it = particlesystem_stream.begin(); it != particlesystem_stream.end(); it++) {
+ Particle *particle = (*it);
+
+ const float t = now - particle->time();
+ const float f = t / particlesystem_script->timeout();
+ const float radius = particlesystem_radius * f;
+
+ particlesystem_color.a = (1.0f - f) * particlesystem_script->alpha();
+ gl::color(particlesystem_color);
+
+ glTexCoord2f(0, 1);
+ gl::vertex(particle->location() + quad[0] * radius);
+ glTexCoord2f(0, 0);
+ gl::vertex(particle->location() + quad[1] * radius);
+ glTexCoord2f(1, 0);
+ gl::vertex(particle->location() + quad[2] * radius);
+ glTexCoord2f(1, 1);
+ gl::vertex(particle->location() + quad[3] * radius);
+ Stats::quads++;
+ }
+
+ gl::end();
+ }
+}
+
} // namespace render
diff --git a/src/render/particles.h b/src/render/particles.h
index a41065c..c2d9c02 100644
--- a/src/render/particles.h
+++ b/src/render/particles.h
@@ -128,6 +128,7 @@ public:
static void clear();
static void list();
+
private:
static ParticleScript *find(const std::string &label);
@@ -253,18 +254,6 @@ public:
virtual void draw(const float elapsed);
};
-/* ---- class Spray ----------------------------------------------- */
-
-/// spray style particles
-class Spray : public ParticleSystem
-{
-public:
- Spray(const ParticleScript *script, const core::Entity *entity, const model::Particles *modelclass);
- virtual ~Spray();
-
- virtual void draw(const float elapsed);
-};
-
/* ---- class Trail ------------------------------------------------ */
/// trail style particles, like an engine trail
@@ -277,6 +266,21 @@ public:
virtual void draw(float elapsed);
};
+/* ---- class Spray ----------------------------------------------- */
+
+/**
+ * @brief spray style particles
+ * a spray is a sprite ejector
+ * */
+class Spray : public ParticleSystem
+{
+public:
+ Spray(const ParticleScript *script, const core::Entity *entity, const model::Particles *modelclass);
+ virtual ~Spray();
+
+ virtual void draw(const float elapsed);
+};
+
} // namespace render
#endif // __INCLUDED_RENDER_PARTICLES_H__
diff --git a/src/render/renderext.cc b/src/render/renderext.cc
index 51b7976..20c4cae 100644
--- a/src/render/renderext.cc
+++ b/src/render/renderext.cc
@@ -26,6 +26,7 @@ RenderExt::RenderExt(core::Entity *entity) : core::Extension(core::Extension::Re
state_detailvisible = false;
state_fuzz = math::randomf();
state_enginetime = state_fuzz * core::application()->time();
+ state_explosion = 0;
if (!entity->model() && entity->modelname().size()) {
entity->set_modelname(entity->modelname());
@@ -64,12 +65,15 @@ RenderExt::RenderExt(core::Entity *entity) : core::Extension(core::Extension::Re
if ( script->type() == render::ParticleScript::Trail) {
Trail *trail = new Trail(script, entity, particlesystem);
state_particles.push_back(trail);
+
} else if (script->type() == render::ParticleScript::Jet) {
Jet *jet = new Jet(script, entity, particlesystem);
state_particles.push_back(jet);
+
} else if (script->type() == render::ParticleScript::Spray) {
Spray *spray = new Spray(script, entity, particlesystem);
state_particles.push_back(spray);
+
} else if (script->type() == render::ParticleScript::Flame) {
Flame *flame = new Flame(script, entity, particlesystem);
state_particles.push_back(flame);
@@ -118,9 +122,11 @@ void RenderExt::frame(float elapsed)
if (!state_visible)
return;
+ int state = core::Entity::Normal;
+
if (entity()->type() == core::Entity::Dynamic) {
- int state = static_cast<core::EntityDynamic *>(entity())->state();
+ state = static_cast<core::EntityDynamic *>(entity())->state();
if ((state == core::Entity::NoPower) || (state == core::Entity::Destroyed)) {
state_power = false;
@@ -131,6 +137,8 @@ void RenderExt::frame(float elapsed)
} else if ((entity()->type() == core::Entity::Controlable)) {
core::EntityControlable *controlable = static_cast<core::EntityControlable *>(entity());
+
+ state = controlable->state();
if (controlable->state() == core::Entity::Docked) {
state_visible = false;
@@ -159,6 +167,29 @@ void RenderExt::frame(float elapsed)
state_enginetime += elapsed;
}
+ if (state == core::Entity::Destroyed) {
+
+ if (!state_explosion) {
+ // add explosion
+ const ParticleScript *script = ParticleScript::load("explosion");
+ if (script) {
+ state_explosion = (ParticleSystem *) new Spray(script, entity(), 0);
+ state_particles.push_back(state_explosion);
+ }
+ }
+
+ } else {
+ if (state_explosion) {
+ // remove explosion
+ for (ParticleSystems::iterator it = particles().begin(); state_explosion && (it != particles().end()); it++) {
+ if ((*it) == state_explosion) {
+ particles().erase(it);
+ state_explosion = 0;
+ }
+ }
+ }
+ }
+
if (entity()->model()) {
if (distance() < core::range::fxdistance) {
diff --git a/src/render/renderext.h b/src/render/renderext.h
index b70b4a0..14dbaa3 100644
--- a/src/render/renderext.h
+++ b/src/render/renderext.h
@@ -85,6 +85,7 @@ private:
float state_thrust;
ParticleSystems state_particles;
+ ParticleSystem *state_explosion;
};
} // namespace render