00001 00002 // 00003 // Thor C++ Library 00004 // Copyright (c) 2011-2012 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/Particles/ParticleInterfaces.hpp> 00033 #include <Thor/Multimedia/Colors.hpp> 00034 #include <Thor/Config.hpp> 00035 00036 #include <SFML/System/Time.hpp> 00037 #include <SFML/System/Vector2.hpp> 00038 00039 00040 namespace thor 00041 { 00042 00045 00048 class THOR_API ForceAffector : public Affector 00049 { 00050 // --------------------------------------------------------------------------------------------------------------------------- 00051 // Public types 00052 public: 00055 typedef std::tr1::shared_ptr<ForceAffector> Ptr; 00056 00057 00058 // --------------------------------------------------------------------------------------------------------------------------- 00059 // Public static member functions 00060 public: 00063 static Ptr Create(sf::Vector2f acceleration); 00064 00065 00066 // --------------------------------------------------------------------------------------------------------------------------- 00067 // Public member functions 00068 public: 00071 explicit ForceAffector(sf::Vector2f acceleration); 00072 00073 virtual void Affect(Particle& particle, sf::Time dt); 00074 00077 void SetAcceleration(sf::Vector2f acceleration); 00078 00081 sf::Vector2f GetAcceleration() const; 00082 00083 00084 // --------------------------------------------------------------------------------------------------------------------------- 00085 // Private variables 00086 private: 00087 sf::Vector2f mAcceleration; 00088 }; 00089 00090 00093 class THOR_API TorqueAffector : public Affector 00094 { 00095 // --------------------------------------------------------------------------------------------------------------------------- 00096 // Public types 00097 public: 00100 typedef std::tr1::shared_ptr<TorqueAffector> Ptr; 00101 00102 00103 // --------------------------------------------------------------------------------------------------------------------------- 00104 // Public static member functions 00105 public: 00108 static Ptr Create(float angularAcceleration); 00109 00110 00111 // --------------------------------------------------------------------------------------------------------------------------- 00112 // Public member functions 00113 public: 00117 explicit TorqueAffector(float angularAcceleration); 00118 00119 virtual void Affect(Particle& particle, sf::Time dt); 00120 00123 void SetAngularAcceleration(float angularAcceleration); 00124 00127 float GetAngularAcceleration() const; 00128 00129 00130 // --------------------------------------------------------------------------------------------------------------------------- 00131 // Private variables 00132 private: 00133 float mAngularAcceleration; 00134 }; 00135 00136 00139 class THOR_API ScaleAffector : public Affector 00140 { 00141 // --------------------------------------------------------------------------------------------------------------------------- 00142 // Public types 00143 public: 00146 typedef std::tr1::shared_ptr<ScaleAffector> Ptr; 00147 00148 00149 // --------------------------------------------------------------------------------------------------------------------------- 00150 // Public static member functions 00151 public: 00154 static Ptr Create(sf::Vector2f scaleFactor); 00155 00156 00157 // --------------------------------------------------------------------------------------------------------------------------- 00158 // Public member functions 00159 public: 00162 explicit ScaleAffector(sf::Vector2f scaleFactor); 00163 00164 virtual void Affect(Particle& particle, sf::Time dt); 00165 00168 void SetScaleFactor(sf::Vector2f scaleFactor); 00169 00172 sf::Vector2f GetScaleFactor() const; 00173 00174 00175 // --------------------------------------------------------------------------------------------------------------------------- 00176 // Private variables 00177 private: 00178 sf::Vector2f mScaleFactor; 00179 }; 00180 00181 00184 class THOR_API FadeInAffector : public Affector 00185 { 00186 // --------------------------------------------------------------------------------------------------------------------------- 00187 // Public types 00188 public: 00191 typedef std::tr1::shared_ptr<FadeInAffector> Ptr; 00192 00193 00194 // --------------------------------------------------------------------------------------------------------------------------- 00195 // Public static member functions 00196 public: 00199 static Ptr Create(float timeRatio = 1.f); 00200 00201 00202 // --------------------------------------------------------------------------------------------------------------------------- 00203 // Public member functions 00204 public: 00208 explicit FadeInAffector(float timeRatio = 1.f); 00209 00210 virtual void Affect(Particle& particle, sf::Time dt); 00211 00214 void SetTimeRatio(float timeRatio); 00215 00218 float GetTimeRatio() const; 00219 00220 00221 // --------------------------------------------------------------------------------------------------------------------------- 00222 // Private variables 00223 private: 00224 float mTimeRatio; 00225 }; 00226 00227 00230 class THOR_API FadeOutAffector : public Affector 00231 { 00232 // --------------------------------------------------------------------------------------------------------------------------- 00233 // Public types 00234 public: 00237 typedef std::tr1::shared_ptr<FadeOutAffector> Ptr; 00238 00239 00240 // --------------------------------------------------------------------------------------------------------------------------- 00241 // Public static member functions 00242 public: 00245 static Ptr Create(float timeRatio = 1.f); 00246 00247 00248 // --------------------------------------------------------------------------------------------------------------------------- 00249 // Public member functions 00250 public: 00254 explicit FadeOutAffector(float timeRatio = 1.f); 00255 00256 virtual void Affect(Particle& particle, sf::Time dt); 00257 00260 void SetTimeRatio(float timeRatio); 00261 00264 float GetTimeRatio() const; 00265 00266 00267 // --------------------------------------------------------------------------------------------------------------------------- 00268 // Private variables 00269 private: 00270 float mTimeRatio; 00271 }; 00272 00273 00276 class THOR_API ColorAffector : public Affector 00277 { 00278 // --------------------------------------------------------------------------------------------------------------------------- 00279 // Public types 00280 public: 00283 typedef std::tr1::shared_ptr<ColorAffector> Ptr; 00284 00285 00286 // --------------------------------------------------------------------------------------------------------------------------- 00287 // Public static member functions 00288 public: 00291 static Ptr Create(const ColorGradient& gradient); 00292 00293 00294 // --------------------------------------------------------------------------------------------------------------------------- 00295 // Public member functions 00296 public: 00300 explicit ColorAffector(const ColorGradient& gradient); 00301 00302 virtual void Affect(Particle& particle, sf::Time dt); 00303 00306 void SetGradient(const ColorGradient& gradient); 00307 00310 const ColorGradient& GetGradient() const; 00311 00312 00313 // --------------------------------------------------------------------------------------------------------------------------- 00314 // Private variables 00315 private: 00316 ColorGradient mGradient; 00317 }; 00318 00320 00321 } // namespace thor 00322 00323 #endif // THOR_AFFECTOR_HPP