WIP camera arm component
This commit is contained in:
parent
dee4e9acbd
commit
b0f28f98c5
|
@ -108,7 +108,7 @@ namespace Sandbox
|
|||
SHComponentManager::CreateComponentSparseSet<SHColliderComponent>();
|
||||
SHComponentManager::CreateComponentSparseSet<SHTransformComponent>();
|
||||
SHComponentManager::CreateComponentSparseSet<SHRenderable>();
|
||||
SHComponentManager::CreateComponentSparseSet<SHCameraComponent>();
|
||||
//SHComponentManager::CreateComponentSparseSet<SHCameraComponent>();
|
||||
|
||||
//TODO: REMOVE AFTER PRESENTATION
|
||||
//SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf");
|
||||
|
@ -119,9 +119,6 @@ namespace Sandbox
|
|||
//TODO: REMOVE AFTER PRESENTATION
|
||||
|
||||
|
||||
auto id = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
|
||||
auto id2 = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
|
||||
auto id3 = SHFamilyID<SHSystem>::GetID<SHGraphicsSystem>();
|
||||
|
||||
SHSystemManager::RegisterRoutine<SHAudioSystem, SHAudioSystem::AudioRoutine>();
|
||||
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHCameraArmComponent.h"
|
||||
|
||||
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
||||
SHCameraArmComponent::SHCameraArmComponent()
|
||||
:pitch(0.0f), yaw(0.0f), armLength(1.0f),rtMatrix(), dirty(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
SHMatrix const& SHCameraArmComponent::GetMatrix() const noexcept
|
||||
{
|
||||
return rtMatrix;
|
||||
}
|
||||
|
||||
float SHCameraArmComponent::GetPitch() const noexcept
|
||||
{
|
||||
return pitch;
|
||||
}
|
||||
|
||||
float SHCameraArmComponent::GetYaw() const noexcept
|
||||
{
|
||||
return yaw;
|
||||
}
|
||||
|
||||
float SHCameraArmComponent::GetArmLength() const noexcept
|
||||
{
|
||||
return armLength;
|
||||
}
|
||||
|
||||
void SHCameraArmComponent::SetPitch(float pitch) noexcept
|
||||
{
|
||||
this->pitch = pitch;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void SHCameraArmComponent::SetYaw(float yaw) noexcept
|
||||
{
|
||||
this->yaw = yaw;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
void SHCameraArmComponent::SetArmLength(float length) noexcept
|
||||
{
|
||||
this->armLength = length;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
}//namespace SHADE
|
||||
|
||||
|
||||
RTTR_REGISTRATION
|
||||
{
|
||||
using namespace SHADE;
|
||||
using namespace rttr;
|
||||
|
||||
registration::class_<SHCameraArmComponent>("Camera Arm Component")
|
||||
.property("Arm Pitch", &SHCameraArmComponent::GetPitch, &SHCameraArmComponent::SetPitch)
|
||||
.property("Arm Yaw", &SHCameraArmComponent::GetYaw, &SHCameraArmComponent::SetYaw)
|
||||
.property("Arm Length", &SHCameraArmComponent::GetArmLength, &SHCameraArmComponent::SetArmLength);
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include <rttr/registration>
|
||||
#include "ECS_Base/Components/SHComponent.h"
|
||||
#include "Math/SHMatrix.h"
|
||||
#include "SH_API.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
class SH_API SHCameraArmComponent final: public SHComponent
|
||||
{
|
||||
private:
|
||||
float pitch;
|
||||
float yaw;
|
||||
float armLength;
|
||||
|
||||
bool dirty;
|
||||
SHMatrix rtMatrix;
|
||||
|
||||
public:
|
||||
friend class SHCameraSystem;
|
||||
SHCameraArmComponent();
|
||||
virtual ~SHCameraArmComponent() = default;
|
||||
|
||||
|
||||
//Getters
|
||||
SHMatrix const& GetMatrix() const noexcept;
|
||||
float GetPitch() const noexcept;
|
||||
float GetYaw() const noexcept;
|
||||
float GetArmLength() const noexcept;
|
||||
|
||||
//Setters
|
||||
void SetPitch(float pitch) noexcept;
|
||||
void SetYaw(float yaw) noexcept;
|
||||
void SetArmLength(float length) noexcept;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
};
|
||||
|
||||
}//namespace SHADE
|
|
@ -41,7 +41,7 @@ namespace SHADE
|
|||
friend class SHCameraSystem;
|
||||
|
||||
SHCameraComponent();
|
||||
~SHCameraComponent();
|
||||
virtual ~SHCameraComponent();
|
||||
|
||||
|
||||
//Getters and setters.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHCameraDirector.h"
|
||||
#include "SHCameraComponent.h"
|
||||
#include "SHCameraArmComponent.h"
|
||||
#include "ECS_Base/Managers/SHComponentManager.h"
|
||||
#include "ECS_Base/SHECSMacros.h"
|
||||
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||
|
@ -48,6 +49,12 @@ namespace SHADE
|
|||
viewMatrix = camComponent->GetViewMatrix();
|
||||
projMatrix = camComponent->GetProjMatrix();
|
||||
}
|
||||
SHCameraArmComponent* armComponent = SHComponentManager::GetComponent_s<SHCameraArmComponent>(mainCameraEID);
|
||||
if (armComponent && camComponent)
|
||||
{
|
||||
SHMatrix tempView = armComponent->GetMatrix() * camComponent->GetViewMatrix();
|
||||
viewMatrix = tempView;
|
||||
}
|
||||
}
|
||||
|
||||
void SHCameraDirector::SetMainCamera(SHCameraComponent& camera) noexcept
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "SHpch.h"
|
||||
#include "SHCameraSystem.h"
|
||||
#include "SHCameraArmComponent.h"
|
||||
#include "Math/SHMathHelpers.h"
|
||||
#include "Input/SHInputManager.h"
|
||||
#include "Math/Vector/SHVec2.h"
|
||||
|
@ -122,6 +123,9 @@ namespace SHADE
|
|||
editorCamera.SetRoll(0.0f);
|
||||
editorCamera.movementSpeed = 2.0f;
|
||||
|
||||
SHComponentManager::CreateComponentSparseSet<SHCameraComponent>();
|
||||
SHComponentManager::CreateComponentSparseSet<SHCameraArmComponent>();
|
||||
|
||||
}
|
||||
|
||||
void SHCameraSystem::Exit(void)
|
||||
|
@ -134,6 +138,19 @@ namespace SHADE
|
|||
return &editorCamera;
|
||||
}
|
||||
|
||||
void SHCameraSystem::UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept
|
||||
{
|
||||
if (pivot.dirty)
|
||||
{
|
||||
pivot.rtMatrix = SHMatrix::RotateX(SHMath::DegreesToRadians(pivot.GetPitch()))
|
||||
* SHMatrix::RotateY(SHMath::DegreesToRadians(pivot.GetYaw()))
|
||||
* SHMatrix::Translate(SHVec3(0.0f , 0.0f, pivot.GetArmLength()));
|
||||
|
||||
pivot.rtMatrix = SHMatrix::Inverse(pivot.rtMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SHCameraSystem::UpdateCameraComponent(SHCameraComponent& camera) noexcept
|
||||
{
|
||||
if (SHComponentManager::HasComponent<SHTransformComponent>(camera.GetEID()) == true && &camera != &editorCamera)
|
||||
|
@ -241,6 +258,13 @@ namespace SHADE
|
|||
{
|
||||
SHCameraSystem* system = static_cast<SHCameraSystem*>(GetSystem());
|
||||
auto& dense = SHComponentManager::GetDense<SHCameraComponent>();
|
||||
auto& pivotDense = SHComponentManager::GetDense<SHCameraArmComponent>();
|
||||
|
||||
for (auto& pivot : pivotDense)
|
||||
{
|
||||
system->UpdatePivotArmComponent(pivot);
|
||||
}
|
||||
|
||||
for (auto& cam : dense)
|
||||
{
|
||||
system->UpdateCameraComponent(cam);
|
||||
|
@ -274,17 +298,17 @@ namespace SHADE
|
|||
}
|
||||
void SHCameraSystem::ClampCameraRotation(SHCameraComponent& camera) noexcept
|
||||
{
|
||||
constexpr float clampVal = 85.0f;
|
||||
|
||||
|
||||
|
||||
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);
|
||||
if (camera.pitch > clampVal)
|
||||
camera.SetPitch(clampVal);
|
||||
if (camera.pitch < -clampVal)
|
||||
camera.SetPitch(-clampVal);
|
||||
if (camera.roll > clampVal)
|
||||
camera.SetRoll(clampVal);
|
||||
if (camera.roll < -clampVal)
|
||||
camera.SetRoll(-clampVal);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
|
||||
class SHCameraArmComponent;
|
||||
|
||||
class SH_API SHCameraSystem final : public SHSystem
|
||||
{
|
||||
private:
|
||||
|
@ -39,7 +42,7 @@ namespace SHADE
|
|||
class SH_API CameraSystemUpdate final: public SHSystemRoutine
|
||||
{
|
||||
public:
|
||||
CameraSystemUpdate() : SHSystemRoutine("Camera System Update", false) {};
|
||||
CameraSystemUpdate() : SHSystemRoutine("Camera System Update", true) {};
|
||||
virtual void Execute(double dt)noexcept override final;
|
||||
};
|
||||
friend class CameraSystemUpdate;
|
||||
|
@ -51,10 +54,11 @@ namespace SHADE
|
|||
DirectorHandle GetDirector(size_t index) noexcept;
|
||||
void ClampCameraRotation(SHCameraComponent& camera) noexcept;
|
||||
void UpdateEditorCamera(double dt) noexcept;
|
||||
|
||||
protected:
|
||||
|
||||
void UpdateCameraComponent(SHCameraComponent& camera) noexcept;
|
||||
|
||||
void UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept;
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "Physics/Components/SHRigidBodyComponent.h"
|
||||
#include "Physics/Components/SHColliderComponent.h"
|
||||
#include "Camera/SHCameraComponent.h"
|
||||
#include "Camera/SHCameraArmComponent.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -103,6 +104,9 @@ namespace SHADE
|
|||
if (auto cameraComponent = SHComponentManager::GetComponent_s<SHCameraComponent>(eid))
|
||||
{
|
||||
DrawComponent(cameraComponent);
|
||||
}if (auto cameraArmComponent = SHComponentManager::GetComponent_s<SHCameraArmComponent>(eid))
|
||||
{
|
||||
DrawComponent(cameraArmComponent);
|
||||
}
|
||||
ImGui::Separator();
|
||||
// Render Scripts
|
||||
|
@ -113,6 +117,7 @@ namespace SHADE
|
|||
{
|
||||
DrawAddComponentButton<SHTransformComponent>(eid);
|
||||
DrawAddComponentButton<SHCameraComponent>(eid);
|
||||
DrawAddComponentButton<SHCameraArmComponent>(eid);
|
||||
|
||||
// Components that require Transforms
|
||||
|
||||
|
|
Loading…
Reference in New Issue