Bromeon
Particles/ParticleInterfaces.hpp
Go to the documentation of this file.
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_PARTICLEINTERFACES_HPP
00030 #define THOR_PARTICLEINTERFACES_HPP
00031 
00032 #include <Thor/SmartPtr/CopiedPtr.hpp>
00033 #include <Thor/SmartPtr/MovedPtr.hpp>
00034 #include <Thor/Geometry/Zone.hpp>
00035 #include <Thor/Config.hpp>
00036 
00037 #include <SFML/System/Time.hpp>
00038 #include <SFML/Graphics/Color.hpp>
00039 
00040 #include THOR_TR1_HEADER(memory)
00041 
00042 
00043 namespace thor
00044 {
00045 
00046 class Particle;
00047 class Zone;
00048 
00049 
00052 
00056 class THOR_API Affector
00057 {
00058     // ---------------------------------------------------------------------------------------------------------------------------
00059     // Public types
00060     public:
00063         typedef std::tr1::shared_ptr<Affector>  Ptr;
00064 
00065 
00066     // ---------------------------------------------------------------------------------------------------------------------------
00067     // Public member functions
00068     public:
00071         virtual                     ~Affector();
00072 
00076         virtual void                Affect(Particle& particle, sf::Time dt) = 0; 
00077 };
00078 
00079 
00083 class THOR_API Emitter
00084 {
00085     // ---------------------------------------------------------------------------------------------------------------------------
00086     // Public types
00087     public:
00090         typedef std::tr1::shared_ptr<Emitter>   Ptr;
00091 
00092 
00097         typedef MovedPtr<Zone, VirtualClone>    ZonePtr;
00098 
00099 
00102         struct THOR_API Adder
00103         {
00106             virtual                     ~Adder() {}
00107 
00110             virtual void                AddParticle(const Particle& particle) = 0;
00111         };
00112 
00113     
00114     // ---------------------------------------------------------------------------------------------------------------------------
00115     // Public member functions
00116     public:
00119         virtual                     ~Emitter();
00120 
00126         virtual void                Emit(Adder& system, sf::Time dt) = 0;
00127 
00130         void                        SetEmissionZone(Emitter::ZonePtr zone);
00131 
00134         Zone&                       GetEmissionZone();
00135 
00138         const Zone&                 GetEmissionZone() const;
00139 
00143         void                        SetEmissionRate(float particlesPerSecond);
00144 
00148         float                       GetEmissionRate() const;
00149 
00152         void                        SetParticleScale(sf::Vector2f scale);
00153 
00156         sf::Vector2f                GetParticleScale() const;
00157 
00160         void                        SetParticleColor(const sf::Color& color);
00161 
00164         const sf::Color&            GetParticleColor() const;
00165 
00168         void                        SetParticleLifetime(sf::Time lifetime);
00169 
00172         sf::Time                        GetParticleLifetime() const;
00173 
00174 
00175     // ---------------------------------------------------------------------------------------------------------------------------
00176     // Protected member functions
00177     protected:
00182                                     Emitter(float particlesPerSecond, sf::Time particleLifetime);
00183 
00189         unsigned int                ComputeNbParticles(sf::Time dt);
00190 
00193         Particle                    CreateParticlePrototype() const;
00194 
00195     
00196     // ---------------------------------------------------------------------------------------------------------------------------
00197     // Private variables
00198     private:
00199         CopiedPtr<Zone, VirtualClone> mEmissionZone;
00200         float                       mEmissionRate;
00201         float                       mEmissionDifference;
00202 
00203         sf::Time                    mParticleLifetime;
00204         sf::Vector2f                mParticleScale;
00205         sf::Color                   mParticleColor;
00206 };
00207 
00209 
00210 } // namespace thor
00211 
00212 #endif // THOR_PARTICLEINTERFACES_HPP