godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

Transform2D is missing xform and xform_inv methods

Open LuisCarli opened this issue 2 years ago • 6 comments

Godot version

4.0rc2

System information

MacOS 13.1

Issue description

In Godot 4.0, the Transform2D class is not exposing the xform and xform_inv methods anymore.

Steps to reproduce

Minimal reproduction project

LuisCarli avatar Feb 17 '23 20:02 LuisCarli

xform and xform_inv have been replaced with a normal multiplcation with *. The project upgrade tool will do the conversion automatically for you if you run it on a 3.x project.

xform and xform_inv should be added to the migration guide as well https://docs.godotengine.org/en/latest/tutorials/migrating/upgrading_to_godot_4.html#manually-renaming-methods-properties-signals-and-constants

clayjohn avatar Feb 17 '23 21:02 clayjohn

@clayjohn Thank you!

I just wanted to confirm if I'm also missing something here, or if this is the expected behavior: Transform2D * Vector2D operation is giving me the results I expect, but the inverse Vector2D * Transform2D is not.

Example:

func _ready():
	var node2d := Node2D.new()
	node2d.position = Vector2(100, 100)
	node2d.rotation = PI/2
	node2d.scale = Vector2(3.5, 2.5)
	
	var point = Node2D.new()
	point.position = Vector2(100, 100)
	add_child(node2d)
	node2d.add_child(point)
	
	var t = node2d.get_global_transform()
	
	prints(point.position) # (100, 100)
	prints(point.global_position) # (-150, 450)
	print(t * point.position) # (-150, 450)
	print(point.global_position * t) # (1225, 625)

I tried to describe the problem on the issue #71035, but maybe I was not clear enough.

LuisCarli avatar Feb 17 '23 21:02 LuisCarli

I think this is a different issue from #71035. In either case I think the values are expected. They just might not be what you personally expect.

I converted your code block to use xform and xform_inv in 3.x and it produces the same results:

func _ready():
	var node2d = Node2D.new()
	node2d.position = Vector2(100, 100)
	node2d.rotation = PI/2
	node2d.scale = Vector2(3.5, 2.5)
	
	var point = Node2D.new()
	point.position = Vector2(100, 100)
	add_child(node2d)
	node2d.add_child(point)
	
	var t = node2d.get_global_transform()
	
	prints(point.position) # (100, 100)
	prints(point.global_position) # (-150, 450)
	print(t.xform(point.position)) # (-150, 450)
	print(t.xform_inv(point.global_position)) # (1225, 625)

So it sounds like xform_inv does not do what you think it does. So it should be better documented. At any rate, that is in issue to discuss in #71035 as this Issue is only about the rename of xform and xform_inv

clayjohn avatar Feb 18 '23 02:02 clayjohn

@clayjohn did you mean to say the conversion tool "does not" convert xform and xform_inv automatically? I don't see them listed on the renames file. And the guide says everything that's done automatically should be there.

skyace65 avatar Mar 29 '23 00:03 skyace65

Hello, I'm curious whether the xform function in Godot 3 can be entirely replaced by * in Godot 4. The deprecated function supported multiple types of parameters, including Vector3, Plane, AABB, and PoolVector3Array.

Sorry, my math isn't good...

BioPyRope avatar Apr 07 '24 13:04 BioPyRope

you mean something like this and get (3, 5, 7)? var transform = Transform() transform.origin = Vector3(1, 2, 3) transform.basis = Basis() print(transform.xform(Vector3(2, 3, 4))) Also I think that would be replaced by (example vector) + (second example vector) right? (sorry I don't get godot 3)

QuotientParadox avatar Jun 12 '24 17:06 QuotientParadox