Renamed translate in Transform2D to translate_local.

This commit is contained in:
Relintai 2022-08-14 14:59:46 +02:00
parent 662c3a7e88
commit d9a8497546
8 changed files with 25 additions and 20 deletions

View File

@ -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 {

View File

@ -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;

View File

@ -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());

View File

@ -2997,10 +2997,10 @@ void CanvasItemEditor::_draw_rulers() {
if (show_grid || grid_snap_active) {
List<CanvasItem *> 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) {

View File

@ -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;
}

View File

@ -412,7 +412,7 @@ void Prop2DInstanceMerger::_prop_preprocess(Transform2D transform, const Ref<Pro
Transform2D tt = t;
//tt.origin += Vector3(hew, heh, 0);
tt.translate(hew, heh);
tt.translate_local(hew, heh);
_job->add_collision_shape(tws, tt, true);
}

View File

@ -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<Vector2> pts;
pts.push_back(xf.xform(Vector2(arrow_size, 0)));

View File

@ -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)));
}