Merge pull request #21 from antopilo/feature/NK-93-player-controller-ignoring-transform

Feature/nk 93 player controller ignoring transform
This commit is contained in:
Antoine Pilote
2023-07-10 00:01:24 -04:00
committed by GitHub
5 changed files with 21 additions and 14 deletions

View File

@@ -4,10 +4,10 @@ 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)));
}
Vector3 Nuake::QuatToDirection(const Quat& quat)
{
return glm::rotate(glm::inverse(quat), glm::vec3(1.0, 0.0, 0.0));
}

View File

@@ -17,6 +17,8 @@ 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);
Vector3 QuatToDirection(const Quat& quat);
}

View File

@@ -13,8 +13,9 @@ namespace Nuake
class CharacterController
{
public:
Vector3 Position = Vector3(0, 0, 0);
Quat Rotation = Quat(1, 0, 0, 0);
Entity Owner;
bool IsOnGround = false;
@@ -25,8 +26,6 @@ namespace Nuake
float Friction = 0.5f;
Ref<PhysicShape> Shape;
//bool m_onJumpableGround; // A bit lower contact than just onGround
float m_bottomYOffset;
float m_bottomRoundedRegionYOffset;

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(Vector3(Vector4(0, 0, -1, 0) * transform.GetGlobalTransform()));
camTransform = transform.GetGlobalTransform();
cam->Translation = transform.GetGlobalPosition();
const Vector3& forward = QuatToDirection(transform.GetGlobalRotation());
cam->SetDirection(forward);
camTransform = transform.GetGlobalTransform();
break;
}
}

View File

@@ -286,10 +286,12 @@ namespace Nuake
const auto& capsuleColliderComponent = entity.GetComponent<CapsuleColliderComponent>();
auto& capsule = capsuleColliderComponent.Capsule;
float friction = characterControllerComponent.Friction;
float maxSlopeAngle = characterControllerComponent.MaxSlopeAngle;
const float friction = characterControllerComponent.Friction;
const float maxSlopeAngle = characterControllerComponent.MaxSlopeAngle;
auto characterController = CreateRef<Physics::CharacterController>(capsule, friction, maxSlopeAngle);
characterController->SetEntity(entity); // Used to link back to the entity
characterController->Position = transformComponent.GetGlobalPosition();
characterController->Rotation = transformComponent.GetGlobalRotation();
characterControllerComponent.CharacterController = characterController;
PhysicsManager::Get().RegisterCharacterController(characterControllerComponent.CharacterController);