-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Object position and vertices are not intuitive. #762
Comments
Moving an object while adjusting its shape is pretty much out of the question because of the difficulties this would cause, especially for rotated objects. An alternative would be to display a special marker at the position of the object, with which it can be moved. Adding polyline/polygon points to the Properties view is difficult, because the view can currently only display Object-based classes whereas the polyline/polygon is just a list of QPointF. However, I agree it would be a nice thing to do. |
Tiled already supports a visual bounding box that surrounds the area of an object (when dealing with relocation and rotation), wouldn't it be possible to use the data from that bounding box as a basis for an object's position? I would suggest using the centre of that box as the object position, and adjust the vertex data relative to that. I suspect you already have all the math written in Tiled to do this, it would just be a matter of piecing it together. |
No, it is more complicated than that. When you adjust the position of a polygon because you're moving one of its points, that means you will have to move all the other points too just to make sure they stay in the same place. And this adjustment gets a little complicated since the polygon may be rotated as well. |
Relocating an object is a very straight-forward operation in and of itself. When you click and hold the object, you can the put it into "move" mode. Since all the vertices are moving relative to the object position, all this means is you need to add the different between when you press and when you release the mouse button to each vertex. To factor in rotation, you could un-rotate the object, modify the vertices, and re-rotate it. Forgive the Lua: function process_move()
diff = { x=mr.x-mp.x, y=mr.y-mp.y } -- we now have the difference in where we dragged from, to where we dragged to
-- temporarily undo rotation
object = reverse_rotate(object)
-- loop through each vertex and include the movement
for _, vertex in ipairs(object.polygon) do
vertex.x = vertex.x + diff.x
vertex.y = vertex.y + diff.y
end
-- re-apply rotation
object = rotate(object)
end
love.mousepressed(x, y, button)
mp = { x=x, y=y }
end
love.mousereleased(x, y, button)
mr = { x=x, y=y }
process_move()
end |
Hmm, that doesn't seem like a complete implementation. For example, the rotation of the object also affects how the mouse movement should be interpreted. And when adjusting the points the origin point is supposed to stay in the same place. Anyway, maybe one day I will have time to dig into this code again. |
After discussing this issue with @shakesoda, it makes sense that an object's position is not adjusted automatically since a use case for such an offset is using the position as an axis for rotation. However, it might be useful to add a "recentre position" button to allow a user to fix their axis of rotation. |
In other programs I've worked with (AutoCAD and Google Maps API), there were no position or rotation attribute on the polygons, only the absolutely positioned vertices. Moving the polygon would be done by moving all vertices. This solution wouldn't even break existing parsers, since you can set the position and rotation to 0 and everything should load as always. |
@zilluss That approach works for static meshes, but is not ideal for objects that can move or rotate in the game or when in the future support of "instancing" the same shape multiple times is added. |
Scenario 1
I have a polyline. I create it in a random spot on the map and then drag the vertices to where I want them to be.
Expectation
Reality
Scenario 2
I have a polygon. I create it in a random spot on the map and then drag the vertices to where I want them to be.
Expectation
Reality
The text was updated successfully, but these errors were encountered: