Integrated Daniel's camera

Still need to integrate camera directors
This commit is contained in:
Brandon Mak 2022-10-19 16:53:45 +08:00
parent 284ee12205
commit d9136de134
5 changed files with 52 additions and 38 deletions

View File

@ -10,7 +10,7 @@ Collapsed=0
[Window][Hierarchy Panel] [Window][Hierarchy Panel]
Pos=0,142 Pos=0,142
Size=381,918 Size=650,918
Collapsed=0 Collapsed=0
DockId=0x00000004,0 DockId=0x00000004,0
@ -27,22 +27,22 @@ DockId=0x00000006,0
[Window][Profiler] [Window][Profiler]
Pos=0,48 Pos=0,48
Size=381,92 Size=650,92
Collapsed=0 Collapsed=0
DockId=0x00000003,0 DockId=0x00000003,0
[Window][Viewport] [Window][Viewport]
Pos=383,48 Pos=652,48
Size=1264,1012 Size=995,1012
Collapsed=0 Collapsed=0
DockId=0x00000002,0 DockId=0x00000002,0
[Docking][Data] [Docking][Data]
DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=90,200 Size=1920,1012 Split=X DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=8,79 Size=1920,1012 Split=X
DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1992,1036 Split=X DockNode ID=0x00000005 Parent=0xC5C9B8AB SizeRef=1992,1036 Split=X
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=381,1036 Split=Y Selected=0x1E6EB881 DockNode ID=0x00000001 Parent=0x00000005 SizeRef=650,1036 Split=Y Selected=0x1E6EB881
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,94 Selected=0x1E6EB881 DockNode ID=0x00000003 Parent=0x00000001 SizeRef=225,94 Selected=0x1E6EB881
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=225,940 Selected=0xE096E5AE DockNode ID=0x00000004 Parent=0x00000001 SizeRef=225,940 Selected=0xE096E5AE
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1264,1036 CentralNode=1 Selected=0x13926F0B DockNode ID=0x00000002 Parent=0x00000005 SizeRef=995,1036 CentralNode=1 Selected=0x13926F0B
DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=271,1036 Selected=0xE7039252 DockNode ID=0x00000006 Parent=0xC5C9B8AB SizeRef=271,1036 Selected=0xE7039252

View File

@ -8,7 +8,7 @@ namespace SHADE
SHCameraComponent::SHCameraComponent() SHCameraComponent::SHCameraComponent()
:yaw(0.0f), pitch(0.0f), roll(0.0f) :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) , width(1920.0f), height(1080.0f), zNear(0.01f), zFar(10000.0f), fov(90.0f), movementSpeed(1.0f), turnSpeed(1.0f)
, perspProj(false), dirtyView(true), dirtyProj(true) , perspProj(true), dirtyView(true), dirtyProj(true)
, viewMatrix(), projMatrix() , viewMatrix(), projMatrix()
, position() , position()
{ {

View File

@ -11,18 +11,19 @@ namespace SHADE
void SHCameraSystem::EditorCameraUpdate::Execute(double dt) noexcept void SHCameraSystem::EditorCameraUpdate::Execute(double dt) noexcept
{ {
SHCameraSystem* system = static_cast<SHCameraSystem*>(GetSystem()); SHCameraSystem* system = static_cast<SHCameraSystem*>(GetSystem());
auto& camera = system->editorCamera;
SHVec3 target{ 0.0f,0.0f,-1.0f }; SHVec3 target{ 0.0f,0.0f,-1.0f };
SHVec3 up = { 0.0f,1.0f,0.0f }; SHVec3 up = { 0.0f,1.0f,0.0f };
auto& camera = system->editorCamera; target += camera.position;
SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw));
SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch));
//SHVec3::RotateZ(target, SHMath::DegreesToRadians(camera.roll));
target = SHVec3::Normalise(target); //SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw));
//SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch));
////SHVec3::RotateZ(target, SHMath::DegreesToRadians(camera.roll));
SHVec3::RotateZ(up, camera.roll); //target = SHVec3::Normalise(target);
//SHVec3::RotateZ(up, camera.roll);
up = SHVec3::Normalise(up); up = SHVec3::Normalise(up);
@ -33,7 +34,7 @@ namespace SHADE
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::A)) if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::A))
{ {
system->editorCamera.position -= SHVec3(1.0,0.0,0.0) * dt * camera.movementSpeed; system->editorCamera.position -= right * dt * camera.movementSpeed;
system->editorCamera.dirtyView = true; system->editorCamera.dirtyView = true;
} }
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::D)) if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::D))
@ -70,7 +71,7 @@ namespace SHADE
editorCamera.SetPitch(0.0f); editorCamera.SetPitch(0.0f);
editorCamera.SetYaw(0.0f); editorCamera.SetYaw(0.0f);
editorCamera.SetRoll(0.0f); editorCamera.SetRoll(0.0f);
//editorCamera.movementSpeed = 100.0f; editorCamera.movementSpeed = 2.0f;
} }
@ -91,13 +92,15 @@ namespace SHADE
SHVec3 target{ 0.0f,0.0f,-1.0f }; SHVec3 target{ 0.0f,0.0f,-1.0f };
SHVec3 up = { 0.0f,1.0f,0.0f }; SHVec3 up = { 0.0f,1.0f,0.0f };
SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw)); target += camera.position;
SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch));
//SHVec3::RotateZ(target, SHMath::DegreesToRadians(camera.roll));
target = SHVec3::Normalise(target); //SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw));
//SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch));
////SHVec3::RotateZ(target, SHMath::DegreesToRadians(camera.roll));
SHVec3::RotateZ(up, camera.roll); //target = SHVec3::Normalise(target);
//SHVec3::RotateZ(up, camera.roll);
up = SHVec3::Normalise(up); up = SHVec3::Normalise(up);
@ -128,14 +131,28 @@ namespace SHADE
{ {
if (camera.perspProj == true) if (camera.perspProj == true)
{ {
const float ASPECT_RATIO = camera.GetAspectRatio(); const float ASPECT_RATIO = (camera.GetAspectRatio());
const float TAN_HALF_FOV = tan(camera.fov * 0.5f); const float TAN_HALF_FOV = tan(SHMath::DegreesToRadians(camera.fov) * 0.5f);
camera.projMatrix = SHMatrix::Identity; camera.projMatrix = SHMatrix::Identity;
camera.projMatrix(0, 0) = 1.0f / (ASPECT_RATIO * TAN_HALF_FOV); camera.projMatrix(0, 0) = 1.0f / (ASPECT_RATIO * TAN_HALF_FOV);
camera.projMatrix(1, 1) = 1.0f / TAN_HALF_FOV; camera.projMatrix(1, 1) = 1.0f / TAN_HALF_FOV;
camera.projMatrix(2, 2) = camera.zFar / (camera.zFar - camera.zNear); camera.projMatrix(2, 2) = camera.zFar / (camera.zFar - camera.zNear);
camera.projMatrix(2, 3) = 1.0f; camera.projMatrix(3, 3) = 0.0f;
camera.projMatrix(3, 2) = -(camera.zFar * camera.zNear) / (camera.zFar - camera.zNear);
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; camera.dirtyProj = false;
} }

View File

@ -328,10 +328,7 @@ namespace SHADE
auto editorSystem = SHSystemManager::GetSystem<SHEditor>(); auto editorSystem = SHSystemManager::GetSystem<SHEditor>();
if (editorSystem->editorState != SHEditor::State::PLAY) if (editorSystem->editorState != SHEditor::State::PLAY)
{ {
//cameraSystem->GetEditorCamera()->GetViewMatrix(); worldRenderer->SetViewProjectionMatrix(SHMatrix::Transpose(cameraSystem->GetEditorCamera()->GetProjMatrix() * cameraSystem->GetEditorCamera()->GetViewMatrix()));
//cameraSystem->GetEditorCamera()->GetProjMatrix();
worldRenderer->SetViewProjectionMatrix(cameraSystem->GetEditorCamera()->GetViewMatrix() );
//worldRenderer->SetViewProjectionMatrix(SHMatrix::Inverse(cameraSystem->GetEditorCamera()->GetViewMatrix()/* * cameraSystem->GetEditorCamera()->GetProjMatrix()*/));
} }
else else
{ {

View File

@ -92,8 +92,8 @@ namespace SHADE
void SHRenderer::SetViewProjectionMatrix(SHMatrix const& vpMatrix) noexcept void SHRenderer::SetViewProjectionMatrix(SHMatrix const& vpMatrix) noexcept
{ {
cpuCameraData.viewProjectionMatrix = camera->GetViewMatrix() * camera->GetProjectionMatrix(); //cpuCameraData.viewProjectionMatrix = camera->GetViewMatrix() * camera->GetProjectionMatrix();
//cpuCameraData.viewProjectionMatrix = vpMatrix * camera->GetProjectionMatrix(); cpuCameraData.viewProjectionMatrix = vpMatrix;
} }
Handle<SHRenderGraph> SHRenderer::GetRenderGraph(void) const noexcept Handle<SHRenderGraph> SHRenderer::GetRenderGraph(void) const noexcept