1
0
rwu_particles_informatikpro.../particlesystem.h

118 lines
2.2 KiB
C
Raw Normal View History

#define UPPER_AGE 250
#define LOWER_AGE 60
2019-12-16 18:22:52 +00:00
/*
* A vector with three floats
*/
2019-12-17 21:29:36 +00:00
typedef struct vector3f
2019-12-16 18:22:52 +00:00
{
float x;
float y;
float z;
2019-12-17 21:29:36 +00:00
} vector3f;
2019-12-16 18:22:52 +00:00
/*
2020-03-08 20:03:48 +00:00
* A particle has a position and a velocity
2019-12-16 18:22:52 +00:00
*/
2019-12-17 21:29:36 +00:00
typedef struct particle
2019-12-16 18:22:52 +00:00
{
2019-12-17 21:29:36 +00:00
vector3f *position;
2020-03-08 20:03:48 +00:00
vector3f *velocity;
2019-12-28 12:54:53 +00:00
vector3f *color;
float age;
2019-12-17 21:29:36 +00:00
} particle;
2019-12-16 18:22:52 +00:00
/*
* An emitter has a position and contains an array of particles
*/
2019-12-17 21:29:36 +00:00
typedef struct emitter
2019-12-16 18:22:52 +00:00
{
2019-12-17 21:29:36 +00:00
vector3f *position;
particle **particles;
2019-12-16 18:22:52 +00:00
int pamount;
2019-12-17 21:29:36 +00:00
} emitter;
2019-12-16 18:22:52 +00:00
/*
* A particle system consists of one or more emitter
*/
2019-12-17 21:29:36 +00:00
typedef struct particle_system
2019-12-16 18:22:52 +00:00
{
2019-12-17 21:29:36 +00:00
emitter **emitters;
2019-12-16 18:22:52 +00:00
int eamount;
2019-12-17 21:29:36 +00:00
} particle_system;
2019-12-16 18:22:52 +00: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 18:22:52 +00:00
/*
2019-12-17 21:29:36 +00:00
* Initializes a particle
2019-12-16 18:22:52 +00:00
*/
2019-12-28 12:54:53 +00:00
particle *initParticle(vector3f *pos, vector3f *dir, vector3f *color, float age);
2019-12-16 18:22:52 +00:00
/*
2019-12-17 21:29:36 +00:00
* Initializes an emitter
2019-12-16 18:22:52 +00:00
*/
2019-12-17 21:29:36 +00:00
emitter *initEmitter(vector3f *pos, int pamount);
/*
* Initializes a particle system
*/
particle_system *initParticleSystem(int eamount);
/*
* Updates particle
*/
int updateParticles(float dt, particle_system *particleSystem, CalculatePositionFunction calculatePosition, CalculateColorFunction calculateColor);
2019-12-17 21:29:36 +00:00
2020-01-08 16:33:01 +00:00
/*
* Resets a particle to seed at emitter's position
*/
void resetParticle(emitter *e, particle *p);
2019-12-17 21:29:36 +00: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 18:22:52 +00:00
/*
* Frees a given particle and all corresponding data
*/
void freeParticle(particle *p);
2019-12-20 13:24:52 +00:00
/*
* Frees an given emitter with all particles
*/
void freeEmitter(emitter *e);
2019-12-16 18:22:52 +00:00
2019-12-20 13:24:52 +00: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 18:01:50 +00:00
void freeParticleSystem(particle_system *ps);
/*
* Creates float array out of a particle system
*/
float *serializeParticlesystem(particle_system *ps);
/*
* Inits random particle
*/
void initRandomParticles(emitter *e);