From 29409c54ce3279f884018b343f26c8cf6b81b35b Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 9 Nov 2025 11:41:11 -0500 Subject: [PATCH] Camera for the storyboard can now do pan, bounce, dolly, and shake. --- assets/cameras.json | 14 +++++++------- camera.cpp | 17 ++++++++++++----- camera.hpp | 3 ++- main.cpp | 2 +- storyboard/ui.cpp | 2 +- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/assets/cameras.json b/assets/cameras.json index 466c5ef..4e971ed 100644 --- a/assets/cameras.json +++ b/assets/cameras.json @@ -39,7 +39,7 @@ "_type": "Animation", "easing": 1, "motion": 0, - "ease_rate": 0.5, + "ease_rate": 1.0, "min_x": 0.8, "min_y": 0.8, "max_x": 1.0, @@ -55,13 +55,13 @@ }, "bounce": { "_type": "Animation", - "easing": 3, + "easing": 4, "motion": 2, - "ease_rate": 0.05, - "min_x": -10, - "min_y": -10, - "max_x": 10, - "max_y": 10, + "ease_rate": 0.001, + "min_x": 0, + "min_y": -20, + "max_x": 0, + "max_y": 0, "simple": true, "frames": 1, "speed": 0.01, diff --git a/camera.cpp b/camera.cpp index dae878e..0d0803d 100644 --- a/camera.cpp +++ b/camera.cpp @@ -40,15 +40,22 @@ namespace cinematic { anim = MGR.animations.at(name); } - void Camera::position(float x, float y) { - anim.min_x = x; - anim.min_y = y; + void Camera::focus(float x, float y) { + position.x = x; + position.y = y; } void Camera::move(sf::RenderTexture& target, sf::Vector2f pos) { sf::View zoom; - anim.max_x = pos.x; - anim.max_y = pos.y; + + // BUG: annoying special case + if(anim.motion == ease::SLIDE) { + anim.min_x = position.x; + anim.min_y = position.y; + anim.max_x = pos.x; + anim.max_y = pos.y; + } + anim.apply(zoom, pos, size); target.setView(zoom); } diff --git a/camera.hpp b/camera.hpp index 9db2c46..45cfc17 100644 --- a/camera.hpp +++ b/camera.hpp @@ -7,6 +7,7 @@ namespace cinematic { components::Animation anim; sf::View view; sf::Vector2f size; + sf::Vector2f position; Camera(); @@ -14,7 +15,7 @@ namespace cinematic { void move(sf::RenderTexture& target, sf::Vector2f pos); bool playing(); void play(); - void position(float x, float y); + void focus(float x, float y); void style(const std::string &name); }; diff --git a/main.cpp b/main.cpp index decf45e..0e66f5d 100644 --- a/main.cpp +++ b/main.cpp @@ -20,7 +20,7 @@ int main(int argc, char* argv[]) { cinematic::init(); GameDB::init(); - if(DEBUG_BUILD) sound::mute(true); + sound::mute(true); gui::FSM main; main.event(gui::Event::STARTED); diff --git a/storyboard/ui.cpp b/storyboard/ui.cpp index 6d4cc48..ad46237 100644 --- a/storyboard/ui.cpp +++ b/storyboard/ui.cpp @@ -39,7 +39,7 @@ namespace storyboard { bool UI::mouse(float x, float y, guecs::Modifiers mods) { auto& cell = $ui.cell_for($zoom_target); - $camera.position(cell.mid_x, cell.mid_y); + $camera.focus(cell.mid_x, cell.mid_y); $zoom_target = *$ui.$parser.hit(x, y);