Camera is now using animate2 but isn't actually using it yet. Just converted.
This commit is contained in:
parent
7bf7b25a10
commit
46cc21ec7b
8 changed files with 111 additions and 90 deletions
|
|
@ -206,6 +206,10 @@ namespace animate2 {
|
||||||
transform.motion_func = ease2::get_motion(transform.motion);
|
transform.motion_func = ease2::get_motion(transform.motion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Animate2::apply(sf::View& view_out, sf::Vector2f pos, sf::Vector2f size) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Animate2 load(const std::string &file, const std::string &anim_name) {
|
Animate2 load(const std::string &file, const std::string &anim_name) {
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
std::ifstream infile(file);
|
std::ifstream infile(file);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <SFML/Graphics/Rect.hpp>
|
#include <SFML/Graphics/Rect.hpp>
|
||||||
#include <SFML/Graphics/Sprite.hpp>
|
#include <SFML/Graphics/Sprite.hpp>
|
||||||
#include <SFML/Graphics/Shader.hpp>
|
#include <SFML/Graphics/Shader.hpp>
|
||||||
|
#include <SFML/Graphics/View.hpp>
|
||||||
#include <SFML/System/Clock.hpp>
|
#include <SFML/System/Clock.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
@ -117,6 +118,7 @@ namespace animate2 {
|
||||||
bool has_form(const std::string& as_form);
|
bool has_form(const std::string& as_form);
|
||||||
void set_form(const std::string& form);
|
void set_form(const std::string& form);
|
||||||
void apply(sf::Sprite& sprite);
|
void apply(sf::Sprite& sprite);
|
||||||
|
void apply(sf::View& view_out, sf::Vector2f pos, sf::Vector2f size);
|
||||||
void apply_effect(std::shared_ptr<sf::Shader> effect);
|
void apply_effect(std::shared_ptr<sf::Shader> effect);
|
||||||
void update();
|
void update();
|
||||||
void motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale);
|
void motion(sf::Sprite& sprite, sf::Vector2f pos, sf::Vector2f scale);
|
||||||
|
|
|
||||||
|
|
@ -1,74 +1,84 @@
|
||||||
{
|
{
|
||||||
|
"cameras": {
|
||||||
|
"sheet": {
|
||||||
|
"frames": 1,
|
||||||
|
"frame_width": 1024,
|
||||||
|
"frame_height": 768
|
||||||
|
},
|
||||||
|
"sequences": {
|
||||||
|
"idle": {"frames": [0], "durations": [800] },
|
||||||
|
"pan": {"frames": [0], "durations": [800] },
|
||||||
|
"shake": {"frames": [0], "durations": [800] },
|
||||||
|
"dolly": {"frames": [0], "durations": [800] },
|
||||||
|
"bounce": {"frames": [0], "durations": [800] }
|
||||||
|
},
|
||||||
|
"transforms": {
|
||||||
"pan": {
|
"pan": {
|
||||||
"_type": "Animation",
|
|
||||||
"easing": 7,
|
|
||||||
"motion": 7,
|
|
||||||
"ease_rate": 0.001,
|
|
||||||
"min_x": 0.0,
|
"min_x": 0.0,
|
||||||
"min_y": 0.0,
|
"min_y": 0.0,
|
||||||
"max_x": 0.0,
|
"max_x": 0.0,
|
||||||
"max_y": 0.0,
|
"max_y": 0.0,
|
||||||
"simple": true,
|
|
||||||
"frames": 1,
|
|
||||||
"speed": 0.01,
|
|
||||||
"scaled": false,
|
|
||||||
"stationary": true,
|
|
||||||
"toggled": false,
|
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"looped": false
|
"ease_rate": 5.0,
|
||||||
|
"scaled": false,
|
||||||
|
"toggled": false,
|
||||||
|
"looped": false,
|
||||||
|
"easing": "linear",
|
||||||
|
"motion": "move_slide"
|
||||||
},
|
},
|
||||||
"shake": {
|
"shake": {
|
||||||
"_type": "Animation",
|
|
||||||
"easing": 6,
|
|
||||||
"motion": 1,
|
|
||||||
"ease_rate": 0.05,
|
|
||||||
"min_x": -10.0,
|
"min_x": -10.0,
|
||||||
"min_y": -10.0,
|
"min_y": -10.0,
|
||||||
"max_x": 10.0,
|
"max_x": 10.0,
|
||||||
"max_y": 10.0,
|
"max_y": 10.0,
|
||||||
"simple": true,
|
|
||||||
"frames": 1,
|
|
||||||
"speed": 0.01,
|
|
||||||
"scaled": false,
|
|
||||||
"stationary": true,
|
|
||||||
"toggled": false,
|
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"looped": false
|
"ease_rate": 5.0,
|
||||||
|
"scaled": false,
|
||||||
|
"toggled": false,
|
||||||
|
"looped": false,
|
||||||
|
"easing": "normal_dist",
|
||||||
|
"motion": "move_shake"
|
||||||
},
|
},
|
||||||
"dolly": {
|
"dolly": {
|
||||||
"_type": "Animation",
|
|
||||||
"easing": 1,
|
|
||||||
"motion": 0,
|
|
||||||
"ease_rate": 1.0,
|
|
||||||
"min_x": 0.8,
|
"min_x": 0.8,
|
||||||
"min_y": 0.8,
|
"min_y": 0.8,
|
||||||
"max_x": 1.0,
|
"max_x": 1.0,
|
||||||
"max_y": 1.0,
|
"max_y": 1.0,
|
||||||
"simple": true,
|
|
||||||
"frames": 1,
|
|
||||||
"speed": 0.1,
|
|
||||||
"scaled": true,
|
|
||||||
"stationary": true,
|
|
||||||
"toggled": false,
|
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"looped": false
|
"ease_rate": 3.0,
|
||||||
|
"scaled": false,
|
||||||
|
"toggled": false,
|
||||||
|
"looped": false,
|
||||||
|
"easing": "sine",
|
||||||
|
"motion": "move_rush"
|
||||||
},
|
},
|
||||||
"bounce": {
|
"bounce": {
|
||||||
"_type": "Animation",
|
|
||||||
"easing": 4,
|
|
||||||
"motion": 2,
|
|
||||||
"ease_rate": 0.001,
|
|
||||||
"min_x": 0,
|
"min_x": 0,
|
||||||
"min_y": -20,
|
"min_y": -20,
|
||||||
"max_x": 0,
|
"max_x": 0,
|
||||||
"max_y": 0,
|
"max_y": 0,
|
||||||
"simple": true,
|
|
||||||
"frames": 1,
|
|
||||||
"speed": 0.01,
|
|
||||||
"scaled": false,
|
|
||||||
"stationary": true,
|
|
||||||
"toggled": false,
|
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"looped": false
|
"ease_rate": 3.0,
|
||||||
|
"scaled": false,
|
||||||
|
"toggled": false,
|
||||||
|
"looped": false,
|
||||||
|
"easing": "in_out_back",
|
||||||
|
"motion": "move_bounce"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"forms": {
|
||||||
|
"idle": ["idle", "idle"],
|
||||||
|
"pan": ["pan", "pan"],
|
||||||
|
"dolly": ["dolly", "dolly"],
|
||||||
|
"shake": ["shake", "shake"],
|
||||||
|
"bounce": ["bounce", "bounce"]
|
||||||
|
},
|
||||||
|
"sounds": {
|
||||||
|
"idle": [],
|
||||||
|
"pan": [],
|
||||||
|
"dolly": [],
|
||||||
|
"shake": [],
|
||||||
|
"bounce": []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
31
camera.cpp
31
camera.cpp
|
|
@ -1,16 +1,16 @@
|
||||||
#include "camera.hpp"
|
#include "camera.hpp"
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
#include "animation.hpp"
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "components.hpp"
|
#include "components.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace cinematic {
|
namespace cinematic {
|
||||||
using components::Animation, std::string, std::min, std::clamp;
|
using animate2::Animate2, std::string, std::min, std::clamp;
|
||||||
|
|
||||||
struct CameraManager {
|
struct CameraManager {
|
||||||
std::unordered_map<string, Animation> animations;
|
std::unordered_map<string, Animate2> animations;
|
||||||
};
|
};
|
||||||
|
|
||||||
static CameraManager MGR;
|
static CameraManager MGR;
|
||||||
|
|
@ -18,18 +18,15 @@ namespace cinematic {
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
if(!initialized) {
|
if(!initialized) {
|
||||||
auto cameras = settings::get("cameras");
|
auto data = settings::get("cameras");
|
||||||
for(auto &[name, data] : cameras.json().items()) {
|
auto anim = components::convert<Animate2>(data["cameras"]);
|
||||||
auto anim = components::convert<Animation>(data);
|
MGR.animations.try_emplace("main", anim);
|
||||||
MGR.animations.try_emplace(name, anim);
|
|
||||||
}
|
|
||||||
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera::Camera(sf::Vector2f size) :
|
Camera::Camera(sf::Vector2f size) :
|
||||||
anim(MGR.animations.at("pan")),
|
anim(MGR.animations.at("main")),
|
||||||
size(size),
|
size(size),
|
||||||
base_size(size),
|
base_size(size),
|
||||||
aimed_at{size.x/2, size.y/2},
|
aimed_at{size.x/2, size.y/2},
|
||||||
|
|
@ -63,7 +60,7 @@ namespace cinematic {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::style(const std::string &name) {
|
void Camera::style(const std::string &name) {
|
||||||
anim = MGR.animations.at(name);
|
anim.set_form(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::position(float x, float y) {
|
void Camera::position(float x, float y) {
|
||||||
|
|
@ -76,12 +73,12 @@ namespace cinematic {
|
||||||
going_to.y = clamp(y, camera_bounds.position.y, camera_bounds.size.y);
|
going_to.y = clamp(y, camera_bounds.position.y, camera_bounds.size.y);
|
||||||
|
|
||||||
// BUG: annoying special case
|
// BUG: annoying special case
|
||||||
if(anim.motion == ease::SLIDE) {
|
//if(anim.motion == ease::SLIDE) {
|
||||||
anim.min_x = aimed_at.x;
|
// anim.min_x = aimed_at.x;
|
||||||
anim.min_y = aimed_at.y;
|
// anim.min_y = aimed_at.y;
|
||||||
anim.max_x = going_to.x;
|
// anim.max_x = going_to.x;
|
||||||
anim.max_y = going_to.y;
|
// anim.max_y = going_to.y;
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::reset(sf::RenderTexture& target) {
|
void Camera::reset(sf::RenderTexture& target) {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "components.hpp"
|
#include "animate2.hpp"
|
||||||
|
#include "constants.hpp"
|
||||||
#include <SFML/Graphics/RenderTexture.hpp>
|
#include <SFML/Graphics/RenderTexture.hpp>
|
||||||
|
|
||||||
namespace cinematic {
|
namespace cinematic {
|
||||||
struct Camera {
|
struct Camera {
|
||||||
components::Animation anim;
|
animate2::Animate2 anim;
|
||||||
sf::Vector2f size{SCREEN_WIDTH, SCREEN_HEIGHT};
|
sf::Vector2f size{SCREEN_WIDTH, SCREEN_HEIGHT};
|
||||||
sf::Vector2f base_size{SCREEN_WIDTH, SCREEN_HEIGHT};
|
sf::Vector2f base_size{SCREEN_WIDTH, SCREEN_HEIGHT};
|
||||||
sf::Vector2f aimed_at{0,0};
|
sf::Vector2f aimed_at{0,0};
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,10 @@ namespace ease2 {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double linear(float tick) {
|
||||||
|
return tick;
|
||||||
|
}
|
||||||
|
|
||||||
double sine(double x) {
|
double sine(double x) {
|
||||||
// old one? return std::abs(std::sin(seq.subframe * ease_rate));
|
// old one? return std::abs(std::sin(seq.subframe * ease_rate));
|
||||||
return (std::sin(x) + 1.0) / 2.0;
|
return (std::sin(x) + 1.0) / 2.0;
|
||||||
|
|
@ -107,6 +111,7 @@ namespace ease2 {
|
||||||
{"random", random},
|
{"random", random},
|
||||||
{"normal_dist", normal_dist},
|
{"normal_dist", normal_dist},
|
||||||
{"none", none},
|
{"none", none},
|
||||||
|
{"linear", linear},
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unordered_map<std::string, MotionFunc> map_of_motions{
|
std::unordered_map<std::string, MotionFunc> map_of_motions{
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include "camera.hpp"
|
#include "camera.hpp"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "animate2.hpp"
|
#include "animate2.hpp"
|
||||||
|
#include "components.hpp"
|
||||||
|
|
||||||
namespace scene {
|
namespace scene {
|
||||||
using std::shared_ptr;
|
using std::shared_ptr;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <guecs/ui.hpp>
|
#include <guecs/ui.hpp>
|
||||||
#include "camera.hpp"
|
#include "camera.hpp"
|
||||||
#include <SFML/Audio/Sound.hpp>
|
#include <SFML/Audio/Sound.hpp>
|
||||||
|
#include "components.hpp"
|
||||||
|
|
||||||
namespace storyboard {
|
namespace storyboard {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue