#ifndef CPARTICLESCALEAFFECTOR_H_INCLUDED
#define CPARTICLESCALEAFFECTOR_H_INCLUDED


#include <IParticleAffector.h>



namespace irr
{
    namespace scene
    {
        class CParticleScaleAffector : public IParticleAffector
        {
        public:
            CParticleScaleAffector(f32 scaleTo)
            {
                //ctor
                m_scaleTo = scaleTo;
            }

            virtual ~CParticleScaleAffector() {};
            virtual void  affect (u32 now, SParticle *particlearray, u32 count)
            {
                for(u32 i=0;i<count;i++)
                {
                    u32 maxdiff = particlearray[i].endTime - particlearray[i].startTime;
                    u32 curdiff = now - particlearray[i].startTime;
                    irr::f32 newscale = (irr::f32)curdiff/maxdiff;
                    particlearray[i].scale = 1.0f+newscale*m_scaleTo;
                }

            }

            //! Writes attributes of the object.
            //! Implement this to expose the attributes of your scene node animator for
            //! scripting languages, editors, debuggers or xml serialization purposes.
            virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options)
            {
                out->addFloat("ScaleTo", m_scaleTo);
            }


            //! Reads attributes of the object.
            //! Implement this to set the attributes of your scene node animator for
            //! scripting languages, editors, debuggers or xml deserialization purposes.
            //! \param startIndex: start index where to start reading attributes.
            //! \return: returns last index of an attribute read by this affector
            virtual s32 deserializeAttributes(s32 startIndex, io::IAttributes* in, io::SAttributeReadWriteOptions* options)
            {
                const char* name = in->getAttributeName(startIndex);
                if (!name || strcmp(name, "ScaleTo"))
                    return startIndex; // attribute not valid
                m_scaleTo = in->getAttributeAsFloat(startIndex);
                ++startIndex;
                return startIndex;

            }

            //! Get emitter type
            virtual E_PARTICLE_AFFECTOR_TYPE getType() const { return EPAT_NONE; };

        protected:

            f32 m_scaleTo;

        private:

        };


    }
}

#endif // CPARTICLESCALEAFFECTOR_H_INCLUDED
