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,10 +155,14 @@ OctreeElement* AddEntityOperator::PossiblyCreateChildAt(OctreeElement* element,
|
||||||
// We only care if this happens while still searching for the new entity location.
|
// We only care if this happens while still searching for the new entity location.
|
||||||
// Check to see if
|
// Check to see if
|
||||||
if (!_foundNew) {
|
if (!_foundNew) {
|
||||||
int indexOfChildContainingNewEntity = element->getMyChildContaining(_newEntityBox);
|
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) {
|
if (childIndex == indexOfChildContainingNewEntity) {
|
||||||
return element->addChildAtIndex(childIndex);
|
return element->addChildAtIndex(childIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -488,10 +492,16 @@ OctreeElement* UpdateEntityOperator::PossiblyCreateChildAt(OctreeElement* elemen
|
||||||
// We only care if this happens while still searching for the new entity location.
|
// We only care if this happens while still searching for the new entity location.
|
||||||
// Check to see if
|
// Check to see if
|
||||||
if (!_foundNew) {
|
if (!_foundNew) {
|
||||||
int indexOfChildContainingNewEntity = element->getMyChildContaining(_newEntityCube);
|
|
||||||
|
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) {
|
if (childIndex == indexOfChildContainingNewEntity) {
|
||||||
return element->addChildAtIndex(childIndex);
|
return element->addChildAtIndex(childIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -127,21 +127,45 @@ bool MovingEntitiesOperator::PostRecursion(OctreeElement* element) {
|
||||||
return keepSearching; // if we haven't yet found it, keep looking
|
return keepSearching; // if we haven't yet found it, keep looking
|
||||||
}
|
}
|
||||||
|
|
||||||
OctreeElement* MovingEntitiesOperator::PossiblyCreateChildAt(OctreeElement* element, int childIndex) {
|
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.
|
// 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.
|
// We only care if this happens while still searching for the new entity locations.
|
||||||
if (_foundNewCount < _lookingCount) {
|
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
|
// check against each of our entities
|
||||||
foreach(const EntityToMoveDetails& details, _entitiesToMove) {
|
foreach(const EntityToMoveDetails& details, _entitiesToMove) {
|
||||||
int indexOfChildContainingNewEntity = element->getMyChildContaining(details.newCube);
|
EntityTreeElement* entityTreeElement = static_cast<EntityTreeElement*>(element);
|
||||||
|
|
||||||
// If the childIndex we were asked if we wanted to create contains this newCube,
|
bool thisElementIsBestFit = entityTreeElement->bestFitBounds(details.newCube);
|
||||||
// then we will create this branch and continue. We can exit this loop immediately
|
if (wantDebug) {
|
||||||
// because if we need this branch for any one entity then it doesn't matter if it's
|
qDebug() << " thisElementIsBestFit=" << thisElementIsBestFit;
|
||||||
// needed for more entities.
|
qDebug() << " details.newCube=" << details.newCube;
|
||||||
if (childIndex == indexOfChildContainingNewEntity) {
|
qDebug() << " element->getAACube()=" << element->getAACube();
|
||||||
return element->addChildAtIndex(childIndex);
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// because if we need this branch for any one entity then it doesn't matter if it's
|
||||||
|
// needed for more entities.
|
||||||
|
if (childIndex == indexOfChildContainingNewEntity) {
|
||||||
|
return element->addChildAtIndex(childIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1489,14 +1489,18 @@ int OctreeElement::getMyChildContaining(const AACube& cube) const {
|
||||||
float cubeScale = cube.getScale();
|
float cubeScale = cube.getScale();
|
||||||
|
|
||||||
// TODO: consider changing this to assert()
|
// TODO: consider changing this to assert()
|
||||||
if(cubeScale > ourScale) {
|
if (cubeScale > ourScale) {
|
||||||
qDebug("UNEXPECTED -- OctreeElement::getMyChildContaining() "
|
qDebug() << "UNEXPECTED -- OctreeElement::getMyChildContaining() -- (cubeScale > ourScale)";
|
||||||
"cubeScale=[%f] > ourScale=[%f] ", 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...
|
// Determine which of our children the minimum and maximum corners of the cube live in...
|
||||||
glm::vec3 cubeCornerMinimum = cube.getCorner();
|
glm::vec3 cubeCornerMinimum = glm::clamp(cube.getCorner(), 0.0f, 1.0f);
|
||||||
glm::vec3 cubeCornerMaximum = cube.calcTopFarLeft();
|
glm::vec3 cubeCornerMaximum = glm::clamp(cube.calcTopFarLeft(), 0.0f, 1.0f);
|
||||||
|
|
||||||
int childIndexCubeMinimum = getMyChildContainingPoint(cubeCornerMinimum);
|
int childIndexCubeMinimum = getMyChildContainingPoint(cubeCornerMinimum);
|
||||||
int childIndexCubeMaximum = getMyChildContainingPoint(cubeCornerMaximum);
|
int childIndexCubeMaximum = getMyChildContainingPoint(cubeCornerMaximum);
|
||||||
|
|
Loading…
Reference in a new issue