CSEngine
Loading...
Searching...
No Matches
AnimationUtil.h
1#pragma once
2
3#include "../../SObject.h"
4#include "../Matrix.h"
5#include "../Quaternion.h"
6#include "../../Manager/ResMgr.h"
7#include "../../MacroDef.h"
8#include <utility>
9#include <vector>
10#include <string>
11
12namespace CSE {
13
15 public:
17 m_position = vec3();
18 m_rotation = Quaternion();
19 }
20
21 JointTransform(const vec3& position, Quaternion rotation) {
22 m_position.Set(position.x, position.y, position.z);
23 m_rotation = rotation;
24 }
25
26 ~JointTransform() = default;
27
28 static JointTransform Interpolate(float t, JointTransform& a, JointTransform& b) {
29 vec3 position = vec3::Lerp(t, a.m_position, b.m_position);
30 Quaternion rotation = a.m_rotation.Slerp(t, b.m_rotation);
31
32 return {position, rotation};
33 }
34
35 mat4 GetLocalMatrix() {
36 mat4 mat;
37 mat = mat4::Translate(m_position.x, m_position.y, m_position.z);
38 mat = m_rotation.ToMatrix4() * mat;
39
40
41 return mat;
42 }
43
44 private:
45 vec3 m_position;
46 Quaternion m_rotation;
47 };
48
49 class KeyFrame {
50 public:
51 KeyFrame(float timeStamp, std::vector<JointTransform*>&& pose) {
52 m_timeStamp = timeStamp;
53 m_pose = std::move(pose);
54 }
55
56 ~KeyFrame() {
57 for (auto pair : m_pose) {
58 SAFE_DELETE(pair);
59 }
60
61 m_pose.clear();
62 }
63
64 float GetTimeStamp() const {
65 return m_timeStamp;
66 }
67
68 std::vector<JointTransform*> GetJointKeyFrames() const {
69 return m_pose;
70 }
71
72 private:
73 float m_timeStamp = 0;
74 std::vector<JointTransform*> m_pose;
75 };
76}