Commit 0a2ddaee authored by Thomas Jund's avatar Thomas Jund

correction chemin

parent adaf1f4a
......@@ -78,7 +78,7 @@ void generateCity(EnvMap& envMap, unsigned int nbBuildings)
if (!envMap.buildingMark.isMarked(d) && (rand() % 12 == 0)
&& notDiagonalAdjacentToAnObstacle<PFP>(envMap.map, d, envMap.buildingMark))
{
generateBuilding<PFP>(envMap, d, (1 + (rand() % 3)) * 50.0f, rand() % 4) ;
generateBuilding<PFP>(envMap, d, (1 + (rand() % 3)) * 50.0f, rand() % 4) ;
--nbBuilding ;
}
}
......
......@@ -23,6 +23,9 @@
#include "Utils/vbo.h"
#endif
#include "Utils/drawer.h"
using namespace std;
PFP::VEC3 rotate (PFP::VEC3 pos1, PFP::VEC3 center, float angle);
float get_angle (PFP::VEC3 v1, PFP::VEC3 v2);
......@@ -36,7 +39,7 @@ public:
MovingObstacle(Simulator* sim, int index, std::vector<PFP::VEC3> pos, std::vector<VEC3> goals, bool rigid, bool spin,int curGoal=0, Dart d=NIL, ArticulatedObstacle * art=NULL, int indParent=-1);
void initGL();
void draw();
void draw(bool showPath=false);
void addGeneralCell ( Dart d);
bool removeGeneralCell (Dart d);
bool test_opposition(VEC3 o, VEC3 p1, VEC3 p2);
......@@ -87,6 +90,8 @@ public:
Utils::ShaderSimpleColor* m_shader;
#endif
Utils::Drawer* m_ds;
//vector de détails pour la deformation
// std::vector<PFP::VEC3> verticesDeformation;
......
......@@ -105,8 +105,8 @@ public:
void addAgent(const VEC3& start,const VEC3& goals, Dart d);
#ifndef SPATIAL_HASHING
void addPathToObstacles();
void addPathToObstacle(MovingObstacle * mo, Dart dStart, Dart dGoal);
void addPathToObstacles(CellMarker<FACE>& markForbid, bool goalCenterCell);
void addPathToObstacle(MovingObstacle * mo, Dart dStart, Dart dGoal, CellMarker<FACE>& markForbid, bool goalCenterCell);
void addPathToCorner() ;
void addPathsToAgents() ;
void addPathsToAgents_height() ;
......
......@@ -302,9 +302,11 @@ void MovingObstacle::initGL()
// registerShader(m_shader);
#endif
m_ds = new Utils::Drawer();
}
void MovingObstacle::draw()
void MovingObstacle::draw(bool showPath)
{
#ifdef EXPORTING_BOXES
// m_render->initPrimitives<PFP>(map, Algo::Render::GL2::LINES,false) ;
......@@ -322,6 +324,23 @@ void MovingObstacle::draw()
m_shader->setColor(Geom::Vec4f(0.,0.,0.,0.));
m_render->draw(m_shader, Algo::Render::GL2::LINES);
#endif
if(showPath)
{
m_ds->newList(GL_COMPILE_AND_EXECUTE);
m_ds->begin(GL_LINE_STRIP);
VEC3 col = Utils::color_map_BCGYR(float(index)/float(sim_->movingObstacles_.size()));
m_ds->color3f(col[0],col[1],col[2]);
for(std::vector<VEC3>::iterator it = goals_.begin() ; it != goals_.end() ; ++it)
{
m_ds->vertex(*it);
}
m_ds->end();
m_ds->endList();
}
}
VEC3 MovingObstacle::getDilatedPosition(unsigned int ind)
......@@ -1247,7 +1266,7 @@ void MovingObstacle::computePrefVelocity() //calcul du vecteur optimal pour atte
{
goalVector = (get_center(parent,index_parent-1) -center);
float goalDist2 = goalVector.norm2() ;
if (goalDist2 > 100*maxSpeed_)
if (goalDist2 > 1000.0f*maxSpeed_)
{
goalVector.normalize() ;
goalVector *= maxSpeed_;
......
......@@ -53,7 +53,7 @@ void Simulator::init( float dimension, unsigned int nbAgent, unsigned int nbObst
envMap_.init(config, 1000.0f, 1000.0f, minSize, 100.0f) ; //grosses cases
setupScenario(nbAgent, false) ;
addMovingObstacles(nbObst);
addPathToObstacles();
addPathToObstacles(envMap_.buildingMark, true);
//// setupCityScenario(-1.0f * (12 * (70.0f / 2.0f) - 10),
//// -1.0f * (12 * (70.0f / 2.0f) - 10), 20, 20);
break ;
......@@ -65,7 +65,7 @@ void Simulator::init( float dimension, unsigned int nbAgent, unsigned int nbObst
setupScenario(nbAgent, true) ;
// SelectorCellNotMarked<PFP::MAP> scnm(envMap_.pedWayMark);
addMovingObstacles(nbObst);
// addPathToObstacles();
// addPathToObstacles(envMap_.pedWayMark, false);
addPathsToAgents();
break;
case 6:
......@@ -73,7 +73,7 @@ void Simulator::init( float dimension, unsigned int nbAgent, unsigned int nbObst
envMap_.init(config,200.0,200.0, minSize, 400.0f);
setupPlanetScenario(nbAgent,nbObst);
addMovingObstacles(nbObst);
addPathToObstacles();
addPathToObstacles(envMap_.buildingMark, true);
#else
std::cout << "Agents not in 2.5D mode" << std::endl;
#endif
......@@ -859,17 +859,19 @@ void Simulator::addMovingObstacle(Dart d, unsigned int obstType)
}
}
void Simulator::addPathToObstacles()
void Simulator::addPathToObstacles(CellMarker<FACE>& markForbid, bool goalCenterCell)
{
unsigned int dartDistForPath = 50 ;
for (std::vector<MovingObstacle*>::iterator it = movingObstacles_.begin() ; it != movingObstacles_.end() ; ++it)
{
(*it)->goals_.clear();
Dart dStart = (*it)->parts_[0]->d;
while(envMap_.pedWayMark.isMarked(dStart))
while(markForbid.isMarked(dStart))
{
if(!envMap_.pedWayMark.isMarked(envMap_.map.phi2(dStart)))
if(!markForbid.isMarked(envMap_.map.phi2(dStart)))
dStart = envMap_.map.phi2(dStart);
else
dStart = envMap_.map.phi1(dStart);
......@@ -880,7 +882,7 @@ void Simulator::addPathToObstacles()
for (unsigned int j = 0 ; envMap_.buildingMark.isMarked(dStop)
|| j < dartDistForPath + rand() * 20
|| envMap_.map.sameFace(dStop, dStart)
|| envMap_.pedWayMark.isMarked(dStop)
|| markForbid.isMarked(dStop)
; ++j)
{
envMap_.map.next(dStop) ;
......@@ -888,21 +890,27 @@ void Simulator::addPathToObstacles()
dStop = envMap_.map.begin() ;
}
addPathToObstacle(*it, dStart, dStop);
addPathToObstacle(*it, dStart, dStop, markForbid, goalCenterCell);
}
}
void Simulator::addPathToObstacle(MovingObstacle * mo, Dart dStart, Dart dGoal)
void Simulator::addPathToObstacle(MovingObstacle * mo, Dart dStart, Dart dGoal, CellMarker<FACE>& markForbid, bool goalCenterCell)
{
std::vector<Dart> path = CGoGN::PathFinder::pathFindAStar<PFP>(envMap_,
envMap_.position, dStart,
dGoal,
envMap_.pedWayMark) ;
markForbid) ;
for (std::vector<Dart>::iterator it = path.begin() ; it != path.end() ; ++it)
{
VEC3 dest = envMap_.position[*it] + envMap_.position[envMap_.map.phi1(*it)] ;
dest /= 2.0f ;
VEC3 dest;
if(goalCenterCell)
dest = Algo::Surface::Geometry::faceCentroid<PFP>(envMap_.map, *it, envMap_.position) ;
else
{
dest = envMap_.position[*it] + envMap_.position[envMap_.map.phi1(*it)] ;
dest /= 2.0f ;
}
mo->goals_.push_back(dest) ;
}
......@@ -911,12 +919,18 @@ void Simulator::addPathToObstacle(MovingObstacle * mo, Dart dStart, Dart dGoal)
envMap_.position,
dGoal,
dStart,
envMap_.pedWayMark) ;
markForbid) ;
for (std::vector<Dart>::iterator it = path.begin() ; it != path.end() ; ++it)
{
VEC3 dest = envMap_.position[*it] + envMap_.position[envMap_.map.phi1(*it)] ;
dest /= 2.0f ;
VEC3 dest;
if(goalCenterCell)
dest = Algo::Surface::Geometry::faceCentroid<PFP>(envMap_.map, *it, envMap_.position) ;
else
{
dest = envMap_.position[*it] + envMap_.position[envMap_.map.phi1(*it)] ;
dest /= 2.0f ;
}
mo->goals_.push_back(dest) ;
}
......
......@@ -723,7 +723,7 @@ void SocialAgents::cb_redraw()
#endif
#ifdef EXPORTING_BOXES
simulator.movingObstacles_[i]->draw();
simulator.movingObstacles_[i]->draw(drawObstPath);
#endif
}
// Commente par Arash
......
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