Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
colour_fader.h
1 #pragma once
2 
3 #include "../particle_script.h"
4 #include "curves.h"
5 
6 namespace smlt {
7 
8 class ColourFader:
9  public Manipulator {
10 public:
11  ColourFader(ParticleScript* script, const std::vector<Colour>& colours, bool interpolate):
12  Manipulator(script, "colour_fader"),
13  colours_(colours),
14  interpolate_(interpolate) {}
15 
16 private:
17  void do_manipulate(ParticleSystem*, Particle* particles, std::size_t particle_count, float) const {
18  auto size = colours_.size();
19  auto particle = particles;
20  for(auto i = 0u; i < particle_count; ++i) {
21  float e = (particle->lifetime - particle->ttl);
22  float n = e / particle->lifetime;
23  long unsigned int colour = (size * n);
24 
25  particle->colour = colours_[colour];
26 
27  if(interpolate_) {
28  float f = (size * n) - int(size * n);
29  auto next_colour = colours_[std::min((uint32_t) colour + 1, (uint32_t) size - 1)];
30  particle->colour = (particle->colour * (1.0f - f)) + (next_colour * f);
31  }
32 
33  ++particle;
34  }
35  }
36 
37  std::vector<Colour> colours_;
38  bool interpolate_ = true;
39 };
40 
41 }
smlt::Manipulator
Definition: particle_script.h:38
smlt
Definition: animation.cpp:25
smlt::ParticleSystem
Definition: particle_system.h:43
smlt::Particle
Definition: particle_system.h:21
smlt::ParticleScript
Definition: particle_script.h:71
smlt::ColourFader
Definition: colour_fader.h:9