Showing the changes to interface/src/ParticleSystem.h (1 of 4 files). Show all
Unified · Split
| @@ -11,11 +11,18 @@ · 10 unmodified lines | |||
| 11 | #include <glm/gtc/quaternion.hpp> | 11 | #include <glm/gtc/quaternion.hpp> |
| 12 | 12 | ||
| 13 | const int MAX_PARTICLES = 5000; | 13 | const int MAX_PARTICLES = 5000; |
| 14 | const int MAX_EMITTERS = 20; | 14 | const int MAX_EMITTERS = 1000; |
| 15 | const int NUM_PARTICLE_LIFE_STAGES = 4; | 15 | const int NUM_PARTICLE_LIFE_STAGES = 4; // each equal time-division of the particle's life can have different attributes |
| 16 | const bool USE_BILLBOARD_RENDERING = false; | ||
| 17 | const bool SHOW_VELOCITY_TAILS = false; | 16 | const bool SHOW_VELOCITY_TAILS = false; |
| 18 | 17 | ||
| 18 | enum ParticleRenderStyle | ||
| 19 | { | ||
| 20 | PARTICLE_RENDER_STYLE_SPHERE = 0, | ||
| 21 | PARTICLE_RENDER_STYLE_BILLBOARD, | ||
| 22 | PARTICLE_RENDER_STYLE_RIBBON, | ||
| 23 | NUM_PARTICLE_RENDER_STYLES | ||
| 24 | }; | ||
| 25 | |||
| 19 | class ParticleSystem { | 26 | class ParticleSystem { |
| 20 | public: | 27 | public: |
| 21 | 28 | ||
| @@ -45,42 +52,44 @@ public: · 23 unmodified lines | |||
| 45 | void render(); | 52 | void render(); |
| 46 | 53 | ||
| 47 | void setUpDirection(glm::vec3 upDirection) {_upDirection = upDirection;} // tell particle system which direction is up | 54 | void setUpDirection(glm::vec3 upDirection) {_upDirection = upDirection;} // tell particle system which direction is up |
| 48 | void setShowingEmitterBaseParticle(int emitterIndex, bool showing ); | ||
| 49 | void setParticleAttributes (int emitterIndex, ParticleAttributes attributes); // set attributes for whole life of particles | 55 | void setParticleAttributes (int emitterIndex, ParticleAttributes attributes); // set attributes for whole life of particles |
| 50 | void setParticleAttributes (int emitterIndex, int lifeStage, ParticleAttributes attributes); // set attributes for this life stage of particles | 56 | void setParticleAttributes (int emitterIndex, int lifeStage, ParticleAttributes attributes); // set attributes for this life stage of particles |
| 51 | void setEmitterBaseParticleColor (int emitterIndex, glm::vec4 color ) {_emitter[emitterIndex].baseParticle.color = color; } | 57 | void setEmitterPosition (int emitterIndex, glm::vec3 position ) {_emitter[emitterIndex].position = position; } |
| 52 | void setEmitterBaseParticleRadius (int emitterIndex, float radius ) {_emitter[emitterIndex].baseParticle.radius = radius; } | 58 | void setEmitterParticleResolution (int emitterIndex, int resolution ) {_emitter[emitterIndex].particleResolution = resolution; } |
| 53 | void setEmitterPosition (int emitterIndex, glm::vec3 position ) {_emitter[emitterIndex].position = position; } | 59 | void setEmitterDirection (int emitterIndex, glm::vec3 direction ) {_emitter[emitterIndex].direction = direction; } |
| 54 | void setEmitterParticleResolution (int emitterIndex, int resolution) {_emitter[emitterIndex].particleResolution = resolution; } | 60 | void setShowingEmitter (int emitterIndex, bool showing ) {_emitter[emitterIndex].visible = showing; } |
| 55 | void setEmitterDirection (int emitterIndex, glm::vec3 direction ) {_emitter[emitterIndex].direction = direction; } | 61 | void setEmitterParticleLifespan (int emitterIndex, float lifespan ) {_emitter[emitterIndex].particleLifespan = lifespan; } |
| 56 | void setShowingEmitter (int emitterIndex, bool showing ) {_emitter[emitterIndex].visible = showing; } | 62 | void setParticleRenderStyle (int emitterIndex, ParticleRenderStyle renderStyle ) {_emitter[emitterIndex].particleRenderStyle = renderStyle; } |
| 57 | void setEmitterParticleLifespan (int emitterIndex, float lifespan ) {_emitter[emitterIndex].particleLifespan = lifespan; } | 63 | void setEmitterThrust (int emitterIndex, float thrust ) {_emitter[emitterIndex].thrust = thrust; } |
| 58 | void setEmitterThrust (int emitterIndex, float thrust ) {_emitter[emitterIndex].thrust = thrust; } | 64 | void setEmitterRate (int emitterIndex, float rate ) {_emitter[emitterIndex].rate = rate; } |
| 59 | void setEmitterRate (int emitterIndex, float rate ) {_emitter[emitterIndex].rate = rate; } | 65 | void setShowingEmitterBaseParticle(int emitterIndex, bool showing ) {_emitter[emitterIndex].showingBaseParticle = showing; } |
| 60 | 66 | ||
| 61 | private: | 67 | private: |
| 62 | 68 | ||
| 63 | struct Particle { | 69 | struct Particle { |
| 64 | bool alive; // is the particle active? | 70 | bool alive; // is the particle active? |
| 65 | glm::vec3 position; // position | 71 | glm::vec3 position; // position |
| 66 | glm::vec3 velocity; // velocity | 72 | glm::vec3 velocity; // velocity |
| 67 | glm::vec4 color; // color (rgba) | 73 | glm::vec4 color; // color (rgba) |
| 68 | float age; // age in seconds | 74 | float age; // age in seconds |
| 69 | float radius; // radius | 75 | float radius; // radius |
| 70 | int emitterIndex; // which emitter created this particle? | 76 | int emitterIndex; // which emitter created this particle? |
| 77 | int previousParticle; // the last particle that this particle's emitter emitted; | ||
| 71 | }; | 78 | }; |
| 72 | 79 | ||
| 73 | struct Emitter { | 80 | struct Emitter { |
| 74 | glm::vec3 position; // teh position of the emitter in world coordinates | 81 | glm::vec3 position; // the position of the emitter in world coordinates |
| 75 | glm::vec3 direction; // a normalized vector used as an axis for particle emission and other effects | 82 | glm::vec3 direction; // a normalized vector used as an axis for particle emission and other effects |
| 76 | bool visible; // whether or not a line is shown indicating the emitter (indicating its direction) | 83 | bool visible; // whether or not a line is shown indicating the emitter (indicating its direction) |
| 77 | float particleLifespan; // how long the particle shall live, in seconds | 84 | float particleLifespan; // how long the particle shall live, in seconds |
| 78 | int particleResolution; // for sphere-based particles | 85 | int particleResolution; // for sphere-based particles |
| 79 | float thrust; // the initial velocity upon emitting along the emitter direction | 86 | float thrust; // the initial velocity upon emitting along the emitter direction |
| 80 | float rate; // currently, how many particles emitted during a simulation time step | 87 | float rate; // currently, how many particles emitted during a simulation time step |
| 81 | Particle baseParticle; // a non-physical particle at the emitter position | 88 | bool showingBaseParticle; // if true, a copy of particle 0 is shown on the emitter position |
| 89 | int currentParticle; // the index of the most recently-emitted particle | ||
| 82 | ParticleAttributes particleAttributes[NUM_PARTICLE_LIFE_STAGES]; // the attributes of particles emitted from this emitter | 90 | ParticleAttributes particleAttributes[NUM_PARTICLE_LIFE_STAGES]; // the attributes of particles emitted from this emitter |
| 83 | }; | 91 | ParticleRenderStyle particleRenderStyle; |
| 92 | }; | ||
| 84 | 93 | ||
| 85 | glm::vec3 _upDirection; | 94 | glm::vec3 _upDirection; |
| 86 | Emitter _emitter[MAX_EMITTERS]; | 95 | Emitter _emitter[MAX_EMITTERS]; |