Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
AnimationComponent.h
Go to the documentation of this file.
1#pragma once
2#include "scene/Component.h"
3
4#include <glm/vec3.hpp>
5#include <glm/gtc/quaternion.hpp>
6
7#include <string>
8#include <vector>
9#include <unordered_map>
10#include <memory>
11
12namespace eng
13{
15 {
16 float time = 0.0f;
17 glm::vec3 value = glm::vec3(0.0f);
18 };
19
21 {
22 float time = 0.0f;
23 glm::quat value = glm::quat(1.0f, 0.0f, 0.0f, 0.0f);
24 };
25
27 {
28 std::string targetName;
29 std::vector<KeyFrameVec3> positions;
30 std::vector<KeyFrameQuat> rotations;
31 std::vector<KeyFrameVec3> scales;
32 };
33
35 {
36 std::string name;
37 float duration = 0.0f;
38 bool looping = true;
39 std::vector<TransformTrack> tracks;
40 };
41
43 {
44 GameObject* object = nullptr;
45 std::vector<size_t> trackIndices;
46 };
47
49 {
51 public:
52 void Update(float deltaTime) override;
53 void SetClip(AnimationClip* clip);
54 void RegisterClip(const std::string& name, const std::shared_ptr<AnimationClip>& clip);
55 void Play(const std::string& name, bool loop = true);
56
57 bool IsPlaying() const;
58
59 private:
60 void BuildBindings();
61 glm::vec3 Interpolate(const std::vector<KeyFrameVec3>& keys, float time);
62 glm::quat Interpolate(const std::vector<KeyFrameQuat>& keys, float time);
63
64 private:
65 AnimationClip* m_clip = nullptr;
66 float m_time = 0.0f;
67 bool m_looping = true;
68 bool m_isPlaying = false;
69
70 std::unordered_map<std::string, std::shared_ptr<AnimationClip>> m_clips;
71 std::unordered_map<GameObject*, std::unique_ptr<ObjectBinding>> m_bindings;
72 };
73}
void RegisterClip(const std::string &name, const std::shared_ptr< AnimationClip > &clip)
void SetClip(AnimationClip *clip)
void Play(const std::string &name, bool loop=true)
void Update(float deltaTime) override
#define COMPONENT(ComponentClass)
Definition Component.h:105
std::vector< TransformTrack > tracks
std::vector< size_t > trackIndices
std::vector< KeyFrameQuat > rotations
std::vector< KeyFrameVec3 > scales
std::vector< KeyFrameVec3 > positions