2 * Copyright 2012-2013 Tri-Edge AI <triedgeai@gmail.com>
3 * Copyright 2014 Haiku, Inc. All rights reserved.
5 * Distributed under the terms of the MIT license.
9 * John Scipione, jscipione@gmail.com
18 #define frand() ((float)rand() / (float)RAND_MAX)
21 BObjectList
<Particle
>* Particle::list
;
25 Particle::Initialize(int32 size
, int32 shade
)
27 list
= new BObjectList
<Particle
>(2048);
29 for (int32 i
= 0; i
< size
; i
++) {
30 Particle
* p
= new Particle();
31 Particle::_FillParticle(p
, size
, shade
);
38 Particle::AddParticles(int32 size
, int32 shade
)
40 for (int32 i
= list
->CountItems(); i
< size
; i
++) {
41 Particle
* p
= new Particle();
42 Particle::_FillParticle(p
, size
, shade
);
49 Particle::RemoveParticles(int32 size
, int32 shade
)
51 while (list
->CountItems() > size
)
52 delete list
->RemoveItemAt(list
->CountItems() - 1);
57 Particle::ColorParticles(int32 size
, int32 shade
)
59 for (int32 i
= 0; i
< size
; i
++) {
60 Particle
* p
= list
->ItemAt(i
);
61 Particle::_ColorParticle(p
, size
, shade
);
77 for (int32 i
= 0; i
< list
->CountItems(); i
++) {
78 Particle
* p
= list
->ItemAt(i
);
103 Particle::_Render() const
106 glTranslatef(x
, y
, z
);
107 glRotatef(r
, 0.0f
, 0.0f
, 1.0f
);
108 glColor3f(red
, green
, blue
);
110 glVertex3f(-0.25f
, 0.25f
, 0.0f
);
111 glVertex3f(-0.25f
, -0.25f
, 0.0f
);
112 glVertex3f( 0.25f
, -0.25f
, 0.0f
);
113 glVertex3f( 0.25f
, 0.25f
, 0.0f
);
120 Particle::_FillParticle(Particle
* p
, int32 size
, int32 shade
)
122 p
->x
= frand() * 30.0f
- 15.0f
;
123 p
->y
= frand() * 30.0f
- 15.0f
;
124 p
->z
= frand() * 5.0f
;
125 p
->r
= frand() * 360.0f
;
127 p
->vx
= frand() - 0.5f
;
128 p
->vy
= frand() - 0.5f
;
129 p
->vz
= frand() - 0.5f
;
130 p
->vr
= (frand() - 0.5f
) * 180.0f
;
132 Particle::_ColorParticle(p
, size
, shade
);
137 Particle::_ColorParticle(Particle
* p
, int32 size
, int32 shade
)
142 p
->red
= 0.1f
+ frand() * 0.2f
;
144 p
->blue
= frand() * 0.05f
;
150 p
->green
= 0.1f
+ frand() * 0.2f
;
151 p
->blue
= frand() * 0.05f
;
158 p
->green
= frand() * 0.05f
;
159 p
->blue
= 0.1f
+ frand() * 0.2f
;
164 p
->red
= 0.1f
+ frand() * 0.1f
;
165 p
->green
= 0.05f
+ frand() * 0.1f
;
171 p
->red
= 0.1f
+ frand() * 0.2f
;
173 p
->blue
= 0.1f
+ frand() * 0.2f
;
178 p
->red
= p
->green
= p
->blue
= 0.1f
+ frand() * 0.2f
;
183 p
->red
= 0.1f
+ frand() * 0.2f
;
184 p
->green
= 0.1f
+ frand() * 0.2f
;
185 p
->blue
= 0.1f
+ frand() * 0.2f
;