99 lines
2.4 KiB
C++
99 lines
2.4 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 "Base/IInitable.hpp"
|
|
#include "Base/ICloseable.hpp"
|
|
#include "Math/Math.hpp"
|
|
#include "Drawable.hpp"
|
|
#include <vector>
|
|
|
|
namespace openVulkanoCpp
|
|
{
|
|
namespace Scene
|
|
{
|
|
class Scene;
|
|
|
|
enum class UpdateFrequency
|
|
{
|
|
Always, Sometimes, Never
|
|
};
|
|
|
|
class Node : public virtual IInitable, public virtual ICloseable
|
|
{
|
|
friend Scene;
|
|
|
|
public:
|
|
Math::Matrix4f 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(const Math::Matrix4f& mat);
|
|
|
|
[[nodiscard]] Math::Matrix3f GetRotationMatrix() const { return static_cast<const Math::Matrix3f>(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);
|
|
};
|
|
}
|
|
}
|