Added clamping of camera, and copying of position and rotation from transform
This commit is contained in:
parent
7e04bee8d6
commit
6039ec534d
|
@ -3,6 +3,7 @@
|
|||
#include "ECS_Base/Managers/SHComponentManager.h"
|
||||
#include "SHCameraSystem.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "Math/Transform/SHTransformComponent.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -23,33 +24,69 @@ namespace SHADE
|
|||
void SHCameraComponent::SetYaw(float yaw) noexcept
|
||||
{
|
||||
this->yaw = yaw;
|
||||
if (SHComponentManager::HasComponent<SHTransformComponent>(GetEID()))
|
||||
{
|
||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(GetEID());
|
||||
SHVec3 rotation = transform->GetWorldRotation();
|
||||
transform->SetWorldRotation(SHVec3{rotation.x,yaw, rotation.z});
|
||||
}
|
||||
dirtyView = true;
|
||||
}
|
||||
|
||||
void SHCameraComponent::SetPitch(float pitch) noexcept
|
||||
{
|
||||
this->pitch = pitch;
|
||||
if (SHComponentManager::HasComponent<SHTransformComponent>(GetEID()))
|
||||
{
|
||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(GetEID());
|
||||
SHVec3 rotation = transform->GetWorldRotation();
|
||||
transform->SetWorldRotation(SHVec3{ pitch,rotation.y, rotation.z });
|
||||
}
|
||||
dirtyView = true;
|
||||
}
|
||||
|
||||
void SHCameraComponent::SetRoll(float roll) noexcept
|
||||
{
|
||||
this->roll = roll;
|
||||
if (SHComponentManager::HasComponent<SHTransformComponent>(GetEID()))
|
||||
{
|
||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(GetEID());
|
||||
SHVec3 rotation = transform->GetWorldRotation();
|
||||
transform->SetWorldRotation(SHVec3{ rotation.x,rotation.y, roll});
|
||||
}
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPositionX(float x) noexcept
|
||||
{
|
||||
position.x = x;
|
||||
if (SHComponentManager::HasComponent<SHTransformComponent>(GetEID()))
|
||||
{
|
||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(GetEID());
|
||||
SHVec3 position = transform->GetWorldPosition();
|
||||
transform->SetWorldRotation(SHVec3{ x,position.y, position.z});
|
||||
}
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPositionY(float y) noexcept
|
||||
{
|
||||
position.y = y;
|
||||
if (SHComponentManager::HasComponent<SHTransformComponent>(GetEID()))
|
||||
{
|
||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(GetEID());
|
||||
SHVec3 position = transform->GetWorldPosition();
|
||||
transform->SetWorldRotation(SHVec3{ position.x,y, position.z });
|
||||
}
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPositionZ(float z) noexcept
|
||||
{
|
||||
position.z = z;
|
||||
if (SHComponentManager::HasComponent<SHTransformComponent>(GetEID()))
|
||||
{
|
||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(GetEID());
|
||||
SHVec3 position = transform->GetWorldPosition();
|
||||
transform->SetWorldRotation(SHVec3{ position.x,position.y, z });
|
||||
}
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPosition(float x,float y, float z) noexcept
|
||||
|
@ -57,11 +94,23 @@ namespace SHADE
|
|||
position.x = x;
|
||||
position.y = y;
|
||||
position.z = z;
|
||||
if (SHComponentManager::HasComponent<SHTransformComponent>(GetEID()))
|
||||
{
|
||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(GetEID());
|
||||
SHVec3 position = transform->GetWorldPosition();
|
||||
transform->SetWorldRotation(SHVec3{ x,y, z });
|
||||
}
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPosition(SHVec3& pos) noexcept
|
||||
{
|
||||
this->position = pos;
|
||||
if (SHComponentManager::HasComponent<SHTransformComponent>(GetEID()))
|
||||
{
|
||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(GetEID());
|
||||
SHVec3 position = transform->GetWorldPosition();
|
||||
transform->SetWorldRotation(pos);
|
||||
}
|
||||
dirtyView = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "Input/SHInputManager.h"
|
||||
#include "Math/Vector/SHVec2.h"
|
||||
#include "ECS_Base/Managers/SHComponentManager.h"
|
||||
|
||||
#include "Math/Transform/SHTransformComponent.h"
|
||||
|
||||
|
||||
namespace SHADE
|
||||
|
@ -84,10 +84,25 @@ namespace SHADE
|
|||
|
||||
void SHCameraSystem::UpdateCameraComponent(SHCameraComponent& camera) noexcept
|
||||
{
|
||||
if (SHComponentManager::HasComponent<SHTransformComponent>(camera.GetEID()) == true)
|
||||
{
|
||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(camera.GetEID());
|
||||
SHVec3 rotation = transform->GetWorldRotation();
|
||||
camera.pitch = rotation.x;
|
||||
camera.yaw = rotation.y;
|
||||
camera.roll = rotation.z;
|
||||
camera.position = transform->GetWorldPosition();
|
||||
}
|
||||
|
||||
|
||||
if (camera.dirtyView)
|
||||
{
|
||||
|
||||
SHVec3 view, right, UP;
|
||||
|
||||
|
||||
ClampCameraRotation(camera);
|
||||
|
||||
GetCameraAxis(camera, view, right, UP);
|
||||
|
||||
camera.viewMatrix = SHMatrix::Identity;
|
||||
|
@ -205,5 +220,17 @@ namespace SHADE
|
|||
return CreateDirector();
|
||||
}
|
||||
}
|
||||
void SHCameraSystem::ClampCameraRotation(SHCameraComponent& camera) noexcept
|
||||
{
|
||||
if (camera.pitch > 85)
|
||||
camera.SetPitch(85);
|
||||
if (camera.pitch < -85)
|
||||
camera.SetPitch(-85);
|
||||
if (camera.roll > 85)
|
||||
camera.SetRoll(85);
|
||||
if (camera.roll < -85)
|
||||
camera.SetRoll(-85);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ namespace SHADE
|
|||
void GetCameraAxis(SHCameraComponent const& camera, SHVec3& forward, SHVec3& right, SHVec3& up) const noexcept;
|
||||
DirectorHandle CreateDirector() noexcept;
|
||||
DirectorHandle GetDirector(size_t index) noexcept;
|
||||
void ClampCameraRotation(SHCameraComponent& camera) noexcept;
|
||||
|
||||
protected:
|
||||
|
||||
void UpdateCameraComponent(SHCameraComponent& camera) noexcept;
|
||||
|
|
Loading…
Reference in New Issue