Now have a simple camera system that I can configure in json for different motion effects.
This commit is contained in:
parent
8345097e10
commit
5b57fb2033
11 changed files with 173 additions and 128 deletions
56
camera.cpp
Normal file
56
camera.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#include "camera.hpp"
|
||||
#include <fmt/core.h>
|
||||
#include "animation.hpp"
|
||||
#include <unordered_map>
|
||||
#include "components.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
namespace cinematic {
|
||||
using components::Animation, std::string;
|
||||
|
||||
struct CameraManager {
|
||||
std::unordered_map<string, Animation> animations;
|
||||
};
|
||||
|
||||
static CameraManager MGR;
|
||||
static bool initialized = false;
|
||||
|
||||
void init() {
|
||||
if(!initialized) {
|
||||
auto cameras = settings::get("cameras");
|
||||
for(auto &[name, data] : cameras.json().items()) {
|
||||
auto anim = components::convert<Animation>(data);
|
||||
MGR.animations.try_emplace(name, anim);
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
Camera::Camera() :
|
||||
anim(MGR.animations.at("pan"))
|
||||
{
|
||||
}
|
||||
|
||||
void Camera::resize(sf::Vector2f to) {
|
||||
size = to;
|
||||
}
|
||||
|
||||
void Camera::style(const std::string &name) {
|
||||
anim = MGR.animations.at(name);
|
||||
}
|
||||
|
||||
void Camera::move(sf::RenderTexture& target, sf::Vector2f pos) {
|
||||
sf::View zoom;
|
||||
anim.apply(zoom, pos, size);
|
||||
target.setView(zoom);
|
||||
}
|
||||
|
||||
bool Camera::playing() {
|
||||
return anim.playing;
|
||||
}
|
||||
|
||||
void Camera::play() {
|
||||
anim.play();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue