* Add functional snow rendering code.

This commit is contained in:
iProgramInCpp
2023-12-30 18:57:43 +02:00
parent e9da87bfa0
commit 3c382d13b7
6 changed files with 119 additions and 5 deletions

View File

@@ -18,6 +18,7 @@
Random::Random(TLong seed)
{
setSeed(seed);
nextNextGaussian = INFINITY;
}
void Random::setSeed(TLong seed)
@@ -105,3 +106,25 @@ int Random::nextInt()
{
return int(genrand_int32() >> 1);
}
float Random::nextGaussian()
{
if (!isinf(nextNextGaussian))
{
double backup = nextNextGaussian;
nextNextGaussian = INFINITY;
return backup;
}
// See Knuth, ACP, Section 3.4.1 Algorithm C.
float v1, v2, s;
do
{
v1 = 2 * nextFloat() - 1;
v2 = 2 * nextFloat() - 1;
s = v1 * v1 + v2 * v2;
}
while (s >= 1 || s == 0);
float mult = sqrtf(-2 * log(s) / s);
nextNextGaussian = v2 * mult;
return v1 * mult;
}

View File

@@ -42,6 +42,7 @@ class Random
unsigned int rseed;
unsigned TLong mt[CMATH_N]; // the array for the state vector
int mti; // mti==N+1 means mt[N] is not initialized
double nextNextGaussian;
public:
Random(TLong seed = getTimeMs());
@@ -53,4 +54,5 @@ public:
double genrand_real2();
TLong nextLong();
int nextInt();
float nextGaussian();
};