-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose some useful method from rotation class Quaternion
& Basis
& Transform2D
to GDScript
#69202
Expose some useful method from rotation class Quaternion
& Basis
& Transform2D
to GDScript
#69202
Conversation
a2404ef
to
88c9dc9
Compare
Quaternion
& Basis
in GDScriptQuaternion
& Basis
to GDScript
88c9dc9
to
edc3468
Compare
edc3468
to
234f8e9
Compare
234f8e9
to
6267281
Compare
Added some functions to Transform2D for scale, but I am not sure if the behavior is correct, so I will test it later. |
Quaternion
& Basis
to GDScriptQuaternion
& Basis
& Transform2D
to GDScript
6267281
to
12241ab
Compare
Finished testing the methods added in Transform2D. The calculation seems to be correct. |
12241ab
to
8d6690d
Compare
@@ -144,6 +156,18 @@ void Transform2D::translate_local(const Vector2 &p_translation) { | |||
columns[2] += basis_xform(p_translation); | |||
} | |||
|
|||
void Transform2D::orthogonalize() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with a method like this is that its very misleading. You cant call multiple times without incurring into precision loss. The size will mutate over time and deform the object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same thing has already been done in Basis, but I can't think of any other way. Definitely there is an accuracy issue, but I assume that calling it multiple times (consectively) seems to be a corner case. Should I describe the possible loss of accuracy in the documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added notes:
Note: When a Basis/Transform2D that is already orthogonalized uses this method, the equality of the values before and after is not guaranteed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding notes, I added a check is_orthogonal()
to Basis and added a check Math::is_zero_approx(get_skew())
to Transform2D for making guarantee the equality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One possibility for the Transform2D version is to always make the Y axis orthogonal to the X axis and leave the X axis untouched, this should more or less avoid precision errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented what you said, but the behavior is no different from setting skew = 0, so I don't think there is much point in having it. Well, I think it is fine to have the function for consistency with 3D.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now
Vector2 y = Vector2(-(columns[0].y), columns[0].x).normalized(); // Make a vector orthogonal to x.
if (y.dot(columns[1].normalized()) < 0) {
y = -y; // Flip to be closer to current y.
}
columns[1] = y * columns[1].length();
427e8f9
to
1cc4474
Compare
Quaternion
& Basis
& Transform2D
to GDScriptQuaternion
& Basis
& Transform2D
to GDScript
1cc4474
to
5125ed2
Compare
5125ed2
to
2fe4d24
Compare
Note that adding mutating methods to the binds is not possible and doesn't work, see #62706 |
Expose useful methods to GDScript for calculating rotations and scales.