예제 #1
0
파일: Env.cpp 프로젝트: schlog/camass_v2
bool Env::sendMsg(long idSrc, long idDest, char *msg) {
    logMsg("SEND MSG : " + std::to_string(idSrc) + " -> " + std::to_string(idDest));
    // if (this->phy->getNeighbours(idSrc).count(idDest)) {
        this->agents.at(idDest)->addMsg(msg);

        // Display the sending message with dataAgents
        Agent * agentSrc = this->agents.at(idSrc);
        Agent * agentDest = this->agents.at(idDest);
        Vect posSrc = PosToCell(agentSrc->getPos().x, agentSrc->getPos().y);
        Vect posDest = PosToCell(agentDest->getPos().x, agentDest->getPos().y);
        if (posSrc != posDest) {
            float dist = ((724-Vect(posSrc - posDest).Length()) / 724.0) / 6.0;
            for (float n = 0; n < 1; n += dist) {
                Vect base = posDest + n * (posSrc - posDest);
                Vect dirSommet = Vect(posSrc - posDest);
                dirSommet.Normalize();
                Vect vectBase = Vect(dirSommet.y, -dirSommet.x);
                for (int j = 0; j < 20; j++) {
                    for (int i = -j*0.5; i <= j*0.5; i++) {
                        Vect point = base + j / 2.0 * dirSommet + i / 2.0 * vectBase;
                        if (point.x >= 0 && point.x < 512 && point.y >= 0 && point.y < 512) {
                            agentSrc->getVision(point.x, point.y)->dataAgent = 10 * (1 - n);
                        }
                    }
                }
            }
        }
        return true;
    //}
    //return false;
}
예제 #2
0
파일: Env.cpp 프로젝트: schlog/camass_v2
Agent* Env::addAgent(float range, float speed) {
    int idAgent = this->agents.size();
    Agent *agent = new Agent(idAgent, phy, range/this->W, speed, (EnvAgents*)this);
    this->phy->addAgent(idAgent, agent->getPos(), agent->getAngle(), agent->getSize(), agent->getRange()/this->W);
    this->agents.insert(pair<long, Agent*>(idAgent, agent));
    this->phy->setMaxSpeed(idAgent, speed);
    return agent;
}
예제 #3
0
파일: SWGraph.cpp 프로젝트: calucita/Tesis
void SWGraph::getRealConnectivities(ofstream& fp){
  
  // Para cada agente obtener su posicion 
  // y con esa posicion buscar los vecinos 
  // y contarlos.
  
  list<Agent*> vecinos;
  Agent* a = NULL;
  Position* pos=NULL;

  set<Agent*>::iterator i;
  for (i = agents.begin(); i != agents.end(); ++i) {  
    a = *i;
    pos = a->getPos();
    vecinos = getNeighbourgs(pos);
    //cout << a->getId()<< "\t" << vecinos.size()<<"\n";
    fp << a->getId()<< "\t" << vecinos.size()<<"\n";}

}