Separated Ortho and perspective matrices in camera #221

Merged
maverickdgg merged 5 commits from SP3-141-Camera-System into main 2022-11-18 12:24:19 +08:00
1 changed files with 24 additions and 13 deletions
Showing only changes of commit eb32e87387 - Show all commits

View File

@ -107,7 +107,11 @@ 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.SetWidth(1080.0f);
editorCamera.SetHeight(720.0f);
editorCamera.SetFar(10000000.0f);
editorCamera.movementSpeed = 2.0f; editorCamera.movementSpeed = 2.0f;
editorCamera.perspProj = true;
SHComponentManager::CreateComponentSparseSet<SHCameraComponent>(); SHComponentManager::CreateComponentSparseSet<SHCameraComponent>();
SHComponentManager::CreateComponentSparseSet<SHCameraArmComponent>(); SHComponentManager::CreateComponentSparseSet<SHCameraArmComponent>();
@ -228,18 +232,24 @@ namespace SHADE
} }
else else
{ {
//const float R = camera.width * 0.5f; const float right = camera.GetWidth() * 0.5f;
//const float L = -R; const float left = -right;
//const float T = camera.height * 0.5f; const float top = camera.GetHeight() * 0.5f;
//const float B = -T; const float btm = -top;
const float n = camera.GetNear();
const float f = camera.GetFar();
//camera.projMatrix = SHMatrix::Identity; camera.projMatrix = SHMatrix::Identity;
//camera.projMatrix(0, 0) = 2.0f / (R - L); camera.projMatrix(0, 0) = 2.0f / (right - left);
//camera.projMatrix(1, 1) = 2.0f / (B - T); camera.projMatrix(1, 1) = 2.0f / (btm - top);
//camera.projMatrix(2, 2) = 1.0f / (camera.zFar - camera.zNear); camera.projMatrix(2, 2) = 1.0f / (f-n);
//camera.projMatrix(3, 0) = -(R + L) / (R - L); camera.projMatrix(0, 3) = -(right + left) / (right - left);
//camera.projMatrix(3, 1) = -(B + T) / (B - T); camera.projMatrix(1, 3) = -(btm + top) / (btm - top);
//camera.projMatrix(3, 2) = -camera.zNear / (camera.zFar - camera.zNear); camera.projMatrix(2, 3) = -n / (f-n);
camera.projMatrix(3, 3) = 1.0f;
camera.projMatrix = SHMatrix::OrthographicRH(camera.GetWidth(), camera.GetHeight(), camera.GetNear(), camera.GetFar());
//camera.projMatrix.Transpose();
camera.dirtyProj = false; camera.dirtyProj = false;
} }
@ -252,8 +262,6 @@ namespace SHADE
SHVec3 up = { 0.0f,1.0f,0.0f }; SHVec3 up = { 0.0f,1.0f,0.0f };
target = SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch)); target = SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch));
target = SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw)); target = SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw));
target += camera.position; target += camera.position;
@ -287,6 +295,9 @@ namespace SHADE
if (SHSceneManager::CheckNodeAndComponentsActive<SHCameraComponent>(cam.GetEID())) if (SHSceneManager::CheckNodeAndComponentsActive<SHCameraComponent>(cam.GetEID()))
system->UpdateCameraComponent(cam); system->UpdateCameraComponent(cam);
} }
for (auto& handle : system->directorHandleList) for (auto& handle : system->directorHandleList)
{ {
handle->UpdateMatrix(); handle->UpdateMatrix();