Moved quat to forward vector in math helper class

This commit is contained in:
Antoine Pilote
2023-07-09 23:51:32 -04:00
parent f66865c0ec
commit 2a6601a2db
3 changed files with 14 additions and 3 deletions

View File

@@ -6,3 +6,8 @@ Quat Nuake::QuatFromEuler(float x, float y, float z)
{
return Quat(Vector3(Rad(z), Rad(y), Rad(x)));
}
Vector3 Nuake::QuatToDirection(const Quat& quat)
{
return glm::rotate(glm::inverse(quat), glm::vec3(1.0, 0.0, 0.0));
}

View File

@@ -18,5 +18,7 @@ namespace Nuake
using Matrix4 = glm::mat4;
using Matrix3 = glm::mat3;
#define Rad(degrees) glm::radians(degrees)
Quat QuatFromEuler(float x, float y, float z);
Vector3 QuatToDirection(const Quat& quat);
}

View File

@@ -16,6 +16,7 @@
#include <GL/glew.h>
#include "Engine.h"
#include "src/Core/Maths.h"
#include "src/Core/FileSystem.h"
#include "src/Scene/Components/Components.h"
#include "src/Scene/Components/BoxCollider.h"
@@ -141,10 +142,13 @@ namespace Nuake {
{
auto [transform, camera, parent] = view.get<TransformComponent, CameraComponent, ParentComponent>(e);
cam = camera.CameraInstance;
cam->Translation = transform.GetGlobalPosition();
cam->SetDirection(glm::rotate(glm::inverse(transform.GetGlobalRotation()), glm::vec3(1.0, 0.0, 0.0)));
camTransform = transform.GetGlobalTransform();
cam->Translation = transform.GetGlobalPosition();
const Vector3& forward = QuatToDirection(transform.GetGlobalRotation());
cam->SetDirection(forward);
camTransform = transform.GetGlobalTransform();
break;
}
}