|
|
|
 |
Reply From: |
Xrayez |
The actual coordinates that define a polygon are actually local, the position of Polygon2D
doesn’t automatically shift all the coordinates defined by the polygon for it to be represented in global coordinates, you can use an overridden xform
method for translating an array of points.
Edit: transform_points_2d
is removed since 3.2.beta in favor of xform
, see this PR.
if event.is_action_pressed("leftclick"):
var trans = Transform2D(0.0, get_global_mouse_position())
var polyB = trans.xform(adder.get_polygon())
mergeResult = Geometry.merge_polygons_2d(levelVec2, polyB)
Similarly the levelVec2
polygon needs to be transformed perhaps.
Also, merge_polygons_2d
will return an empty array if neither polygon overlap.
I was wondering if transform_points_2d was the key to this. I’ll check it out a little later and let you know if it works. Thank you so much and thank you for your contributions to Godot I never thought I’d get a response from the person actually making this happen! You rock!!
spiderbyte87 | 2019-08-28 14:49
Thanks! You can download a test project in this pull request where transform_points_2d
is actually used, just for reference.
Xrayez | 2019-08-28 14:56
I took a look at your example and I’m still confused.
Basically I’m trying to move polygon A to the mouse position on click, merge it with polygon B, then modify the vertices on the polygon B to match the merge.
spiderbyte87 | 2019-08-28 19:48
Not sure what exactly you’re confused with.
func polygon_at_mouse_position(p_polygon):
var offset = Transform2D(0.0, get_global_mouse_position())
var polygon = Geometry.transform_points_2d(p_polygon, offset)
return polygon
This function should essentially “move” any polygon to mouse position (returns modified vertices themselves). Ideally you shouldn’t change the position of Polygon2D
nodes while doing this as well.
Xrayez | 2019-08-28 20:19
I’ll give that a try. Thank you for your help and patience.
spiderbyte87 | 2019-08-28 22:44
The Geometry.transform_points_2d() doesn’t seem to be merged (or functional) as of 3.2beta2.
I get Invalid call. Nonexistent function ‘transform_points_2d’ in base ‘_Geometry’.
gururise | 2019-11-29 06:27