Commit 2538a137 authored by Jund Thomas's avatar Jund Thomas
Browse files

adding details vectors on moving obstacles

parent b5f9230a
......@@ -56,9 +56,6 @@ public:
Dart finalDart ;
MovingObstacle **movingObstacles_;
int nb_mos;
MovingObstacle **movingObstacles_;
int nb_mos;
......
......@@ -46,11 +46,22 @@ inline void renderPredictionTriangle(EnvMap& m, Dart d, PFP::VEC3 p)
inline void renderObstacle(EnvMap& m, MovingObstacle * obst, bool showBelonging=false, bool renderPath = false)
{
glBegin(GL_POLYGON) ;
for (unsigned int i = 0 ; i < (obst->nbVertices) ; ++i)
{
const VEC3& p = obst->getPosition(i) ;
glVertex3fv(p.data()) ;
}
glEnd() ;
glColor3f(1.0,0.0,1.0);
glBegin(GL_LINE_LOOP) ;
for (unsigned int i = 0 ; i < (obst->nbVertices) ; ++i)
{
const VEC3& p = obst->vertices[i] ;
const VEC3& p = obst->getDilatedPosition(i) ;
glVertex3fv(p.data()) ;
}
glEnd() ;
......
......@@ -26,11 +26,15 @@ public:
void computeNewVelocity();
std::vector<Dart> getMemoCross(const VEC3& pos, const VEC3& dest, Dart& d1);
VEC3 getDilatedPosition(unsigned int ind); //vertex position with velocity dilatation
VEC3 getPosition(unsigned int ind); // vertex position
void update();
unsigned int nbVertices;
CGoGN::Algo::MovingObjects::ParticleCell2DMemo<PFP> *registering_part;
std::vector<PFP::VEC3> vertices;
std::vector<PFP::VEC3> verticesDetails;
float gravity_dist;
VEC3 center;
int nb_agents_voisins;
......
......@@ -6,7 +6,7 @@
class Obstacle
{
public:
Obstacle(const VEC3& point1, const VEC3& point2, const VEC3& prevPoint, const VEC3& nextPoint,
Obstacle(const VEC3 point1, const VEC3 point2, const VEC3 prevPoint, const VEC3 nextPoint,
MovingObstacle * moving1, unsigned int ind) :
p1(point1), p2(point2), prevP(prevPoint), nextP(nextPoint),
mo(moving1), index(ind)
......@@ -17,10 +17,10 @@ public:
// nextP[2] = 0 ;
}
const VEC3& p1 ;
const VEC3& p2 ;
const VEC3& prevP ;
const VEC3& nextP ;
VEC3 p1 ;
VEC3 p2 ;
VEC3 prevP ;
VEC3 nextP ;
MovingObstacle * mo ;
unsigned int index ;
} ;
......
......@@ -222,7 +222,7 @@ void Agent::updateObstacleNeighbors()
if ((movingObstacleNeighbors_.size() < maxNeighbors_ || distSq < maxDistMovingObst)
&&distSq < rangeSq_)
{
if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
// if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
{
if (distSq > maxDistMovingObst) maxDistMovingObst = distSq ;
......@@ -257,7 +257,7 @@ void Agent::updateObstacleNeighbors()
if ((movingObstacleNeighbors_.size() < maxNeighbors_ || distSq < maxDistMovingObst)
&&distSq < rangeSq_)
{
if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
// if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
{
if (distSq > maxDistMovingObst) maxDistMovingObst = distSq ;
......@@ -604,10 +604,10 @@ void Agent::computeNewVelocity() // de arash
//----- forces dues à la répulsion des autres agents -------
double ag_stiffness = 20.0; // agent-agent interaction stiffness
double ag_stiffness = 200.0; // agent-agent interaction stiffness
double ag_damping = 1.0; // agent-agent interaction damping
double ag_phys_radius_coef = 20.0;
double ag_power = 8; // the power to which elevate the agent-agent distance
double ag_power = 1; // the power to which elevate the agent-agent distance
unsigned int nbA = 0 ;
......
......@@ -74,7 +74,7 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
{
case 0 :
// CityGenerator::generateGrid<PFP>(*this) ;
CityGenerator::generateCity<PFP>(*this,1) ;
CityGenerator::generateCity<PFP>(*this,0) ;
break ;
case 1 :
CityGenerator::generateGrid<PFP>(*this) ;
......@@ -536,13 +536,11 @@ void EnvMap::pushObstacleInCells(Obstacle * o)// réenregistre l'obstacle en que
if (mo != NULL)
{
int n = o->index;
VEC3 p1 = mo->vertices[n];
VEC3 p2 = mo->vertices[(n+1)%(mo->nbVertices)];
Dart d1=NIL;
Dart d2=NIL;
std::vector<Dart> memo;
memo = mo->getMemoCross(p1,p2,d1);
memo = mo->getMemoCross(o->p1,o->p2,d1);
d2=mo->registering_part->d;
if(map.sameFace(d1,d2))
......@@ -559,8 +557,6 @@ void EnvMap::pushObstacleInCells(Obstacle * o)// réenregistre l'obstacle en que
void EnvMap::popAndPushObstacleInCells(Obstacle* o, int n)// maj de l'enregistrement
{
MovingObstacle * mo = o->mo;
VEC3 p1 = mo->vertices[n];
VEC3 p2 = mo->vertices[(n+1)%mo->nbVertices];
Dart d1=NIL;
Dart d2=NIL;
......@@ -571,7 +567,7 @@ void EnvMap::popAndPushObstacleInCells(Obstacle* o, int n)// maj de l'enregistre
// if(p1->crossCell != CGoGN::Algo::MovingObjects::NO_CROSS
// || p2->crossCell != CGoGN::Algo::MovingObjects::NO_CROSS)
// {
memo = mo->getMemoCross(p1,p2,d1);
memo = mo->getMemoCross(o->p1,o->p2,d1);
d2=mo->registering_part->d;
// memo.sort();
// modif=true;
......@@ -720,7 +716,8 @@ void EnvMap::refine()
subdivisable = sf.second ;
else
{
float minSizeSq = minCellSize * minCellSize ; // diametre de vision de l'agent au carré
// float minSizeSq = minCellSize * minCellSize ; // diametre de vision de l'agent au carré
float minSizeSq = Agent::neighborDistSq_;
fLevel = map.faceLevel(old) ;
map.setCurrentLevel(fLevel) ;
......
......@@ -14,23 +14,22 @@ float MovingObstacle::detectionFixedObst = 50;
bool MovingObstacle::is_inside(VEC3 p)
{
VEC3 vec, norm;
Obstacle * obst;
for (unsigned int i = 0; i < nbVertices; i++)
{
obst = this->obstacles_[i];
vec = VEC3(obst->p2 - obst->p1);
norm[0] = vec[1];
norm[1] = -vec[0];
vec = VEC3(obst->p2 -p);
if (vec*norm < 0)
return false;
}
return true;
return false;
// VEC3 vec, norm;
// Obstacle * obst;
//
// for (unsigned int i = 0; i < nbVertices; i++)
// {
// vec = VEC3(getPosition(i+1 % nbVertices)- getPosition(i));
// norm[0] = vec[1];
// norm[1] = -vec[0];
//
// vec = VEC3(getPosition(i+1 % nbVertices) -p);
// if (vec*norm < 0)
// return false;
// }
//
// return true;
}
float get_angle(VEC3 v1, VEC3 v2) //renvoie l'angle entre [- pi ; Pi] du v2 à v1
......@@ -105,6 +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));
}
center = sum / nbVertices;
front=(vertices[1] + vertices[2]) / 2;
......@@ -155,6 +155,16 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
obstacle_range = 15.0f * 15.0f;
}
VEC3 MovingObstacle::getDilatedPosition(unsigned int ind)
{
return vertices[ind]+verticesDetails[ind];
}
VEC3 MovingObstacle::getPosition(unsigned int ind)
{
return vertices[ind];
}
bool MovingObstacle::test_opposition(VEC3 o, VEC3 p1, VEC3 p2)
{
o.normalize();
......@@ -368,9 +378,10 @@ void MovingObstacle::update()
target += rotate(vertices[i], center, abs_angle*rotor);
target += (velocity_ * sim_->timeStep_);
vertices[i]=target;
vertices[i] = target;
bary += target;
}
front=(vertices[1] + vertices[2]) / 2;
if(angle >0)
{
......@@ -383,6 +394,18 @@ void MovingObstacle::update()
center = bary / nbVertices;
//computing details vector on vertices
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);
}
//-------- code ajoute par Arash pour les obstacles rectangulaires --------------
VEC3 P0_P1 = vertices[1] - vertices[0];
......@@ -407,10 +430,10 @@ void MovingObstacle::update()
{
// CGoGNout << "avant une etape : Obstacle "<< i << CGoGNendl;
Obstacle* o = obstacles_[i];
// o->p1 = parts_[i]->getPosition();
// o->p2 = parts_[(i + 1) % nbVertices]->getPosition();
// o->prevP = parts_[(i - 1 + nbVertices) % nbVertices]->getPosition();
// o->nextP = parts_[(i + 2) % nbVertices]->getPosition();
o->p1 = getDilatedPosition(i);
o->p2 = getDilatedPosition((i+1) % nbVertices);
o->prevP = getDilatedPosition((i - 1 + nbVertices) % nbVertices);
o->nextP = getDilatedPosition((i + 2 + nbVertices) % nbVertices);
sim_->envMap_.popAndPushObstacleInCells(o,i);
......
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