16-04-2020, 10:55 PM
(This post was last modified: 16-04-2020, 11:18 PM by facaelectrica.)
(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;
}