// __autor__ = Juan Carlos De Abreu R.
// __date__ = 03/13/2008
// __version__ = 1.0
//
// This file provide some functions to build the instruments
// and to manipulate it for the exercise "aros".
//

// NOTE: este archivo es el mismo para TouchColors.

include("Util.snf");

// Path for the each part of the instrument.
bodyInstrumentPath = "../Models/pinza2.obj";
headInstrumentPath = "../Models/diente2.obj";

// Load each geometry part of the instrument.
bodyInstrumentGeometry = Model(bodyInstrumentPath);
leftHeadInstrumentGeometry = Model(headInstrumentPath);
rightHeadInstrumentGeometry = Model(headInstrumentPath);

// Function to create the instrument SceneNode.
instrumentNode = Group(
					translate(0, 2, 0),
					rotate(100, 1, 0, 0),
					rotate(-30, 0, 1, 0),
					rotate(180, 0, 0, 1),
					scale(2, 2, 2),
					Group(
					  translate(0.013, 0, 0),
					  rightHeadInstrumentGeometry
					),
					Group(
					  translate(-0.013, 0, 0),
					  rotate(180, 0, 0, 1),
					  leftHeadInstrumentGeometry
					),
					Group(
					  translate(0, 0, -5.8),
					  scale(11,11,11),
					  bodyInstrumentGeometry
					)
				);

// Actual instrument position and orientation.
instrumentPosition = (0, 2, 0);
instrumentOrientation = (100, -30, 180);
moveStep = 0.1;

// Function to update the instrument position and orientation.
def updateInstrument() {
  setXYZ(instrumentNode.get(0), instrumentPosition);
  instrumentNode.get(1).setAngle(instrumentOrientation.get(0));
  instrumentNode.get(2).setAngle(instrumentOrientation.get(1));
  instrumentNode.get(3).setAngle(instrumentOrientation.get(2));
}

// Set the keys for move the instrument.
setKeyFunc("I", moveInstrumentUp());
setKeyFunc("K", moveInstrumentDown());
setKeyFunc("J", moveInstrumentLeft());
setKeyFunc("L", moveInstrumentRight());
setKeyFunc("U", moveInstrumentFordward());
setKeyFunc("O", moveInstrumentBackward());

def moveInstrumentLeft() {
  instrumentPosition.set(0, instrumentPosition.get(0) - moveStep);
  updateInstrument();
}

def moveInstrumentRight() {
  instrumentPosition.set(0, instrumentPosition.get(0) + moveStep);
  updateInstrument();
}

def moveInstrumentFordward() {
  instrumentPosition.set(1, instrumentPosition.get(1) - moveStep);
  updateInstrument();
}

def moveInstrumentBackward() {
  instrumentPosition.set(1, instrumentPosition.get(1) + moveStep);
  updateInstrument();
}

def moveInstrumentUp() {
  instrumentPosition.set(2, instrumentPosition.get(2) - moveStep);
  updateInstrument();
}

def moveInstrumentDown() {
  instrumentPosition.set(2, instrumentPosition.get(2) + moveStep);
  updateInstrument();
}
