mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 16:36:54 +02:00
spherical queries into Octree use meters
This commit is contained in:
parent
7836bb4dcd
commit
e1954d3e1d
5 changed files with 20 additions and 9 deletions
|
@ -476,8 +476,9 @@ public:
|
||||||
bool EntityTree::findInSphereOperation(OctreeElement* element, void* extraData) {
|
bool EntityTree::findInSphereOperation(OctreeElement* element, void* extraData) {
|
||||||
FindAllNearPointArgs* args = static_cast<FindAllNearPointArgs*>(extraData);
|
FindAllNearPointArgs* args = static_cast<FindAllNearPointArgs*>(extraData);
|
||||||
glm::vec3 penetration;
|
glm::vec3 penetration;
|
||||||
bool sphereIntersection = element->getAACube().findSpherePenetration(args->position,
|
AACube cube = element->getAACube();
|
||||||
args->targetRadius, penetration);
|
cube *= (float)TREE_SCALE;
|
||||||
|
bool sphereIntersection = cube.findSpherePenetration(args->position, args->targetRadius, penetration);
|
||||||
|
|
||||||
// If this element contains the point, then search it...
|
// If this element contains the point, then search it...
|
||||||
if (sphereIntersection) {
|
if (sphereIntersection) {
|
||||||
|
@ -493,7 +494,7 @@ bool EntityTree::findInSphereOperation(OctreeElement* element, void* extraData)
|
||||||
// NOTE: assumes caller has handled locking
|
// NOTE: assumes caller has handled locking
|
||||||
void EntityTree::findEntitiesInMeters(const glm::vec3& center, float radius, QVector<const EntityItem*>& foundEntities) {
|
void EntityTree::findEntitiesInMeters(const glm::vec3& center, float radius, QVector<const EntityItem*>& foundEntities) {
|
||||||
// position and targetRadius are in meters, so we need to convert to TreeUnits in FindNearPointArgs
|
// position and targetRadius are in meters, so we need to convert to TreeUnits in FindNearPointArgs
|
||||||
FindAllNearPointArgs args = { center / (float)TREE_SCALE, radius / (float)TREE_SCALE };
|
FindAllNearPointArgs args = { center, radius };
|
||||||
// NOTE: This should use recursion, since this is a spatial operation
|
// NOTE: This should use recursion, since this is a spatial operation
|
||||||
recurseTreeWithOperation(findInSphereOperation, &args);
|
recurseTreeWithOperation(findInSphereOperation, &args);
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,7 @@ private:
|
||||||
bool updateEntityWithElement(EntityItem* entity, const EntityItemProperties& properties,
|
bool updateEntityWithElement(EntityItem* entity, const EntityItemProperties& properties,
|
||||||
EntityTreeElement* containingElement, bool allowLockChange);
|
EntityTreeElement* containingElement, bool allowLockChange);
|
||||||
static bool findNearPointOperation(OctreeElement* element, void* extraData);
|
static bool findNearPointOperation(OctreeElement* element, void* extraData);
|
||||||
static bool findInSphereOperation(OctreeElement* element, void* extraData);
|
static bool findInSphereOperationInMeters(OctreeElement* element, void* extraData);
|
||||||
static bool findInCubeOperation(OctreeElement* element, void* extraData);
|
static bool findInCubeOperation(OctreeElement* element, void* extraData);
|
||||||
static bool sendEntitiesOperation(OctreeElement* element, void* extraData);
|
static bool sendEntitiesOperation(OctreeElement* element, void* extraData);
|
||||||
|
|
||||||
|
|
|
@ -748,8 +748,11 @@ public:
|
||||||
bool findSpherePenetrationOp(OctreeElement* element, void* extraData) {
|
bool findSpherePenetrationOp(OctreeElement* element, void* extraData) {
|
||||||
SphereArgs* args = static_cast<SphereArgs*>(extraData);
|
SphereArgs* args = static_cast<SphereArgs*>(extraData);
|
||||||
|
|
||||||
|
// the details in args is in meters (world-frame) so we have to scale the element cube up
|
||||||
|
AACube box = element->getAACube();
|
||||||
|
box *= (float)TREE_SCALE;
|
||||||
|
|
||||||
// coarse check against bounds
|
// coarse check against bounds
|
||||||
const AACube& box = element->getAACube();
|
|
||||||
if (!box.expandedContains(args->center, args->radius)) {
|
if (!box.expandedContains(args->center, args->radius)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -758,7 +761,7 @@ bool findSpherePenetrationOp(OctreeElement* element, void* extraData) {
|
||||||
if (element->findSpherePenetration(args->center, args->radius, elementPenetration, &args->penetratedObject)) {
|
if (element->findSpherePenetration(args->center, args->radius, elementPenetration, &args->penetratedObject)) {
|
||||||
// NOTE: it is possible for this penetration accumulation algorithm to produce a
|
// NOTE: it is possible for this penetration accumulation algorithm to produce a
|
||||||
// final penetration vector with zero length.
|
// final penetration vector with zero length.
|
||||||
args->penetration = addPenetrations(args->penetration, elementPenetration * (float)(TREE_SCALE));
|
args->penetration = addPenetrations(args->penetration, elementPenetration);
|
||||||
args->found = true;
|
args->found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -772,8 +775,8 @@ bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::v
|
||||||
void** penetratedObject, Octree::lockType lockType, bool* accurateResult) {
|
void** penetratedObject, Octree::lockType lockType, bool* accurateResult) {
|
||||||
|
|
||||||
SphereArgs args = {
|
SphereArgs args = {
|
||||||
center / (float)(TREE_SCALE),
|
center,
|
||||||
radius / (float)(TREE_SCALE),
|
radius,
|
||||||
penetration,
|
penetration,
|
||||||
false,
|
false,
|
||||||
NULL };
|
NULL };
|
||||||
|
|
|
@ -1390,7 +1390,10 @@ bool OctreeElement::findDetailedRayIntersection(const glm::vec3& origin, const g
|
||||||
|
|
||||||
bool OctreeElement::findSpherePenetration(const glm::vec3& center, float radius,
|
bool OctreeElement::findSpherePenetration(const glm::vec3& center, float radius,
|
||||||
glm::vec3& penetration, void** penetratedObject) const {
|
glm::vec3& penetration, void** penetratedObject) const {
|
||||||
return _cube.findSpherePenetration(center, radius, penetration);
|
// center and radius are in meters, so we have to scale the _cube into world-frame
|
||||||
|
AACube cube = _cube;
|
||||||
|
cube *= (float)TREE_SCALE;
|
||||||
|
return cube.findSpherePenetration(center, radius, penetration);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: consider removing this, or switching to using getOrCreateChildElementContaining(const AACube& box)...
|
// TODO: consider removing this, or switching to using getOrCreateChildElementContaining(const AACube& box)...
|
||||||
|
|
|
@ -125,6 +125,10 @@ public:
|
||||||
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
|
||||||
void** intersectedObject, bool precisionPicking, float distanceToElementCube);
|
void** intersectedObject, bool precisionPicking, float distanceToElementCube);
|
||||||
|
|
||||||
|
/// \param center center of sphere in meters
|
||||||
|
/// \param radius radius of sphere in meters
|
||||||
|
/// \param[out] penetration pointing into cube from sphere
|
||||||
|
/// \param penetratedObject unused
|
||||||
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
virtual bool findSpherePenetration(const glm::vec3& center, float radius,
|
||||||
glm::vec3& penetration, void** penetratedObject) const;
|
glm::vec3& penetration, void** penetratedObject) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue