View Full Version : selection in 3D
09-29-2002, 10:19 PM
I am doing application in which is drawing simple cube with selectable faces. The problem is selection algorithm - the OpenGL selection mechanism (IMO) is suitable only in simple flat selection cases. After looking to tutorial examples at ww.gametutorials.com this thing don't seems clearer - my application from selection buffer is getting only nearest cube face. In Red Book about 3d selection I have found only words "this is difficult thing". At last I decided to write to this forum - may be someone has an algorithm or can point to it ? Thanks in advance...
09-30-2002, 12:09 AM
Please give us some kind of specification of exactly what you are trying to do. do you want *all* of the faces selected at that point, regardless of which is the closest?
09-30-2002, 04:00 AM
My goal is selection of one cube's face per mouse click. I not need to have *all* selected faces.
Specification http://www.opengl.org/discussion_boards/ubb/smile.gif :
1) The viewer is looking at cube in 3d. I want visible cube's faces to be selectable by mouse click - one face per click.
2) After selection of first face, when user clicks on another visible face, this face become selected, previos face selection disappear
Sorry for poor English, I am Lithuanian http://www.opengl.org/discussion_boards/ubb/smile.gif
If it is not clear enough yet, do not hesitate to ask more questions...
09-30-2002, 06:23 AM
Actually this is not difficult. The functionallity you described in (2) can be reached using the GL_SELECT rendering mode.
Take a look at the following functions: glRenderMode(GL_SELECT), glInitNames, glLoadName, glSelectBuffer.
Your rendering method will be something like this:
Then in the MouseClick event switch to GL_SELECT mode, call the render method again then the selection buffer will give you the Name of the polygon you cliked on.
09-30-2002, 04:14 PM
U can refer to (OpenGL interoperability with mouse under Ms Windows & X-win systems ). I just had post it....
09-30-2002, 09:55 PM
thanks for advices, I have GL_SELECT stuff already done ( with mouse event ). The problem is I ALWAYS get selected only nearest face to viewer - glSelectBuffer returns parameters for this nearest (front) face ( it is perpendicular to z axis), even when I clicked on upper face or side face. If this will be helpful I can send my code excerpts tomorrow.
Basic of this technique is on www.gametutorials.com, (http://www.gametutorials.com,) very detail explanation of all this algorithm steps. But results are not succesive on my case http://www.opengl.org/discussion_boards/ubb/frown.gif
10-02-2002, 12:24 PM
Originally posted by XChanger:
thanks for advices, I have GL_SELECT stuff already done ( with mouse event ). The problem is I ALWAYS get selected only nearest face to viewer - glSelectBuffer returns parameters for this nearest (front) face ( it is perpendicular to z axis), even when I clicked on upper face or side face.
I have used the Opengl picking technique and it work wonderfull...but your are right, it is very dificult to make it work Ok the first time, but when you do it will never fail.
The keys is that you have to render the scene in select mode but before you have to setup the Viewport using the glulookat command to ZOOM IN x,y coordinates from the mouse so only this tiny area will be rendered.
After comming back from selecting mode, opengl will NOT give you which faces (marked with glloadname()) was selected...it will give you ALL FACES that are below the X,Y mouse coordinates but they could be at different Z position. All faces found (called "hits") are returned in a buffer, this buffer has ONE record for each face found and each record include the "Z" coordinate for the found face; you have to inspect all records and choose as "selected" face the one who has the Higher "Z" value. depending on how you are rendering your scene, sometimes the selected faces is choosing the lower "Z" value.
There is another method for picking that could be easier to implement for some peoples, when you want to do a pick, render all your faces using a solid DIFFERENT COLORs, but do not swap the back bufer so this especial rendering scene is never seen for the user, then use the getpixel function for get the color pixel from the X,Y coordinate, depending the color returned you will know which face was clicked.
10-02-2002, 09:26 PM
thanks, Turbo Pascal. I am working now on selection problem, and your last idea seems the best for me. My selection buffer always return only one record with the nearest cube's face. I think the problem lies somewhere in using gluPerspective, which using difference view volume in selection mode. I found this in literature, but except these words nothing more. If at this week I
will not find the solution, I will try glProject/glUnproject methods (or another http://www.opengl.org/discussion_boards/ubb/smile.gif
10-27-2002, 10:23 AM
I too am having problems getting objects selecting properly. I have incorporated the RetrieveObjectID Code from gametutorials.com into my code and it says that it located one item which makes sense as this is a 2D tile program. For now I would just like to be able to see which tile is being selected but it always returns 0, regardless to what tile I click on in the screen.
During my DrawTile routine I load the request ID using glLoadName prior to drawing the tile itself.
The only change to the RetrieveObjectID code I did was to introduce the Ortho/Pers code that is used in my viewport/scene routines.
Whether the glScissor command I use to set up my viewports is causing the problem I don't know. But if it is I will need to find another way of locating the identity of the tile and eventually object being selected.
I have placed the whole project on my site with details of the source code and the problem on the page http://programming.swangen.co.uk/opengl/glLoadName.asp.
Does anyone know whether this is the reason for the problem? If not then why on earth does this not work for me. I can't see anything I missed from the tutorials.
Thanks in advance of any possible help on this.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.