Repository: godotengine/godot
File: editor/plugins/node_3d_editor_plugin.cpp (C++)

Code before:

					// Display the zoom center distance to help the user get a better sense of scale.
					const int precision = cursor.distance < 1.0 ? 2 : 1;
					draw_indicator_bar(
							*surface,
							logscale_t,
							get_editor_theme_icon(SNAME("ViewportZoom")),
							get_theme_font(SceneStringName(font), SNAME("Label")),
							get_theme_font_size(SceneStringName(font_size), SNAME("Label")),
							vformat("%s m", String::num(cursor.distance).pad_decimals(precision)),
							Color(0.7, 0.95, 1.0));
				}
			}
		}
	}
}

bool Node3DEditorViewport::_camera_moved_externally() {
	Transform3D t = camera->get_global_transform();
	return !t.is_equal_approx(last_camera_transform);
}

void Node3DEditorViewport::_apply_camera_transform_to_cursor() {
	// Effectively the reverse of to_camera_transform, use camera transform to set cursor position and rotation.
	Transform3D camera_transform = camera->get_camera_transform();
	Basis basis = camera_transform.basis;

	real_t distance;
	if (orthogonal) {
		distance = (get_zfar() - get_znear()) / 2.0;
	} else {
		distance = cursor.distance;
	}

	cursor.pos = camera_transform.origin - basis.get_column(2) * distance;

	cursor.x_rot = -camera_transform.basis.get_euler().x;
	cursor.y_rot = -camera_transform.basis.get_euler().y;
}

void Node3DEditorViewport::_menu_option(int p_option) {
	EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
	switch (p_option) {
		case VIEW_TOP: {
			cursor.y_rot = 0;
			cursor.x_rot = Math::PI / 2.0;
			set_message(TTR("Top View."), 2);
			view_type = VIEW_TYPE_TOP;
			_set_auto_orthogonal();
			_update_name();


Review comment (suggestion):
These two variables could be made `const` to make it clear that their data is only read from and not used for an intermediate calculation.

Code after:

					// Display the zoom center distance to help the user get a better sense of scale.
					const int precision = cursor.distance < 1.0 ? 2 : 1;
					draw_indicator_bar(
							*surface,
							logscale_t,
							get_editor_theme_icon(SNAME("ViewportZoom")),
							get_theme_font(SceneStringName(font), SNAME("Label")),
							get_theme_font_size(SceneStringName(font_size), SNAME("Label")),
							vformat("%s m", String::num(cursor.distance).pad_decimals(precision)),
							Color(0.7, 0.95, 1.0));
				}
			}
		}
	}
}

bool Node3DEditorViewport::_camera_moved_externally() {
	Transform3D t = camera->get_global_transform();
	return !t.is_equal_approx(last_camera_transform);
}

void Node3DEditorViewport::_apply_camera_transform_to_cursor() {
	// Effectively the reverse of to_camera_transform, use camera transform to set cursor position and rotation.
	const Transform3D camera_transform = camera->get_camera_transform();
	const Basis basis = camera_transform.basis;

	real_t distance;
	if (orthogonal) {
		distance = (get_zfar() - get_znear()) / 2.0;
	} else {
		distance = cursor.distance;
	}

	cursor.pos = camera_transform.origin - basis.get_column(2) * distance;

	cursor.x_rot = -camera_transform.basis.get_euler().x;
	cursor.y_rot = -camera_transform.basis.get_euler().y;
}

void Node3DEditorViewport::_menu_option(int p_option) {
	EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
	switch (p_option) {
		case VIEW_TOP: {
			cursor.y_rot = 0;
			cursor.x_rot = Math::PI / 2.0;
			set_message(TTR("Top View."), 2);
			view_type = VIEW_TYPE_TOP;
			_set_auto_orthogonal();
			_update_name();