mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-13 18:42:33 +02:00
Small optimization by using squared distance and not distance in depth sort
This commit is contained in:
parent
8eb7ceb66a
commit
c56bb9a855
3 changed files with 7 additions and 6 deletions
|
@ -61,9 +61,9 @@ void render::depthSortItems(const RenderContextPointer& renderContext, bool fron
|
|||
for (auto itemDetails : inItems) {
|
||||
auto item = scene->getItem(itemDetails.id);
|
||||
auto bound = itemDetails.bound; // item.getBound();
|
||||
float distance = args->getViewFrustum().distanceToCamera(bound.calcCenter());
|
||||
float distanceSquared = args->getViewFrustum().distanceToCameraSquared(bound.calcCenter());
|
||||
|
||||
itemBoundSorts.emplace_back(ItemBoundSort(distance, distance, distance, itemDetails.id, bound));
|
||||
itemBoundSorts.emplace_back(ItemBoundSort(distanceSquared, distanceSquared, distanceSquared, itemDetails.id, bound));
|
||||
}
|
||||
|
||||
// sort against Z
|
||||
|
|
|
@ -654,10 +654,10 @@ const ViewFrustum::Corners ViewFrustum::getCorners(const float depth) const {
|
|||
};
|
||||
}
|
||||
|
||||
float ViewFrustum::distanceToCamera(const glm::vec3& point) const {
|
||||
float ViewFrustum::distanceToCameraSquared(const glm::vec3& point) const {
|
||||
glm::vec3 temp = getPosition() - point;
|
||||
float distanceToPoint = sqrtf(glm::dot(temp, temp));
|
||||
return distanceToPoint;
|
||||
float distanceToPointSquared = glm::dot(temp, temp);
|
||||
return distanceToPointSquared;
|
||||
}
|
||||
|
||||
void ViewFrustum::evalProjectionMatrix(glm::mat4& proj) const {
|
||||
|
|
|
@ -127,7 +127,8 @@ public:
|
|||
bool getProjectedRect(const AABox& box, glm::vec2& bottomLeft, glm::vec2& topRight) const;
|
||||
void getFurthestPointFromCamera(const AACube& box, glm::vec3& furthestPoint) const;
|
||||
|
||||
float distanceToCamera(const glm::vec3& point) const;
|
||||
float distanceToCameraSquared(const glm::vec3& point) const;
|
||||
float distanceToCamera(const glm::vec3& point) const { return sqrtf(distanceToCameraSquared(point)); }
|
||||
|
||||
void evalProjectionMatrix(glm::mat4& proj) const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue