-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathanimate.hpp
49 lines (41 loc) · 1.14 KB
/
animate.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// animate.hpp
// Simpleton Engine
//
// Created by Indi Kernick on 26/11/17.
// Copyright © 2017 Indi Kernick. All rights reserved.
//
#ifndef engine_camera_2d_animate_hpp
#define engine_camera_2d_animate_hpp
#include "props.hpp"
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/norm.hpp>
#undef GLM_ENABLE_EXPERIMENTAL
namespace Cam2D {
template <PropID PROP_>
class Animate {
public:
static constexpr PropID PROP = PROP_;
using Type = PropType<PROP>;
Animate() = default;
virtual ~Animate() = 0;
virtual Type calculate(const Props props, const Params params, const Type target) {
const Type current = getProp<PROP>(props);
const Type toTarget = target - current;
const float targetDist = glm::length(toTarget);
const float moveDist = getMoveDistance(props, params, target);
if (targetDist <= moveDist) {
return target;
} else {
return current + moveDist * toTarget / targetDist;
}
}
private:
virtual float getMoveDistance(Props, Params, Type) {
return 1.0f;
}
};
template <PropID PROP>
inline Animate<PROP>::~Animate() {}
}
#endif