try to be more coherent about queryAABox meaning

This commit is contained in:
Seth Alves 2015-12-17 14:29:41 -08:00
parent 9438015f3a
commit 473212e5b7
7 changed files with 68 additions and 16 deletions

View file

@ -1177,7 +1177,7 @@ void EntityItem::setDimensions(const glm::vec3& value) {
/// The maximum bounding cube for the entity, independent of it's rotation.
/// This accounts for the registration point (upon which rotation occurs around).
///
const AACube& EntityItem::getMaximumAACube(bool& success) const {
AACube EntityItem::getMaximumAACube(bool& success) const {
if (_recalcMaxAACube) {
// * we know that the position is the center of rotation
glm::vec3 centerOfRotation = getPosition(success); // also where _registration point is
@ -1207,7 +1207,7 @@ const AACube& EntityItem::getMaximumAACube(bool& success) const {
/// The minimum bounding cube for the entity accounting for it's rotation.
/// This accounts for the registration point (upon which rotation occurs around).
///
const AACube& EntityItem::getMinimumAACube(bool& success) const {
AACube EntityItem::getMinimumAACube(bool& success) const {
if (_recalcMinAACube) {
// _position represents the position of the registration point.
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;
@ -1236,7 +1236,7 @@ const AACube& EntityItem::getMinimumAACube(bool& success) const {
return _minAACube;
}
const AABox& EntityItem::getAABox(bool& success) const {
AABox EntityItem::getAABox(bool& success) const {
if (_recalcAABox) {
// _position represents the position of the registration point.
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;
@ -1261,11 +1261,17 @@ const AABox& EntityItem::getAABox(bool& success) const {
}
AACube EntityItem::getQueryAACube(bool& success) const {
AACube result = getMaximumAACube(success);
AACube result = SpatiallyNestable::getQueryAACube(success);
if (success) {
return result;
}
return SpatiallyNestable::getQueryAACube(success);
// this is for when we've loaded an older json file that didn't have queryAACube properties.
result = getMaximumAACube(success);
if (success) {
_queryAACube = result;
_queryAACubeSet = true;
}
return result;
}

View file

@ -231,9 +231,9 @@ public:
quint64 getExpiry() const;
// position, size, and bounds related helpers
const AACube& getMaximumAACube(bool& success) const;
const AACube& getMinimumAACube(bool& success) const;
const AABox& getAABox(bool& success) const; /// axis aligned bounding box in world-frame (meters)
virtual AACube getMaximumAACube(bool& success) const override;
AACube getMinimumAACube(bool& success) const;
AABox getAABox(bool& success) const; /// axis aligned bounding box in world-frame (meters)
using SpatiallyNestable::getQueryAACube;
virtual AACube getQueryAACube(bool& success) const override;

View file

@ -279,6 +279,17 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties&
}
entity->setLastBroadcast(usecTimestampNow());
}
// if we've moved an entity with children, check/update the queryAACube of all descendents and tell the server
// if they've changed.
// TODO -- ancestors of this entity may also need to expand their queryAACubes.
entity->forEachDescendant([&](SpatiallyNestablePointer descendant) {
if (descendant->setPuffedQueryAACube()) {
EntityItemProperties newQueryCubeProperties;
newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube());
queueEntityMessage(PacketType::EntityEdit, descendant->getID(), newQueryCubeProperties);
}
});
});
queueEntityMessage(PacketType::EntityEdit, entityID, properties);
return id;

View file

@ -89,6 +89,9 @@ void EntityTree::postAddEntity(EntityItemPointer entity) {
_isDirty = true;
maybeNotifyNewCollisionSoundURL("", entity->getCollisionSoundURL());
emit addingEntity(entity->getEntityItemID());
// find and hook up any entities with this entity as a (previously) missing parent
fixupMissingParents();
}
bool EntityTree::updateEntity(const EntityItemID& entityID, const EntityItemProperties& properties, const SharedNodePointer& senderNode) {

View file

@ -507,6 +507,17 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q
entityPacketSender->queueEditEntityMessage(PacketType::EntityEdit, id, properties);
_entity->setLastBroadcast(usecTimestampNow());
// if we've moved an entity with children, check/update the queryAACube of all descendents and tell the server
// if they've changed.
// TODO -- ancestors of this entity may also need to expand their queryAACubes.
_entity->forEachDescendant([&](SpatiallyNestablePointer descendant) {
if (descendant->setPuffedQueryAACube()) {
EntityItemProperties newQueryCubeProperties;
newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube());
entityPacketSender->queueEditEntityMessage(PacketType::EntityEdit, descendant->getID(), newQueryCubeProperties);
}
});
_lastStep = step;
}

View file

@ -552,11 +552,33 @@ void SpatiallyNestable::setQueryAACube(const AACube& queryAACube) {
_queryAACubeSet = true;
}
AACube SpatiallyNestable::getMaximumAACube(bool& success) const {
return AACube(getPosition(success) - glm::vec3(0.5f), 1.0f); // XXX
}
bool SpatiallyNestable::setPuffedQueryAACube() {
bool success;
AACube currentAACube = getMaximumAACube(success);
if (!success) {
qDebug() << "can't getMaximumAACube for" << getID();
return false;
}
if (_queryAACubeSet && _queryAACube.contains(currentAACube)) {
return false;
}
// make an AACube with edges twice as long and centered on the object
_queryAACube = AACube(currentAACube.getCorner() - glm::vec3(currentAACube.getScale()), currentAACube.getScale() * 2.0f);
_queryAACubeSet = true;
return true;
}
AACube SpatiallyNestable::getQueryAACube(bool& success) const {
if (_queryAACubeSet) {
success = true;
return _queryAACube;
}
success = false;
return AACube(getPosition(success) - glm::vec3(0.5f), 1.0f); // XXX
}
@ -564,11 +586,7 @@ AACube SpatiallyNestable::getQueryAACube() const {
bool success;
auto result = getQueryAACube(success);
if (!success) {
if (_queryAACubeSet) {
result = _queryAACube;
} else {
qDebug() << "getQueryAACube failed:" << getID();
}
qDebug() << "getQueryAACube failed for" << getID();
}
return result;
}

View file

@ -68,6 +68,9 @@ public:
virtual void setOrientation(const glm::quat& orientation, bool& success);
virtual void setOrientation(const glm::quat& orientation);
virtual AACube getMaximumAACube(bool& success) const;
virtual bool setPuffedQueryAACube();
virtual void setQueryAACube(const AACube& queryAACube);
virtual AACube getQueryAACube(bool& success) const;
virtual AACube getQueryAACube() const;
@ -106,6 +109,9 @@ public:
void markAncestorMissing(bool value) { _missingAncestor = value; }
bool getAncestorMissing() { return _missingAncestor; }
void forEachChild(std::function<void(SpatiallyNestablePointer)> actor);
void forEachDescendant(std::function<void(SpatiallyNestablePointer)> actor);
protected:
const NestableType _nestableType; // EntityItem or an AvatarData
QUuid _id;
@ -123,9 +129,6 @@ protected:
virtual void locationChanged(); // called when a this object's location has changed
virtual void dimensionsChanged() {} // called when a this object's dimensions have changed
void forEachChild(std::function<void(SpatiallyNestablePointer)> actor);
void forEachDescendant(std::function<void(SpatiallyNestablePointer)> actor);
// _queryAACube is used to decide where something lives in the octree
mutable AACube _queryAACube;
mutable bool _queryAACubeSet { false };