Adding ParticleTree::findParticles(box, QVector<Particle*>) method

This commit is contained in:
Andrew Meadows 2014-01-24 14:01:34 -08:00
parent 998b772be4
commit 5cc2b029cf
2 changed files with 34 additions and 0 deletions

View file

@ -458,3 +458,31 @@ void ParticleTree::processEraseMessage(const QByteArray& dataByteArray, const Hi
recurseTreeWithOperation(findAndDeleteOperation, &args);
}
}
class FindParticlesArgs {
public:
FindParticlesArgs(const AABox& box)
: _box(box), _foundParticles() {
}
AABox _box;
QVector<Particle*> _foundParticles;
};
bool findOperation(OctreeElement* element, void* extraData) {
FindParticlesArgs* args = static_cast< FindParticlesArgs*>(extraData);
const AABox& elementBox = element->getAABox();
if (elementBox.touches(args->_box)) {
ParticleTreeElement* particleTreeElement = static_cast<ParticleTreeElement*>(element);
particleTreeElement->findParticles(args->_box, args->_foundParticles);
return true;
}
return false;
}
void ParticleTree::findParticles(const AABox& box, QVector<Particle*> foundParticles) {
FindParticlesArgs args(box);
recurseTreeWithOperation(findOperation, &args);
// swap the two lists of particle pointers instead of copy
foundParticles.swap(args._foundParticles);
}

View file

@ -53,6 +53,12 @@ public:
void processEraseMessage(const QByteArray& dataByteArray, const HifiSockAddr& senderSockAddr, Node* sourceNode);
/// finds all particles that touch a box
/// \param box the query box
/// \param particles[out] vector of Particle pointer
/// \remark Side effect: any initial contents in particles will be lost
void findParticles(const AABox& box, QVector<Particle*> particles);
private:
static bool updateOperation(OctreeElement* element, void* extraData);