Skip to content

Commit

Permalink
Move scene_up out of OrbitEye
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Feb 14, 2024
1 parent 6fc15df commit a5c3b5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
18 changes: 4 additions & 14 deletions crates/re_space_view_spatial/src/eye.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ pub struct OrbitEye {
pub world_from_view_rot: Quat,
pub fov_y: f32,

/// The up-axis of the scene we're looking at, if defined by its [`ViewCoordinates`].
///
/// This is used to track changes to the scene's view coordinates reactively.
pub scene_up: Option<Vec3>,

/// The up-axis of the eye itself, in world-space.
///
/// Initially, the up-axis of the eye will be the same as the up-axis of the scene (or +Z if
Expand All @@ -187,7 +182,6 @@ impl OrbitEye {
orbit_center: Vec3,
orbit_radius: f32,
world_from_view_rot: Quat,
scene_up: Option<Vec3>,
eye_up: Vec3,
) -> Self {
OrbitEye {
Expand All @@ -196,7 +190,6 @@ impl OrbitEye {
world_from_view_rot,
fov_y: Eye::DEFAULT_FOV_Y,
eye_up,
scene_up,
velocity: Vec3::ZERO,
}
}
Expand Down Expand Up @@ -227,6 +220,7 @@ impl OrbitEye {
self.world_from_view_rot = eye.world_from_rub_view.rotation();
self.fov_y = eye.fov_y.unwrap_or(Eye::DEFAULT_FOV_Y);
self.velocity = Vec3::ZERO;
self.eye_up = eye.world_from_rub_view.rotation() * glam::Vec3::Y;
}

pub fn lerp(&self, other: &Self, t: f32) -> Self {
Expand All @@ -240,14 +234,10 @@ impl OrbitEye {
orbit_radius: lerp(self.orbit_radius..=other.orbit_radius, t),
world_from_view_rot: self.world_from_view_rot.slerp(other.world_from_view_rot, t),
fov_y: egui::lerp(self.fov_y..=other.fov_y, t),
// A slerp would technically be nicer for eye_up, but it only really
// matters if the user starts interacting half-way through the lerp,
// and even then it's not a big deal.
eye_up: self.eye_up.lerp(other.eye_up, t).normalize_or_zero(),
scene_up: other.scene_up, // TODO: crazy interp bug
// scene_up: other.scene_up.map(|scene_up| {
// self.scene_up
// .unwrap_or(glam::Vec3::Z)
// .lerp(scene_up, t)
// .normalize_or_zero()
// }),
velocity: self.velocity.lerp(other.velocity, t),
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/re_space_view_spatial/src/ui_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ pub struct View3DState {

eye_interpolation: Option<EyeInterpolation>,

/// Last known view coordinates.
/// Used to detect changes in view coordinates, in which case we reset the camera eye.
scene_view_coordinates: Option<ViewCoordinates>,

// options:
spin: bool,
pub show_axes: bool,
Expand All @@ -70,6 +74,7 @@ impl Default for View3DState {
tracked_entity: None,
camera_before_tracked_entity: None,
eye_interpolation: Default::default(),
scene_view_coordinates: None,
spin: false,
show_axes: false,
show_bbox: false,
Expand Down Expand Up @@ -113,15 +118,13 @@ impl View3DState {
}

// Detect live changes to view coordinates, and interpolate to the new up axis as needed.
let scene_up = scene_view_coordinates
.and_then(|vc| vc.up())
.map(Into::into);
if self.orbit_eye.and_then(|oe| oe.scene_up) != scene_up {
if scene_view_coordinates != self.scene_view_coordinates {
self.interpolate_to_orbit_eye(default_eye(
&bounding_boxes.accumulated,
scene_view_coordinates,
));
}
self.scene_view_coordinates = scene_view_coordinates;

// Follow tracked object.
if let Some(tracked_entity) = self.tracked_entity.clone() {
Expand Down Expand Up @@ -904,9 +907,6 @@ fn default_eye(
center,
radius,
Quat::from_affine3(&Affine3A::look_at_rh(eye_pos, center, eye_up).inverse()),
scene_view_coordinates
.and_then(|vc| vc.up())
.map(Into::into),
eye_up,
)
}

0 comments on commit a5c3b5c

Please sign in to comment.