diff --git a/openVulkanoCpp/Scene/Node.hpp b/openVulkanoCpp/Scene/Node.hpp index 18246d1..a66a674 100644 --- a/openVulkanoCpp/Scene/Node.hpp +++ b/openVulkanoCpp/Scene/Node.hpp @@ -10,89 +10,82 @@ #include "Base/ICloseable.hpp" #include "Math/Math.hpp" #include "Drawable.hpp" +#include "UpdateFrequency.hpp" #include -namespace openVulkanoCpp +namespace openVulkanoCpp::Scene { - namespace Scene + class Scene; + + class Node : public virtual IInitable, public virtual ICloseable { - class Scene; + friend Scene; - enum class UpdateFrequency + public: + Math::Matrix4f localMat, worldMat; + bool enabled = true; + Node* parent = nullptr; + Scene* scene = nullptr; + std::vector children; + std::vector drawables; + UpdateFrequency matrixUpdateFrequency = UpdateFrequency::Never; + ICloseable* renderNode = nullptr; + + public: + Node(); + + ~Node() override; + + void Init() override; + + void Close() override; + + void AddChild(Node* node); + + inline void AddChild(Drawable* drawable) { AddDrawable(drawable); } + + void RemoveChild(Node* node); + + inline void RemoveChild(Drawable* drawable) { RemoveDrawable(drawable); } + + void AddDrawable(Drawable* drawable); + + void RemoveDrawable(Drawable* drawable); + + void SetMatrix(const Math::Matrix4f& mat); + + [[nodiscard]] Math::Matrix3f GetRotationMatrix() const { return static_cast(localMat); } + + [[nodiscard]] const Math::Matrix4f& GetMatrix() const { return localMat; } + + [[nodiscard]] const Math::Matrix4f& GetWorldMatrix() const { return worldMat; } + + [[nodiscard]] bool IsEnabled() const { return enabled; } + + void Enable() { enabled = true; } + + void Disable() { enabled = false; } + + [[nodiscard]] Node* GetParent() const { return parent; } + + [[nodiscard]] Scene* GetScene() const { return scene; } + + [[nodiscard]] bool IsRoot() const { return scene && parent == this; } + + [[nodiscard]] UpdateFrequency GetUpdateFrequency() const { return matrixUpdateFrequency; } + + void SetUpdateFrequency(UpdateFrequency frequency) { - Always, Sometimes, Never - }; - - class Node : public virtual IInitable, public virtual ICloseable - { - friend Scene; + if (!children.empty()) throw std::runtime_error("The update must not be changed for nodes with children."); + this->matrixUpdateFrequency = frequency; + } - public: - Math::Matrix4f localMat, worldMat; - bool enabled = true; - Node* parent = nullptr; - Scene* scene = nullptr; - std::vector children; - std::vector drawables; - UpdateFrequency matrixUpdateFrequency = UpdateFrequency::Never; - ICloseable* renderNode = nullptr; + protected: + virtual void UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat); - public: - Node(); + private: + void SetParent(Node* parent); - ~Node() override; - - void Init() override; - - void Close() override; - - void AddChild(Node* node); - - inline void AddChild(Drawable* drawable) { AddDrawable(drawable); } - - void RemoveChild(Node* node); - - inline void RemoveChild(Drawable* drawable) { RemoveDrawable(drawable); } - - void AddDrawable(Drawable* drawable); - - void RemoveDrawable(Drawable* drawable); - - void SetMatrix(const Math::Matrix4f& mat); - - [[nodiscard]] Math::Matrix3f GetRotationMatrix() const { return static_cast(localMat); } - - [[nodiscard]] const Math::Matrix4f& GetMatrix() const { return localMat; } - - [[nodiscard]] const Math::Matrix4f& GetWorldMatrix() const { return worldMat; } - - [[nodiscard]] bool IsEnabled() const { return enabled; } - - void Enable() { enabled = true; } - - void Disable() { enabled = false; } - - [[nodiscard]] Node* GetParent() const { return parent; } - - [[nodiscard]] Scene* GetScene() const { return scene; } - - [[nodiscard]] bool IsRoot() const { return scene && parent == this; } - - [[nodiscard]] UpdateFrequency GetUpdateFrequency() const { return matrixUpdateFrequency; } - - void SetUpdateFrequency(UpdateFrequency frequency) - { - if (!children.empty()) throw std::runtime_error("The update must not be changed for nodes with children."); - this->matrixUpdateFrequency = frequency; - } - - protected: - virtual void UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat); - - private: - void SetParent(Node* parent); - - void SetScene(Scene* scene); - }; - } + void SetScene(Scene* scene); + }; } diff --git a/openVulkanoCpp/Scene/UpdateFrequency.hpp b/openVulkanoCpp/Scene/UpdateFrequency.hpp new file mode 100644 index 0000000..a2f12c7 --- /dev/null +++ b/openVulkanoCpp/Scene/UpdateFrequency.hpp @@ -0,0 +1,15 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#pragma once + +namespace openVulkanoCpp::Scene +{ + enum class UpdateFrequency : uint8_t + { + Always, Sometimes, Never + }; +}