bool ParticleEditHandle::updateParticle(glm::vec3 position, float radius, xColor color, glm::vec3 velocity, glm::vec3 gravity, float damping, bool inHand, QString updateScript) { if (!isKnownID()) { return false; // not allowed until we know the id } // setup a ParticleDetail struct with the data uint64_t now = usecTimestampNow(); ParticleDetail newParticleDetail = { _id, now, position, radius, {color.red, color.green, color.blue }, velocity, gravity, damping, inHand, updateScript, _creatorTokenID }; // queue the packet _packetSender->queueParticleEditMessages(PACKET_TYPE_PARTICLE_ADD_OR_EDIT, 1, &newParticleDetail); // release them _packetSender->releaseQueuedMessages(); // if we have a local tree, also update it... if (_localTree) { rgbColor rcolor = {color.red, color.green, color.blue }; Particle tempParticle(position, radius, rcolor, velocity, gravity, damping, inHand, updateScript, _id); _localTree->storeParticle(tempParticle); } return true; }
void ParticleInstance::emitNewParticles(float p_DeltaTime) { DirectX::XMFLOAT3 tempPos = DirectX::XMFLOAT3(m_SysPosition.x, m_SysPosition.y, m_SysPosition.z); DirectX::XMFLOAT4 tempColor = m_SysBaseColor; m_AccumulatedTime += p_DeltaTime; const float timePerParticle = 1.f / m_ParticleEffectDef->particlesPerSec; //check if new particles are to be emitted or not while (m_AccumulatedTime > timePerParticle) { m_AccumulatedTime -= timePerParticle; if (m_ParticleList.size() >= m_ParticleEffectDef->maxParticles) { break; } //Velocity std::uniform_real_distribution<float> velDistributionX(-m_ParticleEffectDef->velocityDeviation.x, m_ParticleEffectDef->velocityDeviation.x); std::uniform_real_distribution<float> velDistributionY(-m_ParticleEffectDef->velocityDeviation.y, m_ParticleEffectDef->velocityDeviation.y); std::uniform_real_distribution<float> velDistributionZ(-m_ParticleEffectDef->velocityDeviation.z, m_ParticleEffectDef->velocityDeviation.z); DirectX::XMFLOAT3 randVel( m_ParticleEffectDef->velocitybase.x + velDistributionX(m_RandomEngine), m_ParticleEffectDef->velocitybase.y + velDistributionY(m_RandomEngine), m_ParticleEffectDef->velocitybase.z + velDistributionZ(m_RandomEngine)); DirectX::XMMATRIX tempRotationM = DirectX::XMMatrixRotationRollPitchYaw(m_SysRotation.y, m_SysRotation.x, m_SysRotation.z); DirectX::XMVECTOR tempVEC = DirectX::XMLoadFloat3(&randVel); tempVEC = DirectX::XMVector3Transform(tempVEC, tempRotationM); DirectX::XMStoreFloat3(&randVel, tempVEC); //Position std::uniform_real_distribution<float> posDistribution(-m_ParticleEffectDef->particlePositionDeviation, m_ParticleEffectDef->particlePositionDeviation); DirectX::XMFLOAT3 randPos( tempPos.x + posDistribution(m_RandomEngine), tempPos.y + posDistribution(m_RandomEngine), tempPos.z + posDistribution(m_RandomEngine)); //Life std::uniform_real_distribution<float> lifeDistribution(-m_ParticleEffectDef->maxLifeDeviation, m_ParticleEffectDef->maxLifeDeviation); float randMaxLife = m_ParticleEffectDef->maxLife + lifeDistribution(m_RandomEngine); //Color std::uniform_real_distribution<float> oneToOneDistribution(-1.f, 1.f); DirectX::XMFLOAT4 randColorOffset( tempColor.x + oneToOneDistribution(m_RandomEngine) * m_ParticleEffectDef->particleColorDeviation.x, tempColor.y + oneToOneDistribution(m_RandomEngine) * m_ParticleEffectDef->particleColorDeviation.y, tempColor.z + oneToOneDistribution(m_RandomEngine) * m_ParticleEffectDef->particleColorDeviation.z, tempColor.w + oneToOneDistribution(m_RandomEngine) * m_ParticleEffectDef->particleColorDeviation.w); //Put all the new data for the new particle into one container Particle tempParticle(randPos, randVel, randColorOffset, m_ParticleEffectDef->size, 0.f, randMaxLife); //Add the new particle to the others in the same system m_ParticleList.push_back(tempParticle); } }