diff --git a/modules/base/rendering/renderabletrailtrajectory.cpp b/modules/base/rendering/renderabletrailtrajectory.cpp index ee019b8827..476e064e43 100644 --- a/modules/base/rendering/renderabletrailtrajectory.cpp +++ b/modules/base/rendering/renderabletrailtrajectory.cpp @@ -333,6 +333,25 @@ void RenderableTrailTrajectory::update(const UpdateData& data) { } glBindVertexArray(0); + + // Updating bounding sphere + glm::vec3 maxVertex(-std::numeric_limits::max()); + glm::vec3 minVertex(std::numeric_limits::max()); + + auto setMax = [&maxVertex, &minVertex](const TrailVBOLayout& vertexData) { + maxVertex.x = std::max(maxVertex.x, vertexData.x); + maxVertex.y = std::max(maxVertex.y, vertexData.y); + maxVertex.z = std::max(maxVertex.z, vertexData.z); + + minVertex.x = std::min(minVertex.x, vertexData.x); + minVertex.y = std::min(minVertex.y, vertexData.y); + minVertex.z = std::min(minVertex.z, vertexData.z); + }; + + std::for_each(_vertexArray.begin(), _vertexArray.end(), setMax); + + setBoundingSphere(glm::distance(maxVertex, minVertex) / 2.0); + } } // namespace openspace