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