// Esta escena es una prueba para estereoscopia estereocopia.

// Ruta de los modelos.
cubePath = "Data/Models/cube.obj";

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

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

// Scene tree spec.
scene = Group(
			Group(rotate(0, 0, 1, 0), translate(0, 0, 0), m1),
			Group(translate(1, 0.5, 0.5), m2),
			Group(translate(1, 1, 2), l)
		);

// 
cameraActive = 1;
c1 = Camera();
c2 = Camera();

angleInitial = -0.075; posX = 2;
c1.setPos(posX +angleInitial, 1, 4);
c2.setPos(posX - angleInitial, 1, 4);
c1.setView(0, 0, -10);
c2.setView(0, 0, -10);

cubeCyan = clone(getMaterial("cube"));
cubeRed = clone(getMaterial("cube"));

setRedBkg(cubeRed);  
setCyanBkg(cubeCyan);  

def changeCamera() {
  if (cameraActive == 1) {
    c2.setActive();
	cameraActive = 2;
	m1.setMaterial(cubeCyan);
	m2.setMaterial(cubeCyan);
  }
  else {
    c1.setActive();
    cameraActive = 1;
	m1.setMaterial(cubeRed);
	m2.setMaterial(cubeRed);
  }
}


def AddAngleCam() {
  angleInitial += 0.01;
  c1.setPos(posX + angleInitial, 1, 4);
  c2.setPos(posX - angleInitial, 1, 4);
}
def SubAngleCam() {
  angleInitial -= 0.01;
  c1.setPos(posX + angleInitial, 1, 4);
  c2.setPos(posX - angleInitial, 1, 4);
}

def rotateTest() {
  angle = scene.get(0).get(0).getAngle();
  scene.get(0).get(0).setAngle(angle + 1);
}

def setRedBkg(mtl) {
  mtl.setDiffuseX(1);
  mtl.setDiffuseY(0);
  mtl.setDiffuseZ(0);
  mtl.setAmbientX(1);
  mtl.setAmbientY(0);
  mtl.setAmbientZ(0);
}

def setCyanBkg(mtl) {
  mtl.setDiffuseX(0);
  mtl.setDiffuseY(1);
  mtl.setDiffuseZ(1);
  mtl.setAmbientX(0);
  mtl.setAmbientY(1);
  mtl.setAmbientZ(1);
}

setKeyFunc("E", SubAngleCam());
setKeyFunc("R", AddAngleCam());

def main() {
  Timer(10, -1, rotateTest(), rotateTest());
  Timer(10, -1, changeCamera(), changeCamera());
}
