CSEngine
Loading...
Searching...
No Matches
JointComponent.cpp
1#include "JointComponent.h"
2#include "../TransformComponent.h"
3#include "../../Object/SResource.h"
4
5using namespace CSE;
6
7COMPONENT_CONSTRUCTOR(JointComponent), m_id(-1), m_animatedMatrix(mat4::Identity()), m_inverseTransformMatrix(mat4::Identity()) {
8
9}
10
11JointComponent::JointComponent(const JointComponent& src) : SComponent(src) {
12 m_animatedMatrix = src.m_animatedMatrix;
13 m_id = src.m_id;
14 m_inverseTransformMatrix = src.m_inverseTransformMatrix;
15}
16
17JointComponent::~JointComponent() = default;
18
19void JointComponent::Exterminate() {
20
21}
22
23void JointComponent::Init() {
24
25}
26
27void JointComponent::Tick(float elapsedTime) {
28
29}
30
31
32void JointComponent::SetAnimationMatrix(mat4&& animation) {
33 m_animatedMatrix = animation;
34}
35
36void JointComponent::calcInverseBindTransform(const mat4& parentTransform) {
37 mat4 bindTransform = m_localBindMatrix * parentTransform;
38 m_inverseTransformMatrix = mat4::Invert(bindTransform);
39
40 auto children = gameObject->GetChildren();
41 for (const auto& child : children) {
42 auto child_comp = child->GetComponent<JointComponent>();
43
44 if(child_comp == nullptr) continue;
45
46 child_comp->calcInverseBindTransform(bindTransform);
47 }
48}
49
50SComponent* JointComponent::Clone(SGameObject* object) {
51 INIT_COMPONENT_CLONE(JointComponent, clone);
52
53 clone->m_inverseTransformMatrix = mat4(m_inverseTransformMatrix);
54 clone->m_animatedMatrix = mat4(m_animatedMatrix);
55 clone->m_localBindMatrix = mat4(m_localBindMatrix);
56 clone->m_id = m_id;
57 clone->m_animationJointId = m_animationJointId;
58
59 return clone;
60}
61
62void JointComponent::SetBindLocalMatrix(const mat4& mat) {
63 m_localBindMatrix = mat;
64}
65
66void JointComponent::SetValue(std::string name_str, VariableBinder::Arguments value) {
67 if(name_str == "m_inverseTransformMatrix") {
68 SET_MAT4(m_inverseTransformMatrix)
69 }
70 else if(name_str == "m_animatedMatrix") {
71 SET_MAT4(m_animatedMatrix)
72 }
73 else if(name_str == "m_localBindMatrix") {
74 SET_MAT4(m_localBindMatrix)
75 }
76}
77
78std::string JointComponent::PrintValue() const {
79 PRINT_START("component");
80
81 PRINT_VALUE_MAT4(m_inverseTransformMatrix);
82 PRINT_VALUE_MAT4(m_animatedMatrix);
83 PRINT_VALUE_MAT4(m_localBindMatrix);
84
85 PRINT_END("component");
86}