Thread: [PyOpenGL-Users] OpenGl + Mouse Selection
Brought to you by:
mcfletch
From: Jasper P. <ja...@pe...> - 2003-04-21 19:07:59
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I want to be able to "select" different entities rendered in OpenGL w/ a mouse -- essentially asking which shape the mouse pointer is over. Ideally this could be used to select game pieces to move, etc. This is fairly easy to compute when rending in an orthographic view, as you can simply translate mouse coordinates to viewpane coordinates. However, this doesn't work well for perspective views! It would be nice to simply ask opengl what lies behind a certain screen coordinate, but I haven't been able to find anything amongst the "glut" (rimshot!) of opengl documentation about this. Has anyone here had any experience with something like this? I suspect there must be an easy way to do it, as obviously the information is available inside of opengl. - -Jasper -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE+pEJN8EpjZ7/X9bIRAilwAKDWUmh9ltlv1HiYRh7G5WO0TlJwWQCg1F3N v9HHh5Eip+cBteBTCcPFMbE= =c8Xf -----END PGP SIGNATURE----- |
From: Mike C. F. <mcf...@ro...> - 2003-04-21 19:35:30
|
There are a number of ways to do this, but the most common way I've encountered is to use the glSelectBuffer-based selection mechanisms which come with OpenGL. You can find sample code for the glSelectBuffer stuff in OpenGLContext or just about any OpenGL reference or programming Web site (such as NeHe). The basic approach is to re-render the scene in "select" mode, pushing "names" (integers) onto the selection stack as you render to a frustum which is the projection of your picking point to infinity. When you exit the select rendering mode you receive a list of records indicating which names were active when items were rendered to the frustum. Hope this helps, Mike Jasper Phillips wrote: >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >I want to be able to "select" different entities rendered in OpenGL w/ >a mouse -- essentially asking which shape the mouse pointer is over. >Ideally this could be used to select game pieces to move, etc. > >This is fairly easy to compute when rending in an orthographic view, as you >can simply translate mouse coordinates to viewpane coordinates. However, >this doesn't work well for perspective views! > >It would be nice to simply ask opengl what lies behind a certain screen >coordinate, but I haven't been able to find anything amongst the "glut" >(rimshot!) of opengl documentation about this. > >Has anyone here had any experience with something like this? I suspect >there must be an easy way to do it, as obviously the information is >available inside of opengl. > >- -Jasper > >-----BEGIN PGP SIGNATURE----- >Version: GnuPG v1.0.6 (GNU/Linux) >Comment: For info see http://www.gnupg.org > >iD8DBQE+pEJN8EpjZ7/X9bIRAilwAKDWUmh9ltlv1HiYRh7G5WO0TlJwWQCg1F3N >v9HHh5Eip+cBteBTCcPFMbE= >=c8Xf >-----END PGP SIGNATURE----- > > > >------------------------------------------------------- >This sf.net email is sponsored by:ThinkGeek >Welcome to geek heaven. >http://thinkgeek.com/sf >_______________________________________________ >PyOpenGL Homepage >http://pyopengl.sourceforge.net >_______________________________________________ >PyOpenGL-Users mailing list >PyO...@li... >https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > -- _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ |
From: Jasper P. <ja...@pe...> - 2003-04-21 20:32:29
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 That sounds like what I want. Thanks for the search reference! - -Jasper On Mon, 21 Apr 2003, Mike C. Fletcher wrote: > There are a number of ways to do this, but the most common way I've > encountered is to use the glSelectBuffer-based selection mechanisms > which come with OpenGL. You can find sample code for the glSelectBuffer > stuff in OpenGLContext or just about any OpenGL reference or programming > Web site (such as NeHe). > > The basic approach is to re-render the scene in "select" mode, pushing > "names" (integers) onto the selection stack as you render to a frustum > which is the projection of your picking point to infinity. When you > exit the select rendering mode you receive a list of records indicating > which names were active when items were rendered to the frustum. > > Hope this helps, > Mike [snip my original question] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE+pFYa8EpjZ7/X9bIRAj6zAJ9Qd3y0PFhixkxbplYA+dxw4vCnYQCgwnGY ic7GD51sUgA+UrrgT+jii2M= =04I+ -----END PGP SIGNATURE----- |
From: sebastien H. <2l...@2l...> - 2003-04-22 07:21:32
|
I use this method with good success. I just have a little problem. My program paint some line on the OpenGL panel and when i try to select one, I need to be very close to select it. Is it a way to make the select area more large ? Thanks in advance. SEB Jasper Phillips a écrit: >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > > >That sounds like what I want. Thanks for the search reference! >- -Jasper > >On Mon, 21 Apr 2003, Mike C. Fletcher wrote: > > >>There are a number of ways to do this, but the most common way I've >>encountered is to use the glSelectBuffer-based selection mechanisms >>which come with OpenGL. You can find sample code for the glSelectBuffer >>stuff in OpenGLContext or just about any OpenGL reference or programming >>Web site (such as NeHe). >> >>The basic approach is to re-render the scene in "select" mode, pushing >>"names" (integers) onto the selection stack as you render to a frustum >>which is the projection of your picking point to infinity. When you >>exit the select rendering mode you receive a list of records indicating >>which names were active when items were rendered to the frustum. >> >>Hope this helps, >>Mike >> >> > >[snip my original question] >-----BEGIN PGP SIGNATURE----- >Version: GnuPG v1.0.6 (GNU/Linux) >Comment: For info see http://www.gnupg.org > >iD8DBQE+pFYa8EpjZ7/X9bIRAj6zAJ9Qd3y0PFhixkxbplYA+dxw4vCnYQCgwnGY >ic7GD51sUgA+UrrgT+jii2M= >=04I+ >-----END PGP SIGNATURE----- > > > >------------------------------------------------------- >This sf.net email is sponsored by:ThinkGeek >Welcome to geek heaven. >http://thinkgeek.com/sf >_______________________________________________ >PyOpenGL Homepage >http://pyopengl.sourceforge.net >_______________________________________________ >PyOpenGL-Users mailing list >PyO...@li... >https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > |
From: Mike C. F. <mcf...@ro...> - 2003-04-22 15:19:47
|
Setup the projection matrix to be slightly larger than a single point (OpenGLContext gives you a 2x2 area). Here's the code from OpenGLContext/renderpass's SelectRenderPass class (matrixSize is just a tuple of (2,2) in this case): def PickProjection( self ): """Setup the constrained picking matrix and result buffer We set up the view frustum to be a box centered around the picking point of size self.matrixSize, projecting back into the screen from our current viewpoint. We then set up the selection buffer into which our results will be saved, and then switch to selection-mode rendering. """ glMatrixMode(GL_PROJECTION) glLoadIdentity() glInitNames() x,y = self.pickPoint gluPickMatrix( x,y, self.matrixSize [0], self.matrixSize [1], self.getViewport() ) glSelectBuffer(self.bufferSize) glRenderMode(GL_SELECT) You can find documentation on gluPickMatrix here: http://pyopengl.sourceforge.net/documentation/manual/gluPickMatrix.3G.html HTH, Mike sebastien HEITZMANN wrote: > I use this method with good success. > > I just have a little problem. My program paint some line on the OpenGL > panel and when i try to select one, I need to be very close to select > it. Is it a way to make the select area more large ? > > Thanks in advance. > > SEB > > Jasper Phillips a écrit: > >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> >> That sounds like what I want. Thanks for the search reference! >> - -Jasper >> >> On Mon, 21 Apr 2003, Mike C. Fletcher wrote: >> >> >>> There are a number of ways to do this, but the most common way I've >>> encountered is to use the glSelectBuffer-based selection mechanisms >>> which come with OpenGL. You can find sample code for the >>> glSelectBuffer stuff in OpenGLContext or just about any OpenGL >>> reference or programming Web site (such as NeHe). >>> >>> The basic approach is to re-render the scene in "select" mode, >>> pushing "names" (integers) onto the selection stack as you render to >>> a frustum which is the projection of your picking point to >>> infinity. When you exit the select rendering mode you receive a >>> list of records indicating which names were active when items were >>> rendered to the frustum. >>> >>> Hope this helps, >>> Mike >>> >> >> >> [snip my original question] >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v1.0.6 (GNU/Linux) >> Comment: For info see http://www.gnupg.org >> >> iD8DBQE+pFYa8EpjZ7/X9bIRAj6zAJ9Qd3y0PFhixkxbplYA+dxw4vCnYQCgwnGY >> ic7GD51sUgA+UrrgT+jii2M= >> =04I+ >> -----END PGP SIGNATURE----- >> >> >> >> ------------------------------------------------------- >> This sf.net email is sponsored by:ThinkGeek >> Welcome to geek heaven. >> http://thinkgeek.com/sf >> _______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users >> >> >> >> > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > -- _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ |
From: Gary H. <gh...@is...> - 2003-04-21 19:40:43
|
On Monday 21 April 2003 12:11 pm, Jasper Phillips wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > I want to be able to "select" different entities rendered in OpenGL w/ > a mouse -- essentially asking which shape the mouse pointer is over. > Ideally this could be used to select game pieces to move, etc. > > This is fairly easy to compute when rending in an orthographic view, as you > can simply translate mouse coordinates to viewpane coordinates. However, > this doesn't work well for perspective views! > > It would be nice to simply ask opengl what lies behind a certain screen > coordinate, but I haven't been able to find anything amongst the "glut" > (rimshot!) of opengl documentation about this. > > Has anyone here had any experience with something like this? I suspect > there must be an easy way to do it, as obviously the information is > available inside of opengl. OpenGL has a way to do this. Look at glSelectBuffer, and also glInitNames, glLoadName, glPushName, and gluPickMaatrix. Like most things in OpenGL, these are low level tools which provide much power, but will take a little time to learn to use. Good Luck, Gary Herron |