diff options
author | Vito Caputo <vcaputo@gnugeneration.com> | 2016-12-13 07:51:23 -0800 |
---|---|---|
committer | Vito Caputo <vcaputo@gnugeneration.com> | 2016-12-13 07:51:23 -0800 |
commit | 8add1663d9a02db2bc65224cdceb480733a81379 (patch) | |
tree | fea6aa880a366c007d2b7fdda87c746e6345b301 /modules/sparkler/sparkler.c | |
parent | af49b97cd819cec3a19b1ff5ed6076a0d23f4233 (diff) |
sparkler: introduce a particle system
A while ago I made this particle system on SDL, and had the beginnings of
an octree implemented within it, but never finished actually using the
octree to accelerate the proximity searches.
This now has the octree completed and of course more particle interactions now
that neighbors could be found more quickly.
The simulation somewhat resembles a fireworks display. Every particle is drawn
as a single pixel. The visual effect is dominated by spontaneously spawned
rockets which explode into thousands of particles accompanied by bursts that
thrust particles away from the explosion radially in an expanding sphere
resembling a shock wave. When the shock wave happens to strike another rocket,
it explodes, resulting in another shock wave. This can produce spectacular
chain reactions, so it's worth running for some time and seeing what transpires.
Diffstat (limited to 'modules/sparkler/sparkler.c')
-rw-r--r-- | modules/sparkler/sparkler.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/modules/sparkler/sparkler.c b/modules/sparkler/sparkler.c new file mode 100644 index 0000000..de2123e --- /dev/null +++ b/modules/sparkler/sparkler.c @@ -0,0 +1,53 @@ +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <time.h> +#include <unistd.h> + +#include "fb.h" +#include "rototiller.h" +#include "util.h" + +#include "particles.h" + +/* particle system gadget (C) Vito Caputo <vcaputo@pengaru.com> 2/15/2014 */ +/* 1/10/2015 added octree bsp (though not yet leveraged) */ +/* 11/25/2016 refactor and begun adapting to rototiller */ + +#define INIT_PARTS 100 + +extern particle_ops_t simple_ops; + + +/* Render a 3D particle system */ +static void sparkler(fb_fragment_t *fragment) +{ + static particles_t *particles; + static int initialized; + uint32_t *buf = fragment->buf; + + if (!initialized) { + srand(time(NULL) + getpid()); + + particles = particles_new(); + particles_add_particles(particles, NULL, &simple_ops, INIT_PARTS); + + initialized = 1; + } + + particles_age(particles); + memset(buf, 0, ((fragment->width << 2) + fragment->stride) * fragment->height); + + particles_draw(particles, fragment); + particles_sim(particles); + particles_add_particles(particles, NULL, &simple_ops, INIT_PARTS / 4); +} + + +rototiller_renderer_t sparkler_renderer = { + .render = sparkler, + .name = "sparkler", + .description = "Particle system with spatial interactions", + .author = "Vito Caputo <vcaputo@pengaru.com>", + .license = "GPLv2", +}; |