From 0e2b0177163d8f1d0cbec688a877874ec58a6476 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Mon, 31 Oct 2022 15:39:04 +0800 Subject: [PATCH] View matrix decomposition and set view matrix View matrix decomposition does not decompose roll yet but there isn't much use case --- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 35 ++++++++++++++-------- SHADE_Engine/src/Camera/SHCameraSystem.h | 14 ++++----- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index be34ecf0..16f651e8 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -354,7 +354,7 @@ namespace SHADE } } - void SHCameraSystem::DecomposeViewMatrix(SHMatrix& viewMatrix, float& pitch, float& yaw, float& roll, SHVec3& pos) noexcept + void SHCameraSystem::DecomposeViewMatrix(SHMatrix const& viewMatrix, float& pitch, float& yaw, float& roll, SHVec3& pos) noexcept { float initPitch = pitch; @@ -362,20 +362,29 @@ namespace SHADE SHVec3 translate3, scale; SHQuaternion quat; - SHMatrix viewInverse = viewMatrix; + //SHMatrix viewInverse = viewMatrix; - viewInverse.Decompose(translate3, quat, scale); + viewMatrix.Decompose(translate3, quat, scale); yaw = 180+ SHMath::RadiansToDegrees(quat.ToEuler().y); pitch = -SHMath::RadiansToDegrees(quat.ToEuler().x); - SHVec4 translate = (viewMatrix * SHVec4(0.0f, 0.0f, 0.0f,1.0f) ); - - //float forwardLengthXZ = sqrt(viewMatrix(0,2) * viewMatrix(0,2) + viewMatrix(2, 2) * viewMatrix(2, 2)); - //yaw = SHMath::RadiansToDegrees( atan2f(viewMatrix(2,0), viewMatrix(2, 2))); - //pitch = SHMath::RadiansToDegrees( atan2f(viewMatrix(2, 1), forwardLengthXZ )); - //roll = SHMath::RadiansToDegrees( atan2f(viewMatrix(0, 1), viewMatrix(0,0))); - - //std::cout << "Init yaw: " << initPitch<< " , yaw: " << pitch << std::endl; - std::cout << "Init pos: " << initPos.x << initPos.y<< initPos.z << " , pos: " << translate.x< directorLibrary; std::vector directorHandleList; + + void UpdateCameraComponent(SHCameraComponent& camera) noexcept; + void UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept; + + public: SHCameraSystem(void) = default; virtual ~SHCameraSystem(void) = default; @@ -55,13 +60,8 @@ namespace SHADE void ClampCameraRotation(SHCameraComponent& camera) noexcept; void UpdateEditorCamera(double dt) noexcept; void SetMainCamera(EntityID eid, size_t directorIndex) noexcept; - void DecomposeViewMatrix(SHMatrix& matrix, float& pitch, float& yaw, float& roll, SHVec3& pos) noexcept; - - protected: - - void UpdateCameraComponent(SHCameraComponent& camera) noexcept; - void UpdatePivotArmComponent(SHCameraArmComponent& pivot) noexcept; - + void DecomposeViewMatrix(SHMatrix const& matrix, float& pitch, float& yaw, float& roll, SHVec3& pos) noexcept; + void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept; };