summaryrefslogtreecommitdiffstats
path: root/editor/plugins/gizmos
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-08-17 00:45:34 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-08-17 00:45:34 +0200
commit195a174864dffa3e8a60f18d017acbb24788f97d (patch)
tree4e32c5213424bc9cdf0ef5d1f00d555bf7382ac9 /editor/plugins/gizmos
parent5b6d9a7dd815a3dbd005626710ceb22e4e42ea3e (diff)
parentb97d995664faa5f1b6ebd52bc9b33199f4598889 (diff)
downloadredot-engine-195a174864dffa3e8a60f18d017acbb24788f97d.tar.gz
Merge pull request #90690 from jsjtxietian/camera-aspect
Adjust orthographic camera gizmo with respect to `keep_aspect` setting
Diffstat (limited to 'editor/plugins/gizmos')
-rw-r--r--editor/plugins/gizmos/camera_3d_gizmo_plugin.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/editor/plugins/gizmos/camera_3d_gizmo_plugin.cpp b/editor/plugins/gizmos/camera_3d_gizmo_plugin.cpp
index 19dd45a3ea..21ad8f021c 100644
--- a/editor/plugins/gizmos/camera_3d_gizmo_plugin.cpp
+++ b/editor/plugins/gizmos/camera_3d_gizmo_plugin.cpp
@@ -112,9 +112,12 @@ void Camera3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id,
float a = _find_closest_angle_to_half_pi_arc(s[0], s[1], 1.0, gt2);
camera->set("fov", CLAMP(a * 2.0, 1, 179));
} else {
+ Camera3D::KeepAspect aspect = camera->get_keep_aspect_mode();
+ Vector3 far = aspect == Camera3D::KeepAspect::KEEP_WIDTH ? Vector3(4096, 0, -1) : Vector3(0, 4096, -1);
+
Vector3 ra, rb;
- Geometry3D::get_closest_points_between_segments(Vector3(0, 0, -1), Vector3(4096, 0, -1), s[0], s[1], ra, rb);
- float d = ra.x * 2;
+ Geometry3D::get_closest_points_between_segments(Vector3(0, 0, -1), far, s[0], s[1], ra, rb);
+ float d = aspect == Camera3D::KeepAspect::KEEP_WIDTH ? ra.x * 2 : ra.y * 2;
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap());
}
@@ -213,25 +216,33 @@ void Camera3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
} break;
case Camera3D::PROJECTION_ORTHOGONAL: {
+ Camera3D::KeepAspect aspect = camera->get_keep_aspect_mode();
+
float size = camera->get_size();
+ float keep_size = size * 0.5;
- float hsize = size * 0.5;
- Vector3 right(hsize * size_factor.x, 0, 0);
- Vector3 up(0, hsize * size_factor.y, 0);
+ Vector3 right, up;
Vector3 back(0, 0, -1.0);
Vector3 front(0, 0, 0);
+ if (aspect == Camera3D::KeepAspect::KEEP_WIDTH) {
+ right = Vector3(keep_size, 0, 0);
+ up = Vector3(0, keep_size / viewport_aspect, 0);
+ handles.push_back(right + back);
+ } else {
+ right = Vector3(keep_size * viewport_aspect, 0, 0);
+ up = Vector3(0, keep_size, 0);
+ handles.push_back(up + back);
+ }
+
ADD_QUAD(-up - right, -up + right, up + right, up - right);
ADD_QUAD(-up - right + back, -up + right + back, up + right + back, up - right + back);
ADD_QUAD(up + right, up + right + back, up - right + back, up - right);
ADD_QUAD(-up + right, -up + right + back, -up - right + back, -up - right);
- handles.push_back(right + back);
-
- right.x = MIN(right.x, hsize * 0.25);
- Vector3 tup(0, up.y + hsize / 2, back.z);
+ right.x = MIN(right.x, keep_size * 0.25);
+ Vector3 tup(0, up.y + keep_size / 2, back.z);
ADD_TRIANGLE(tup, right + up + back, -right + up + back);
-
} break;
case Camera3D::PROJECTION_FRUSTUM: {