![]() |
00001 00002 // 00003 // Thor C++ Library 00004 // Copyright (c) 2011-2015 Jan Haller 00005 // 00006 // This software is provided 'as-is', without any express or implied 00007 // warranty. In no event will the authors be held liable for any damages 00008 // arising from the use of this software. 00009 // 00010 // Permission is granted to anyone to use this software for any purpose, 00011 // including commercial applications, and to alter it and redistribute it 00012 // freely, subject to the following restrictions: 00013 // 00014 // 1. The origin of this software must not be misrepresented; you must not 00015 // claim that you wrote the original software. If you use this software 00016 // in a product, an acknowledgment in the product documentation would be 00017 // appreciated but is not required. 00018 // 00019 // 2. Altered source versions must be plainly marked as such, and must not be 00020 // misrepresented as being the original software. 00021 // 00022 // 3. This notice may not be removed or altered from any source distribution. 00023 // 00025 00028 00029 #ifndef THOR_AFFECTOR_HPP 00030 #define THOR_AFFECTOR_HPP 00031 00032 #include <Thor/Config.hpp> 00033 00034 #include <SFML/System/Time.hpp> 00035 #include <SFML/System/Vector2.hpp> 00036 00037 #include <functional> 00038 00039 00040 namespace thor 00041 { 00042 00043 class Particle; 00044 00047 00064 template <typename Affector> 00065 std::function<void(Particle&, sf::Time)> refAffector(Affector& referenced) 00066 { 00067 return [&referenced] (Particle& particle, sf::Time dt) 00068 { 00069 return referenced(particle, dt); 00070 }; 00071 } 00072 00073 00076 class THOR_API ForceAffector 00077 { 00078 // --------------------------------------------------------------------------------------------------------------------------- 00079 // Public member functions 00080 public: 00083 explicit ForceAffector(sf::Vector2f acceleration); 00084 00088 void operator() (Particle& particle, sf::Time dt); 00089 00090 00091 // --------------------------------------------------------------------------------------------------------------------------- 00092 // Private variables 00093 private: 00094 sf::Vector2f mAcceleration; 00095 }; 00096 00097 00100 class THOR_API TorqueAffector 00101 { 00102 // --------------------------------------------------------------------------------------------------------------------------- 00103 // Public member functions 00104 public: 00108 explicit TorqueAffector(float angularAcceleration); 00109 00112 void operator() (Particle& particle, sf::Time dt); 00113 00114 00115 // --------------------------------------------------------------------------------------------------------------------------- 00116 // Private variables 00117 private: 00118 float mAngularAcceleration; 00119 }; 00120 00121 00124 class THOR_API ScaleAffector 00125 { 00126 // --------------------------------------------------------------------------------------------------------------------------- 00127 // Public member functions 00128 public: 00131 explicit ScaleAffector(sf::Vector2f scaleFactor); 00132 00135 void operator() (Particle& particle, sf::Time dt); 00136 00137 00138 // --------------------------------------------------------------------------------------------------------------------------- 00139 // Private variables 00140 private: 00141 sf::Vector2f mScaleFactor; 00142 }; 00143 00144 00148 class THOR_API AnimationAffector 00149 { 00150 // --------------------------------------------------------------------------------------------------------------------------- 00151 // Public member functions 00152 public: 00157 explicit AnimationAffector(std::function<void(Particle&, float)> particleAnimation); 00158 00161 void operator() (Particle& particle, sf::Time dt); 00162 00163 00164 // --------------------------------------------------------------------------------------------------------------------------- 00165 // Private variables 00166 private: 00167 std::function<void(Particle&, float)> mAnimation; 00168 }; 00169 00171 00172 } // namespace thor 00173 00174 #endif // THOR_AFFECTOR_HPP