-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscene_graph.cpp
61 lines (50 loc) · 1.13 KB
/
scene_graph.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "scene_graph.h"
SceneGraph::SceneGraph()
{
matrixStack.reserve(10);
currentMatrix = glm::mat4(1.f);
matrixStack.push_back(currentMatrix);
}
void SceneGraph::PushMatrix(const glm::mat4& matrix)
{
currentMatrix *= matrix;
matrixStack.push_back(currentMatrix);
}
void SceneGraph::PopMatrix()
{
if (matrixStack.size() > 1) {
matrixStack.pop_back();
currentMatrix = matrixStack.back();
}
}
const glm::mat4 SceneGraph::getModelViewMatrix() const
{
return currentMatrix;
}
void SceneGraph::Render()
{
if (root != nullptr) {
root->render();
}
}
const SceneNode* SceneGraph::getNode(const std::string& identifier) const
{
if (root == nullptr) return nullptr;
return root->getChild(identifier);
}
void SceneGraph::AddNode(SceneNode* childNode)
{
if (root == nullptr) {
root = new SceneNode("root");
root->setGraph(this);
}
root->addChild(childNode);
}
void SceneGraph::Addnode(const std::string& identifier, SceneNode* childNode)
{
if (root == nullptr) {
root = new SceneNode("root");
root->setGraph(this);
}
root->addChild(identifier, childNode);
}