mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 12:39:24 -05:00
Make Chunk bounding polyhedron fully, but still not tightly, encapsulate the chunk
This commit is contained in:
@@ -128,23 +128,44 @@ namespace openspace {
|
||||
BoundingHeights boundingHeight = getBoundingHeights();
|
||||
|
||||
// assume worst case
|
||||
double patchCenterRadius = ellipsoid.maximumRadius();
|
||||
double patchCenterRadius = ellipsoid.maximumRadius();
|
||||
|
||||
double maxCenterRadius = patchCenterRadius + boundingHeight.max;
|
||||
Geodetic2 halfSize = patch.halfSize();
|
||||
|
||||
// As the patch is curved, the maximum height offsets at the corners must be long
|
||||
// enough to cover large enough to cover a boundingHeight.max at the center of the
|
||||
// patch.
|
||||
double maxCenterRadius = patchCenterRadius + boundingHeight.max;
|
||||
double maximumPatchSide = max(patch.halfSize().lat, patch.halfSize().lon);
|
||||
double maxCornerHeight = maxCenterRadius / cos(maximumPatchSide) - patchCenterRadius;
|
||||
// patch. Below this is done by an approximation.
|
||||
double scaleToCoverCenter = 1 / cos(halfSize.lat) + 1 / cos(halfSize.lon) - 1;
|
||||
double maxCornerHeight = maxCenterRadius * scaleToCoverCenter - patchCenterRadius;
|
||||
|
||||
bool chunkIsNorthOfEquator = patch.isNorthern();
|
||||
|
||||
// The minimum height offset, however, we can simply
|
||||
double minCornerHeight = boundingHeight.min;
|
||||
std::vector<glm::dvec4> corners(8);
|
||||
|
||||
Scalar latCloseToEquator = patch.edgeLatitudeNearestEquator();
|
||||
Geodetic3 p1Geodetic = { { latCloseToEquator, patch.minLon() }, maxCornerHeight };
|
||||
Geodetic3 p2Geodetic = { { latCloseToEquator, patch.maxLon() }, maxCornerHeight };
|
||||
|
||||
glm::vec3 p1 = ellipsoid.cartesianPosition(p1Geodetic);
|
||||
glm::vec3 p2 = ellipsoid.cartesianPosition(p2Geodetic);
|
||||
glm::vec3 p = 0.5f * (p1 + p2);
|
||||
Geodetic2 pGeodetic = ellipsoid.cartesianToGeodetic2(p);
|
||||
Scalar latDiff = latCloseToEquator - pGeodetic.lat;
|
||||
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
Quad q = (Quad)(i % 4);
|
||||
double cornerHeight = i < 4 ? minCornerHeight : maxCornerHeight;
|
||||
const Geodetic3& cornerGeodetic = { patch.getCorner(q), cornerHeight };
|
||||
Geodetic3 cornerGeodetic = { patch.getCorner(q), cornerHeight };
|
||||
|
||||
bool cornerIsNorthern = i < 2;
|
||||
bool cornerCloseToEquator = chunkIsNorthOfEquator ^ cornerIsNorthern;
|
||||
if (cornerCloseToEquator) {
|
||||
cornerGeodetic.geodetic2.lat += latDiff;
|
||||
}
|
||||
|
||||
corners[i] = dvec4(ellipsoid.cartesianPosition(cornerGeodetic), 1);
|
||||
}
|
||||
return corners;
|
||||
|
||||
@@ -42,6 +42,13 @@ enum Quad {
|
||||
SOUTH_EAST
|
||||
};
|
||||
|
||||
enum CardinalDirection {
|
||||
WEST = 0,
|
||||
EAST,
|
||||
NORTH,
|
||||
SOUTH,
|
||||
};
|
||||
|
||||
|
||||
|
||||
using HashKey = unsigned long;
|
||||
|
||||
Reference in New Issue
Block a user