#include <cmath>
#include <GL/glut.h>

#include "globale.h"
#include "CCube.h"




// Dessin du cube

void CCube::Draw(void) const
{
	if (Sens)
	{
		// Plan y-0.5f
		glBegin(GL_QUADS);
			glColor3f(r1, g1, b1);
			glVertex3f(x-0.5f, y-0.5f, z-0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x+0.5f, y-0.5f, z-0.5f);
			glColor3f(r1, g1, b1);
			glVertex3f(x+0.5f, y-0.5f, z+0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x-0.5f, y-0.5f, z+0.5f);
		glEnd();

		// Plan y+0.5f
		glBegin(GL_QUADS);
			glColor3f(r1, g1, b1);
			glVertex3f(x+0.5f, y+0.5f, z-0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x-0.5f, y+0.5f, z-0.5f);
			glColor3f(r1, g1, b1);
			glVertex3f(x-0.5f, y+0.5f, z+0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x+0.5f, y+0.5f, z+0.5f);
		glEnd();

		// Plan x-0.5f
		glBegin(GL_QUADS);
			glColor3f(r1, g1, b1);
			glVertex3f(x-0.5f, y-0.5f, z-0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x-0.5f, y+0.5f, z-0.5f);
			glColor3f(r1, g1, b1);
			glVertex3f(x-0.5f, y+0.5f, z+0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x-0.5f, y-0.5f, z+0.5f);
		glEnd();

		// Plan x+0.5f
		glBegin(GL_QUADS);
			glColor3f(r1, g1, b1);
			glVertex3f(x+0.5f, y+0.5f, z-0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x+0.5f, y+0.5f, z+0.5f);
			glColor3f(r1, g1, b1);
			glVertex3f(x+0.5f, y-0.5f, z+0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x+0.5f, y-0.5f, z-0.5f);
		glEnd();

		// Plan z-0.5f
		glBegin(GL_QUADS);
			glColor3f(r1, g1, b1);
			glVertex3f(x-0.5f, y-0.5f, z-0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x-0.5f, y+0.5f, z-0.5f);
			glColor3f(r1, g1, b1);
			glVertex3f(x+0.5f, y+0.5f, z-0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x+0.5f, y-0.5f, z-0.5f);
		glEnd();

		// Plan z+0.5f
		glBegin(GL_QUADS);
			glColor3f(r1, g1, b1);
			glVertex3f(x-0.5f, y+0.5f, z+0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x+0.5f, y+0.5f, z+0.5f);
			glColor3f(r1, g1, b1);
			glVertex3f(x+0.5f, y-0.5f, z+0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x-0.5f, y-0.5f, z+0.5f);
		glEnd();
	}
	else
	{		
		// Plan y-0.5f
		glBegin(GL_QUADS);
			glColor3f(r1, g1, b1);
			glVertex3f(x+0.5f, y-0.5f, z-0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x+0.5f, y-0.5f, z+0.5f);
			glColor3f(r1, g1, b1);
			glVertex3f(x-0.5f, y-0.5f, z+0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x-0.5f, y-0.5f, z-0.5f);
		glEnd();

		// Plan y+0.5f
		glBegin(GL_QUADS);
			glColor3f(r1, g1, b1);
			glVertex3f(x-0.5f, y+0.5f, z-0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x-0.5f, y+0.5f, z+0.5f);
			glColor3f(r1, g1, b1);
			glVertex3f(x+0.5f, y+0.5f, z+0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x+0.5f, y+0.5f, z-0.5f);
		glEnd();

		// Plan x-0.5f
		glBegin(GL_QUADS);
			glColor3f(r1, g1, b1);
			glVertex3f(x-0.5f, y+0.5f, z-0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x-0.5f, y+0.5f, z+0.5f);
			glColor3f(r1, g1, b1);
			glVertex3f(x-0.5f, y-0.5f, z+0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x-0.5f, y-0.5f, z-0.5f);
		glEnd();

		// Plan x+0.5f
		glBegin(GL_QUADS);
			glColor3f(r1, g1, b1);
			glVertex3f(x+0.5f, y+0.5f, z+0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x+0.5f, y-0.5f, z+0.5f);
			glColor3f(r1, g1, b1);
			glVertex3f(x+0.5f, y-0.5f, z-0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x+0.5f, y+0.5f, z-0.5f);
		glEnd();

		// Plan z-0.5f
		glBegin(GL_QUADS);
			glColor3f(r1, g1, b1);
			glVertex3f(x-0.5f, y+0.5f, z-0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x+0.5f, y+0.5f, z-0.5f);
			glColor3f(r1, g1, b1);
			glVertex3f(x+0.5f, y-0.5f, z-0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x-0.5f, y-0.5f, z-0.5f);
		glEnd();

		// Plan z+0.5f
		glBegin(GL_QUADS);
			glColor3f(r1, g1, b1);
			glVertex3f(x+0.5f, y+0.5f, z+0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x+0.5f, y-0.5f, z+0.5f);
			glColor3f(r1, g1, b1);
			glVertex3f(x-0.5f, y-0.5f, z+0.5f);
			glColor3f(r2, g2, b2);
			glVertex3f(x-0.5f, y+0.5f, z+0.5f);
		glEnd();
	}
}




// Fonction qui sert à dessiner le guide
void CCube::DrawGuide(void) const
{
	glColor3f(0, 0, 0);

	// Plan y-0.5f
	glBegin(GL_LINE_LOOP);
		glVertex3f(x-0.5f, y-0.5f, z-0.5f);
		glVertex3f(x+0.5f, y-0.5f, z-0.5f);
		glVertex3f(x+0.5f, y-0.5f, z+0.5f);
		glVertex3f(x-0.5f, y-0.5f, z+0.5f);
	glEnd();

	// Plan y+0.5f
	glBegin(GL_LINE_LOOP);
		glVertex3f(x+0.5f, y+0.5f, z-0.5f);
		glVertex3f(x-0.5f, y+0.5f, z-0.5f);
		glVertex3f(x-0.5f, y+0.5f, z+0.5f);
		glVertex3f(x+0.5f, y+0.5f, z+0.5f);
	glEnd();

	// Plan x-0.5f
	glBegin(GL_LINE_LOOP);
		glVertex3f(x-0.5f, y-0.5f, z-0.5f);
		glVertex3f(x-0.5f, y+0.5f, z-0.5f);
		glVertex3f(x-0.5f, y+0.5f, z+0.5f);
		glVertex3f(x-0.5f, y-0.5f, z+0.5f);
	glEnd();

	// Plan x+0.5f
	glBegin(GL_LINE_LOOP);
		glVertex3f(x+0.5f, y+0.5f, z-0.5f);
		glVertex3f(x+0.5f, y+0.5f, z+0.5f);
		glVertex3f(x+0.5f, y-0.5f, z+0.5f);
		glVertex3f(x+0.5f, y-0.5f, z-0.5f);
	glEnd();

	// Plan z-0.5f
	glBegin(GL_LINE_LOOP);
		glVertex3f(x-0.5f, y-0.5f, z-0.5f);
		glVertex3f(x-0.5f, y+0.5f, z-0.5f);
		glVertex3f(x+0.5f, y+0.5f, z-0.5f);
		glVertex3f(x+0.5f, y-0.5f, z-0.5f);
	glEnd();

	// Plan z+0.5f
	glBegin(GL_LINE_LOOP);
		glVertex3f(x-0.5f, y+0.5f, z+0.5f);
		glVertex3f(x+0.5f, y+0.5f, z+0.5f);
		glVertex3f(x+0.5f, y-0.5f, z+0.5f);
		glVertex3f(x-0.5f, y-0.5f, z+0.5f);
	glEnd();
}
