ThreeLab/Engine/Components/TransformComponent.h

62 lines
1.8 KiB
C
Raw Normal View History

2025-04-01 20:03:18 +00:00
#ifndef TRANSFORM_COMPONENT_H
#define TRANSFORM_COMPONENT_H
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
2025-04-02 00:19:53 +00:00
#include <yaml-cpp/yaml.h>
2025-04-01 20:03:18 +00:00
class TransformComponent {
public:
TransformComponent();
~TransformComponent();
glm::vec3 position;
glm::vec3 rotation; // Euler angles (pitch, yaw, roll) in degrees.
glm::vec3 scale;
// Returns the world transform matrix.
glm::mat4 GetMatrix() const;
2025-04-02 00:19:53 +00:00
// Save this transform to a YAML node.
YAML::Node Save() const {
YAML::Node node;
node["position"] = YAML::Node();
node["position"].push_back(position.x);
node["position"].push_back(position.y);
node["position"].push_back(position.z);
node["rotation"] = YAML::Node();
node["rotation"].push_back(rotation.x);
node["rotation"].push_back(rotation.y);
node["rotation"].push_back(rotation.z);
node["scale"] = YAML::Node();
node["scale"].push_back(scale.x);
node["scale"].push_back(scale.y);
node["scale"].push_back(scale.z);
return node;
}
// Load this transform from a YAML node.
void Load(const YAML::Node &node) {
if (node["position"]) {
position.x = node["position"][0].as<float>();
position.y = node["position"][1].as<float>();
position.z = node["position"][2].as<float>();
}
if (node["rotation"]) {
rotation.x = node["rotation"][0].as<float>();
rotation.y = node["rotation"][1].as<float>();
rotation.z = node["rotation"][2].as<float>();
}
if (node["scale"]) {
scale.x = node["scale"][0].as<float>();
scale.y = node["scale"][1].as<float>();
scale.z = node["scale"][2].as<float>();
}
}
2025-04-01 20:03:18 +00:00
};
#endif // TRANSFORM_COMPONENT_H