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

Fix double clicking objects no longer focusing the camera on them #2227

Merged
merged 3 commits into from
May 30, 2023
Merged
Changes from 2 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
17 changes: 9 additions & 8 deletions crates/re_viewer/src/ui/view_spatial/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ pub struct View3DState {

eye_interpolation: Option<EyeInterpolation>,

/// Where in world space the mouse is hovering (from previous frame)
hovered_point: Option<glam::Vec3>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, I would had hoped clippy would have caught a field only being read from


// options:
pub spin: bool,
pub show_axes: bool,
Expand All @@ -69,7 +66,6 @@ impl Default for View3DState {
tracked_camera: None,
camera_before_tracked_camera: None,
eye_interpolation: Default::default(),
hovered_point: Default::default(),
spin: false,
show_axes: false,
show_bbox: false,
Expand Down Expand Up @@ -399,8 +395,9 @@ pub fn view_3d(
);
}

// Double click changes camera
// Double click changes camera to focus on an entity.
if response.double_clicked() {
// Clear out tracked camera if there's any.
state.state_3d.tracked_camera = None;
state.state_3d.camera_before_tracked_camera = None;

Expand All @@ -411,13 +408,17 @@ pub fn view_3d(
state.state_3d.orbit_eye.map(|eye| eye.to_eye());
state.state_3d.interpolate_to_eye(camera);
state.state_3d.tracked_camera = Some(instance_path.entity_path.clone());
} else if let Some(clicked_point) = state.state_3d.hovered_point {
} else if let HoveredSpace::ThreeD {
pos: Some(clicked_point),
..
} = ctx.selection_state().hovered_space()
{
if let Some(mut new_orbit_eye) = state.state_3d.orbit_eye {
// TODO(andreas): It would be nice if we could focus on the center of the entity rather than the clicked point.
// We can figure out the transform/translation at the hovered path but that's usually not what we'd expect either
// (especially for entities with many instances, like a point cloud)
new_orbit_eye.orbit_radius = new_orbit_eye.position().distance(clicked_point);
new_orbit_eye.orbit_center = clicked_point;
new_orbit_eye.orbit_radius = new_orbit_eye.position().distance(*clicked_point);
new_orbit_eye.orbit_center = *clicked_point;
state.state_3d.interpolate_to_orbit_eye(new_orbit_eye);
}
}
Expand Down