Merge pull request #122 from SHADE-DP/SP3-141-Camera-System
Sp3 141 camera system Fixed weird camera movement, Added clamping for camera pitch. Added RTTR reflection for camera. Editor inspector now draws camera component.
This commit is contained in:
commit
41ef49a8d3
|
@ -4,6 +4,7 @@
|
|||
#include "SHCameraSystem.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "Math/Transform/SHTransformComponent.h"
|
||||
#include "Math/SHMath.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -28,7 +29,7 @@ namespace SHADE
|
|||
{
|
||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(GetEID());
|
||||
SHVec3 rotation = transform->GetWorldRotation();
|
||||
transform->SetWorldRotation(SHVec3{rotation.x,yaw, rotation.z});
|
||||
transform->SetWorldRotation(SHVec3{rotation.x,SHMath::DegreesToRadians(yaw), rotation.z});
|
||||
}
|
||||
dirtyView = true;
|
||||
}
|
||||
|
@ -40,7 +41,7 @@ namespace SHADE
|
|||
{
|
||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(GetEID());
|
||||
SHVec3 rotation = transform->GetWorldRotation();
|
||||
transform->SetWorldRotation(SHVec3{ pitch,rotation.y, rotation.z });
|
||||
transform->SetWorldRotation(SHVec3{ SHMath::DegreesToRadians(pitch),rotation.y, rotation.z });
|
||||
}
|
||||
dirtyView = true;
|
||||
}
|
||||
|
@ -52,7 +53,7 @@ namespace SHADE
|
|||
{
|
||||
auto transform = SHComponentManager::GetComponent<SHTransformComponent>(GetEID());
|
||||
SHVec3 rotation = transform->GetWorldRotation();
|
||||
transform->SetWorldRotation(SHVec3{ rotation.x,rotation.y, roll});
|
||||
transform->SetWorldRotation(SHVec3{ rotation.x,rotation.y, SHMath::DegreesToRadians(roll)});
|
||||
}
|
||||
dirtyView = true;
|
||||
}
|
||||
|
@ -102,7 +103,7 @@ namespace SHADE
|
|||
}
|
||||
dirtyView = true;
|
||||
}
|
||||
void SHCameraComponent::SetPosition(SHVec3& pos) noexcept
|
||||
void SHCameraComponent::SetPosition(SHVec3 pos) noexcept
|
||||
{
|
||||
this->position = pos;
|
||||
if (SHComponentManager::HasComponent<SHTransformComponent>(GetEID()))
|
||||
|
@ -145,6 +146,17 @@ namespace SHADE
|
|||
dirtyProj = true;
|
||||
}
|
||||
|
||||
void SHCameraComponent::SetIsPerspective(bool persp) noexcept
|
||||
{
|
||||
this->perspProj = persp;
|
||||
dirtyProj = true;
|
||||
}
|
||||
|
||||
SHVec3 SHCameraComponent::GetPosition() const noexcept
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
float SHCameraComponent::GetYaw() const noexcept
|
||||
{
|
||||
return yaw;
|
||||
|
@ -158,6 +170,27 @@ namespace SHADE
|
|||
{
|
||||
return roll;
|
||||
}
|
||||
|
||||
float SHCameraComponent::GetWidth() const noexcept
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
float SHCameraComponent::GetHeight() const noexcept
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
float SHCameraComponent::GetNear() const noexcept
|
||||
{
|
||||
return zNear;
|
||||
}
|
||||
|
||||
float SHCameraComponent::GetFar() const noexcept
|
||||
{
|
||||
return zFar;
|
||||
}
|
||||
|
||||
float SHCameraComponent::GetAspectRatio() const noexcept
|
||||
{
|
||||
return width/height;
|
||||
|
@ -168,6 +201,11 @@ namespace SHADE
|
|||
return fov;
|
||||
}
|
||||
|
||||
bool SHCameraComponent::GetIsPerspective() const noexcept
|
||||
{
|
||||
return perspProj;
|
||||
}
|
||||
|
||||
const SHMatrix& SHCameraComponent::GetViewMatrix() const noexcept
|
||||
{
|
||||
return viewMatrix;
|
||||
|
@ -178,12 +216,32 @@ namespace SHADE
|
|||
return projMatrix;
|
||||
}
|
||||
|
||||
void SHCameraComponent::SetMainCamera(size_t directorCameraIndex) noexcept
|
||||
{
|
||||
auto system = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||
system->GetDirector(directorCameraIndex)->SetMainCamera(*this);
|
||||
}
|
||||
//void SHCameraComponent::SetMainCamera(size_t directorCameraIndex) noexcept
|
||||
//{
|
||||
// auto system = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||
// system->GetDirector(directorCameraIndex)->SetMainCamera(*this);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}//namespace SHADE
|
||||
|
||||
|
||||
RTTR_REGISTRATION
|
||||
{
|
||||
using namespace SHADE;
|
||||
using namespace rttr;
|
||||
|
||||
registration::class_<SHCameraComponent>("Camera Component")
|
||||
.property("Position", &SHCameraComponent::GetPosition, select_overload<void(SHVec3)>(&SHCameraComponent::SetPosition))
|
||||
.property("Pitch", &SHCameraComponent::GetPitch, &SHCameraComponent::SetPitch)
|
||||
.property("Yaw", &SHCameraComponent::GetYaw, &SHCameraComponent::SetYaw)
|
||||
.property("Roll", &SHCameraComponent::GetRoll, &SHCameraComponent::SetRoll)
|
||||
.property("Width", &SHCameraComponent::GetWidth, &SHCameraComponent::SetWidth)
|
||||
.property("Height", &SHCameraComponent::GetHeight, &SHCameraComponent::SetHeight)
|
||||
.property("Near", &SHCameraComponent::GetNear, &SHCameraComponent::SetNear)
|
||||
.property("Far", &SHCameraComponent::GetFar, &SHCameraComponent::SetFar)
|
||||
.property("Perspective", &SHCameraComponent::GetIsPerspective, &SHCameraComponent::SetIsPerspective);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <rttr/registration>
|
||||
|
||||
#include "ECS_Base/Components/SHComponent.h"
|
||||
#include "Math/Vector/SHVec3.h"
|
||||
#include "Math/SHMatrix.h"
|
||||
|
@ -50,37 +52,44 @@ namespace SHADE
|
|||
void SetPositionY(float y) noexcept;
|
||||
void SetPositionZ(float z) noexcept;
|
||||
void SetPosition(float x, float y, float z) noexcept;
|
||||
void SetPosition(SHVec3& pos) noexcept;
|
||||
void SetPosition(SHVec3 pos) noexcept;
|
||||
|
||||
void SetWidth(float width) noexcept;
|
||||
void SetHeight(float height) noexcept;
|
||||
void SetNear(float znear) noexcept;
|
||||
void SetFar(float zfar) noexcept;
|
||||
void SetFOV(float fov) noexcept;
|
||||
void SetIsPerspective(bool persp) noexcept;
|
||||
|
||||
|
||||
|
||||
SHVec3 GetPosition() const noexcept;
|
||||
float GetYaw() const noexcept;
|
||||
float GetPitch() const noexcept;
|
||||
float GetRoll() const noexcept;
|
||||
|
||||
float GetWidth() const noexcept;
|
||||
float GetHeight() const noexcept;
|
||||
float GetNear() const noexcept;
|
||||
float GetFar() const noexcept;
|
||||
|
||||
float GetAspectRatio() const noexcept;
|
||||
float GetFOV() const noexcept;
|
||||
bool GetIsPerspective() const noexcept;
|
||||
|
||||
const SHMatrix& GetViewMatrix() const noexcept;
|
||||
const SHMatrix& GetProjMatrix() const noexcept;
|
||||
|
||||
void SetMainCamera(size_t cameraDirectorIndex = 0) noexcept;
|
||||
//void SetMainCamera(size_t cameraDirectorIndex = 0) noexcept;
|
||||
|
||||
|
||||
float movementSpeed;
|
||||
SHVec3 turnSpeed;
|
||||
|
||||
RTTR_ENABLE()
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ namespace SHADE
|
|||
SHVec3 view, right, UP;
|
||||
|
||||
|
||||
//ClampCameraRotation(camera);
|
||||
ClampCameraRotation(camera);
|
||||
|
||||
GetCameraAxis(camera, view, right, UP);
|
||||
|
||||
|
@ -221,8 +221,8 @@ namespace SHADE
|
|||
SHVec3 up = { 0.0f,1.0f,0.0f };
|
||||
|
||||
|
||||
target = SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch));
|
||||
target = SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw));
|
||||
target =SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch));
|
||||
target += camera.position;
|
||||
////SHVec3::RotateZ(target, SHMath::DegreesToRadians(camera.roll));
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "AudioSystem/SHAudioSystem.h"
|
||||
#include "Physics/Components/SHRigidBodyComponent.h"
|
||||
#include "Physics/Components/SHColliderComponent.h"
|
||||
#include "Camera/SHCameraComponent.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -99,6 +100,10 @@ namespace SHADE
|
|||
{
|
||||
DrawComponent(rigidbodyComponent);
|
||||
}
|
||||
if (auto cameraComponent = SHComponentManager::GetComponent_s<SHCameraComponent>(eid))
|
||||
{
|
||||
DrawComponent(cameraComponent);
|
||||
}
|
||||
ImGui::Separator();
|
||||
// Render Scripts
|
||||
SHScriptEngine* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
|
||||
|
@ -107,12 +112,14 @@ namespace SHADE
|
|||
if(ImGui::BeginMenu(std::format("{} Add Component", ICON_MD_LIBRARY_ADD).data()))
|
||||
{
|
||||
DrawAddComponentButton<SHTransformComponent>(eid);
|
||||
DrawAddComponentButton<SHCameraComponent>(eid);
|
||||
|
||||
// Components that require Transforms
|
||||
|
||||
DrawAddComponentWithEnforcedComponentButton<SHRenderable, SHTransformComponent>(eid);
|
||||
DrawAddComponentWithEnforcedComponentButton<SHRigidBodyComponent, SHTransformComponent>(eid);
|
||||
DrawAddComponentWithEnforcedComponentButton<SHColliderComponent, SHTransformComponent>(eid);
|
||||
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue