mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-27 23:56:25 +00:00
Core/Misc: update g3dlite lib (#2904)
* Core/Misc: update g3dlite lib * update Co-authored-by: Francesco Borzì <borzifrancesco@gmail.com>
This commit is contained in:
30
deps/g3dlite/source/Random.cpp
vendored
30
deps/g3dlite/source/Random.cpp
vendored
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
@file Random.cpp
|
||||
\file Random.cpp
|
||||
|
||||
@maintainer Morgan McGuire, http://graphics.cs.williams.edu
|
||||
\maintainer Morgan McGuire, http://graphics.cs.williams.edu
|
||||
|
||||
@created 2009-01-02
|
||||
@edited 2009-03-29
|
||||
\created 2009-01-02
|
||||
\edited 2012-03-29
|
||||
|
||||
Copyright 2000-2009, Morgan McGuire.
|
||||
Copyright 2000-2012, Morgan McGuire.
|
||||
All rights reserved.
|
||||
*/
|
||||
#include "G3D/Random.h"
|
||||
@@ -18,15 +18,23 @@ Random& Random::common() {
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
Random::Random(void* x) : state(NULL), m_threadsafe(false) {
|
||||
(void)x;
|
||||
}
|
||||
|
||||
|
||||
Random::Random(uint32 seed, bool threadsafe) : m_threadsafe(threadsafe) {
|
||||
state = new uint32[N];
|
||||
reset(seed, threadsafe);
|
||||
}
|
||||
|
||||
|
||||
void Random::reset(uint32 seed, bool threadsafe) {
|
||||
m_threadsafe = threadsafe;
|
||||
|
||||
const uint32 X = 1812433253UL;
|
||||
|
||||
state = new uint32[N];
|
||||
state[0] = seed;
|
||||
for (index = 1; index < (int)N; ++index) {
|
||||
state[index] = X * (state[index - 1] ^ (state[index - 1] >> 30)) + index;
|
||||
@@ -115,6 +123,7 @@ void Random::generate() {
|
||||
|
||||
|
||||
int Random::integer(int low, int high) {
|
||||
debugAssert(high >= low);
|
||||
int r = iFloor(low + (high - low + 1) * (double)bits() / 0xFFFFFFFFUL);
|
||||
|
||||
// There is a *very small* chance of generating
|
||||
@@ -147,6 +156,15 @@ float Random::gaussian(float mean, float stdev) {
|
||||
}
|
||||
|
||||
|
||||
void Random::cosSphere(float& x, float& y, float& z) {
|
||||
cosHemi(x, y, z);
|
||||
if (bits() & 1) {
|
||||
// Choose the axis direction uniformly at random
|
||||
z = -z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Random::cosHemi(float& x, float& y, float& z) {
|
||||
const float e1 = uniform();
|
||||
const float e2 = uniform();
|
||||
|
||||
Reference in New Issue
Block a user