-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathComponentBone.cpp
More file actions
98 lines (79 loc) · 2.77 KB
/
ComponentBone.cpp
File metadata and controls
98 lines (79 loc) · 2.77 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "ComponentBone.h"
#include <string>
#include "imgui\imgui.h"
#include "ResourceFileBone.h"
#include "Application.h"
#include "ModuleRenderer3D.h"
#include "ModuleResourceManager.h"
#include "Data.h"
#include "GameObject.h"
#include "ComponentTransform.h"
ComponentBone::ComponentBone(GameObject* game_object) : Component(C_BONE, game_object)
{
}
ComponentBone::~ComponentBone()
{
}
void ComponentBone::OnInspector(bool debug)
{
std::string str = (std::string("Bone") + std::string("##") + std::to_string(uuid));
if (ImGui::CollapsingHeader(str.c_str(), ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::Text("Num Weights: %i", rBone->numWeights);
ImGui::Text("Offset Matrix:");
ImGui::Text("%0.2f %0.2f %0.2f %0.2f", rBone->offset.v[0][0], rBone->offset.v[0][1], rBone->offset.v[0][2], rBone->offset.v[0][3]);
ImGui::Text("%0.2f %0.2f %0.2f %0.2f", rBone->offset.v[1][0], rBone->offset.v[1][1], rBone->offset.v[1][2], rBone->offset.v[1][3]);
ImGui::Text("%0.2f %0.2f %0.2f %0.2f", rBone->offset.v[2][0], rBone->offset.v[2][1], rBone->offset.v[2][2], rBone->offset.v[2][3]);
ImGui::Text("%0.2f %0.2f %0.2f %0.2f", rBone->offset.v[3][0], rBone->offset.v[3][1], rBone->offset.v[3][2], rBone->offset.v[3][3]);
}
}
void ComponentBone::Save(Data& file)const
{
Data data;
data.AppendInt("type", type);
data.AppendUInt("UUID", uuid);
data.AppendBool("active", active);
data.AppendString("path", rBone->GetFile());
file.AppendArrayValue(data);
}
void ComponentBone::Load(Data& conf)
{
uuid = conf.GetUInt("UUID");
active = conf.GetBool("active");
const char* path = conf.GetString("path");
rBone = (ResourceFileBone*)App->resource_manager->LoadResource(path, ResourceFileType::RES_BONE);
}
void ComponentBone::SetResource(ResourceFileBone* rBone)
{
this->rBone = rBone;
}
ResourceFileBone* ComponentBone::GetResource() const
{
return rBone;
}
const char* ComponentBone::GetResourcePath() const
{
return rBone == nullptr ? nullptr : rBone->GetFile();
}
void ComponentBone::Update()
{
if (App->StartInGame() == false)
{
for (std::vector<GameObject*>::const_iterator it = game_object->GetChilds()->begin(); it != game_object->GetChilds()->end(); it++)
{
float3 pos1 = game_object->transform->GetGlobalMatrix().TranslatePart();
float3 pos2 = (*it)->transform->GetGlobalMatrix().TranslatePart();
App->renderer3D->DrawLine(pos1, pos2, float4(1, 0, 1, 1));
}
}
}
float4x4 ComponentBone::GetSystemTransform()
{
float4x4 transform = game_object->transform->GetGlobalMatrix();
return GetRoot()->game_object->GetParent()->GetParent()->transform->GetGlobalMatrix().Inverted() * transform;
}
ComponentBone* ComponentBone::GetRoot()
{
ComponentBone* parentBone = (ComponentBone*)game_object->GetParent()->GetComponent(C_BONE);
return parentBone == nullptr ? this : parentBone->GetRoot();
}