2020-03-16 20:46:54 +01:00
|
|
|
#define UPPER_AGE 250
|
|
|
|
#define LOWER_AGE 60
|
|
|
|
|
2019-12-16 19:22:52 +01:00
|
|
|
/*
|
|
|
|
* A vector with three floats
|
|
|
|
*/
|
2019-12-17 22:29:36 +01:00
|
|
|
typedef struct vector3f
|
2019-12-16 19:22:52 +01:00
|
|
|
{
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
float z;
|
2019-12-17 22:29:36 +01:00
|
|
|
} vector3f;
|
2019-12-16 19:22:52 +01:00
|
|
|
|
|
|
|
/*
|
2020-03-08 21:03:48 +01:00
|
|
|
* A particle has a position and a velocity
|
2019-12-16 19:22:52 +01:00
|
|
|
*/
|
2019-12-17 22:29:36 +01:00
|
|
|
typedef struct particle
|
2019-12-16 19:22:52 +01:00
|
|
|
{
|
2019-12-17 22:29:36 +01:00
|
|
|
vector3f *position;
|
2020-03-08 21:03:48 +01:00
|
|
|
vector3f *velocity;
|
2019-12-28 13:54:53 +01:00
|
|
|
vector3f *color;
|
|
|
|
float age;
|
2019-12-17 22:29:36 +01:00
|
|
|
} particle;
|
2019-12-16 19:22:52 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* An emitter has a position and contains an array of particles
|
|
|
|
*/
|
2019-12-17 22:29:36 +01:00
|
|
|
typedef struct emitter
|
2019-12-16 19:22:52 +01:00
|
|
|
{
|
2019-12-17 22:29:36 +01:00
|
|
|
vector3f *position;
|
|
|
|
particle **particles;
|
2019-12-16 19:22:52 +01:00
|
|
|
int pamount;
|
2019-12-17 22:29:36 +01:00
|
|
|
} emitter;
|
2019-12-16 19:22:52 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A particle system consists of one or more emitter
|
|
|
|
*/
|
2019-12-17 22:29:36 +01:00
|
|
|
typedef struct particle_system
|
2019-12-16 19:22:52 +01:00
|
|
|
{
|
2019-12-17 22:29:36 +01:00
|
|
|
emitter **emitters;
|
2019-12-16 19:22:52 +01:00
|
|
|
int eamount;
|
2019-12-17 22:29:36 +01:00
|
|
|
} particle_system;
|
2019-12-16 19:22:52 +01:00
|
|
|
|
2020-01-08 16:58:38 +01:00
|
|
|
/*
|
|
|
|
* A function to calculate the new position of a particle
|
|
|
|
*/
|
|
|
|
typedef void (* CalculatePositionFunction)(particle *particle, float dt);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A function to calculate the new color of a particle
|
|
|
|
*/
|
|
|
|
typedef void (* CalculateColorFunction)(particle *particle);
|
|
|
|
|
2019-12-16 19:22:52 +01:00
|
|
|
/*
|
2019-12-17 22:29:36 +01:00
|
|
|
* Initializes a particle
|
2019-12-16 19:22:52 +01:00
|
|
|
*/
|
2019-12-28 13:54:53 +01:00
|
|
|
particle *initParticle(vector3f *pos, vector3f *dir, vector3f *color, float age);
|
2019-12-16 19:22:52 +01:00
|
|
|
|
|
|
|
/*
|
2019-12-17 22:29:36 +01:00
|
|
|
* Initializes an emitter
|
2019-12-16 19:22:52 +01:00
|
|
|
*/
|
2019-12-17 22:29:36 +01:00
|
|
|
emitter *initEmitter(vector3f *pos, int pamount);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes a particle system
|
|
|
|
*/
|
|
|
|
particle_system *initParticleSystem(int eamount);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Updates particle
|
|
|
|
*/
|
2020-04-01 22:17:35 +02:00
|
|
|
void updateParticles(float dt, particle_system *particleSystem, CalculatePositionFunction calculatePosition, CalculateColorFunction calculateColor);
|
2019-12-17 22:29:36 +01:00
|
|
|
|
2020-01-08 17:33:01 +01:00
|
|
|
/*
|
|
|
|
* Resets a particle to seed at emitter's position
|
|
|
|
*/
|
|
|
|
void resetParticle(emitter *e, particle *p);
|
|
|
|
|
2019-12-17 22:29:36 +01:00
|
|
|
/*
|
|
|
|
* Updates particle
|
|
|
|
*/
|
|
|
|
int drawParticles(particle_system *particleSystem);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes a vector
|
|
|
|
* For that it allocates memory that must be freed later
|
|
|
|
*/
|
|
|
|
vector3f *initVector3f(float x, float y, float z);
|
2019-12-16 19:22:52 +01:00
|
|
|
|
2020-01-08 16:58:38 +01:00
|
|
|
/*
|
|
|
|
* Frees a given particle and all corresponding data
|
|
|
|
*/
|
|
|
|
void freeParticle(particle *p);
|
|
|
|
|
2019-12-20 14:24:52 +01:00
|
|
|
/*
|
|
|
|
* Frees an given emitter with all particles
|
|
|
|
*/
|
|
|
|
void freeEmitter(emitter *e);
|
2019-12-16 19:22:52 +01:00
|
|
|
|
2019-12-20 14:24:52 +01:00
|
|
|
/*
|
|
|
|
* Frees all emitters within an particle system
|
|
|
|
*/
|
|
|
|
void freeEmitters(particle_system *ps);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Frees all emitter and particles within a particle system
|
|
|
|
*/
|
2020-02-11 19:01:50 +01:00
|
|
|
void freeParticleSystem(particle_system *ps);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates float array out of a particle system
|
|
|
|
*/
|
2020-03-16 20:46:54 +01:00
|
|
|
float *serializeParticlesystem(particle_system *ps);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inits random particle
|
|
|
|
*/
|
|
|
|
void initRandomParticles(emitter *e);
|