Bromeon
Particles/ParticleInterfaces.hpp
Go to the documentation of this file.
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_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/Graphics/Color.hpp>
00038 
00039 #include THOR_TR1_HEADER(memory)
00040 
00041 
00042 namespace thor
00043 {
00044 
00045 class Particle;
00046 class Zone;
00047 
00048 
00051 
00055 class THOR_API Affector
00056 {
00057     // ---------------------------------------------------------------------------------------------------------------------------
00058     // Public types
00059     public:
00062         typedef std::tr1::shared_ptr<Affector>  Ptr;
00063 
00064 
00065     // ---------------------------------------------------------------------------------------------------------------------------
00066     // Public member functions
00067     public:
00070         virtual                     ~Affector();
00071 
00075         virtual void                Affect(Particle& particle, float dt) = 0; 
00076 };
00077 
00078 
00082 class THOR_API Emitter
00083 {
00084     // ---------------------------------------------------------------------------------------------------------------------------
00085     // Public types
00086     public:
00089         typedef std::tr1::shared_ptr<Emitter>   Ptr;
00090 
00093         struct THOR_API Adder
00094         {
00097             virtual                     ~Adder() {}
00098 
00101             virtual void                AddParticle(const Particle& particle) = 0;
00102         };
00103 
00104     
00105     // ---------------------------------------------------------------------------------------------------------------------------
00106     // Public member functions
00107     public:
00110         virtual                     ~Emitter();
00111 
00117         virtual void                Emit(Adder& system, float dt) = 0;
00118 
00121         void                        SetEmissionZone(MovedPtr<Zone> zone);
00122 
00125         Zone&                       GetEmissionZone();
00126 
00129         const Zone&                 GetEmissionZone() const;
00130 
00134         void                        SetEmissionRate(float particlesPerSecond);
00135 
00139         float                       GetEmissionRate() const;
00140 
00143         void                        SetParticleScale(sf::Vector2f scale);
00144 
00147         sf::Vector2f                GetParticleScale() const;
00148 
00151         void                        SetParticleColor(const sf::Color& color);
00152 
00155         const sf::Color&            GetParticleColor() const;
00156 
00159         void                        SetParticleLifetime(float lifetime);
00160 
00163         float                       GetParticleLifetime() const;
00164 
00165 
00166     // ---------------------------------------------------------------------------------------------------------------------------
00167     // Protected member functions
00168     protected:
00173                                     Emitter(float particlesPerSecond, float particleLifetime);
00174 
00180         unsigned int                ComputeNbParticles(float dt);
00181 
00184         Particle                    CreateParticlePrototype() const;
00185 
00186     
00187     // ---------------------------------------------------------------------------------------------------------------------------
00188     // Private variables
00189     private:
00190         CopiedPtr<Zone, VirtualClone> mEmissionZone;
00191         float                       mEmissionRate;
00192         float                       mEmissionDifference;
00193 
00194         float                       mParticleLifetime;
00195         sf::Vector2f                mParticleScale;
00196         sf::Color                   mParticleColor;
00197 };
00198 
00200 
00201 } // namespace thor
00202 
00203 #endif // THOR_PARTICLEINTERFACES_HPP