From db243aed4e34d93c40ccde333377e24fbcdd1137 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Wed, 22 Feb 2023 12:35:28 +0000 Subject: [PATCH] Add a keyboard key to rotate the scene --- examples/with_winit/src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/with_winit/src/main.rs b/examples/with_winit/src/main.rs index 9f5bae6..5d42e78 100644 --- a/examples/with_winit/src/main.rs +++ b/examples/with_winit/src/main.rs @@ -87,6 +87,16 @@ async fn run(event_loop: EventLoop, window: Window, args: Args, mut s match input.virtual_keycode { Some(VirtualKeyCode::Left) => scene_ix = scene_ix.saturating_sub(1), Some(VirtualKeyCode::Right) => scene_ix = scene_ix.saturating_add(1), + Some(key @ VirtualKeyCode::Q) | Some(key @ VirtualKeyCode::E) => { + if let Some(prior_position) = prior_position { + let is_clockwise = key == VirtualKeyCode::E; + let angle = if is_clockwise { -0.05 } else { 0.05 }; + transform = Affine::translate(prior_position) + * Affine::rotate(angle) + * Affine::translate(-prior_position) + * transform; + } + } Some(VirtualKeyCode::Escape) => { *control_flow = ControlFlow::Exit; }