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

// Ruta del modelo.
cubePath = "Data/Models/cube.obj";
spherePath = "Data/Models/sphere.obj";


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

// Modelos.
m1 = Model(cubePath);
m2 = Model(cubePath);

m1.setMaterial(getMaterial("Gray"));

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

l = Light();
/*l.setAmbientX(0);
l.setAmbientY(1);
l.setAmbientZ(0);
*/
l.setDiffuseX(0);
l.setDiffuseY(1);
l.setDiffuseZ(0);


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

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());
}
