#include "DirectionalParticle.h"

#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>

#include "MemoryManager/DebugNew.h"


using namespace ParticleSystem;

DirectionalParticle::DirectionalParticle(){
	factor = 4;
}

DirectionalParticle::~DirectionalParticle(void){
}

void DirectionalParticle::draw(){
		static float size2 = 0.5;
		size2 = size/2.0f;
		float dir2[3] = {0.0f,0.0f,0.0f};
		float newDir[3];
		newDir[0] = direction[0]/factor;
		newDir[1] = direction[1]/factor;
		newDir[2] = direction[2]/factor;
		// calcule du produit vectoriel entre le vecteur direction et le vecteur Z de la camera
		const float * camVector = ParticleEngine::getBillboardAxes();
		dir2[0] = newDir[1]*camVector[8]-newDir[2]*camVector[7];;
		dir2[1] = newDir[2]*camVector[6]-newDir[0]*camVector[8];;
		dir2[2] = newDir[0]*camVector[7]-newDir[1]*camVector[6];;

		// calcule du billboarding en fonction de la direction de la particules
		static float vertice[4][3];

		vertice[0][0]=pos[0] + (-dir2[0]*size2);
		vertice[0][1]=pos[1] + (-dir2[1]*size2);
		vertice[0][2]=pos[2] + (-dir2[2]*size2);

		vertice[1][0]=pos[0] + (+dir2[0]*size2);
		vertice[1][1]=pos[1] + (+dir2[1]*size2);
		vertice[1][2]=pos[2] + (+dir2[2]*size2);

		vertice[2][0]=pos[0] + (+newDir[0]+dir2[0]*size2);
		vertice[2][1]=pos[1] + (+newDir[1]+dir2[1]*size2);
		vertice[2][2]=pos[2] + (+newDir[2]+dir2[2]*size2);

		vertice[3][0]=pos[0] + (+newDir[0]-dir2[0]*size2);
		vertice[3][1]=pos[1] + (+newDir[1]-dir2[1]*size2);
		vertice[3][2]=pos[2] + (+newDir[2]-dir2[2]*size2);

		glColor4fv(couleur);
		glTexCoord2f(0.0f,0.0f);glVertex3fv(vertice[0]); 
		glTexCoord2f(1.0f,0.0f);glVertex3fv(vertice[1]);
		glTexCoord2f(1.0f,1.0f);glVertex3fv(vertice[2]); 
		glTexCoord2f(0.0f,1.0f);glVertex3fv(vertice[3]); 

}

