5#include "hellfire/graphics/Transform3D.h"
7#include <glm/gtc/quaternion.hpp>
12 glm::vec3 direction = glm::normalize(target - get_position());
13 glm::vec3 right = glm::normalize(glm::cross(direction, up));
14 glm::vec3 adjusted_up = glm::normalize(glm::cross(right, direction));
17 glm::mat4 rotation(1.0f);
18 rotation[0] = glm::vec4(right, 0.0f);
19 rotation[1] = glm::vec4(adjusted_up, 0.0f);
20 rotation[2] = glm::vec4(direction, 0.0f);
22 rotation_matrix_ = rotation;
28 rotation_x_ = glm::radians(angles.x);
29 rotation_y_ = glm::radians(angles.y);
30 rotation_z_ = glm::radians(angles.z);
31 rotation_in_degrees_ = glm::vec3(glm::degrees(rotation_x_), glm::degrees(rotation_y_), glm::degrees(rotation_z_));
39 glm::vec3 euler = glm::eulerAngles(q);
42 glm::vec3 euler_degrees = glm::degrees(euler);
45 set_rotation(euler_degrees);
49 return rotation_in_degrees_;
56 glm::mat3 rot3(rotation_matrix);
59 if (std::abs(rot3[0][2]) > 0.998f) {
61 y = atan2f(-rot3[2][0], rot3[0][0]) * (rot3[0][2] > 0 ? -1.0f : 1.0f);
62 x = (rot3[0][2] > 0 ? -1.0f : 1.0f) * glm::half_pi<
float>();
66 y = atan2f(rot3[0][2], rot3[2][2]);
67 x = -asinf(rot3[1][2]);
68 z = atan2f(rot3[1][0], rot3[1][1]);
73 rotation_matrix_ = other.get_rotation_matrix();