Dragging NURBS Control Points

Hello. I also have been trying to to convert the position of the mouse click to world coordinates so that I may drag a control point of a NURBS. Following info in a FAQ on www.opengl.org I read about using glReadPixels() to query for the screen z coordinate. Unfortunately, my code has been producing strange results. The source for my screen_to_world() routine is online at http://srv.acenetworks.org/~porters/coord.c

The strange results seem to occur when the screen z value changes, here is some example debug output from my program:

sirannon: warning: screen: 488.00 192.00 0.99 world: 6.10 -3.01 -0.28
sirannon: warning: screen: 488.00 191.00 0.99 world: 6.10 -3.06 -0.29
sirannon: warning: screen: 488.00 190.00 0.99 world: 6.09 -3.12 -0.29
sirannon: warning: screen: 488.00 189.00 1.00 world: 32.62 75.52 -94.19
sirannon: warning: screen: 489.00 189.00 1.00 world: 32.81 75.52 -94.19
sirannon: warning: screen: 489.00 188.00 1.00 world: 32.81 75.33 -94.37

As you can see, when the screen z goes from 0.99 to 1.00 the world coordinates get totally out of whack. Whereas while the z coord remains 0.99 it was adjusting the control point’s position just fine.

Any ideas? Thanks!


I had that type of fight to. To use glReadPixels() you have to be on the lowest matrix when drawing, not after and not before, you have to call it between glBegin and glEnd. Only at this point you get the results you really want, all other attempts will fail!
Try searching for mphanke on the board I posted about this already.