Movement is now much smoother for the easing functions and I can pan around better, but it's hard coded to only do pan at the moment.
This commit is contained in:
parent
2ebefcce05
commit
0d326089f7
8 changed files with 37 additions and 47 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
#include "animation.hpp"
|
#include "animation.hpp"
|
||||||
#include "rand.hpp"
|
#include "rand.hpp"
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
namespace components {
|
namespace components {
|
||||||
|
|
||||||
void Animation::play() {
|
void Animation::play() {
|
||||||
if(!playing) {
|
if(!playing) {
|
||||||
current = 0;
|
current = 0;
|
||||||
|
|
@ -11,7 +13,7 @@ namespace components {
|
||||||
}
|
}
|
||||||
|
|
||||||
float Animation::twitching() {
|
float Animation::twitching() {
|
||||||
float tick = ease::sine(float(frames) / (subframe + 0.0001) * ease_rate);
|
float tick = 1 - std::powf(ease_rate, subframe + 0.0001);
|
||||||
|
|
||||||
switch(easing) {
|
switch(easing) {
|
||||||
case ease::NONE:
|
case ease::NONE:
|
||||||
|
|
@ -21,13 +23,15 @@ namespace components {
|
||||||
case ease::OUT_CIRC:
|
case ease::OUT_CIRC:
|
||||||
return ease::out_circ(tick);
|
return ease::out_circ(tick);
|
||||||
case ease::OUT_BOUNCE:
|
case ease::OUT_BOUNCE:
|
||||||
return ease::sine(ease::out_bounce(tick));
|
return ease::out_bounce(tick);
|
||||||
case ease::IN_OUT_BACK:
|
case ease::IN_OUT_BACK:
|
||||||
return ease::sine(ease::in_out_back(tick));
|
return ease::in_out_back(tick);
|
||||||
case ease::RANDOM:
|
case ease::RANDOM:
|
||||||
return Random::uniform_real(0.0001f, 1.0f);
|
return Random::uniform_real(0.0001f, 1.0f);
|
||||||
case ease::NORM_DIST:
|
case ease::NORM_DIST:
|
||||||
return Random::normal(0.5f, 0.1f);
|
return Random::normal(0.5f, 0.1f);
|
||||||
|
case ease::LINEAR:
|
||||||
|
return tick;
|
||||||
default:
|
default:
|
||||||
dbc::sentinel(
|
dbc::sentinel(
|
||||||
fmt::format("Invalid easing {} given to animation",
|
fmt::format("Invalid easing {} given to animation",
|
||||||
|
|
@ -65,8 +69,8 @@ namespace components {
|
||||||
scale_out.y = std::lerp(min_y, max_y, tick);
|
scale_out.y = std::lerp(min_y, max_y, tick);
|
||||||
} break;
|
} break;
|
||||||
case ease::SLIDE: {
|
case ease::SLIDE: {
|
||||||
pos_out.x += std::lerp(pos_out.x, pos_out.x + max_x, tick);
|
pos_out.x = std::lerp(min_x, max_x, tick);
|
||||||
pos_out.y += std::lerp(pos_out.y, pos_out.y + max_y, tick);
|
pos_out.y = std::lerp(min_y, max_y, tick);
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
dbc::sentinel("Unknown animation.motion setting.");
|
dbc::sentinel("Unknown animation.motion setting.");
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@
|
||||||
"max_y": 1.2,
|
"max_y": 1.2,
|
||||||
"simple": true,
|
"simple": true,
|
||||||
"frames": 1,
|
"frames": 1,
|
||||||
"speed": 0.6,
|
"speed": 0.2,
|
||||||
"scaled": true,
|
"scaled": true,
|
||||||
"stationary": false,
|
"stationary": false,
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
|
|
@ -192,7 +192,7 @@
|
||||||
"max_y": 1.1,
|
"max_y": 1.1,
|
||||||
"simple": true,
|
"simple": true,
|
||||||
"frames": 10,
|
"frames": 10,
|
||||||
"speed": 1.0,
|
"speed": 0.2,
|
||||||
"scaled": true,
|
"scaled": true,
|
||||||
"stationary": false,
|
"stationary": false,
|
||||||
"toggled": false,
|
"toggled": false,
|
||||||
|
|
@ -235,24 +235,6 @@
|
||||||
"flipped": false,
|
"flipped": false,
|
||||||
"looped": false
|
"looped": false
|
||||||
},
|
},
|
||||||
"rat_king_boss": {
|
|
||||||
"_type": "Animation",
|
|
||||||
"easing": 4,
|
|
||||||
"motion": 0,
|
|
||||||
"ease_rate": 0.5,
|
|
||||||
"min_x": 0.6,
|
|
||||||
"min_y": 0.6,
|
|
||||||
"max_x": 0.8,
|
|
||||||
"max_y": 0.8,
|
|
||||||
"simple": false,
|
|
||||||
"frames": 2,
|
|
||||||
"speed": 0.02,
|
|
||||||
"scaled": true,
|
|
||||||
"stationary": true,
|
|
||||||
"toggled": false,
|
|
||||||
"flipped": false,
|
|
||||||
"looped": false
|
|
||||||
},
|
|
||||||
"torch_fixture": {
|
"torch_fixture": {
|
||||||
"_type": "Animation",
|
"_type": "Animation",
|
||||||
"easing": 0,
|
"easing": 0,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"pan": {
|
"pan": {
|
||||||
"_type": "Animation",
|
"_type": "Animation",
|
||||||
"easing": 2,
|
"easing": 7,
|
||||||
"motion": 7,
|
"motion": 7,
|
||||||
"ease_rate": 0.05,
|
"ease_rate": 0.001,
|
||||||
"min_x": 0,
|
"min_x": 0.0,
|
||||||
"min_y": 0,
|
"min_y": 0.0,
|
||||||
"max_x": 150.0,
|
"max_x": 0.0,
|
||||||
"max_y": 0.0,
|
"max_y": 0.0,
|
||||||
"simple": true,
|
"simple": true,
|
||||||
"frames": 1,
|
"frames": 1,
|
||||||
|
|
@ -40,8 +40,8 @@
|
||||||
"easing": 1,
|
"easing": 1,
|
||||||
"motion": 0,
|
"motion": 0,
|
||||||
"ease_rate": 0.5,
|
"ease_rate": 0.5,
|
||||||
"min_x": 1.3,
|
"min_x": 0.8,
|
||||||
"min_y": 1.3,
|
"min_y": 0.8,
|
||||||
"max_x": 1.0,
|
"max_x": 1.0,
|
||||||
"max_y": 1.0,
|
"max_y": 1.0,
|
||||||
"simple": true,
|
"simple": true,
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,15 @@ namespace cinematic {
|
||||||
anim = MGR.animations.at(name);
|
anim = MGR.animations.at(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Camera::position(float x, float y) {
|
||||||
|
anim.min_x = x;
|
||||||
|
anim.min_y = y;
|
||||||
|
}
|
||||||
|
|
||||||
void Camera::move(sf::RenderTexture& target, sf::Vector2f pos) {
|
void Camera::move(sf::RenderTexture& target, sf::Vector2f pos) {
|
||||||
sf::View zoom;
|
sf::View zoom;
|
||||||
|
anim.max_x = pos.x;
|
||||||
|
anim.max_y = pos.y;
|
||||||
anim.apply(zoom, pos, size);
|
anim.apply(zoom, pos, size);
|
||||||
target.setView(zoom);
|
target.setView(zoom);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ namespace cinematic {
|
||||||
void move(sf::RenderTexture& target, sf::Vector2f pos);
|
void move(sf::RenderTexture& target, sf::Vector2f pos);
|
||||||
bool playing();
|
bool playing();
|
||||||
void play();
|
void play();
|
||||||
|
void position(float x, float y);
|
||||||
void style(const std::string &name);
|
void style(const std::string &name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ namespace ease {
|
||||||
OUT_BOUNCE=3,
|
OUT_BOUNCE=3,
|
||||||
IN_OUT_BACK=4,
|
IN_OUT_BACK=4,
|
||||||
RANDOM=5,
|
RANDOM=5,
|
||||||
NORM_DIST=6
|
NORM_DIST=6,
|
||||||
|
LINEAR=7
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Motion {
|
enum Motion {
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,12 @@
|
||||||
#include "animation.hpp"
|
#include "animation.hpp"
|
||||||
|
|
||||||
namespace storyboard {
|
namespace storyboard {
|
||||||
|
|
||||||
UI::UI() :
|
UI::UI() :
|
||||||
$view_texture({SCREEN_WIDTH, SCREEN_HEIGHT}),
|
$view_texture({SCREEN_WIDTH, SCREEN_HEIGHT}),
|
||||||
$view_sprite($view_texture.getTexture())
|
$view_sprite($view_texture.getTexture())
|
||||||
{
|
{
|
||||||
$view_sprite.setPosition({0, 0});
|
$view_sprite.setPosition({0, 0});
|
||||||
$camera.style("dolly");
|
$camera.style("pan");
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI::init() {
|
void UI::init() {
|
||||||
|
|
@ -31,6 +30,7 @@ namespace storyboard {
|
||||||
zoom($zoom_target);
|
zoom($zoom_target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$view_texture.clear();
|
||||||
$ui.render($view_texture);
|
$ui.render($view_texture);
|
||||||
$ui.debug_layout($view_texture);
|
$ui.debug_layout($view_texture);
|
||||||
$view_texture.display();
|
$view_texture.display();
|
||||||
|
|
@ -38,17 +38,13 @@ namespace storyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UI::mouse(float x, float y, guecs::Modifiers mods) {
|
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);
|
||||||
|
|
||||||
|
$zoom_target = *$ui.$parser.hit(x, y);
|
||||||
|
|
||||||
if(zoomed) {
|
|
||||||
zoomed = false;
|
|
||||||
reset();
|
|
||||||
} else {
|
|
||||||
zoomed = true;
|
|
||||||
auto target = $ui.$parser.hit(x, y);
|
|
||||||
$zoom_target = *target;
|
|
||||||
zoom($zoom_target);
|
zoom($zoom_target);
|
||||||
$camera.play();
|
$camera.play();
|
||||||
}
|
|
||||||
|
|
||||||
return $ui.mouse(x, y, mods);
|
return $ui.mouse(x, y, mods);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,7 @@ namespace storyboard {
|
||||||
sf::RenderTexture $view_texture;
|
sf::RenderTexture $view_texture;
|
||||||
sf::Sprite $view_sprite;
|
sf::Sprite $view_sprite;
|
||||||
cinematic::Camera $camera;
|
cinematic::Camera $camera;
|
||||||
std::string $zoom_target;
|
std::string $zoom_target = "a";
|
||||||
bool zoomed = false;
|
|
||||||
|
|
||||||
UI();
|
UI();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue