Affectors.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_AFFECTOR_HPP
30 #define THOR_AFFECTOR_HPP
31 
32 #include <Thor/Config.hpp>
33 
34 #include <SFML/System/Time.hpp>
35 #include <SFML/System/Vector2.hpp>
36 
37 #include <functional>
38 
39 
40 namespace thor
41 {
42 
43 class Particle;
44 
47 
64 template <typename Affector>
65 std::function<void(Particle&, sf::Time)> refAffector(Affector& referenced)
66 {
67  return [&referenced] (Particle& particle, sf::Time dt)
68  {
69  return referenced(particle, dt);
70  };
71 }
72 
73 
76 class THOR_API ForceAffector
77 {
78  // ---------------------------------------------------------------------------------------------------------------------------
79  // Public member functions
80  public:
83  explicit ForceAffector(sf::Vector2f acceleration);
84 
88  void operator() (Particle& particle, sf::Time dt);
89 
90 
91  // ---------------------------------------------------------------------------------------------------------------------------
92  // Private variables
93  private:
94  sf::Vector2f mAcceleration;
95 };
96 
97 
100 class THOR_API TorqueAffector
101 {
102  // ---------------------------------------------------------------------------------------------------------------------------
103  // Public member functions
104  public:
108  explicit TorqueAffector(float angularAcceleration);
109 
112  void operator() (Particle& particle, sf::Time dt);
113 
114 
115  // ---------------------------------------------------------------------------------------------------------------------------
116  // Private variables
117  private:
118  float mAngularAcceleration;
119 };
120 
121 
124 class THOR_API ScaleAffector
125 {
126  // ---------------------------------------------------------------------------------------------------------------------------
127  // Public member functions
128  public:
131  explicit ScaleAffector(sf::Vector2f scaleFactor);
132 
135  void operator() (Particle& particle, sf::Time dt);
136 
137 
138  // ---------------------------------------------------------------------------------------------------------------------------
139  // Private variables
140  private:
141  sf::Vector2f mScaleFactor;
142 };
143 
144 
148 class THOR_API AnimationAffector
149 {
150  // ---------------------------------------------------------------------------------------------------------------------------
151  // Public member functions
152  public:
157  explicit AnimationAffector(std::function<void(Particle&, float)> particleAnimation);
158 
161  void operator() (Particle& particle, sf::Time dt);
162 
163 
164  // ---------------------------------------------------------------------------------------------------------------------------
165  // Private variables
166  private:
167  std::function<void(Particle&, float)> mAnimation;
168 };
169 
171 
172 } // namespace thor
173 
174 #endif // THOR_AFFECTOR_HPP
Affector that animates particles using a function.
Definition: Affectors.hpp:148
Applies a rotational acceleration to particles over time.
Definition: Affectors.hpp:100
Definition: AnimationMap.hpp:42
Configuration header of the library.
Applies a translational acceleration to particles over time.
Definition: Affectors.hpp:76
std::function< void(Particle &, sf::Time)> refAffector(Affector &referenced)
Creates a functor that references an affector.
Definition: Affectors.hpp:65
Scales particles over time.
Definition: Affectors.hpp:124
Particle class
Definition: Particle.hpp:49