mirror of
https://github.com/g-truc/glm.git
synced 2024-11-23 09:14:34 +00:00
Merge pull request #708 from corporateshark/master
Fixed #692: sphericalRand() is doing correct distribution on a sphere #708
This commit is contained in:
commit
fa668e26b6
@ -340,13 +340,12 @@ namespace detail
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
GLM_FUNC_QUALIFIER vec<3, T, defaultp> sphericalRand(T Radius)
|
GLM_FUNC_QUALIFIER vec<3, T, defaultp> sphericalRand(T Radius)
|
||||||
{
|
{
|
||||||
T z = linearRand(T(-1), T(1));
|
T theta = linearRand(T(0), T(6.283185307179586476925286766559f));
|
||||||
T a = linearRand(T(0), T(6.283185307179586476925286766559f));
|
T phi = std::acos(linearRand(T(-1.0f), T(1.0f)));
|
||||||
|
|
||||||
T r = sqrt(T(1) - z * z);
|
T x = std::sin(phi) * std::cos(theta);
|
||||||
|
T y = std::sin(phi) * std::sin(theta);
|
||||||
T x = r * std::cos(a);
|
T z = std::cos(phi);
|
||||||
T y = r * std::sin(a);
|
|
||||||
|
|
||||||
return vec<3, T, defaultp>(x, y, z) * Radius;
|
return vec<3, T, defaultp>(x, y, z) * Radius;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user