Skip to content
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

Correct rotation gizmo plane math for off-center perspective view #95402

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5001,14 +5001,24 @@ void Node3DEditorViewport::update_transform(bool p_shift) {
} break;

case TRANSFORM_ROTATE: {
Plane plane = Plane(_get_camera_normal(), _edit.center);
Plane plane;
if (camera->get_projection() == Camera3D::PROJECTION_PERSPECTIVE) {
Vector3 cam_to_obj = _edit.center - _get_camera_position();
if (!cam_to_obj.is_zero_approx()) {
plane = Plane(cam_to_obj.normalized(), _edit.center);
} else {
plane = Plane(_get_camera_normal(), _edit.center);
}
} else {
plane = Plane(_get_camera_normal(), _edit.center);
}

Vector3 local_axis;
Vector3 global_axis;
switch (_edit.plane) {
case TRANSFORM_VIEW:
// local_axis unused
global_axis = _get_camera_normal();
global_axis = plane.normal;
break;
case TRANSFORM_X_AXIS:
local_axis = Vector3(1, 0, 0);
Expand Down Expand Up @@ -5039,7 +5049,7 @@ void Node3DEditorViewport::update_transform(bool p_shift) {
break;
}

static const float orthogonal_threshold = Math::cos(Math::deg_to_rad(87.0f));
static const float orthogonal_threshold = Math::cos(Math::deg_to_rad(85.0f));
bool axis_is_orthogonal = ABS(plane.normal.dot(global_axis)) < orthogonal_threshold;

double angle = 0.0f;
Expand Down
Loading