| 15 | namespace CesiumGeometry { |
| 16 | |
| 17 | CullingVolume createCullingVolume( |
| 18 | const glm::dvec3& position, |
| 19 | const glm::dvec3& direction, |
| 20 | const glm::dvec3& up, |
| 21 | const double fovx, |
| 22 | const double fovy) noexcept { |
| 23 | const double t = glm::tan(0.5 * fovy); |
| 24 | const double b = -t; |
| 25 | const double r = glm::tan(0.5 * fovx); |
| 26 | const double l = -r; |
| 27 | |
| 28 | const double positionLen = glm::length(position); |
| 29 | const double n = std::max( |
| 30 | 1.0, |
| 31 | std::nextafter(positionLen, std::numeric_limits<double>::max()) - |
| 32 | positionLen); |
| 33 | |
| 34 | // TODO: this is all ported directly from CesiumJS, can probably be refactored |
| 35 | // to be more efficient with GLM. |
| 36 | |
| 37 | const glm::dvec3 right = glm::cross(direction, up); |
| 38 | |
| 39 | glm::dvec3 nearCenter = direction * n; |
| 40 | nearCenter = position + nearCenter; |
| 41 | |
| 42 | // Left plane computation |
| 43 | glm::dvec3 normal = right * l; |
| 44 | normal = nearCenter + normal; |
| 45 | normal = normal - position; |
| 46 | normal = glm::normalize(normal); |
| 47 | normal = glm::cross(normal, up); |
| 48 | normal = glm::normalize(normal); |
| 49 | |
| 50 | const CesiumGeometry::Plane leftPlane(normal, -glm::dot(normal, position)); |
| 51 | |
| 52 | // Right plane computation |
| 53 | normal = right * r; |
| 54 | normal = nearCenter + normal; |
| 55 | normal = normal - position; |
| 56 | normal = glm::cross(up, normal); |
| 57 | normal = glm::normalize(normal); |
| 58 | |
| 59 | const CesiumGeometry::Plane rightPlane(normal, -glm::dot(normal, position)); |
| 60 | |
| 61 | // Bottom plane computation |
| 62 | normal = up * b; |
| 63 | normal = nearCenter + normal; |
| 64 | normal = normal - position; |
| 65 | normal = glm::cross(right, normal); |
| 66 | normal = glm::normalize(normal); |
| 67 | |
| 68 | const CesiumGeometry::Plane bottomPlane(normal, -glm::dot(normal, position)); |
| 69 | |
| 70 | // Top plane computation |
| 71 | normal = up * t; |
| 72 | normal = nearCenter + normal; |
| 73 | normal = normal - position; |
| 74 | normal = glm::cross(normal, right); |
no test coverage detected