7#include <glm/gtc/matrix_transform.hpp>
8#include <glm/gtc/quaternion.hpp>
70 glm::mat4 desiredWorld = glm::translate(glm::mat4(1.f), newLocation)
71 * glm::mat4_cast(currentRotation)
72 * glm::scale(glm::mat4(1.f), currentScale);
75 glm::mat4 parentInverse = glm::inverse(
parent->getWorldMatrix());
96 glm::mat4 desiredWorld = glm::translate(glm::mat4(1.f), currentPosition)
97 * glm::mat4_cast(newRotation)
98 * glm::scale(glm::mat4(1.f), currentScale);
100 glm::mat4 parentInverse = glm::inverse(
parent->getWorldMatrix());
107 rotateWorld(glm::quat(glm::radians(deltaRotation)));
113 glm::quat newRotation = deltaRotation * currentRotation;
128 glm::mat4 desiredWorld = glm::translate(glm::mat4(1.f), currentPosition)
129 * glm::mat4_cast(currentRotation)
130 * glm::scale(glm::mat4(1.f), newScale);
132 glm::mat4 parentInverse = glm::inverse(
parent->getWorldMatrix());
152 glm::mat4 parentInverse = glm::inverse(
parent->getWorldMatrix());
158 newChild->indexInParent =
children.size();
160 newChild->parent = shared_from_this();
164 size_t startIndex =
children.size();
166 for (
size_t i = 0; i < newChildren.size(); ++i) {
167 newChildren[i]->indexInParent = startIndex + i;
168 newChildren[i]->parent = shared_from_this();
174 child->parent =
nullptr;
180 size_t idx = child->indexInParent;
186 child->parent =
nullptr;
218 std::vector<std::weak_ptr<SceneNode>> weakChildren;
219 weakChildren.reserve(
children.size());
220 for (
const auto& child :
children) {
221 weakChildren.push_back(child);
233 for (
const auto& child :
children) {
234 child->markDirtyRecursive();
246 bool disableCaching) {
248 node->setWorldModelMatrix(transform.
matrix);
253 const bool disableCaching) {
255 throw std::invalid_argument(
"Parent node cannot be null when creating a new node");
258 auto node = std::shared_ptr<SceneNode>(
new SceneNode(registry, disableCaching));
259 parent->addChild(node);
260 node->registerWithEcs();
265 size_t count,
bool disableCaching) {
267 throw std::invalid_argument(
"Parent node cannot be null when creating nodes");
269 std::vector<std::shared_ptr<SceneNode>> nodes;
270 nodes.reserve(count);
272 for (
size_t i = 0; i < count; ++i) {
273 nodes.push_back(std::shared_ptr<SceneNode>(
new SceneNode(registry, disableCaching)));
275 parent->addChildren(nodes);
static entt::registry & get()
Gets the registry for all components.
static std::shared_ptr< SceneNode > createNode(const std::shared_ptr< SceneNode > &parent, const bool disableCaching=false)
Creates a new SceneNode with the specified parent.
static std::vector< std::shared_ptr< SceneNode > > createNodes(const std::shared_ptr< SceneNode > &parent, size_t count, bool disableCaching=false)
Creates multiple nodes under the same parent.
RootNode(entt::registry ®istry)
SceneGraph(const std::shared_ptr< SceneNode > &root)
Constructs a new Scene Graph object, initializing the root node.
std::shared_ptr< SceneNode > createNode(const Ecs::LocalTransform &transform, std::shared_ptr< SceneNode > parent, bool disableCaching=false)
Creates a node which tells you where an object is in the scene.
std::shared_ptr< SceneNode > root
Represents a node in the scene graph, containing information about its position, rotation,...
std::vector< std::shared_ptr< SceneNode > > children
void removeChild(const std::shared_ptr< SceneNode > &child)
Removes a single child from this node.
std::vector< std::weak_ptr< SceneNode > > getChildren() const
Get a list of all children of this node.
void setWorldScale(const glm::vec3 &newScale)
sets the scale for this node
void setWorldPosition(const glm::vec3 &newLocation)
Sets the world position of the scene node. This will calculate the corresponding local position based...
bool isWorldMatrixDirty() const
Checks if the world matrix has to be recalculated.
void setWorldRotation(const glm::vec3 &newRotation)
Sets the world rotation of this node with euler angles.
void addChild(const std::shared_ptr< SceneNode > &newChild)
Adds a child node to this node.
void clearChildren()
Removes all children from this node.
bool isRoot() const
Checks if this node is the root node.
const glm::mat4 & getWorldMatrix() const
get the world matrix as a raw glm matrix
void updateWorldMatrix() const
void rotateWorld(const glm::vec3 &deltaRotation)
Applies an incremental rotation to the current world rotation using quaternion multiplication....
void markDirtyRecursive()
Marks this node and its children as dirty.
void setLocalModelMatrix(const glm::mat4 &newModelMatrix)
Overwrites all components of the transform.
SceneNode(entt::registry ®istry, bool disableCaching=false)
Constructs a new Scene Node object.
entt::registry * registry
Ecs::LocalTransform & getLocalTransform()
Gets the local transform of the scene node. The local transform is relative to the parent node.
std::shared_ptr< SceneNode > parent
void setWorldModelMatrix(const glm::mat4 &newModelMatrix)
Overwrites all components of this transform.
void addChildren(std::vector< std::shared_ptr< SceneNode > > newChildren)
adds new children to this node
entt::entity getEntity() const
Gets the entity associated with this scene node.
Log category system implementation.
A struct which allows the engine to find out which SceneNode needs to propagate a dirty flag down the...