summaryrefslogtreecommitdiff
path: root/sparks.cpp
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2010-08-18 14:38:34 +0000
committerIan C <ianc@noddybox.co.uk>2010-08-18 14:38:34 +0000
commit19bbd5822593c7198dd54eb0f5d38fa1ed8d8fb7 (patch)
tree97f7f8849c3a8282ba571a64ff2a655cdf5d41aa /sparks.cpp
parent0d2f672482fee91a9642a7cb6eb01fcdded79159 (diff)
Reformatted code and altered the attraction rule to something a bit more
correct. Also added two tests to prove it works.
Diffstat (limited to 'sparks.cpp')
-rw-r--r--sparks.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/sparks.cpp b/sparks.cpp
index 6a1484b..096e12a 100644
--- a/sparks.cpp
+++ b/sparks.cpp
@@ -27,7 +27,7 @@ static const char id[]="$Id$";
#include "sparks.h"
Sparks::Sparks(int num, GLfloat alpha_dec, GLfloat alpha_min,
- int len, GLfloat delta)
+ int len, GLfloat delta)
{
m_num=max(num,1);
m_alpha_dec=alpha_dec;
@@ -53,7 +53,7 @@ void Sparks::add(GLfloat ox, GLfloat oy, GLfloat oz)
p.life=m_life;
for(f=0;f<m_num;f++)
- {
+ {
p.dx=DRand()*m_delta*2-m_delta;
p.dy=DRand()*m_delta*2-m_delta;
p.dz=DRand()*m_delta*2-m_delta;
@@ -65,7 +65,7 @@ void Sparks::add(GLfloat ox, GLfloat oy, GLfloat oz)
p.alpha=1.0f;
m_list.push_back(p);
- }
+ }
}
@@ -76,17 +76,17 @@ void Sparks::update()
// Delete dead sparks
//
i=m_list.begin();
-
+
while ((i!=m_list.end())&&(i->alpha<=m_alpha_min))
- {
+ {
m_list.pop_front();
i=m_list.begin();
- }
+ }
// Update them
//
for(i=m_list.begin();i!=m_list.end();i++)
- {
+ {
i->x1+=i->dx;
i->y1+=i->dy;
i->z1+=i->dz;
@@ -96,7 +96,7 @@ void Sparks::update()
i->z2+=i->dz;
i->alpha-=m_alpha_dec;
- }
+ }
}
@@ -109,12 +109,12 @@ void Sparks::draw()
glBegin(GL_LINES);
for(i=m_list.begin();i!=m_list.end();i++)
- {
+ {
glColor4f(1.0,1.0,0.0,i->alpha);
glVertex3f(i->x1,i->y1,i->z1);
glColor4f(0.5,0.0,0.0,i->alpha);
glVertex3f(i->x2,i->y2,i->z2);
- }
+ }
glEnd();
}