Camera Orthographic projection

This commit is contained in:
maverickdgg 2022-11-14 15:10:23 +08:00
parent 557a198367
commit eb32e87387
1 changed files with 24 additions and 13 deletions

View File

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