Do not copy list of collision pick contact points when filtering them

This commit is contained in:
sabrina-shanman 2018-08-13 16:49:51 -07:00
parent 83ededfd37
commit 61d12923ea
4 changed files with 13 additions and 13 deletions

View file

@ -308,20 +308,18 @@ CollisionRegion CollisionPick::getMathematicalPick() const {
return _mathPick; return _mathPick;
} }
const std::vector<ContactTestResult> CollisionPick::filterIntersections(const std::vector<ContactTestResult>& intersections) const { void CollisionPick::filterIntersections(std::vector<ContactTestResult>& intersections) const {
std::vector<ContactTestResult> filteredIntersections;
const QVector<QUuid>& ignoreItems = getIgnoreItems(); const QVector<QUuid>& ignoreItems = getIgnoreItems();
const QVector<QUuid>& includeItems = getIncludeItems(); const QVector<QUuid>& includeItems = getIncludeItems();
bool isWhitelist = includeItems.size(); bool isWhitelist = includeItems.size();
for (const auto& intersection : intersections) { for (int i = 0; i < intersections.size(); i++) {
auto& intersection = intersections[i];
const QUuid& id = intersection.foundID; const QUuid& id = intersection.foundID;
if (!ignoreItems.contains(id) && (!isWhitelist || includeItems.contains(id))) { if (ignoreItems.contains(id) || (isWhitelist && !includeItems.contains(id))) {
filteredIntersections.push_back(intersection); intersections[i] = intersections[intersections.size()-1];
intersections.pop_back();
} }
} }
return filteredIntersections;
} }
PickResultPointer CollisionPick::getEntityIntersection(const CollisionRegion& pick) { PickResultPointer CollisionPick::getEntityIntersection(const CollisionRegion& pick) {
@ -330,7 +328,8 @@ PickResultPointer CollisionPick::getEntityIntersection(const CollisionRegion& pi
return std::make_shared<CollisionPickResult>(pick.toVariantMap(), CollisionPickResult::LOAD_STATE_NOT_LOADED, std::vector<ContactTestResult>(), std::vector<ContactTestResult>()); return std::make_shared<CollisionPickResult>(pick.toVariantMap(), CollisionPickResult::LOAD_STATE_NOT_LOADED, std::vector<ContactTestResult>(), std::vector<ContactTestResult>());
} }
const auto& entityIntersections = filterIntersections(_physicsEngine->getCollidingInRegion(MOTIONSTATE_TYPE_ENTITY, *pick.shapeInfo, pick.transform)); auto& entityIntersections = _physicsEngine->getCollidingInRegion(MOTIONSTATE_TYPE_ENTITY, *pick.shapeInfo, pick.transform);
filterIntersections(entityIntersections);
return std::make_shared<CollisionPickResult>(pick, CollisionPickResult::LOAD_STATE_LOADED, entityIntersections, std::vector<ContactTestResult>()); return std::make_shared<CollisionPickResult>(pick, CollisionPickResult::LOAD_STATE_LOADED, entityIntersections, std::vector<ContactTestResult>());
} }
@ -344,7 +343,8 @@ PickResultPointer CollisionPick::getAvatarIntersection(const CollisionRegion& pi
return std::make_shared<CollisionPickResult>(pick.toVariantMap(), CollisionPickResult::LOAD_STATE_NOT_LOADED, std::vector<ContactTestResult>(), std::vector<ContactTestResult>()); return std::make_shared<CollisionPickResult>(pick.toVariantMap(), CollisionPickResult::LOAD_STATE_NOT_LOADED, std::vector<ContactTestResult>(), std::vector<ContactTestResult>());
} }
const auto& avatarIntersections = filterIntersections(_physicsEngine->getCollidingInRegion(MOTIONSTATE_TYPE_AVATAR, *pick.shapeInfo, pick.transform)); auto& avatarIntersections = _physicsEngine->getCollidingInRegion(MOTIONSTATE_TYPE_AVATAR, *pick.shapeInfo, pick.transform);
filterIntersections(avatarIntersections);
return std::make_shared<CollisionPickResult>(pick, CollisionPickResult::LOAD_STATE_LOADED, std::vector<ContactTestResult>(), avatarIntersections); return std::make_shared<CollisionPickResult>(pick, CollisionPickResult::LOAD_STATE_LOADED, std::vector<ContactTestResult>(), avatarIntersections);
} }

View file

@ -92,7 +92,7 @@ protected:
// Returns true if pick.shapeInfo is valid. Otherwise, attempts to get the shapeInfo ready for use. // Returns true if pick.shapeInfo is valid. Otherwise, attempts to get the shapeInfo ready for use.
bool isShapeInfoReady(); bool isShapeInfoReady();
void computeShapeInfo(CollisionRegion& pick, ShapeInfo& shapeInfo, QSharedPointer<GeometryResource> resource); void computeShapeInfo(CollisionRegion& pick, ShapeInfo& shapeInfo, QSharedPointer<GeometryResource> resource);
const std::vector<ContactTestResult> filterIntersections(const std::vector<ContactTestResult>& intersections) const; void filterIntersections(std::vector<ContactTestResult>& intersections) const;
CollisionRegion _mathPick; CollisionRegion _mathPick;
PhysicsEnginePointer _physicsEngine; PhysicsEnginePointer _physicsEngine;

View file

@ -944,7 +944,7 @@ protected:
} }
}; };
const std::vector<ContactTestResult> PhysicsEngine::getCollidingInRegion(MotionStateType desiredObjectType, const ShapeInfo& regionShapeInfo, const Transform& regionTransform) const { std::vector<ContactTestResult> PhysicsEngine::getCollidingInRegion(MotionStateType desiredObjectType, const ShapeInfo& regionShapeInfo, const Transform& regionTransform) const {
// TODO: Give MyAvatar a motion state so we don't have to do this // TODO: Give MyAvatar a motion state so we don't have to do this
btCollisionObject* myAvatarCollisionObject = nullptr; btCollisionObject* myAvatarCollisionObject = nullptr;
if (desiredObjectType == MOTIONSTATE_TYPE_AVATAR && _myAvatarController) { if (desiredObjectType == MOTIONSTATE_TYPE_AVATAR && _myAvatarController) {

View file

@ -126,7 +126,7 @@ public:
void setShowBulletConstraintLimits(bool value); void setShowBulletConstraintLimits(bool value);
// Function for getting colliding ObjectMotionStates in the world of specified type // Function for getting colliding ObjectMotionStates in the world of specified type
const std::vector<ContactTestResult> getCollidingInRegion(MotionStateType desiredObjectType, const ShapeInfo& regionShapeInfo, const Transform& regionTransform) const; std::vector<ContactTestResult> getCollidingInRegion(MotionStateType desiredObjectType, const ShapeInfo& regionShapeInfo, const Transform& regionTransform) const;
private: private:
QList<EntityDynamicPointer> removeDynamicsForBody(btRigidBody* body); QList<EntityDynamicPointer> removeDynamicsForBody(btRigidBody* body);