Skip to content

Commit fce9497

Browse files
committed
Small tweaks
- swap Y and Z - move camera target - fix wasd - flip grid and turn on MSAA (still bad ants running effect)
1 parent b097669 commit fce9497

File tree

6 files changed

+95
-42
lines changed

6 files changed

+95
-42
lines changed

graphics/neurons/camera.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct Camera
2020
m_target.dest = { 0.0f, 0.0f, 0.0f };
2121

2222
m_pos.curr = { 2.0f, 3.0f, 4.0f };
23-
m_pos.dest = { 0.0f, 0.0f, 4.0f };
23+
m_pos.dest = { 5.0f, 9.0f, -12.0f };
2424

2525
m_orbit[0] = 0.0f;
2626
m_orbit[1] = 0.0f;

graphics/neurons/mnist_data_processor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ NeuronLayer MnistDataProcessor::prepare_neurons() const {
8888
auto ctx = std::make_shared<NeuronVisualContext>(neurons[i]);
8989
ctx->position = {
9090
float(i % area_size[0]),
91+
0.0f,
9192
float(i / area_size[0]),
92-
0.0f };
93+
};
9394
neurons[i]->render = std::make_shared<NeuronRenderStrategy>(ctx);
9495
}
9596

graphics/neurons/network.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void Network::addLayer(const NeuronLayer&& layer, const std::vector<size_t>& are
2525
}
2626

2727
void Network::addNeuron(const std::vector<int32_t>& pos, const NeuronLayer& connected_to) {
28-
uint32_t layer = pos[2];
28+
uint32_t layer = pos[1]; // y
2929
if (layer >= layers.size()) {
3030
layers.insert(layers.end(), layers.size() - layer + 1, {});
3131
// std::cerr << "wrong layer position\n";

graphics/neurons/neurons_gui.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,9 @@ namespace
194194
ImGui::SetNextWindowPos(ImVec2(0, 0));
195195
ImGui::SetNextWindowSize(ImVec2(leftPanelWidth, 0));
196196

197-
ImGui::Begin("MainDock",
197+
ImGui::Begin("Controls",
198198
nullptr,
199199
ImGuiWindowFlags_NoTitleBar |
200-
ImGuiWindowFlags_NoResize |
201200
ImGuiWindowFlags_NoMove |
202201
ImGuiWindowFlags_NoCollapse);
203202

@@ -351,6 +350,18 @@ namespace
351350
m_camera.dolly(float(m_mouse.m_scroll) * 0.05f);
352351
}
353352
}
353+
354+
const float camera_step = 3.0f;
355+
if (ImGui::IsKeyPressed(ImGuiKey_RightArrow))
356+
m_camera.m_target.dest.x += camera_step;
357+
if (ImGui::IsKeyPressed(ImGuiKey_LeftArrow))
358+
m_camera.m_target.dest.x -= camera_step;
359+
360+
if (ImGui::IsKeyPressed(ImGuiKey_UpArrow))
361+
m_camera.m_target.dest.z += camera_step;
362+
if (ImGui::IsKeyPressed(ImGuiKey_DownArrow))
363+
m_camera.m_target.dest.z -= camera_step;
364+
354365
m_camera.update(deltaTimeSec);
355366
// bx::memCopy(m_uniforms.m_cameraPos, &m_camera.m_pos.curr.x, 3*sizeof(float) );
356367

graphics/neurons/render/ground.hpp

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ struct Ground {
99
bgfx::ViewId viewId;
1010
bgfx::VertexBufferHandle m_vbhGround;
1111
bgfx::IndexBufferHandle m_ibhGround;
12+
13+
std::vector<PosColorVertex> gridVerts;
14+
std::vector<uint16_t> gridIndices;
1215
bgfx::VertexBufferHandle m_vbhGrid;
1316
bgfx::IndexBufferHandle m_ibhGrid;
1417

@@ -25,10 +28,10 @@ struct Ground {
2528

2629
void make_ground() {
2730
static PosColorVertex s_groundVertices[4] = {
28-
{ -1.0f, 1.0f, 0.0f, 0xff696969 },
29-
{ 1.0f, 1.0f, 0.0f, 0xff696969 },
30-
{ -1.0f, -1.0f, 0.0f, 0xff696969 },
31-
{ 1.0f, -1.0f, 0.0f, 0xff696969 },
31+
{ -1.0f, 0.0f, 1.0f, 0xff696969 },
32+
{ 1.0f, 0.0f, 1.0f, 0xff696969 },
33+
{ -1.0f, 0.0f, -1.0f, 0xff696969 },
34+
{ 1.0f, 0.0f, -1.0f, 0xff696969 },
3235
};
3336

3437
static const uint16_t s_groundIndices[] = {
@@ -51,35 +54,49 @@ struct Ground {
5154
void make_grid() {
5255
// grid
5356

54-
std::vector<PosColorVertex> gridVerts;
55-
std::vector<uint16_t> gridIndices;
57+
5658

5759
const int gridSize = 20;
58-
const float spacing = 1.0f;
60+
const float cube = 2.0f;
61+
const float offset = 1.0f;
62+
const float spacing = cube + offset;
5963

6064
uint16_t idx = 0;
61-
for (int i = -gridSize; i <= gridSize; ++i) {
65+
for (int i = -gridSize / 2; i < gridSize / 2; ++i) {
6266
float x = i * spacing;
6367
float zmin = -gridSize * spacing;
6468
float zmax = gridSize * spacing;
6569

66-
uint32_t color = (i == 0 ? 0xffffffff : 0xff404040);
70+
uint32_t color = 0xff404040;
6771

68-
gridVerts.push_back({ x, 0.01f, zmin, color });
69-
gridVerts.push_back({ x, 0.01f, zmax, color });
70-
gridIndices.push_back(idx++);
71-
gridIndices.push_back(idx++);
72+
gridVerts.push_back({ x, 0.0f, zmin, color });
73+
gridVerts.push_back({ x + 0.01f, 0.0f, zmin, color });
74+
gridVerts.push_back({ x, 0.0f, zmax, color });
75+
gridVerts.push_back({ x + 0.01f, 0.0f, zmax, color });
76+
gridIndices.push_back(idx + 0);
77+
gridIndices.push_back(idx + 1);
78+
gridIndices.push_back(idx + 2);
79+
gridIndices.push_back(idx + 1);
80+
gridIndices.push_back(idx + 3);
81+
gridIndices.push_back(idx + 2);
82+
idx += 4;
7283

7384
float z = i * spacing;
7485
float xmin = -gridSize * spacing;
7586
float xmax = gridSize * spacing;
7687

77-
color = (i == 0 ? 0xffffffff : 0xff404040);
78-
79-
gridVerts.push_back({ xmin, 0.01f, z, color });
80-
gridVerts.push_back({ xmax, 0.01f, z, color });
81-
gridIndices.push_back(idx++);
82-
gridIndices.push_back(idx++);
88+
gridVerts.push_back({ xmax, 0.0f, z, color });
89+
gridVerts.push_back({ xmax, 0.0f, z + 0.01f, color });
90+
gridVerts.push_back({ xmin, 0.0f, z, color });
91+
gridVerts.push_back({ xmin, 0.0f, z + 0.01f, color });
92+
gridIndices.push_back(idx + 0);
93+
gridIndices.push_back(idx + 1);
94+
gridIndices.push_back(idx + 2);
95+
gridIndices.push_back(idx + 1);
96+
gridIndices.push_back(idx + 3);
97+
gridIndices.push_back(idx + 2);
98+
idx += 4;
99+
83100
}
84101

85102
m_vbhGrid = bgfx::createVertexBuffer(
@@ -94,12 +111,14 @@ struct Ground {
94111

95112
void draw() {
96113
draw_ground();
97-
// draw_grid();
114+
draw_grid();
98115

99-
DebugDrawEncoder dde;
100-
dde.begin(viewId); // viewId
116+
// DebugDrawEncoder dde;
117+
// dde.begin(viewId); // viewId
101118

102-
dde.drawGrid(Axis::Y, { 0.0f, 0.0f, 0.0f });
119+
// dde.drawGrid(Axis::Y, { 0.0f, 0.0f, 0.0f });
120+
121+
103122
// const int gridSize = 20;
104123
// const float spacing = 1.0f;
105124

@@ -116,16 +135,16 @@ struct Ground {
116135
// // optional axes
117136
// dde.drawAxis(0.0f, 0.0f, 0.0f);
118137

119-
dde.end();
138+
// dde.end();
120139
}
121140

122141
void draw_ground() {
123142
float selMtx[16];
124143
bx::mtxIdentity(selMtx);
125144
bx::mtxSRT(selMtx,
126-
10.0f, 10.0f, 1.0f, // scale
145+
50.0f, 1.0f, 50.0f, // scale
127146
0.0f, 0.0f, 0.0f, // rotation
128-
0.0f,0.0f, -3.0f);// translation
147+
0.0f,-1.0f, 0.0f);// translation
129148
// bx::mtxTranslate(selMtx, -12.0f, -12.0f, 0.0f);
130149
bgfx::setTransform(selMtx);
131150

@@ -144,9 +163,30 @@ struct Ground {
144163
}
145164

146165
void draw_grid() {
166+
167+
float selMtx[16];
168+
bx::mtxIdentity(selMtx);
169+
bx::mtxSRT(selMtx,
170+
1.0f, 1.0f, 1.0f, // scale
171+
0.0f, 0.0f, 0.0f, // rotation
172+
-1.5f,-1.0f, -1.5f);// translation
173+
// bx::mtxTranslate(selMtx, -12.0f, -12.0f, 0.0f);
174+
bgfx::setTransform(selMtx);
175+
176+
float m_color[4];
177+
178+
m_color[0] = 0.1f;
179+
m_color[1] = 0.1f;
180+
m_color[2] = 0.1f;
181+
m_color[3] = 1.0f;
182+
bgfx::setUniform(u_color, m_color);
183+
147184
bgfx::setVertexBuffer(0, m_vbhGrid);
148185
bgfx::setIndexBuffer(m_ibhGrid);
149-
bgfx::setState(BGFX_STATE_DEFAULT);
186+
bgfx::setState(BGFX_STATE_WRITE_RGB |
187+
BGFX_STATE_DEPTH_TEST_LESS |
188+
BGFX_STATE_CULL_CW |
189+
BGFX_STATE_MSAA);
150190
bgfx::submit(viewId, m_program);
151191
}
152192

graphics/neurons/render/network_render.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ void NetworkRenderStrategy::addLayer(const NeuronLayer& layer, const std::vector
9494

9595
void NetworkRenderStrategy::update(float dt) {
9696
if (ImGui::IsKeyPressed(ImGuiKey_W))
97-
selected_y = std::max(0, selected_y - 1);
97+
selected_z = std::min(max_area_size - 1, selected_z + 1);
9898
if (ImGui::IsKeyPressed(ImGuiKey_S))
99-
selected_y = std::min(max_area_size - 1, selected_y + 1);
99+
selected_z = std::max(0, selected_z - 1);
100100

101-
if (ImGui::IsKeyPressed(ImGuiKey_A))
102-
selected_x = std::max(0, selected_x - 1);
103101
if (ImGui::IsKeyPressed(ImGuiKey_D))
104102
selected_x = std::min(max_area_size - 1, selected_x + 1);
103+
if (ImGui::IsKeyPressed(ImGuiKey_A))
104+
selected_x = std::max(0, selected_x - 1);
105105

106106
if (ImGui::IsKeyPressed(ImGuiKey_R))
107-
selected_z = std::max(0, selected_z - 1);
107+
selected_y = std::min(max_area_size - 1, selected_y + 1);
108108
if (ImGui::IsKeyPressed(ImGuiKey_F))
109-
selected_z = std::min(max_area_size - 1, selected_z + 1);
109+
selected_y = std::max(0, selected_y - 1);
110110

111111
if (ImGui::IsKeyPressed(ImGuiKey_Space)) {
112112
std::vector<int32_t> pos = { selected_x, selected_y, selected_z };
@@ -175,12 +175,13 @@ void NetworkRenderStrategy::drawNeurons(float time) {
175175
// | 2 6 10 14 |
176176
// | 3 7 11 15 |
177177

178-
mtx[12] = start_x + float(xx) * offset;
179-
mtx[13] = start_y + float(yy) * offset;
180-
mtx[14] = start_z + float(zz) * offset;
178+
bx::mtxTranslate(mtx,
179+
start_x + float(xx) * offset,
180+
start_y + float(yy) * offset,
181+
start_z + float(zz) * offset
182+
);
181183

182184
float* color = (float*)&data[64];
183-
184185
float r = neuron->v;
185186
color[0] = r;
186187
color[1] = 0.0f;

0 commit comments

Comments
 (0)