Brenta Engine 1.2
Loading...
Searching...
No Matches
node.cpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#include <brenta/renderer/renderer.hpp>
7#include <brenta/node.hpp>
8
9using namespace brenta;
10
11void Node::update_world_matrix()
12{
13 glm::mat4 parent_matrix = glm::mat4(1.0f);
14
15 if (auto parent_ptr = parent->lock())
16 {
17 parent_matrix = parent_ptr->world_matrix;
18 }
19
20 this->world_matrix = parent_matrix * this->transform.get_model_matrix();
21
22 for (auto& child : this->children)
23 child->update_world_matrix();
24}
25
26void Node::update(float delta_time)
27{
28 Script::current_node = this; // This is a big non-thread safe hack for now
29 if (this->script)
30 this->script->update(delta_time);
31
32 for (auto& component : this->components)
33 component->update(delta_time);
34
35 for (auto& child : this->children)
36 child->update(delta_time);
37 return;
38}
39
40void Node::draw()
41{
42 for (auto& component : this->components)
43 component->draw(this->world_matrix);
44
45 for (auto& child : this->children)
46 child->draw();
47 return;
48}