Commit 622c61be authored by Jund Thomas's avatar Jund Thomas
Browse files

fast and sluggy : amelioration gestion limace et trace au sol

parent f9652c68
......@@ -78,6 +78,26 @@ inline void renderObstacle(EnvMap& m, MovingObstacle * obst, bool showBelonging=
}
glEnd() ;
glColor3f(0.0,1.0,1.0);
glBegin(GL_LINES) ;
for (unsigned int i = 0 ; i < (obst->nbVertices) ; ++i)
{
const VEC3& p = obst->getPosition(i) ;
glVertex3fv(p.data()) ;
const VEC3& p2 = obst->getDilatedPosition(i) ;
glVertex3fv(p2.data()) ;
}
glEnd() ;
glLineWidth(5.0f) ;
glColor3f(1.0,1.0,0.0);
glBegin(GL_LINES) ;
VEC3 p = obst->getPosition(0) ;
glVertex3fv(p.data()) ;
p += 20.0f*obst->velocity_;
glVertex3fv(p.data()) ;
glEnd() ;
if (renderPath)
{
glLineWidth(3.0f) ;
......
......@@ -19,6 +19,7 @@ public:
void linkWithObstacle(MovingObstacle * mo);
void transform(Geom::Matrix44f m);
void translate(VEC3 v);
void scale(float val);
void moveInFace(PFP::MAP& motherMap, Dart d, VertexAttribute<VEC3> pos);
......@@ -27,7 +28,7 @@ public:
void draw();
std::vector<VEC3> computeProjectedPointSet();
std::vector<VEC3> computeProjectedPointSet(float maxHeight);
std::vector<VEC3> jarvisConvexHull(std::vector<VEC3> projectedPointSet);
std::vector<VEC3> computeSkeleton(std::vector<VEC3> projectedPointSet, unsigned int nodeNumber);
......
......@@ -34,7 +34,7 @@ public:
unsigned int nbVertices;
CGoGN::Algo::MovingObjects::ParticleCell2DMemo<PFP> *registering_part;
std::vector<PFP::VEC3> vertices;
std::vector<PFP::VEC3> verticesDetails;
std::vector<PFP::VEC3> verticesDeformation;
float gravity_dist;
VEC3 center;
int nb_agents_voisins;
......
......@@ -183,7 +183,7 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
Algo::Modelisation::TwoNPlusOneSubdivision<PFP,PFP::TVEC3, VEC3>(map,position,nb);
markPedWay();
scale(5.0f);
scale(20.0f);
}
break;
}
......
......@@ -39,6 +39,15 @@ void MovingMesh::linkWithObstacle(MovingObstacle * mo)
this->mo = mo;
}
void MovingMesh::transform(Geom::Matrix44f m)
{
TraversorV<PFP::MAP> tv(map);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
position[d] = Geom::transform(position[d],m);
}
}
void MovingMesh::translate(VEC3 v)
{
TraversorV<PFP::MAP> tv(map);
......@@ -125,14 +134,15 @@ void MovingMesh::draw()
normal) ;
}
std::vector<VEC3> MovingMesh::computeProjectedPointSet()
std::vector<VEC3> MovingMesh::computeProjectedPointSet(float maxHeight)
{
std::vector<VEC3> res;
TraversorV<PFP::MAP> tv(map);
for(Dart dd = tv.begin() ; dd != tv.end() ; dd = tv.next())
{
res.push_back(position[dd]);
if(position[dd][2]<maxHeight)
res.push_back(position[dd]);
}
res = jarvisConvexHull(res);
......@@ -147,23 +157,6 @@ std::vector<VEC3> MovingMesh::computeProjectedPointSet()
return res;
}
double jarvisFindAngle(VEC3 v1, VEC3 v2)
{
double deltaX=(double)(v2[0]-v1[0]);
double deltaY=(double)(v2[1]-v1[1]);
double angle;
if (deltaX==0 && deltaY==0)
return 0;
angle=std::atan2(deltaY,deltaX)*57.295779513082;
if (angle < 0)
angle += 360.;
return angle;
}
std::vector<VEC3> MovingMesh::jarvisConvexHull(std::vector<VEC3> pointSet)
{
assert(pointSet.size()>2);
......@@ -218,76 +211,6 @@ std::vector<VEC3> MovingMesh::jarvisConvexHull(std::vector<VEC3> pointSet)
return res;
}
//std::vector<VEC3> MovingMesh::jarvisConvexHull(std::vector<VEC3> pointSet)
//{
// assert(pointSet.size()>2);
//
// std::vector<unsigned int> convHull;
// int maxAngle=0, minAngle=0;
// unsigned int minPoint=0, maxPoint=0;
// unsigned int cP; //currPoint
//
// for(unsigned int i=1; i<pointSet.size(); ++i)
// if(pointSet[i][1]>pointSet[maxPoint][1])
// maxPoint=i;
//
// for(unsigned int i=1; i<pointSet.size(); ++i) //FOR ALL POINTS IN THE SET, FIND MIN POINT
// if(pointSet[i][1]<pointSet[minPoint][1])
// minPoint=i;
//
// convHull.push_back(minPoint);
// cP =minPoint;
//
// while(cP!=maxPoint) //build left hand side
// {
// maxAngle=cP;
//
// for(unsigned int i=0; i<pointSet.size(); ++i) //LOOP FOR ALL POINTS IN THE SET, FIND POINT WITH LOWEST RELATIVE ANGLE
// {
// if ((i==maxPoint || std::find(convHull.begin(), convHull.end(), i)==convHull.end())
// && jarvisFindAngle(pointSet[cP],pointSet[maxAngle]) < jarvisFindAngle(pointSet[cP],pointSet[i])
// && jarvisFindAngle(pointSet[cP],pointSet[i])<=270)
// {
// maxAngle=i;
// }
// }
//
// cP=maxAngle;
// convHull.push_back(cP); //add point to final perimeter list
// }
//
// cP=minPoint;
//
// while(cP!=maxPoint) //build right hand side
// {
// minAngle=maxPoint;
//
// for(unsigned int i=0; i<pointSet.size(); ++i) //LOOP FOR ALL POINTS IN THE SET, FIND POINT WITH GREATEST RELATIVE ANGLE
// {
// if ((i==maxPoint || std::find(convHull.begin(), convHull.end(), i)==convHull.end())
// && jarvisFindAngle(pointSet[cP],pointSet[minAngle])> jarvisFindAngle(pointSet[cP],pointSet[i])
// && jarvisFindAngle(pointSet[cP],pointSet[i])>=90)
// {
// minAngle=i;
// }
// }
//
// cP=minAngle;
// convHull.push_back(cP); //add point to final perimeter list
// std::cout << "push right hand side" << std::endl;
// }
//
// std::vector<VEC3> res;
// res.reserve(convHull.size());
//
// for(std::vector<unsigned int>::iterator it = convHull.begin() ; it != convHull.end() ; ++it)
// {
// res.push_back(pointSet[*it]);
// }
//
// return res;
//}
bool vecSort(const VEC3& a1, const VEC3& a2)
{
return a1[0] < a2[0] || (a1[0]==a2[0] && a1[1]<a2[1]);
......
......@@ -104,7 +104,7 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
{
vertices[i]=pos [i];
sum += vertices[i];
verticesDetails.push_back(VEC3(0));
verticesDeformation.push_back(VEC3(0));
}
center = sum / nbVertices;
front=(vertices[1] + vertices[2]) / 2;
......@@ -157,7 +157,7 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
VEC3 MovingObstacle::getDilatedPosition(unsigned int ind)
{
return vertices[ind]+verticesDetails[ind];
return vertices[ind]+verticesDeformation[ind];
}
VEC3 MovingObstacle::getPosition(unsigned int ind)
......@@ -333,8 +333,6 @@ void MovingObstacle::updateObstacleNeighbors() // obstacles voisins , distance p
// }
}
// TODO Check position
void MovingObstacle::update()
{
assert(sim_->envMap_.map.getCurrentLevel() == sim_->envMap_.map.getMaxLevel()) ;
......@@ -358,52 +356,40 @@ void MovingObstacle::update()
float abs_angle= angle > 0 ? 1 : -1;
float rotor=0;
if (index_parent==0)
{
rotor = abs_angle*angle > 0.04f ? 0.04f : abs_angle*angle ;
}
else
{
rotor = abs_angle*angle ;
}
// CGoGNout << "Obstacle "<< index << CGoGNendl;
// CGoGNout << "vitesse : "<< velocity_ << CGoGNendl;
// on fait tourner l'obstacle
for (unsigned int i = 0; i < nbVertices; ++i)
{
VEC3 target =vertices[i];
target += rotate(vertices[i], center, abs_angle*rotor);
VEC3& target =vertices[i];
target += rotate(target, center, abs_angle*rotor);
target += (velocity_ * sim_->timeStep_);
vertices[i] = target;
bary += target;
}
front=(vertices[1] + vertices[2]) / 2;
if(angle >0)
{
angle -= rotor;
}
else
{
angle += rotor;
}
center = bary / nbVertices;
//computing details vector on vertices
for (unsigned int i = 0; i < nbVertices; ++i)
//computing deformation vector on vertices
VEC3 vel = velocity_.normalized();
for(unsigned int i = 0; i < nbVertices; ++i)
{
VEC3 v(vertices[i]-center);
if(v*velocity_>=0)
{
verticesDetails[i] = v*2.0f;
}
else
verticesDetails[i] = VEC3(0);
VEC3 v(vertices[i] - center);
VEC3 vN = v.normalized();
float dot = vN * vel;
verticesDeformation[i] = v * 2.0f * (dot+1.0f)/2.0f;
}
//-------- code ajoute par Arash pour les obstacles rectangulaires --------------
......
......@@ -57,6 +57,7 @@ void Simulator::init( float dimension, unsigned int nbAgent, unsigned int nbObst
envMap_.init(config, 1600.0f, 1200.0f, minSize, 400.0f) ; //svg import
setupScenario(nbAgent) ;
addPathsToAgents();
// SelectorCellNotMarked<PFP::MAP> scnm(envMap_.pedWayMark);
addMovingObstacles(nbObst);
addPathToObstacles();
break;
......@@ -662,7 +663,8 @@ void Simulator::addMovingObstacle(Dart d, unsigned int obstType)
{
MovingMesh * mm = new MovingMesh(envMap_, d, "meshRessources/Limace.ply");
movingMeshes_.push_back(mm);
vPos = mm->computeProjectedPointSet();
float maxHeight=1.0f;
vPos = mm->computeProjectedPointSet(maxHeight);
}
break;
default:
......@@ -714,6 +716,19 @@ void Simulator::addPathToObstacle(MovingObstacle * mo, Dart dStart, Dart dGoal)
mo->goals_.push_back(dest) ;
}
path = CGoGN::PathFinder::pathFindAStar<PFP>(envMap_,
envMap_.position,
dGoal,
dStart,
envMap_.buildingMark) ;
for (std::vector<Dart>::iterator it = path.begin() ; it != path.end() ; ++it)
{
VEC3 dest = Algo::Geometry::faceCentroid<PFP>(envMap_.map, *it, envMap_.position) ;
mo->goals_.push_back(dest) ;
}
}
#ifndef SPATIAL_HASHING
......
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