Beispiel #1
0
void Grid::rebuildGrid()
{
    cells.clear();
    globalCell = SharedCell(new Cell());
    calculateTranslationMatrix();
    for (boost::unordered_map<int, Item::SharedArea>::iterator a = core->getData()->areas.begin(); a != core->getData()->areas.end(); ++a)
    {
        addArea(a->second);
    }
    for (boost::unordered_map<int, Item::SharedCheckpoint>::iterator c = core->getData()->checkpoints.begin(); c != core->getData()->checkpoints.end(); ++c)
    {
        addCheckpoint(c->second);
    }
    for (boost::unordered_map<int, Item::SharedMapIcon>::iterator m = core->getData()->mapIcons.begin(); m != core->getData()->mapIcons.end(); ++m)
    {
        addMapIcon(m->second);
    }
    for (boost::unordered_map<int, Item::SharedObject>::iterator o = core->getData()->objects.begin(); o != core->getData()->objects.end(); ++o)
    {
        addObject(o->second);
    }
    for (boost::unordered_map<int, Item::SharedPickup>::iterator p = core->getData()->pickups.begin(); p != core->getData()->pickups.end(); ++p)
    {
        addPickup(p->second);
    }
    for (boost::unordered_map<int, Item::SharedRaceCheckpoint>::iterator r = core->getData()->raceCheckpoints.begin(); r != core->getData()->raceCheckpoints.end(); ++r)
    {
        addRaceCheckpoint(r->second);
    }
    for (boost::unordered_map<int, Item::SharedTextLabel>::iterator t = core->getData()->textLabels.begin(); t != core->getData()->textLabels.end(); ++t)
    {
        addTextLabel(t->second);
    }
}
Beispiel #2
0
void Grid::removeCheckpoint(const Item::SharedCheckpoint &checkpoint, bool reassign)
{
    bool found = false;
    if (checkpoint->cell)
    {
        boost::unordered_map<CellID, SharedCell>::iterator c = cells.find(checkpoint->cell->cellID);
        if (c != cells.end())
        {
            boost::unordered_map<int, Item::SharedCheckpoint>::iterator d = c->second->checkpoints.find(checkpoint->checkpointID);
            if (d != c->second->checkpoints.end())
            {
                c->second->checkpoints.quick_erase(d);
                eraseCellIfEmpty(c->second);
                found = true;
            }
        }
    }
    else
    {
        boost::unordered_map<int, Item::SharedCheckpoint>::iterator c = globalCell->checkpoints.find(checkpoint->checkpointID);
        if (c != globalCell->checkpoints.end())
        {
            globalCell->checkpoints.quick_erase(c);
            found = true;
        }
    }
    if (found)
    {
        if (reassign)
        {
            addCheckpoint(checkpoint);
        }
    }
}
Beispiel #3
0
//return true if there is a collision and do side effect on argument collision (a vec of 2 elements), if not return false
bool Trajectory::isCollision(obstacle &obs)
{
  vec collision(2);
  vector<vec> obsPoints = obs.getBoundingBox();
  for(list<vec>::iterator it = _currentInitCheckpoint; it != prev(_checkpoints.end(),1) ; it++)
    {
      list<vec>::iterator nextIt = next(it,1);
      if(intersection(obsPoints[0], obsPoints[1], *it, *nextIt, collision) ||
         intersection(obsPoints[1], obsPoints[2], *it, *nextIt, collision) ||
         intersection(obsPoints[2], obsPoints[3], *it, *nextIt, collision) ||
         intersection(obsPoints[3], obsPoints[0], *it, *nextIt, collision) )
        {
          if(it == _currentInitCheckpoint && dist(*it,collision) > dist(*it,_robotPosition))
            {
              _collisionInitCheckpoint = it;
              makeForwardCheckpoint(DIST);
              vec direct = obs.getDirection();
              addCheckpoint(create2dvec(collision[0] + direct[0]* DEF_LENGHT,collision[1] + direct[1]*DEF_LENGHT));
              return true;
            }
        }
      else
        cout << "No Collision" << endl;
    }
  return false;
}