-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDebugVisual.h
208 lines (161 loc) · 5.42 KB
/
DebugVisual.h
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
#pragma once
#include "irrlicht.h"
#include "IrrManagers.h"
#include "DrawSphere.h"
#include <string>
#include <vector>
using namespace irr;
using namespace scene;
using namespace core;
using namespace video;
// Enum for debug types
enum class DebugType {
CAMERA = 0,
RAY_PICK,
LIGHT,
PARTICLE_SYSTEM,
EMPTY
};
class DebugSceneNode : public ISceneNode {
public:
// Constructor
DebugSceneNode(ISceneNode* parent, ISceneManager* smgr, s32 id, DebugType type)
: ISceneNode(parent, smgr, id), debugType(type) {
}
virtual void OnRegisterSceneNode() override {
SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
ISceneNode::OnRegisterSceneNode();
}
virtual void render() override {
switch (debugType) {
case DebugType::CAMERA:
renderCameraDebug();
break;
case DebugType::RAY_PICK:
renderRayPickDebug();
break;
case DebugType::LIGHT:
renderLightDebug();
break;
case DebugType::PARTICLE_SYSTEM:
renderParticleDebug();
break;
case DebugType::EMPTY:
renderEmptyDebug();
break;
}
}
// Set the debug type
void setDebugType(DebugType type) {
debugType = type;
}
// Access bounding box (required override)
virtual const aabbox3d<f32>& getBoundingBox() const override {
static aabbox3d<f32> dummyBox(vector3df(-1, -1, -1), vector3df(1, 1, 1));
return dummyBox;
}
virtual u32 getMaterialCount() const override {
return 0;
}
virtual SMaterial& getMaterial(u32 i) override {
static SMaterial dummyMaterial;
return dummyMaterial;
}
DebugType debugType;
Vector3D raypick_start;
Vector3D raypick_end;
bool raypick_hit;
float raypick_life;
float rad;
vector3df pos;
int val1;
int val2;
SColor col;
private:
void renderCameraDebug() {
float boxSize = 0.25;
vector3df nodePosition = getAbsolutePosition();
const aabbox3d<f32> box(
nodePosition - vector3df(boxSize, boxSize, boxSize),
nodePosition + vector3df(boxSize, boxSize, boxSize)
);
SMaterial m;
m.Lighting = false;
driver->setMaterial(m);
driver->setTransform(video::ETS_WORLD, core::matrix4());
driver->draw3DBox(box, SColor(255, 255, 0, 0));
vector3df start = nodePosition;
vector3df direction = getParent()->getRotation().rotationToDirection();
vector3df end = nodePosition + direction * 2;
driver->draw3DLine(start, end, SColor(255, 255, 0, 0));
}
void renderRayPickDebug() {
SMaterial m;
m.Lighting = false;
driver->setMaterial(m);
driver->setTransform(video::ETS_WORLD, core::matrix4());
vector3df end = vector3df(raypick_end.x, raypick_end.y, raypick_end.z);
driver->draw3DLine(
vector3df(raypick_start.x, raypick_start.y, raypick_start.z),
end,
SColor(255, 255 * !raypick_hit, 255 * raypick_hit, 0)
);
if (raypick_hit) {
float boxSize = 0.05;
const aabbox3d<f32> box(
end - vector3df(boxSize, boxSize, boxSize),
end + vector3df(boxSize, boxSize, boxSize)
);
driver->draw3DBox(box, SColor(255, 255 * !raypick_hit, 255 * raypick_hit, 0));
}
raypick_life -= irrHandler->dt;
if (raypick_life <= 0)
this->remove();
}
void renderLightDebug() {
SMaterial m;
m.Lighting = false;
driver->setMaterial(m);
driver->setTransform(video::ETS_WORLD, core::matrix4());
float boxSize = 0.125;
vector3df nodePosition = getAbsolutePosition();
aabbox3d<f32> box(
nodePosition - vector3df(boxSize, boxSize, boxSize),
nodePosition + vector3df(boxSize, boxSize, boxSize)
);
driver->draw3DBox(box, SColor(255, 255, 255, 0));
vector3df start = nodePosition;
vector3df direction = getParent()->getRotation().rotationToDirection();
vector3df end = nodePosition + direction * 1;
driver->draw3DLine(start, end, SColor(255, 255, 255, 0));
// val1 == is point light
if (rad > 0.0f && val1 == 1)
renderSphere(start, rad, 0, 10, 10, SColor(255, 255, 255, 0));
}
void renderParticleDebug() {
SMaterial m;
m.Lighting = false;
driver->setMaterial(m);
driver->setTransform(video::ETS_WORLD, core::matrix4());
float boxSize = 0.25;
vector3df nodePosition = getAbsolutePosition();
const aabbox3d<f32> box(
nodePosition - vector3df(boxSize, boxSize, boxSize),
nodePosition + vector3df(boxSize, boxSize, boxSize)
);
driver->draw3DBox(box, SColor(255, 160, 30, 240));
}
void renderEmptyDebug() {
SMaterial m;
m.Lighting = false;
driver->setMaterial(m);
driver->setTransform(video::ETS_WORLD, core::matrix4());
float boxSize = 0.125;
vector3df nodePosition = getAbsolutePosition();
const aabbox3d<f32> box(
nodePosition - vector3df(boxSize, boxSize, boxSize),
nodePosition + vector3df(boxSize, boxSize, boxSize)
);
driver->draw3DBox(box, SColor(255, 255, 255, 255));
}
};