00001 #include "myGLRendererStateVariables.h"
00002 #include <GL/glut.h>
00003
00004 #include <iostream>
00005 using std::cout;
00006 using std::endl;
00007
00008 namespace X3DTK
00009 {
00010 namespace GL
00011 {
00012
00013 MyRendererStateVariables::MyRendererStateVariables()
00014 : StateVariables()
00015 , boundedObject(NULL)
00016 {}
00017
00018 MyRendererStateVariables::~MyRendererStateVariables()
00019 {}
00020
00021 void MyRendererStateVariables::initSelect(double , double )
00022 {
00023 glSelectBuffer(32768, _hits);
00024 glRenderMode(GL_SELECT);
00025 glInitNames();
00026 glPushName(0);
00027 }
00028
00029 void MyRendererStateVariables::finishSelect()
00030 {
00031 glFlush();
00032
00033 _shape = 0;
00034
00035
00036 GLint nb_hits = glRenderMode(GL_RENDER);
00037
00038
00039 if (nb_hits <= 0)
00040 {
00041 cout << "found nothing" << endl;
00042 _shapeVector.clear();
00043 return;
00044 }
00045 else
00046 cout << nb_hits << " hits:" << endl;
00047
00048
00049 for (unsigned int i = 0; i < static_cast<unsigned int>(nb_hits*4 + 1); ++i)
00050 cout << _hits[i] << endl;
00051
00052
00053 unsigned zMin = _hits[2];
00054 int selectedId(_hits[3]);
00055
00056 for (int j = 1; j < nb_hits; ++j)
00057 {
00058
00059 if (_hits[j*4 + 2] < zMin)
00060 {
00061 zMin = _hits[j*4 + 2];
00062 selectedId = _hits[j*4 + 3];
00063 }
00064 }
00065
00066 cout << "found " << selectedId << " in " << _shapeVector.size() << endl;
00067
00068
00069
00070
00071 _shapeVector.clear();
00072 }
00073
00074 void MyRendererStateVariables::storeShape(X3DShapeNode *S)
00075 {
00076 _shapeVector.push_back(S);
00077 }
00078
00079 void MyRendererStateVariables::setSelectionMode(bool value)
00080 {
00081 _selectionMode = value;
00082 }
00083
00084
00085 }
00086 }
00087