
#include "Tscene.h"


void Tscene::keyDown(OKeyboard& keyboard)
{
    if (keyboard.getKeyDown(ECOK_escape))
    {
        m_running = false;
        return;
    }
    /*
    if (keyboard.getKeyDown(ECOK_f1))
    {
        keyboard.clear(); // evite la répétition des touches
        return;
    }
    */

    // ---

    bool camera_on = false;

	//avance recule
	if (keyboard.getKeyDown(ECOK_n8))
	{
		camera.move_front();
		camera_on = true;
	}
	if (keyboard.getKeyDown(ECOK_n2))
	{
		camera.move_back();
		camera_on = true;
	}
	//déplacement gauche droite
	if (keyboard.getKeyDown(ECOK_n4))
	{
		camera.move_side_left();
		camera_on = true;
	}
	if (keyboard.getKeyDown(ECOK_n6))
	{
		camera.move_side_right();
		camera_on = true;
	}
	//tourne (la tete) gauche droite
	if (keyboard.getKeyDown(ECOK_n7))
	{
		camera.move_left();
		camera_on = true;
	}
	if (keyboard.getKeyDown(ECOK_n9))
	{
		camera.move_right();
		camera_on = true;
	}
	//monte descend (repère vertical z)
	if (keyboard.getKeyDown(ECOK_nAdd))
	{
		camera.move_up();
		camera_on = true;
	}
	if (keyboard.getKeyDown(ECOK_nSub))
	{
		camera.move_down();
		camera_on = true;
	}
	// inclinaison (de la tête) avant->bas arrière->haut
	if (keyboard.getKeyDown(ECOK_nDiv))
	{
		camera.move_head_down();
		camera_on = true;
	}
	if (keyboard.getKeyDown(ECOK_nMul))
	{
		camera.move_head_up();
		camera_on = true;
	}
	//inclinaison (de la tête) gauche droite
	if (keyboard.getKeyDown(ECOK_n1))
	{
		camera.move_head_left();
		camera_on = true;
	}
	if (keyboard.getKeyDown(ECOK_n3))
	{
		camera.move_head_right();
		camera_on = true;
	}
	//raz
	if (keyboard.getKeyDown(ECOK_n5))
	{
		camera.setPos(65,-70,4);
		camera.setRot(0,0,128);
	}
	if (camera_on)
    {
        std::string str;

        str = "pos : x " + ECO_floatToStr(camera.getPosX(), "###,#") + " y " + ECO_floatToStr(camera.getPosY(), "###,#") + " z " + ECO_floatToStr(camera.getPosZ(), "###,#") + " / ";
        str = str + "ang h " + ECO_floatToStr(camera.getAngleH(), "###,#") + " v " + ECO_floatToStr(camera.getAngleV(), "##,#");
        lblInfo0.setText(str);

        ECO_mouse_set(IDC_ARROW);
        // note : tant que le curseur est dans la zone de detection => il reste hand

        // quand on bouge la camera
        if (ECO_distanceVF(camera.getPos(), gl_pos_ile_so) < gl_dist_camera_isle)
        {
            m_mode_interface = ISLE_SO;
        }
        else if (ECO_distanceVF(camera.getPos(), gl_pos_ile_se) < gl_dist_camera_isle)
        {
            m_mode_interface = ISLE_SE;
        }
        else if (ECO_distanceVF(camera.getPos(), gl_pos_ile_ne) < gl_dist_camera_isle)
        {
            m_mode_interface = ISLE_NE;
        }
        else
        {
            m_mode_interface = ISLE_NO; // vide
        }
    }
}



void Tscene::mouseDownL(int x, int y)
{
    if (interface_mouseDownL(x,y)) return;
    // rien d'autre
    pick_ray(x,y);
}

void Tscene::mouseMove(int x, int y)
{
    if (interface_mouseMove(x,y)) return;

    // il faudrait bloquer quand on survole une partie de l'interface
    pick_ray_move(x,y);
}

void Tscene::mouseWheel(int delta)
{
    if (interface_mouseWheel(delta)) return;

    // modif vitesse camera
    float speed = camera.getSpeed();
    float speedRot = camera.getSpeedRot();
    if (delta > 0)
    {
        if (speed < 4.0f)
        {
            speed += 0.25f;
            speedRot = 1.0f / speed;
        }
        camera.setSpeed(speed);
        camera.setCoefRot(speedRot);
        lblInfo1.setText( "camera speed : " + ECO_floatToStr(speed) );
    }
    else if (delta < 0)
    {
        if (speed > 0.25f)
        {
            speed -= 0.25f;
            speedRot = 1.0f / speed;
        }
        camera.setSpeed(speed);
        camera.setCoefRot(speedRot);
        lblInfo1.setText( "camera speed : " + ECO_floatToStr(speed) );
    }
}



