Beispiel #1
0
void Node::_link(unsigned int direction, Action* action) {
  // We ensure the texture is properly stretched, so we take the default
  // cube size.
  // TODO: This setting should be obtained directly from the Config class
  int minorBound = kDefTexSize / 3;
  int majorBound = static_cast<int>(kDefTexSize / 1.5f);
  int offset = kDefTexSize / 3;
  
  // We always have four corners here, hence eight elements since they are
  // squared spots.
  
  std::vector<int> arrayOfCoordinates;
  int coordsNormal[] = {minorBound, minorBound, majorBound, minorBound,
    majorBound, majorBound, minorBound, majorBound};
  int coordsShiftRight[] = {minorBound + offset, minorBound,
    majorBound + offset, minorBound, majorBound + offset, majorBound,
    minorBound + offset, majorBound};
  int coordsShiftLeft[] = {minorBound - offset, minorBound, majorBound - offset,
    minorBound, majorBound - offset, majorBound, minorBound - offset,
    majorBound};
  
  Spot *newSpot = NULL, *auxSpot = NULL;
  
  switch (direction) {
    case kNorth:
    case kEast:
    case kSouth:
    case kWest: {
      arrayOfCoordinates.assign(coordsNormal, coordsNormal + 8);
      newSpot = new Spot(arrayOfCoordinates, direction, kSpotClass);
      break;
    }
    case kNorthEast: {
      arrayOfCoordinates.assign(coordsShiftRight, coordsShiftRight + 8);
      newSpot = new Spot(arrayOfCoordinates, kNorth, kSpotClass);
      arrayOfCoordinates.assign(coordsShiftLeft, coordsShiftLeft + 8);
      auxSpot = new Spot(arrayOfCoordinates, kEast, kSpotClass);
      break;
    }
    case kSouthEast: {
      arrayOfCoordinates.assign(coordsShiftRight, coordsShiftRight + 8);
      newSpot = new Spot(arrayOfCoordinates, kEast, kSpotClass);
      arrayOfCoordinates.assign(coordsShiftLeft, coordsShiftLeft + 8);
      auxSpot = new Spot(arrayOfCoordinates, kSouth, kSpotClass);
      break;
    }
    case kSouthWest: {
      arrayOfCoordinates.assign(coordsShiftRight, coordsShiftRight + 8);
      newSpot = new Spot(arrayOfCoordinates, kSouth, kSpotClass);
      arrayOfCoordinates.assign(coordsShiftLeft, coordsShiftLeft + 8);
      auxSpot = new Spot(arrayOfCoordinates, kWest, kSpotClass);
      break;
    }
    case kNorthWest: {
      arrayOfCoordinates.assign(coordsShiftRight, coordsShiftRight + 8);
      newSpot = new Spot(arrayOfCoordinates, kWest, kSpotClass);
      arrayOfCoordinates.assign(coordsShiftLeft, coordsShiftLeft + 8);
      auxSpot = new Spot(arrayOfCoordinates, kNorth, kSpotClass);
      break;
    }
    default: {
      assert(false);
    }
  }
  
  newSpot->setAction(action);
  newSpot->setColor(0); // Color is set automatically
  _arrayOfSpots.push_back(newSpot);
  
  if (auxSpot) {
    auxSpot->setAction(action);
    auxSpot->setColor(0);
    _arrayOfSpots.push_back(auxSpot);
  }
}