#include "editNetwork.h" #include "imgui_wrap.h" #include #include #include #include EditNetwork::EditNetwork(Network * n) : network {n} { } bool EditNetwork::click(const SDL_MouseButtonEvent & event, const Ray & ray) { switch (event.button) { case SDL_BUTTON_MIDDLE: currentStart.reset(); candidates.clear(); return true; case SDL_BUTTON_LEFT: if (!currentStart) { currentStart = resolveRay(ray); } else { if (const auto def = resolveRay(ray)) { candidates = network->create( gameState->terrain.get(), CreationDefinition {.fromEnd = *currentStart, .toEnd = *def}); for (const auto & link : candidates) { network->add(gameState->terrain.get(), link); } if (continuousMode) { currentStart = def; currentStart->direction = candidates.back()->endAt(def->position)->dir; } else { currentStart.reset(); } candidates.clear(); } } return true; default: return false; } } bool EditNetwork::move(const SDL_MouseMotionEvent &, const Ray & ray) { if (currentStart) { if (const auto def = resolveRay(ray)) { candidates = network->create( gameState->terrain.get(), CreationDefinition {.fromEnd = *currentStart, .toEnd = *def}); } } return false; } bool EditNetwork::handleInput(const SDL_Event &) { return false; } void EditNetwork::render(const SceneShader &, const Frustum &) const { } std::optional EditNetwork::resolveRay(const Ray & ray) const { if (const auto position = gameState->terrain->intersectRay(ray)) { const auto node = network->intersectRayNodes(ray); if (node) { const auto direction = network->findNodeDirection(node); return CreationDefinitionEnd {.position = node->pos, .direction = direction}; } return CreationDefinitionEnd {.position = position->first, .direction = std::nullopt}; } return {}; } void EditNetwork::render(bool & open) { ImGui::SetNextWindowSize({-1, -1}); ImGui::Begin("Edit Network", &open); ImGui::Checkbox("Continuous mode", &continuousMode); ImGui::End(); }