Last active
August 16, 2021 20:01
-
-
Save joeld42/f255f26b18829ed0d98161ec90ed5ff0 to your computer and use it in GitHub Desktop.
number of particles to emit for a given rate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size_t EmitterNode::_numPartsForRate(float rate, float dt) {// number of parts to emit | |
size_t numParts = 0; | |
float numPartsReal = rate * dt; | |
// Treat fractional particles as a probability -- e.g. .3 particles | |
// means 30% chance to emit | |
float numPartsF = floor(numPartsReal); | |
float partProb = numPartsReal - numPartsF; | |
numParts = (size_t)numPartsF; | |
if (randUniform() < partProb) | |
{ | |
numParts++; | |
} | |
return numParts; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment