#include "Input.h"


Input::Input() 
{
  exit_status = false;
	trace_depth = 1;
	shadows = false;
  tree_level_visible = 0;
  rayPos.set(-5,5,-5);
  rayRot.set(0,0,0);
  drawAllGrid = false;
  //cam_rot.set(20,0,0,1);
}


void Input::Mouse(int button, int state, int x, int y) //Обработка щелчков мыши
{
	if (button==GLUT_LEFT_BUTTON)		//Левая кнопка
	{
		switch (state)
		{
			case GLUT_DOWN:		//Если нажата
				ldown=true;		//установить флаг
				mx=x;			//Запомнить координаты
				my=y;
				break;
			case GLUT_UP:
				ldown=false;
				break;
		}
	}
	if (button==GLUT_RIGHT_BUTTON)	//Правая кнопка
	{
		switch (state)
		{
			case GLUT_DOWN:
				rdown=true;
				mx=x;
				my=y;
				break;
			case GLUT_UP:
				rdown=false;
				break;
		}
	}
}

void Input::MouseMotion(int x, int y)                  //Перемешение мыши
{
    if(ldown)		// Левая кнопка
	{
		cam_rot.M[0]+=0.1*(y-my);	//Изменение угола поворота
		cam_rot.M[1]+=0.1*(x-mx);
		mx=x;
		my=y;
	}
	if (rdown)	//Правая
	{
//		global_translate.M[0]+=0.01*(x-mx);	//Перемещение вдоль активной плоскости
//		if (tt)
//			global_translate.M[2]+=0.01*(y-my);
//		else
//			global_translate.M[1]+=0.01*(my-y);
		mx=x;
		my=y;
	}
}


void Input::Keyboard(unsigned char key, int x, int y)
{

	switch(key)
	{
	case VK_ESCAPE:
		exit_status = true;
	break;
	
	case 'q':
	case 'Q':
		cam_rot.z -= 10;
	break;
		
	case 'e':
	case 'E':
		cam_rot.z += 10;
	break;

	case 'w':
	case 'W':
		cam_mov.z = -0.1;
	break;
	
	case 's':
	case 'S':
		cam_mov.z = 0.1;
	break;

	case 'a':
	case 'A':
		cam_mov.x = -0.1;
	break;

	case 'd':
	case 'D':
		cam_mov.x = 0.1;
	break;

	case 'r':
	case 'R':
		cam_mov.y = 0.1;
	break;

	case 'f':
	case 'F':
		cam_mov.y = -0.1;
	break;


	case '1':
		trace_depth=1;
	break;

	case '2':
		trace_depth=2;
	break;

	case '3':
		trace_depth=3;
	break;

	case '4':
		trace_depth=4;
	break;

	case '5':
		trace_depth=5;
	break;

  case '6':
		trace_depth=6;
	break;

  case '7':
		trace_depth=7;
	break;

  case '8':
		trace_depth=8;
	break;

  case '9':
		trace_depth=9;
	break;

	case 'Z':
	case 'z':
		shadows=!shadows;
	break;

  case 'U':
	case 'u':
		tree_level_visible++;
	break;


  //case 'J':
	//case 'j':
	//	tree_level_visible--;
	//break;


  case 'P':
  case 'p':
    printPerfInfo = true;
    break;


  case 'G':
	case 'g':
		rayPos.x -= 0.1f;
	break;

  case 'H':
	case 'h':
		rayPos.x += 0.1f;
	break;

  case 'V':
	case 'v':
		rayPos.y += 0.1f;
	break;

  case 'B':
	case 'b':
		rayPos.y -= 0.1f;
	break;


  case 'J':
	case 'j':
		rayPos.z += 0.1f;
	break;

  case 'K':
	case 'k':
		rayPos.z -= 0.1f;
	break;

  case 'N':
	case 'n':
		rayRot.x += 5;
	break;

  case 'M':
	case 'm':
		rayRot.x -= 5;
	break;
  
  case '<':
	case ',':
		rayRot.y += 5;
	break;

  case '>':
	case '.':
		rayRot.y -= 5;
	break;

  case 'I':
  case 'i':
    drawAllGrid = !drawAllGrid;
  break;

	}

}

void Input::KeyboardSpecial(int key, int x, int y)
{

}