Skip to content

Commit 30e5767

Browse files
committed
Fix incorrect transform when editor camera is moved externally
1 parent aeb526c commit 30e5767

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

editor/plugins/node_3d_editor_plugin.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,10 +3061,11 @@ void Node3DEditorViewport::_notification(int p_what) {
30613061
if (_camera_moved_externally()) {
30623062
// If camera moved after this plugin last set it, presumably a tool script has moved it, accept the new camera transform as the cursor position.
30633063
_apply_camera_transform_to_cursor();
3064+
_update_camera(0);
3065+
} else {
3066+
_update_camera(delta);
30643067
}
30653068

3066-
_update_camera(delta);
3067-
30683069
const HashMap<Node *, Object *> &selection = editor_selection->get_selection();
30693070

30703071
bool changed = false;
@@ -3591,7 +3592,17 @@ bool Node3DEditorViewport::_camera_moved_externally() {
35913592
void Node3DEditorViewport::_apply_camera_transform_to_cursor() {
35923593
// Effectively the reverse of to_camera_transform, use camera transform to set cursor position and rotation.
35933594
Transform3D camera_transform = camera->get_camera_transform();
3594-
cursor.pos = camera_transform.origin;
3595+
Basis basis = camera_transform.basis;
3596+
3597+
real_t distance;
3598+
if (orthogonal) {
3599+
distance = (get_zfar() - get_znear()) / 2.0;
3600+
} else {
3601+
distance = cursor.distance;
3602+
}
3603+
3604+
cursor.pos = camera_transform.origin - basis.get_column(2) * d;
3605+
35953606
cursor.x_rot = -camera_transform.basis.get_euler().x;
35963607
cursor.y_rot = -camera_transform.basis.get_euler().y;
35973608
}

0 commit comments

Comments
 (0)