Skip to content

Commit

Permalink
Fix always redrawing in the presence of a 3D space view (#2900)
Browse files Browse the repository at this point in the history
* Fixes #2897

### What

Fix regression introduced in #2839
This landed in 0.8. Candidate for potential 0.8.1 release if we decide
to do one.

### 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)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/2900) (if
applicable)

- [PR Build Summary](https://build.rerun.io/pr/2900)
- [Docs
preview](https://rerun.io/preview/pr%3Aandreas%2Ffix-redraw/docs)
- [Examples
preview](https://rerun.io/preview/pr%3Aandreas%2Ffix-redraw/examples)
  • Loading branch information
Wumpf authored Aug 3, 2023
1 parent 8d5d6b7 commit f453f37
Showing 1 changed file with 44 additions and 23 deletions.
67 changes: 44 additions & 23 deletions crates/re_space_view_spatial/src/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ impl View3DState {

if let Some(target_orbit) = &cam_interpolation.target_orbit {
*orbit_camera = cam_interpolation.start.lerp(target_orbit, t);
} else if let Some(target_camera) = &cam_interpolation.target_eye {
let camera = cam_interpolation.start.to_eye().lerp(target_camera, t);
} else if let Some(target_eye) = &cam_interpolation.target_eye {
let camera = cam_interpolation.start.to_eye().lerp(target_eye, t);
orbit_camera.copy_from_eye(&camera);
} else {
self.eye_interpolation = None;
Expand All @@ -163,32 +163,44 @@ impl View3DState {
}

fn interpolate_to_eye(&mut self, target: Eye) {
if let Some(start) = self.orbit_eye {
let target_time = EyeInterpolation::target_time(&start.to_eye(), &target);
self.spin = false; // the user wants to move the camera somewhere, so stop spinning
self.eye_interpolation = Some(EyeInterpolation {
elapsed_time: 0.0,
target_time,
start,
target_orbit: None,
target_eye: Some(target),
});
if let Some(start) = self.orbit_eye.as_mut() {
// the user wants to move the camera somewhere, so stop spinning
self.spin = false;

if let Some(target_time) = EyeInterpolation::target_time(&start.to_eye(), &target) {
self.eye_interpolation = Some(EyeInterpolation {
elapsed_time: 0.0,
target_time,
start: *start,
target_orbit: None,
target_eye: Some(target),
});
} else {
start.copy_from_eye(&target);
}
} else {
// shouldn't really happen (`self.orbit_eye` is only `None` for the first frame).
}
}

fn interpolate_to_orbit_eye(&mut self, target: OrbitEye) {
if let Some(start) = self.orbit_eye {
let target_time = EyeInterpolation::target_time(&start.to_eye(), &target.to_eye());
self.spin = false; // the user wants to move the camera somewhere, so stop spinning
self.eye_interpolation = Some(EyeInterpolation {
elapsed_time: 0.0,
target_time,
start,
target_orbit: Some(target),
target_eye: None,
});
// the user wants to move the camera somewhere, so stop spinning
self.spin = false;

if let Some(target_time) =
EyeInterpolation::target_time(&start.to_eye(), &target.to_eye())
{
self.eye_interpolation = Some(EyeInterpolation {
elapsed_time: 0.0,
target_time,
start,
target_orbit: Some(target),
target_eye: None,
});
} else {
self.orbit_eye = Some(target);
}
} else {
self.orbit_eye = Some(target);
}
Expand All @@ -205,14 +217,23 @@ struct EyeInterpolation {
}

impl EyeInterpolation {
pub fn target_time(start: &Eye, stop: &Eye) -> f32 {
pub fn target_time(start: &Eye, stop: &Eye) -> Option<f32> {
// Take more time if the rotation is big:
let angle_difference = start
.world_from_rub_view
.rotation()
.angle_between(stop.world_from_rub_view.rotation());

egui::remap_clamp(angle_difference, 0.0..=std::f32::consts::PI, 0.2..=0.7)
// Threshold to avoid doing pointless interpolations that trigger frame requests.
if angle_difference < 0.01 && start.pos_in_world().distance(stop.pos_in_world()) < 0.0001 {
None
} else {
Some(egui::remap_clamp(
angle_difference,
0.0..=std::f32::consts::PI,
0.2..=0.7,
))
}
}
}

Expand Down

0 comments on commit f453f37

Please sign in to comment.