Mercurial > love-experiments
annotate src/modules/graphics/opengl/ParticleSystem.cpp @ 1353:c3c9d6ed3e21 particlesystem-quads
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
| author | Alex Szpakowski <slime73@gmail.com> |
|---|---|
| date | Mon, 11 Mar 2013 01:44:43 -0300 |
| parents | 470a47bebfb3 |
| children | b88c88225336 f1c353a5067d |
| rev | line source |
|---|---|
| 1096 | 1 /** |
|
1282
b7f097053d74
Updated copyright text for the new year
Alex Szpakowski <slime73@gmail.com>
parents:
1230
diff
changeset
|
2 * Copyright (c) 2006-2013 LOVE Development Team |
| 1096 | 3 * |
| 4 * This software is provided 'as-is', without any express or implied | |
| 5 * warranty. In no event will the authors be held liable for any damages | |
| 6 * arising from the use of this software. | |
| 7 * | |
| 8 * Permission is granted to anyone to use this software for any purpose, | |
| 9 * including commercial applications, and to alter it and redistribute it | |
| 10 * freely, subject to the following restrictions: | |
| 11 * | |
| 12 * 1. The origin of this software must not be misrepresented; you must not | |
| 13 * claim that you wrote the original software. If you use this software | |
| 14 * in a product, an acknowledgment in the product documentation would be | |
| 15 * appreciated but is not required. | |
| 16 * 2. Altered source versions must be plainly marked as such, and must not be | |
| 17 * misrepresented as being the original software. | |
| 18 * 3. This notice may not be removed or altered from any source distribution. | |
| 19 **/ | |
| 20 | |
| 21 #include "ParticleSystem.h" | |
| 22 | |
| 23 #include "common/math.h" | |
| 24 | |
|
1216
8ae3ebeeda85
opengl graphics module files now always include OpenGL.h rather than GLee.h
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
25 #include "OpenGL.h" |
| 1096 | 26 #include <cmath> |
| 27 #include <cstdlib> | |
| 28 | |
| 29 namespace love | |
| 30 { | |
| 31 namespace graphics | |
| 32 { | |
| 33 namespace opengl | |
| 34 { | |
| 35 | |
| 36 namespace | |
| 37 { | |
| 38 Colorf colorToFloat(const Color &c) | |
| 39 { | |
| 40 return Colorf((GLfloat)c.r/255.0f, (GLfloat)c.g/255.0f, (GLfloat)c.b/255.0f, (GLfloat)c.a/255.0f); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 float calculate_variation(float inner, float outer, float var) | |
| 45 { | |
| 46 float low = inner - (outer/2.0f)*var; | |
| 47 float high = inner + (outer/2.0f)*var; | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
48 float r = random(); |
| 1096 | 49 return low*(1-r)+high*r; |
| 50 } | |
| 51 | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
52 StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_MAX_ENUM>::Entry ParticleSystem::distributionsEntries[] = { |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
53 { "none", ParticleSystem::DISTRIBUTION_NONE }, |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
54 { "uniform", ParticleSystem::DISTRIBUTION_UNIFORM }, |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
55 { "normal", ParticleSystem::DISTRIBUTION_NORMAL }, |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
56 }; |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
57 |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
58 StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_MAX_ENUM> ParticleSystem::distributions(ParticleSystem::distributionsEntries, sizeof(ParticleSystem::distributionsEntries)); |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
59 |
| 1096 | 60 |
| 61 ParticleSystem::ParticleSystem(Image *sprite, unsigned int buffer) | |
| 62 : pStart(0) | |
| 63 , pLast(0) | |
| 64 , pEnd(0) | |
| 1147 | 65 , particleVerts(0) |
|
1307
1c61424c6024
Cleaned up exception handling code when creating new fonts, spritebatches, and shaders
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
66 , sprite(sprite) |
| 1096 | 67 , active(true) |
| 68 , emissionRate(0) | |
| 69 , emitCounter(0) | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
70 , areaSpreadDistribution(DISTRIBUTION_NONE) |
| 1096 | 71 , lifetime(-1) |
| 72 , life(0) | |
| 73 , particleLifeMin(0) | |
| 74 , particleLifeMax(0) | |
| 75 , direction(0) | |
| 76 , spread(0) | |
| 77 , relative(false) | |
| 78 , speedMin(0) | |
| 79 , speedMax(0) | |
| 80 , gravityMin(0) | |
| 81 , gravityMax(0) | |
| 82 , radialAccelerationMin(0) | |
| 83 , radialAccelerationMax(0) | |
| 84 , tangentialAccelerationMin(0) | |
| 85 , tangentialAccelerationMax(0) | |
| 86 , sizeVariation(0) | |
| 87 , rotationMin(0) | |
| 88 , rotationMax(0) | |
| 89 , spinStart(0) | |
| 90 , spinEnd(0) | |
| 91 , spinVariation(0) | |
| 92 , offsetX(sprite->getWidth()*0.5f) | |
| 93 , offsetY(sprite->getHeight()*0.5f) | |
| 94 { | |
| 95 sizes.push_back(1.0f); | |
| 96 colors.push_back(Colorf(1.0f, 1.0f, 1.0f, 1.0f)); | |
| 97 setBufferSize(buffer); | |
|
1307
1c61424c6024
Cleaned up exception handling code when creating new fonts, spritebatches, and shaders
Alex Szpakowski <slime73@gmail.com>
parents:
1282
diff
changeset
|
98 sprite->retain(); |
| 1096 | 99 } |
| 100 | |
| 101 ParticleSystem::~ParticleSystem() | |
| 102 { | |
|
1353
c3c9d6ed3e21
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
Alex Szpakowski <slime73@gmail.com>
parents:
1352
diff
changeset
|
103 for (size_t i = 0; i < quads.size(); i++) |
|
c3c9d6ed3e21
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
Alex Szpakowski <slime73@gmail.com>
parents:
1352
diff
changeset
|
104 quads[i]->release(); |
|
c3c9d6ed3e21
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
Alex Szpakowski <slime73@gmail.com>
parents:
1352
diff
changeset
|
105 |
| 1096 | 106 if (this->sprite != 0) |
| 107 this->sprite->release(); | |
| 108 | |
| 109 if (pStart != 0) | |
| 110 delete [] pStart; | |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
111 |
| 1147 | 112 if (particleVerts != 0) |
| 113 delete [] particleVerts; | |
| 1096 | 114 } |
| 115 | |
| 116 void ParticleSystem::add() | |
| 117 { | |
| 118 if (isFull()) return; | |
| 119 | |
| 120 float min,max; | |
| 121 | |
| 122 min = particleLifeMin; | |
| 123 max = particleLifeMax; | |
| 124 if (min == max) | |
| 125 pLast->life = min; | |
| 126 else | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
127 pLast->life = random(min, max); |
| 1096 | 128 pLast->lifetime = pLast->life; |
| 129 | |
| 130 pLast->position[0] = position.getX(); | |
| 131 pLast->position[1] = position.getY(); | |
| 132 | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
133 switch (areaSpreadDistribution) |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
134 { |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
135 case DISTRIBUTION_UNIFORM: |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
136 pLast->position[0] += random(-areaSpread.getX(), areaSpread.getX()); |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
137 pLast->position[1] += random(-areaSpread.getY(), areaSpread.getY()); |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
138 break; |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
139 case DISTRIBUTION_NORMAL: |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
140 pLast->position[0] += random_normal(areaSpread.getX()); |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
141 pLast->position[1] += random_normal(areaSpread.getY()); |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
142 break; |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
143 case DISTRIBUTION_NONE: |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
144 default: |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
145 break; |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
146 } |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
147 |
| 1096 | 148 min = direction - spread/2.0f; |
| 149 max = direction + spread/2.0f; | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
150 pLast->direction = random(min, max); |
| 1096 | 151 |
| 152 pLast->origin = position; | |
| 153 | |
| 154 min = speedMin; | |
| 155 max = speedMax; | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
156 float speed = random(min, max); |
| 1096 | 157 pLast->speed = love::Vector(cos(pLast->direction), sin(pLast->direction)); |
| 158 pLast->speed *= speed; | |
| 159 | |
| 160 min = gravityMin; | |
| 161 max = gravityMax; | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
162 pLast->gravity = random(min, max); |
| 1096 | 163 |
| 164 min = radialAccelerationMin; | |
| 165 max = radialAccelerationMax; | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
166 pLast->radialAcceleration = random(min, max); |
| 1096 | 167 |
| 168 min = tangentialAccelerationMin; | |
| 169 max = tangentialAccelerationMax; | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
170 pLast->tangentialAcceleration = random(min, max); |
| 1096 | 171 |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
172 pLast->sizeOffset = random(sizeVariation); // time offset for size change |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
173 pLast->sizeIntervalSize = (1.0f - random(sizeVariation)) - pLast->sizeOffset; |
| 1096 | 174 pLast->size = sizes[(size_t)(pLast->sizeOffset - .5f) * (sizes.size() - 1)]; |
| 175 | |
| 176 min = rotationMin; | |
| 177 max = rotationMax; | |
| 178 pLast->spinStart = calculate_variation(spinStart, spinEnd, spinVariation); | |
| 179 pLast->spinEnd = calculate_variation(spinEnd, spinStart, spinVariation); | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
180 pLast->rotation = random(min, max); |
| 1096 | 181 |
| 182 pLast->color = colors[0]; | |
| 183 | |
| 184 pLast++; | |
| 185 } | |
| 186 | |
| 187 void ParticleSystem::remove(particle *p) | |
| 188 { | |
| 189 if (!isEmpty()) | |
| 190 { | |
| 191 *p = *(--pLast); | |
| 192 } | |
| 193 } | |
| 194 | |
| 195 void ParticleSystem::setSprite(Image *image) | |
| 196 { | |
| 197 if (sprite != 0) | |
| 198 sprite->release(); | |
| 199 | |
| 200 sprite = image; | |
| 201 sprite->retain(); | |
| 202 } | |
| 203 | |
| 204 void ParticleSystem::setBufferSize(unsigned int size) | |
| 205 { | |
| 206 // delete previous data | |
| 1147 | 207 if (pStart != 0) |
| 208 delete [] pStart; | |
| 1096 | 209 |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
210 pLast = pStart = new particle[size](); |
| 1096 | 211 |
| 212 pEnd = pStart + size; | |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
213 |
| 1147 | 214 if (particleVerts != 0) |
| 215 delete [] particleVerts; | |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
216 |
| 1147 | 217 // each particle has 4 vertices |
| 218 particleVerts = new vertex[size*4]; | |
| 1096 | 219 } |
| 220 | |
| 221 void ParticleSystem::setEmissionRate(int rate) | |
| 222 { | |
| 223 emissionRate = rate; | |
| 224 } | |
| 225 | |
| 226 void ParticleSystem::setLifetime(float life) | |
| 227 { | |
| 228 this->life = lifetime = life; | |
| 229 } | |
| 230 | |
| 231 void ParticleSystem::setParticleLife(float min, float max) | |
| 232 { | |
| 233 particleLifeMin = min; | |
| 234 if (max == 0) | |
| 235 particleLifeMax = min; | |
| 236 else | |
| 237 particleLifeMax = max; | |
| 238 } | |
| 239 | |
| 240 void ParticleSystem::setPosition(float x, float y) | |
| 241 { | |
| 242 position = love::Vector(x, y); | |
| 243 } | |
| 244 | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
245 |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
246 void ParticleSystem::setAreaSpread(AreaSpreadDistribution distribution, float x, float y) |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
247 { |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
248 areaSpread = love::Vector(x, y); |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
249 areaSpreadDistribution = distribution; |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
250 } |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
251 |
| 1096 | 252 void ParticleSystem::setDirection(float direction) |
| 253 { | |
| 254 this->direction = direction; | |
| 255 } | |
| 256 | |
| 257 void ParticleSystem::setSpread(float spread) | |
| 258 { | |
| 259 this->spread = spread; | |
| 260 } | |
| 261 | |
| 262 void ParticleSystem::setRelativeDirection(bool relative) | |
| 263 { | |
| 264 this->relative = relative; | |
| 265 } | |
| 266 | |
| 267 void ParticleSystem::setSpeed(float speed) | |
| 268 { | |
| 269 speedMin = speedMax = speed; | |
| 270 } | |
| 271 | |
| 272 void ParticleSystem::setSpeed(float min, float max) | |
| 273 { | |
| 274 speedMin = min; | |
| 275 speedMax = max; | |
| 276 } | |
| 277 | |
| 278 void ParticleSystem::setGravity(float gravity) | |
| 279 { | |
| 280 gravityMin = gravityMax = gravity; | |
| 281 } | |
| 282 | |
| 283 void ParticleSystem::setGravity(float min, float max) | |
| 284 { | |
| 285 gravityMin = min; | |
| 286 gravityMax = max; | |
| 287 } | |
| 288 | |
| 289 void ParticleSystem::setRadialAcceleration(float acceleration) | |
| 290 { | |
| 291 radialAccelerationMin = radialAccelerationMax = acceleration; | |
| 292 } | |
| 293 | |
| 294 void ParticleSystem::setRadialAcceleration(float min, float max) | |
| 295 { | |
| 296 radialAccelerationMin = min; | |
| 297 radialAccelerationMax = max; | |
| 298 } | |
| 299 | |
| 300 void ParticleSystem::setTangentialAcceleration(float acceleration) | |
| 301 { | |
| 302 tangentialAccelerationMin = tangentialAccelerationMax = acceleration; | |
| 303 } | |
| 304 | |
| 305 void ParticleSystem::setTangentialAcceleration(float min, float max) | |
| 306 { | |
| 307 tangentialAccelerationMin = min; | |
| 308 tangentialAccelerationMax = max; | |
| 309 } | |
| 310 | |
| 311 void ParticleSystem::setSize(float size) | |
| 312 { | |
| 313 sizes.resize(1); | |
| 314 sizes[0] = size; | |
| 315 } | |
| 316 | |
| 317 void ParticleSystem::setSize(const std::vector<float> &newSizes, float variation) | |
| 318 { | |
| 319 sizes = newSizes; | |
| 320 sizeVariation = variation; | |
| 321 } | |
| 322 | |
| 323 void ParticleSystem::setSizeVariation(float variation) | |
| 324 { | |
| 325 sizeVariation = variation; | |
| 326 } | |
| 327 | |
| 328 void ParticleSystem::setRotation(float rotation) | |
| 329 { | |
| 330 rotationMin = rotationMax = rotation; | |
| 331 } | |
| 332 | |
| 333 void ParticleSystem::setRotation(float min, float max) | |
| 334 { | |
| 335 rotationMin = min; | |
| 336 rotationMax = max; | |
| 337 } | |
| 338 | |
| 339 void ParticleSystem::setSpin(float spin) | |
| 340 { | |
| 341 spinStart = spin; | |
| 342 spinEnd = spin; | |
| 343 } | |
| 344 | |
| 345 void ParticleSystem::setSpin(float start, float end) | |
| 346 { | |
| 347 spinStart = start; | |
| 348 spinEnd = end; | |
| 349 } | |
| 350 | |
| 351 void ParticleSystem::setSpin(float start, float end, float variation) | |
| 352 { | |
| 353 spinStart = start; | |
| 354 spinEnd = end; | |
| 355 spinVariation = variation; | |
| 356 } | |
| 357 | |
| 358 void ParticleSystem::setSpinVariation(float variation) | |
| 359 { | |
| 360 spinVariation = variation; | |
| 361 } | |
| 362 | |
| 363 void ParticleSystem::setColor(const Color &color) | |
| 364 { | |
| 365 colors.resize(1); | |
| 366 colors[0] = colorToFloat(color); | |
| 367 } | |
| 368 | |
| 369 void ParticleSystem::setColor(const std::vector<Color> &newColors) | |
| 370 { | |
| 371 colors.resize(newColors.size()); | |
| 372 for (size_t i = 0; i < newColors.size(); ++i) | |
| 373 colors[i] = colorToFloat(newColors[i]); | |
| 374 } | |
| 375 | |
|
1353
c3c9d6ed3e21
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
Alex Szpakowski <slime73@gmail.com>
parents:
1352
diff
changeset
|
376 void ParticleSystem::setQuads(const std::vector<love::graphics::Quad *> &newQuads) |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
377 { |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
378 for (size_t i = 0; i < quads.size(); i++) |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
379 quads[i]->release(); |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
380 |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
381 quads.resize(newQuads.size()); |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
382 |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
383 for (size_t i = 0; i < newQuads.size(); i++) |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
384 { |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
385 quads[i] = newQuads[i]; |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
386 quads[i]->retain(); |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
387 } |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
388 } |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
389 |
|
1353
c3c9d6ed3e21
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
Alex Szpakowski <slime73@gmail.com>
parents:
1352
diff
changeset
|
390 void ParticleSystem::setQuads() |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
391 { |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
392 for (size_t i = 0; i < quads.size(); i++) |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
393 quads[i]->release(); |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
394 |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
395 quads.resize(0); |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
396 } |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
397 |
| 1096 | 398 void ParticleSystem::setOffset(float x, float y) |
| 399 { | |
| 400 offsetX = x; | |
| 401 offsetY = y; | |
| 402 } | |
| 403 | |
| 404 float ParticleSystem::getX() const | |
| 405 { | |
| 406 return position.getX(); | |
| 407 } | |
| 408 | |
| 409 float ParticleSystem::getY() const | |
| 410 { | |
| 411 return position.getY(); | |
| 412 } | |
| 413 | |
| 414 const love::Vector &ParticleSystem::getPosition() const | |
| 415 { | |
| 416 return position; | |
| 417 } | |
| 418 | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
419 ParticleSystem::AreaSpreadDistribution ParticleSystem::getAreaSpreadDistribution() const |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
420 { |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
421 return areaSpreadDistribution; |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
422 } |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
423 |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
424 const love::Vector &ParticleSystem::getAreaSpreadParameters() const |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
425 { |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
426 return areaSpread; |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
427 } |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
428 |
| 1096 | 429 float ParticleSystem::getDirection() const |
| 430 { | |
| 431 return direction; | |
| 432 } | |
| 433 | |
| 434 float ParticleSystem::getSpread() const | |
| 435 { | |
| 436 return spread; | |
| 437 } | |
| 438 | |
| 439 float ParticleSystem::getOffsetX() const | |
| 440 { | |
| 441 return offsetX; | |
| 442 } | |
| 443 | |
| 444 float ParticleSystem::getOffsetY() const | |
| 445 { | |
| 446 return offsetY; | |
| 447 } | |
| 448 | |
| 449 int ParticleSystem::count() const | |
| 450 { | |
| 451 return (int)(pLast - pStart); | |
| 452 } | |
| 453 | |
| 454 void ParticleSystem::start() | |
| 455 { | |
| 456 active = true; | |
| 457 } | |
| 458 | |
| 459 void ParticleSystem::stop() | |
| 460 { | |
| 461 active = false; | |
| 462 life = lifetime; | |
| 463 emitCounter = 0; | |
| 464 } | |
| 465 | |
| 466 void ParticleSystem::pause() | |
| 467 { | |
| 468 active = false; | |
| 469 } | |
| 470 | |
| 471 void ParticleSystem::reset() | |
| 472 { | |
| 473 pLast = pStart; | |
| 474 life = lifetime; | |
| 475 emitCounter = 0; | |
| 476 } | |
| 477 | |
| 478 bool ParticleSystem::isActive() const | |
| 479 { | |
| 480 return active; | |
| 481 } | |
| 482 | |
| 483 bool ParticleSystem::isEmpty() const | |
| 484 { | |
| 485 return pStart == pLast; | |
| 486 } | |
| 487 | |
| 488 bool ParticleSystem::isFull() const | |
| 489 { | |
| 490 return pLast == pEnd; | |
| 491 } | |
| 492 | |
| 493 void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const | |
| 494 { | |
| 495 if (sprite == 0) return; // just in case of failure | |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
496 |
| 1147 | 497 int numParticles = count(); |
| 498 if (numParticles == 0) return; // don't bother if there's nothing to do | |
| 1096 | 499 |
| 500 glPushMatrix(); | |
| 501 glPushAttrib(GL_CURRENT_BIT); | |
| 502 | |
| 1147 | 503 static Matrix t; |
| 1096 | 504 t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky); |
| 505 glMultMatrixf((const GLfloat *)t.getElements()); | |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
506 |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
507 const vertex *imageVerts = sprite->getVertices(); |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
508 const vertex *tVerts; |
|
1353
c3c9d6ed3e21
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
Alex Szpakowski <slime73@gmail.com>
parents:
1352
diff
changeset
|
509 |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
510 size_t numQuads = quads.size(); |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
511 |
| 1147 | 512 // set the vertex data for each particle (transformation, texcoords, color) |
| 513 for (int i = 0; i < numParticles; i++) | |
| 1096 | 514 { |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
515 particle *p = pStart + i; |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
516 |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
517 if (numQuads > 0) |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
518 { |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
519 // Make sure the quad index is valid |
|
1353
c3c9d6ed3e21
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
Alex Szpakowski <slime73@gmail.com>
parents:
1352
diff
changeset
|
520 size_t quadIndex = (p->quadIndex >= numQuads) ? numQuads - 1 : p->quadIndex; |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
521 tVerts = quads[quadIndex]->getVertices(); |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
522 } |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
523 else |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
524 tVerts = imageVerts; |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
525 |
| 1147 | 526 // particle vertices are sprite vertices transformed by particle information |
| 527 t.setTransformation(p->position[0], p->position[1], p->rotation, p->size, p->size, offsetX, offsetY, 0.0f, 0.0f); | |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
528 t.transform(&particleVerts[i*4], &tVerts[0], 4); |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
529 |
| 1147 | 530 // set the texture coordinate and color data for particle vertices |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
531 for (int v = 0; v < 4; v++) |
|
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
532 { |
| 1147 | 533 int vi = (i * 4) + v; // current vertex index for particle |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
534 |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
535 particleVerts[vi].s = tVerts[v].s; |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
536 particleVerts[vi].t = tVerts[v].t; |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
537 |
| 1147 | 538 // particle colors are stored as floats (0-1) but vertex colors are stored as unsigned bytes (0-255) |
| 539 particleVerts[vi].r = p->color.r*255; | |
| 540 particleVerts[vi].g = p->color.g*255; | |
| 541 particleVerts[vi].b = p->color.b*255; | |
| 542 particleVerts[vi].a = p->color.a*255; | |
| 543 } | |
| 1096 | 544 } |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
545 |
| 1147 | 546 sprite->bind(); |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
547 |
| 1147 | 548 glEnableClientState(GL_COLOR_ARRAY); |
| 549 glEnableClientState(GL_VERTEX_ARRAY); | |
| 550 glEnableClientState(GL_TEXTURE_COORD_ARRAY); | |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
551 |
| 1147 | 552 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex), (GLvoid *)&particleVerts[0].r); |
| 553 glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&particleVerts[0].x); | |
| 554 glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid *)&particleVerts[0].s); | |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
555 |
| 1147 | 556 glDrawArrays(GL_QUADS, 0, numParticles*4); |
|
1180
1e9aa846f624
Removed unnecessary tabs in empty lines, fixed texture filtering when the minification and mipmap filter are the same
Alexander Szpakowski <amaranth72@gmail.com>
parents:
1147
diff
changeset
|
557 |
| 1147 | 558 glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
| 559 glDisableClientState(GL_VERTEX_ARRAY); | |
| 560 glDisableClientState(GL_COLOR_ARRAY); | |
| 1096 | 561 |
| 562 glPopAttrib(); | |
| 563 glPopMatrix(); | |
| 564 } | |
| 565 | |
| 566 void ParticleSystem::update(float dt) | |
| 567 { | |
| 568 // Traverse all particles and update. | |
| 569 particle *p = pStart; | |
| 570 | |
| 571 // Make some more particles. | |
| 572 if (active) | |
| 573 { | |
| 574 float rate = 1.0f / emissionRate; // the amount of time between each particle emit | |
| 575 emitCounter += dt; | |
| 576 while (emitCounter > rate) | |
| 577 { | |
| 578 add(); | |
| 579 emitCounter -= rate; | |
| 580 } | |
| 581 /*int particles = (int)(emissionRate * dt); | |
| 582 for (int i = 0; i != particles; i++) | |
| 583 add();*/ | |
| 584 | |
| 585 life -= dt; | |
| 586 if (lifetime != -1 && life < 0) | |
| 587 stop(); | |
| 588 } | |
| 589 | |
| 590 while (p != pLast) | |
| 591 { | |
| 592 // Decrease lifespan. | |
| 593 p->life -= dt; | |
| 594 | |
| 595 if (p->life > 0) | |
| 596 { | |
| 597 | |
| 598 // Temp variables. | |
| 599 love::Vector radial, tangential, gravity(0, p->gravity); | |
| 600 love::Vector ppos(p->position[0], p->position[1]); | |
| 601 | |
| 602 // Get vector from particle center to particle. | |
| 603 radial = ppos - p->origin; | |
| 604 radial.normalize(); | |
| 605 tangential = radial; | |
| 606 | |
| 607 // Resize radial acceleration. | |
| 608 radial *= p->radialAcceleration; | |
| 609 | |
| 610 // Calculate tangential acceleration. | |
| 611 { | |
| 612 float a = tangential.getX(); | |
| 613 tangential.setX(-tangential.getY()); | |
| 614 tangential.setY(a); | |
| 615 } | |
| 616 | |
| 617 // Resize tangential. | |
| 618 tangential *= p->tangentialAcceleration; | |
| 619 | |
| 620 // Update position. | |
| 621 p->speed += (radial+tangential+gravity)*dt; | |
| 622 | |
| 623 // Modify position. | |
| 624 ppos += p->speed * dt; | |
| 625 | |
| 626 p->position[0] = ppos.getX(); | |
| 627 p->position[1] = ppos.getY(); | |
| 628 | |
| 629 const float t = 1.0f - p->life / p->lifetime; | |
| 630 | |
| 631 // Rotate. | |
| 632 p->rotation += (p->spinStart * (1.0f - t) + p->spinEnd * t)*dt; | |
| 633 | |
| 634 // Change size according to given intervals: | |
| 635 // i = 0 1 2 3 n-1 | |
| 636 // |-------|-------|------|--- ... ---| | |
| 637 // t = 0 1/(n-1) 3/(n-1) 1 | |
| 638 // | |
| 639 // `s' is the interpolation variable scaled to the current | |
| 640 // interval width, e.g. if n = 5 and t = 0.3, then the current | |
| 641 // indices are 1,2 and s = 0.3 - 0.25 = 0.05 | |
| 642 float s = p->sizeOffset + t * p->sizeIntervalSize; // size variation | |
| 643 s *= (float)(sizes.size() - 1); // 0 <= s < sizes.size() | |
| 644 size_t i = (size_t)s; | |
| 645 size_t k = (i == sizes.size() - 1) ? i : i + 1; // boundary check (prevents failing on t = 1.0f) | |
| 646 s -= (float)i; // transpose s to be in interval [0:1]: i <= s < i + 1 ~> 0 <= s < 1 | |
| 647 p->size = sizes[i] * (1.0f - s) + sizes[k] * s; | |
| 648 | |
| 649 // Update color according to given intervals (as above) | |
| 650 s = t * (float)(colors.size() - 1); | |
| 651 i = (size_t)s; | |
| 652 k = (i == colors.size() - 1) ? i : i + 1; | |
| 653 s -= (float)i; // 0 <= s <= 1 | |
| 654 p->color = colors[i] * (1.0f - s) + colors[k] * s; | |
| 655 | |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
656 // Update quad index |
|
1353
c3c9d6ed3e21
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
Alex Szpakowski <slime73@gmail.com>
parents:
1352
diff
changeset
|
657 k = quads.size(); |
|
c3c9d6ed3e21
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
Alex Szpakowski <slime73@gmail.com>
parents:
1352
diff
changeset
|
658 if (k > 0) |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
659 { |
|
1353
c3c9d6ed3e21
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
Alex Szpakowski <slime73@gmail.com>
parents:
1352
diff
changeset
|
660 s = t * (float) k; // [0:numquads-1] |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
661 i = (s > 0) ? (size_t) s : 0; |
|
1353
c3c9d6ed3e21
ParticleSystem:setQuads can now accept a table argument, cleaned up the ParticleSystem quad code
Alex Szpakowski <slime73@gmail.com>
parents:
1352
diff
changeset
|
662 p->quadIndex = (i < k) ? i : k - 1; |
|
1352
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
663 } |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
664 else |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
665 p->quadIndex = 0; |
|
470a47bebfb3
Added ParticleSystem:setQuads(q1, q2, ...), quads are chosen based on current particle lifetime in a similar style to ParticleSystem:setColors
Alex Szpakowski <slime73@gmail.com>
parents:
1333
diff
changeset
|
666 |
| 1096 | 667 // Next particle. |
| 668 p++; | |
| 669 } | |
| 670 else | |
| 671 { | |
| 672 remove(p); | |
| 673 | |
| 674 if (p >= pLast) | |
| 675 return; | |
| 676 } // else | |
| 677 } // while | |
| 678 } | |
| 679 | |
|
1127
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
680 bool ParticleSystem::getConstant(const char *in, AreaSpreadDistribution &out) |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
681 { |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
682 return distributions.find(in, out); |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
683 } |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
684 |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
685 bool ParticleSystem::getConstant(AreaSpreadDistribution in, const char *&out) |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
686 { |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
687 return distributions.find(in, out); |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
688 } |
|
13e6ca38c28c
Fix issue #437: Area-based particle spawn.
vrld <vrld@vrld.org>
parents:
1096
diff
changeset
|
689 |
| 1096 | 690 } // opengl |
| 691 } // graphics | |
| 692 } // love |
