From 50b93d1e2ba7e8e415e541d8cde22933b2ad411d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 12 Dec 2013 12:40:38 -0800 Subject: [PATCH] added easy access to creating a ParticleEditHandle for a know particle ID --- interface/src/Application.cpp | 8 +++++++- interface/src/Application.h | 1 + interface/src/avatar/Hand.cpp | 6 ++++++ libraries/particles/src/Particle.h | 2 ++ .../particles/src/ParticleEditHandle.cpp | 19 +++++++++++++------ libraries/particles/src/ParticleEditHandle.h | 4 +++- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9075e235a9..1ab9dea1f3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1523,11 +1523,17 @@ void Application::shootParticle() { delete particleEditHandle; } +// Caller is responsible for managing this EditableParticle +ParticleEditHandle* Application::newParticleEditHandle(uint32_t id) { + ParticleEditHandle* particleEditHandle = new ParticleEditHandle(&_particleEditSender, _particles.getTree()); + return particleEditHandle; +} + // Caller is responsible for managing this EditableParticle ParticleEditHandle* Application::makeParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity, glm::vec3 gravity, float damping, QString updateScript) { - ParticleEditHandle* particleEditHandle = new ParticleEditHandle(&_particleEditSender, _particles.getTree()); + ParticleEditHandle* particleEditHandle = newParticleEditHandle(); particleEditHandle->createParticle(position, radius, color, velocity, gravity, damping, updateScript); return particleEditHandle; } diff --git a/interface/src/Application.h b/interface/src/Application.h index 601bec8573..fd44d44ea1 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -121,6 +121,7 @@ public: void wheelEvent(QWheelEvent* event); void shootParticle(); // shoots a particle in the direction you're looking + ParticleEditHandle* newParticleEditHandle(uint32_t id = NEW_PARTICLE); ParticleEditHandle* makeParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity, glm::vec3 gravity, float damping, QString updateScript); diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 00ddc4d301..32a9c26d36 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -69,6 +69,12 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f if (closestParticle) { printf("potentially caught... particle ID:%d\n", closestParticle->getID()); + + // you can create a ParticleEditHandle by doing this... + ParticleEditHandle* caughtParticle = Application::getInstance()->newParticleEditHandle(closestParticle->getID()); + + // but make sure you clean it up, when you're done + delete caughtParticle; } // Is the controller button being held down.... diff --git a/libraries/particles/src/Particle.h b/libraries/particles/src/Particle.h index 764f10c87d..bfdcbdd338 100644 --- a/libraries/particles/src/Particle.h +++ b/libraries/particles/src/Particle.h @@ -20,6 +20,8 @@ #include const uint32_t NEW_PARTICLE = 0xFFFFFFFF; +const uint32_t UNKNOWN_TOKEN = 0xFFFFFFFF; + class ParticleDetail { public: uint32_t id; diff --git a/libraries/particles/src/ParticleEditHandle.cpp b/libraries/particles/src/ParticleEditHandle.cpp index 27182b24e0..c14c960d3f 100644 --- a/libraries/particles/src/ParticleEditHandle.cpp +++ b/libraries/particles/src/ParticleEditHandle.cpp @@ -16,15 +16,22 @@ std::map ParticleEditHandle::_allHandles; uint32_t ParticleEditHandle::_nextCreatorTokenID = 0; -ParticleEditHandle::ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree) { - _creatorTokenID = _nextCreatorTokenID; - _nextCreatorTokenID++; - _id = NEW_PARTICLE; - _isKnownID = false; +ParticleEditHandle::ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree, uint32_t id) { + if (id == NEW_PARTICLE) { + _creatorTokenID = _nextCreatorTokenID; + _nextCreatorTokenID++; + _id = NEW_PARTICLE; + _isKnownID = false; + _allHandles[_creatorTokenID] = this; + } else { + _creatorTokenID = UNKNOWN_TOKEN; + _id = id; + _isKnownID = true; + // don't add to _allHandles because we already know it... + } _packetSender = packetSender; _localTree = localTree; - _allHandles[_creatorTokenID] = this; } ParticleEditHandle::~ParticleEditHandle() { diff --git a/libraries/particles/src/ParticleEditHandle.h b/libraries/particles/src/ParticleEditHandle.h index 2e81f35abf..bed8b29d14 100644 --- a/libraries/particles/src/ParticleEditHandle.h +++ b/libraries/particles/src/ParticleEditHandle.h @@ -19,12 +19,14 @@ #include #include +#include "Particle.h" + class ParticleEditPacketSender; class ParticleTree; class ParticleEditHandle { public: - ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree); + ParticleEditHandle(ParticleEditPacketSender* packetSender, ParticleTree* localTree, uint32_t id = NEW_PARTICLE); ~ParticleEditHandle(); uint32_t getCreatorTokenID() const { return _creatorTokenID; }