"Snap to grid" is scoring quite high in the feature voting. I am starting to think about ways to implement it, but since the item types in a Box2D scene are quite different, there does not seem to be any one specific way to handle them all. I'm wondering if people who have something specific in mind could comment here about what would help them out. Mainly I'm looking for people who have actually come across this issue in real situations in the past, rather than a general brainstorm.
Firstly the grid dimensions would need to be defined, which would go in the scene settings dialog, with x,y sizes for grid cells, for each edit mode (body, fixture, vertex, image, joint).
For some edit modes it seems quite straightforward, eg. for bodies, joints and vertices, I guess the position of the body/anchor/vertex could snap to the grid. For fixtures and images though it's not so simple. There does not seem to be any obvious way to align these with a grid, especially fixtures which are not even restricted to being rectangular. Any comments about this would be appreciated.
Ideas for "Snap to grid"
Re: Ideas for "Snap to grid"
> For fixtures and images though it's not so simple. There does not seem to be any obvious way to align these with a grid
My understanding of snap to grid is simply that whatever you're dragging gets snapped to a grid point. Whether it's fixture vertices, bodies or joints, I don't see what the difference is?
I use this feature in Box2d Body Editor for creating large static fixtures for levels, e.g. mazes. I use arbitrarily shaped polygons but often need various points from different fixtures to line up along the same x/y plane. Without snap to grid, the only way to align them is manually setting the location in the Property panel.
Can you not implement it globally as a modifier to the mouse x/y coordinates if snap to grid is on?
My understanding of snap to grid is simply that whatever you're dragging gets snapped to a grid point. Whether it's fixture vertices, bodies or joints, I don't see what the difference is?
I use this feature in Box2d Body Editor for creating large static fixtures for levels, e.g. mazes. I use arbitrarily shaped polygons but often need various points from different fixtures to line up along the same x/y plane. Without snap to grid, the only way to align them is manually setting the location in the Property panel.
Can you not implement it globally as a modifier to the mouse x/y coordinates if snap to grid is on?
Re: Ideas for "Snap to grid"
The difference is that a body is a single point, which is easy and intuitive to snap to a grid, while a fixture can have hundreds of points.joolean wrote:... whatever you're dragging gets snapped to a grid point. Whether it's fixture vertices, bodies or joints, I don't see what the difference is?
Take this for example: It's all very well to say "just snap it to the grid" but how exactly? The only way I can think of is to have every point of the fixture checking for the closest grid-line to itself, and then choose the closest among them. Seems like a reasonable solution, but I was wondering if there was a better way.
You say that you line fixtures up along the same x/y plane... does this involve rotating them? Are we still talking about a grid, or are they being snapped to the position of other fixtures?
Yes, it would be implemented as a modifier to the mouse coordinates.
Re: Ideas for "Snap to grid"
Ah ok sorry, I see what you mean. When I think of moving fixtures, I was only thinking of individual vertices.
If moving the whole fixture, then your solution of nearest vertex to grid point makes sense. Alternatively, the vertex nearest the mouse point when you start a transpose could be used as the sole anchor to snap to a grid point. I'm sure both use cases would be valid in different situations. The latter would be especially useful for complex polygons which could end up snapping all all over the place.
The same two techniques could be used for rotations and scaling.
Though it would be an order of magnitude more complex, I can see valid use cases for snapping to other vertices/ bodies/ joints as well.
When I was referring to aligning on the xy, I just meant vertices. For example take that image you posted. A common use case would be too make the bottom edge flat and the right edge vertical forming a right angle. Without snap to grid, it's not easy to do.
Jules
If moving the whole fixture, then your solution of nearest vertex to grid point makes sense. Alternatively, the vertex nearest the mouse point when you start a transpose could be used as the sole anchor to snap to a grid point. I'm sure both use cases would be valid in different situations. The latter would be especially useful for complex polygons which could end up snapping all all over the place.
The same two techniques could be used for rotations and scaling.
Though it would be an order of magnitude more complex, I can see valid use cases for snapping to other vertices/ bodies/ joints as well.
When I was referring to aligning on the xy, I just meant vertices. For example take that image you posted. A common use case would be too make the bottom edge flat and the right edge vertical forming a right angle. Without snap to grid, it's not easy to do.
Jules
-
- Posts: 5
- Joined: Mon Jul 01, 2013 1:37 am
Re: Ideas for "Snap to grid"
It would be fairly complex to make grid snap cover all the bases.
What I think would work well enough for most cases would be:
- For each item type, have some sensible potentially snappable features, eg vertices, bounding box corners, centre points etc. So a polygon would expose vertices, bounding box corners and centre point. An image would have bounding box corners, actual corners and centre point.
- While the item(s) are selected and before starting the translate, highlight on-screen whichever of these snappable features is closest to the mouse pointer, so the user knows exactly what they're going to get.
- When starting the translate, snap that feature that was closest to the mouse pointer.
I'd love to see options to snap to other items too, eg snap to other vertices or lines in the scene. So you would choose between off, grid, vertex, line etc...
What I think would work well enough for most cases would be:
- For each item type, have some sensible potentially snappable features, eg vertices, bounding box corners, centre points etc. So a polygon would expose vertices, bounding box corners and centre point. An image would have bounding box corners, actual corners and centre point.
- While the item(s) are selected and before starting the translate, highlight on-screen whichever of these snappable features is closest to the mouse pointer, so the user knows exactly what they're going to get.
- When starting the translate, snap that feature that was closest to the mouse pointer.
I'd love to see options to snap to other items too, eg snap to other vertices or lines in the scene. So you would choose between off, grid, vertex, line etc...
Re: Ideas for "Snap to grid"
![Idea :idea:](./images/smilies/icon_idea.gif)