mirror of
https://github.com/overte-org/overte.git
synced 2025-07-22 18:34:56 +02:00
dont try to create child elements that are smaller than the entities
This commit is contained in:
parent
8339f1059e
commit
6ce6d8ae47
3 changed files with 57 additions and 19 deletions
|
@ -155,12 +155,16 @@ OctreeElement* AddEntityOperator::PossiblyCreateChildAt(OctreeElement* element,
|
|||
// We only care if this happens while still searching for the new entity location.
|
||||
// Check to see if
|
||||
if (!_foundNew) {
|
||||
float childElementScale = element->getAACube().getScale() / 2.0f; // all of our children will be half our scale
|
||||
// if the scale of our desired cube is smaller than our children, then consider making a child
|
||||
if (_newEntityBox.getLargestDimension() <= childElementScale) {
|
||||
int indexOfChildContainingNewEntity = element->getMyChildContaining(_newEntityBox);
|
||||
|
||||
if (childIndex == indexOfChildContainingNewEntity) {
|
||||
return element->addChildAtIndex(childIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -488,12 +492,18 @@ OctreeElement* UpdateEntityOperator::PossiblyCreateChildAt(OctreeElement* elemen
|
|||
// We only care if this happens while still searching for the new entity location.
|
||||
// Check to see if
|
||||
if (!_foundNew) {
|
||||
|
||||
float childElementScale = element->getAACube().getScale() / 2.0f; // all of our children will be half our scale
|
||||
// if the scale of our desired cube is smaller than our children, then consider making a child
|
||||
if (_newEntityCube.getScale() <= childElementScale) {
|
||||
//qDebug() << "UpdateEntityOperator::PossiblyCreateChildAt().... calling element->getMyChildContaining(_newEntityCube);";
|
||||
int indexOfChildContainingNewEntity = element->getMyChildContaining(_newEntityCube);
|
||||
|
||||
if (childIndex == indexOfChildContainingNewEntity) {
|
||||
return element->addChildAtIndex(childIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -128,13 +128,36 @@ bool MovingEntitiesOperator::PostRecursion(OctreeElement* element) {
|
|||
}
|
||||
|
||||
OctreeElement* MovingEntitiesOperator::PossiblyCreateChildAt(OctreeElement* element, int childIndex) {
|
||||
bool wantDebug = false;
|
||||
|
||||
if (wantDebug) {
|
||||
qDebug() << "MovingEntitiesOperator::PossiblyCreateChildAt().... ";
|
||||
qDebug() << " _foundNewCount=" << _foundNewCount;
|
||||
qDebug() << " _lookingCount=" << _lookingCount;
|
||||
}
|
||||
|
||||
// If we're getting called, it's because there was no child element at this index while recursing.
|
||||
// We only care if this happens while still searching for the new entity locations.
|
||||
if (_foundNewCount < _lookingCount) {
|
||||
|
||||
float childElementScale = element->getAACube().getScale() / 2.0f; // all of our children will be half our scale
|
||||
|
||||
// check against each of our entities
|
||||
foreach(const EntityToMoveDetails& details, _entitiesToMove) {
|
||||
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
|
||||
|
||||
bool thisElementIsBestFit = entityTreeElement->bestFitBounds(details.newCube);
|
||||
if (wantDebug) {
|
||||
qDebug() << " thisElementIsBestFit=" << thisElementIsBestFit;
|
||||
qDebug() << " details.newCube=" << details.newCube;
|
||||
qDebug() << " element->getAACube()=" << element->getAACube();
|
||||
}
|
||||
|
||||
// if the scale of our desired cube is smaller than our children, then consider making a child
|
||||
if (details.newCube.getScale() <= childElementScale) {
|
||||
//qDebug() << " calling element->getMyChildContaining(details.newCube); ---------";
|
||||
int indexOfChildContainingNewEntity = element->getMyChildContaining(details.newCube);
|
||||
//qDebug() << " called element->getMyChildContaining(details.newCube); ---------";
|
||||
|
||||
// If the childIndex we were asked if we wanted to create contains this newCube,
|
||||
// then we will create this branch and continue. We can exit this loop immediately
|
||||
|
@ -145,6 +168,7 @@ OctreeElement* MovingEntitiesOperator::PossiblyCreateChildAt(OctreeElement* elem
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -1489,14 +1489,18 @@ int OctreeElement::getMyChildContaining(const AACube& cube) const {
|
|||
float cubeScale = cube.getScale();
|
||||
|
||||
// TODO: consider changing this to assert()
|
||||
if(cubeScale > ourScale) {
|
||||
qDebug("UNEXPECTED -- OctreeElement::getMyChildContaining() "
|
||||
"cubeScale=[%f] > ourScale=[%f] ", cubeScale, ourScale);
|
||||
if (cubeScale > ourScale) {
|
||||
qDebug() << "UNEXPECTED -- OctreeElement::getMyChildContaining() -- (cubeScale > ourScale)";
|
||||
qDebug() << " cube=" << cube;
|
||||
qDebug() << " elements AACube=" << getAACube();
|
||||
qDebug() << " cubeScale=" << cubeScale;
|
||||
qDebug() << " ourScale=" << ourScale;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
// Determine which of our children the minimum and maximum corners of the cube live in...
|
||||
glm::vec3 cubeCornerMinimum = cube.getCorner();
|
||||
glm::vec3 cubeCornerMaximum = cube.calcTopFarLeft();
|
||||
glm::vec3 cubeCornerMinimum = glm::clamp(cube.getCorner(), 0.0f, 1.0f);
|
||||
glm::vec3 cubeCornerMaximum = glm::clamp(cube.calcTopFarLeft(), 0.0f, 1.0f);
|
||||
|
||||
int childIndexCubeMinimum = getMyChildContainingPoint(cubeCornerMinimum);
|
||||
int childIndexCubeMaximum = getMyChildContainingPoint(cubeCornerMaximum);
|
||||
|
|
Loading…
Reference in a new issue