22#include " Animator.h"
33#include " Logger.h"
44
5- Animator::Animator (Animation* animation) : finalBoneMatrices(MAX_BONES, MyMath::VQS())
6- {
5+ Animator::Animator (Animation *animation) : finalBoneMatrices(MAX_BONES, MyMath::VQS()) {
76 currentTime = 0.0 ;
87 currentAnimation = animation;
98}
109
11- void Animator::UpdateAnimation (float dt)
12- {
10+ void Animator::UpdateAnimation (float dt) {
1311 deltaTime = dt;
14- if (currentAnimation)
15- {
12+ if (currentAnimation) {
1613 currentTime += currentAnimation->GetTicksPerSecond () * dt;
1714 currentTime = fmod (currentTime, currentAnimation->GetDuration ());
1815 CalculateBoneTransform (¤tAnimation->GetRootNode (), MyMath::VQS ());
1916 }
2017}
2118
22- void Animator::PlayAnimation (Animation* pAnimation)
23- {
19+ void Animator::PlayAnimation (Animation *pAnimation) {
2420 currentAnimation = pAnimation;
2521 currentTime = 0 .0f ;
2622}
2723
28- void Animator::CalculateBoneTransform (const AssimpNodeData* node, MyMath::VQS parentTransform)
29- {
24+ void Animator::CalculateBoneTransform (const AssimpNodeData *node, MyMath::VQS parentTransform) {
3025 std::string nodeName = node->name ;
3126 MyMath::VQS nodeTransform = node->transformation ;
3227
33- Bone* Bone = currentAnimation->FindBone (nodeName);
28+ Bone * Bone = currentAnimation->FindBone (nodeName);
3429
35- if (Bone)
36- {
30+ if (Bone) {
3731 Bone->Update (currentTime, currentLerpMode);
3832 nodeTransform = Bone->GetLocalTransform ();
3933 }
4034
4135 MyMath::VQS globalTransformation = parentTransform * nodeTransform;
4236
4337 auto boneInfoMap = currentAnimation->GetBoneIDMap ();
44- if (boneInfoMap.find (nodeName) != boneInfoMap.end ())
45- {
38+ if (boneInfoMap.find (nodeName) != boneInfoMap.end ()) {
4639 int index = boneInfoMap[nodeName].id ;
4740 MyMath::VQS offset = boneInfoMap[nodeName].offset ;
4841 finalBoneMatrices[index] = globalTransformation * offset;
@@ -52,92 +45,81 @@ void Animator::CalculateBoneTransform(const AssimpNodeData* node, MyMath::VQS pa
5245 CalculateBoneTransform (&node->children [i], globalTransformation);
5346}
5447
55- const std::vector<MyMath::VQS>& Animator::GetFinalBoneMatrices () const
56- {
48+ const std::vector<MyMath::VQS> &Animator::GetFinalBoneMatrices () const {
5749 return finalBoneMatrices;
5850}
5951
60- void Animator::ImGuiDisplay (float dt) const
61- {
62- if (ImGui::TreeNode (" Animator Controller" ))
63- {
64- if (currentAnimation)
65- {
52+ void Animator::ImGuiDisplay (float dt) const {
53+ if (ImGui::TreeNode (" Animator Controller" )) {
54+ if (currentAnimation) {
6655 ImGui::Text (" Currently playing: " );
6756 ImGui::SameLine ();
68- ImGui::TextColored ({ 0.0 ,0.7 ,0.2 ,1.0 }, " [%s]" , currentAnimation->GetName ().c_str ());
57+ ImGui::TextColored ({0.0 , 0.7 , 0.2 , 1.0 }, " [%s]" , currentAnimation->GetName ().c_str ());
6958 ImGui::Text (" Time: " );
7059 ImGui::SameLine ();
71- ImGui::TextColored ({ 0.0 ,0.7 ,0.2 ,1.0 }, " %.2f" , currentTime);
60+ ImGui::TextColored ({0.0 , 0.7 , 0.2 , 1.0 }, " %.2f" , currentTime);
7261 ImGui::SameLine ();
7362 ImGui::Text (" \\ " );
7463 ImGui::SameLine ();
75- ImGui::TextColored ({ 0.0 ,0.7 ,0.2 ,1.0 }, " %.2f" , currentAnimation->GetDuration ());
64+ ImGui::TextColored ({0.0 , 0.7 , 0.2 , 1.0 }, " %.2f" , currentAnimation->GetDuration ());
7665
7766
7867 static int selected = -1 ;
7968 ImGui::Text (" Interpolation Mode " );
8069 ImGui::Indent ();
81- ImGui::PushStyleColor (ImGuiCol_Text, { 0.2 ,0.8 ,0.2 ,1.0 });
82- if (ImGui::Selectable (" VQS [Lerp_iSlerp_eLerp]" , selected == 0 ))
83- {
70+ ImGui::PushStyleColor (ImGuiCol_Text, {0.2 , 0.8 , 0.2 , 1.0 });
71+ if (ImGui::Selectable (" VQS [Lerp_iSlerp_eLerp]" , selected == 0 )) {
8472 selected = 0 ;
8573 currentLerpMode = LerpMode::MyMix_L_iSlerp_E;
8674 }
87- ImGui::SameLine (); ImGui::TextColored ({ 0.8 , 0.2 , 0.1 , 1.0 }, " 60 FPS " );
88- if ( ImGui::Selectable ( " VQS [iLerp_iSlerp_iLerp] " , selected == 4 ))
89- {
75+ ImGui::SameLine ();
76+ ImGui::TextColored ({ 0.8 , 0.2 , 0.1 , 1.0 }, " 60 FPS " );
77+ if ( ImGui::Selectable ( " VQS [iLerp_iSlerp_iLerp] " , selected == 4 )) {
9078 selected = 4 ;
9179 currentLerpMode = MyMix_iL_iS_iL;
9280 }
93- ImGui::SameLine (); ImGui::TextColored ({ 0.8 ,0.2 ,0.1 ,1.0 }, " 60 FPS" );
94- if (ImGui::Selectable (" VQS [Lerp_Slerp_Lerp]" , selected == 2 ))
95- {
96- selected = 2 ;
97- currentLerpMode = LerpMode::MyMix_L_S_L;
98- }
99-
100- if (ImGui::Selectable (" VQS [Lerp_Slerp_eLerp]" , selected == 3 ))
101- {
102- selected = 3 ;
103- currentLerpMode = LerpMode::MyMix_L_S_E;
104- }
105-
106- if (ImGui::Selectable (" GLM [Lerp_Slerp_Lerp]" , selected == 1 ))
107- {
81+ ImGui::SameLine ();
82+ ImGui::TextColored ({0.8 , 0.2 , 0.1 , 1.0 }, " 60 FPS" );
83+ if (ImGui::Selectable (" VQS [Lerp_Slerp_Lerp]" , selected == 2 )) {
84+ selected = 2 ;
85+ currentLerpMode = LerpMode::MyMix_L_S_L;
86+ }
87+
88+ if (ImGui::Selectable (" VQS [Lerp_Slerp_eLerp]" , selected == 3 )) {
89+ selected = 3 ;
90+ currentLerpMode = LerpMode::MyMix_L_S_E;
91+ }
92+
93+ if (ImGui::Selectable (" GLM [Lerp_Slerp_Lerp]" , selected == 1 )) {
10894 selected = 1 ;
10995 currentLerpMode = LerpMode::GLMMix;
11096 }
111- ImGui::Unindent ();
112- ImGui::PopStyleColor ();
113- }
114- else
115- {
116- ImGui::TextColored ({ 0.7 , 0.1 , 0.1 , 1.0 }, " No animation set currently" );
97+ ImGui::Unindent ();
98+ ImGui::PopStyleColor ();
99+ } else {
100+ ImGui::TextColored ({0.7 , 0.1 , 0.1 , 1.0 }, " No animation set currently" );
117101 }
118102 ImGui::TreePop ();
119103 }
120104}
121105
122- const std::vector<MyMath::VQS> Animator::DrawBones (const MyMath::VQS& mat) const
123- {
106+ const std::vector<MyMath::VQS> Animator::DrawBones (const MyMath::VQS &mat) const {
124107 std::vector<MyMath::VQS> res;
125- if (currentAnimation)
126- {
108+ if (currentAnimation) {
127109 DrawBoneRecur (¤tAnimation->GetRootNode (), mat, res);
128110 }
129111 return res;
130112}
131113
132- void Animator::DrawBoneRecur (const AssimpNodeData* node, const MyMath::VQS& parentMatrix, std::vector<MyMath::VQS>& matrices) const
133- {
114+ void Animator::DrawBoneRecur (
115+ const AssimpNodeData *node, const MyMath::VQS &parentMatrix, std::vector<MyMath::VQS> &matrices
116+ ) const {
134117 std::string nodeName = node->name ;
135118 MyMath::VQS nodeTransform = node->transformation ;
136119
137- Bone* Bone = currentAnimation->FindBone (nodeName);
120+ Bone * Bone = currentAnimation->FindBone (nodeName);
138121
139- if (Bone)
140- {
122+ if (Bone) {
141123 nodeTransform = Bone->GetLocalTransform ();
142124 }
143125 MyMath::VQS globalTransform = parentMatrix * nodeTransform;
0 commit comments