textpsys
diff src/psys.h @ 0:a4ffd9e6984c
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 19 Aug 2015 09:13:48 +0300 |
parents | |
children | 4b1360a5d54d |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/psys.h Wed Aug 19 09:13:48 2015 +0300 1.3 @@ -0,0 +1,71 @@ 1.4 +#ifndef PSYS_H_ 1.5 +#define PSYS_H_ 1.6 + 1.7 +#include <vector> 1.8 +#include "vec3.h" 1.9 +#include "image.h" 1.10 + 1.11 +struct PSysParam { 1.12 + // emitter parameters 1.13 + float spawn_rate; 1.14 + float spawn_range; 1.15 + float life, life_range; 1.16 + float size, size_range; 1.17 + Vector3 gravity; 1.18 + Image *spawn_map; 1.19 + float spawn_map_speed; 1.20 + 1.21 + // particle parameters 1.22 + Image *pimg; 1.23 + Vector3 pcolor_start, pcolor_mid, pcolor_end; 1.24 + float palpha_start, palpha_mid, palpha_end; 1.25 + float pscale_start, pscale_mid, pscale_end; 1.26 +}; 1.27 + 1.28 +void psys_default(PSysParam *pp); 1.29 + 1.30 +struct Particle { 1.31 + Vector3 pos, vel; 1.32 + Vector3 color; 1.33 + float alpha; 1.34 + float life, max_life; 1.35 + float size, scale; 1.36 + 1.37 + struct Particle *next; 1.38 +}; 1.39 + 1.40 +class ParticleSystem { 1.41 +private: 1.42 + float spawn_pending; 1.43 + Particle *plist; 1.44 + int pcount; 1.45 + 1.46 + float active_time; 1.47 + bool expl; 1.48 + Vector3 expl_cent; 1.49 + float expl_force, expl_dur; 1.50 + float expl_life; 1.51 + 1.52 + Vector3 *smcache; 1.53 + int smcache_max[256]; 1.54 + void gen_spawnmap(int count); 1.55 + 1.56 + void spawn_particle(); 1.57 + 1.58 +public: 1.59 + Vector3 pos; 1.60 + PSysParam pp; 1.61 + bool active; 1.62 + 1.63 + ParticleSystem(); 1.64 + ~ParticleSystem(); 1.65 + 1.66 + void explode(const Vector3 &c, float force, float dur = 1.0, float life = 0.0); 1.67 + 1.68 + bool alive() const; 1.69 + 1.70 + void update(float dt); 1.71 + void draw() const; 1.72 +}; 1.73 + 1.74 +#endif // PSYS_H_