nicer random distribution in PS emitter

makes "explosions" in fireworks and impact FX circular instead of square, looking much better.
This commit is contained in:
Damian Schneider
2025-12-16 08:26:37 +01:00
parent b452370be7
commit 7f4e0f74ba

View File

@@ -185,8 +185,16 @@ int32_t ParticleSystem2D::sprayEmit(const PSsource &emitter) {
emitIndex = 0;
if (particles[emitIndex].ttl == 0) { // find a dead particle
success = true;
particles[emitIndex].vx = emitter.vx + hw_random16(emitter.var << 1) - emitter.var; // random(-var, var)
particles[emitIndex].vy = emitter.vy + hw_random16(emitter.var << 1) - emitter.var; // random(-var, var)
int32_t dx = hw_random16(emitter.var << 1) - emitter.var;
int32_t dy = hw_random16(emitter.var << 1) - emitter.var;
if (emitter.var > 5) { // use circular random distribution for large variance to generate nicer "explosions"
while (dx*dx + dy*dy > emitter.var*emitter.var) { // reject points outside circle
dx = hw_random16(emitter.var << 1) - emitter.var;
dy = hw_random16(emitter.var << 1) - emitter.var;
}
}
particles[emitIndex].vx = emitter.vx + dx;
particles[emitIndex].vy = emitter.vy + dy;
particles[emitIndex].x = emitter.source.x;
particles[emitIndex].y = emitter.source.y;
particles[emitIndex].hue = emitter.source.hue;