Exemple #1
0
Function::Function() {
  for (int i = 0; i < 6; ++i) {
    _coefs[i] = biunitRandom();
  }
  _red = unitRandom();
  _green = unitRandom();
  _blue = unitRandom();
  _nonLinear = randomTo(14);
}
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++;
            }
        }



    }
}