![]() |
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_EMITTER_HPP 00030 #define THOR_EMITTER_HPP 00031 00032 #include <Thor/Math/Distribution.hpp> 00033 #include <Thor/Config.hpp> 00034 00035 #include <SFML/System/Time.hpp> 00036 #include <SFML/System/Vector2.hpp> 00037 #include <SFML/Graphics/Color.hpp> 00038 00039 00040 namespace thor 00041 { 00042 00043 class EmissionInterface; 00044 00045 00048 00065 template <typename Emitter> 00066 std::function<void(EmissionInterface&, sf::Time)> refEmitter(Emitter& referenced) 00067 { 00068 return [&referenced] (EmissionInterface& system, sf::Time dt) 00069 { 00070 return referenced(system, dt); 00071 }; 00072 } 00073 00074 00080 class THOR_API UniversalEmitter 00081 { 00082 // --------------------------------------------------------------------------------------------------------------------------- 00083 // Public member functions 00084 public: 00087 UniversalEmitter(); 00088 00092 void operator() (EmissionInterface& system, sf::Time dt); 00093 00097 void setEmissionRate(float particlesPerSecond); 00098 00101 void setParticleLifetime(Distribution<sf::Time> particleLifetime); 00102 00105 void setParticlePosition(Distribution<sf::Vector2f> particlePosition); 00106 00109 void setParticleVelocity(Distribution<sf::Vector2f> particleVelocity); 00110 00113 void setParticleRotation(Distribution<float> particleRotation); 00114 00117 void setParticleRotationSpeed(Distribution<float> particleRotationSpeed); 00118 00121 void setParticleScale(Distribution<sf::Vector2f> particleScale); 00122 00125 void setParticleColor(Distribution<sf::Color> particleColor); 00126 00129 void setParticleTextureIndex(Distribution<unsigned int> particleTextureIndex); 00130 00131 00132 // --------------------------------------------------------------------------------------------------------------------------- 00133 // Private member functions 00134 private: 00135 // Returns the number of particles to emit during this frame. 00136 std::size_t computeParticleCount(sf::Time dt); 00137 00138 00139 // --------------------------------------------------------------------------------------------------------------------------- 00140 // Private variables 00141 private: 00142 float mEmissionRate; 00143 float mEmissionDifference; 00144 00145 Distribution<sf::Time> mParticleLifetime; 00146 Distribution<sf::Vector2f> mParticlePosition; 00147 Distribution<sf::Vector2f> mParticleVelocity; 00148 Distribution<float> mParticleRotation; 00149 Distribution<float> mParticleRotationSpeed; 00150 Distribution<sf::Vector2f> mParticleScale; 00151 Distribution<sf::Color> mParticleColor; 00152 Distribution<unsigned int> mParticleTextureIndex; 00153 }; 00154 00156 00157 } // namespace thor 00158 00159 #endif // THOR_EMITTER_HPP