96 lines
2.2 KiB
C++
96 lines
2.2 KiB
C++
/*
|
|
* 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
|
|
|
|
#include <vector>
|
|
#include <glm/glm.hpp>
|
|
#include "../Base/ICloseable.hpp"
|
|
#include "Drawable.hpp"
|
|
|
|
namespace openVulkanoCpp
|
|
{
|
|
namespace Scene
|
|
{
|
|
class Scene;
|
|
|
|
enum class UpdateFrequency
|
|
{
|
|
Always, Sometimes, Never
|
|
};
|
|
|
|
struct Node : virtual IInitable, virtual ICloseable
|
|
{
|
|
friend Scene;
|
|
|
|
public:
|
|
glm::mat4x4 localMat, worldMat;
|
|
bool enabled = true;
|
|
Node* parent = nullptr;
|
|
Scene* scene = nullptr;
|
|
std::vector<Node*> children;
|
|
std::vector<Drawable*> 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(glm::mat4x4 mat);
|
|
|
|
[[nodiscard]] const glm::mat4x4& GetMatrix() const { return localMat; }
|
|
|
|
[[nodiscard]] const glm::mat4x4& 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 glm::mat4x4& parentWorldMat);
|
|
|
|
private:
|
|
void SetParent(Node* parent);
|
|
|
|
void SetScene(Scene* scene);
|
|
};
|
|
}
|
|
}
|