Commit 84006d76 authored by pitiot's avatar pitiot
Browse files

mAJ circle

parent 4f427d7d
......@@ -17,7 +17,7 @@ class Simulator ;
class MovingObstacle
{
public:
MovingObstacle(Simulator* sim, int index, std::vector<PFP::VEC3> pos, VEC3 goal,float rota);
MovingObstacle(Simulator* sim, int index, std::vector<PFP::VEC3> pos, std::vector<VEC3> goals,float rota);
bool test_opposition(VEC3 o, VEC3 p1, VEC3 p2);
// void contournerBatiment();
void updateAgentNeighbors() ;
......
......@@ -90,13 +90,13 @@ public:
~Simulator() ;
void init(unsigned int config, int minSize, float dimension, bool enablePathFinding = false) ;
void init( float dimension, bool enablePathFinding = false) ;
void doStep() ;
bool reachedGoal() ;
void setupCircleScenario(unsigned int nbAgents) ;
void setupCircleScenario(unsigned int nbAgents, unsigned int nbObstacles) ;
void setupCorridorScenario(unsigned int nbAgents, unsigned int nbObstacles) ;
void setupCityScenario(int nbLines, int nbRank) ;
void setupScenario(unsigned int nbMaxAgent) ;
......@@ -122,7 +122,8 @@ public:
EnvMap envMap_ ;
std::vector<Agent*> agents_ ;
std::vector<MovingObstacle*> movingObstacles_;
int minSize;
unsigned int config;
float timeStep_ ;
float globalTime_ ;
unsigned int nbSteps_ ;
......
......@@ -64,7 +64,7 @@ VEC3 rotate(VEC3 pos1, VEC3 center, float angle)
return pos2;
}
MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, VEC3 goal, float rota) :
MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, std::vector<VEC3> goals, float rota) :
index(ind),
newVelocity_(0),
sim_(sim)
......@@ -118,8 +118,8 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, V
front=(vertices[0] + vertices[1]) / 2;
make_half_turn = get_angle(finalGoal - center,front - center) * nbVertices;
goals_.push_back(center);
goals_.push_back(goal);
goals_=goals;
curGoal_ = 0;
}
......
#include "simulator.h"
Simulator::Simulator(int minSize) :
Simulator::Simulator(int minS) :
timeStep_(0.2f),
globalTime_(0.0f),
nbSteps_(0),
......@@ -13,11 +13,13 @@ Simulator::Simulator(int minSize) :
avoidance(1),
nb_dead(0)
{
minSize=minS;
multires=true;
detect_agent_collision=false;
srand(10) ;
nbStepsPerUnit_ = 1 / timeStep_ ;
init(1, minSize, 2.0f) ;
config=0;
init( minSize, 2.0f) ;
}
Simulator::~Simulator()
......@@ -26,37 +28,29 @@ Simulator::~Simulator()
delete agents_[i] ;
}
void Simulator::init(unsigned int config, int minSize, float dimension, bool enablePathFinding)
void Simulator::init( float dimension, bool enablePathFinding)
{
std::cout << "Setup scenario" << std::endl ;
if (multires)
{
envMap_.init(config, 1600.0f, 960.0f, minSize, 320.0f) ; //grosses cases
}
else
{
envMap_.init(config, 1600.0f, 960.0f, minSize, 20.0f) ; //cases fines
}
switch (config)
{
case 0 :
setupCircleScenario(100) ;
setupCircleScenario(1000,40) ;
break ;
case 1 :
setupCorridorScenario(1000,40) ;
break ;
case 2 :
setupScenario(1000) ;
break ;
case 3 :
setupCityScenario(20, 20) ;
// setupCityScenario(-1.0f * (12 * (70.0f / 2.0f) - 10),
// -1.0f * (12 * (70.0f / 2.0f) - 10), 20, 20);
break ;
case 4 :
importAgents("myAgents.pos") ;
break ;
// case 2 :
// setupScenario(1000) ;
// break ;
// case 3 :
// setupCityScenario(20, 20) ;
//// setupCityScenario(-1.0f * (12 * (70.0f / 2.0f) - 10),
//// -1.0f * (12 * (70.0f / 2.0f) - 10), 20, 20);
// break ;
// case 4 :
// importAgents("myAgents.pos") ;
// break ;
}
#ifndef SPATIAL_HASHING
......@@ -200,8 +194,18 @@ void Simulator::addAgent(const VEC3& start, const std::vector<VEC3>& goal)
agents_.back()->curGoal_ = 0 ;
}
void Simulator::setupCircleScenario(unsigned int nbAgents)
void Simulator::setupCircleScenario(unsigned int nbAgents , unsigned int nbObstacles)
{
if (multires)
{
envMap_.init(config, 2000.0f, 2000.0f, minSize, 400.0f) ; //grosses cases
}
else
{
envMap_.init(config, 1600.0f, 960.0f, minSize, 20.0f) ; //cases fines
}
std::cout << " - Setup Circle Scenario : " << nbAgents << " agents" << std::endl ;
// Bordure à éviter autour de la scène (10% de sa taille)
......@@ -229,12 +233,53 @@ void Simulator::setupCircleScenario(unsigned int nbAgents)
goals.push_back(goal);
addAgent(start, goals) ;
}
for (unsigned int i = 0 ; i < movingObstacles_.size() ; ++i)
VEC3 xSide (5.0f,0.0f,0.0f);
VEC3 ySide (0.0f,10.0f,0.0f);
std::vector<VEC3> vPos;
MovingObstacle* mo4;
std::vector<VEC3> positions;
for (unsigned int i = 0 ; i < nbObstacles/2 ; i++)
{
// movingObstacles_[i]->updateFixedObstNeighbors() ;
movingObstacles_[i]->computePrefVelocity() ;
movingObstacles_[i]->update() ;
double angle = i * 2.0f * pi / float(nbObstacles/2) ;
VEC3 v(std::cos(angle) * (2*radius/3), std::sin(angle) * (2*radius/3), 0) ;
VEC3 start = center + v ;
positions.push_back(start);
}
for (unsigned int i = 0 ; i < nbObstacles/2 ; i++)
{
VEC3 start = positions[i];
std::vector<VEC3> goals;
for(unsigned int k = 0 ; k < nbObstacles/2 ; k++)
{
goals.push_back(positions[(i+k)%(nbObstacles/2)]);
}
vPos.clear();
// Un obstacle sur deux va vers le haut
vPos.push_back(start+xSide-ySide);
vPos.push_back(start+xSide+ySide);
vPos.push_back(start-xSide+ySide);
vPos.push_back(start-xSide-ySide);
mo4= new MovingObstacle(this, i,vPos,goals,0);
//for generating a random path
// unsigned int dartDistForPath = 50 ;
// mo4->goals_.clear() ;
// Dart dStart = mo4->parts_[0]->d;
// Dart dStop = dStart ;
// for (unsigned int j = 0 ; envMap_.buildingMark.isMarked(dStop) || j < dartDistForPath + rand() * 20 || envMap_.map.sameFace(dStop, dStart) ; ++j)
// {
// envMap_.map.next(dStop) ;
// if (dStop == envMap_.map.end())
// dStop = envMap_.map.begin() ;
// }
//
// addPathToObstacle(mo4, dStart, dStop);
// addPathToObstacle(mo4, dStop, dStart);
movingObstacles_.push_back(mo4);
}
#ifndef SPATIAL_HASHING
......@@ -247,6 +292,17 @@ void Simulator::setupCircleScenario(unsigned int nbAgents)
void Simulator::setupCorridorScenario(unsigned int nbAgents, unsigned int nbObstacles)
{
if (multires)
{
envMap_.init(config, 1600.0f, 960.0f, minSize, 320.0f) ; //grosses cases
}
else
{
envMap_.init(config, 1600.0f, 960.0f, minSize, 20.0f) ; //cases fines
}
std::cout << " - Setup Corridor Scenario : " << nbAgents << " agents et " << nbObstacles << " obstacles" << std::endl ;
// Bordure à éviter autour de la scène (10% de sa taille)
......@@ -327,7 +383,10 @@ void Simulator::setupCorridorScenario(unsigned int nbAgents, unsigned int nbObst
vPos.push_back(start-xSide+ySide);
vPos.push_back(start-xSide-ySide);
}
mo4= new MovingObstacle(this, i,vPos,goal,0);
std::vector<VEC3> goals;
goals.push_back(start);
goals.push_back(goal);
mo4= new MovingObstacle(this, i,vPos,goals,0);
//for generating a random path
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment