| 339 | } |
| 340 | |
| 341 | void ToolsManager::selectWorldAt(glm::ivec2 mousePos) { |
| 342 | if (simulation == nullptr || renderer == nullptr || !renderer->get() || pickingSystem == nullptr || simulation->worldCount() == 0) { |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | BaseRenderer& rend = **renderer; |
| 347 | Lattice::Simulation::WorldId bestWorldId = simulation->activeWorldId(); |
| 348 | bool found = false; |
| 349 | float bestT = std::numeric_limits<float>::max(); |
| 350 | |
| 351 | if (rend.camera.getMode() == Camera::Mode::Mode2D) { |
| 352 | const glm::vec3 worldPos = rend.camera.screenToWorld(glm::ivec2(mousePos.x, mousePos.y)); |
| 353 | for (Lattice::Simulation::WorldId worldId = 0; worldId < simulation->worldCount(); ++worldId) { |
| 354 | const World& world = simulation->worldAt(worldId); |
| 355 | const glm::vec3 min = world.getRenderOffset(); |
| 356 | const glm::vec3 max = min + world.getWorldSize(); |
| 357 | if (worldPos.x >= min.x && worldPos.x <= max.x && worldPos.y >= min.y && worldPos.y <= max.y) { |
| 358 | bestWorldId = worldId; |
| 359 | found = true; |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | else { |
| 364 | const RenderRay ray = rend.camera.screenToRay(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y)); |
| 365 | for (Lattice::Simulation::WorldId worldId = 0; worldId < simulation->worldCount(); ++worldId) { |
| 366 | const World& world = simulation->worldAt(worldId); |
| 367 | const glm::vec3 min = world.getRenderOffset(); |
| 368 | const glm::vec3 max = min + world.getWorldSize(); |
| 369 | float hitT = 0.0f; |
| 370 | if (rayBoxIntersect(ray, min, max, hitT) && hitT < bestT) { |
| 371 | bestT = hitT; |
| 372 | bestWorldId = worldId; |
| 373 | found = true; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | if (found && bestWorldId != simulation->activeWorldId()) { |
| 379 | simulation->setActiveWorld(bestWorldId); |
| 380 | syncPickingWorldToActive(true); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | size_t ToolsManager::toIndex(Mode mode) noexcept { return static_cast<size_t>(mode); } |
nothing calls this directly
no test coverage detected