-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTrail.cpp
208 lines (170 loc) · 4.39 KB
/
Trail.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include "Trail.h"
Trail::Trail() {
empty = smgr->addEmptySceneNode();
trailWidth = 10.0f;
segments = 64;
mode = 3;
make();
}
void Trail::make() {
irr::video::SMaterial cur;
cur.Lighting = false;
if (t) {
cur = t->getMaterial(0);
t->remove();
}
t = new ghostTrailSceneNode(empty, smgr, -1, trailWidth, segments);
t->getMaterial(0) = cur;
setAlignmentMode(mode);
}
void Trail::destroy() {
if (t) {
t->remove();
empty->remove();
}
}
bool Trail::getVisibility() const {
return t ? t->isVisible() : false;
}
void Trail::setVisibility(bool visible) {
t->setVisible(visible);
}
Vector3D Trail::getPosition() {
if (!t)
return Vector3D();
return Vector3D(empty->getPosition().X, empty->getPosition().Y, empty->getPosition().Z);
}
void Trail::setPosition(const Vector3D& pos) {
if (!t)
return;
empty->setPosition(irr::core::vector3df(pos.x, pos.y, pos.z));
}
Vector3D Trail::getRotation() {
if (!t)
return Vector3D();
return Vector3D(empty->getRotation().X, empty->getRotation().Y, empty->getRotation().Z);
}
void Trail::setRotation(const Vector3D& rot) {
if (!t)
return;
empty->setRotation(irr::core::vector3df(rot.x, rot.y, rot.z));
}
Vector3D Trail::getScale() {
if (!t)
return Vector3D();
return Vector3D(empty->getScale().X, empty->getScale().Y, empty->getScale().Z);
}
void Trail::setScale(const Vector3D& scale) {
if (!t)
return;
empty->setScale(irr::core::vector3df(scale.x, scale.y, scale.z));
}
float Trail::getWidth() {
return t ? trailWidth : 0.0f;
}
void Trail::setWidth(float w) {
if (!t)
return;
t->setTrailWidth(w);
trailWidth = w;
}
int Trail::getSegments() {
return t ? segments : 0;
}
void Trail::setSegments(int s) {
if (!t)
return;
segments = s;
make();
}
Vector3D Trail::getWind() {
return t ? wind : Vector3D();
}
void Trail::setWind(const Vector3D& w) {
if (!t)
return;
wind = w;
t->setWind(irr::core::vector3df(wind.x, wind.y, wind.z));
}
bool Trail::getDebug() {
if (t)
return t->isDebugDataVisible();
return false;
}
void Trail::setDebug(bool visible) {
if (t) {
if (visible)
t->setDebugDataVisible(irr::scene::EDS_FULL);
else
t->setDebugDataVisible(irr::scene::EDS_OFF);
}
}
bool Trail::loadMaterial(const Material& material) {
if (!t) return false;
t->getMaterial(0) = material.mat;
t->getMaterial(0).Lighting = false;
return true;
}
void Trail::exclude() {
if (t)
effects->excludeNodeFromLightingCalculations(t);
}
int Trail::getShadows() {
return t ? shadow : 0;
}
void Trail::setShadows(int i) {
if (t) {
shadow = i;
E_SHADOW_MODE mode = (E_SHADOW_MODE)i;
if (!hadShadow && (mode == E_SHADOW_MODE::ESM_BOTH || mode == E_SHADOW_MODE::ESM_CAST)) {
effects->addShadowToNode(t, irrHandler->defaultShadowFiltering, (E_SHADOW_MODE)shadow);
hadShadow = true;
}
else if (hadShadow) {
effects->removeShadowFromNode(t);
hadShadow = false;
}
}
}
void Trail::setUpdateNormals(bool enable) {
if (t)
t->setUpdateNormals(enable);
}
int Trail::getAlignmentMode() {
return t ? mode : 0;
}
void Trail::setAlignmentMode(int m) {
if (t) {
t->setAlignmentMode((ghostTrailSceneNode::E_ALIGNMENT_MODE)m);
mode = m;
}
}
float Trail::getFixedSize() {
return t ? t->getFixedSize() : 0.0f;
}
void Trail::setFixedSize(float s) {
if (t)
t->setFixedSize(s);
}
void bindTrail() {
sol::usertype<Trail> bind_type = lua->new_usertype<Trail>("Trail",
sol::constructors<Trail()>(),
sol::base_classes, sol::bases<Compatible3D>(),
"visible", sol::property(&Trail::getVisibility, &Trail::setVisibility),
"position", sol::property(&Trail::getPosition, &Trail::setPosition),
"rotation", sol::property(&Trail::getRotation, &Trail::setRotation),
"scale", sol::property(&Trail::getScale, &Trail::setScale),
"debug", sol::property(&Trail::getDebug, &Trail::setDebug),
"shadows", sol::property(&Trail::getShadows, &Trail::setShadows),
"width", sol::property(&Trail::getWidth, &Trail::setWidth),
"wind", sol::property(&Trail::getWind, &Trail::setWind),
"segments", sol::property(&Trail::getSegments, &Trail::setSegments),
"alignment", sol::property(&Trail::getAlignmentMode, &Trail::setAlignmentMode),
"fixedLength", sol::property(&Trail::getFixedSize, &Trail::setFixedSize)
);
bind_type["destroy"] = &Trail::destroy;
bind_type["setParent"] = &Trail::setParent;
bind_type["loadMaterial"] = &Trail::loadMaterial;
bind_type["ignoreLighting"] = &Trail::exclude;
bind_type["updateNormals"] = &Trail::setUpdateNormals;
}