Merge branch 'main' into SP3-4-editor_fix
This commit is contained in:
commit
125ce7b564
|
@ -0,0 +1,48 @@
|
||||||
|
[Window][MainStatusBar]
|
||||||
|
Pos=0,1389
|
||||||
|
Size=2547,20
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][SHEditorMenuBar]
|
||||||
|
Pos=0,48
|
||||||
|
Size=2547,1341
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][Hierarchy Panel]
|
||||||
|
Pos=0,172
|
||||||
|
Size=571,1217
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000004,0
|
||||||
|
|
||||||
|
[Window][Debug##Default]
|
||||||
|
Pos=60,60
|
||||||
|
Size=400,400
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][Inspector]
|
||||||
|
Pos=2276,48
|
||||||
|
Size=271,1341
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000006,0
|
||||||
|
|
||||||
|
[Window][Profiler]
|
||||||
|
Pos=0,48
|
||||||
|
Size=571,122
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000003,0
|
||||||
|
|
||||||
|
[Window][Viewport]
|
||||||
|
Pos=573,48
|
||||||
|
Size=1701,1341
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x00000002,0
|
||||||
|
|
||||||
|
[Docking][Data]
|
||||||
|
DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=8,79 Size=2547,1341 Split=X
|
||||||
|
DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1992,1036 Split=X
|
||||||
|
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=571,1036 Split=Y Selected=0x1E6EB881
|
||||||
|
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,94 Selected=0x1E6EB881
|
||||||
|
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=225,940 Selected=0xE096E5AE
|
||||||
|
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1074,1036 CentralNode=1 Selected=0x13926F0B
|
||||||
|
DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=271,1036 Selected=0xE7039252
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "Input/SHInputManager.h"
|
#include "Input/SHInputManager.h"
|
||||||
#include "FRC/SHFramerateController.h"
|
#include "FRC/SHFramerateController.h"
|
||||||
#include "AudioSystem/SHAudioSystem.h"
|
#include "AudioSystem/SHAudioSystem.h"
|
||||||
|
#include "Camera/SHCameraSystem.h"
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||||
|
@ -67,6 +68,7 @@ namespace Sandbox
|
||||||
SHSystemManager::CreateSystem<SHTransformSystem>();
|
SHSystemManager::CreateSystem<SHTransformSystem>();
|
||||||
SHGraphicsSystem* graphicsSystem = static_cast<SHGraphicsSystem*>(SHSystemManager::GetSystem<SHGraphicsSystem>());
|
SHGraphicsSystem* graphicsSystem = static_cast<SHGraphicsSystem*>(SHSystemManager::GetSystem<SHGraphicsSystem>());
|
||||||
SHSystemManager::CreateSystem<SHAudioSystem>();
|
SHSystemManager::CreateSystem<SHAudioSystem>();
|
||||||
|
SHSystemManager::CreateSystem<SHCameraSystem>();
|
||||||
|
|
||||||
#ifdef SHEDITOR
|
#ifdef SHEDITOR
|
||||||
SDL_Init(SDL_INIT_VIDEO);
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
|
@ -89,6 +91,8 @@ namespace Sandbox
|
||||||
|
|
||||||
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BatcherDispatcherRoutine>();
|
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BatcherDispatcherRoutine>();
|
||||||
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BeginRoutine>();
|
SHSystemManager::RegisterRoutine<SHGraphicsSystem, SHGraphicsSystem::BeginRoutine>();
|
||||||
|
|
||||||
|
SHSystemManager::RegisterRoutine<SHCameraSystem, SHCameraSystem::EditorCameraUpdate>();
|
||||||
|
|
||||||
#ifdef SHEDITOR
|
#ifdef SHEDITOR
|
||||||
SHSystemManager::RegisterRoutine<SHEditor, SHEditor::EditorRoutine>();
|
SHSystemManager::RegisterRoutine<SHEditor, SHEditor::EditorRoutine>();
|
||||||
|
@ -101,6 +105,7 @@ namespace Sandbox
|
||||||
SHComponentManager::CreateComponentSparseSet<SHColliderComponent>();
|
SHComponentManager::CreateComponentSparseSet<SHColliderComponent>();
|
||||||
SHComponentManager::CreateComponentSparseSet<SHTransformComponent>();
|
SHComponentManager::CreateComponentSparseSet<SHTransformComponent>();
|
||||||
SHComponentManager::CreateComponentSparseSet<SHRenderable>();
|
SHComponentManager::CreateComponentSparseSet<SHRenderable>();
|
||||||
|
SHComponentManager::CreateComponentSparseSet<SHCameraComponent>();
|
||||||
|
|
||||||
//TODO: REMOVE AFTER PRESENTATION
|
//TODO: REMOVE AFTER PRESENTATION
|
||||||
//SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf");
|
//SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf");
|
||||||
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "SHCameraComponent.h"
|
||||||
|
#include "ECS_Base/Managers/SHComponentManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
SHCameraComponent::SHCameraComponent()
|
||||||
|
:yaw(0.0f), pitch(0.0f), roll(0.0f)
|
||||||
|
, width(1920.0f), height(1080.0f), zNear(0.01f), zFar(10000.0f), fov(90.0f), movementSpeed(1.0f), turnSpeed(1.0f)
|
||||||
|
, perspProj(true), dirtyView(true), dirtyProj(true)
|
||||||
|
, viewMatrix(), projMatrix()
|
||||||
|
, position()
|
||||||
|
{
|
||||||
|
ComponentFamily::GetID<SHCameraComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
SHCameraComponent::~SHCameraComponent()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHCameraComponent::SetYaw(float yaw) noexcept
|
||||||
|
{
|
||||||
|
this->yaw = yaw;
|
||||||
|
dirtyView = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHCameraComponent::SetPitch(float pitch) noexcept
|
||||||
|
{
|
||||||
|
this->pitch = pitch;
|
||||||
|
dirtyView = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHCameraComponent::SetRoll(float roll) noexcept
|
||||||
|
{
|
||||||
|
this->roll = roll;
|
||||||
|
dirtyView = true;
|
||||||
|
}
|
||||||
|
void SHCameraComponent::SetPositionX(float x) noexcept
|
||||||
|
{
|
||||||
|
position.x = x;
|
||||||
|
dirtyView = true;
|
||||||
|
}
|
||||||
|
void SHCameraComponent::SetPositionY(float y) noexcept
|
||||||
|
{
|
||||||
|
position.y = y;
|
||||||
|
dirtyView = true;
|
||||||
|
}
|
||||||
|
void SHCameraComponent::SetPositionZ(float z) noexcept
|
||||||
|
{
|
||||||
|
position.z = z;
|
||||||
|
dirtyView = true;
|
||||||
|
}
|
||||||
|
void SHCameraComponent::SetPosition(float x,float y, float z) noexcept
|
||||||
|
{
|
||||||
|
position.x = x;
|
||||||
|
position.y = y;
|
||||||
|
position.z = z;
|
||||||
|
dirtyView = true;
|
||||||
|
}
|
||||||
|
void SHCameraComponent::SetPosition(SHVec3& pos) noexcept
|
||||||
|
{
|
||||||
|
this->position = pos;
|
||||||
|
dirtyView = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHCameraComponent::SetWidth(float width) noexcept
|
||||||
|
{
|
||||||
|
this->width = width;
|
||||||
|
dirtyProj = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SHCameraComponent::SetHeight(float height) noexcept
|
||||||
|
{
|
||||||
|
this->height = height;
|
||||||
|
dirtyProj = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHCameraComponent::SetNear(float znear) noexcept
|
||||||
|
{
|
||||||
|
this->zNear = znear;
|
||||||
|
dirtyProj = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHCameraComponent::SetFar(float zFar) noexcept
|
||||||
|
{
|
||||||
|
this->zFar = zFar;
|
||||||
|
dirtyProj = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHCameraComponent::SetFOV(float fov) noexcept
|
||||||
|
{
|
||||||
|
this->fov = fov;
|
||||||
|
dirtyProj = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float SHCameraComponent::GetYaw() const noexcept
|
||||||
|
{
|
||||||
|
return yaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
float SHCameraComponent::GetPitch() const noexcept
|
||||||
|
{
|
||||||
|
return pitch;
|
||||||
|
}
|
||||||
|
float SHCameraComponent::GetRoll() const noexcept
|
||||||
|
{
|
||||||
|
return roll;
|
||||||
|
}
|
||||||
|
float SHCameraComponent::GetAspectRatio() const noexcept
|
||||||
|
{
|
||||||
|
return width/height;
|
||||||
|
}
|
||||||
|
|
||||||
|
float SHCameraComponent::GetFOV() const noexcept
|
||||||
|
{
|
||||||
|
return fov;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SHMatrix& SHCameraComponent::GetViewMatrix() const noexcept
|
||||||
|
{
|
||||||
|
return viewMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SHMatrix& SHCameraComponent::GetProjMatrix() const noexcept
|
||||||
|
{
|
||||||
|
return projMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ECS_Base/Components/SHComponent.h"
|
||||||
|
#include "Math/Vector/SHVec3.h"
|
||||||
|
#include "Math/SHMatrix.h"
|
||||||
|
#include "SH_API.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
|
||||||
|
class SH_API SHCameraComponent final : public SHComponent
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
float yaw;
|
||||||
|
float pitch;
|
||||||
|
float roll;
|
||||||
|
|
||||||
|
float width;
|
||||||
|
float height;
|
||||||
|
float zNear;
|
||||||
|
float zFar;
|
||||||
|
float fov;
|
||||||
|
|
||||||
|
bool dirtyView;
|
||||||
|
bool dirtyProj;
|
||||||
|
|
||||||
|
|
||||||
|
SHMatrix viewMatrix;
|
||||||
|
SHMatrix projMatrix;
|
||||||
|
SHVec3 position;
|
||||||
|
|
||||||
|
bool perspProj;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
friend class SHCameraSystem;
|
||||||
|
|
||||||
|
SHCameraComponent();
|
||||||
|
~SHCameraComponent();
|
||||||
|
|
||||||
|
|
||||||
|
//Getters and setters.
|
||||||
|
void SetYaw(float yaw) noexcept;
|
||||||
|
void SetPitch(float pitch) noexcept;
|
||||||
|
void SetRoll(float roll) noexcept;
|
||||||
|
void SetPositionX(float x) noexcept;
|
||||||
|
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 SetWidth(float width) noexcept;
|
||||||
|
void SetHeight(float height) noexcept;
|
||||||
|
void SetNear(float znear) noexcept;
|
||||||
|
void SetFar(float zfar) noexcept;
|
||||||
|
void SetFOV(float fov) noexcept;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
float GetYaw() const noexcept;
|
||||||
|
float GetPitch() const noexcept;
|
||||||
|
float GetRoll() const noexcept;
|
||||||
|
|
||||||
|
float GetAspectRatio() const noexcept;
|
||||||
|
float GetFOV() const noexcept;
|
||||||
|
|
||||||
|
const SHMatrix& GetViewMatrix() const noexcept;
|
||||||
|
const SHMatrix& GetProjMatrix() const noexcept;
|
||||||
|
|
||||||
|
|
||||||
|
float movementSpeed;
|
||||||
|
SHVec3 turnSpeed;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,179 @@
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "SHCameraSystem.h"
|
||||||
|
#include "Math/SHMathHelpers.h"
|
||||||
|
#include "Input/SHInputManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
|
||||||
|
void SHCameraSystem::EditorCameraUpdate::Execute(double dt) noexcept
|
||||||
|
{
|
||||||
|
SHCameraSystem* system = static_cast<SHCameraSystem*>(GetSystem());
|
||||||
|
auto& camera = system->editorCamera;
|
||||||
|
SHVec3 target{ 0.0f,0.0f,-1.0f };
|
||||||
|
SHVec3 up = { 0.0f,1.0f,0.0f };
|
||||||
|
|
||||||
|
|
||||||
|
SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw));
|
||||||
|
SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch));
|
||||||
|
target += camera.position;
|
||||||
|
////SHVec3::RotateZ(target, SHMath::DegreesToRadians(camera.roll));
|
||||||
|
|
||||||
|
//target = SHVec3::Normalise(target);
|
||||||
|
|
||||||
|
SHVec3::RotateZ(up, camera.roll);
|
||||||
|
up = SHVec3::Normalise(up);
|
||||||
|
|
||||||
|
|
||||||
|
SHVec3 view = target - camera.position; view = SHVec3::Normalise(view);
|
||||||
|
SHVec3 right = SHVec3::Cross(view, up); right = SHVec3::Normalise(right);
|
||||||
|
const SHVec3 UP = SHVec3::Cross(view, right);
|
||||||
|
|
||||||
|
|
||||||
|
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::A))
|
||||||
|
{
|
||||||
|
system->editorCamera.position -= right * dt * camera.movementSpeed;
|
||||||
|
system->editorCamera.dirtyView = true;
|
||||||
|
}
|
||||||
|
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::D))
|
||||||
|
{
|
||||||
|
system->editorCamera.position += right * dt * camera.movementSpeed;
|
||||||
|
system->editorCamera.dirtyView = true;
|
||||||
|
}
|
||||||
|
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::W))
|
||||||
|
{
|
||||||
|
system->editorCamera.position += view * dt * camera.movementSpeed;
|
||||||
|
system->editorCamera.dirtyView = true;
|
||||||
|
}
|
||||||
|
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::S))
|
||||||
|
{
|
||||||
|
system->editorCamera.position -= view * dt * camera.movementSpeed;
|
||||||
|
system->editorCamera.dirtyView = true;
|
||||||
|
}
|
||||||
|
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::Q))
|
||||||
|
{
|
||||||
|
system->editorCamera.position += UP * dt * camera.movementSpeed;
|
||||||
|
system->editorCamera.dirtyView = true;
|
||||||
|
}
|
||||||
|
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::E))
|
||||||
|
{
|
||||||
|
system->editorCamera.position -= UP * dt * camera.movementSpeed;
|
||||||
|
system->editorCamera.dirtyView = true;
|
||||||
|
}
|
||||||
|
system->UpdateCameraComponent(system->editorCamera);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHCameraSystem::Init(void)
|
||||||
|
{
|
||||||
|
editorCamera.SetPosition(0.0f, 0.0f, 0.0f);
|
||||||
|
editorCamera.SetPitch(0.0f);
|
||||||
|
editorCamera.SetYaw(0.0f);
|
||||||
|
editorCamera.SetRoll(0.0f);
|
||||||
|
editorCamera.movementSpeed = 2.0f;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHCameraSystem::Exit(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SHCameraComponent* SHCameraSystem::GetEditorCamera(void) noexcept
|
||||||
|
{
|
||||||
|
return &editorCamera;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHCameraSystem::UpdateCameraComponent(SHCameraComponent& camera) noexcept
|
||||||
|
{
|
||||||
|
if (camera.dirtyView)
|
||||||
|
{
|
||||||
|
SHVec3 target{ 0.0f,0.0f,-1.0f };
|
||||||
|
SHVec3 up = { 0.0f,1.0f,0.0f };
|
||||||
|
|
||||||
|
|
||||||
|
SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw));
|
||||||
|
SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch));
|
||||||
|
target += camera.position;
|
||||||
|
////SHVec3::RotateZ(target, SHMath::DegreesToRadians(camera.roll));
|
||||||
|
|
||||||
|
//target = SHVec3::Normalise(target);
|
||||||
|
|
||||||
|
SHVec3::RotateZ(up, camera.roll);
|
||||||
|
up = SHVec3::Normalise(up);
|
||||||
|
|
||||||
|
|
||||||
|
SHVec3 view = target - camera.position; view = SHVec3::Normalise(view);
|
||||||
|
SHVec3 right = SHVec3::Cross(view, up); right = SHVec3::Normalise(right);
|
||||||
|
const SHVec3 UP = SHVec3::Cross(view, right);
|
||||||
|
|
||||||
|
camera.viewMatrix = SHMatrix::Identity;
|
||||||
|
camera.viewMatrix(0, 0) = right[0];
|
||||||
|
camera.viewMatrix(0, 1) = right[1];
|
||||||
|
camera.viewMatrix(0, 2) = right[2];
|
||||||
|
|
||||||
|
camera.viewMatrix(1, 0) = UP[0];
|
||||||
|
camera.viewMatrix(1, 1) = UP[1];
|
||||||
|
camera.viewMatrix(1, 2) = UP[2];
|
||||||
|
|
||||||
|
camera.viewMatrix(2, 0) = view[0];
|
||||||
|
camera.viewMatrix(2, 1) = view[1];
|
||||||
|
camera.viewMatrix(2, 2) = view[2];
|
||||||
|
|
||||||
|
camera.viewMatrix(0, 3) = -right.Dot(camera.position);
|
||||||
|
camera.viewMatrix(1, 3) = -UP.Dot(camera.position);
|
||||||
|
camera.viewMatrix(2, 3) = -view.Dot(camera.position);
|
||||||
|
|
||||||
|
camera.dirtyView = false;
|
||||||
|
}
|
||||||
|
if (camera.dirtyProj == true)
|
||||||
|
{
|
||||||
|
if (camera.perspProj == true)
|
||||||
|
{
|
||||||
|
const float ASPECT_RATIO = (camera.GetAspectRatio());
|
||||||
|
const float TAN_HALF_FOV = tan(SHMath::DegreesToRadians(camera.fov) * 0.5f);
|
||||||
|
camera.projMatrix = SHMatrix::Identity;
|
||||||
|
camera.projMatrix(0, 0) = 1.0f / (ASPECT_RATIO * TAN_HALF_FOV);
|
||||||
|
camera.projMatrix(1, 1) = 1.0f / TAN_HALF_FOV;
|
||||||
|
camera.projMatrix(2, 2) = camera.zFar / (camera.zFar - camera.zNear);
|
||||||
|
camera.projMatrix(3, 3) = 0.0f;
|
||||||
|
|
||||||
|
camera.projMatrix(3, 2) = 1.0f;
|
||||||
|
camera.projMatrix(2, 3) = -(camera.zFar * camera.zNear) / (camera.zFar - camera.zNear);
|
||||||
|
|
||||||
|
//const float fov_rad = SHMath::DegreesToRadians(camera.fov);
|
||||||
|
//const float focal_length = 1.0f / tan(fov_rad * 0.5f);
|
||||||
|
|
||||||
|
//camera.projMatrix(0,0) = focal_length / camera.GetAspectRatio();
|
||||||
|
//camera.projMatrix(1,1) = -focal_length;
|
||||||
|
//camera.projMatrix(2,2) = camera.zNear / (camera.zFar - camera.zNear);
|
||||||
|
//camera.projMatrix(2,3) = camera.zFar * (camera.zNear / (camera.zFar - camera.zNear));
|
||||||
|
//camera.projMatrix(3,2) = -1.0f;
|
||||||
|
//camera.projMatrix(3,3) = 0.0f;
|
||||||
|
|
||||||
|
//camera.projMatrix = SHMatrix::Inverse(camera.projMatrix);
|
||||||
|
|
||||||
|
camera.dirtyProj = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const float R = camera.width * 0.5f;
|
||||||
|
const float L = -R;
|
||||||
|
const float T = camera.height * 0.5f;
|
||||||
|
const float B = -T;
|
||||||
|
|
||||||
|
camera.projMatrix = SHMatrix::Identity;
|
||||||
|
camera.projMatrix(0, 0) = 2.0f / (R - L);
|
||||||
|
camera.projMatrix(1, 1) = 2.0f / (B - T);
|
||||||
|
camera.projMatrix(2, 2) = 1.0f / (camera.zFar - camera.zNear);
|
||||||
|
camera.projMatrix(3, 0) = -(R + L) / (R - L);
|
||||||
|
camera.projMatrix(3, 1) = -(B + T) / (B - T);
|
||||||
|
camera.projMatrix(3, 2) = -camera.zNear / (camera.zFar - camera.zNear);
|
||||||
|
|
||||||
|
camera.dirtyProj = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ECS_Base/System/SHSystem.h"
|
||||||
|
#include "SHCameraComponent.h"
|
||||||
|
#include "ECS_Base/System/SHSystemRoutine.h"
|
||||||
|
#include "SH_API.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
class SH_API SHCameraSystem final : public SHSystem
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
//A camera component that represents editor camera.
|
||||||
|
//This is not tied to any entity. Hence this EID should not be used.
|
||||||
|
SHCameraComponent editorCamera;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
SHCameraSystem(void) = default;
|
||||||
|
virtual ~SHCameraSystem(void) = default;
|
||||||
|
|
||||||
|
void Init (void);
|
||||||
|
void Exit (void);
|
||||||
|
|
||||||
|
class SH_API EditorCameraUpdate final : public SHSystemRoutine
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
EditorCameraUpdate() : SHSystemRoutine("Editor Camera Update", true) { };
|
||||||
|
virtual void Execute(double dt) noexcept override final;
|
||||||
|
|
||||||
|
};
|
||||||
|
friend class EditorCameraUpdate;
|
||||||
|
|
||||||
|
SHCameraComponent* GetEditorCamera (void) noexcept;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void UpdateCameraComponent(SHCameraComponent& camera) noexcept;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -214,23 +214,50 @@ namespace SHADE
|
||||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHEditorUI::InputSlider(const std::string& label, double min, double max, double& value, bool* isHovered)
|
bool SHEditorUI::InputSlider(const std::string& label, int min, int max, int& value, bool* isHovered /*= nullptr*/)
|
||||||
{
|
{
|
||||||
float val = static_cast<float>(value);
|
ImGui::Text(label.c_str());
|
||||||
ImGui::Text(label.c_str());
|
if (isHovered)
|
||||||
if (isHovered)
|
*isHovered = ImGui::IsItemHovered();
|
||||||
*isHovered = ImGui::IsItemHovered();
|
ImGui::SameLine();
|
||||||
ImGui::SameLine();
|
return ImGui::SliderInt("##", &value,
|
||||||
const bool CHANGED = ImGui::SliderFloat("#", &val,
|
static_cast<float>(min), static_cast<float>(max), "%d",
|
||||||
static_cast<float>(min), static_cast<float>(max), "%.3f",
|
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||||
ImGuiInputTextFlags_EnterReturnsTrue);
|
}
|
||||||
|
|
||||||
if (CHANGED)
|
bool SHEditorUI::InputSlider(const std::string& label, unsigned int min, unsigned int max, unsigned int& value, bool* isHovered /*= nullptr*/)
|
||||||
{
|
{
|
||||||
value = val;
|
int val = static_cast<int>(value);
|
||||||
}
|
const bool CHANGED = InputSlider(label, min, max, val, isHovered);
|
||||||
|
if (CHANGED)
|
||||||
|
{
|
||||||
|
value = static_cast<int>(val);
|
||||||
|
}
|
||||||
|
|
||||||
return CHANGED;
|
return CHANGED;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHEditorUI::InputSlider(const std::string& label, float min, float max, float& value, bool* isHovered)
|
||||||
|
{
|
||||||
|
ImGui::Text(label.c_str());
|
||||||
|
if (isHovered)
|
||||||
|
*isHovered = ImGui::IsItemHovered();
|
||||||
|
ImGui::SameLine();
|
||||||
|
return ImGui::SliderFloat("##", &value,
|
||||||
|
static_cast<float>(min), static_cast<float>(max), "%.3f",
|
||||||
|
ImGuiInputTextFlags_EnterReturnsTrue);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHEditorUI::InputSlider(const std::string& label, double min, double max, double& value, bool* isHovered /*= nullptr*/)
|
||||||
|
{
|
||||||
|
float val = static_cast<float>(value);
|
||||||
|
const bool CHANGED = InputSlider(label, min, max, val, isHovered);
|
||||||
|
if (CHANGED)
|
||||||
|
{
|
||||||
|
value = static_cast<double>(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return CHANGED;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHEditorUI::InputVec2(const std::string& label, SHVec2& value, bool* isHovered)
|
bool SHEditorUI::InputVec2(const std::string& label, SHVec2& value, bool* isHovered)
|
||||||
|
|
|
@ -230,9 +230,45 @@ namespace SHADE
|
||||||
/// <returns>True if the value was changed.</returns>
|
/// <returns>True if the value was changed.</returns>
|
||||||
static bool InputAngle(const std::string& label, double& value, bool* isHovered = nullptr);
|
static bool InputAngle(const std::string& label, double& value, bool* isHovered = nullptr);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Creates an int slider field widget for double input.
|
||||||
|
/// <br/>
|
||||||
|
/// Wraps up ImGui::SliderInt().
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="label">Label used to identify this widget.</param>
|
||||||
|
/// <param name="min">Minimum value of the slider.</param>
|
||||||
|
/// <param name="max">Maximum value of the slider.</param>
|
||||||
|
/// <param name="value">Reference to the variable to store the result.</param>
|
||||||
|
/// <param name="isHovered>If set, stores the hover state of this widget.</param>
|
||||||
|
/// <returns>True if the value was changed.</returns>
|
||||||
|
static bool InputSlider(const std::string& label, int min, int max, int& value, bool* isHovered = nullptr);
|
||||||
|
/// <summary>
|
||||||
|
/// Creates an unsigned int slider field widget for double input.
|
||||||
|
/// <br/>
|
||||||
|
/// Wraps up ImGui::SliderInt().
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="label">Label used to identify this widget.</param>
|
||||||
|
/// <param name="min">Minimum value of the slider.</param>
|
||||||
|
/// <param name="max">Maximum value of the slider.</param>
|
||||||
|
/// <param name="value">Reference to the variable to store the result.</param>
|
||||||
|
/// <param name="isHovered>If set, stores the hover state of this widget.</param>
|
||||||
|
/// <returns>True if the value was changed.</returns>
|
||||||
|
static bool InputSlider(const std::string& label, unsigned int min, unsigned int max, unsigned int& value, bool* isHovered = nullptr);
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a float slider field widget for double input.
|
||||||
|
/// <br/>
|
||||||
|
/// Wraps up ImGui::SliderFloat().
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="label">Label used to identify this widget.</param>
|
||||||
|
/// <param name="min">Minimum value of the slider.</param>
|
||||||
|
/// <param name="max">Maximum value of the slider.</param>
|
||||||
|
/// <param name="value">Reference to the variable to store the result.</param>
|
||||||
|
/// <param name="isHovered>If set, stores the hover state of this widget.</param>
|
||||||
|
/// <returns>True if the value was changed.</returns>
|
||||||
|
static bool InputSlider(const std::string& label, float min, float max, float& value, bool* isHovered = nullptr);
|
||||||
|
/// <summary>
|
||||||
/// Creates a double slider field widget for double input.
|
/// Creates a double slider field widget for double input.
|
||||||
/// <br/>
|
/// <br/>
|
||||||
/// Wraps up ImGui::InputSliderFloat().
|
/// Wraps up ImGui::SliderFloat().
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="label">Label used to identify this widget.</param>
|
/// <param name="label">Label used to identify this widget.</param>
|
||||||
/// <param name="min">Minimum value of the slider.</param>
|
/// <param name="min">Minimum value of the slider.</param>
|
||||||
|
|
|
@ -16,9 +16,9 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* ImGui Wrapper Functions - Widgets */
|
/* ImGui Wrapper Functions - Widgets */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
template<typename Enum>
|
template<typename Enum>
|
||||||
inline bool SHEditorUI::InputEnumCombo(const std::string& label, Enum& v, int maxVal, std::function<const char* (Enum)> toStrFn, bool* isHovered)
|
inline bool SHEditorUI::InputEnumCombo(const std::string& label, Enum& v, int maxVal, std::function<const char* (Enum)> toStrFn, bool* isHovered)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include "Tools/SHLogger.h"
|
|
||||||
#include "SH_API.h"
|
#include "SH_API.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
|
|
@ -97,14 +97,16 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Getter Functions */
|
/* Getter Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
SHMatrix SHCamera::GetViewMatrix() const
|
SHMatrix SHCamera::GetViewMatrix()
|
||||||
{
|
{
|
||||||
return viewMatrix;
|
updateMatrices();
|
||||||
|
return viewMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHMatrix SHCamera::GetProjectionMatrix() const
|
SHMatrix SHCamera::GetProjectionMatrix()
|
||||||
{
|
{
|
||||||
return projMatrix;
|
updateMatrices();
|
||||||
|
return projMatrix;
|
||||||
}
|
}
|
||||||
SHMatrix SHCamera::GetViewProjectionMatrix()
|
SHMatrix SHCamera::GetViewProjectionMatrix()
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
\par email: kahwei.tng\@digipen.edu
|
\par email: kahwei.tng\@digipen.edu
|
||||||
\date Aug 21, 2022
|
\date Aug 21, 2022
|
||||||
\brief
|
\brief
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
of DigiPen Institute of Technology is prohibited.
|
of DigiPen Institute of Technology is prohibited.
|
||||||
*//*************************************************************************************/
|
*//*************************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
@ -17,64 +17,66 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/***********************************************************************************/
|
/***********************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
\brief
|
\brief
|
||||||
Object that manages the view and projection transformations for rendering
|
Object that manages the view and projection transformations for rendering
|
||||||
a 3D scene.
|
a 3D scene.
|
||||||
*/
|
*/
|
||||||
/***********************************************************************************/
|
/***********************************************************************************/
|
||||||
class SHCamera
|
class SHCamera
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructor/Destructors */
|
/* Constructor/Destructors */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* View Set Functions */
|
/* View Set Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void SetLookAt(const SHVec3& pos, const SHVec3& target, const SHVec3& up);
|
void SetLookAt(const SHVec3& pos, const SHVec3& target, const SHVec3& up);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Projection Set Functions */
|
/* Projection Set Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void SetPerspective(float fov, float width, float height, float zNear, float zFar);
|
void SetPerspective(float fov, float width, float height, float zNear, float zFar);
|
||||||
void SetOrthographic(float width, float height, float zNear, float zFar);
|
void SetOrthographic(float width, float height, float zNear, float zFar);
|
||||||
|
|
||||||
|
//void SetPerspectiveMatrixExplicit (
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Getter Functions */
|
/* Getter Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
SHMatrix GetViewMatrix() const;
|
SHMatrix GetViewMatrix();
|
||||||
SHMatrix GetProjectionMatrix() const;
|
SHMatrix GetProjectionMatrix();
|
||||||
SHMatrix GetViewProjectionMatrix();
|
SHMatrix GetViewProjectionMatrix();
|
||||||
SHMatrix GetInverseViewMatrix() const;
|
SHMatrix GetInverseViewMatrix() const;
|
||||||
SHMatrix GetInverseProjectionMatrix() const;
|
SHMatrix GetInverseProjectionMatrix() const;
|
||||||
SHMatrix GetInverseViewProjectionMatrix();
|
SHMatrix GetInverseViewProjectionMatrix();
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Mapping Functions */
|
/* Mapping Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
SHVec3 ScreenToWorld(const SHVec3& vec) const;
|
SHVec3 ScreenToWorld(const SHVec3& vec) const;
|
||||||
SHVec3 WorldToScreen(const SHVec3& vec) const;
|
SHVec3 WorldToScreen(const SHVec3& vec) const;
|
||||||
SHVec3 CameraToWorld(const SHVec3& vec) const;
|
SHVec3 CameraToWorld(const SHVec3& vec) const;
|
||||||
SHVec3 WorldToCamera(const SHVec3& vec) const;
|
SHVec3 WorldToCamera(const SHVec3& vec) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
SHMatrix viewMatrix;
|
SHMatrix viewMatrix;
|
||||||
SHMatrix projMatrix;
|
SHMatrix projMatrix;
|
||||||
SHMatrix vpMatrix;
|
SHMatrix vpMatrix;
|
||||||
SHMatrix inverseViewMatrix;
|
SHMatrix inverseViewMatrix;
|
||||||
SHMatrix inverseProjMatrix;
|
SHMatrix inverseProjMatrix;
|
||||||
SHMatrix inverseVpMatrix;
|
SHMatrix inverseVpMatrix;
|
||||||
bool isDirty = true;
|
bool isDirty = true;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void updateMatrices();
|
void updateMatrices();
|
||||||
static SHVec3 multiplyHomogenous(const SHMatrix& mat, const SHVec3& vec);
|
static SHVec3 multiplyHomogenous(const SHMatrix& mat, const SHVec3& vec);
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -16,6 +16,9 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Graphics/Instance/SHVkInstance.h"
|
#include "Graphics/Instance/SHVkInstance.h"
|
||||||
#include "Graphics/Windowing/Surface/SHVkSurface.h"
|
#include "Graphics/Windowing/Surface/SHVkSurface.h"
|
||||||
#include "Graphics/Swapchain/SHVkSwapchain.h"
|
#include "Graphics/Swapchain/SHVkSwapchain.h"
|
||||||
|
#include "Camera/SHCameraSystem.h"
|
||||||
|
#include "Editor/SHEditor.hpp"
|
||||||
|
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||||
//#include "SHRenderer.h"
|
//#include "SHRenderer.h"
|
||||||
#include "Graphics/Windowing/SHWindow.h"
|
#include "Graphics/Windowing/SHWindow.h"
|
||||||
#include "Graphics/MiddleEnd/PerFrame/SHPerFrameData.h"
|
#include "Graphics/MiddleEnd/PerFrame/SHPerFrameData.h"
|
||||||
|
@ -318,6 +321,23 @@ namespace SHADE
|
||||||
|
|
||||||
// Bind textures
|
// Bind textures
|
||||||
|
|
||||||
|
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||||
|
|
||||||
|
#ifdef SHEDITOR
|
||||||
|
|
||||||
|
auto editorSystem = SHSystemManager::GetSystem<SHEditor>();
|
||||||
|
if (editorSystem->editorState != SHEditor::State::PLAY)
|
||||||
|
{
|
||||||
|
worldRenderer->SetViewProjectionMatrix(SHMatrix::Transpose(cameraSystem->GetEditorCamera()->GetProjMatrix() * cameraSystem->GetEditorCamera()->GetViewMatrix()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// main camera
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
// main camera
|
||||||
|
#endif
|
||||||
|
|
||||||
// For every viewport
|
// For every viewport
|
||||||
for (int vpIndex = 0; vpIndex < static_cast<int>(viewports.size()); ++vpIndex)
|
for (int vpIndex = 0; vpIndex < static_cast<int>(viewports.size()); ++vpIndex)
|
||||||
|
@ -704,6 +724,14 @@ namespace SHADE
|
||||||
|
|
||||||
worldCamera->SetPerspective(90.0f, static_cast<float>(resizeWidth), static_cast<float>(resizeHeight), 0.0f, 100.0f);
|
worldCamera->SetPerspective(90.0f, static_cast<float>(resizeWidth), static_cast<float>(resizeHeight), 0.0f, 100.0f);
|
||||||
|
|
||||||
|
auto cameraSystem = SHSystemManager::GetSystem<SHCameraSystem>();
|
||||||
|
#ifdef SHEDITOR
|
||||||
|
cameraSystem->GetEditorCamera()->SetWidth(resizeWidth);
|
||||||
|
cameraSystem->GetEditorCamera()->SetHeight(resizeHeight);
|
||||||
|
#else
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
for (auto& semaHandle : graphSemaphores)
|
for (auto& semaHandle : graphSemaphores)
|
||||||
semaHandle = device->CreateSemaphore();
|
semaHandle = device->CreateSemaphore();
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
if (camera)
|
if (camera)
|
||||||
{
|
{
|
||||||
cpuCameraData.viewProjectionMatrix = camera->GetViewProjectionMatrix();
|
//cpuCameraData.viewProjectionMatrix = camera->GetViewProjectionMatrix();
|
||||||
cameraBuffer->WriteToMemory(&cpuCameraData, sizeof(SHShaderCameraData), 0, cameraDataAlignedSize * frameIndex);
|
cameraBuffer->WriteToMemory(&cpuCameraData, sizeof(SHShaderCameraData), 0, cameraDataAlignedSize * frameIndex);
|
||||||
|
|
||||||
std::array<uint32_t, 1> dynamicOffsets{ frameIndex * cameraDataAlignedSize };
|
std::array<uint32_t, 1> dynamicOffsets{ frameIndex * cameraDataAlignedSize };
|
||||||
|
@ -90,6 +90,12 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHRenderer::SetViewProjectionMatrix(SHMatrix const& vpMatrix) noexcept
|
||||||
|
{
|
||||||
|
//cpuCameraData.viewProjectionMatrix = camera->GetViewMatrix() * camera->GetProjectionMatrix();
|
||||||
|
cpuCameraData.viewProjectionMatrix = vpMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
Handle<SHRenderGraph> SHRenderer::GetRenderGraph(void) const noexcept
|
Handle<SHRenderGraph> SHRenderer::GetRenderGraph(void) const noexcept
|
||||||
{
|
{
|
||||||
return renderGraph;
|
return renderGraph;
|
||||||
|
|
|
@ -78,6 +78,7 @@ namespace SHADE
|
||||||
void Draw(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept;
|
void Draw(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) noexcept;
|
||||||
void UpdateDataAndBind (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
void UpdateDataAndBind (Handle<SHVkCommandBuffer> cmdBuffer, uint32_t frameIndex) noexcept;
|
||||||
void UpdateCameraDataToBuffer (void) noexcept;
|
void UpdateCameraDataToBuffer (void) noexcept;
|
||||||
|
void SetViewProjectionMatrix (SHMatrix const& vpMatrix) noexcept;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Setters and Getters */
|
/* Setters and Getters */
|
||||||
|
|
|
@ -30,6 +30,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Editor/Command/SHCommandManager.h"
|
#include "Editor/Command/SHCommandManager.h"
|
||||||
#include "Editor/Command/SHCommand.hpp"
|
#include "Editor/Command/SHCommand.hpp"
|
||||||
#include "TooltipAttribute.hxx"
|
#include "TooltipAttribute.hxx"
|
||||||
|
#include "RangeAttribute.hxx"
|
||||||
|
|
||||||
// Using Directives
|
// Using Directives
|
||||||
using namespace System;
|
using namespace System;
|
||||||
|
@ -61,6 +62,43 @@ using namespace System::Collections::Generic;
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Alternative to RENDER_FIELD that checks for RangeAttribute and switches to a slider
|
||||||
|
/// instead.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="MANAGED_TYPE">The managed type of the object to edit.</param>
|
||||||
|
/// <param name="NATIVE_TYPE">The native type of the object to edit.</param>
|
||||||
|
/// <param name="FUNC">The SHEditorUI:: function to use for editing.</param>
|
||||||
|
#define RENDER_FIELD_RANGE(MANAGED_TYPE, NATIVE_TYPE, FUNC) \
|
||||||
|
(field->FieldType == MANAGED_TYPE::typeid) \
|
||||||
|
{ \
|
||||||
|
NATIVE_TYPE val = safe_cast<NATIVE_TYPE>(field->GetValue(object)); \
|
||||||
|
NATIVE_TYPE oldVal = val; \
|
||||||
|
\
|
||||||
|
RangeAttribute^ rangeAttrib = hasAttribute<RangeAttribute^>(field); \
|
||||||
|
const std::string FIELD_NAME = Convert::ToNative(field->Name); \
|
||||||
|
bool changed = false; \
|
||||||
|
if (rangeAttrib) \
|
||||||
|
{ \
|
||||||
|
changed = SHEditorUI::InputSlider \
|
||||||
|
( \
|
||||||
|
FIELD_NAME, \
|
||||||
|
static_cast<NATIVE_TYPE>(rangeAttrib->Min), \
|
||||||
|
static_cast<NATIVE_TYPE>(rangeAttrib->Max), \
|
||||||
|
val, &isHovered \
|
||||||
|
); \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
changed = SHEditorUI::FUNC(FIELD_NAME, val, &isHovered); \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
if (changed) \
|
||||||
|
{ \
|
||||||
|
field->SetValue(object, val); \
|
||||||
|
registerUndoAction(object, field, val, oldVal); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
/// <summary>
|
||||||
/// Macro expansion that is used in renderFieldInInspector() to check the type of a field
|
/// Macro expansion that is used in renderFieldInInspector() to check the type of a field
|
||||||
/// named "field" against the specified type and if it matches, retrieves the value of
|
/// named "field" against the specified type and if it matches, retrieves the value of
|
||||||
/// that field from an object named "object" and pass it into the specified SHEditorUI::
|
/// that field from an object named "object" and pass it into the specified SHEditorUI::
|
||||||
|
@ -77,6 +115,7 @@ using namespace System::Collections::Generic;
|
||||||
{ \
|
{ \
|
||||||
NATIVE_TYPE val = Convert::ToNative(safe_cast<MANAGED_TYPE>(field->GetValue(object))); \
|
NATIVE_TYPE val = Convert::ToNative(safe_cast<MANAGED_TYPE>(field->GetValue(object))); \
|
||||||
NATIVE_TYPE oldVal = val; \
|
NATIVE_TYPE oldVal = val; \
|
||||||
|
\
|
||||||
if (SHEditorUI::FUNC(Convert::ToNative(field->Name), val, &isHovered)) \
|
if (SHEditorUI::FUNC(Convert::ToNative(field->Name), val, &isHovered)) \
|
||||||
{ \
|
{ \
|
||||||
field->SetValue(object, Convert::ToCLI(val)); \
|
field->SetValue(object, Convert::ToCLI(val)); \
|
||||||
|
@ -199,16 +238,16 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
bool isHovered = false;
|
bool isHovered = false;
|
||||||
|
|
||||||
if RENDER_FIELD (Int16, int, InputInt)
|
if RENDER_FIELD_RANGE (Int16, int, InputInt)
|
||||||
else if RENDER_FIELD (Int32, int, InputInt)
|
else if RENDER_FIELD_RANGE (Int32, int, InputInt)
|
||||||
else if RENDER_FIELD (Int64, int, InputInt)
|
else if RENDER_FIELD_RANGE (Int64, int, InputInt)
|
||||||
else if RENDER_FIELD (UInt16, unsigned int, InputUnsignedInt)
|
else if RENDER_FIELD_RANGE (UInt16, unsigned int, InputUnsignedInt)
|
||||||
else if RENDER_FIELD (UInt32, unsigned int, InputUnsignedInt)
|
else if RENDER_FIELD_RANGE (UInt32, unsigned int, InputUnsignedInt)
|
||||||
else if RENDER_FIELD (UInt64, unsigned int, InputUnsignedInt)
|
else if RENDER_FIELD_RANGE (UInt64, unsigned int, InputUnsignedInt)
|
||||||
else if RENDER_FIELD (Byte, int, InputInt)
|
else if RENDER_FIELD_RANGE (Byte, int, InputInt)
|
||||||
else if RENDER_FIELD (bool, bool, InputCheckbox)
|
else if RENDER_FIELD (bool, bool, InputCheckbox)
|
||||||
else if RENDER_FIELD (float, float, InputFloat)
|
else if RENDER_FIELD_RANGE (float, float, InputFloat)
|
||||||
else if RENDER_FIELD (double, double, InputDouble)
|
else if RENDER_FIELD_RANGE (double, double, InputDouble)
|
||||||
else if (field->FieldType->IsSubclassOf(Enum::typeid))
|
else if (field->FieldType->IsSubclassOf(Enum::typeid))
|
||||||
{
|
{
|
||||||
// Get all the names of the enums
|
// Get all the names of the enums
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file RangeAttribute.cxx
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Oct 18, 2022
|
||||||
|
\brief Contains the definition of the functions of the managed Range Attribute
|
||||||
|
class.
|
||||||
|
|
||||||
|
Note: This file is written in C++17/CLI.
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "RangeAttribute.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
float RangeAttribute::Min::get()
|
||||||
|
{
|
||||||
|
return minVal;
|
||||||
|
}
|
||||||
|
float RangeAttribute::Max::get()
|
||||||
|
{
|
||||||
|
return maxVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Constructors */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
RangeAttribute::RangeAttribute(float min, float max)
|
||||||
|
: minVal { min }
|
||||||
|
, maxVal { max }
|
||||||
|
{}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file RangeAttribute.hxx
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Oct 18, 2022
|
||||||
|
\brief Contains the definition of the managed Range Attribute class with
|
||||||
|
the declaration of functions for working with it.
|
||||||
|
|
||||||
|
Note: This file is written in C++17/CLI.
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Simple attribute to constrain the range of values for a field on the editor.
|
||||||
|
/// </summary>
|
||||||
|
[System::AttributeUsage(System::AttributeTargets::Field)]
|
||||||
|
public ref class RangeAttribute : public System::Attribute
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Minimum value for the Ranged field.
|
||||||
|
/// </summary>
|
||||||
|
property float Min
|
||||||
|
{
|
||||||
|
float get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Maximum value for the Ranged field.
|
||||||
|
/// </summary>
|
||||||
|
property float Max
|
||||||
|
{
|
||||||
|
float get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Constructors */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for a Tooltip attribute that fills in the description.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="description">Text to be shown when a field is hovered.</param>
|
||||||
|
RangeAttribute(float min, float max);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
float minVal;
|
||||||
|
float maxVal;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Simple attribute to mark that a field in a Script should be serialised.
|
/// Simple attribute to provide a field in a script with a tooltip.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[System::AttributeUsage(System::AttributeTargets::Field)]
|
[System::AttributeUsage(System::AttributeTargets::Field)]
|
||||||
public ref class TooltipAttribute : public System::Attribute
|
public ref class TooltipAttribute : public System::Attribute
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file Time.cxx
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Oct 19, 2022
|
||||||
|
\brief This file is present so that the properties in Time.hxx would be compiled
|
||||||
|
into the DLL.
|
||||||
|
|
||||||
|
Note: This file is written in C++17/CLI.
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
// Precompiled Headers
|
||||||
|
#include "SHpch.h"
|
||||||
|
// Primary Header
|
||||||
|
#include "Time.hxx"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
double Time::DeltaTime::get()
|
||||||
|
{
|
||||||
|
return SHFrameRateController::GetRawDeltaTime();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file Time.hxx
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Oct 19, 2022
|
||||||
|
\brief Contains the definition of the Time static class and the definition of
|
||||||
|
its properties.
|
||||||
|
|
||||||
|
Note: This file is written in C++17/CLI.
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "FRC/SHFramerateController.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Static class that contains the functions for working with time.
|
||||||
|
/// </summary>
|
||||||
|
public ref class Time abstract sealed
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Time taken to process the previous frame.
|
||||||
|
/// Note, is affected by TimeScale. Use UnscaledDeltaTime if you wish to retrieve
|
||||||
|
/// real world time. This is also affected by MaxDeltaTime clamping that
|
||||||
|
/// UnscaledDeltaTime is subject to.
|
||||||
|
/// </summary>
|
||||||
|
static property double DeltaTime
|
||||||
|
{
|
||||||
|
double get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
|
@ -5,7 +5,11 @@ public class RaccoonShowcase : Script
|
||||||
{
|
{
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
[Tooltip("Speed of the rotation in radians per second.")]
|
[Tooltip("Speed of the rotation in radians per second.")]
|
||||||
|
[Range(-1.0f, 2.0f)]
|
||||||
private double RotateSpeed = 1.0;
|
private double RotateSpeed = 1.0;
|
||||||
|
//[SerializeField]
|
||||||
|
//[Range(-5, 20)]
|
||||||
|
//private int test = 5;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
[Tooltip("Speed of the scaling in radians per second around each axis.")]
|
[Tooltip("Speed of the scaling in radians per second around each axis.")]
|
||||||
private Vector3 ScaleSpeed = new Vector3(1.0, 1.0, 0.0);
|
private Vector3 ScaleSpeed = new Vector3(1.0, 1.0, 0.0);
|
||||||
|
|
Loading…
Reference in New Issue