// Copyright (C) 2002-2007 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#include "IrrCompileConfig.h"
#include "CParticleRotationAffector.h"
#include "matrix4.h"
#include "os.h"

namespace irr
{
namespace scene
{

//! constructor
CParticleRotationAffector::CParticleRotationAffector( f32 speedX, f32 speedY, f32 speedZ,
	core::vector3df pivotPoint )
: PivotPoint( pivotPoint )
, SpeedX( speedX )
, SpeedY( speedY )
, SpeedZ( speedZ )
, LastTime( 0 )
{
}


//! Affects an array of particles.
void CParticleRotationAffector::affect(u32 now, SParticle* particlearray, u32 count)
{
	if( LastTime == 0 )
	{
		LastTime = now;
		return;
	}

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

	if( Enabled )
	{

//	    printf("dumm affector\n");
		for(u32 i=0; i<count; ++i)
		{
			//core::vector3df temp;

			//temp = particlearray[i].pos;
			//temp -= PivotPoint;
			//core::matrix4 rotMat;
			//rotMat.setRotationDegrees( core::vector3df( SpeedX * timeDelta, SpeedY * timeDelta, SpeedZ * timeDelta ) );
			//rotMat.rotateVect( temp );
			//temp += PivotPoint;
			//particlearray[i].pos = temp;

			if( SpeedX )
				particlearray[i].pos.rotateYZBy( timeDelta * SpeedX, PivotPoint );

			if( SpeedY )
				particlearray[i].pos.rotateXZBy( timeDelta * SpeedY, PivotPoint );

			if( SpeedZ )
				particlearray[i].pos.rotateXYBy( timeDelta * SpeedZ, PivotPoint );
		}
	}
}


} // end namespace scene
} // end namespace irr

