From: Joshua Simmons Date: Mon, 27 Oct 2025 22:40:10 +0000 (+0100) Subject: shark: Improve camera controls X-Git-Url: https://git.nega.tv//gitweb.cgi?a=commitdiff_plain;ds=sidebyside;p=josh%2Fnarcissus shark: Improve camera controls --- diff --git a/title/shark/src/game.rs b/title/shark/src/game.rs index d1a9a09..90aa050 100644 --- a/title/shark/src/game.rs +++ b/title/shark/src/game.rs @@ -56,6 +56,7 @@ pub enum Action { CameraRight, CameraUp, CameraDown, + CameraZoom, Damage, } @@ -81,6 +82,10 @@ impl Default for Actions { impl Actions { const MAX_ACTIONS: usize = 256; + fn value(&self, action: Action) -> f32 { + self.new_values[action as usize] + } + fn is_active(&self, action: Action) -> bool { self.new_values[action as usize] != 0.0 } @@ -92,6 +97,9 @@ impl Actions { pub fn tick(&mut self, action_queue: &[ActionEvent]) { self.old_values = self.new_values; + // TODO: Handle this properly... + self.new_values[Action::CameraZoom as usize] = 0.0; + for event in action_queue { self.new_values[event.action as usize] = event.value; } @@ -156,6 +164,9 @@ impl CameraState { } pub fn tick(&mut self, actions: &Actions, target: Point3, time: f32, delta_time: f32) { + self.distance += actions.value(Action::CameraZoom); + self.distance = self.distance.clamp(1.0, 100.0); + let movement_bitmap = actions.is_active(Action::CameraUp) as usize | (actions.is_active(Action::CameraDown) as usize) << 1 | (actions.is_active(Action::CameraLeft) as usize) << 2 @@ -165,11 +176,10 @@ impl CameraState { const DOWN: Vec2 = vec2(0.0, -1.0); const LEFT: Vec2 = vec2(-1.0, 0.0); const RIGHT: Vec2 = vec2(1.0, 0.0); - //SQRT_2 / 2.0 - const UP_LEFT: Vec2 = vec2(1.0, 0.0); - const UP_RIGHT: Vec2 = vec2(0.0, 1.0); - const DOWN_LEFT: Vec2 = vec2(0.0, -1.0); - const DOWN_RIGHT: Vec2 = vec2(-1.0, 0.0); + const UP_LEFT: Vec2 = vec2(-SQRT_2 / 2.0, SQRT_2 / 2.0); + const UP_RIGHT: Vec2 = vec2(SQRT_2 / 2.0, SQRT_2 / 2.0); + const DOWN_LEFT: Vec2 = vec2(-SQRT_2 / 2.0, -SQRT_2 / 2.0); + const DOWN_RIGHT: Vec2 = vec2(SQRT_2 / 2.0, -SQRT_2 / 2.0); let movement = [ // 0 0 0 0 diff --git a/title/shark/src/main.rs b/title/shark/src/main.rs index 4d340fd..58e0ff3 100644 --- a/title/shark/src/main.rs +++ b/title/shark/src/main.rs @@ -177,6 +177,18 @@ pub fn main() { action_queue.push(ActionEvent { action, value }) } } + MouseWheel { + window_id: _, + x: _, + y, + } => { + if y != 0.0 { + action_queue.push(ActionEvent { + action: Action::CameraZoom, + value: y, + }); + } + } ScaleChanged { window_id: _ } => { window_display_scale = window.display_scale() }