From 5136366112a720d22471b8e50431534323681669 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Sat, 14 Jan 2023 18:03:01 +0100 Subject: C#: Add missing `Transform{2D,3D}` and `Basis` constructors - Remove `Transform3D(Quaternion, Vector3)` constructor from C#. - Add `Transform3D(Projection)` constructor to C#. - Add documentation to the `Transform3D(Projection)` constructor in Core. - Add `Transform3D` constructor with only real_t params to C# that mirrors `Transform2D`. - Expose `Basis` constructor with only real_t params in C#. - Add `Transform2D(real_t, Vector2, real_t, Vector2)` constructor to C#. --- .../mono/glue/GodotSharp/GodotSharp/Core/Basis.cs | 16 +++++++- .../glue/GodotSharp/GodotSharp/Core/Transform2D.cs | 20 ++++++++- .../glue/GodotSharp/GodotSharp/Core/Transform3D.cs | 47 ++++++++++++++++++---- 3 files changed, 73 insertions(+), 10 deletions(-) (limited to 'modules/mono/glue') diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs index 5aa1622bf8..36bb62ca3e 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs @@ -977,8 +977,20 @@ namespace Godot // We need to assign the struct fields here first so we can't do it that way... } - // Arguments are named such that xy is equal to calling x.y - internal Basis(real_t xx, real_t yx, real_t zx, real_t xy, real_t yy, real_t zy, real_t xz, real_t yz, real_t zz) + /// + /// Constructs a transformation matrix from the given components. + /// Arguments are named such that xy is equal to calling x.y. + /// + /// The X component of the X column vector, accessed via b.x.x or [0][0]. + /// The X component of the Y column vector, accessed via b.y.x or [1][0]. + /// The X component of the Z column vector, accessed via b.z.x or [2][0]. + /// The Y component of the X column vector, accessed via b.x.y or [0][1]. + /// The Y component of the Y column vector, accessed via b.y.y or [1][1]. + /// The Y component of the Z column vector, accessed via b.y.y or [2][1]. + /// The Z component of the X column vector, accessed via b.x.y or [0][2]. + /// The Z component of the Y column vector, accessed via b.y.y or [1][2]. + /// The Z component of the Z column vector, accessed via b.y.y or [2][2]. + public Basis(real_t xx, real_t yx, real_t zx, real_t xy, real_t yy, real_t zy, real_t xz, real_t yz, real_t zz) { Row0 = new Vector3(xx, yx, zx); Row1 = new Vector3(xy, yy, zy); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs index c99d91bff1..8566899770 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -433,7 +433,7 @@ namespace Godot /// /// Constructs a transformation matrix from the given components. - /// Arguments are named such that xy is equal to calling x.y + /// Arguments are named such that xy is equal to calling x.y. /// /// The X component of the X column vector, accessed via t.x.x or [0][0]. /// The Y component of the X column vector, accessed via t.x.y or [0][1]. @@ -462,6 +462,24 @@ namespace Godot this.origin = origin; } + /// + /// Constructs a transformation matrix from a value, + /// vector, value, and + /// vector. + /// + /// The rotation of the new transform, in radians. + /// The scale of the new transform. + /// The skew of the new transform, in radians. + /// The origin vector, or column index 2. + public Transform2D(real_t rotation, Vector2 scale, real_t skew, Vector2 origin) + { + x.x = Mathf.Cos(rotation) * scale.x; + y.y = Mathf.Cos(rotation + skew) * scale.y; + y.x = -Mathf.Sin(rotation + skew) * scale.y; + x.y = Mathf.Sin(rotation) * scale.x; + this.origin = origin; + } + /// /// Composes these two transformation matrices by multiplying them /// together. This has the effect of transforming the second transform diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs index dee1e91512..e2388fcbb3 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs @@ -356,15 +356,25 @@ namespace Godot } /// - /// Constructs a transformation matrix from the given - /// and vector. + /// Constructs a transformation matrix from the given components. + /// Arguments are named such that xy is equal to calling basis.x.y. /// - /// The to create the basis from. - /// The origin vector, or column index 3. - public Transform3D(Quaternion quaternion, Vector3 origin) + /// The X component of the X column vector, accessed via t.basis.x.x or [0][0]. + /// The X component of the Y column vector, accessed via t.basis.y.x or [1][0]. + /// The X component of the Z column vector, accessed via t.basis.z.x or [2][0]. + /// The Y component of the X column vector, accessed via t.basis.x.y or [0][1]. + /// The Y component of the Y column vector, accessed via t.basis.y.y or [1][1]. + /// The Y component of the Z column vector, accessed via t.basis.y.y or [2][1]. + /// The Z component of the X column vector, accessed via t.basis.x.y or [0][2]. + /// The Z component of the Y column vector, accessed via t.basis.y.y or [1][2]. + /// The Z component of the Z column vector, accessed via t.basis.y.y or [2][2]. + /// The X component of the origin vector, accessed via t.origin.x or [2][0]. + /// The Y component of the origin vector, accessed via t.origin.y or [2][1]. + /// The Z component of the origin vector, accessed via t.origin.z or [2][2]. + public Transform3D(real_t xx, real_t yx, real_t zx, real_t xy, real_t yy, real_t zy, real_t xz, real_t yz, real_t zz, real_t ox, real_t oy, real_t oz) { - basis = new Basis(quaternion); - this.origin = origin; + basis = new Basis(xx, yx, zx, xy, yy, zy, xz, yz, zz); + origin = new Vector3(ox, oy, oz); } /// @@ -379,6 +389,29 @@ namespace Godot this.origin = origin; } + /// + /// Constructs a transformation matrix from the given + /// by trimming the last row of the projection matrix (projection.x.w, + /// projection.y.w, projection.z.w, and projection.w.w + /// are not copied over). + /// + /// The to create the transform from. + public Transform3D(Projection projection) + { + basis = new Basis + ( + projection.x.x, projection.y.x, projection.z.x, + projection.x.y, projection.y.y, projection.z.y, + projection.x.z, projection.y.z, projection.z.z + ); + origin = new Vector3 + ( + projection.w.x, + projection.w.y, + projection.w.z + ); + } + /// /// Composes these two transformation matrices by multiplying them /// together. This has the effect of transforming the second transform -- cgit v1.2.3