added easy access to creating a ParticleEditHandle for a know particle ID

This commit is contained in:
ZappoMan 2013-12-12 12:40:38 -08:00
parent cd830efdd4
commit 50b93d1e2b
6 changed files with 32 additions and 8 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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....

View file

@ -20,6 +20,8 @@
#include <OctreePacketData.h>
const uint32_t NEW_PARTICLE = 0xFFFFFFFF;
const uint32_t UNKNOWN_TOKEN = 0xFFFFFFFF;
class ParticleDetail {
public:
uint32_t id;

View file

@ -16,15 +16,22 @@ std::map<uint32_t,ParticleEditHandle*> 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() {

View file

@ -19,12 +19,14 @@
#include <SharedUtil.h>
#include <OctreePacketData.h>
#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; }