00001 00002 // 00003 // Thor C++ Library 00004 // Copyright (c) 2011 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/Vector2.hpp> 00037 00038 00039 namespace thor 00040 { 00041 00044 00047 class THOR_API ForceAffector : public Affector 00048 { 00049 // --------------------------------------------------------------------------------------------------------------------------- 00050 // Public types 00051 public: 00054 typedef std::tr1::shared_ptr<ForceAffector> Ptr; 00055 00056 00057 // --------------------------------------------------------------------------------------------------------------------------- 00058 // Public static member functions 00059 public: 00062 static Ptr Create(sf::Vector2f acceleration); 00063 00064 00065 // --------------------------------------------------------------------------------------------------------------------------- 00066 // Public member functions 00067 public: 00070 explicit ForceAffector(sf::Vector2f acceleration); 00071 00072 virtual void Affect(Particle& particle, float dt); 00073 00076 void SetAcceleration(sf::Vector2f acceleration); 00077 00080 sf::Vector2f GetAcceleration() const; 00081 00082 00083 // --------------------------------------------------------------------------------------------------------------------------- 00084 // Private variables 00085 private: 00086 sf::Vector2f mAcceleration; 00087 }; 00088 00089 00092 class THOR_API TorqueAffector : public Affector 00093 { 00094 // --------------------------------------------------------------------------------------------------------------------------- 00095 // Public types 00096 public: 00099 typedef std::tr1::shared_ptr<TorqueAffector> Ptr; 00100 00101 00102 // --------------------------------------------------------------------------------------------------------------------------- 00103 // Public static member functions 00104 public: 00107 static Ptr Create(float angularAcceleration); 00108 00109 00110 // --------------------------------------------------------------------------------------------------------------------------- 00111 // Public member functions 00112 public: 00116 explicit TorqueAffector(float angularAcceleration); 00117 00118 virtual void Affect(Particle& particle, float dt); 00119 00122 void SetAngularAcceleration(float angularAcceleration); 00123 00126 float GetAngularAcceleration() const; 00127 00128 00129 // --------------------------------------------------------------------------------------------------------------------------- 00130 // Private variables 00131 private: 00132 float mAngularAcceleration; 00133 }; 00134 00135 00138 class THOR_API FadeInAffector : public Affector 00139 { 00140 // --------------------------------------------------------------------------------------------------------------------------- 00141 // Public types 00142 public: 00145 typedef std::tr1::shared_ptr<FadeInAffector> Ptr; 00146 00147 00148 // --------------------------------------------------------------------------------------------------------------------------- 00149 // Public static member functions 00150 public: 00153 static Ptr Create(float timeRatio = 1.f); 00154 00155 00156 // --------------------------------------------------------------------------------------------------------------------------- 00157 // Public member functions 00158 public: 00162 explicit FadeInAffector(float timeRatio = 1.f); 00163 00164 virtual void Affect(Particle& particle, float dt); 00165 00168 void SetTimeRatio(float timeRatio); 00169 00172 float GetTimeRatio() const; 00173 00174 00175 // --------------------------------------------------------------------------------------------------------------------------- 00176 // Private variables 00177 private: 00178 float mTimeRatio; 00179 }; 00180 00181 00184 class THOR_API FadeOutAffector : public Affector 00185 { 00186 // --------------------------------------------------------------------------------------------------------------------------- 00187 // Public types 00188 public: 00191 typedef std::tr1::shared_ptr<FadeOutAffector> 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 FadeOutAffector(float timeRatio = 1.f); 00209 00210 virtual void Affect(Particle& particle, float 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 ColorAffector : public Affector 00231 { 00232 // --------------------------------------------------------------------------------------------------------------------------- 00233 // Public types 00234 public: 00237 typedef std::tr1::shared_ptr<ColorAffector> Ptr; 00238 00239 00240 // --------------------------------------------------------------------------------------------------------------------------- 00241 // Public static member functions 00242 public: 00245 static Ptr Create(const ColorGradient& gradient); 00246 00247 00248 // --------------------------------------------------------------------------------------------------------------------------- 00249 // Public member functions 00250 public: 00254 explicit ColorAffector(const ColorGradient& gradient); 00255 00256 virtual void Affect(Particle& particle, float dt); 00257 00260 void SetGradient(const ColorGradient& gradient); 00261 00264 const ColorGradient& GetGradient() const; 00265 00266 00267 // --------------------------------------------------------------------------------------------------------------------------- 00268 // Private variables 00269 private: 00270 ColorGradient mGradient; 00271 }; 00272 00273 00275 00276 } // namespace thor 00277 00278 #endif // THOR_AFFECTOR_HPP