Commit e8e94ed9 authored by Thomas Pitiot 's avatar Thomas Pitiot

pas bien

parent 2c736586
......@@ -78,11 +78,11 @@ public:
void initGL(); // initialisation GL
void draw(); // redessiner l'objet
void changeColor(Triangle *t, float distance);
// Algo::Render::GL2::MapRender* m_render; // render de l'objet
Algo::Render::GL2::MapRender* m_render_map; // render de l'objet
Algo::Render::GL2::ColorPerFaceRender * m_render;
Utils::VBO* m_positionVBO; //VBO
Utils::VBO* m_colorVBO;
// Utils::ShaderSimpleColor* m_simpleColorShader; // shader
Utils::ShaderSimpleColor* m_simpleColorShader; // shader
Utils::ShaderColorPerVertex * m_shader;
};
......
......@@ -6,8 +6,8 @@ class Surface;
class Triangle
{
public:
Triangle(VEC3 p1, VEC3 p2, VEC3 p3,Surface * surf =NULL,Dart d=NIL,float rouge=0,float green =0, float blue=1.0f) :
p1(p1),p2(p2),p3(p3),surf(surf),cell(d),r(rouge),g(green),b(blue),closest_point(p1)
Triangle(VEC3 p1, VEC3 p2, VEC3 p3,Surface * surf =NULL,Dart d=NIL,float rouge=0,float green =0, float blue=1.0f, int indexTri=0) :
p1(p1),p2(p2),p3(p3),surf(surf),cell(d),r(rouge),g(green),b(blue),closest_point(p1),indexTri(indexTri)
{
}
// colors
......@@ -18,6 +18,7 @@ public:
float g;
float b;
VEC3 closest_point;
int indexTri;
} ;
......
......@@ -117,11 +117,13 @@ inline VEC3 closestPointInTriangle(VEC3 p1, VEC3 p2, VEC3 p3, VEC3 obj)
{
if(t<0)
{
// CGoGNout<<"closest from "<<p1<<" in region 4"<<CGoGNendl;
s=0;
t=0; //region 4
}
else
{
// CGoGNout<<"closest from "<<p1<<" in region 3"<<CGoGNendl;
s=0;
if(e>=0)
{
......@@ -143,8 +145,10 @@ inline VEC3 closestPointInTriangle(VEC3 p1, VEC3 p2, VEC3 p3, VEC3 obj)
}
else
{
if(t<0)
{
// CGoGNout<<"closest from "<<p1<<" in region 5"<<CGoGNendl;
t=0;
if(d>=0)
{
......@@ -164,6 +168,7 @@ inline VEC3 closestPointInTriangle(VEC3 p1, VEC3 p2, VEC3 p3, VEC3 obj)
}
else
{
// CGoGNout<<"closest from "<<p1<<" in region 0"<<CGoGNendl;
float invDet = 1/det;
s*=invDet;
t*=invDet; //region 0
......@@ -177,6 +182,7 @@ inline VEC3 closestPointInTriangle(VEC3 p1, VEC3 p2, VEC3 p3, VEC3 obj)
{
if(s<0)
{
// CGoGNout<<"closest from "<<p1<<" in region 2"<<CGoGNendl;
s=0;
t=1;//region 2
}
......@@ -184,11 +190,13 @@ inline VEC3 closestPointInTriangle(VEC3 p1, VEC3 p2, VEC3 p3, VEC3 obj)
{
if(t<0)
{
// CGoGNout<<"closest from "<<p1<<" in region 6"<<CGoGNendl;
s=1;
t=0; //region 6
}
else
{
// CGoGNout<<"closest from "<<p1<<" in region 1"<<CGoGNendl;
//region 1
float numer =c+e-b-d;
if(numer <= 0)
......@@ -201,7 +209,7 @@ inline VEC3 closestPointInTriangle(VEC3 p1, VEC3 p2, VEC3 p3, VEC3 obj)
float denom=a-2*b+c;
s= numer >=denom ? 1 : numer/denom;
}
t=1-s;
}
}
......@@ -210,7 +218,7 @@ inline VEC3 closestPointInTriangle(VEC3 p1, VEC3 p2, VEC3 p3, VEC3 obj)
}
//CGoGNout<<"closest : "<<s*E0 +t*E1 + p1<<CGoGNendl;
return s*E0 +t*E1 + p1;
......
......@@ -23,7 +23,7 @@ EnvMap::EnvMap()
void EnvMap::init(int argc, char **argv)
{
maxCellRay = 2.0f;
maxCellRay = 1.0f;
std::cout << "Init EnvMap" << std::endl ;
if (argc>2)
{
......
......@@ -61,6 +61,16 @@ void Needle::color_close()
{
VEC3 closest = closestPointInTriangle(t->p1,t->p2,t->p3,pos);
t->closest_point=closest;
// CGoGNout<<"pos :"<<pos<<" || closest :"<<closest<<CGoGNendl;
distSq = (pos-closest).norm2();
if(distSq < ((pos-closest_point).norm2()))
closest_point=closest;
t->surf->changeColor(t,distSq);
}
for(Triangle * t : sim_->envMap_.RegisteredNeighborTriangles[volume])
{
VEC3 closest = closestPointInTriangle(t->p1,t->p2,t->p3,pos);
t->closest_point=closest;
// CGoGNout<<"pos :"<<pos<<" || closest :"<<closest<<CGoGNendl;
distSq = (pos-closest).norm2();
if(distSq < ((pos-closest_point).norm2()))
......
......@@ -12,8 +12,8 @@ Surface::Surface(Simulator* sim,VEC3 offset):
width=1.0;
nbVertices=0;
nbTriangles=0;
distanceColorationMaxi=0.25f;
distanceColorationMini=5.0f;
distanceColorationMaxi=0.01f;
distanceColorationMini=2.0f;
surfaceMap.initImplicitProperties();
positionSurface = surfaceMap.addAttribute<VEC3, VERTEX, SURFACE>("positionSurface");
......@@ -54,14 +54,14 @@ Surface::Surface(Simulator* sim,VEC3 offset):
for(Dart d = tE.begin() ; d != tE.end() ; d = tE.next())
{
faceColor[d]=VEC3(r,g,b);
//#ifdef DEBUG_affichage
#ifdef DEBUG_affichage
CGoGNout<<" init Segment :"<< nbTriangles ;
CGoGNout<<" || nb_segments :"<< triangles_.size() <<CGoGNendl;
//#endif
#endif
indexTriangle[d]=triangles_.size();
VEC3 p1=positionSurface[d],p2=positionSurface[surfaceMap.phi1(d)],p3=positionSurface[surfaceMap.phi1(surfaceMap.phi1(d))];
Triangle* o = new Triangle(p1,p2,p3,this,d,r,g,b);
Triangle* o = new Triangle(p1,p2,p3,this,d,r,g,b,indexTriangle[d]);
triangles_.push_back(o);
sim_->envMap_.FirstRegistrationTriangle(o);
......@@ -72,21 +72,21 @@ Surface::Surface(Simulator* sim,VEC3 offset):
sim_->surfaces.push_back(this);
for(Dart d = tE.begin() ; d != tE.end() ; d = tE.next())
{
CGoGNout<<" color face :"<<d<<" || : "<<faceColor[d]<<CGoGNendl ;
}
// for(Dart d = tE.begin() ; d != tE.end() ; d = tE.next())
// {
// CGoGNout<<" color face :"<<d<<" || : "<<faceColor[d]<<CGoGNendl ;
// }
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
CGoGNout<<" position dart :"<<d<<" || : "<<positionSurface[d]<<CGoGNendl ;
}
// for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
// {
// CGoGNout<<" position dart :"<<d<<" || : "<<positionSurface[d]<<CGoGNendl ;
// }
}
void Surface::initGL()
{
//rendering
// m_render = new Algo::Render::GL2::MapRender();
m_render_map = new Algo::Render::GL2::MapRender();
m_positionVBO = new Utils::VBO();
m_colorVBO= new Utils::VBO();
m_render = new Algo::Render::GL2::ColorPerFaceRender();
......@@ -95,31 +95,33 @@ void Surface::initGL()
m_shader= new Utils::ShaderColorPerVertex();
m_shader->setAttributeColor(m_colorVBO);
m_shader->setAttributePosition(m_positionVBO);
// m_simpleColorShader = new Utils::ShaderSimpleColor();
// m_simpleColorShader->setAttributePosition(m_positionVBO);
// m_simpleColorShader->setColor(Geom::Vec4f(0.,1.,0.,0.));
m_simpleColorShader = new Utils::ShaderSimpleColor();
m_simpleColorShader->setAttributePosition(m_positionVBO);
m_simpleColorShader->setColor(Geom::Vec4f(0.,1.,0.,0.));
m_render->updateVBO<PFPSurface,FACE>(*m_positionVBO,*m_colorVBO,surfaceMap,positionSurface,faceColor);
// m_render->initPrimitives<PFPSurface>(surfaceMap, Algo::Render::GL2::LINES) ;
m_render_map->initPrimitives<PFPSurface>(surfaceMap, Algo::Render::GL2::LINES) ;
// m_render->initPrimitives<PFPSurface>(surfaceMap, Algo::Render::GL2::TRIANGLES) ;
}
void Surface::draw()
{
// m_positionVBO->updateData(positionSurface) ;
m_positionVBO->updateData(positionSurface) ;
m_render_map->draw(m_simpleColorShader,Algo::Render::GL2::LINES);
// m_colorVBO->updateData(faceColor);
// colorRender->updateVBO<PFPSurface,FACE>(m_positionVBO,m_colorVBO,surfaceMap,positionSurface,colorRender);
glLineWidth(1.0f);
m_render->updateVBO<PFPSurface,FACE>(*m_positionVBO,*m_colorVBO,surfaceMap,positionSurface,faceColor);
// m_simpleColorShader->setColor(Geom::Vec4f(0.0,0.0,0.0,0.));
m_simpleColorShader->setColor(Geom::Vec4f(0.0,0.0,0.0,0.));
m_render->draw(m_shader);
}
void Surface::initPlane()
......@@ -180,7 +182,7 @@ bool Surface::subdiveMap()
if(dist > sim_->envMap_.maxCellRay)
{
CGoGNout<<"ok pour subdiv face :"<<d<<CGoGNendl;
mapOperator.subdivideFace(d,true,false) ;
mapOperator.subdivideFace(d,true,true) ;
res=false;
}
......
......@@ -246,10 +246,12 @@ void Volusion::cb_initGL()
{
surf->initGL();
registerShader(surf->m_shader);
registerShader(surf->m_simpleColorShader);
for(Triangle * t : surf->triangles_)
{
data[j]=t->closest_point;
j++;
data[j+1]=t->p1;
j=j+2;
}
}
......@@ -276,7 +278,7 @@ void Volusion::cb_initGL()
VEC3 p = simul.aiguille->parts_[i]->getPosition();
data[i] = p;
}
data[simul.aiguille->nbVertices]=simul.aiguille->closest_point;
// data[simul.aiguille->nbVertices]=simul.aiguille->closest_point;
m_MovingObjectVBO->releasePtr();
......@@ -344,7 +346,7 @@ void Volusion::cb_redraw()
data[i] = p;
i++;
}
data[simul.aiguille->nbVertices]=simul.aiguille->closest_point;
// data[simul.aiguille->nbVertices]=simul.aiguille->closest_point;
m_MovingObjectVBO->releasePtr();
// m_frame_MovingObject->draw();
......@@ -356,7 +358,7 @@ void Volusion::cb_redraw()
m_sprite->enableVertexAttribs();
glDrawArrays(GL_POINTS, 0, simul.aiguille->nbVertices+1);
glDrawArrays(GL_POINTS, 0, simul.aiguille->nbVertices/*+1*/);
m_sprite->disableVertexAttribs();
......@@ -373,7 +375,9 @@ void Volusion::cb_redraw()
for(Triangle * t : surf->triangles_)
{
data2[j]=t->closest_point;
// data2[j+1]=t->p1;
j++;
}
}
......
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