44#include " network_render.h"
55#include " neuron_render.hpp"
66
7+
78void NetworkRenderStrategy::init () {
89 m_lastFrameMissing = 0 ;
910 // 80 bytes stride = 64 bytes for 4x4 matrix + 16 bytes for RGBA color.
@@ -92,18 +93,26 @@ void NetworkRenderStrategy::update(float dt) {
9293 if (ImGui::IsKeyPressed (ImGuiKey_W))
9394 selected_y = std::max (0 , selected_y - 1 );
9495 if (ImGui::IsKeyPressed (ImGuiKey_S))
95- selected_y = std::min (area_size_y - 1 , selected_y + 1 );
96+ selected_y = std::min (max_area_size - 1 , selected_y + 1 );
9697
9798 if (ImGui::IsKeyPressed (ImGuiKey_A))
9899 selected_x = std::max (0 , selected_x - 1 );
99100 if (ImGui::IsKeyPressed (ImGuiKey_D))
100- selected_x = std::min (area_size_x - 1 , selected_x + 1 );
101+ selected_x = std::min (max_area_size - 1 , selected_x + 1 );
101102
102103 if (ImGui::IsKeyPressed (ImGuiKey_R))
103- selected_x = std::max (0 , selected_z - 1 );
104+ selected_z = std::max (0 , selected_z - 1 );
104105 if (ImGui::IsKeyPressed (ImGuiKey_F))
105- selected_x = std::min (area_size_z - 1 , selected_z + 1 );
106+ selected_z = std::min (max_area_size - 1 , selected_z + 1 );
107+
108+ if (ImGui::IsKeyPressed (ImGuiKey_Space)) {
109+ std::vector<int32_t > pos = { selected_x, selected_y, selected_z };
110+ if (selected_neuron == nullptr ) {
111+ // create neuron
112+ ctx->net .addNeuron (pos, {});
113+ }
106114
115+ }
107116 // to total number of instances to draw
108117 uint32_t totalCubes = ctx->net .neurons .size ();
109118
@@ -119,7 +128,7 @@ void NetworkRenderStrategy::update(float dt) {
119128 }
120129}
121130
122- void NetworkRenderStrategy::drawNeurons (float time) const {
131+ void NetworkRenderStrategy::drawNeurons (float time) {
123132 bgfx::InstanceDataBuffer idb;
124133 bgfx::allocInstanceDataBuffer (&idb, drawnCubes, instanceStride);
125134
@@ -130,14 +139,22 @@ void NetworkRenderStrategy::drawNeurons(float time) const {
130139 const float start_y = - area_size_y * offset / 2 .0f ;
131140 const float start_z = - area_size_z * offset / 2 .0f ;
132141
142+ // reset the selection
143+ selected_neuron = nullptr ;
144+
133145 for (uint32_t ii = 0 ; ii < drawnCubes; ++ii)
134146 {
135147 const auto & neuron = ctx->net .neurons [ii];
136148
137149 std::shared_ptr<NeuronRenderStrategy>& s = std::dynamic_pointer_cast<NeuronRenderStrategy>(neuron->render );
138150 bx::Vec3 pos = s->get_position ();
139- uint32_t yy = pos.y ;
140151 uint32_t xx = pos.x ;
152+ uint32_t yy = pos.y ;
153+ uint32_t zz = pos.z ;
154+
155+ if (xx == selected_x && yy == selected_y && zz == selected_z) {
156+ selected_neuron = neuron;
157+ }
141158
142159 float * mtx = (float *)data;
143160 time = 0 .0f ;
@@ -156,7 +173,7 @@ void NetworkRenderStrategy::drawNeurons(float time) const {
156173
157174 mtx[12 ] = start_x + float (xx) * offset;
158175 mtx[13 ] = start_y + float (yy) * offset;
159- mtx[14 ] = 0 . 0f ;
176+ mtx[14 ] = start_z + float (zz) * offset ;
160177
161178 float * color = (float *)&data[64 ];
162179
@@ -187,7 +204,7 @@ void NetworkRenderStrategy::drawNeurons(float time) const {
187204 bgfx::submit (0 , m_program);
188205}
189206
190- void NetworkRenderStrategy::drawSelection (float time) const {
207+ void NetworkRenderStrategy::drawSelection (float time) {
191208
192209 const float offset = 3 .0f ;
193210 const float start_x = - area_size_x * offset / 2 .0f ;
@@ -215,7 +232,7 @@ void NetworkRenderStrategy::drawSelection(float time) const {
215232 bgfx::submit (0 , m_selection_program);
216233}
217234
218- void NetworkRenderStrategy::draw (float time) const {
235+ void NetworkRenderStrategy::draw (float time) {
219236 if (drawnCubes > 0 ) {
220237 drawNeurons (time);
221238 }
0 commit comments