Object Picking

Moderator
Posts: 608
Joined: 2002.04
Post: #1
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?
Quote this message in a reply
swcrissman
Unregistered
 
Post: #2
If anyone can contribute an object picking tutorial, I could really use one too. Any takers? Smile

Spencer
Quote this message in a reply
kainsin
Unregistered
 
Post: #3
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?
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #4
I am talking about using the selection buffer. For some reason, I NEVER get hits!
Quote this message in a reply
swcrissman
Unregistered
 
Post: #5
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.

Spencer
Quote this message in a reply
kainsin
Unregistered
 
Post: #6
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.
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #7
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 Sad 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?
Quote this message in a reply
Feanor
Unregistered
 
Post: #8
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.

FÎanor
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #9
Quote:Originally posted by Feanor
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?
Yep, that's what I'm using.
Quote:
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.
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...
Quote this message in a reply
kainsin
Unregistered
 
Post: #10
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.
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #11
Quote:Originally posted by kainsin
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 ).
No 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.
Quote this message in a reply
kainsin
Unregistered
 
Post: #12
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.
Quote this message in a reply
kainsin
Unregistered
 
Post: #13
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.
Quote this message in a reply
Member
Posts: 78
Joined: 2002.06
Post: #14
Try the tutorial at:

http://nehe.gamedev.net/tutorials/lesson.asp?l=32

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.

Will
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #15
Quote:Originally posted by willThimbleby
Try the tutorial at:

http://nehe.gamedev.net/tutorials/lesson.asp?l=32
I already have, but it uses GLUT. I can get GLUT object picking to work, just not AGL.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How do I do Color Picking? dockode 2 5,149 Sep 24, 2011 08:02 PM
Last Post: dockode
  Issues with picking FFaqui 0 2,283 Nov 21, 2009 04:37 PM
Last Post: FFaqui
  Opengl picking problem (zip file) papillon68 1 4,504 Mar 1, 2009 08:49 PM
Last Post: chronus
  Picking and selection... chalamov33 2 3,464 Mar 31, 2008 02:08 PM
Last Post: wyrmmage
  glut picking clashes with drawing wyrmmage 2 3,581 Jan 24, 2008 06:39 PM
Last Post: wyrmmage