From 933721907bfedd2e28217c88544868729b517784 Mon Sep 17 00:00:00 2001 From: sariug Date: Wed, 8 Apr 2020 23:35:31 +0200 Subject: [PATCH] Mosra was right. --- src/Magnum/Math/Random.h | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Magnum/Math/Random.h b/src/Magnum/Math/Random.h index 28f3d9038..09d93fcea 100644 --- a/src/Magnum/Math/Random.h +++ b/src/Magnum/Math/Random.h @@ -58,15 +58,10 @@ public: namespace Random { template -T randomUnsignedScalar() // range [0, 1] +T randomScalar(T begin = 0.0f, T end = 1.0f) { - return Implementation::RandomGenerator::generate(static_cast(0.0f), - static_cast(1.0f)); -} -template -T randomSignedScalar() // range [-1, 1] -{ - return Implementation::RandomGenerator::generate(static_cast(-1.0f), static_cast(1.0f)); + return Implementation::RandomGenerator::generate(static_cast(begin), + static_cast(end)); } template @@ -82,7 +77,7 @@ Vector3 randomUnitVector3() // Better to have it "theta" and "z" than three random numbers. // https://mathworld.wolfram.com/SpherePointPicking.html auto a = Implementation::RandomGenerator::generate(0.0f, 2 * Math::Constants::pi()); - auto z = randomSignedScalar(); + auto z = randomScalar(-1.0f, -1.0f); auto r = sqrt(1 - z * z); return {r * std::cos(a), r * std::sin(a), z}; } @@ -91,9 +86,9 @@ template Quaternion randomRotation() { //http://planning.cs.uiuc.edu/node198.html - auto u{randomUnsignedScalar()}; - auto v{2 * Math::Constants::pi() * randomUnsignedScalar()}; - auto w{2 * Math::Constants::pi() * randomUnsignedScalar()}; + auto u{randomScalar()}; + auto v{2 * Math::Constants::pi() * randomScalar()}; + auto w{2 * Math::Constants::pi() * randomScalar()}; return Quaternion({sqrt(1 - u) * std::sin(v), sqrt(1 - u) * std::cos(v), sqrt(u) * std::sin(w)},