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

correction chemin

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