Set up the CameraDirector creation and setting of main camera
This commit is contained in:
parent
31ad8b8c87
commit
267ad5f8c6
|
@ -1,7 +1,8 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHCameraComponent.h"
|
||||
#include "ECS_Base/Managers/SHComponentManager.h"
|
||||
|
||||
#include "SHCameraSystem.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -128,4 +129,12 @@ namespace SHADE
|
|||
return projMatrix;
|
||||
}
|
||||
|
||||
void SHCameraComponent::SetMainCamera(size_t directorCameraIndex) noexcept
|
||||
{
|
||||
auto system = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||
system->GetDirector(directorCameraIndex)->SetMainCamera(*this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -70,6 +70,8 @@ namespace SHADE
|
|||
const SHMatrix& GetViewMatrix() const noexcept;
|
||||
const SHMatrix& GetProjMatrix() const noexcept;
|
||||
|
||||
void SetMainCamera(size_t cameraDirectorIndex = 0) noexcept;
|
||||
|
||||
|
||||
float movementSpeed;
|
||||
SHVec3 turnSpeed;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "SHCameraComponent.h"
|
||||
#include "ECS_Base/Managers/SHComponentManager.h"
|
||||
#include "ECS_Base/SHECSMacros.h"
|
||||
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||
#include "Tools/SHLog.h"
|
||||
|
||||
namespace SHADE
|
||||
|
@ -42,9 +43,18 @@ namespace SHADE
|
|||
viewMatrix = camComponent->GetViewMatrix();
|
||||
projMatrix = camComponent->GetProjMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SHCameraDirector::SetMainCamera(SHCameraComponent& camera) noexcept
|
||||
{
|
||||
if (SHEntityManager::IsValidEID(camera.GetEID()) == false)
|
||||
{
|
||||
SHLOG_WARNING("Camera Director Warning: Attempting to set an invalid entity as main camera.")
|
||||
return;
|
||||
}
|
||||
mainCameraEID = camera.GetEID();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,10 +3,15 @@
|
|||
#include "SH_API.h"
|
||||
#include "ECS_Base/Entity/SHEntity.h"
|
||||
#include "Math/SHMatrix.h"
|
||||
#include "Resource/Handle.h"
|
||||
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SHCameraComponent;
|
||||
|
||||
|
||||
|
||||
class SH_API SHCameraDirector
|
||||
{
|
||||
public:
|
||||
|
@ -21,6 +26,7 @@ namespace SHADE
|
|||
SHMatrix GetProjMatrix() const noexcept;
|
||||
SHMatrix GetVPMatrix() const noexcept;
|
||||
void UpdateMatrix() noexcept;
|
||||
void SetMainCamera(SHCameraComponent& cam) noexcept;
|
||||
|
||||
|
||||
private:
|
||||
|
@ -32,5 +38,6 @@ namespace SHADE
|
|||
|
||||
};
|
||||
|
||||
typedef Handle<SHCameraDirector> DirectorHandle;
|
||||
|
||||
}
|
||||
|
|
|
@ -187,11 +187,23 @@ namespace SHADE
|
|||
}
|
||||
|
||||
|
||||
Handle<SHCameraDirector> SHCameraSystem::CreateDirector() noexcept
|
||||
DirectorHandle SHCameraSystem::CreateDirector() noexcept
|
||||
{
|
||||
auto handle = directorLibrary.Create();
|
||||
directorHandleList.emplace_back(handle);
|
||||
return handle;
|
||||
}
|
||||
|
||||
DirectorHandle SHCameraSystem::GetDirector(size_t index) noexcept
|
||||
{
|
||||
if (index < directorHandleList.size())
|
||||
{
|
||||
return directorHandleList[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
return CreateDirector();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#include "ECS_Base/System/SHSystemRoutine.h"
|
||||
#include "Resource/ResourceLibrary.h"
|
||||
#include "SHCameraDirector.h"
|
||||
#include "Resource/Handle.h"
|
||||
#include "SH_API.h"
|
||||
|
||||
namespace SHADE
|
||||
|
@ -18,7 +17,7 @@ namespace SHADE
|
|||
SHCameraComponent editorCamera;
|
||||
|
||||
ResourceLibrary<SHCameraDirector> directorLibrary;
|
||||
std::vector<Handle<SHCameraDirector>> directorHandleList;
|
||||
std::vector<DirectorHandle> directorHandleList;
|
||||
|
||||
public:
|
||||
SHCameraSystem(void) = default;
|
||||
|
@ -48,7 +47,8 @@ namespace SHADE
|
|||
|
||||
SHCameraComponent* GetEditorCamera (void) noexcept;
|
||||
void GetCameraAxis(SHCameraComponent const& camera, SHVec3& forward, SHVec3& right, SHVec3& up) const noexcept;
|
||||
Handle<SHCameraDirector> CreateDirector() noexcept;
|
||||
DirectorHandle CreateDirector() noexcept;
|
||||
DirectorHandle GetDirector(size_t index) noexcept;
|
||||
protected:
|
||||
|
||||
void UpdateCameraComponent(SHCameraComponent& camera) noexcept;
|
||||
|
|
Loading…
Reference in New Issue