#ifndef SPINPARTICLEAFFECTOR_H_INCLUDED
#define SPINPARTICLEAFFECTOR_H_INCLUDED


class CParticleSpinAffector : public IParticleAffector
{
public:
   //!
   CParticleSpinAffector(const f32 speed)
      : speed(speed)
   {
   }

   //! Affects an array of particles.
   virtual void affect(u32 now, SParticle* particlearray, u32 count)
   {

        if( LastTime == 0 )
        {
            LastTime = now;
            return;
        }

        f32 timeDelta = ( now - LastTime ) / 1000.0f;
        LastTime = now;

        if( Enabled )
        {
            u32 p;
            for (p = 0; p < count; ++p)
            {
                SParticle& particle = particlearray[p];
                particle.rotation += (timeDelta * particle.rotation_speed) ;

                if (particle.rotation >=360)
                    particle.rotation-=360;
                if (particle.rotation <0)
                    particle.rotation-=360;
            }
        }
//         particle.rotation.rotateXZBy(speed,particle.pos);
//         particle.rotation.rotateYZBy(speed,particle.pos);

   }


    E_PARTICLE_AFFECTOR_TYPE getType() const { return EPAT_NONE; }



    void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options)
    {
        out->addFloat("speed", speed);
    }

    s32 deserializeAttributes(s32 startIndex, io::IAttributes* in, io::SAttributeReadWriteOptions* options)
    {

        const char* name = in->getAttributeName(startIndex);
        if (!name || strcmp(name, "speed"))
            return startIndex; // attribute not valid
        speed = in->getAttributeAsFloat(startIndex);

        ++startIndex;

        return startIndex;
    }

private:
   f32 speed;
   u32 LastTime;
};


#endif // SPINPARTICLEAFFECTOR_H_INCLUDED
