1#include "TransformComponent.h"
6 m_position =
vec3{ 0, 0, 0 };
8 m_scale =
vec3{ 1, 1, 1 };
12TransformComponent::~TransformComponent() =
default;
15void TransformComponent::Init() {
19void TransformComponent::Tick(
float elapsedTime) {
21 m_f_matrix = GetFinalMatrix();
22 m_f_position =
vec3{ m_f_matrix.w.x, m_f_matrix.w.y, m_f_matrix.w.z };
23 m_f_scale =
vec3{ m_f_matrix.x.x, m_f_matrix.y.y, m_f_matrix.z.z };
28void TransformComponent::Exterminate() {
31mat4 TransformComponent::GetMatrix()
const {
35vec3* TransformComponent::GetPosition() {
39vec3 TransformComponent::GetScale()
const {
43Quaternion TransformComponent::GetRotation()
const {
46 if (gameObject->GetParent() !=
nullptr) {
47 parent =
static_cast<TransformComponent*
>(gameObject->GetParent()->GetTransform())->GetRotation();
51 return m_rotation.Multiplied(parent);
54void TransformComponent::SetMatrix(
const mat4& matrix) {
55 m_position =
vec3{ matrix.w.x, matrix.w.y, matrix.w.z };
56 m_scale =
vec3{ matrix.x.x, matrix.y.y, matrix.z.z };
57 m_rotation = Quaternion::ToQuaternion(matrix);
61mat4 TransformComponent::GetFinalMatrix()
const {
62 mat4 scale = mat4::Scale(m_scale.x, m_scale.y, m_scale.z);
63 mat4 translation = mat4::Translate(m_position.x, m_position.y, m_position.z);
66 mat4 rotation =
mat4(m_rotation.ToMatrix3());
70 mat4 parentMatrix = mat4::Identity();
71 if (gameObject->GetParent() !=
nullptr) {
72 parentMatrix =
static_cast<TransformComponent*
>(gameObject->GetParent()->GetTransform())->GetMatrix();
76 return scale * rotation * translation * parentMatrix;
82 clone->m_position =
vec3(m_position);
83 clone->m_scale =
vec3(m_scale);
89void TransformComponent::SetValue(std::string name_str, Arguments value) {
90 if (name_str ==
"m_position") {
91 m_position =
vec3(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]));
92 }
else if (name_str ==
"m_scale") {
93 m_scale =
vec3(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]));
94 }
else if (name_str ==
"m_rotation") {
95 m_rotation =
Quaternion(std::stof(value[0]), std::stof(value[1]), std::stof(value[2]), std::stof(value[3]));
99std::string TransformComponent::PrintValue()
const {
100 PRINT_START(
"component");
102 PRINT_VALUE(m_position, m_position.x,
' ', m_position.y,
' ', m_position.z);
103 PRINT_VALUE(m_scale, m_scale.x,
' ', m_scale.y,
' ', m_scale.z);
104 PRINT_VALUE(m_rotation, m_rotation.x,
' ', m_rotation.y,
' ', m_rotation.z,
' ', m_rotation.w);
106 PRINT_END(
"component");