54 #include <ACG/GL/acg_glew.hh> 55 #include "QtBaseViewer.hh" 56 #include "QtGLGraphicsScene.hh" 57 #include "QtGLGraphicsView.hh" 59 #include "../GL/GLState.hh" 60 #include "../Scenegraph/SceneGraph.hh" 69 static const unsigned int SELECTION_BUFFER_SIZE = 10000;
70 static const unsigned int NAME_STACK_SIZE = 2;
84 const QPoint& _mousePos,
85 unsigned int& _nodeIdx,
86 unsigned int& _targetIdx,
94 y = h - _mousePos.y();
95 GLint viewport[4] = {0,0,w,h};
96 GLuint nameBuffer[ NAME_STACK_SIZE ];
99 std::vector<GLuint> selectionBuffer(SELECTION_BUFFER_SIZE);
113 glSelectBuffer( SELECTION_BUFFER_SIZE, &selectionBuffer[0] );
114 glRenderMode(GL_SELECT);
115 glMatrixMode(GL_PROJECTION);
120 const float deltax = 3.0f, deltay = 3.0f;
121 glTranslatef(
float(viewport[2] - 2 * (x - viewport[0])) / deltax,
122 float(viewport[3] - 2 * (y - viewport[1])) / deltay, 0.0f);
123 glScalef(viewport[2] / deltax, viewport[3] / deltay, 1.0);
126 glMatrixMode(GL_MODELVIEW);
129 glClear(GL_DEPTH_BUFFER_BIT);
135 int hits = glRenderMode(GL_RENDER);
138 glMatrixMode( GL_PROJECTION );
140 glMatrixMode( GL_MODELVIEW );
148 GLuint *ptr = &selectionBuffer[0],
153 for (
int i=0; i<hits; ++i)
155 const GLuint num_names = *ptr++;
156 if ( num_names != NAME_STACK_SIZE )
158 std::cerr <<
"QtBaseViewer::pick() : namestack error\n\n";
162 if ( (z = *ptr++) < min_z )
166 for (
unsigned int j=0; j<num_names; ++j)
167 nameBuffer[j] = *ptr++;
169 else ptr += 1+num_names;
172 _nodeIdx = nameBuffer[0];
173 _targetIdx = nameBuffer[1];
178 GLdouble min_zz = ((GLdouble)min_z) / ((GLdouble)zscale);
179 GLdouble max_zz = ((GLdouble)max_z) / ((GLdouble)zscale);
180 GLdouble zz = 0.5F * (min_zz + max_zz);
187 std::cerr <<
"QtBaseViewer::pick() : selection buffer overflow\n\n";
203 GLint x(_mousePos.x()), y(
glHeight() - _mousePos.y());
208 glPixelStorei(GL_PACK_ALIGNMENT, 1);
209 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
210 glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
256 std::vector<PickMode>::iterator it =
pick_modes_.begin();
276 glView_->setCursor(_cursor);
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
void pick_init(bool _color)
initialize name/color picking stack (like glInitNames())
Namespace providing different geometric functions concerning angles.
PickTarget
What target to use for picking.
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
const GLMatrixd & modelview() const
get modelview matrix
const GLMatrixd & projection() const
get projection matrix
const Scalar * get_raw_data() const
void traverse(BaseNode *_node, Action &_action)
VectorT< double, 3 > Vec3d