Commit de3a6e76 authored by pitiot's avatar pitiot
Browse files

maj

parent 9b8d3a29
......@@ -57,7 +57,11 @@ public:
unsigned int curGoal_ ;
MovingObstacle **movingObstacles_;
int nb_mos;
static unsigned int maxNeighbors_ ;
static unsigned int maxMovingObstacles_;
static float maxSpeed_ ;
static float neighborDist_ ;
static float neighborDistSq_ ;
......
......@@ -20,7 +20,7 @@ public:
void linkWithObstacle(MovingObstacle * mo);
void scale(float val);
void moveInFace(typename PFP::MAP& motherMap, Dart d, VertexAttribute<VEC3> pos);
void moveInFace(PFP::MAP& motherMap, Dart d, VertexAttribute<VEC3> pos);
void move();
void animate();
......@@ -28,7 +28,7 @@ public:
std::vector<VEC3> jarvisConvexHull(std::vector<VEC3> projectedPointSet);
std::vector<VEC3> computeSkeleton(std::vector<VEC3> projectedPointSet, unsigned int nodeNumber);
typename PFP::MAP map;
PFP::MAP map;
VertexAttribute<VEC3> position;
VertexAttribute<VEC3> normal;
......
......@@ -44,6 +44,8 @@ public:
std::vector<Dart> * neighbor_cells;
std::set<Dart> general_belonging;
VEC3 front;
VEC3 focus1, focus2;
double length, width, sum_dist_foci, sum_dist_foci_rest;
VEC3 finalGoal;
float angle;
......@@ -61,6 +63,10 @@ public:
float obstacle_range;
static float timeHorizonObst_;
float velocity_factor;
float color1;
float color2;
float color3;
bool seen;
VEC3 velocity_;
VEC3 newVelocity_;
VEC3 prefVelocity_;
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>211</width>
<width>219</width>
<height>457</height>
</rect>
</property>
......@@ -115,6 +115,13 @@
<item>
<widget class="QSpinBox" name="check_slide"/>
</item>
<item>
<widget class="QCheckBox" name="check_elipse">
<property name="text">
<string>draw elipse</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......
......@@ -97,6 +97,7 @@ public:
bool drawAgentsPredictionTri ;
bool drawObstPredictionTri ;
bool draw_dart;
bool draw_elipse;
unsigned int dartSlider;
public slots:
......@@ -166,4 +167,9 @@ public slots:
dartSlider = i;
updateGL();
}
void slot_elipse(bool b)
{
draw_elipse = b;
updateGL();
}
} ;
This diff is collapsed.
......@@ -32,14 +32,14 @@ void MovingMesh::linkWithObstacle(MovingObstacle * mo)
void MovingMesh::scale(float val)
{
TraversorV<typename PFP::MAP> tv(map);
TraversorV<PFP::MAP> tv(map);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
position[d] *= val;
}
}
void MovingMesh::moveInFace(typename PFP::MAP& motherMap, Dart d, VertexAttribute<VEC3> pos)
void MovingMesh::moveInFace(PFP::MAP& motherMap, Dart d, VertexAttribute<VEC3> pos)
{
VEC3 n = Algo::Geometry::faceNormal<PFP>(motherMap, d, pos);
VEC3 b = Algo::Geometry::faceCentroid<PFP>(motherMap, d, pos);
......
......@@ -77,6 +77,10 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
parent(art),
index_parent(ind2)
{
seen = false;
color1=1.0f;
color2=1.0f;
color3=1.0f;
assert(pos.size() > 2);
// movingObstNeighbors_.reserve(maxNeighbors_);
......@@ -104,6 +108,17 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
}
center = sum / nbVertices;
front=(vertices[1] + vertices[2]) / 2;
//-------- code ajoute par Arash pour les obstacles rectangulaires --------------
length = (vertices[0]-vertices[1]).norm();
width = (vertices[1]-vertices[2]).norm();
sum_dist_foci_rest = 2*(length + width*(sqrt(2)-0.5));
// M appartient à l'ellipse ssi MF1 + MF2 = sum_dist_foci est une constante
// où F1 et F2 sont les deux foyers.
//-------- fin du code ajoute par Arash pour les obstacles rectangulaires -------
if (spinning && parent==NULL) //départ face à la cible en cas d'obstacles pouvant effectuer des rotations
{
angle = get_angle(goals_[curGoal_] - center,front - center);
......@@ -138,11 +153,6 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
gravity_dist = pos_max + 5.0f;
obstacle_range = 15.0f * 15.0f;
}
bool MovingObstacle::test_opposition(VEC3 o, VEC3 p1, VEC3 p2)
......@@ -321,6 +331,13 @@ void MovingObstacle::update()
if(sim_->detect_agent_collision)
general_belonging.clear();
if(!seen)
{
color1=1.0f;
color2=1.0f;
color3=1.0f;
}
seen=false;
PFP::VEC3 bary = 0;
Dart d;
......@@ -356,6 +373,25 @@ void MovingObstacle::update()
center = bary / nbVertices;
//-------- code ajoute par Arash pour les obstacles rectangulaires --------------
VEC3 P0_P1 = vertices[1] - vertices[0];
float velocity_coef = 50.0;
if(P0_P1 * velocity_ > 0) // P0_P1 est dans le sens de la vitesse
{
focus1 = center - P0_P1*(1-(width/length)*(sqrt(2)-0.5));
focus2 = center + P0_P1*(1-(width/length)*(sqrt(2)-0.5)) + (velocity_coef*velocity_);
}
else
{
focus1 = center - P0_P1*(1-(width/length)*(sqrt(2)-0.5)) + (velocity_coef*velocity_);
focus2 = center + P0_P1*(1-(width/length)*(sqrt(2)-0.5));
}
sum_dist_foci = sum_dist_foci_rest + velocity_coef*velocity_.norm();
//-------- fin du code ajoute par Arash pour les obstacles rectangulaires -------
// MAJ des obstacles
for (unsigned int i = 0; i < nbVertices; ++i)
{
......@@ -403,6 +439,7 @@ void MovingObstacle::update()
}
std::vector<Dart> MovingObstacle::getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1)
{
registering_part->move(pos);
......@@ -419,7 +456,8 @@ void resetPartSubdiv(Obstacle* o)
if (mo != NULL)
{
VEC3 pos =mo->registering_part->getPosition();
mo->registering_part->ParticleBase<PFP>::move(Algo::Geometry::faceCentroid<PFP>(mo->sim_->envMap_.map, mo->registering_part->d, mo->sim_->envMap_.position)) ;
mo->registering_part->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Geometry::faceCentroid<PFP>(mo->sim_->envMap_.map, mo->registering_part->d, mo->sim_->envMap_.position)) ;
mo->registering_part->setState(FACE) ;
mo->registering_part->move(pos) ;
}
......
......@@ -14,11 +14,12 @@ Simulator::Simulator(int minS) :
nb_dead(0)
{
minSize=minS;
multires=true;
multires=false;
detect_agent_collision=false;
srand(10) ;
nbStepsPerUnit_ = 1 / timeStep_ ;
config=2;
config=0;
// config=1;
init( minSize, 2.0f) ;
}
......@@ -40,7 +41,7 @@ void Simulator::init( float dimension, bool enablePathFinding)
switch (config)
{
case 0 :
setupCircleScenario(1000,40) ;
setupCircleScenario(5,40) ;
break ;
case 1 :
setupCorridorScenario(1000,40) ;
......@@ -211,7 +212,7 @@ void Simulator::setupCircleScenario(unsigned int nbAgents , unsigned int nbObsta
else
{
envMap_.init(config, 1600.0f, 960.0f, minSize, 20.0f) ; //cases fines
envMap_.init(config, 1600.0f, 960.0f, minSize, 400.0f) ; //cases fines
}
std::cout << " - Setup Circle Scenario : " << nbAgents << " agents" << std::endl ;
......@@ -320,7 +321,7 @@ void Simulator::setupCorridorScenario(unsigned int nbAgents, unsigned int nbObst
else
{
envMap_.init(config, 1600.0f, 960.0f, minSize, 20.0f) ; //cases fines
envMap_.init(config, 1600.0f, 960.0f, minSize, 320.0f) ; //cases fines
}
......@@ -438,7 +439,7 @@ void Simulator::setupSnakeCorridorScenario(unsigned int nbAgents, unsigned int n
else
{
envMap_.init(config, 1600.0f, 960.0f, minSize, 20.0f) ; //cases fines
envMap_.init(config, 1600.0f, 960.0f, minSize, 320.0f) ; //cases fines
}
......
......@@ -43,7 +43,8 @@ SocialAgents::SocialAgents(int minSize, int iterations) :
drawAgentsObstacleDist(false),
drawAgentsPredictionTri(false),
drawObstPredictionTri(false),
draw_dart(false)
draw_dart(false),
draw_elipse(false)
{
timer = new QTimer(this) ;
connect(timer, SIGNAL(timeout()), this, SLOT(animate())) ;
......@@ -62,6 +63,7 @@ void SocialAgents::initGUI()
dock.check_drawAgents->setChecked(drawAgents) ;
dock.check_drawMovingObstacles->setChecked(drawMovingObstacles) ;
dock.check_dart->setChecked(draw_dart) ;
dock.check_elipse->setChecked(draw_elipse) ;
setCallBack(dock.check_timer, SIGNAL(toggled(bool)), SLOT(slot_timer(bool))) ;
setCallBack(dock.check_drawEnvLines, SIGNAL(toggled(bool)), SLOT(slot_drawEnvLines(bool))) ;
......@@ -76,6 +78,7 @@ void SocialAgents::initGUI()
setCallBack(dock.check_drawAgentsObstacleDist, SIGNAL(toggled(bool)), SLOT(slot_drawAgentsObstacleDist(bool))) ;
setCallBack(dock.check_dart, SIGNAL(toggled(bool)), SLOT(slot_dart(bool))) ;
setCallBack(dock.check_slide, SIGNAL(valueChanged(int)), SLOT(slot_slide(int))) ;
setCallBack(dock.check_elipse, SIGNAL(toggled(bool)), SLOT(slot_elipse(bool))) ;
}
void SocialAgents::cb_initGL()
......@@ -93,6 +96,59 @@ void SocialAgents::cb_initGL()
setParamObject(gWidthObj, gPosObj.data()) ;
}
//-----------------------------------
// An ellipse has two foci placed at
// F1 and F2. The ellipse is the set
// of points M for whom MF1 + MF2 = s
static void drawEllipse(VEC3 F1, VEC3 F2, float s, int N)
{
float a,b=0;
VEC3 O,u,v;
O = 0.5f*(F1+F2);
u = F1-F2;
float c = (F1-F2).norm();
if(c==0)
{
u[0] = 1.0;
u[1] = 0.0;
v[0] = 0.0;
v[1] = 1.0;
a=s/2;
b=s/2;
}
else // c>0
{
u = (1.0f/c) * u;
v.zero();
v[0] = u[1];
v[1] = -u[0];
c = 0.5 * c;
a = s/2.0;
if(a<c)
{
cerr << "a=" << a << " and c=" << c << endl;
cerr << "No such an ellipse is possible" << endl;
}
else // a >= c
b = sqrt( a*a - c*c );
}
glBegin(GL_LINE_LOOP);
VEC3 M;
float dtheta = 2 * M_PI / N;
float theta;
for(theta=0; theta<2*M_PI; theta+=dtheta)
{
M = O + a*cos(theta)*u + b*sin(theta)*v;
glColor3f(0,0,1);
glVertex2f(M[0],M[1]);
}
glEnd();
}
//-----------------------------------
void SocialAgents::cb_redraw()
{
dock.check_slide->setRange(0, sim.envMap_.map.end().index) ;
......@@ -217,6 +273,18 @@ void SocialAgents::cb_redraw()
{
for (std::vector<MovingObstacle*>::iterator it = sim.movingObstacles_.begin() ; it != sim.movingObstacles_.end() ; ++it)
{
if (draw_elipse)
{ // Dessiner les foyers
glBegin(GL_POINTS);
glColor3f(1.0,0.0,0.0);
glVertex3fv((*it)->focus1.data());
glColor3f(0.0,1.0,0.0);
glVertex3fv((*it)->focus2.data());
glEnd();
// Dessiner l'ellipse
drawEllipse((*it)->focus1,(*it)->focus2,(*it)->sum_dist_foci,20);
}
// MovingObstacle* mo = *it ;
//affiche les sommets des obstacles
// for (unsigned int i =0; i< (*it)->nbVertices;i++)
......@@ -235,7 +303,7 @@ void SocialAgents::cb_redraw()
// glEnd();
// }
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
glColor3f(1.0f, 1.0f, 1.0f) ;
glColor3f((*it)->color1, (*it)->color2, (*it)->color3) ;
glLineWidth(1.0f) ;
// if((*it)->index==74)
// {
......
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