diff options
Diffstat (limited to 'src/mbgl/util/bounding_volumes.cpp')
-rw-r--r-- | src/mbgl/util/bounding_volumes.cpp | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/src/mbgl/util/bounding_volumes.cpp b/src/mbgl/util/bounding_volumes.cpp index ccad4d95af..fc3419342c 100644 --- a/src/mbgl/util/bounding_volumes.cpp +++ b/src/mbgl/util/bounding_volumes.cpp @@ -8,7 +8,7 @@ namespace mbgl { namespace { vec3 toVec3(const vec4& v) { - return vec3{v[0], v[1], v[2]}; + return vec3{{v[0], v[1], v[2]}}; } double vec4Dot(const vec4& a, const vec4& b) { @@ -33,14 +33,14 @@ static Point<double> ProjectPointsToAxis(const std::array<vec3, N>& points, cons namespace util { -AABB::AABB() : min({0, 0, 0}), max({0, 0, 0}) {} +AABB::AABB() : min({{0, 0, 0}}), max({{0, 0, 0}}) {} AABB::AABB(const vec3& min_, const vec3& max_) : min(min_), max(max_) {} vec3 AABB::closestPoint(const vec3& point) const { - return {std::max(std::min(max[0], point[0]), min[0]), - std::max(std::min(max[1], point[1]), min[1]), - std::max(std::min(max[2], point[2]), min[2])}; + return {{std::max(std::min(max[0], point[0]), min[0]), + std::max(std::min(max[1], point[1]), min[1]), + std::max(std::min(max[2], point[2]), min[2])}}; } vec3 AABB::distanceXYZ(const vec3& point) const { @@ -62,8 +62,8 @@ AABB AABB::quadrant(int idx) const { // This aabb is split into 4 quadrants. For each axis define in which side of the split "idx" is // The result for indices 0, 1, 2, 3 is: { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } - const std::array<int, 4> xSplit = {0, 1, 0, 1}; - const std::array<int, 4> ySplit = {0, 0, 1, 1}; + const std::array<int, 4> xSplit = {{0, 1, 0, 1}}; + const std::array<int, 4> ySplit = {{0, 0, 1, 1}}; quadrantMin[0] = xSplit[idx] ? xCenter : quadrantMin[0]; quadrantMax[0] = xSplit[idx] ? quadrantMax[0] : xCenter; @@ -103,26 +103,26 @@ enum { Frustum::Frustum(const std::array<vec3, 8>& points_, const std::array<vec4, 6>& planes_) : points(points_), planes(planes_) { - const Point<double> xBounds = ProjectPointsToAxis(points, {0, 0, 0}, {1, 0, 0}); - const Point<double> yBounds = ProjectPointsToAxis(points, {0, 0, 0}, {0, 1, 0}); - const Point<double> zBounds = ProjectPointsToAxis(points, {0, 0, 0}, {0, 0, 1}); + const Point<double> xBounds = ProjectPointsToAxis(points, {{0, 0, 0}}, {{1, 0, 0}}); + const Point<double> yBounds = ProjectPointsToAxis(points, {{0, 0, 0}}, {{0, 1, 0}}); + const Point<double> zBounds = ProjectPointsToAxis(points, {{0, 0, 0}}, {{0, 0, 1}}); - bounds = AABB({xBounds.x, yBounds.x, zBounds.x}, {xBounds.y, yBounds.y, zBounds.y}); + bounds = AABB({{xBounds.x, yBounds.x, zBounds.x}}, {{xBounds.y, yBounds.y, zBounds.y}}); // Precompute a set of separating axis candidates for precise intersection tests. // Remaining axes not covered in basic intersection tests are: axis[] = (edges of aabb) x (edges of frustum) - std::array<vec3, 6> frustumEdges = {vec3Sub(points[near_br], points[near_bl]), - vec3Sub(points[near_tl], points[near_bl]), - vec3Sub(points[far_tl], points[near_tl]), - vec3Sub(points[far_tr], points[near_tr]), - vec3Sub(points[far_br], points[near_br]), - vec3Sub(points[far_bl], points[near_bl])}; + std::array<vec3, 6> frustumEdges = {{vec3Sub(points[near_br], points[near_bl]), + vec3Sub(points[near_tl], points[near_bl]), + vec3Sub(points[far_tl], points[near_tl]), + vec3Sub(points[far_tr], points[near_tr]), + vec3Sub(points[far_br], points[near_br]), + vec3Sub(points[far_bl], points[near_bl])}}; for (size_t i = 0; i < frustumEdges.size(); i++) { // Cross product [1, 0, 0] x [a, b, c] == [0, -c, b] // Cross product [0, 1, 0] x [a, b, c] == [c, 0, -a] - const vec3 axis0 = {0.0, -frustumEdges[i][2], frustumEdges[i][1]}; - const vec3 axis1 = {frustumEdges[i][2], 0.0, -frustumEdges[i][0]}; + const vec3 axis0 = {{0.0, -frustumEdges[i][2], frustumEdges[i][1]}}; + const vec3 axis1 = {{frustumEdges[i][2], 0.0, -frustumEdges[i][0]}}; projections[i * 2] = {axis0, ProjectPointsToAxis(points, points[0], axis0)}; projections[i * 2 + 1] = {axis1, ProjectPointsToAxis(points, points[0], axis1)}; @@ -131,14 +131,14 @@ Frustum::Frustum(const std::array<vec3, 8>& points_, const std::array<vec4, 6>& Frustum Frustum::fromInvProjMatrix(const mat4& invProj, double worldSize, double zoom, bool flippedY) { // Define frustum corner points in normalized clip space - std::array<vec4, 8> cornerCoords = {vec4{-1.0, 1.0, -1.0, 1.0}, - vec4{1.0, 1.0, -1.0, 1.0}, - vec4{1.0, -1.0, -1.0, 1.0}, - vec4{-1.0, -1.0, -1.0, 1.0}, - vec4{-1.0, 1.0, 1.0, 1.0}, - vec4{1.0, 1.0, 1.0, 1.0}, - vec4{1.0, -1.0, 1.0, 1.0}, - vec4{-1.0, -1.0, 1.0, 1.0}}; + std::array<vec4, 8> cornerCoords = {{vec4{{-1.0, 1.0, -1.0, 1.0}}, + vec4{{1.0, 1.0, -1.0, 1.0}}, + vec4{{1.0, -1.0, -1.0, 1.0}}, + vec4{{-1.0, -1.0, -1.0, 1.0}}, + vec4{{-1.0, 1.0, 1.0, 1.0}}, + vec4{{1.0, 1.0, 1.0, 1.0}}, + vec4{{1.0, -1.0, 1.0, 1.0}}, + vec4{{-1.0, -1.0, 1.0, 1.0}}}}; const double scale = std::pow(2.0, zoom); @@ -148,14 +148,14 @@ Frustum Frustum::fromInvProjMatrix(const mat4& invProj, double worldSize, double for (auto& component : coord) component *= 1.0 / coord[3] / worldSize * scale; } - std::array<vec3i, 6> frustumPlanePointIndices = { - vec3i{near_bl, near_br, far_br}, // bottom - vec3i{near_tl, near_bl, far_bl}, // left - vec3i{near_br, near_tr, far_tr}, // right - vec3i{near_tl, far_tl, far_tr}, // top - vec3i{near_tl, near_tr, near_br}, // near - vec3i{far_br, far_tr, far_tl} // far - }; + std::array<vec3i, 6> frustumPlanePointIndices = {{ + vec3i{{near_bl, near_br, far_br}}, // bottom + vec3i{{near_tl, near_bl, far_bl}}, // left + vec3i{{near_br, near_tr, far_tr}}, // right + vec3i{{near_tl, far_tl, far_tr}}, // top + vec3i{{near_tl, near_tr, near_br}}, // near + vec3i{{far_br, far_tr, far_tl}} // far + }}; if (flippedY) { std::for_each(frustumPlanePointIndices.begin(), frustumPlanePointIndices.end(), [](vec3i& tri) { @@ -177,7 +177,7 @@ Frustum Frustum::fromInvProjMatrix(const mat4& invProj, double worldSize, double const vec3 b = vec3Sub(p2, p1); const vec3 n = vec3Normalize(vec3Cross(a, b)); - frustumPlanes[i] = {n[0], n[1], n[2], -vec3Dot(n, p1)}; + frustumPlanes[i] = {{n[0], n[1], n[2], -vec3Dot(n, p1)}}; } std::array<vec3, 8> frustumPoints; @@ -197,12 +197,12 @@ IntersectionResult Frustum::intersects(const AABB& aabb) const { if (!bounds.intersects(aabb)) return IntersectionResult::Separate; - const std::array<vec4, 4> aabbPoints = { - vec4{aabb.min[0], aabb.min[1], 0.0, 1.0}, - vec4{aabb.max[0], aabb.min[1], 0.0, 1.0}, - vec4{aabb.max[0], aabb.max[1], 0.0, 1.0}, - vec4{aabb.min[0], aabb.max[1], 0.0, 1.0}, - }; + const std::array<vec4, 4> aabbPoints = {{ + vec4{{aabb.min[0], aabb.min[1], 0.0, 1.0}}, + vec4{{aabb.max[0], aabb.min[1], 0.0, 1.0}}, + vec4{{aabb.max[0], aabb.max[1], 0.0, 1.0}}, + vec4{{aabb.min[0], aabb.max[1], 0.0, 1.0}}, + }}; bool fullyInside = true; @@ -232,10 +232,10 @@ IntersectionResult Frustum::intersectsPrecise(const AABB& aabb, bool edgeCasesOn if (result == IntersectionResult::Separate) return result; } - const std::array<vec3, 4> aabbPoints = {vec3{aabb.min[0], aabb.min[1], 0.0}, - vec3{aabb.max[0], aabb.min[1], 0.0}, - vec3{aabb.max[0], aabb.max[1], 0.0}, - vec3{aabb.min[0], aabb.max[1], 0.0}}; + const std::array<vec3, 4> aabbPoints = {{vec3{{aabb.min[0], aabb.min[1], 0.0}}, + vec3{{aabb.max[0], aabb.min[1], 0.0}}, + vec3{{aabb.max[0], aabb.max[1], 0.0}}, + vec3{{aabb.min[0], aabb.max[1], 0.0}}}}; // For a precise SAT-test all edge cases needs to be covered // Projections of the frustum on separating axis candidates have been precomputed already |