2022-12-28 16:50:54 -06:00
|
|
|
#ifndef PARTICLE_H
|
|
|
|
#define PARTICLE_H
|
|
|
|
|
2023-11-28 17:17:40 -06:00
|
|
|
#include "HandmadeMath.h"
|
2024-01-04 08:14:37 -06:00
|
|
|
#include "warp.h"
|
2023-12-04 13:38:37 -06:00
|
|
|
#include "transform.h"
|
2023-12-29 19:08:53 -06:00
|
|
|
#include "texture.h"
|
2024-01-01 17:30:42 -06:00
|
|
|
#include "anim.h"
|
2024-01-14 10:24:31 -06:00
|
|
|
#include "gameobject.h"
|
2024-05-06 21:59:22 -05:00
|
|
|
#include "render.h"
|
2022-12-28 16:50:54 -06:00
|
|
|
|
2023-12-29 19:08:53 -06:00
|
|
|
typedef struct particle {
|
2024-01-03 12:29:27 -06:00
|
|
|
HMM_Vec4 pos;
|
|
|
|
HMM_Vec4 v; /* velocity */
|
2023-12-29 19:08:53 -06:00
|
|
|
float angle;
|
|
|
|
float av; /* angular velocity */
|
|
|
|
float scale;
|
2024-01-04 09:46:28 -06:00
|
|
|
double time;
|
2023-12-29 19:08:53 -06:00
|
|
|
double life;
|
2024-01-01 17:30:42 -06:00
|
|
|
HMM_Vec4 color;
|
2023-12-29 19:08:53 -06:00
|
|
|
} particle;
|
2022-12-28 16:50:54 -06:00
|
|
|
|
2024-01-14 10:24:31 -06:00
|
|
|
#define SPRAY 0
|
|
|
|
#define CLOUD 1
|
|
|
|
#define MESH 2
|
|
|
|
|
2024-05-06 21:59:22 -05:00
|
|
|
typedef struct par_vert {
|
|
|
|
HMM_Vec2 pos;
|
|
|
|
float angle;
|
|
|
|
float scale;
|
|
|
|
struct rgba color;
|
|
|
|
} par_vert;
|
|
|
|
|
2023-12-04 13:38:37 -06:00
|
|
|
typedef struct emitter {
|
2023-11-28 17:17:40 -06:00
|
|
|
struct particle *particles;
|
2024-05-06 21:59:22 -05:00
|
|
|
par_vert *verts;
|
2024-01-14 10:24:31 -06:00
|
|
|
HMM_Vec3 *mesh; /* list of points to optionally spawn from */
|
|
|
|
HMM_Vec3 *norm; /* norm at each point */
|
|
|
|
int type; /* spray, cloud, or mesh */
|
2023-12-29 19:08:53 -06:00
|
|
|
float explosiveness; /* 0 for a stream, 1 for all at once. Range of values allowed. */
|
|
|
|
int max; /* number of particles */
|
|
|
|
double life; /* how long a particle lasts */
|
2024-01-04 09:46:28 -06:00
|
|
|
double life_var;
|
2024-01-14 10:24:31 -06:00
|
|
|
/* SPRAY PARTICLE GEN */
|
2024-01-04 08:14:37 -06:00
|
|
|
float speed; /* initial speed of particle */
|
|
|
|
float variation; /* variation on speed */
|
|
|
|
float divergence; /* angular degree of variation from emitter normal, up to 1 */
|
2024-01-14 10:24:31 -06:00
|
|
|
float tumble; /* amount of random rotation of particles */
|
|
|
|
float tumble_rate; /* tumble rotation */
|
2024-01-01 17:30:42 -06:00
|
|
|
sampler color; /* color over particle lifetime */
|
2023-12-29 19:08:53 -06:00
|
|
|
float scale;
|
2024-01-04 08:14:37 -06:00
|
|
|
float scale_var;
|
|
|
|
float grow_for; /* seconds to grow from small until scale */
|
2024-01-04 09:46:28 -06:00
|
|
|
float shrink_for; /* seconds to shrink to small prior to its death */
|
2024-01-04 08:14:37 -06:00
|
|
|
/* ROTATION AND COLLISION */
|
|
|
|
int collision_mask; /* mask for collision */
|
|
|
|
float bounce; /* bounce back after collision */
|
|
|
|
/* PARTICLE SPAWN */
|
|
|
|
int die_after_collision;
|
|
|
|
float persist; /* how long to linger after death */
|
|
|
|
float persist_var;
|
|
|
|
/* TRAILS */
|
|
|
|
warpmask warp_mask;
|
2024-05-06 21:59:22 -05:00
|
|
|
double tte; /* time to emit */
|
|
|
|
sg_buffer buffer;
|
2023-12-04 13:38:37 -06:00
|
|
|
} emitter;
|
2022-12-28 16:50:54 -06:00
|
|
|
|
2023-12-29 19:08:53 -06:00
|
|
|
emitter *make_emitter();
|
2024-01-14 10:24:31 -06:00
|
|
|
void emitter_free(emitter *e);
|
2022-12-28 16:50:54 -06:00
|
|
|
|
2024-05-06 21:59:22 -05:00
|
|
|
void emitter_emit(emitter *e, int count, transform2d *t);
|
|
|
|
void emitter_step(emitter *e, double dt, transform2d *t);
|
|
|
|
void emitter_draw(emitter *e, sg_bindings bind);
|
2022-12-28 16:50:54 -06:00
|
|
|
|
2023-11-28 17:17:40 -06:00
|
|
|
#endif
|