From e245efaead2a23f717079350637a13d4e74ca8a4 Mon Sep 17 00:00:00 2001 From: JFonS Date: Wed, 27 Jun 2018 16:59:45 +0200 Subject: [PATCH] Fix selection in 3D orthogonal view --- editor/plugins/spatial_editor_plugin.cpp | 26 ++++++++++++++++-------- editor/spatial_editor_gizmos.cpp | 9 ++++---- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 30fff474d73..37b8562e964 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -471,7 +471,11 @@ void SpatialEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_incl Vector3 SpatialEditorViewport::_get_screen_to_space(const Vector3 &p_vector3) { CameraMatrix cm; - cm.set_perspective(get_fov(), get_size().aspect(), get_znear() + p_vector3.z, get_zfar()); + if (orthogonal) { + cm.set_orthogonal(camera->get_size(), get_size().aspect(), get_znear() + p_vector3.z, get_zfar()); + } else { + cm.set_perspective(get_fov(), get_size().aspect(), get_znear() + p_vector3.z, get_zfar()); + } float screen_w, screen_h; cm.get_viewport_size(screen_w, screen_h); @@ -518,18 +522,24 @@ void SpatialEditorViewport::_select_region() { Vector3 a = _get_screen_to_space(box[i]); Vector3 b = _get_screen_to_space(box[(i + 1) % 4]); - frustum.push_back(Plane(a, b, cam_pos)); + if (orthogonal) { + frustum.push_back(Plane(a, (a - b).normalized())); + } else { + frustum.push_back(Plane(a, b, cam_pos)); + } } - Plane near(cam_pos, -_get_camera_normal()); - near.d -= get_znear(); + if (!orthogonal) { + Plane near(cam_pos, -_get_camera_normal()); + near.d -= get_znear(); - frustum.push_back(near); + frustum.push_back(near); - Plane far = -near; - far.d += get_zfar(); + Plane far = -near; + far.d += get_zfar(); - frustum.push_back(far); + frustum.push_back(far); + } Vector instances = VisualServer::get_singleton()->instances_cull_convex(frustum, get_tree()->get_root()->get_world()->get_scenario()); Vector selected; diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 873420b3834..17f3b4886e7 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -202,7 +202,7 @@ void EditorSpatialGizmo::add_unscaled_billboard(const Ref &p_material, } selectable_icon_size = p_scale; - mesh->set_custom_aabb(AABB(Vector3(-selectable_icon_size, -selectable_icon_size, -selectable_icon_size) * 40.0f, Vector3(selectable_icon_size, selectable_icon_size, selectable_icon_size) * 80.0f)); + mesh->set_custom_aabb(AABB(Vector3(-selectable_icon_size, -selectable_icon_size, -selectable_icon_size) * 100.0f, Vector3(selectable_icon_size, selectable_icon_size, selectable_icon_size) * 200.0f)); ins.mesh = mesh; ins.unscaled = true; @@ -212,7 +212,7 @@ void EditorSpatialGizmo::add_unscaled_billboard(const Ref &p_material, VS::get_singleton()->instance_set_transform(ins.instance, spatial_node->get_global_transform()); } - selectable_icon_size = p_scale * 2.0; + selectable_icon_size = p_scale; instances.push_back(ins); } @@ -475,8 +475,9 @@ bool EditorSpatialGizmo::intersect_ray(Camera *p_camera, const Point2 &p_point, float scale = t.origin.distance_to(p_camera->get_camera_transform().origin); if (p_camera->get_projection() == Camera::PROJECTION_ORTHOGONAL) { - float h = Math::abs(p_camera->get_size()); - scale = (h * 2.0); + float aspect = p_camera->get_viewport()->get_visible_rect().size.aspect(); + float size = p_camera->get_size(); + scale = size / aspect; } Point2 center = p_camera->unproject_position(t.origin);