Snap to vertex

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

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.

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

Just cycle through all your current vertices, and return a pointer to whichever is closest.

It would be better to use gluProject to compare 2D distances, rather than gluUnproject to compare 3D distance.

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.