Skip to content
This repository was archived by the owner on Feb 9, 2022. It is now read-only.

Commit 1960fd5

Browse files
committed
Formatted files
1 parent 87a5049 commit 1960fd5

95 files changed

Lines changed: 2867 additions & 2992 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Perspective/Source/src/Animation.cpp

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#include "stdafx.h"
22
#include "Animation.h"
33

4-
Animation::Animation(const std::string& animationPath, Model* model)
5-
{
4+
Animation::Animation(const std::string &animationPath, Model *model) {
65
Assimp::Importer importer;
7-
const aiScene* scene = importer.ReadFile(animationPath, aiProcess_Triangulate | aiProcess_OptimizeGraph);
6+
const aiScene *scene = importer.ReadFile(animationPath, aiProcess_Triangulate | aiProcess_OptimizeGraph);
87
assert(scene && scene->mRootNode);
98

109
auto animation = scene->mAnimations[0];
@@ -15,76 +14,66 @@ Animation::Animation(const std::string& animationPath, Model* model)
1514
animName = animation->mName.C_Str();
1615
}
1716

18-
Animation::Animation(const aiScene* scene, const aiAnimation* animation, Model* model)
19-
{
17+
Animation::Animation(const aiScene *scene, const aiAnimation *animation, Model *model) {
2018
duration = animation->mDuration;
2119
ticksPerSecond = animation->mTicksPerSecond;
2220
animName = animation->mName.C_Str();
2321
ReadHeirarchyData(rootNode, scene->mRootNode);
2422
ReadMissingBones(animation, *model);
2523
}
2624

27-
Bone* Animation::FindBone(const std::string& name)
28-
{
25+
Bone *Animation::FindBone(const std::string &name) {
2926
auto iter = std::find_if(bones.begin(), bones.end(),
30-
[&](const Bone& Bone)
31-
{
32-
return Bone.GetBoneName() == name;
33-
}
27+
[&](const Bone &Bone) {
28+
return Bone.GetBoneName() == name;
29+
}
3430
);
3531
if (iter == bones.end()) return nullptr;
3632
else return &(*iter);
3733
}
3834

3935
// Sometimes there are missing bone data...
4036

41-
void Animation::ImGuiDisplay(float dt) const
42-
{
43-
if (ImGui::TreeNode("Show heiarchy of %s", animName.c_str()))
44-
{
37+
void Animation::ImGuiDisplay(float dt) const {
38+
if (ImGui::TreeNode("Show heiarchy of %s", animName.c_str())) {
4539
rootNode.DisplayImGui(0);
4640
ImGui::TreePop();
4741
}
4842
}
4943

50-
void Animation::ReadMissingBones(const aiAnimation* animation, Model& model)
51-
{
44+
void Animation::ReadMissingBones(const aiAnimation *animation, Model &model) {
5245
int size = animation->mNumChannels;
5346

54-
auto& boneInfoMap = model.GetBoneInfoMap();//getting m_BoneInfoMap from Model class
55-
int& boneCount = model.GetBoneCounter(); //getting the m_BoneCounter from Model class
47+
auto &boneInfoMap = model.GetBoneInfoMap();//getting m_BoneInfoMap from Model class
48+
int &boneCount = model.GetBoneCounter(); //getting the m_BoneCounter from Model class
5649

57-
//reading channels(bones engaged in an animation and their keyframes)
58-
for (int i = 0; i < size; i++)
59-
{
50+
//reading channels(bones engaged in an animation and their keyframes)
51+
for (int i = 0; i < size; i++) {
6052
auto channel = animation->mChannels[i];
6153
std::string boneName = channel->mNodeName.data;
6254

63-
if (boneInfoMap.find(boneName) == boneInfoMap.end())
64-
{
55+
if (boneInfoMap.find(boneName) == boneInfoMap.end()) {
6556
Log("Looks like we missed boned ... [%s]", boneName.c_str());
6657
boneInfoMap[boneName].id = boneCount;
6758
boneCount++;
6859
}
6960
bones.emplace_back(Bone(channel->mNodeName.data,
70-
boneInfoMap[channel->mNodeName.data].id, channel));
61+
boneInfoMap[channel->mNodeName.data].id, channel));
7162
}
7263

7364
this->boneInfoMap = boneInfoMap;
7465
}
7566

76-
void Animation::ReadHeirarchyData(AssimpNodeData& dest, const aiNode* src)
77-
{
78-
assert(src);
67+
void Animation::ReadHeirarchyData(AssimpNodeData &dest, const aiNode *src) {
68+
assert(src);
7969

80-
dest.name = src->mName.data;
81-
glm::mat4 transformation = MyMath::AssimpToMat4(src->mTransformation);
82-
dest.transformation = MyMath::VQS(transformation);
83-
dest.childrenCount = src->mNumChildren;
70+
dest.name = src->mName.data;
71+
glm::mat4 transformation = MyMath::AssimpToMat4(src->mTransformation);
72+
dest.transformation = MyMath::VQS(transformation);
73+
dest.childrenCount = src->mNumChildren;
8474

85-
for (int i = 0; i < src->mNumChildren; i++)
86-
{
87-
AssimpNodeData newData;
75+
for (int i = 0; i < src->mNumChildren; i++) {
76+
AssimpNodeData newData;
8877
ReadHeirarchyData(newData, src->mChildren[i]);
8978
dest.children.emplace_back(newData);
9079
}

Perspective/Source/src/Animation.h

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@
22

33

44
#pragma once
5+
56
#include "Model.h"
67
#include "MyMath.h"
7-
struct AssimpNodeData
8-
{
8+
9+
struct AssimpNodeData {
910
MyMath::VQS transformation;
1011
std::string name;
1112
int childrenCount;
1213
std::vector<AssimpNodeData> children;
1314

14-
void DisplayImGui(int nodeID) const
15-
{
16-
if (childrenCount == 0)
17-
{
18-
ImGui::TextColored({0.8, 0.1,0.1,1.0}, "%s", name.c_str());
19-
}
20-
else if (ImGui::TreeNode((void*)(intptr_t)nodeID, "%s", name.c_str(), nodeID))
21-
{
22-
for (int i = 0; i < childrenCount; ++i)
23-
{
15+
void DisplayImGui(int nodeID) const {
16+
if (childrenCount == 0) {
17+
ImGui::TextColored({0.8, 0.1, 0.1, 1.0}, "%s", name.c_str());
18+
} else if (ImGui::TreeNode((void *) (intptr_t) nodeID, "%s", name.c_str(), nodeID)) {
19+
for (int i = 0; i < childrenCount; ++i) {
2420
children[i].DisplayImGui(nodeID + i);
2521
}
2622
ImGui::TreePop();
@@ -30,41 +26,43 @@ struct AssimpNodeData
3026

3127
//! Read data from assimp and create a heiracrchy of bones
3228
class Animation {
33-
public:
29+
public:
3430
Animation() = default;
35-
Animation(const std::string& animationPath, Model* model);
36-
Animation(const aiScene* scene, const aiAnimation* animation, Model* model);
3731

38-
Bone* FindBone(const std::string& name);
32+
Animation(const std::string &animationPath, Model *model);
33+
34+
Animation(const aiScene *scene, const aiAnimation *animation, Model *model);
3935

36+
Bone *FindBone(const std::string &name);
37+
38+
void ImGuiDisplay(float dt) const;
4039

4140
inline float GetTicksPerSecond() { return ticksPerSecond; }
4241

4342
inline float GetDuration() { return duration; }
4443

45-
inline const AssimpNodeData& GetRootNode() { return rootNode; }
44+
inline const AssimpNodeData &GetRootNode() { return rootNode; }
4645

47-
inline const std::unordered_map<std::string, BoneInfo>& GetBoneIDMap()
48-
{
46+
inline const std::unordered_map<std::string, BoneInfo> &GetBoneIDMap() {
4947
return boneInfoMap;
5048
}
51-
const std::string& GetName() const {return animName;}
52-
void ImGuiDisplay(float dt) const;
53-
54-
private:
55-
// Sometimes there are missing bone data...
56-
void ReadMissingBones(const aiAnimation* animation, Model& model);
5749

58-
void ReadHeirarchyData(AssimpNodeData& dest, const aiNode* src);
50+
inline const std::string &GetName() const { return animName; }
51+
52+
private:
53+
// Sometimes there are missing bone data that assimp can only get from animation
54+
void ReadMissingBones(const aiAnimation *animation, Model &model);
55+
// Read data
56+
void ReadHeirarchyData(AssimpNodeData &dest, const aiNode *src);
5957

6058

61-
private:
62-
float duration;
63-
int ticksPerSecond;
64-
std::vector<Bone> bones;
65-
AssimpNodeData rootNode;
66-
std::unordered_map<std::string, BoneInfo> boneInfoMap;
67-
std::string animName;
59+
private:
60+
float duration;
61+
int ticksPerSecond;
62+
std::vector<Bone> bones;
63+
AssimpNodeData rootNode;
64+
std::unordered_map<std::string, BoneInfo> boneInfoMap;
65+
std::string animName;
6866
};
6967

7068

Perspective/Source/src/Animator.cpp

Lines changed: 44 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,40 @@
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(&currentAnimation->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(&currentAnimation->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

Comments
 (0)