forked from rubenwardy/NodeBoxEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.cpp
103 lines (82 loc) · 1.57 KB
/
Node.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "Node.h"
Node::Node(IrrlichtDevice* mdevice,EditorState* state)
:_device(mdevice),_state(state),number(0),_id(-1)
{
for (int i=0;i<NODEB_MAX;i++){
boxes[i] = NULL;
}
}
Node::~Node(){
for (int i=0;i<NODEB_MAX;i++){
if (boxes[i])
delete boxes[i];
}
}
NodeBox* Node::GetCurrentNodeBox(){
return GetNodeBox(GetId());
}
NodeBox* Node::GetNodeBox(int id){
if (id==-1)
return NULL;
return boxes[id];
}
// Operation functions
NodeBox* Node::addNodeBox(){
if (!number)
number = 0;
// Name it
core::stringc nb="NodeBox";
nb+=(number+1);
// Set up structure
NodeBox* tmp =new NodeBox(nb,vector3df(0,-0.5,-0.5),vector3df(0.5,0.5,0.5));
if (!tmp)
return NULL;
boxes[number] = tmp;
select(number);
tmp->buildNode(getPosition(),_device);
// Increment and print message
number++;
printf("Nodebox added\n");
// Clean up list
defrag();
return tmp;
}
void Node::deleteNodebox(int id){
if (!GetNodeBox(id))
return;
delete boxes[id];
boxes[id] = NULL;
defrag();
}
// Build node models
void Node::remesh(){
for (int i=0;i<NODEB_MAX;i++){
NodeBox* box = GetNodeBox(i);
if (box)
box->buildNode(getPosition(),_device);
}
}
// Private functions
void Node::defrag(){
int a=0;
for (int i=0;i<NODEB_MAX;i++){
if (boxes[i]!=NULL){
boxes[a]=boxes[i];
if (GetId()==i)
_id=a;
a++;
}else{
boxes[a]=NULL;
}
}
number = a;
#ifdef _DEBUG
for (int i=0;i<NODEB_MAX;i++){
if (boxes[i]!=NULL && boxes[i]->model->getName()){
printf("%i> ",i);
printf("%s \n",boxes[i]->model->getName());
}
}
printf("There are %i boxes\n",a);
#endif
}