#include "DustGenerator.h"
#include "DustParticle.h"
#include "Renderer.h"
#include "RenderableEntity.h"

#include "MemoryManager/debugNew.h"

using namespace ParticleSystem;
using namespace RenderSystem;
DustGenerator::DustGenerator(RenderSystem::RenderableEntity * entity){
	this->entity = entity;
	maxGeneration = 1;
	this->generationDelay = 0.3f;
	this->previousTime = 0.0f;
	loop = true;
}

DustGenerator::~DustGenerator(void)
{
}

void DustGenerator::generate(ParticleEngine::Particle * particle){
	DustParticle * part = static_cast<DustParticle*>(particle);
	if (canGenerate()&&allowGeneration){
		Point2D& p = entity->getRenderableEntityPosition();
		part->beginSize = fabs(cos((float)rand()))*2+1;
		part->endSize = fabs(cos((float)rand()))*3+3;
		part->pos[0] = (p.getX()+0.5) * CASE_SIDE_SIZE;
		part->pos[1] = Renderer::getInstance().getElevation(p) + part->beginSize*0.75;
		part->pos[2] = (p.getY()+0.5) * CASE_SIDE_SIZE;
		part->direction[0] = 0;
		part->direction[1] = fabs(cos((float)rand()));
		part->direction[2] = 0;
		part->life = 0;
		part->maxLife = 2.0f;
		part->beginCouleur[0] = 2.0f;
		part->beginCouleur[1] = 2.0f;
		part->beginCouleur[2] = 2.0f;
		part->beginCouleur[3] = 0.5f;
		part->endCouleur[0] = 0.0f;
		part->endCouleur[1] = 0.0f;
		part->endCouleur[2] = 0.0f;
		part->endCouleur[3] = 0.5f;
		part->masse = 5.0f;
		generation++;
	}
}

void DustGenerator::allowDust(bool allow){
	allowGeneration = allow;
}

