mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
optimized ViewFrustum::getFurthestPointFromCamera()
This commit is contained in:
parent
cd6e0f1698
commit
252bc3b3ee
3 changed files with 16 additions and 21 deletions
|
@ -1222,10 +1222,11 @@ bool OctreeElement::calculateShouldRender(const ViewFrustum* viewFrustum, float
|
|||
float OctreeElement::furthestDistanceToCamera(const ViewFrustum& viewFrustum) const {
|
||||
AABox box = getAABox();
|
||||
box.scale(TREE_SCALE);
|
||||
glm::vec3 furthestPoint = viewFrustum.getFurthestPointFromCamera(box);
|
||||
glm::vec3 furthestPoint;
|
||||
viewFrustum.getFurthestPointFromCamera(box, furthestPoint);
|
||||
glm::vec3 temp = viewFrustum.getPosition() - furthestPoint;
|
||||
float distanceToVoxelCenter = sqrtf(glm::dot(temp, temp));
|
||||
return distanceToVoxelCenter;
|
||||
float distanceToFurthestPoint = sqrtf(glm::dot(temp, temp));
|
||||
return distanceToFurthestPoint;
|
||||
}
|
||||
|
||||
float OctreeElement::distanceToCamera(const ViewFrustum& viewFrustum) const {
|
||||
|
|
|
@ -695,39 +695,32 @@ OctreeProjectedPolygon ViewFrustum::getProjectedPolygon(const AABox& box) const
|
|||
return projectedPolygon;
|
||||
}
|
||||
|
||||
|
||||
// Similar strategy to getProjectedPolygon() we use the knowledge of camera position relative to the
|
||||
// axis-aligned voxels to determine which of the voxels vertices must be the furthest. No need for
|
||||
// squares and square-roots. Just compares.
|
||||
glm::vec3 ViewFrustum::getFurthestPointFromCamera(const AABox& box) const {
|
||||
void ViewFrustum::getFurthestPointFromCamera(const AABox& box, glm::vec3& furthestPoint) const {
|
||||
const glm::vec3& bottomNearRight = box.getCorner();
|
||||
glm::vec3 center = box.calcCenter();
|
||||
glm::vec3 topFarLeft = box.calcTopFarLeft();
|
||||
float scale = box.getScale();
|
||||
float halfScale = scale * 0.5f;
|
||||
|
||||
glm::vec3 furthestPoint;
|
||||
if (_position.x < center.x) {
|
||||
if (_position.x < bottomNearRight.x + halfScale) {
|
||||
// we are to the right of the center, so the left edge is furthest
|
||||
furthestPoint.x = topFarLeft.x;
|
||||
furthestPoint.x = bottomNearRight.x + scale;
|
||||
} else {
|
||||
// we are to the left of the center, so the right edge is furthest (at center ok too)
|
||||
furthestPoint.x = bottomNearRight.x;
|
||||
}
|
||||
|
||||
if (_position.y < center.y) {
|
||||
if (_position.y < bottomNearRight.y + halfScale) {
|
||||
// we are below of the center, so the top edge is furthest
|
||||
furthestPoint.y = topFarLeft.y;
|
||||
furthestPoint.y = bottomNearRight.y + scale;
|
||||
} else {
|
||||
// we are above the center, so the lower edge is furthest (at center ok too)
|
||||
furthestPoint.y = bottomNearRight.y;
|
||||
}
|
||||
|
||||
if (_position.z < center.z) {
|
||||
if (_position.z < bottomNearRight.z + halfScale) {
|
||||
// we are to the near side of the center, so the far side edge is furthest
|
||||
furthestPoint.z = topFarLeft.z;
|
||||
furthestPoint.z = bottomNearRight.z + scale;
|
||||
} else {
|
||||
// we are to the far side of the center, so the near side edge is furthest (at center ok too)
|
||||
furthestPoint.z = bottomNearRight.z;
|
||||
}
|
||||
|
||||
return furthestPoint;
|
||||
}
|
||||
|
|
|
@ -102,8 +102,9 @@ public:
|
|||
|
||||
glm::vec2 projectPoint(glm::vec3 point, bool& pointInView) const;
|
||||
OctreeProjectedPolygon getProjectedPolygon(const AABox& box) const;
|
||||
glm::vec3 getFurthestPointFromCamera(const AABox& box) const;
|
||||
|
||||
//glm::vec3 getFurthestPointFromCamera(const AABox& box) const;
|
||||
void getFurthestPointFromCamera(const AABox& box, glm::vec3& furthestPoint) const;
|
||||
|
||||
private:
|
||||
// Used for keyhole calculations
|
||||
ViewFrustum::location pointInKeyhole(const glm::vec3& point) const;
|
||||
|
|
Loading…
Reference in a new issue