mirror of
https://github.com/g-truc/glm.git
synced 2024-11-26 18:24:35 +00:00
Added spherical and circular rand implementations
This commit is contained in:
parent
7df14e51dd
commit
5f52e6a82f
@ -66,10 +66,10 @@ namespace glm
|
|||||||
|
|
||||||
/// Generate random numbers in the interval [Min, Max], according a gaussian distribution
|
/// Generate random numbers in the interval [Min, Max], according a gaussian distribution
|
||||||
/// (From GLM_GTX_random extension)
|
/// (From GLM_GTX_random extension)
|
||||||
template <typename T, template <typename> class vecType>
|
template <typename genType>
|
||||||
vecType<T> gaussRand(
|
genType gaussRand(
|
||||||
vecType<T> const & Mean,
|
genType const & Mean,
|
||||||
vecType<T> const & Deviation);
|
genType const & Deviation);
|
||||||
|
|
||||||
/// Generate a random 2D vector which coordinates are regulary distributed on a circle of a given radius
|
/// Generate a random 2D vector which coordinates are regulary distributed on a circle of a given radius
|
||||||
/// (From GLM_GTX_random extension)
|
/// (From GLM_GTX_random extension)
|
||||||
|
@ -81,4 +81,39 @@ GLM_FUNC_QUALIFIER detail::tvec4<T> linearRand
|
|||||||
linearRand(Min.w, Max.w));
|
linearRand(Min.w, Max.w));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
half gaussRand
|
||||||
|
(
|
||||||
|
half const & Mean,
|
||||||
|
half const & Deviation
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
detail::tvec2<T> circularRand
|
||||||
|
(
|
||||||
|
T const & Radius
|
||||||
|
)
|
||||||
|
{
|
||||||
|
T a = compRand1<T>(T(0), T(6.283185307179586476925286766559f));
|
||||||
|
return detail::tvec2<T>(cos(a), sin(a)) * Radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
detail::tvec3<T> 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<T>(x, y, z) * Radius;
|
||||||
|
}
|
||||||
|
|
||||||
}//namespace glm
|
}//namespace glm
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include <glm/gtx/epsilon.hpp>
|
#include <glm/gtx/epsilon.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int test_signedRand1()
|
int test_linearRand()
|
||||||
{
|
{
|
||||||
int Error = 0;
|
int Error = 0;
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ int main()
|
|||||||
{
|
{
|
||||||
int Error = 0;
|
int Error = 0;
|
||||||
|
|
||||||
Error += test_signedRand1();
|
Error += test_linearRand();
|
||||||
Error += test_normalizedRand2();
|
Error += test_normalizedRand2();
|
||||||
Error += test_normalizedRand3();
|
Error += test_normalizedRand3();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user