From 5f52e6a82f8de54cdfcf7ae09ca51c90f74f7444 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 23 Sep 2011 09:14:25 +0100 Subject: [PATCH] Added spherical and circular rand implementations --- glm/gtc/random.hpp | 8 ++++---- glm/gtc/random.inl | 35 +++++++++++++++++++++++++++++++++++ test/gtc/gtc_random.cpp | 4 ++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/glm/gtc/random.hpp b/glm/gtc/random.hpp index 79d66bfd..099e1095 100644 --- a/glm/gtc/random.hpp +++ b/glm/gtc/random.hpp @@ -66,10 +66,10 @@ namespace glm /// Generate random numbers in the interval [Min, Max], according a gaussian distribution /// (From GLM_GTX_random extension) - template class vecType> - vecType gaussRand( - vecType const & Mean, - vecType const & Deviation); + template + genType gaussRand( + genType const & Mean, + genType const & Deviation); /// Generate a random 2D vector which coordinates are regulary distributed on a circle of a given radius /// (From GLM_GTX_random extension) diff --git a/glm/gtc/random.inl b/glm/gtc/random.inl index 171fb474..b2020f3e 100644 --- a/glm/gtc/random.inl +++ b/glm/gtc/random.inl @@ -81,4 +81,39 @@ GLM_FUNC_QUALIFIER detail::tvec4 linearRand linearRand(Min.w, Max.w)); } +template <> +half gaussRand +( + half const & Mean, + half const & Deviation +) +{ + +template +detail::tvec2 circularRand +( + T const & Radius +) +{ + T a = compRand1(T(0), T(6.283185307179586476925286766559f)); + return detail::tvec2(cos(a), sin(a)) * Radius; +} + +template +detail::tvec3 sphericalRand +( + T const & Radius +) +{ + T z = compRand1(T(-1), T(1)); + T a = compRand1(T(0), T(6.283185307179586476925286766559f)); + + T r = sqrt(T(1) - z * z); + + T x = r * cos(a); + T y = r * sin(a); + + return detail::tvec3(x, y, z) * Radius; +} + }//namespace glm diff --git a/test/gtc/gtc_random.cpp b/test/gtc/gtc_random.cpp index bb8cf573..ff5999c4 100644 --- a/test/gtc/gtc_random.cpp +++ b/test/gtc/gtc_random.cpp @@ -12,7 +12,7 @@ #include #include -int test_signedRand1() +int test_linearRand() { int Error = 0; @@ -93,7 +93,7 @@ int main() { int Error = 0; - Error += test_signedRand1(); + Error += test_linearRand(); Error += test_normalizedRand2(); Error += test_normalizedRand3();