#include "GL_RendererStateVariables.h" #include #include using namespace std; namespace X3DTK { namespace GL { RendererStateVariables::RendererStateVariables() : StateVariables() { } RendererStateVariables::~RendererStateVariables() { } void RendererStateVariables::initSelect(double x, double y) { glSelectBuffer(32768, _hits); glRenderMode(GL_SELECT); glInitNames(); glPushName(0); } void RendererStateVariables::finishSelect() { glFlush(); _shape = 0; // Get the results GLint nb_hits = glRenderMode(GL_RENDER); // Too many elements in selection buffer if (nb_hits <= 0) { cout << "found nothing" << endl; _shapeVector.clear(); return; } else cout << nb_hits << " hits:" << endl; for (unsigned int i = 0; i < static_cast(nb_hits*4 + 1); ++i) cout << _hits[i] << endl; //interpreting the results. unsigned zMin = _hits[2]; int selectedId(_hits[3]); for (int j = 1; j < nb_hits; ++j) { // Prefer vertices over edges and edges over faces if (_hits[j*4 + 2] < zMin) { zMin = _hits[j*4 + 2]; selectedId = _hits[j*4 + 3]; } } cout << "found " << selectedId << " in " << _shapeVector.size() << endl; //_shape = _shapeVector[selectedId]; /* _matrixStack.clear(); _matrixVector.clear();*/ _shapeVector.clear(); } void RendererStateVariables::storeShape(X3DShapeNode *S) { _shapeVector.push_back(S); } void RendererStateVariables::setSelectionMode(bool value) { _selectionMode = value; } } }