Merge fini
Showing
... | ... | @@ -27,6 +27,9 @@ float Agent::rangeSq_ = range_ * range_ ; |
unsigned int Agent::cptAgent = 0 ; | ||
Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal, Dart d) : | ||
#ifdef EXPORTING_OBJ | ||
m_obj(map), | ||
#endif | ||
#ifdef SPATIAL_HASHING | ||
pos(position), | ||
#else | ||
... | ... | @@ -44,6 +47,9 @@ Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal, Dart d) : |
} | ||
Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal) : | ||
#ifdef EXPORTING_OBJ | ||
m_obj(map), | ||
#endif | ||
#ifdef SPATIAL_HASHING | ||
pos(position), | ||
#else | ||
... | ... | @@ -62,6 +68,12 @@ Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal) : |
void Agent::init(const VEC3& start, const VEC3& goal) | ||
{ | ||
#ifdef EXPORTING_OBJ | ||
std::vector<std::string> attrNames ; | ||
m_obj.import("./meshRessources/Mexicainlowres.obj",attrNames); | ||
position = map.getAttribute<VEC3, VERTEX>(attrNames[0]) ; | ||
#endif | ||
#ifdef SPATIAL_HASHING | ||
sim->envMap_.addAgentInGrid(this) ; | ||
#endif | ||
... | ... | @@ -88,9 +100,97 @@ void Agent::init(const VEC3& start, const VEC3& goal) |
movingObstacles_ = new MovingObstacle* [maxMovingObstacles_]; | ||
nb_mos=0; | ||
agentNo = cptAgent++ ; | ||
CGoGNout<<this<<" = agent n°"<<agentNo<<CGoGNendl; | ||
// CGoGNout<<this<<" = agent n°"<<agentNo<<CGoGNendl; | ||
} | ||
void Agent::initGL() | ||
{ | ||
#ifdef EXPORTING_AGENT | ||
m_ghost_shader = new Utils::ShaderSimpleColor(); | ||
m_ghost_shader->setColor(Geom::Vec4f(1.,0.,0.,0.)); | ||
// m_ghost_shader->setAmbiant(Geom::Vec4f(1.,1.,0.,0.)) ; | ||
// m_ghost_shader->setDiffuse(Geom::Vec4f(1.,1.,0.,0.)); | ||
m_ghost_VBO = new Utils::VBO(); | ||
m_ghost_VBO->setDataSize(3); | ||
m_ghost_VBO->allocate(m_ghost_nb); | ||
m_ghost_shader->setAttributePosition(m_ghost_VBO); | ||
// registerShader(m_ghost_shader); | ||
#endif | ||
#ifdef EXPORTING_OBJ | ||
m_texcoordVBO = new Utils::VBO(); | ||
m_positionVBO = new Utils::VBO(); | ||
m_normalVBO = new Utils::VBO(); | ||
m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE); | ||
if (m_texture->load("./meshRessources/sombrero2lowres_grp.png")) | ||
m_texture->update(); | ||
else | ||
std::cout << "problem : loading texture" << std::endl; | ||
m_texture->setWrapping(GL_CLAMP_TO_EDGE); | ||
m_shaderTex = new ShaderCustomTex(); | ||
m_shaderTex->setAttributePosition(m_positionVBO); | ||
m_shaderTex->setAttributeTexCoord(m_texcoordVBO); | ||
m_shaderTex->setTextureUnit(GL_TEXTURE0); | ||
m_shaderTex->setTexture(m_texture); | ||
glEnable(GL_TEXTURE_2D); | ||
if (!m_obj.hasNormals()) | ||
{ | ||
normal = map.getAttribute<VEC3, VERTEX>("normal") ; | ||
if(!normal.isValid()) | ||
normal = map.addAttribute<VEC3, VERTEX>("normal") ; | ||
Algo::Surface::Geometry::computeNormalVertices<PFP2>(map, m_obj.m_positions, normal) ; | ||
m_obj.setNormalAttribute(normal); | ||
} | ||
map.setBrowser(NULL); | ||
m_nbIndices = m_obj.createSimpleVBO_PTN(m_positionVBO,m_texcoordVBO,m_normalVBO); | ||
previousPos = VEC3(0,0,0); | ||
#endif | ||
} | ||
void Agent::draw() | ||
{ | ||
#ifdef EXPORTING_AGENT | ||
PFP::VEC3* data = static_cast<PFP::VEC3*>(m_ghost_VBO->lockPtr()); | ||
unsigned int i = 0; | ||
for(std::list<VEC3>::iterator it = m_ghost_previousPos.begin() ; it != m_ghost_previousPos.end() ; ++it, ++i) | ||
{ | ||
data[i] = *it; | ||
} | ||
m_ghost_VBO->releasePtr(); | ||
m_ghost_shader->enableVertexAttribs(); | ||
glDrawArrays(GL_LINE_STRIP, 0, m_ghost_previousPos.size()); | ||
m_ghost_shader->disableVertexAttribs(); | ||
#endif | ||
#ifdef EXPORTING_OBJ | ||
Algo::Surface::Geometry::computeNormalVertices<PFP2>(map, m_obj.m_positions, normal) ; | ||
m_nbIndices = m_obj.createSimpleVBO_PTN(m_positionVBO,m_texcoordVBO,m_normalVBO); | ||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | ||
m_shaderTex->activeTexture(); | ||
m_shaderTex->enableVertexAttribs(); | ||
glDrawArrays(GL_TRIANGLES, 0, m_nbIndices); | ||
m_shaderTex->disableVertexAttribs(); | ||
#endif | ||
} | ||
//----------------------------------------------------------------- | ||
//----------------------------------------------------------------- | ||
... | ... | @@ -217,7 +317,7 @@ void Agent::updateObstacleNeighbors() |
if ((obstacleNeighbors_.size() < maxMovingObstacles_|| distSq < maxDistObst) | ||
&& 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 > maxDistObst) | ||
... | ... | @@ -236,7 +336,7 @@ void Agent::updateObstacleNeighbors() |
if ((movingObstacleNeighbors_.size() < maxMovingObstacles_ || 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) | ||
... | ... | @@ -253,37 +353,37 @@ void Agent::updateObstacleNeighbors() |
for(std::vector<Obstacle*>::const_iterator it = neighborObst.begin() ; it != neighborObst.end() ; ++it) | ||
{ | ||
if ((*it)->mo==NULL) | ||
{ | ||
float distSq = distSqPointLineSegment((*it)->p1, (*it)->p2, part_.getPosition()) ; | ||
if ((obstacleNeighbors_.size() < maxNeighbors_ || distSq < maxDistObst) | ||
&&distSq < rangeSq_) | ||
{ | ||
if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT) | ||
{ | ||
float distSq = distSqPointLineSegment((*it)->p1, (*it)->p2, part_.getPosition()) ; | ||
if ((obstacleNeighbors_.size() < maxNeighbors_ || distSq < maxDistObst) | ||
&&distSq < rangeSq_) | ||
{ | ||
// if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT) | ||
{ | ||
if (distSq > maxDistObst) maxDistObst = distSq ; | ||
obstacleNeighbors_.push_back(std::make_pair(distSq, *it)) ; | ||
} | ||
if (distSq > maxDistObst) maxDistObst = distSq ; | ||
obstacleNeighbors_.push_back(std::make_pair(distSq, *it)) ; | ||
} | ||
} | ||
else | ||
{ | ||
float distSq = distSqPointLineSegment((*it)->p1, (*it)->p2, part_.getPosition()) ; | ||
if ((movingObstacleNeighbors_.size() < maxNeighbors_ || distSq < maxDistMovingObst) | ||
&&distSq < rangeSq_) | ||
{ | ||
// if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT) | ||
{ | ||
if (distSq > maxDistMovingObst) maxDistMovingObst = distSq ; | ||
movingObstacleNeighbors_.push_back(std::make_pair(distSq, *it)) ; | ||
} | ||
} | ||
else | ||
{ | ||
float distSq = distSqPointLineSegment((*it)->p1, (*it)->p2, part_.getPosition()) ; | ||
if ((movingObstacleNeighbors_.size() < maxNeighbors_ || distSq < maxDistMovingObst) | ||
&&distSq < rangeSq_) | ||
{ | ||
if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT) | ||
{ | ||
} | ||
if (distSq > maxDistMovingObst) maxDistMovingObst = distSq ; | ||
movingObstacleNeighbors_.push_back(std::make_pair(distSq, *it)) ; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (obstacleNeighbors_.size() > maxNeighbors_) | ||
{ | ||
... | ... | @@ -321,7 +421,6 @@ void Agent::updateObstacleNeighbors() |
// } | ||
} | ||
//----------------------------------------------------------------- | ||
//----------------------------------------------------------------- | ||
... | ... | @@ -339,7 +438,13 @@ void Agent::update() |
#ifdef SECURED | ||
if(target != part_.getPosition()) | ||
std::cout << "Problem agent " << agentNo << " (position : " << part_.getPosition() << ") time " << sim_->globalTime_ << std::endl; | ||
std::cout << "Problem agent " << agentNo << " (position : " << part_.getPosition() << ") time " << sim_->nbSteps_ << std::endl; | ||
#endif | ||
#ifdef EXPORTING_AGENT | ||
m_ghost_previousPos.push_back(target); | ||
if(m_ghost_previousPos.size()>m_ghost_nb) | ||
m_ghost_previousPos.pop_front(); | ||
#endif | ||
#endif | ||
... | ... | @@ -351,6 +456,27 @@ void Agent::update() |
meanVelocity_[3] = velocity_ ; | ||
meanDirection_.normalize() ; | ||
} | ||
#ifdef EXPORTING_OBJ | ||
< |