Commit 72b44877 authored by pitiot's avatar pitiot

Merge fini

parent d8445613
......@@ -43,6 +43,7 @@ add_executable( socialAgentsD
../src/gl2ps.c
../src/ShapeMatching/rigidXfComputation.cpp
../src/shaderCustom.cpp
../src/shaderCustomTex.cpp
${socialAgents_moc}
${socialAgents_ui}
)
......
......@@ -43,6 +43,7 @@ add_executable( socialAgents
../src/gl2ps.c
../src/ShapeMatching/rigidXfComputation.cpp
../src/shaderCustom.cpp
../src/shaderCustomTex.cpp
${socialAgents_moc}
${socialAgents_ui}
)
......
......@@ -7,7 +7,10 @@
#include "env_map.h"
#include "spatialHashing.h"
//#define SECURED
#define EXPORTING_AGENT
//#define EXPORTING_OBJ
#ifdef SECURED
#include "Algo/MovingObjects/particle_cell_2D_secured.h"
......@@ -15,6 +18,19 @@
#include "Algo/MovingObjects/particle_cell_2D.h"
#endif
#ifdef EXPORTING_AGENT
#include "Utils/vbo.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#endif
#ifdef EXPORTING_OBJ
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/vbo.h"
#include "Algo/Import/importObjTex.h"
#include "shaderCustomTex.h"
#endif
class Simulator ;
class Agent
......@@ -24,6 +40,8 @@ public:
Agent(Simulator* sim, const VEC3& position, const VEC3& goals) ;
void init(const VEC3& start, const VEC3& goal);
void initGL();
void draw();
VEC3 getPosition() ;
......@@ -50,6 +68,32 @@ public:
std::vector<std::pair<float, Obstacle*> > obstacleNeighbors_ ;
std::vector<std::pair<float, Obstacle*> > movingObstacleNeighbors_;
#ifdef EXPORTING_AGENT
static const int m_ghost_nb = 500;
std::list<VEC3> m_ghost_previousPos;
Utils::VBO * m_ghost_VBO;
Utils::ShaderSimpleColor * m_ghost_shader;
#endif
#ifdef EXPORTING_OBJ
PFP2::MAP map;
VertexAttribute<VEC3> position;
VertexAttribute<VEC3> normal;
VEC3 previousPos;
float previousRot;
Algo::Render::GL2::MapRender* m_render;
Utils::VBO* m_positionVBO;
Utils::VBO* m_normalVBO;
Utils::Texture<2,Geom::Vec3uc>* m_texture;
Utils::VBO* m_texcoordVBO;
ShaderCustomTex* m_shaderTex;
Algo::Surface::Import::OBJModel<PFP2> m_obj;
unsigned int m_nbIndices;
#endif
#ifdef SPATIAL_HASHING
VEC3 pos ;
#else
......
......@@ -606,15 +606,16 @@ void generatePlanet(EnvMap& envMap)
{
unsigned int nx = envMap.geometry.size(0) / envMap.maxCellSize ;
unsigned int ny = envMap.geometry.size(1) / envMap.maxCellSize ;
if (nx < 1) nx = 1 ;
if (ny < 1) ny = 1 ;
if (nx < 1)
nx = 1 ;
if (ny < 1)
ny = 1 ;
Algo::Surface::Modelisation::Polyhedron<PFP> prim(envMap.map, envMap.position) ;
prim.cylinder_topo(nx, ny, true, true) ;
double pi = 3.14159265358979323846f ;
double xRadius = envMap.geometry.size(0) / 2 * pi ;
double yRadius = envMap.geometry.size(1) / 2 * pi ;
double xRadius = envMap.geometry.size(0) / 2 * M_PI;
double yRadius = envMap.geometry.size(1) / 2 * M_PI ;
prim.embedSphere((xRadius+yRadius)/2.0f) ;
}
......@@ -624,6 +625,7 @@ typename PFP::VEC3 parametrization(typename PFP::VEC3 p, float r,const Geom::Bou
{
p[0] = 2.0f*M_PI*(p[0]-bb.min()[0])/bb.size(0);
p[1] = ((2.0f*M_PI*(p[1]-bb.min()[1])/bb.size(1))-M_PI)/2.0f;
r += p[2];
return typename PFP::VEC3(2.0f*r*cos(p[0])*cos(p[1]),
2.0f*r*sin(p[0])*cos(p[1]),
......
......@@ -32,6 +32,15 @@ class ArticulatedObstacle;
#include "pfp.h"
#define EXPORTING3
#ifdef EXPORTING3
#include "Utils/Shaders/shaderPhongTexture.h"
#include "Utils/Shaders/shaderSimpleTexture.h"
#include "shaderCustomTex.h"
#include "Algo/Import/importObjTex.h"
#endif
class EnvMap
{
public:
......@@ -52,6 +61,9 @@ public:
EnvMap() ;
void init(unsigned int config, REAL width, REAL height, REAL minSize, REAL maxSize) ;
void initGL();
void draw();
void scale(float val);
void markPedWay() ;
......@@ -96,6 +108,8 @@ public:
PFP::TVEC3 position ;
PFP::TVEC3 normal ;
Geom::BoundingBox<PFP::VEC3> bb;
PFP::MAP mapScenary ;
PFP::TVEC3 positionScenary ;
PFP::TVEC3 normalScenary ;
......@@ -112,6 +126,32 @@ public:
void popObstNeighborInCells(Obstacle* o, Dart d);
void find_next(Obstacle* o,Dart * d, CellMarkerMemo<FACE>& cms);
#ifdef EXPORTING3
std::vector<PFP::MAP *> m_map_Export;
std::vector<Algo::Surface::Import::OBJModel<PFP2> *> m_obj_Export;
std::vector<Utils::Texture<2,Geom::Vec3uc>*> m_texture_Export;
std::vector<Utils::VBO*> m_positionVBO_Export;
std::vector<Utils::VBO*> m_normalVBO_Export;
std::vector<Utils::VBO*> m_texcoordVBO_Export;
std::vector<ShaderCustomTex*> m_shaderTex_Export;
std::vector<unsigned int> m_nbIndice_Export;
// PFP2::MAP m_map_Export;
// VertexAttribute<VEC3> position_Export ;
// VertexAttribute<VEC3> normal_Export ;
// Algo::Surface::Import::OBJModel<PFP2> * m_obj_Export;
//
// Utils::Texture<2,Geom::Vec3uc>* m_texture_Export;
// Utils::VBO* m_positionVBO_Export;
// Utils::VBO* m_normalVBO_Export;
// Utils::VBO* m_texcoordVBO_Export;
// ShaderCustomTex* m_shaderTex_Export;
//
// unsigned int m_nbIndice_Export;
#endif
std::vector<Dart> newBuildings ;
......@@ -247,15 +287,15 @@ inline void EnvMap::pushAgentInCells(Agent* agent, Dart d)
// assert(std::find(agentvect[d].begin(), agentvect[d].end(), agent) == agentvect[d].end());
// map.check();
TraversorF<PFP::MAP> tF(map);
for(Dart ddd = tF.begin() ; ddd != tF.end() ; ddd = tF.next())
{
if(std::find(agentvect[ddd].begin(), agentvect[ddd].end(), agent) != agentvect[ddd].end())
std::cout <<agent << " SO WRONG ADD" <<ddd.index<< std::endl;
if(std::find(neighborAgentvect[ddd].begin(), neighborAgentvect[ddd].end(), agent) != neighborAgentvect[ddd].end())
std::cout <<agent<< " SO SO WRONG ADD" <<ddd.index<< std::endl;
}
// TraversorF<PFP::MAP> tF(map);
// for(Dart ddd = tF.begin() ; ddd != tF.end() ; ddd = tF.next())
// {
// if(std::find(agentvect[ddd].begin(), agentvect[ddd].end(), agent) != agentvect[ddd].end())
// std::cout <<agent << " SO WRONG ADD" <<ddd.index<< std::endl;
//
// if(std::find(neighborAgentvect[ddd].begin(), neighborAgentvect[ddd].end(), agent) != neighborAgentvect[ddd].end())
// std::cout <<agent<< " SO SO WRONG ADD" <<ddd.index<< std::endl;
// }
addElementToVector<Agent*>(agentvect[d],agent);
// agentvect[d].push_back(agent) ;
......@@ -267,7 +307,11 @@ inline void EnvMap::pushAgentInCells(Agent* agent, Dart d)
Dart ddd = map.alpha1(map.alpha1(dd)) ;
while (ddd != dd)
{
addElementToVector<Agent*>(neighborAgentvect[ddd],agent);
if (!map.isBoundaryMarked2(ddd))
{
addElementToVector<Agent*>(neighborAgentvect[ddd],agent);
}
// neighborAgentvect[ddd].push_back(agent) ;
// nbAgentsIncrease(ddd);
ddd = map.alpha1(ddd) ;
......@@ -289,22 +333,25 @@ inline void EnvMap::popAgentInCells(Agent* agent, Dart d)
Dart ddd = map.alpha1(map.alpha1(dd)) ;
while (ddd != dd)
{
removeElementFromVector<Agent*>(neighborAgentvect[ddd], agent) ;
if (!map.isBoundaryMarked2(ddd))
{
removeElementFromVector<Agent*>(neighborAgentvect[ddd], agent) ;
}
// nbAgentsDecrease(ddd) ;
ddd = map.alpha1(ddd) ;
}
dd = map.phi1(dd) ;
} while (dd != d) ;
TraversorF<PFP::MAP> tF(map);
for(Dart ddd = tF.begin() ; ddd != tF.end() ; ddd = tF.next())
{
if(std::find(agentvect[ddd].begin(), agentvect[ddd].end(), agent) != agentvect[ddd].end())
std::cout <<agent << " SO WRONG" <<ddd.index<< std::endl;
if(std::find(neighborAgentvect[ddd].begin(), neighborAgentvect[ddd].end(), agent) != neighborAgentvect[ddd].end())
std::cout <<agent<< " SO SO WRONG " <<ddd.index<< std::endl;
}
// TraversorF<PFP::MAP> tF(map);
// for(Dart ddd = tF.begin() ; ddd != tF.end() ; ddd = tF.next())
// {
// if(std::find(agentvect[ddd].begin(), agentvect[ddd].end(), agent) != agentvect[ddd].end())
// std::cout <<agent << " SO WRONG" <<ddd.index<< std::endl;
//
// if(std::find(neighborAgentvect[ddd].begin(), neighborAgentvect[ddd].end(), agent) != neighborAgentvect[ddd].end())
// std::cout <<agent<< " SO SO WRONG " <<ddd.index<< std::endl;
// }
}
......
......@@ -13,15 +13,20 @@
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Qt/qtSimple.h"
using namespace std;
#include "Utils/Shaders/shaderSimpleTexture.h"
#include "Algo/Import/importObjTex.h"
using namespace std;
//#define EXPORTING2
class MovingMesh
{
public:
MovingMesh(EnvMap& envMap, Dart d, std::string filename);
void initGL();
void linkWithObstacle(MovingObstacle * mo);
void transform(Geom::Matrix44f m);
......@@ -40,14 +45,26 @@ public:
PFP::MAP& motherMap;
VertexAttribute<VEC3>& motherPosition;
PFP::MAP map;
PFP2::MAP map;
VertexAttribute<VEC3> position;
VertexAttribute<VEC3> normal;
Algo::Render::GL2::MapRender* m_render;
Utils::VBO* m_positionVBO;
Utils::VBO* m_normalVBO;
#ifdef EXPORTING2
Utils::Texture<2,Geom::Vec3uc>* m_texture;
Utils::VBO* m_texcoordVBO;
ShaderCustomTex* m_shaderTex;
// Utils::ShaderPhongTexture* m_shaderTex;
// Utils::ShaderSimpleTexture* m_shaderTex;
Algo::Surface::Import::OBJModel<PFP2> m_obj;
unsigned int m_nbIndices;
#else
Utils::ShaderSimpleColor* m_simpleColorShader;
#endif
float scaleValue;
......
......@@ -8,6 +8,15 @@
#include <set>
#include "Algo/MovingObjects/particle_cell_2D_memo.h"
//#define EXPORTING_BOXES
#ifdef EXPORTING_BOXES
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderFlat.h"
#include "Utils/vbo.h"
#endif
using namespace std;
PFP::VEC3 rotate (PFP::VEC3 pos1, PFP::VEC3 center, float angle);
float get_angle (PFP::VEC3 v1, PFP::VEC3 v2);
......@@ -19,6 +28,9 @@ class MovingObstacle
{
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();
bool test_opposition(VEC3 o, VEC3 p1, VEC3 p2);
// void contournerBatiment();
void updateAgentNeighbors() ;
......@@ -53,6 +65,13 @@ public:
Dart groundFace;
#ifdef EXPORTING_BOXES
Algo::Render::GL2::MapRender* m_render;
Utils::VBO* m_positionVBO;
Utils::VBO* m_normalVBO;
Utils::ShaderSimpleColor* m_shader;
#endif
//vector de détails pour la deformation
// std::vector<PFP::VEC3> verticesDeformation;
......
......@@ -24,6 +24,13 @@ struct PFP : public PFP_STANDARD
typedef NoMathIONameAttribute<std::pair<bool, bool> > BOOLATTRIB ;
} ;
struct PFP2 : public PFP_STANDARD
{
// definition de la carte
// typedef EmbeddedMap2 MAP ;
typedef Algo::Surface::IHM::ImplicitHierarchicalMap MAP ;
} ;
typedef PFP::VEC3 VEC3 ;
typedef PFP::REAL REAL ;
......
......@@ -94,7 +94,7 @@ public:
void setupCorridorScenario(unsigned int nbAgents, unsigned int nbObstacles) ;
void setupSnakeCorridorScenario(unsigned int nbAgents, unsigned int nbSnakes, int snakeSize) ;
void setupCityScenario(int nbLines, int nbRank) ;
void setupScenario(unsigned int nbMaxAgent, bool path) ;
void setupScenario(unsigned int nbMaxAgent, bool pedWay=false) ;
void addMovingObstacles(unsigned int nb);
void addMovingObstacle(Dart d, unsigned int obstType=0);
......@@ -112,7 +112,6 @@ public:
bool importAgents(std::string filename) ;
bool exportAgents(std::string filename) ;
void checkRegistering();
void swapAgentsGoals() ;
Geom::BoundingBox<VEC3> getAgentsBB() ;
......
......@@ -83,8 +83,7 @@ public:
void exportInfoFace(std::ofstream& out, Dart d) ;
bool exportScenePov(PFP::MAP& map, PFP::TVEC3& position, const std::string& filename,
PFP::VEC3 cameraPos, PFP::VEC3 cameraLook, PFP::VEC3 translate,
float angle_X, float angle_Y, float angle_Z,
const FunctorSelect& good = SelectorTrue()) ;
float angle_X, float angle_Y, float angle_Z) ;
#endif
void cb_keyPress(int keycode) ;
......
This diff is collapsed.
This diff is collapsed.
......@@ -4,49 +4,100 @@
MovingMesh::MovingMesh(EnvMap& envMap, Dart d, std::string filename):
motherMap(envMap.map),
motherPosition(envMap.position),
#ifdef EXPORTING2
m_obj(map),
#endif
constrainedV(map)
{
std::vector<std::string> attrNames ;
if(!Algo::Surface::Import::importMesh<PFP>(map, filename.c_str(), attrNames))
#ifdef EXPORTING2
m_obj.import(filename,attrNames);
#else
if(!Algo::Surface::Import::importMesh<PFP2>(map, filename.c_str(), attrNames))
{
CGoGNerr << "could not import " << filename << CGoGNendl ;
return;
}
normal = map.addAttribute<VEC3, VERTEX>("normal") ;
#endif
position = map.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
normal = map.addAttribute<VEC3, VERTEX>("normal");
float area = Algo::Surface::Geometry::convexFaceArea<PFP>(envMap.map, d, envMap.position);
scaleValue = std::max(area/1400.0f,10.0f);
std::cout << "scaleVal " << scaleValue << std::endl;
// scaleValue = 4.0f;
scale(scaleValue/1.8f);
// scale(2.5f);
// scale(0.5f);
// Geom::Matrix44f m;
// m.identity();
// VEC3 axis(1.0f,0.0f,0.0f);
// Geom::rotate(axis, float(M_PI/2.0f),m);
// transform(m);
VEC3 v = Algo::Surface::Geometry::faceCentroid<PFP>(motherMap, d, motherPosition) ;
translate(v);
// TraversorV<PFP::MAP> tv(map);
// std::vector<Dart> obstDarts;
// for(Dart dd = tv.begin() ; dd != tv.end() ; dd = tv.next())
// {
// obstDarts.push_back(dd);
// }
//
// smg = new ShapeMatchingQuadratic<PFP>(map,position,obstDarts,0.5f);
// smg->initialize();
map.enableQuickTraversal<VERTEX>();
}
void MovingMesh::initGL()
{
//rendering
m_render = new Algo::Render::GL2::MapRender();
m_positionVBO = new Utils::VBO();
m_normalVBO = new Utils::VBO();
#ifdef EXPORTING2
m_texcoordVBO = new Utils::VBO();
m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
if (m_texture->load("./meshRessources/limace.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 = new Utils::ShaderSimpleTexture();
m_shaderTex->setAttributePosition(m_positionVBO);
m_shaderTex->setAttributeTexCoord(m_texcoordVBO);
// m_shaderTex->setAttributeNormal(m_normalVBO);
m_shaderTex->setTextureUnit(GL_TEXTURE0);
m_shaderTex->setTexture(m_texture);
// m_shaderTex->setShininess(10.0f);
// m_shaderTex->setAmbient(0.1f);
// m_shaderTex->setSpecular(Geom::Vec4f(0.5));
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);
#else
m_simpleColorShader = new Utils::ShaderSimpleColor();
m_simpleColorShader->setAttributePosition(m_positionVBO);
m_simpleColorShader->setColor(Geom::Vec4f(0.,1.,0.,0.));
m_positionVBO->updateData(position) ;
m_render->initPrimitives<PFP2>(map, Algo::Render::GL2::TRIANGLES) ;
m_render->initPrimitives<PFP2>(map, Algo::Render::GL2::LINES) ;
#endif
m_normalVBO->updateData(normal) ;
}
......@@ -57,7 +108,7 @@ void MovingMesh::linkWithObstacle(MovingObstacle * mo)
void MovingMesh::transform(Geom::Matrix44f m)
{
TraversorV<PFP::MAP> tv(map);
TraversorV<PFP2::MAP> tv(map);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
position[d] = Geom::transform(position[d],m);
......@@ -66,7 +117,7 @@ void MovingMesh::transform(Geom::Matrix44f m)
void MovingMesh::translate(VEC3 v)
{
TraversorV<PFP::MAP> tv(map);
TraversorV<PFP2::MAP> tv(map);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
position[d] += v;
......@@ -75,7 +126,7 @@ void MovingMesh::translate(VEC3 v)
void MovingMesh::scale(float val)
{
TraversorV<PFP::MAP> tv(map);
TraversorV<PFP2::MAP> tv(map);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
position[d] *= val;
......@@ -95,7 +146,7 @@ void MovingMesh::moveInFace(PFP::MAP& motherMap, Dart d, VertexAttribute<VEC3> p
Geom::rotate(axis, -angle, rot) ;
Geom::translate(b[0],b[1],b[2],rot);
TraversorV<PFP::MAP> tv(map);
TraversorV<PFP2::MAP> tv(map);
for(Dart dd = tv.begin() ; dd != tv.end() ; dd = tv.next())
{
position[dd] = Geom::transform(position[dd],rot);
......@@ -117,23 +168,11 @@ void MovingMesh::moveInFace(PFP::MAP& motherMap, Dart d, VertexAttribute<VEC3> p
void MovingMesh::move()
{
std::cout << "move squeleton" << std::endl;
std::cout << "compute deformation with SM-Quad" << std::endl;
std::cout << "apply to mesh" << std::endl;
std::cout << "project bottom points in plane ?" << std::endl;
std::cout << "apply to moving object" << std::endl;
std::cout << "register moving object" << std::endl;
}
void MovingMesh::animate()
{
smg->animate();
// TraversorV<typename PFP::MAP> tv(map);
// for(Dart dd = tv.begin() ; dd != tv.end() ; dd = tv.next())
// {
// if(!constrainedV.isMarked(dd))
// position[dd] = smg->goal[dd];
// }
for(std::vector<Dart>::iterator it = smg->m_darts.begin() ; it != smg->m_darts.end() ; ++it)
{
......@@ -144,21 +183,36 @@ void MovingMesh::animate()
void MovingMesh::draw()
{
#ifdef EXPORTING2
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();
#else
m_positionVBO->updateData(position) ;
m_render->initPrimitives<PFP>(map, allDarts, Algo::Render::GL2::TRIANGLES) ;
m_simpleColorShader->setColor(Geom::Vec4f(1.0,0.627,0.0,0.));
m_render->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES);
m_simpleColorShader->setColor(Geom::Vec4f(0.0,0.0,0.0,0.));
m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES);
#endif
}
std::vector<VEC3> MovingMesh::computeProjectedPointSet(float maxHeight)
{
std::vector<VEC3> points;
TraversorV<PFP::MAP> tv(map);
TraversorV<PFP2::MAP> tv(map);
for(Dart dd = tv.begin() ; dd != tv.end() ; dd = tv.next())
{
if(position[dd][2]<maxHeight)
{
points.push_back(position[dd]);
}
}
points = jarvisConvexHull(points);
......@@ -180,6 +234,7 @@ std::vector<VEC3> MovingMesh::computeProjectedPointSet(float maxHeight)
{
if(active[i])
res.push_back(points[i]);
// std::cout << "fin " << points[i] << std::endl;
}
std::cout << "nb vertices before simplification -> " << points.size() << std::endl;
......@@ -235,7 +290,7 @@ std::vector<VEC3> MovingMesh::jarvisConvexHull(const std::vector<VEC3>& pointSet
if(pointSet[i][1]>pointSet[minPoint][1])
minPoint=i;
// convHull.push_back(minPoint);
res.push_back(pointSet[minPoint]);
curr = minPoint;
do {
......@@ -263,7 +318,6 @@ std::vector<VEC3> MovingMesh::jarvisConvexHull(const std::vector<VEC3>& pointSet
if(trouve)
{
curr = i-1;
// convHull.push_back(curr);
res.push_back(pointSet[curr]);
}
else
......@@ -274,11 +328,6 @@ std::vector<VEC3> MovingMesh::jarvisConvexHull(const std::vector<VEC3>& pointSet
} while(curr != minPoint);
// res.reserve(convHull.size());
//
// for(std::vector<unsigned int>::iterator it = convHull.begin() ; it != convHull.end() ; ++it)
// res.push_back(pointSet[*it]);
return res;
}
......
......@@ -137,14 +137,14 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
d = map.phi1(d);
}
//extrude face to build a cage
// compute edgeLength for mass-spring
Algo::Surface::Modelisation::extrudeFace<PFP>(map, position, groundFace, -5.0f) ;
map.fillHole(groundFace);
groundFace = map.phi2(groundFace);
if(!rigid_)
{
//extrude face to build a cage
// compute edgeLength for mass-spring
Algo::Surface::Modelisation::extrudeFace<PFP>(map, position, groundFace, 10.0f) ;
map.fillHole(groundFace);
groundFace = map.phi2(groundFace);
Algo::Surface::Modelisation::EarTriangulation<PFP> et(map);
et.triangule();
......@@ -198,6 +198,11 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
for (unsigned int i = 0; i < nbVertices; ++i)
{
position[d]+=rotate(position[d], center, angle);
#ifdef EXPORTING_BOXES
Dart d(i);
position[map.phi<211>(d)] += rotate(position[map.phi<211>(d)], center, -angle);
#endif
parts_[i]->move(position[d]);
d = map.phi1(d);
......@@ -219,6 +224,44 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
}
}
void MovingObstacle::initGL()
{
#ifdef EXPORTING_BOXES
m_render = new Algo::Render::GL2::MapRender();
m_positionVBO = new Utils::VBO();
// using simple shader with color
m_shader = new Utils::ShaderSimpleColor();
m_shader->setAttributePosition(m_positionVBO);
m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.));
// m_shader->setAmbiant(Geom::Vec4f(0.,1.,0.,0.));
// m_shader->setDiffuse(Geom::Vec4f(0.,1.,0.,0.));
m_positionVBO->updateData(position) ;
m_render->initPrimitives<PFP>(map, Algo::Render::GL2::LINES,false) ;
m_render->initPrimitives<PFP>(map, Algo::Render::GL2::TRIANGLES,false) ;
// registerShader(m_shader);
#endif
}
void MovingObstacle::draw()
{
#ifdef EXPORTING_BOXES
// m_render->initPrimitives<PFP>(map, Algo::Render::GL2::LINES,false) ;
// m_render->initPrimitives<PFP>(map, Algo::Render::GL2::TRIANGLES,false) ;
m_positionVBO->updateData(position);
m_shader->setColor(Geom::Vec4f(1.,0.,0.,0.));
m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES);
m_shader->setColor(Geom::Vec4f(0.,0.,0.,0.));
m_render->draw(m_shader, Algo::Render::GL2::LINES);
#endif
}
VEC3 MovingObstacle::getDilatedPosition(unsigned int ind)
{
Dart d(ind); //WARNING : works only for one face created at start !
......@@ -515,14 +558,17 @@ void MovingObstacle::update()
//stretch spring : /!\ max rigidity relative to the timestep used (unstable otherwise)
float norm = v1.norm();
float rigidity = 50.0f;
float rigidity = 70.0f;
float stretch = rigidity*(edgeLength[dd]-v1.norm());
VEC3 f = stretch*(v1/norm);
if(norm>0.0f)
{
VEC3 f = stretch*(v1/norm);
//apply force symmetrically
forces[dd] -= f;
forces[map.phi1(dd)] += f;
//apply force symmetrically