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

#include "globale.h"
#include "CVector3.h"
#include "CCamera.h"
#include "Temps.h"

void BougeSouris(int x, int y)
{
	float AngleHor, AngleVert;

	if ( (x != CENTRE_X) || (y != CENTRE_Y) )
	{
		AngleHor  = (CENTRE_X - x) / 1000.0f;
		AngleVert = (CENTRE_Y - y) / 1000.0f;

		glutWarpPointer(CENTRE_X, CENTRE_Y);

		CVector3 AxeHor;
		AxeHor = (gCamera.Observation - gCamera.Position) ^ gCamera.Haut;
		AxeHor.Normalize();

		gCamera.TournePosition(AngleVert, AxeHor);
		gCamera.TournePosition(AngleHor, gCamera.Haut);

		if (gCamera.EstAvance)
			gCamera.Avance(SPEEDCAM);
		if (gCamera.EstRecule)
			gCamera.Avance(-SPEEDCAM);
	}
	else if (gCamera.EstAvance || gCamera.EstRecule)
	{
		if (gCamera.EstAvance)
			gCamera.Avance(SPEEDCAM);
		if (gCamera.EstRecule)
			gCamera.Avance(-SPEEDCAM);

	}

	(*gCamera.DisplayFunc)();
}

void CliqueSouris(int button, int state, int x, int y)
{
	switch (button)
	{
	case GLUT_LEFT_BUTTON:
		if (state == GLUT_DOWN)
		{
			gCamera.EstAvance = true;
			gCamera.TempsLastFrame = GetTemps();
		}
		else
			gCamera.EstAvance = false;
		break;

	case GLUT_RIGHT_BUTTON:
		if (state == GLUT_DOWN)
		{
			gCamera.EstRecule = true;
			gCamera.TempsLastFrame = GetTemps();
		}
		else
			gCamera.EstRecule = false;
		break;
	}
}
