mirror of
https://github.com/celisej567/mcpe.git
synced 2026-01-04 14:09:47 +03:00
* Add functional snow rendering code.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user