diff --git a/Apps/Tuto/tuto5.cpp b/Apps/Tuto/tuto5.cpp index e7d9a5f472fdb98370c0fe8e1c66a4d38825138b..525a30c0392df81436d85f9e1353a16ac8dbcbf9 100644 --- a/Apps/Tuto/tuto5.cpp +++ b/Apps/Tuto/tuto5.cpp @@ -108,9 +108,26 @@ void myGlutWin::myRedraw(void) glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); + glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); glDisable(GL_LIGHTING); + glLineWidth(3.0); + glBegin(GL_LINES); + glColor3f(1.,0.,0.); + glVertex3f(0.0,0.0,0.0); + glVertex3f(1.0,0.0,0.0); + + glColor3f(0.,1.,0.); + glVertex3f(0.0,0.0,0.0); + glVertex3f(0.0,1.0,0.0); + + glColor3f(0.,0.,1.); + glVertex3f(0.0,0.0,0.0); + glVertex3f(0.0,0.0,1.0); + + glEnd(); + glColor3f(0.0f,1.0f,.0f); m_render->draw(Algo::Render::VBO::POINTS); @@ -187,6 +204,7 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) } break; + case 'x': { // push/pop color is only needed for dart coloring conservation @@ -203,22 +221,23 @@ void myGlutWin::myKeyboard(unsigned char keycode, int x, int y) glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]); //pick Dart d = m_render_topo->picking(x,H-y); + glPopMatrix(); m_render_topo->popColors(); - if (d != Dart::nil()) + if (d != Dart::nil()) { + m_render_topo->setDartColor(d,1.0,0.0,0.0); redraw(); std::stringstream ss; ss << "Pick dart:" << d << std::endl<<"pos="<< position[d]; glColor3f(1.,1.,0.); printString2D(x+12,y+22,ss.str()); glutSwapBuffers(); -// std::cout << "Pick dart:" << d << " position= "<< position[d] << std::endl; - std::cout << "Pick dart:" << d << std::endl; + std::cout << "Pick dart:" << d << " pos= "<< position[d] << std::endl; } - // in console: + break; } @@ -427,6 +446,8 @@ int main(int argc, char **argv) nb = atoi(argv[1]); dglobal = prim.hexaGrid_topo(nb,nb,nb); prim.embedHexaGrid(1.0f,1.0f,1.0f); + + // Geom::Matrix44f mat; // mat.identity(); // Geom::scale(2.0f, 2.0f,2.0f,mat); diff --git a/include/Algo/Render/topo3_vboRender.h b/include/Algo/Render/topo3_vboRender.h index c771cd2bbcd2833b95662b22e9780ff919ea08cf..bb8b1442cea7fb1f2845fcc3b5d40fb5e5a60487 100644 --- a/include/Algo/Render/topo3_vboRender.h +++ b/include/Algo/Render/topo3_vboRender.h @@ -118,6 +118,11 @@ protected: public: + + Dart colToDart(float* color); + + void dartToCol(Dart d, float& r, float& g, float& b); + /** * Constructor * @param map the map to draw diff --git a/include/Algo/Render/topo3_vboRender.hpp b/include/Algo/Render/topo3_vboRender.hpp index 7bde19ad69440df173f6d860e22137a9536de5ae..9852b75ec7948030e9e069206756e816a12aadfa 100644 --- a/include/Algo/Render/topo3_vboRender.hpp +++ b/include/Algo/Render/topo3_vboRender.hpp @@ -905,21 +905,15 @@ void topo3_VBORender::setDartsIdColor(typename PFP::MAP& map, const FunctorSelec { if (good(d)) { - unsigned int lab = d.index + 1; // add one to avoid picking the black of screen - - float r = float(lab%256) / 256.0f; lab = lab/256; - float g = float(lab%256) / 256.0f; lab = lab/256; - float b = float(lab%256) / 256.0f; lab = lab/256; - - if (lab!=0) - std::cerr << "Error picking color, too many darts"<< std::endl; - - *colorBuffer++ = r; - *colorBuffer++ = g; - *colorBuffer++ = b; - *colorBuffer++ = r; - *colorBuffer++ = g; - *colorBuffer++ = b; + float r,g,b; + dartToCol(d, r,g,b); + float* local = colorBuffer+3*m_attIndex[d]; // get the right position in VBO + *local++ = r; + *local++ = g; + *local++ = b; + *local++ = r; + *local++ = g; + *local++ = b; nb++; } diff --git a/src/Algo/Render/topo3_vboRender.cpp b/src/Algo/Render/topo3_vboRender.cpp index 730c5431bf37f5ae75e462f384d4d2dea46983ec..f8f35bbd4d2e03e6b73cb422077a1168a3924570 100644 --- a/src/Algo/Render/topo3_vboRender.cpp +++ b/src/Algo/Render/topo3_vboRender.cpp @@ -98,7 +98,7 @@ void topo3_VBORender::setAllDartsColor(float r, float g, float b) void topo3_VBORender::drawDarts() { - glColor3f(1.0f,1.0f,1.0f); +// glColor3f(1.0f,1.0f,1.0f); glLineWidth(m_topo_dart_width); glPointSize(2.0f*m_topo_dart_width); @@ -214,6 +214,32 @@ void topo3_VBORender::popColors() } +Dart topo3_VBORender::colToDart(float* color) +{ + unsigned int r = (unsigned int)(color[0]*255.0f); + unsigned int g = (unsigned int)(color[1]*255.0f); + unsigned int b = (unsigned int)(color[2]*255.0f); + + unsigned int id = r + 255*g +255*255*b; + + if (id==0) + return Dart::nil(); + return Dart(id-1); + +} + +void topo3_VBORender::dartToCol(Dart d, float& r, float& g, float& b) +{ + unsigned int lab = d.index + 1; // add one to avoid picking the black of screen + + r = float(lab%255) / 255.0f; lab = lab/255; + g = float(lab%255) / 255.0f; lab = lab/255; + b = float(lab%255) / 255.0f; lab = lab/255; + if (lab!=0) + std::cerr << "Error picking color, too many darts"<< std::endl; +} + + Dart topo3_VBORender::picking(unsigned int x, unsigned int y) { //more easy picking for @@ -241,17 +267,7 @@ Dart topo3_VBORender::picking(unsigned int x, unsigned int y) glClearColor(cc[0], cc[1], cc[2], cc[3]); - // compute dart index: - unsigned int r = (unsigned int)(color[0]*255.0f); - unsigned int g = (unsigned int)(color[1]*255.0f); - unsigned int b = (unsigned int)(color[2]*255.0f); - - unsigned int id = r + 256*g +256*256*b; - - if (id == 0) - return Dart::nil(); - - return Dart(id-1); // -1 because we draw +1 + return colToDart(color); }