| 15 | |
| 16 | namespace { |
| 17 | bool rayBoxIntersect(const RenderRay& ray, const glm::vec3& min, const glm::vec3& max, float& hitT) { |
| 18 | float tMin = 0.0f; |
| 19 | float tMax = std::numeric_limits<float>::max(); |
| 20 | |
| 21 | const auto testAxis = [&](double origin, double dir, double axisMin, double axisMax) { |
| 22 | if (std::abs(dir) < 1e-6) { |
| 23 | return origin >= axisMin && origin <= axisMax; |
| 24 | } |
| 25 | |
| 26 | float t1 = static_cast<float>((axisMin - origin) / dir); |
| 27 | float t2 = static_cast<float>((axisMax - origin) / dir); |
| 28 | if (t1 > t2) { |
| 29 | std::swap(t1, t2); |
| 30 | } |
| 31 | |
| 32 | tMin = std::max(tMin, t1); |
| 33 | tMax = std::min(tMax, t2); |
| 34 | return tMin <= tMax; |
| 35 | }; |
| 36 | |
| 37 | if (!testAxis(ray.origin.x, ray.dir.x, min.x, max.x) || !testAxis(ray.origin.y, ray.dir.y, min.y, max.y) || |
| 38 | !testAxis(ray.origin.z, ray.dir.z, min.z, max.z)) { |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | hitT = tMin; |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | ToolsManager::Mode mapPanelTool(SideToolsPanel::Tool tool) { |
| 47 | switch (tool) { |