Object Picking - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Object Picking (/thread-7722.html)
Pages: 1 2
Object Picking - Josh - Jun 5, 2002 11:19 AM
I have gotten object picking to work in a GLUT app, but when I use the same method on an AGL app, it doesn't work. Anyone know why, or better yet, know of some AGL code that uses object picking?
Object Picking - swcrissman - Jun 5, 2002 03:40 PM
If anyone can contribute an object picking tutorial, I could really use one too. Any takers?
Object Picking - kainsin - Jun 6, 2002 07:03 AM
What type of object picking are you talking about? Using the mouse to select an object ( maybe via gluUnProject )? Or hitting a key and determining what the screen is "looking" at?
Object Picking - Josh - Jun 6, 2002 07:54 AM
I am talking about using the selection buffer. For some reason, I NEVER get hits!
Object Picking - swcrissman - Jun 6, 2002 07:55 AM
I was referring to the first kind you mention: User clicked at x, y on screen, or moved mouse to position x, y on screen, what object is the mouse 'over' in 3 space. That sort of deal.
Object Picking - kainsin - Jun 7, 2002 07:27 AM
Hmmm...I've never used the selection buffer before, and I must have skipped it whenever it came up when I was reading OpenGL stuff. It is in the regular gl library, I'm assuming?
As for mouse selection, you need to first find the point that the mouse is on in the 3D world. Think of the window as the near clipping plane, you know the distance of the near clipping plane and how big it is when you set up projection, so you should be able to determine where this plane exists in 3D space. You also know the position of the camera in the 3D world as well because you have to set this up in order to do projection at all. Find the point in the world that the mouse is at, maybe by taking the relative distance from the center of the screen and the position of the mouse, and then translating away the same relative distance in 3D space that the near clipping plane occupies. Now you have 2 points in 3D space and can use those to form a ray which you can project into your world. Just test all the objects to see if the ray intersects them and take the closest one.
I like doing math rather than using buffers. I feel more comfortable doing so, but that may just be because I enjoy math and haven't dabbled much with OpenGL besides just transforming and redering my objects.
Object Picking - Josh - Jun 7, 2002 08:03 PM
A lot of people have suggested that I use math instead of buffers, but my math knowledge right now is only Algebra 1. Not much you can do with that That is why the selection buffer seems so perfect. I am curious though, what is the difference in GLUT and AGL that it works in one and not the other?
Object Picking - Feanor - Jun 7, 2002 10:36 PM
I see that the Red Book has a ten page section on using selection mode. Are you guys familiar with that material? I've never done it myself. jabber, the Red Book picking example uses gluPickMatrix() for the heavy work -- is that what you're using? This stuff is all online if you don't have access to the printed version.
For AGL, it's possible that you need to use a pixel format attribute before you can do picking/selection -- that's just a guess.
Object Picking - Josh - Jun 8, 2002 09:16 AM
Quote:Originally posted by FeanorYep, that's what I'm using.
Quote:Can anyone confirm or deny? Obviously, the real reason that I need object picking is for the user interface. So maybe I will use CopyBits to do the interface and then OGL for all of the heavy drawing...
Object Picking - kainsin - Jun 10, 2002 12:03 PM
You say that you've gotten it to work in a GLUT application, but not in an AGL application...is it just not working or are you getting compile-time errors. gluPickMatrix should work fine in AGL since it is just in the GLU library and only tied to OpenGL ( not GLUT ).
If you are getting compile-time errors then make sure you've included the GLU library in your project. If things just arn't working like they should then try using a debugger to find out if the code that worked when you were using GLUT is working correctly.
If this is a Classic application then don't forget to up the stack size and heap size to see if that helps. I think AGL requires at least a 256K stack size and CodeWarrior ( for instance ) only starts you out at 64K or 128K.
I'll look through the Red Book myself to see what I can find out about it.
Object Picking - Josh - Jun 10, 2002 12:45 PM
Quote:Originally posted by kainsinNo compile errors, just never works.
Quote:If this is a Classic application then don't forget to up the stack size and heap size to see if that helps. I think AGL requires at least a 256K stack size and CodeWarrior ( for instance ) only starts you out at 64K or 128K.That was one of the first things I checked... This is rather weird, too bad Apple doesn't have any examples.
Object Picking - kainsin - Jun 11, 2002 01:58 PM
I took a quick look at the reference pages, not the actual section, for gluPickMatrix and gluUnProject and noticed that it wanted window coordinates. Another thought crossed my mind...you remembered that Apple windows have their origin at the top-left while OpenGL positions them at the bottom-left, right? I believe that that will affect the window coordinates you need to enter, in that you'll have to flip the y ( y-max minus y-position ) to get the correct y-coordinate. Please tell me if I am wrong about this and that AGL handles it for you someway or another.
I'll try to dig deeper into the documentation tonight as I didn't quite get a chance to last night.
Object Picking - kainsin - Jun 12, 2002 07:50 AM
Hmm...I haven't really come up with too much regarding this. I took a look through the AGL documentation and didn't notice too much.
Though it does appear that you can specify how many auxilary buffers you want AGL to create, assuming that the selection buffer is indeed an auxilary buffer. Try putting AGL_AUX_BUFFERS into the aglChoosePixelFormat with a positive integer and see if that creates an auxilary buffer that can be used as the selection buffer.
Object Picking - willThimbleby - Jun 21, 2002 08:50 AM
Try the tutorial at:
Its actually fairly easy. I didn't think too much of the tutorial. But I've a nice and simple cocoa program I could upload if you want.
Object Picking - Josh - Jun 21, 2002 10:54 AM
Quote:Originally posted by willThimblebyI already have, but it uses GLUT. I can get GLUT object picking to work, just not AGL.