2 * This program is under the GNU GPL.
3 * Use at your own risk.
5 * written by David Bucciarelli (humanware@plus.it)
11 #include "particles.h"
13 #define vinit(a,i,j,k) {\
19 #define vadds(a,dt,b) {\
31 #define vinter(a,dt,b,c) {\
32 (a)[0]=(dt)*(b)[0]+(1.0-dt)*(c)[0];\
33 (a)[1]=(dt)*(b)[1]+(1.0-dt)*(c)[1];\
34 (a)[2]=(dt)*(b)[2]+(1.0-dt)*(c)[2];\
37 #define clamp(a) ((a) < 0.0 ? 0.0 : ((a) < 1.0 ? (a) : 1.0))
40 (v)[0]=clamp((v)[0]);\
41 (v)[1]=clamp((v)[1]);\
42 (v)[2]=clamp((v)[2]);\
46 float rainParticle::min
[3];
47 float rainParticle::max
[3];
48 float rainParticle::partLength
=0.2f
;
51 static float vrnd(void)
53 return(((float)rand())/RAND_MAX
);
61 vinit(acc
,0.0f
,0.0f
,0.0f
);
62 vinit(vel
,0.0f
,0.0f
,0.0f
);
63 vinit(pos
,0.0f
,0.0f
,0.0f
);
66 void particle::elapsedTime(float dt
)
75 /////////////////////////////////////////
77 /////////////////////////////////////////
79 particleSystem::particleSystem()
88 particleSystem::~particleSystem()
94 void particleSystem::addParticle(particle
*p
)
97 part
=(particle
**)calloc(1,sizeof(particle
*));
102 part
=(particle
**)realloc(part
,sizeof(particle
*)*particleNum
);
103 part
[particleNum
-1]=p
;
107 void particleSystem::reset(void)
119 void particleSystem::draw(void)
124 part
[0]->beginDraw();
125 for(unsigned int i
=0;i
<particleNum
;i
++)
130 void particleSystem::addTime(float dt
)
135 for(unsigned int i
=0;i
<particleNum
;i
++) {
136 part
[i
]->elapsedTime(dt
);
141 /////////////////////////////////////////
143 /////////////////////////////////////////
145 void rainParticle::init(void)
157 oldpos
[0]=pos
[0]=min
[0]+(max
[0]-min
[0])*vrnd();
158 oldpos
[1]=pos
[1]=max
[1]+0.2f
*max
[1]*vrnd();
159 oldpos
[2]=pos
[2]=min
[2]+(max
[2]-min
[2])*vrnd();
161 vadds(oldpos
,-partLength
,vel
);
164 rainParticle::rainParticle()
169 void rainParticle::setRainingArea(float minx
, float miny
, float minz
,
170 float maxx
, float maxy
, float maxz
)
172 vinit(min
,minx
,miny
,minz
);
173 vinit(max
,maxx
,maxy
,maxz
);
176 void rainParticle::setLength(float l
)
181 void rainParticle::draw(void)
183 glColor4f(0.7f
,0.95f
,1.0f
,0.0f
);
186 glColor4f(0.3f
,0.7f
,1.0f
,1.0f
);
190 void rainParticle::checkAge(void)
196 void rainParticle::elapsedTime(float dt
)
198 particle::elapsedTime(dt
);
201 pos
[0]=max
[0]-(min
[0]-pos
[0]);
203 pos
[2]=max
[2]-(min
[2]-pos
[2]);
206 pos
[0]=min
[0]+(pos
[0]-max
[0]);
208 pos
[2]=min
[2]+(pos
[2]-max
[2]);
211 vadds(oldpos
,-partLength
,vel
);
214 void rainParticle::randomHeight(void)
216 pos
[1]=(max
[1]-min
[1])*vrnd()+min
[1];
218 oldpos
[1]=pos
[1]-partLength
*vel
[1];