-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimation.hpp
More file actions
57 lines (43 loc) · 1.54 KB
/
Animation.hpp
File metadata and controls
57 lines (43 loc) · 1.54 KB
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
50
51
52
53
54
55
56
57
#ifndef GLTF_ANIMATION
#define GLTF_ANIMATION
#include "Mesh.hpp"
struct TRSData {
glm::vec3 t, s;
glm::quat r;
fastgltf::AnimationPath type;
};
struct TRSOverrideData {
glm::vec3 t = glm::vec3(0.0), s = glm::vec3(1.0);
glm::quat r = glm::quat(1,0,0,0);
bool hasTranslation = false, hasRotation = false, hasScale = false;
};
struct SamplerData {
fastgltf::AnimationPath type = (fastgltf::AnimationPath)0;
std::vector<glm::vec4> value;
std::vector<GLfloat> time;
int64_t nodeIndex;
SamplerData() noexcept : nodeIndex(-1) {}
SamplerData(const fastgltf::AnimationPath aType, std::vector<glm::vec4>& aValue, std::vector<GLfloat>& aTime, const int64_t aNodeIndex) noexcept
:type(aType), value(aValue), time(aTime), nodeIndex(aNodeIndex) {}
~SamplerData() {}
};
class Model;
class Animation {
friend class Model;
public:
Animation() noexcept;
void setStateAtTime(Model& aModel, const float aTime) noexcept;
float getMaxTime() const noexcept;
~Animation() noexcept;
private:
std::string mName;
std::vector<SamplerData> mSamplers;
float mMaxTime;
float lerp(float aLast, float aNext, float aCurrent) noexcept;
uint64_t getIndex(const SamplerData& aSampler, const float aTime) noexcept;
glm::vec3 interpolatePosition(const SamplerData& aSampler, const float aTime) noexcept;
glm::quat interpolateRotation(const SamplerData& aSampler, const float aTime) noexcept;
glm::vec3 interpolateScale(const SamplerData& aSampler, const float aTime) noexcept;
TRSData getLocalSamplerTransform(const uint64_t aSamplerId, const float aTime) noexcept;
};
#endif