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

* [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 and emilk committed Jun 15, 2023
1 parent 7772b25 commit 44db91e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions crates/re_viewer/src/ui/view_spatial/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ pub struct View3DState {
#[serde(skip)]
eye_interpolation: Option<EyeInterpolation>,

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

// options:
pub spin: bool,
pub show_axes: bool,
Expand All @@ -75,7 +71,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 @@ -405,8 +400,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 @@ -417,13 +413,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 44db91e

Please sign in to comment.