mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:37:46 +02:00
workaround for zero-size objects in priority formula
This commit is contained in:
parent
eb120b1bc1
commit
05fbf8e511
1 changed files with 12 additions and 4 deletions
|
@ -112,11 +112,19 @@ namespace PrioritySortUtil {
|
||||||
glm::vec3 position = thing.getPosition();
|
glm::vec3 position = thing.getPosition();
|
||||||
glm::vec3 offset = position - _view.getPosition();
|
glm::vec3 offset = position - _view.getPosition();
|
||||||
float distance = glm::length(offset) + 0.001f; // add 1mm to avoid divide by zero
|
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)
|
// we modulatate "age" drift rate by the cosineAngle term to make periphrial objects sort forward
|
||||||
+ _centerWeight * (glm::dot(offset, _view.getDirection()) / distance)
|
// at a reduced rate but we don't want the "age" term to go zero or negative so we clamp it
|
||||||
+ _ageWeight * (float)(usecTimestampNow() - thing.getTimestamp());
|
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
|
// decrement priority of things outside keyhole
|
||||||
if (distance - radius > _view.getCenterRadius()) {
|
if (distance - radius > _view.getCenterRadius()) {
|
||||||
|
|
Loading…
Reference in a new issue