From 688448fe4155a11c2dae4f02c35c43f84ce2809d Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 17 Dec 2015 16:18:41 -0800 Subject: [PATCH] more queryAABox experimenting --- .../entities/src/EntityScriptingInterface.cpp | 2 +- libraries/physics/src/EntityMotionState.cpp | 6 +++++- libraries/shared/src/SpatiallyNestable.cpp | 19 ++++++++++++++----- libraries/shared/src/SpatiallyNestable.h | 1 + 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 9d5600e615..57201174f5 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -274,7 +274,7 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& entity->flagForOwnership(); } } - if (properties.parentRelatedPropertyChanged()) { + if (properties.parentRelatedPropertyChanged() && entity->setPuffedQueryAACube()) { properties.setQueryAACube(entity->getQueryAACube()); } entity->setLastBroadcast(usecTimestampNow()); diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 0e80a28b0a..ac0e25a233 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -374,6 +374,10 @@ bool EntityMotionState::shouldSendUpdate(uint32_t simulationStep, const QUuid& s return true; } + if (_entity->queryAABoxNeedsUpdate()) { + return true; + } + if (_entity->getSimulatorID() != sessionID) { // we don't own the simulation, but maybe we should... if (_outgoingPriority != NO_PRORITY) { @@ -466,7 +470,7 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, const Q properties.setActionData(_serverActionData); } - if (properties.parentRelatedPropertyChanged()) { + if (properties.parentRelatedPropertyChanged() && _entity->setPuffedQueryAACube()) { // due to parenting, the server may not know where something is in world-space, so include the bounding cube. properties.setQueryAACube(_entity->getQueryAACube()); } diff --git a/libraries/shared/src/SpatiallyNestable.cpp b/libraries/shared/src/SpatiallyNestable.cpp index 45cd7fec02..eb8af2101e 100644 --- a/libraries/shared/src/SpatiallyNestable.cpp +++ b/libraries/shared/src/SpatiallyNestable.cpp @@ -536,6 +536,10 @@ void SpatiallyNestable::locationChanged() { }); } +AACube SpatiallyNestable::getMaximumAACube(bool& success) const { + return AACube(getPosition(success) - glm::vec3(0.5f), 1.0f); // XXX +} + void SpatiallyNestable::setQueryAACube(const AACube& queryAACube) { _queryAACube = queryAACube; if (queryAACube.getScale() > 0.0f) { @@ -543,11 +547,7 @@ void SpatiallyNestable::setQueryAACube(const AACube& queryAACube) { } } -AACube SpatiallyNestable::getMaximumAACube(bool& success) const { - return AACube(getPosition(success) - glm::vec3(0.5f), 1.0f); // XXX -} - -bool SpatiallyNestable::setPuffedQueryAACube() { +bool SpatiallyNestable::queryAABoxNeedsUpdate() const { bool success; AACube currentAACube = getMaximumAACube(success); if (!success) { @@ -558,6 +558,15 @@ bool SpatiallyNestable::setPuffedQueryAACube() { return false; } + return true; +} + +bool SpatiallyNestable::setPuffedQueryAACube() { + if (!queryAABoxNeedsUpdate()) { + return false; + } + bool success; + AACube currentAACube = getMaximumAACube(success); // 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; diff --git a/libraries/shared/src/SpatiallyNestable.h b/libraries/shared/src/SpatiallyNestable.h index e5540eb79c..91fdd84be0 100644 --- a/libraries/shared/src/SpatiallyNestable.h +++ b/libraries/shared/src/SpatiallyNestable.h @@ -72,6 +72,7 @@ public: virtual bool setPuffedQueryAACube(); virtual void setQueryAACube(const AACube& queryAACube); + virtual bool queryAABoxNeedsUpdate() const; virtual AACube getQueryAACube(bool& success) const; virtual AACube getQueryAACube() const;