mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 21:36:47 +02:00
Add pick filtering to CollisionPick
This commit is contained in:
parent
658ef4e9e6
commit
c40db2e8f0
2 changed files with 19 additions and 2 deletions
|
@ -316,13 +316,29 @@ CollisionRegion CollisionPick::getMathematicalPick() const {
|
||||||
return _mathPick;
|
return _mathPick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<ContactTestResult> CollisionPick::filterIntersections(const std::vector<ContactTestResult>& intersections) const {
|
||||||
|
std::vector<ContactTestResult> filteredIntersections;
|
||||||
|
|
||||||
|
const QVector<QUuid>& ignoreItems = getIgnoreItems();
|
||||||
|
const QVector<QUuid>& includeItems = getIncludeItems();
|
||||||
|
bool isWhitelist = includeItems.size();
|
||||||
|
for (const auto& intersection : intersections) {
|
||||||
|
const QUuid& id = intersection.foundID;
|
||||||
|
if (!ignoreItems.contains(id) && (!isWhitelist || includeItems.contains(id))) {
|
||||||
|
filteredIntersections.push_back(intersection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filteredIntersections;
|
||||||
|
}
|
||||||
|
|
||||||
PickResultPointer CollisionPick::getEntityIntersection(const CollisionRegion& pick) {
|
PickResultPointer CollisionPick::getEntityIntersection(const CollisionRegion& pick) {
|
||||||
if (!isShapeInfoReady()) {
|
if (!isShapeInfoReady()) {
|
||||||
// Cannot compute result
|
// Cannot compute result
|
||||||
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 = _physicsEngine->getCollidingInRegion(MOTIONSTATE_TYPE_ENTITY, *pick.shapeInfo, pick.transform);
|
const auto& entityIntersections = filterIntersections(_physicsEngine->getCollidingInRegion(MOTIONSTATE_TYPE_ENTITY, *pick.shapeInfo, pick.transform));
|
||||||
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>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +352,7 @@ 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 = _physicsEngine->getCollidingInRegion(MOTIONSTATE_TYPE_AVATAR, *pick.shapeInfo, pick.transform);
|
const auto& avatarIntersections = filterIntersections(_physicsEngine->getCollidingInRegion(MOTIONSTATE_TYPE_AVATAR, *pick.shapeInfo, pick.transform));
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,6 +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;
|
||||||
|
|
||||||
CollisionRegion _mathPick;
|
CollisionRegion _mathPick;
|
||||||
PhysicsEnginePointer _physicsEngine;
|
PhysicsEnginePointer _physicsEngine;
|
||||||
|
|
Loading…
Reference in a new issue