XForms: Picking

Steve Lamont (spl@szechuan.ucsd.edu)
Sat, 4 Apr 98 16:06:02 PST

# To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> I ahve a canvas whoich people can draw objects on to.. lines circle and
> polygons and stuff.
> How do I (easily?) let the user be able to 'select' certian objects with
> the mouse. For example, if a user wanted to select a line thats is in the
> canvas to he could rotate that line, how would he do it? I have
> button_press/release/motion mouse handlers.. but I can't figure out a way
> to accomplish this.

If you're using a graphics API such as OpenGL, then there is a
function call that allows picking. Offhand I forget its name but if
you peruse the OpenGL programming guide, it should be obvious.

If you're drawing your own objects, then basically you'll have to do
it yourself. Presumably you keep some form of display list. You'll
have to traverse the list, comparing the picked point with the points
in the list. If you have a collection of line segments, you'll need
to calculate the distance from the point to the line segment and find
the nearest one. Check the Graphics Gems series of books or any good
book on computational geometry -- O'Rourke comes to mind.

To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
XForms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/