PDA

View Full Version : picking in ortho



vaysd
09-30-2002, 12:46 PM
Hi,

Does anyone know if there are any limitations on picking (using SELECTion mode) in Ortho? Is it possible, even, or do I have to be in perspective view?

thanks for the help!

vshader
10-01-2002, 06:38 AM
there should be no problem - my red book says glPickMatrix() will take a matrix such as made by gluPerspective() or glOrtho() - but you should seriously consider wether you need to use SELECTION mode.

it will force software rasterization on most (all?) drivers = no hardware acceleration = slow openGL program.

also if you are using an ortho projection, the math for calculating the picking youself is even easier.

picking is basically raycasting into your scene - the ray is the line from the eye thru the cursor click location on the view plane.

you only need selection mode if it MUST be pixel accurate (which usually isn't the most user-friendly option), or if you have no data structure representing your scene, and can't easily make one.

GeLeTo
10-01-2002, 06:58 AM
Another reason to use selection mode is when you want to select a rectangle on the screen (not just a pixel).
In this case there are two alternatives to that -
(1) do your own picking, not much beter than using the opengl one.
or
(2) render to a pbuffer mapping the color to the primitive/object index, then do a glReadPixels.

A disadvantage of the second approach is that it works only on visible primitives/objects (i.e. ones that are not occulded). There's a workaround for this using several passes - render evrth. first, do the glReadPixels, clear the buffer, then render evrth. except for what was already selected, do the glReadPixels again, continue till nothing gets selected.

So, no need to use selection mode.

[This message has been edited by GeLeTo (edited 10-01-2002).]

gaby
10-01-2002, 11:25 AM
Selection in OGL is related to geometry pipeline : it is simply a check function that set geometries that are not rejected at the clipping stage as selected. If, in render mode, the current geometry is drawn (at least one pixel, in most cases), then it will be selected in select mode. So, in all case, the clipping in applyed, both in ortho or pers.

Gaby

vaysd
10-01-2002, 11:50 AM
Originally posted by gaby:
Selection in OGL is related to geometry pipeline : it is simply a check function that set geometries that are not rejected at the clipping stage as selected. If, in render mode, the current geometry is drawn (at least one pixel, in most cases), then it will be selected in select mode. So, in all case, the clipping in applyed, both in ortho or pers.

Gaby

That is what I figured,
but I am working within a larger program that switches between persp and ortho several times, and for some reason when I set up the objects I want to be able to pick in ortho I end up getting hits for all the objects rendered to the selection buffer, no matter where I click the mouse. But when I draw the same objects without converting to ortho first, the picking works beautifully.

any suggestions for what I could be doing wrong?

thanks!

Jan
10-02-2002, 01:04 PM
I donīt know what you are doing wrong, but i can assure you, that picking works absolutely fine in ortho-mode.

I created a level-editor with 4 views (3 ortho and 1 perspective). They are drawn using scissor-testing. I donīt have any problems, although i have to admit, that it is a big piece of work to manage the data correctly.

I would NEVER write my own picking algorithm!
The OpenGL selection is really fast in ortho mode, even if it might be software mode (however i donīt think so). I once made my first editor and painted the 2d stuff on my own with DirectDraw and so i also had to do the selection stuff. It got really a mess, because i couldnīt select other forms than rectangles (if you try to compute selection for other geometric shapes you get mad).

Well, therefore i kicked this program into my trash can and started this whole new editor.
So donīt do the same mistake, i did!!!

Jan.

vshader
10-02-2002, 09:20 PM
i'd just like to say that i found writing my own picking code to be one of the best learning experiences i have ever had in graphics coding - it introduced me to raytracing and all the interesting techniques that come with it. that was for single-point mouse clicks, though.

but rectangle selection i found to be not too hard either. in an Ortho projection a rectangle selection just delimits an area in eye space between Xmin-Xmax, Ymin-Ymax, near view plane and far plane. it is not too hard to find all objects in the view volume whose bounding volumes intersect this.

for perspective projections, a rectangle on the view plane just makes another view-frustum, with the rectangle as the new viewplane. there is plenty of example code out there on how to test objects against a view frustrum.

for normal scene graph based apps, you need all of those routines for other things anyway, so writing them is no burden.

but my situation may have no relation to what u had to do, Jan2000, so i am not saying you're wrong by any means.

as for the software mode thing - i have nVidia docs that warn aganst using selection mode as it will cause a fallback to software. i don't know if that applies to other chips, or even newer NV chips (it was a geforce1/2 doc i think) - perhaps an nvidia person could help us out here?

opla
10-03-2002, 05:19 AM
I don't recommend to use OpenGL picking.
I used it and it's very slow on ATI cards.
I wrote my own picking code (that also work for DirectX), and that was a good thing to do.