Emitters.hpp
Go to the documentation of this file.
1 //
3 // Thor C++ Library
4 // Copyright (c) 2011-2016 Jan Haller
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would be
17 // appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not be
20 // misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source distribution.
23 //
25 
28 
29 #ifndef THOR_EMITTER_HPP
30 #define THOR_EMITTER_HPP
31 
33 #include <Thor/Config.hpp>
34 
35 #include <SFML/System/Time.hpp>
36 #include <SFML/System/Vector2.hpp>
37 #include <SFML/Graphics/Color.hpp>
38 
39 
40 namespace thor
41 {
42 
43 class EmissionInterface;
44 
45 
48 
65 template <typename Emitter>
66 std::function<void(EmissionInterface&, sf::Time)> refEmitter(Emitter& referenced)
67 {
68  return [&referenced] (EmissionInterface& system, sf::Time dt)
69  {
70  return referenced(system, dt);
71  };
72 }
73 
74 
80 class THOR_API UniversalEmitter
81 {
82  // ---------------------------------------------------------------------------------------------------------------------------
83  // Public member functions
84  public:
88 
92  void operator() (EmissionInterface& system, sf::Time dt);
93 
97  void setEmissionRate(float particlesPerSecond);
98 
101  void setParticleLifetime(Distribution<sf::Time> particleLifetime);
102 
105  void setParticlePosition(Distribution<sf::Vector2f> particlePosition);
106 
109  void setParticleVelocity(Distribution<sf::Vector2f> particleVelocity);
110 
113  void setParticleRotation(Distribution<float> particleRotation);
114 
117  void setParticleRotationSpeed(Distribution<float> particleRotationSpeed);
118 
121  void setParticleScale(Distribution<sf::Vector2f> particleScale);
122 
125  void setParticleColor(Distribution<sf::Color> particleColor);
126 
129  void setParticleTextureIndex(Distribution<unsigned int> particleTextureIndex);
130 
131 
132  // ---------------------------------------------------------------------------------------------------------------------------
133  // Private member functions
134  private:
135  // Returns the number of particles to emit during this frame.
136  std::size_t computeParticleCount(sf::Time dt);
137 
138 
139  // ---------------------------------------------------------------------------------------------------------------------------
140  // Private variables
141  private:
142  float mEmissionRate;
143  float mEmissionDifference;
144 
145  Distribution<sf::Time> mParticleLifetime;
146  Distribution<sf::Vector2f> mParticlePosition;
147  Distribution<sf::Vector2f> mParticleVelocity;
148  Distribution<float> mParticleRotation;
149  Distribution<float> mParticleRotationSpeed;
150  Distribution<sf::Vector2f> mParticleScale;
151  Distribution<sf::Color> mParticleColor;
152  Distribution<unsigned int> mParticleTextureIndex;
153 };
154 
156 
157 } // namespace thor
158 
159 #endif // THOR_EMITTER_HPP
std::function< void(EmissionInterface &, sf::Time)> refEmitter(Emitter &referenced)
Creates a functor that references an emitter.
Definition: Emitters.hpp:66
Class that connects emitters with their corresponding particle system.
Definition: EmissionInterface.hpp:46
Definition: AnimationMap.hpp:42
Configuration header of the library.
Class template thor::Distribution.
Class that emits particles with customizable initial conditions.
Definition: Emitters.hpp:80