Fixed wrong camera rotation when global rotation is set

This commit is contained in:
Antoine Pilote
2023-07-09 23:44:50 -04:00
parent a8e9beafbb
commit f66865c0ec
3 changed files with 3 additions and 8 deletions

View File

@@ -4,10 +4,5 @@ using namespace Nuake;
Quat Nuake::QuatFromEuler(float x, float y, float z)
{
// Taken from: https://gamedev.stackexchange.com/questions/13436/glm-euler-angles-to-quaternion
Quat QuatAroundX = glm::angleAxis(glm::radians(x), Vector3(1.0, 0.0, 0.0));
Quat QuatAroundY = glm::angleAxis(glm::radians(y), Vector3(0.0, 1.0, 0.0));
Quat QuatAroundZ = glm::angleAxis(glm::radians(z), Vector3(0.0, 0.0, 1.0));
return QuatAroundZ * QuatAroundX * QuatAroundY;
return Quat(Vector3(Rad(z), Rad(y), Rad(x)));
}

View File

@@ -17,6 +17,6 @@ namespace Nuake
using Color = glm::vec4;
using Matrix4 = glm::mat4;
using Matrix3 = glm::mat3;
#define Rad(degrees) glm::radians(degrees)
Quat QuatFromEuler(float x, float y, float z);
}

View File

@@ -142,7 +142,7 @@ namespace Nuake {
auto [transform, camera, parent] = view.get<TransformComponent, CameraComponent, ParentComponent>(e);
cam = camera.CameraInstance;
cam->Translation = transform.GetGlobalPosition();
cam->SetDirection(Vector3(Vector4(0, 0, -1, 0) * transform.GetGlobalTransform()));
cam->SetDirection(glm::rotate(glm::inverse(transform.GetGlobalRotation()), glm::vec3(1.0, 0.0, 0.0)));
camTransform = transform.GetGlobalTransform();
break;