diff --git a/wrap/gl/picking.h b/wrap/gl/picking.h index c1581b34..e3ec1eb6 100644 --- a/wrap/gl/picking.h +++ b/wrap/gl/picking.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once /**************************************************************************** * VCGLib o o * * Visual and Computer Graphics Library o o * @@ -9,7 +9,7 @@ * \ * * All rights reserved. * * * -* This program is free software; you can redistribute it and/or modify * +* This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * @@ -66,92 +66,92 @@ namespace vcg { template -int Pick( const int & x, const int &y, - TO_PICK_CONT_TYPE &m, - std::vector &result, - void (draw_func)(typename TO_PICK_CONT_TYPE::value_type &), - int width=4, - int height=4) - { - result.clear(); - long hits; - int sz = int(m.size())*5; - GLuint *selectBuf =new GLuint[sz]; - glSelectBuffer(sz, selectBuf); - glRenderMode(GL_SELECT); - glInitNames(); +int Pick( const int & x, const int &y, + TO_PICK_CONT_TYPE &m, + std::vector &result, + void (draw_func)(typename TO_PICK_CONT_TYPE::value_type &), + int width=4, + int height=4) + { + result.clear(); + long hits; + int sz = int(m.size())*5; + GLuint *selectBuf =new GLuint[sz]; + glSelectBuffer(sz, selectBuf); + glRenderMode(GL_SELECT); + glInitNames(); - /* Because LoadName() won't work with no names on the stack */ - glPushName(-1); - double mp[16]; + /* Because LoadName() won't work with no names on the stack */ + glPushName(-1); + double mp[16]; - GLint viewport[4]; - glGetIntegerv(GL_VIEWPORT,viewport); - glPushAttrib(GL_TRANSFORM_BIT); - glMatrixMode(GL_PROJECTION); - glGetDoublev(GL_PROJECTION_MATRIX ,mp); - glPushMatrix(); - glLoadIdentity(); - //gluPickMatrix(x, viewport[3]-y, 4, 4, viewport); - gluPickMatrix(x, y, width, height, viewport); - glMultMatrixd(mp); + GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT,viewport); + glPushAttrib(GL_TRANSFORM_BIT); + glMatrixMode(GL_PROJECTION); + glGetDoublev(GL_PROJECTION_MATRIX ,mp); + glPushMatrix(); + glLoadIdentity(); + //gluPickMatrix(x, viewport[3]-y, 4, 4, viewport); + gluPickMatrix(x, y, width, height, viewport); + glMultMatrixd(mp); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - int cnt=0; - typename TO_PICK_CONT_TYPE::iterator ei; - for(ei=m.begin();ei!=m.end();++ei) - { + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + int cnt=0; + typename TO_PICK_CONT_TYPE::iterator ei; + for(ei=m.begin();ei!=m.end();++ei) + { - glLoadName(cnt); - draw_func(*ei); - cnt++; - } + glLoadName(cnt); + draw_func(*ei); + cnt++; + } - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - hits = glRenderMode(GL_RENDER); - - if (hits <= 0) return 0; - std::vector< std::pair > H; - for(int ii=0;ii(selectBuf[ii*4+1]/4294967295.0,selectBuf[ii*4+3])); - } - std::sort(H.begin(),H.end()); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + hits = glRenderMode(GL_RENDER); - result.resize(H.size()); - for(int ii=0;ii > H; + for(int ii=0;ii(selectBuf[ii*4+1]/4294967295.0,selectBuf[ii*4+3])); + } + std::sort(H.begin(),H.end()); -// 10/2/06 Slightly changed the interface. -// Return value is used to determine if the picked point was against the far plane + result.resize(H.size()); + for(int ii=0;ii bool Pick(const int & x, const int &y, PointType &pp){ - double res[3]; - GLdouble mm[16],pm[16]; GLint vp[4]; - glGetDoublev(GL_MODELVIEW_MATRIX,mm); - glGetDoublev(GL_PROJECTION_MATRIX,pm); - glGetIntegerv(GL_VIEWPORT,vp); - - float pix; - glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&pix); + GLdouble res[3]; + GLdouble mm[16],pm[16]; GLint vp[4]; + glGetDoublev(GL_MODELVIEW_MATRIX,mm); + glGetDoublev(GL_PROJECTION_MATRIX,pm); + glGetIntegerv(GL_VIEWPORT,vp); + + GLfloat pix; + glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&pix); GLfloat depthrange[2]={0,0}; glGetFloatv(GL_DEPTH_RANGE,depthrange); if(pix==depthrange[1]) return false; - gluUnProject(x,y,pix,mm,pm,vp,&res[0],&res[1],&res[2]); - pp=PointType (res[0],res[1],res[2]); + gluUnProject(x,y,pix,mm,pm,vp,&res[0],&res[1],&res[2]); + pp=PointType (res[0],res[1],res[2]); return true; - } + } } // end namespace