Skip to content
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

Open
karai17 opened this issue Sep 22, 2014 · 8 comments
Open

Object position and vertices are not intuitive. #762

karai17 opened this issue Sep 22, 2014 · 8 comments

Comments

@karai17
Copy link

karai17 commented Sep 22, 2014

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

  • Object position is adjusted based on the first vertex.
  • Individual vertices show up in the properties and can be manually adjusted for precision.

Reality

  • Object position stays where I originally placed it
  • Vertices move relative to that position
  • Vertices are not able to be precisely adjusted

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

  • Object position is dynamically adjusted based on the top-left most vertex.
  • Individual vertices show up in the properties and can be manually adjusted for precision.

Reality

  • Object position stays where I originally placed it
  • Vertices move relative to that position
  • Vertices are not able to be precisely adjusted
@bjorn
Copy link
Member

bjorn commented Sep 22, 2014

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.

@karai17
Copy link
Author

karai17 commented Sep 22, 2014

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.

@bjorn
Copy link
Member

bjorn commented Sep 22, 2014

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.

@karai17
Copy link
Author

karai17 commented Sep 22, 2014

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

@bjorn
Copy link
Member

bjorn commented Sep 22, 2014

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.

@karai17
Copy link
Author

karai17 commented Sep 22, 2014

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.

@zilluss
Copy link

zilluss commented Sep 23, 2014

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.
As the polygon is rotated, the vertices are updated. For this to work, the rotation pivot must be generated when the polygon is selected, at the center of the polygon's bounding box. You could even give the user the option to move the rotation pivot, like it's the case in Photoshop or Gimp. Also, when you parse a map, you don't need to calculate the vertices from rotation and position (this was the most unintuitive part for me when I was writing the map parser for my game).

This solution wouldn't even break existing parsers, since you can set the position and rotation to 0 and everything should load as always.

@bjorn
Copy link
Member

bjorn commented Sep 23, 2014

@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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants