Add EditorCameraComponent and EditorCameraSystem

This commit is contained in:
SweetId
2023-11-20 14:59:23 +05:30
parent 64171da71a
commit 13a50a87dd
4 changed files with 210 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
#pragma once
#include <NazaraEditor/Core/Core.hpp>
#include <Nazara/Platform/WindowEventHandler.hpp>
namespace Nz
{
class NodeComponent;
class WindowEventHandler;
class NAZARAEDITOR_CORE_API EditorCameraComponent
{
public:
EditorCameraComponent();
EditorCameraComponent(const EditorCameraComponent&) = delete;
EditorCameraComponent(EditorCameraComponent&&);
~EditorCameraComponent();
void Update(Time elapsedTime, NodeComponent& node);
inline void SetPosition(const Nz::Vector3f& position) { m_targetPosition = position; }
inline void SetRotation(const Nz::Quaternionf& rotation) { m_targetAngles = rotation.ToEulerAngles(); }
inline const Nz::Vector3f& GetPosition() const { return m_targetPosition; }
inline const Nz::EulerAnglesf& GetOrientation() const { return m_targetAngles; }
private:
NazaraSlot(Nz::WindowEventHandler, OnMouseMoved, m_onMouseMoved);
Nz::EulerAnglesf m_targetAngles;
Nz::Vector3f m_targetPosition;
Nz::Vector3f m_currentVelocity;
float m_moveSpeed;
float m_smoothSpeed;
};
}

View File

@@ -0,0 +1,37 @@
#pragma once
#include <NazaraEditor/Core/Core.hpp>
#include <entt/entt.hpp>
#include <unordered_set>
namespace Nz
{
class NAZARAEDITOR_CORE_API EditorCameraSystem
{
public:
static constexpr bool AllowConcurrent = false;
static constexpr Int64 ExecutionOrder = 1'001;
EditorCameraSystem(entt::registry& registry);
~EditorCameraSystem();
EditorCameraSystem(const EditorCameraSystem&) = delete;
EditorCameraSystem& operator=(const EditorCameraSystem&) = delete;
EditorCameraSystem(EditorCameraSystem&&) = delete;
EditorCameraSystem& operator=(EditorCameraSystem&&) = delete;
void Update(Time elapsedTime);
private:
void OnCameraDestroy(entt::registry& registry, entt::entity entity);
entt::registry& m_registry;
entt::observer m_cameraConstructObserver;
entt::scoped_connection m_cameraDestroyConnection;
std::unordered_set<entt::entity> m_cameraEntities;
};
}