bool VortexParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps) { if(getBeacon() != NULL) { Matrix BeaconToWorld(getBeacon()->getToWorld()); Vec3f translation, tmp; Quaternion tmp2; BeaconToWorld.getTransform(translation,tmp2,tmp,tmp2); Pnt3f particlePos = System->getPosition(ParticleIndex); Real32 distanceFromAffector = particlePos.dist(Pnt3f(translation.x(),translation.y(),translation.z())); if((getMaxDistance() < 0.0) || (distanceFromAffector <= getMaxDistance())) //only affect the particle if it is in range { Vec3f particleDirectionFromVortex(particlePos.x() - translation.x(), particlePos.y() - translation.y(), particlePos.z() - translation.z()); particleDirectionFromVortex = particleDirectionFromVortex.cross(getVortexAxis()); particleDirectionFromVortex.normalize(); particleDirectionFromVortex = particleDirectionFromVortex * ((-getMagnitude() * elps)/OSG::osgClamp<Real32>(1.0f,std::pow(distanceFromAffector,getAttenuation()),TypeTraits<Real32>::getMax())); System->setVelocity(particleDirectionFromVortex + System->getVelocity(ParticleIndex),ParticleIndex); } } return false; }
bool TurbulenceParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps) { if(getBeacon() != NULL) { Matrix BeaconToWorld(getBeacon()->getToWorld()); Vec3f translation, tmp; Quaternion tmp2; BeaconToWorld.getTransform(translation,tmp2,tmp,tmp2); Pnt3f particlePos = System->getPosition(ParticleIndex); Real32 distanceFromAffector = particlePos.dist(Pnt3f(translation.x(),translation.y(),translation.z())); if((getMaxDistance() < 0.0) || (distanceFromAffector <= getMaxDistance())) //only affect the particle if it is in range { Real32 Xparam, Yparam, Zparam; Pnt3f pos(System->getPosition(ParticleIndex)); getPerlinDistribution()->setPhase(getPhase()[0]); Xparam = getPerlinDistribution()->generate(pos[0]); getPerlinDistribution()->setPhase(getPhase()[1]); Yparam = getPerlinDistribution()->generate(pos[1]); getPerlinDistribution()->setPhase(getPhase()[2]); Zparam = getPerlinDistribution()->generate(pos[2]); Vec3f fieldAffect(Vec3f(Xparam, Yparam, Zparam)); fieldAffect = fieldAffect * (getAmplitude()* (elps/(OSG::osgClamp<Real32>(1.0f,std::pow(distanceFromAffector,getAttenuation()),TypeTraits<Real32>::getMax())))); System->setVelocity(System->getVelocity(ParticleIndex) + fieldAffect, ParticleIndex); } // end distance conditional } // end null beacon conditional return false; }
bool RandomMovementParticleAffector::affect(ParticleSystemRefPtr System, Int32 ParticleIndex, const Time& elps) { //System->setUpdateSecAttribs(false); Real32 x, y, z, age(System->getAge(ParticleIndex)); if(getAttributeAffected() == VELOCITY_ATTRIBUTE) { Vec3f vel = System->getSecVelocity(ParticleIndex); // grab each value independently , and adjust the phase for each // axis, since we have a 3D phase and the 1D distribution only takes // one value Real32 velSum = vel.x() + vel.y() + vel.z(); getPerlinDistribution()->setPhase(getPhase().x() + velSum); x = getPerlinDistribution()->generate(vel.x() + age); getPerlinDistribution()->setPhase(getPhase().y() + velSum); y = getPerlinDistribution()->generate(vel.y() + age); getPerlinDistribution()->setPhase(getPhase().z() + velSum); z = getPerlinDistribution()->generate(vel.z() + age); System->setVelocity(Vec3f(x,y,z) + vel,ParticleIndex); }else // affecting position { Pnt3f pos = System->getSecPosition(ParticleIndex); Real32 posSum = pos.x() + pos.y() + pos.z(); getPerlinDistribution()->setPhase(getPhase().x() + posSum); x = getPerlinDistribution()->generate(pos.x() + age); getPerlinDistribution()->setPhase(getPhase().y() + posSum); y = getPerlinDistribution()->generate(pos.y() + age); getPerlinDistribution()->setPhase(getPhase().z() + posSum); z = getPerlinDistribution()->generate(pos.z() + age); System->setPosition(Pnt3f(x,y,z) + pos.subZero(),ParticleIndex); } return false; }