diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index b803d2e5d828..af928aa57f48 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -344,7 +344,7 @@ void ViewportRotationControl::_draw() { void ViewportRotationControl::_draw_axis(const Axis2D &p_axis) { const bool focused = focused_axis == p_axis.axis; - const bool positive = p_axis.axis < 3; + const bool positive = axis_is_aligned && p_axis.axis == aligned_axis ? !(p_axis.axis < 3) : (p_axis.axis < 3); const int direction = p_axis.axis % 3; const Color axis_color = axis_colors[direction]; @@ -381,11 +381,13 @@ void ViewportRotationControl::_get_sorted_axis(Vector &r_axis) { const real_t radius = get_size().x / 2.0 - AXIS_CIRCLE_RADIUS - 2.0 * EDSCALE; const Basis camera_basis = viewport->to_camera_transform(viewport->cursor).get_basis().inverse(); + axis_is_aligned = false; + for (int i = 0; i < 3; ++i) { Vector3 axis_3d = camera_basis.get_column(i); Vector2 axis_vector = Vector2(axis_3d.x, -axis_3d.y) * radius; - if (Math::abs(axis_3d.z) <= 1.0) { + if (Math::abs(axis_3d.z) < 1.0) { Axis2D pos_axis; pos_axis.axis = i; pos_axis.screen_point = center + axis_vector; @@ -404,6 +406,8 @@ void ViewportRotationControl::_get_sorted_axis(Vector &r_axis) { axis.screen_point = center; axis.z_axis = 1.0; r_axis.push_back(axis); + axis_is_aligned = true; + aligned_axis = axis.axis; } } diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index 6b603864c2c6..effdaf00ee3f 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -99,6 +99,9 @@ class ViewportRotationControl : public Control { void _process_click(int p_index, Vector2 p_position, bool p_pressed); void _process_drag(Ref p_event, int p_index, Vector2 p_position, Vector2 p_relative_position); + int aligned_axis = 0; + bool axis_is_aligned = false; + public: void set_viewport(Node3DEditorViewport *p_viewport); };