From d9a8497546735ddf851824f773e5646f3a8f34ac Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 14 Aug 2022 14:59:46 +0200 Subject: [PATCH] Renamed translate in Transform2D to translate_local. --- core/math/transform_2d.cpp | 13 ++++++------- core/math/transform_2d.h | 12 +++++++++--- core/variant_call.cpp | 4 ++-- editor/plugins/canvas_item_editor_plugin.cpp | 4 ++-- editor/plugins/curve_editor_plugin.cpp | 4 ++-- modules/props_2d/prop_2d_instance_merger.cpp | 2 +- scene/2d/ray_cast_2d.cpp | 2 +- scene/2d/touch_screen_button.cpp | 4 ++-- 8 files changed, 25 insertions(+), 20 deletions(-) diff --git a/core/math/transform_2d.cpp b/core/math/transform_2d.cpp index 56132715c..b60343b57 100644 --- a/core/math/transform_2d.cpp +++ b/core/math/transform_2d.cpp @@ -114,10 +114,10 @@ void Transform2D::scale_basis(const Size2 &p_scale) { elements[1][0] *= p_scale.x; elements[1][1] *= p_scale.y; } -void Transform2D::translate(real_t p_tx, real_t p_ty) { - translate(Vector2(p_tx, p_ty)); +void Transform2D::translate_local(real_t p_tx, real_t p_ty) { + translate_local(Vector2(p_tx, p_ty)); } -void Transform2D::translate(const Vector2 &p_translation) { +void Transform2D::translate_local(const Vector2 &p_translation) { elements[2] += basis_xform(p_translation); } @@ -205,10 +205,9 @@ Transform2D Transform2D::untranslated() const { return copy; } -Transform2D Transform2D::translated(const Vector2 &p_offset) const { - Transform2D copy = *this; - copy.translate(p_offset); - return copy; +Transform2D Transform2D::translated_local(const Vector2 &p_offset) const { + // Equivalent to right multiplication + return Transform2D(elements[0], elements[1], elements[2] + basis_xform(p_offset)); } Transform2D Transform2D::rotated(real_t p_phi) const { diff --git a/core/math/transform_2d.h b/core/math/transform_2d.h index 942486c57..ffe077abd 100644 --- a/core/math/transform_2d.h +++ b/core/math/transform_2d.h @@ -76,8 +76,8 @@ struct _NO_DISCARD_CLASS_ Transform2D { void scale(const Size2 &p_scale); void scale_basis(const Size2 &p_scale); - void translate(real_t p_tx, real_t p_ty); - void translate(const Vector2 &p_translation); + void translate_local(real_t p_tx, real_t p_ty); + void translate_local(const Vector2 &p_translation); real_t basis_determinant() const; @@ -89,7 +89,7 @@ struct _NO_DISCARD_CLASS_ Transform2D { Transform2D scaled(const Size2 &p_scale) const; Transform2D basis_scaled(const Size2 &p_scale) const; - Transform2D translated(const Vector2 &p_offset) const; + Transform2D translated_local(const Vector2 &p_offset) const; Transform2D rotated(real_t p_phi) const; Transform2D untranslated() const; @@ -135,6 +135,12 @@ struct _NO_DISCARD_CLASS_ Transform2D { elements[2][1] = oy; } + Transform2D(const Vector2 &p_x, const Vector2 &p_y, const Vector2 &p_origin) { + elements[0] = p_x; + elements[1] = p_y; + elements[2] = p_origin; + } + Transform2D(real_t p_rot, const Vector2 &p_pos); Transform2D() { elements[0][0] = 1.0; diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 649e2b06f..1c0f76083 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -1079,7 +1079,7 @@ struct _VariantCall { VCALL_PTR0R(Transform2D, orthonormalized); VCALL_PTR1R(Transform2D, rotated); VCALL_PTR1R(Transform2D, scaled); - VCALL_PTR1R(Transform2D, translated); + VCALL_PTR1R(Transform2D, translated_local); VCALL_PTR2R(Transform2D, interpolate_with); VCALL_PTR1R(Transform2D, is_equal_approx); @@ -2639,7 +2639,7 @@ void register_variant_methods() { ADDFUNC0R(TRANSFORM2D, TRANSFORM2D, Transform2D, orthonormalized, varray()); ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, rotated, REAL, "phi", varray()); ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, scaled, VECTOR2, "scale", varray()); - ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, translated, VECTOR2, "offset", varray()); + ADDFUNC1R(TRANSFORM2D, TRANSFORM2D, Transform2D, translated_local, VECTOR2, "offset", varray()); ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform, NIL, "v", varray()); ADDFUNC1R(TRANSFORM2D, NIL, Transform2D, xform_inv, NIL, "v", varray()); ADDFUNC1R(TRANSFORM2D, VECTOR2, Transform2D, basis_xform, VECTOR2, "v", varray()); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 6f18c43df..75dd6a2b9 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -2997,10 +2997,10 @@ void CanvasItemEditor::_draw_rulers() { if (show_grid || grid_snap_active) { List selection = _get_edited_canvas_items(); if (snap_relative && selection.size() > 0) { - ruler_transform.translate(_get_encompassing_rect_from_list(selection).position); + ruler_transform.translate_local(_get_encompassing_rect_from_list(selection).position); ruler_transform.scale_basis(grid_step * Math::pow(2.0, grid_step_multiplier)); } else { - ruler_transform.translate(grid_offset); + ruler_transform.translate_local(grid_offset); ruler_transform.scale_basis(grid_step * Math::pow(2.0, grid_step_multiplier)); } while ((transform * ruler_transform).get_scale().x < 50 || (transform * ruler_transform).get_scale().y < 50) { diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 66073e2ed..063b81e3b 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -554,11 +554,11 @@ void CurveEditor::update_view_transform() { const Vector2 scale = view_size / world_rect.size; Transform2D world_trans; - world_trans.translate(-world_rect.position - Vector2(0, world_rect.size.y)); + world_trans.translate_local(-world_rect.position - Vector2(0, world_rect.size.y)); world_trans.scale(Vector2(scale.x, -scale.y)); Transform2D view_trans; - view_trans.translate(view_margin); + view_trans.translate_local(view_margin); _world_to_view = view_trans * world_trans; } diff --git a/modules/props_2d/prop_2d_instance_merger.cpp b/modules/props_2d/prop_2d_instance_merger.cpp index 6ab8a94fb..b113235b9 100644 --- a/modules/props_2d/prop_2d_instance_merger.cpp +++ b/modules/props_2d/prop_2d_instance_merger.cpp @@ -412,7 +412,7 @@ void Prop2DInstanceMerger::_prop_preprocess(Transform2D transform, const Refadd_collision_shape(tws, tt, true); } diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp index da23ef3dd..d2a9ea9ee 100644 --- a/scene/2d/ray_cast_2d.cpp +++ b/scene/2d/ray_cast_2d.cpp @@ -231,7 +231,7 @@ void RayCast2D::_draw_debug_shape() { Transform2D xf; xf.rotate(cast_to.angle()); - xf.translate(Vector2(no_line ? 0 : line_length - arrow_size, 0)); + xf.translate_local(Vector2(no_line ? 0 : line_length - arrow_size, 0)); Vector pts; pts.push_back(xf.xform(Vector2(arrow_size, 0))); diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index ac40970c5..4aee1f1bf 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -133,7 +133,7 @@ void TouchScreenButton::_notification(int p_what) { Vector2 size = texture.is_null() ? shape->get_rect().size : texture->get_size(); Vector2 pos = shape_centered ? size * 0.5f : Vector2(); - draw_set_transform_matrix(get_canvas_transform().translated(pos)); + draw_set_transform_matrix(get_canvas_transform().translated_local(pos)); shape->draw(get_canvas_item(), draw_col); } @@ -254,7 +254,7 @@ bool TouchScreenButton::_is_point_inside(const Point2 &p_point) { check_rect = false; Vector2 size = texture.is_null() ? shape->get_rect().size : texture->get_size(); - Transform2D xform = shape_centered ? Transform2D().translated(size * 0.5f) : Transform2D(); + Transform2D xform = shape_centered ? Transform2D().translated_local(size * 0.5f) : Transform2D(); touched = shape->collide(xform, unit_rect, Transform2D(0, coord + Vector2(0.5, 0.5))); }