Add method getBoundingPolyhedronCorners in Chunk class

This commit is contained in:
Erik Broberg
2016-06-14 21:42:44 -04:00
parent aefb7c3030
commit 454e19dd83
2 changed files with 36 additions and 0 deletions

View File

@@ -117,6 +117,39 @@ namespace openspace {
return boundingHeights;
}
std::vector<glm::dvec4> Chunk::getBoundingPolyhedronCorners() const {
// OBS!
// This implementation needs to be fixed! Its not completely bounding
// See DebugRenderer::renderBoxFaces to see whats wrong
const Ellipsoid& ellipsoid = owner()->ellipsoid();
const GeodeticPatch& patch = surfacePatch();
BoundingHeights boundingHeight = getBoundingHeights();
// assume worst case
double patchCenterRadius = ellipsoid.maximumRadius();
// 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;
// The minimum height offset, however, we can simply
double minCornerHeight = boundingHeight.min;
std::vector<glm::dvec4> corners(8);
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 };
corners[i] = dvec4(ellipsoid.cartesianPosition(cornerGeodetic), 1);
}
return corners;
}
void Chunk::render(const RenderData& data) const {
_owner->getPatchRenderer().renderChunk(*this, data);