Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  How to know when all the particles are sleeping so I can de-activate the ObiEmitter
#4
(15-04-2020, 10:08 AM)josemendez Wrote: Kinetic energy is just 1/2*mass*sqr(velocity). Because we want the sleep threshold to work the same regardless of particle mass, internally we ignore mass in the formula, leaving: 1/2*sqr(velocity).

So simply iterate over all particles, checking if half of the squared magnitude of their velocity is below the sleep threshold.

Following this, I tried to get a function going, but I'm struggling figuring out how to access the sleep threshold value. Code below:

Code:
    bool CheckIfParticlesAreAsleep(ObiEmitter actor, ObiSolver objSolver) {        
        bool allAsleep = true;

        float sleepTreshold = 0.0001f; //objSolver.sleepTreshold;    //How do I get this value?

        for (int i = 0; i < actor.solverIndices.Length; ++i) {
            Vector3 velocity = objSolver.velocities[i];
            float particleKineticEnergy = 0.5f * Vector3.SqrMagnitude(velocity);

            if (particleKineticEnergy > sleepTreshold) {
                allAsleep = false;
                break;
            }
        }

        return allAsleep;
    }
Reply


Messages In This Thread
RE: How to know when all the particles are sleeping so I can de-activate the ObiEmitter - by facaelectrica - 16-04-2020, 10:55 PM