Skip to content

Commit

Permalink
Fix viewport rotation gizmo aligned axis reversing
Browse files Browse the repository at this point in the history
  • Loading branch information
ryevdokimov committed Jan 7, 2025
1 parent 4cf0231 commit 7a20d8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -381,11 +381,13 @@ void ViewportRotationControl::_get_sorted_axis(Vector<Axis2D> &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;
Expand All @@ -404,6 +406,8 @@ void ViewportRotationControl::_get_sorted_axis(Vector<Axis2D> &r_axis) {
axis.screen_point = center;
axis.z_axis = 1.0;
r_axis.push_back(axis);
axis_is_aligned = true;
aligned_axis = axis.axis;
}
}

Expand Down
3 changes: 3 additions & 0 deletions editor/plugins/node_3d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class ViewportRotationControl : public Control {
void _process_click(int p_index, Vector2 p_position, bool p_pressed);
void _process_drag(Ref<InputEventWithModifiers> 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);
};
Expand Down

0 comments on commit 7a20d8d

Please sign in to comment.