PDA

View Full Version : picking in QGLWidget



kernel_panic
1st January 2008, 12:16
Hi!
First of all i wish all of you a happy new year!
And now to my problem. I'm a kind of 3d Desktop and use QGLWidget (OpenGL) and ode for realizing it. I did everything well, but now i ask me how to pick objects with the mouse.
I call only these two transformations in paintGL:

glTranslatef(0.0, 0.0, -80.0);
glRotatef(90, 1.0, 0.0, 0.0);
The Z-Axis doesn't matter for me i only need the x/y coordinates of one object (or x/z because of the rotation).
Now i tried following to translate the coordinates of the objects to normal paint coordinates, but somehow it doesn't work.......

float *geoPos = (float*)dGeomGetPosition(objs[i].geom);
QPoint bodyPos = QPoint((geoPos[2]+8)*80, (geoPos[0]+8)*80);
QRegion bodyRegion(bodyPos.x(), bodyPos.y(), 80, 80);
if(bodyRegion.contains(mousePos))
qDebug("contains");

Can anyone help me and say how i translate the object coordinates into the same format as the mouse coordinates are?

adonel
1st January 2008, 19:36
Hello and happy new year,

I think you should take a look at the OpenGl picking mechanism (through the use of logig names for every entity that you want to be able to pick).

Take a look at: http://gpwiki.org/index.php/OpenGL:Tutorials:Picking
or google it!

kernel_panic
2nd January 2008, 11:38
this helped me very much.
thanks!