Snap-to grid???

This isn’t really a gl question, more a conceptual thing…

How should one implement a snap-to grid in 2D ortho viewing? I can place vertices and drag objects. Now I have a requirement to snap the vertices to points on a grid.

I can’t see that rendering thousands of grid points in selection mode is the way to do it. It would be hopelessly inffecient. Maybe it would be ok for add vertices, but not dragging.

The effect that I’m supposed to implement is… when you drag a point with the mouse it will jump from grid point to grid point. I can’t find any reference material on this and it seems really tricky.

Any help appreciated.

Matthew

Lets assume the grid you are talking about are based on integers (or whole numbers). As you drag a vertex, store the vertex as floats, but when drawing it round to the nearest integer - and when you release the mouse button convert the final coordinate to a whole number!

Nice! I like it. So simple. Actually, the divisions in the grid are .05 but they could be anything so all that I need is to do a simple mapping based on your idea.

Thanks a lot.

Matthew