Skip to content

Commit

Permalink
Fix double clicking objects no longer focusing the camera on them (#2227
Browse files Browse the repository at this point in the history
)

_Requires #2188_ ✔️ 

Fixes #2215 
* #2215 

### What

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)

<!-- This line will get updated when the PR build summary job finishes.
-->
PR Build Summary: https://build.rerun.io/pr/2227
  • Loading branch information
Wumpf authored May 30, 2023
1 parent b263b9f commit 77b1d34
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions crates/re_viewport/src/view_spatial/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ pub struct View3DState {

eye_interpolation: Option<EyeInterpolation>,

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

// options:
pub spin: bool,
pub show_axes: bool,
Expand All @@ -65,7 +62,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 @@ -396,8 +392,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 @@ -408,13 +405,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

0 comments on commit 77b1d34

Please sign in to comment.