Added code to test EditorCameraArm.

This commit is contained in:
maverickdgg 2022-11-13 05:45:43 +08:00
parent 922d5b0996
commit efed33ce94
1 changed files with 19 additions and 12 deletions

View File

@ -7,13 +7,15 @@
#include "ECS_Base/Managers/SHComponentManager.h" #include "ECS_Base/Managers/SHComponentManager.h"
#include "Math/Transform/SHTransformComponent.h" #include "Math/Transform/SHTransformComponent.h"
#include <math.h> #include <math.h>
#include "Scene/SHSceneManager.h"
namespace SHADE namespace SHADE
{ {
void SHCameraSystem::UpdateEditorCamera(double dt) noexcept void SHCameraSystem::UpdateEditorCamera(double dt) noexcept
{ {
auto& camera = editorCamera; auto& camera = editorCamera;
SHVec3 view, right, UP; SHVec3 view, right, UP;
GetCameraAxis(camera, view, right, UP); GetCameraAxis(camera, view, right, UP);
@ -60,17 +62,15 @@ namespace SHADE
camera.dirtyView = true; camera.dirtyView = true;
} }
UpdateCameraComponent(editorCamera); UpdateCameraComponent(editorCamera);
if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::LEFT_ALT))
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LEFT_ALT))
{ {
UpdateEditorArm(dt, true, SHVec3{ 0.0f }); UpdateEditorArm(dt, true, SHVec3{ 0.0f });
} }
UpdateEditorArm(dt, false, SHVec3{ 0.0f }); else
UpdateEditorArm(dt, false, SHVec3{ 0.0f });
} }
void SHCameraSystem::UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept void SHCameraSystem::UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept
@ -81,16 +81,21 @@ namespace SHADE
return; return;
} }
editorCamera.SetPosition(targetPos);
double mouseX, mouseY; double mouseX, mouseY;
SHInputManager::GetMouseVelocity(&mouseX, &mouseY); SHInputManager::GetMouseVelocity(&mouseX, &mouseY);
editorCameraArm.pitch -= mouseY * dt * editorCamera.turnSpeed.x; editorCameraArm.pitch -= mouseY * dt * editorCamera.turnSpeed.x;
editorCameraArm.yaw -= mouseX * dt * editorCamera.turnSpeed.y; editorCameraArm.yaw -= mouseX * dt * editorCamera.turnSpeed.y;
constexpr float pitchClamp = 85.0f;
if (editorCameraArm.pitch > pitchClamp)
editorCameraArm.pitch = pitchClamp;
if (editorCameraArm.pitch < -pitchClamp)
editorCameraArm.pitch = -pitchClamp;
editorCameraArm.armLength += SHInputManager::GetMouseWheelVerticalDelta() * dt; editorCameraArm.armLength -= SHInputManager::GetMouseWheelVerticalDelta() * dt;
if (editorCameraArm.armLength < 1.0f) if (editorCameraArm.armLength < 1.0f)
editorCameraArm.armLength = 1.0f; editorCameraArm.armLength = 1.0f;
@ -281,12 +286,14 @@ namespace SHADE
for (auto& pivot : pivotDense) for (auto& pivot : pivotDense)
{ {
system->UpdatePivotArmComponent(pivot); if(SHSceneManager::CheckNodeAndComponentsActive<SHCameraArmComponent>(pivot.GetEID()))
system->UpdatePivotArmComponent(pivot);
} }
for (auto& cam : dense) for (auto& cam : dense)
{ {
system->UpdateCameraComponent(cam); if (SHSceneManager::CheckNodeAndComponentsActive<SHCameraComponent>(cam.GetEID()))
system->UpdateCameraComponent(cam);
} }
for (auto& handle : system->directorHandleList) for (auto& handle : system->directorHandleList)
{ {