void SamplePool::Load() { Path sampleDir("samples:"); I_Dir *dir=FileSystem::GetInstance()->Open(sampleDir.GetPath().c_str()) ; if (!dir) { return ; } // First, find all wav files dir->GetContent("*.wav") ; IteratorPtr<Path> it(dir->GetIterator()) ; count_=0 ; for(it->Begin();!it->IsDone();it->Next()) { Path &path=it->CurrentItem() ; // Trace::Dump("Got sample name '%s'",name) ; loadSample(path.GetPath().c_str()) ; if (count_==MAX_PIG_SAMPLES) { Trace::Error("Warning maximum sample count reached") ; break ; } ; } ; // now, let's look at soundfonts dir->GetContent("*.sf2") ; IteratorPtr<Path> it2(dir->GetIterator()) ; for(it2->Begin();!it2->IsDone();it2->Next()) { Path &path=it2->CurrentItem() ; loadSoundFont(path.GetPath().c_str()) ; } ; delete dir ; // now sort the samples int rest=count_ ; while(rest>0) { int index=0 ; for (int i=1;i<rest;i++) { if (strcmp(names_[i],names_[index])>0) { index=i ; }; } ; SoundSource *tWav=wav_[index] ; char *tName=names_[index] ; wav_[index]=wav_[rest-1] ; names_[index]=names_[rest-1] ; wav_[rest-1]=tWav; names_[rest-1]=tName ; rest-- ; } ; } ;
void ParticleGenerator::initialize() { for (int i = 0; i < nMaxPtc; i++) { //double randVal = unitRandom(20); m_Particles[i].pos = pos; m_Particles[i].vel = sampleDir(i) * (mVel + unitRandom(sample_div) * mVelVar); m_Particles[i].life[1] = mLife + (2 * unitRandom(sample_div) - 1.0) * mLifeVar; if (i < nPerFrame) { m_Particles[i].alive = true; } } }
void ParticleGenerator::updateStatus() { Vector3D preVel; Point3D prePos; DifferentialGeometry* intersection = new DifferentialGeometry; Float *tHit = new Float, *hitEpsilon = new Float; for (int i = 0, nGen = 0; i < nMaxPtc; i++) { Particle* curPtc = m_Particles + i; // Current Particle if (curPtc->alive) { if (curPtc->updateLifeStatus(timestep)) // if particle alive { preVel = curPtc->vel; prePos = curPtc->pos; // Update force influence curPtc->vel += timestep * m_totalForce; curPtc->pos += (curPtc->vel + preVel) * timestep * 0.5; // Update field influence // Do something here // Update collision // Do something here... if (m_Collisions.size() > 0) { for (auto curCllsn : m_Collisions) { if (Collision::collide(prePos, curPtc->pos, curCllsn, intersection, tHit, hitEpsilon)) { intersection->object->getNormal(intersection); curPtc->vel = 0.5 * (curPtc->vel - intersection->normal * (curPtc->vel * intersection->normal) * 2); curPtc->pos = prePos;// intersection->pos + curPtc->vel * 0.5; } /*if (curCllsn->inLeaf(curPtc->pos)) { curPtc->vel = -curPtc->vel; }*/ } } } else { nPtc--; } } else { if (nPtc < nMaxAlive && nGen < nPerFrame) { curPtc->activate(pos, sampleDir(i) * (mVel + unitRandom(255) * mVelVar)); nPtc++; nGen++; } } } }