Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/particles.cc')
-rw-r--r--src/render/particles.cc163
1 files changed, 86 insertions, 77 deletions
diff --git a/src/render/particles.cc b/src/render/particles.cc
index 13b69a4..6ffcd35 100644
--- a/src/render/particles.cc
+++ b/src/render/particles.cc
@@ -12,7 +12,8 @@
#include "render/textures.h"
#include "core/application.h"
-namespace render {
+namespace render
+{
/* ---- class Particle --------------------------------------------- */
@@ -35,7 +36,7 @@ void ParticleScript::list()
{
std::string str;
for (Registry::iterator it = particles_registry.begin(); it != particles_registry.end(); it++) {
-
+
ParticleScript *script = (*it).second;
switch (script->type()) {
case Flame:
@@ -59,16 +60,16 @@ void ParticleScript::list()
void ParticleScript::clear()
{
for (Registry::iterator it = particles_registry.begin(); it != particles_registry.end(); it++) {
- delete (*it).second;
+ delete(*it).second;
(*it).second = 0;
}
- particles_registry.clear();
+ particles_registry.clear();
}
ParticleScript *ParticleScript::find(const std::string &label)
{
Registry::iterator it = particles_registry.find(label);
-
+
if (it != particles_registry.end()) {
return (*it).second;
} else {
@@ -195,7 +196,7 @@ ParticleSystem::ParticleSystem(ParticleScript *script, core::Entity *entity, mod
particlesystem_radius = modelclass->radius();
else
particlesystem_radius = particlesystem_script->radius();
-
+
color.assign(particlesystem_script->color());
}
@@ -220,7 +221,7 @@ ParticleSystem::~ParticleSystem()
void ParticleSystem::clear()
{
for (Stream::iterator it = particlesystem_stream.begin(); it != particlesystem_stream.end(); it++) {
- delete (*it);
+ delete(*it);
}
particlesystem_stream.clear();
}
@@ -242,7 +243,7 @@ void ParticleSystem::draw(float elapsed)
// remove dead particles
Stream::reverse_iterator it = particlesystem_stream.rbegin();
while ((it != particlesystem_stream.rend()) && ((*it)->time() + particlesystem_script->timeout() <= now)) {
- delete (*particlesystem_stream.rbegin());
+ delete(*particlesystem_stream.rbegin());
particlesystem_stream.pop_back();
it = particlesystem_stream.rbegin();
}
@@ -279,13 +280,15 @@ void ParticleSystem::draw(float elapsed)
/* ---- class Jet -------------------------------------------------- */
Jet::Jet(ParticleScript *script, core::Entity *entity, model::Particles *modelclass) :
- ParticleSystem(script, entity, modelclass) {
+ ParticleSystem(script, entity, modelclass)
+{
}
Jet::~Jet()
{}
-void Jet::draw(float elapsed) {
+void Jet::draw(float elapsed)
+{
if (!particlesystem_script)
return;
@@ -299,12 +302,12 @@ void Jet::draw(float elapsed) {
for (Stream::iterator it = particlesystem_stream.begin(); it != particlesystem_stream.end(); it++) {
Particle *particle = (*it);
-
+
quad[0].assign(particle->axis().up() - particle->axis().left());
quad[1].assign(particle->axis().up() + particle->axis().left());
quad[2].assign(particle->axis().up() * -1 + particle->axis().left());
quad[3].assign(particle->axis().up() * -1 - particle->axis().left());
-
+
float t = now - particle->time();
float f = 0;
@@ -320,14 +323,14 @@ void Jet::draw(float elapsed) {
float radius = particlesystem_radius * f;
color.a = f * particlesystem_script->alpha();
gl::color(color);
-
- glTexCoord2f(0,1);
+
+ glTexCoord2f(0, 1);
gl::vertex(particle->location() + quad[0] * radius);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(particle->location() + quad[1] * radius);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(particle->location() + quad[2] * radius);
- glTexCoord2f(1,1);
+ glTexCoord2f(1, 1);
gl::vertex(particle->location() + quad[3] * radius);
Stats::quads++;
}
@@ -338,13 +341,15 @@ void Jet::draw(float elapsed) {
/* ---- class Spray ------------------------------------------------ */
Spray::Spray(ParticleScript *script, core::Entity *entity, model::Particles *modelclass) :
- ParticleSystem(script, entity, modelclass) {
+ ParticleSystem(script, entity, modelclass)
+{
}
Spray::~Spray()
{}
-void Spray::draw(float elapsed) {
+void Spray::draw(float elapsed)
+{
if (!particlesystem_script)
return;
@@ -358,12 +363,12 @@ void Spray::draw(float elapsed) {
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;
@@ -379,14 +384,14 @@ void Spray::draw(float elapsed) {
float radius = particlesystem_radius * f;
color.a = f * particlesystem_script->alpha();
gl::color(color);
-
- glTexCoord2f(0,1);
+
+ glTexCoord2f(0, 1);
gl::vertex(particle->location() + quad[0] * radius);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(particle->location() + quad[1] * radius);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(particle->location() + quad[2] * radius);
- glTexCoord2f(1,1);
+ glTexCoord2f(1, 1);
gl::vertex(particle->location() + quad[3] * radius);
Stats::quads++;
}
@@ -399,22 +404,24 @@ void Spray::draw(float elapsed) {
/* ---- class Trail ------------------------------------------------ */
Trail::Trail(ParticleScript *script, core::Entity *entity, model::Particles *modelclass) :
- ParticleSystem(script, entity, modelclass) {
+ ParticleSystem(script, entity, modelclass)
+{
}
Trail::~Trail()
{}
-void Trail::draw(float elapsed) {
+void Trail::draw(float elapsed)
+{
if (!particlesystem_script)
return;
- ParticleSystem::draw(elapsed);
+ ParticleSystem::draw(elapsed);
if (particlesystem_stream.size()) {
Textures::bind(particlesystem_texture);
-
+
gl::begin(gl::Quads);
Stream::iterator first = particlesystem_stream.begin();
@@ -434,18 +441,18 @@ void Trail::draw(float elapsed) {
if (tp > 0) {
color.a = 0.0f;
gl::color(color);
-
- glTexCoord2f(1,0);
+
+ glTexCoord2f(1, 0);
gl::vertex(ejector_location);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(ejector_location);
-
+
color.a = fp;
gl::color(color);
-
- glTexCoord2f(0,1);
+
+ glTexCoord2f(0, 1);
gl::vertex((*first)->location() + (*first)->axis().left() * particlesystem_radius * fp);
- glTexCoord2f(1,1);
+ glTexCoord2f(1, 1);
gl::vertex((*first)->location() - (*first)->axis().left() * particlesystem_radius * fp);
Stats::quads++;
}
@@ -468,17 +475,17 @@ void Trail::draw(float elapsed) {
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex((*first)->location() - (*first)->axis().left() * particlesystem_radius * fp);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex((*first)->location() + (*first)->axis().left() * particlesystem_radius * fp);
color.a = f * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,1);
+ glTexCoord2f(0, 1);
gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_radius * f);
- glTexCoord2f(1,1);
+ glTexCoord2f(1, 1);
gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_radius * f);
Stats::quads++;
@@ -496,21 +503,23 @@ void Trail::draw(float elapsed) {
/* ---- class Flame ------------------------------------------------ */
Flame::Flame(ParticleScript *script, core::Entity *entity, model::Particles *modelclass) :
- ParticleSystem(script, entity, modelclass) {
+ ParticleSystem(script, entity, modelclass)
+{
}
Flame::~Flame()
{}
-void Flame::draw(float elapsed) {
+void Flame::draw(float elapsed)
+{
if (!particlesystem_script)
return;
- ParticleSystem::draw(elapsed);
+ ParticleSystem::draw(elapsed);
if (particlesystem_stream.size() > 1) {
-
+
Textures::bind(particlesystem_texture);
gl::begin(gl::Quads);
@@ -532,61 +541,61 @@ void Flame::draw(float elapsed) {
if (tp > 0) {
color.a = 0;
gl::color(color);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(ejector_location);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(ejector_location);
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_radius * fp);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*next)->location() + (*next)->axis().up() * particlesystem_radius * fp);
Stats::quads++;
color.a = 0;
gl::color(color);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(ejector_location);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(ejector_location);
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*next)->location() + (*next)->axis().up() * particlesystem_radius * fp);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_radius * fp);
Stats::quads++;
color.a = 0;
gl::color(color);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(ejector_location);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(ejector_location);
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_radius * fp);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*next)->location() - (*next)->axis().up() * particlesystem_radius * fp);
Stats::quads++;
color.a = 0;
gl::color(color);
- glTexCoord2f(1,0);
+ glTexCoord2f(1, 0);
gl::vertex(ejector_location);
- glTexCoord2f(0,0);
+ glTexCoord2f(0, 0);
gl::vertex(ejector_location);
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*next)->location() - (*next)->axis().up() * particlesystem_radius * fp);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_radius * fp);
Stats::quads++;
}
@@ -607,61 +616,61 @@ void Flame::draw(float elapsed) {
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*first)->location() + (*first)->axis().up() * particlesystem_radius * fp);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*first)->location() + (*first)->axis().left() * particlesystem_radius * fp);
color.a = f * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,t);
+ glTexCoord2f(0, t);
gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_radius * f);
- glTexCoord2f(1,t);
+ glTexCoord2f(1, t);
gl::vertex((*next)->location() + (*next)->axis().up() * particlesystem_radius * f);
Stats::quads++;
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*first)->location() - (*first)->axis().left() * particlesystem_radius * fp);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*first)->location() + (*first)->axis().up() * particlesystem_radius * fp);
color.a = f * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,t);
+ glTexCoord2f(0, t);
gl::vertex((*next)->location() + (*next)->axis().up() * particlesystem_radius * f);
- glTexCoord2f(1,t);
+ glTexCoord2f(1, t);
gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_radius * f);
Stats::quads++;
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*first)->location() - (*first)->axis().up() * particlesystem_radius * fp);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*first)->location() + (*first)->axis().left() * particlesystem_radius * fp);
color.a = f * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,t);
+ glTexCoord2f(0, t);
gl::vertex((*next)->location() + (*next)->axis().left() * particlesystem_radius * f);
- glTexCoord2f(1,t);
+ glTexCoord2f(1, t);
gl::vertex((*next)->location() - (*next)->axis().up() * particlesystem_radius * f);
Stats::quads++;
color.a = fp * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(1,tp);
+ glTexCoord2f(1, tp);
gl::vertex((*first)->location() - (*first)->axis().left() * particlesystem_radius * fp);
- glTexCoord2f(0,tp);
+ glTexCoord2f(0, tp);
gl::vertex((*first)->location() - (*first)->axis().up() * particlesystem_radius * fp);
color.a = f * particlesystem_script->alpha();
gl::color(color);
- glTexCoord2f(0,t);
+ glTexCoord2f(0, t);
gl::vertex((*next)->location() - (*next)->axis().up() * particlesystem_radius * f);
- glTexCoord2f(1,t);
+ glTexCoord2f(1, t);
gl::vertex((*next)->location() - (*next)->axis().left() * particlesystem_radius * f);
Stats::quads++;