include("keyFuncs.txt");
include("mtlFuncs.txt");

// Ruta de los modelos.
mesaPath = "Data/Models/mesa08.obj";
sillaPath = "Data/Models/silla06.obj";

simuladorPath = "Data/Models/simulador2.obj";

quadPath = "Data/Models/quad.obj";
blendQuadPath = "Data/Models/blendQuad.obj";
cubePath = "Data/Models/cube.obj";
spherePath = "Data/Models/sphere.obj";


// Materiales adicionales.
Material("../Models/Basic.mtl");

// Modelos.

m1 = Model(cubePath);
//m1 = Model(simuladorPath);
m2 = Model(cubePath);
//m1.setMaterial(getMaterial("Gray"));


m3 = Model(spherePath);
m3.setMaterial(getMaterial("Yellow"));
m3.castShadow(false);

l = Light();

quad = Model(quadPath);
quad.setMaterial(getMaterial("Gray"));

/*
l.setDiffuseX(0);
l.setDiffuseY(1);
l.setDiffuseZ(0);
*/

scene = Group(
			Group(rotate(0, 0, 1, 0), translate(0, 0, 0), m1),
			Group(translate(10, 0.5, 0), m2),
			Group(translate(0, 0, 1),
				Group(scale(0.1, 0.1, 0.1), m3),
				l),
			Group(translate(0, 0, -0.15), scale(0.5, 0.5, 0.5), quad)
		);

/*
// Definicion del arbol de escena inicial
scene = 
	Group(
		translate(0, -1, -0.5),
		rotate(-90, 1, 0, 0),
		Group(
			translate(0, 0, 0),
			Group(scale(0.1, 0.1, 0.1), m3),
			l
		),
		Group(
			scale(0.5, 0.5, 0.5),
			Group(translate(2, 2, -0.5), Model(cubePath)),
			Group(translate(3, 2.5, -0.5), Model(cubePath)),
			Group(translate(2.3, 2.2, 0.5), Model(cubePath))
		),
		Group(translate(0, 0, -0.5), scale(4, 4, 1), Model(quadPath)),
		Group(
			translate(-0.5, -0.5, 0),
			//rotate(180, 0, 0, 1),
			Model(sillaPath)
		),
		Group(
			translate(-0.5, -0.5, 0),
			Group(translate(1, 1, -0.125), Model(mesaPath)),
			Group(translate(0, 1, -0.05), rotate(45, 1, 0, 0), Model(mesaPath)),
			Group(translate(1, 0, -0.125), Model(mesaPath))
		)
	);
*/
		
dir = true;
def rotateTest() {
  angle = scene.get(0).get(0).getAngle();
  if (dir) scene.get(0).get(0).setAngle(angle + 1);
  else scene.get(0).get(0).setAngle(angle - 1);
}

prevDetect = false;
def detect() {
  if (collisionDetection(m1, m2)) {
    if (prevDetect == false) {
      if (dir) dir = false;
	  else dir = true;
      m2.setMaterial(cubeMtl);
	}
	prevDetect = true;
  }
  else {
    prevDetect = false;
    m2.setDefaultMaterial();
  }
}

cubeMtl = clone(getMaterial("cube"));

def main() {
  setGreenBkg(cubeMtl);  
//  Timer(10, -1, rotateTest(), rotateTest());
//  Timer(10, -1, detect(), detect());
}
