PDA

View Full Version : Snap to vertex



02-27-2002, 05:09 AM
G'Day !

I am writing a vector drawing program on Linux using Mesa on X-window 4.x
using GTK+ on a gtkglarea.

What I am trying to do is when drawing a primative (point, line etc.) I want the cursor to snap to the closest existing vertex if within a certain distance.

My first thought is to try and use the selection mechanism, but I'm not sure how to proceed. Has any one done this before ?

Currently I am storing my vertex information in a linked list, so it will be eaisily editable.

I do not want to use a X window function, due to portability issues.

cheers,
Jim Parker

Furrage
02-27-2002, 05:29 AM
I'm not sure if selection is the best way to go. It will give you all the points near the mouse but it won't tell you which is closest. I have not looked at feedback but it might be the answer. Alternatively you'll have to use gluUnproject() to get a line through your viewing volume and then check your vertex structure to see which is closest.

02-27-2002, 10:09 AM
I had never thought of gluUnProject () ... Might be just what I was looking for.

Will have to write a test program and see.

Thanks,
Jim Parker

iNsaNEiVaN
02-27-2002, 02:38 PM
Just cycle through all your current vertices, and return a pointer to whichever is closest.

Jambolo
02-27-2002, 09:41 PM
It would be better to use gluProject to compare 2D distances, rather than gluUnproject to compare 3D distance.

Furrage
02-28-2002, 04:36 AM
Originally posted by Jambolo:
It would be better to use gluProject to compare 2D distances, rather than gluUnproject to compare 3D distance.

Good idea! I never thought of that.