Skip to content

Commit

Permalink
ease zoom scale and position at the same time
Browse files Browse the repository at this point in the history
calculates zoom bounds and interpolates those instead of interpolating
scale and position separately
  • Loading branch information
Brendonovich committed Jan 13, 2025
1 parent 2f944f2 commit dcd8b95
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 39 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/media/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tempfile = "3.12.0"
thiserror.workspace = true
tracing = { version = "0.1", features = ["release_max_level_info"] }
futures = "0.3.31"
axum = "0.7.9"
axum = { version = "0.7.9", features = ["macros", "ws"] }
tokio.workspace = true

[target.'cfg(target_os = "macos")'.dependencies]
Expand Down
1 change: 1 addition & 0 deletions crates/media/src/frame_ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub async fn create_frame_ws(frame_rx: Receiver<WSFrame>) -> (u16, mpsc::Sender<

type RouterState = Arc<Mutex<Receiver<WSFrame>>>;

#[axum::debug_handler]
async fn ws_handler(
ws: WebSocketUpgrade,
State(state): State<RouterState>,
Expand Down
21 changes: 17 additions & 4 deletions crates/rendering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ impl ProjectUniforms {

let interpolated_zoom = zoom_keyframes.interpolate(time as f64);

let (zoom_amount, zoom_origin) = {
let (zoom_amount, zoom_origin, lowered_zoom) = {
let origin = match interpolated_zoom.position {
ZoomPosition::Manual { x, y } => Coord::<RawDisplayUVSpace>::new(XY {
x: x as f64,
Expand All @@ -691,7 +691,7 @@ impl ProjectUniforms {
}
};

(interpolated_zoom.amount, origin)
(interpolated_zoom.amount, origin, interpolated_zoom.lowered)
};

let (display, zoom) = {
Expand Down Expand Up @@ -721,8 +721,21 @@ impl ProjectUniforms {
// padding: screen_scale_origin,
};

let start = zoom.apply_scale(display_offset);
let end = zoom.apply_scale(end);
let target_size = end - display_offset;

let (zoom_start, zoom_end) = (
Coord::new(XY::new(
lowered_zoom.top_left.0 as f64 * target_size.x,
lowered_zoom.top_left.1 as f64 * target_size.y,
)),
Coord::new(XY::new(
(lowered_zoom.bottom_right.0 as f64 - 1.0) * target_size.x,
(lowered_zoom.bottom_right.1 as f64 - 1.0) * target_size.y,
)),
);

let start = display_offset + zoom_start;
let end = end + zoom_end;

let target_size = end - start;
let min_target_axis = target_size.x.min(target_size.y);
Expand Down
Loading

0 comments on commit dcd8b95

Please sign in to comment.