forked from rubenwardy/NodeBoxEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NodeBox.cpp
189 lines (162 loc) · 3.85 KB
/
NodeBox.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include "Nodebox.h"
void NodeBox::resizeNodeBoxFace(EditorState* editor,CDR_TYPE type,vector3df position,bool both){
switch(type){
case CDR_X_P:
if (both){
f32 new_opp = one.X - (position.X - two.X);
if (editor->Settings()->getSettingAsBool("limiting")==true){
if (new_opp > 0.5 || new_opp < -0.5)
return;
}
one.X = new_opp;
}
two.X = position.X;
break;
case CDR_X_N:
if (both){
f32 new_opp = two.X - (position.X - one.X);
if (editor->Settings()->getSettingAsBool("limiting")==true){
if (new_opp > 0.5 || new_opp < -0.5)
return;
}
two.X = new_opp;
}
one.X = position.X;
break;
case CDR_Y_P:
if (both){
f32 new_opp = one.Y - (position.Y - two.Y);
if (editor->Settings()->getSettingAsBool("limiting")==true){
if (new_opp > 0.5 || new_opp < -0.5)
return;
}
one.Y = new_opp;
}
two.Y = position.Y;
break;
case CDR_Y_N:
if (both){
f32 new_opp = two.Y - (position.Y - one.Y);
if (editor->Settings()->getSettingAsBool("limiting")==true){
if (new_opp > 0.5 || new_opp < -0.5)
return;
}
two.Y = new_opp;
}
one.Y = position.Y;
break;
case CDR_Z_P:
if (both){
f32 new_opp = one.Z - (position.Z - two.Z);
if (editor->Settings()->getSettingAsBool("limiting")==true){
if (new_opp > 0.5 || new_opp < -0.5)
return;
}
one.Z = new_opp;
}
two.Z = position.Z;
break;
case CDR_Z_N:
if (both){
f32 new_opp = two.Z - (position.Z - one.Z);
if (editor->Settings()->getSettingAsBool("limiting")==true){
if (new_opp > 0.5 || new_opp < -0.5)
return;
}
two.Z = new_opp;
}
one.Z = position.Z;
break;
}
}
void NodeBox::moveNodeBox(EditorState* editor,CDR_TYPE type,vector3df position){
vector3df new_one = one;
vector3df new_two = two;
vector3df move_dist = vector3df(0,0,0);
switch(type){
case CDR_XZ:
move_dist = vector3df(
position.X - GetCenter().X,
0,
position.Z - GetCenter().Z
);
break;
case CDR_XY:
move_dist = vector3df(
position.X - GetCenter().X,
position.Y - GetCenter().Y,
0
);
break;
case CDR_ZY:
move_dist = vector3df(
0,
position.Y - GetCenter().Y,
position.Z - GetCenter().Z
);
break;
}
if (move_dist.X != 0){
if ((
new_one.X+move_dist.X <= 0.5 &&
new_one.X+move_dist.X >= -0.5 &&
new_two.X+move_dist.X <= 0.5 &&
new_two.X+move_dist.X >= -0.5)||
!editor->Settings()->getSettingAsBool("limiting")
){
new_one.X+=move_dist.X;
new_two.X+=move_dist.X;
}
}
if (move_dist.Y != 0){
if ((
new_one.Y+move_dist.Y <= 0.5 &&
new_one.Y+move_dist.Y >= -0.5 &&
new_two.Y+move_dist.Y <= 0.5 &&
new_two.Y+move_dist.Y >= -0.5)||
!editor->Settings()->getSettingAsBool("limiting")
){
new_one.Y+=move_dist.Y;
new_two.Y+=move_dist.Y;
}
}
if (move_dist.Z != 0){
if ((
new_one.Z+move_dist.Z <= 0.5 &&
new_one.Z+move_dist.Z >= -0.5 &&
new_two.Z+move_dist.Z <= 0.5 &&
new_two.Z+move_dist.Z >= -0.5)||
!editor->Settings()->getSettingAsBool("limiting")){
new_one.Z+=move_dist.Z;
new_two.Z+=move_dist.Z;
}
}
one = new_one;
two = new_two;
}
void NodeBox::buildNode(vector3di nd_position,IrrlichtDevice* device){
video::IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
if (model){
model->remove();
model = NULL;
}
vector3df position = vector3df(
nd_position.X + one.X + ((two.X - one.X)/2),
nd_position.Y + one.Y + ((two.Y - one.Y)/2),
nd_position.Z + one.Z + ((two.Z - one.Z)/2)
);
vector3df size = vector3df(
two.X - one.X,
two.Y - one.Y,
two.Z - one.Z
);
// Create the scene node
model=smgr->addCubeSceneNode(1,0,-1,position);
if (!model)
return;
model->setMaterialTexture(0, driver->getTexture("media/texture_box.png"));
model->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
model->setName(name);
model->setScale(size);
}