mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 09:33:29 +02:00
add findContentInCube() and typedef CubeList
This commit is contained in:
parent
06e1d4a8bc
commit
54463ab668
2 changed files with 40 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
|||
#include <fstream> // to load voxels from file
|
||||
|
||||
#include <QDebug>
|
||||
#include <QVector>
|
||||
|
||||
#include <GeometryUtil.h>
|
||||
#include <OctalCode.h>
|
||||
|
@ -730,6 +731,12 @@ public:
|
|||
bool found;
|
||||
};
|
||||
|
||||
class ContentArgs {
|
||||
public:
|
||||
AACube cube;
|
||||
CubeList* cubes;
|
||||
};
|
||||
|
||||
bool findCapsulePenetrationOp(OctreeElement* element, void* extraData) {
|
||||
CapsuleArgs* args = static_cast<CapsuleArgs*>(extraData);
|
||||
|
||||
|
@ -772,6 +779,25 @@ bool findShapeCollisionsOp(OctreeElement* element, void* extraData) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool findContentInCubeOp(OctreeElement* element, void* extraData) {
|
||||
ContentArgs* args = static_cast<ContentArgs*>(extraData);
|
||||
|
||||
// coarse check against bounds
|
||||
AACube cube = element->getAACube();
|
||||
cube.scale(TREE_SCALE);
|
||||
if (!cube.touches(args->cube)) {
|
||||
return false;
|
||||
}
|
||||
if (!element->isLeaf()) {
|
||||
return true; // recurse on children
|
||||
}
|
||||
if (element->hasContent()) {
|
||||
args->cubes->push_back(cube);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius,
|
||||
glm::vec3& penetration, Octree::lockType lockType, bool* accurateResult) {
|
||||
|
||||
|
@ -840,6 +866,16 @@ bool Octree::findShapeCollisions(const Shape* shape, CollisionList& collisions,
|
|||
return args.found;
|
||||
}
|
||||
|
||||
bool Octree::findContentInCube(const AACube& cube, CubeList& cubes) {
|
||||
if (!tryLockForRead()) {
|
||||
return false;
|
||||
}
|
||||
ContentArgs args = { cube, &cubes };
|
||||
recurseTreeWithOperation(findContentInCubeOp, &args);
|
||||
unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
class GetElementEnclosingArgs {
|
||||
public:
|
||||
OctreeElement* element;
|
||||
|
|
|
@ -35,6 +35,7 @@ class Shape;
|
|||
|
||||
#include <QObject>
|
||||
#include <QReadWriteLock>
|
||||
#include <QVector>
|
||||
|
||||
/// derive from this class to use the Octree::recurseTreeWithOperator() method
|
||||
class RecurseOctreeOperator {
|
||||
|
@ -46,6 +47,7 @@ public:
|
|||
// Callback function, for recuseTreeWithOperation
|
||||
typedef bool (*RecurseOctreeOperation)(OctreeElement* element, void* extraData);
|
||||
typedef enum {GRADIENT, RANDOM, NATURAL} creationMode;
|
||||
typedef QVector<AACube> CubeList;
|
||||
|
||||
const bool NO_EXISTS_BITS = false;
|
||||
const bool WANT_EXISTS_BITS = true;
|
||||
|
@ -280,6 +282,8 @@ public:
|
|||
bool findShapeCollisions(const Shape* shape, CollisionList& collisions,
|
||||
Octree::lockType = Octree::TryLock, bool* accurateResult = NULL);
|
||||
|
||||
bool findContentInCube(const AACube& cube, CubeList& cubes);
|
||||
|
||||
OctreeElement* getElementEnclosingPoint(const glm::vec3& point,
|
||||
Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL);
|
||||
|
||||
|
|
Loading…
Reference in a new issue