35 lines
981 B
C++
35 lines
981 B
C++
#pragma once
|
|
|
|
#include <glm/glm.hpp>
|
|
#include <glm/gtc/quaternion.hpp>
|
|
|
|
struct Transform
|
|
{
|
|
glm::vec3 position = glm::vec3(0.0f);
|
|
glm::quat rotation = glm::quat(1.0f, 0.0f, 0.0f, 0.0f); // Identity quaternion
|
|
float scale = 1.0f;
|
|
|
|
glm::mat4 ToMatrix() const
|
|
{
|
|
// TODO: Optimize matrix construction
|
|
glm::mat4 translation_mat = glm::translate(glm::mat4(1.0f), position);
|
|
glm::mat4 rotation_mat = glm::mat4_cast(rotation);
|
|
glm::mat4 scaling_mat = glm::scale(glm::mat4(1.0f), glm::vec3(scale));
|
|
return translation_mat * rotation_mat * scaling_mat;
|
|
}
|
|
|
|
void SetAngles(const glm::vec3& angles_deg)
|
|
{
|
|
glm::vec3 angles_rad = glm::radians(angles_deg);
|
|
rotation = glm::quat(angles_rad);
|
|
}
|
|
|
|
static Transform Lerp(const Transform& a, const Transform& b, float t)
|
|
{
|
|
Transform result;
|
|
result.position = glm::mix(a.position, b.position, t);
|
|
result.rotation = glm::slerp(a.rotation, b.rotation, t);
|
|
result.scale = glm::mix(a.scale, b.scale, t);
|
|
return result;
|
|
}
|
|
}; |