PDA

View Full Version : issue with selection



dlswimmer
05-15-2004, 09:58 AM
I am having an issue with my simple selection of a box. Here is an illustration of my problem. The white box is where it is in my opengl screen, yet the yellow outline is where my hit is registered.
selection of box (http://people.clemson.edu/~rlieber/selection.jpg)

Here is the code that I use to make the selection. Thank you anyone for your help

code for selection (http://people.clemson.edu/~rlieber/cbtest.cpp)

nk
05-15-2004, 10:52 AM
I think your problem is in this lines:

gluPickMatrix(
(GLdouble)mouse_x-100.0f,
(GLdouble)(viewport[3]-mouse_y)+140.0f,
1.0f,
1.0f,
viewport);

gluPerspective(45.0f,
(GLfloat)(viewport[2]-viewport[0])/(GLfloat)(viewport[3]-viewport[1]),0.1f,100.0f);

it sould be:
gluPickMatrix(
(GLdouble)mouse_x,
(GLdouble)(viewport[3]-mouse_y),
5.0f, //here you can try a grater value - it's the size of picking region in screen cords(pixels?)
5.0f, //here you can try a grater value also
viewport);

also for
gluPerspective(45.0f,
(GLfloat)(viewport[2]-viewport[0])/(GLfloat)(viewport[3]-viewport[1]),0.1f, 150.0f);

keep the same values used in your SizeOpenGLScreen function.

I think that OGL will report a hit when the mouse
is over the white rectangle, but not necessary when the mouse is in the CENTER of the rectangle.
Also you can play with gluPickMatrix's 3rd and 4th parameters. By increaseing them the rectangle will be picked when the mouse is close to the rectangle, but does not touch it.

dlswimmer
05-15-2004, 11:36 AM
thank you, I put those values in for a reason for another program and just copied it into this one without really looking. Thanks again