// __autor__ = Juan Carlos De Abreu R.
// __date__ = 03/13/2008
// __version__ = 1.0
//
// This file provide some utilities functions.
//

// Function to create a grid of quads.
//   geometry : <Geometry> to create instances for the grid.
//   nRow : <int> number of rows of geometries to create.
//   nCol : <int> number of cols of geometries to create.
//   geometryList : <List> to store all the geometries that will be created.
//   node : <GroupNode> To store the Final SceneNode.
def createGrid(geometry, nRow, nCol, geometryList, node) {
  // Create all the instaces of the geometry.
  for (i = 0; i < nRow; ++i) {
    for (j = 0; j < nCol; ++j) {
	  newGeometry = clone(geometry);
	  geometryList.add(newGeometry);
      node.add( Group(
				  translate(i, 0, j),
				  rotate(-90, 1, 0, 0),
				  scale(0.95, 0.95, 0.95),
				  newGeometry
				) );
	}
  }
}

// Function to check collision detection between one geometry and a geometry
// list. If exist a collision the function return the index in the geometryList
// otherwise return -1.
def collision(geometry, geometryList) {
  nGeometries = geometryList.size();
  for (i = 0; i < nGeometries; ++i) {
    geometryi = geometryList.get(i);
    if (collisionDetection(geometry, geometryi)) return i;
  }
  return -1;
}
