mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 02:25:48 +02:00
Adding ParticleTree::findParticles(box, QVector<Particle*>) method
This commit is contained in:
parent
998b772be4
commit
5cc2b029cf
2 changed files with 34 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue