workaround for zero-size objects in priority formula

This commit is contained in:
Andrew Meadows 2017-11-30 11:04:51 -08:00
parent eb120b1bc1
commit 05fbf8e511

View file

@ -112,11 +112,19 @@ namespace PrioritySortUtil {
glm::vec3 position = thing.getPosition();
glm::vec3 offset = position - _view.getPosition();
float distance = glm::length(offset) + 0.001f; // add 1mm to avoid divide by zero
float radius = thing.getRadius();
const float MIN_RADIUS = 0.1f; // WORKAROUND for zero size objects (we still want them to sort by distance)
float radius = glm::min(thing.getRadius(), MIN_RADIUS);
float cosineAngle = (glm::dot(offset, _view.getDirection()) / distance);
float age = (float)(usecTimestampNow() - thing.getTimestamp());
float priority = _angularWeight * (radius / distance)
+ _centerWeight * (glm::dot(offset, _view.getDirection()) / distance)
+ _ageWeight * (float)(usecTimestampNow() - thing.getTimestamp());
// we modulatate "age" drift rate by the cosineAngle term to make periphrial objects sort forward
// at a reduced rate but we don't want the "age" term to go zero or negative so we clamp it
const float MIN_COSINE_ANGLE_FACTOR = 0.1f;
float cosineAngleFactor = glm::max(cosineAngle, MIN_COSINE_ANGLE_FACTOR);
float priority = _angularWeight * glm::max(radius, MIN_RADIUS) / distance
+ _centerWeight * cosineAngle
+ _ageWeight * cosineAngleFactor * age;
// decrement priority of things outside keyhole
if (distance - radius > _view.getCenterRadius()) {