Simon Wittber wrote:
>I'm trying to use glRenderMode(GL_SELECT) to implement picking. The
>problem is, almost all picking examples deal with 3D projection
>(gluPerspective), whereas I am using glOrtho, so I suspect I need to
>do something different.
>
>
I don't actually use glOrtho, but I'll try to help...
>The below code doesn't work, it accumulates hits in the select buffer,
>but they are not the hits I expect. Any pointers on where I might be
>going wrong?
>
>
From the docs for gluPickMatrix:
The matrix created by gluPickMatrix is multiplied by the current
matrix just as if glMultMatrix is called with the generated matrix.
To effectively use the generated pick matrix for picking, first call
glLoadIdentity to load an identity matrix onto the perspective
matrix stack. Then call gluPickMatrix, and finally, call a command
(such as gluPerspective) to multiply the perspective matrix by the
pick matrix.
which suggests you want the gluOrtho call *after* the gluPickMatrix
call. I don't actually recall reversing the order in *my* code, but
then I haven't written code of this type in a long while.
>Also, is there a simple way to get OpenGL to render a small box on the
>screen which shows exactly which region is being picked?
>
>
You are creating a rectangular prism centred around the pick location.
So, do 8 gluUnProjects, one for each corner of the prism, with the near
face having winz of 0.0 and the far face having winz of 1.0. That
should give you a rectangle in model-space coordinates that you can
render (if I'm working through the logic correctly).
btw, you might want to check around and see if bitmap operations where
the bitmap position is outside of the picking matrix actually register
with a selection buffer (i.e. they don't draw if the bitmap position is
out-of-frustum, do they select when outside the picking frustum?)
Anyway, HTH,
Mike
...
> glLoadIdentity()
> viewport = glGetIntegerv(GL_VIEWPORT)
> n_w,n_h = display._screen.dimensions
> glOrtho(-n_w,n_w,-n_h,n_h,1,0)
> gluPickMatrix(position[0],viewport[3]-position[1],3,3,viewport)
>
>
...
> display._screen.blit(i.item, i.position)
>
>
>
...
--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
|