62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
#ifndef TRANSFORM_COMPONENT_H
|
|
#define TRANSFORM_COMPONENT_H
|
|
|
|
#include <glm/glm.hpp>
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
#include <yaml-cpp/yaml.h>
|
|
|
|
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;
|
|
|
|
// 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>();
|
|
}
|
|
}
|
|
};
|
|
|
|
#endif // TRANSFORM_COMPONENT_H
|