prosperon/source/engine/particle.h

77 lines
2 KiB
C
Raw Normal View History

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"
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
2023-12-04 13:38:37 -06:00
typedef struct emitter {
2023-11-28 17:17:40 -06:00
struct particle *particles;
2023-12-04 13:38:37 -06:00
transform3d t;
2024-01-14 10:24:31 -06:00
gameobject *go;
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
/* PARTICLE TYPE */
2023-12-29 19:08:53 -06:00
texture *texture;
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-01-01 17:30:42 -06:00
int on;
2024-01-04 08:14:37 -06:00
double tte; /* time to emit */
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
void particle_init();
emitter *make_emitter();
2024-01-14 10:24:31 -06:00
void emitter_free(emitter *e);
2022-12-28 16:50:54 -06:00
2023-12-29 19:08:53 -06:00
void start_emitter(emitter *e);
void stop_emitter(emitter *e);
2022-12-28 16:50:54 -06:00
2023-12-29 19:08:53 -06:00
void emitter_emit(emitter *e, int count);
void emitters_step(double dt);
2024-03-27 15:00:59 -05:00
void emitters_draw(HMM_Mat4 *proj);
2023-12-29 19:08:53 -06:00
void emitter_step(emitter *e, double dt);
2022-12-28 16:50:54 -06:00
2023-11-28 17:17:40 -06:00
#endif