Skip to content

Commit

Permalink
Allow constructing Quat from two Vector3s
Browse files Browse the repository at this point in the history
GDScript in Godot 3 doesn't allow having multiple constructors with the
same argument count but different types.
  • Loading branch information
timothyqiu committed Apr 10, 2024
1 parent f7e9369 commit 76a4223
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ struct _VariantCall {
VCALL_LOCALMEM1R(Vector3, limit_length);
VCALL_LOCALMEM0R(Vector3, sign);

static void _call_Vector3_quat_to(Variant &r_ret, Variant &p_self, const Variant **p_args) {
r_ret = Quat(p_self.operator Vector3(), p_args[0]->operator Vector3());
}

VCALL_LOCALMEM0R(Plane, normalized);
VCALL_LOCALMEM0R(Plane, center);
VCALL_LOCALMEM0R(Plane, get_any_point);
Expand Down Expand Up @@ -1874,6 +1878,7 @@ void register_variant_methods() {
ADDFUNC1R(VECTOR3, VECTOR3, Vector3, reflect, VECTOR3, "n", varray());
ADDFUNC1R(VECTOR3, VECTOR3, Vector3, limit_length, REAL, "length", varray(1.0));
ADDFUNC0R(VECTOR3, VECTOR3, Vector3, sign, varray());
ADDFUNC1R(VECTOR3, QUAT, Vector3, quat_to, VECTOR3, "to", varray());

ADDFUNC0R(PLANE, PLANE, Plane, normalized, varray());
ADDFUNC0R(PLANE, VECTOR3, Plane, center, varray());
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/Vector3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@
Returns this vector projected onto the vector [code]b[/code].
</description>
</method>
<method name="quat_to">
<return type="Quat" />
<argument index="0" name="to" type="Vector3" />
<description>
Returns the quaternion representing the shortest arc between this vector and [code]to[/code]. These can be imagined as two points intersecting a sphere's surface, with a radius of [code]1.0[/code].
</description>
</method>
<method name="reflect">
<return type="Vector3" />
<argument index="0" name="n" type="Vector3" />
Expand Down

0 comments on commit 76a4223

Please sign in to comment.