summaryrefslogtreecommitdiffstats
path: root/external/include/glm/gtc/random.inl
diff options
context:
space:
mode:
Diffstat (limited to 'external/include/glm/gtc/random.inl')
-rw-r--r--external/include/glm/gtc/random.inl310
1 files changed, 129 insertions, 181 deletions
diff --git a/external/include/glm/gtc/random.inl b/external/include/glm/gtc/random.inl
index ad5926e..5301c59 100644
--- a/external/include/glm/gtc/random.inl
+++ b/external/include/glm/gtc/random.inl
@@ -3,58 +3,61 @@
#include "../geometric.hpp"
#include "../exponential.hpp"
+#include "../trigonometric.hpp"
+#include "../ext/vec1.hpp"
#include <cstdlib>
#include <ctime>
#include <cassert>
+#include <cmath>
namespace glm{
namespace detail
{
- template <typename T, precision P, template <class, precision> class vecType>
+ template <length_t L, typename T, qualifier Q>
struct compute_rand
{
- GLM_FUNC_QUALIFIER static vecType<T, P> call();
+ GLM_FUNC_QUALIFIER static vec<L, T, Q> call();
};
- template <precision P>
- struct compute_rand<uint8, P, tvec1>
+ template <qualifier P>
+ struct compute_rand<1, uint8, P>
{
- GLM_FUNC_QUALIFIER static tvec1<uint8, P> call()
+ GLM_FUNC_QUALIFIER static vec<1, uint8, P> call()
{
- return tvec1<uint8, P>(
+ return vec<1, uint8, P>(
std::rand() % std::numeric_limits<uint8>::max());
}
};
- template <precision P>
- struct compute_rand<uint8, P, tvec2>
+ template <qualifier P>
+ struct compute_rand<2, uint8, P>
{
- GLM_FUNC_QUALIFIER static tvec2<uint8, P> call()
+ GLM_FUNC_QUALIFIER static vec<2, uint8, P> call()
{
- return tvec2<uint8, P>(
+ return vec<2, uint8, P>(
std::rand() % std::numeric_limits<uint8>::max(),
std::rand() % std::numeric_limits<uint8>::max());
}
};
- template <precision P>
- struct compute_rand<uint8, P, tvec3>
+ template <qualifier P>
+ struct compute_rand<3, uint8, P>
{
- GLM_FUNC_QUALIFIER static tvec3<uint8, P> call()
+ GLM_FUNC_QUALIFIER static vec<3, uint8, P> call()
{
- return tvec3<uint8, P>(
+ return vec<3, uint8, P>(
std::rand() % std::numeric_limits<uint8>::max(),
std::rand() % std::numeric_limits<uint8>::max(),
std::rand() % std::numeric_limits<uint8>::max());
}
};
- template <precision P>
- struct compute_rand<uint8, P, tvec4>
+ template <qualifier P>
+ struct compute_rand<4, uint8, P>
{
- GLM_FUNC_QUALIFIER static tvec4<uint8, P> call()
+ GLM_FUNC_QUALIFIER static vec<4, uint8, P> call()
{
- return tvec4<uint8, P>(
+ return vec<4, uint8, P>(
std::rand() % std::numeric_limits<uint8>::max(),
std::rand() % std::numeric_limits<uint8>::max(),
std::rand() % std::numeric_limits<uint8>::max(),
@@ -62,289 +65,234 @@ namespace detail
}
};
- template <precision P, template <class, precision> class vecType>
- struct compute_rand<uint16, P, vecType>
+ template <length_t L, qualifier Q>
+ struct compute_rand<L, uint16, Q>
{
- GLM_FUNC_QUALIFIER static vecType<uint16, P> call()
+ GLM_FUNC_QUALIFIER static vec<L, uint16, Q> call()
{
return
- (vecType<uint16, P>(compute_rand<uint8, P, vecType>::call()) << static_cast<uint16>(8)) |
- (vecType<uint16, P>(compute_rand<uint8, P, vecType>::call()) << static_cast<uint16>(0));
+ (vec<L, uint16, Q>(compute_rand<L, uint8, Q>::call()) << static_cast<uint16>(8)) |
+ (vec<L, uint16, Q>(compute_rand<L, uint8, Q>::call()) << static_cast<uint16>(0));
}
};
- template <precision P, template <class, precision> class vecType>
- struct compute_rand<uint32, P, vecType>
+ template <length_t L, qualifier Q>
+ struct compute_rand<L, uint32, Q>
{
- GLM_FUNC_QUALIFIER static vecType<uint32, P> call()
+ GLM_FUNC_QUALIFIER static vec<L, uint32, Q> call()
{
return
- (vecType<uint32, P>(compute_rand<uint16, P, vecType>::call()) << static_cast<uint32>(16)) |
- (vecType<uint32, P>(compute_rand<uint16, P, vecType>::call()) << static_cast<uint32>(0));
+ (vec<L, uint32, Q>(compute_rand<L, uint16, Q>::call()) << static_cast<uint32>(16)) |
+ (vec<L, uint32, Q>(compute_rand<L, uint16, Q>::call()) << static_cast<uint32>(0));
}
};
- template <precision P, template <class, precision> class vecType>
- struct compute_rand<uint64, P, vecType>
+ template <length_t L, qualifier Q>
+ struct compute_rand<L, uint64, Q>
{
- GLM_FUNC_QUALIFIER static vecType<uint64, P> call()
+ GLM_FUNC_QUALIFIER static vec<L, uint64, Q> call()
{
return
- (vecType<uint64, P>(compute_rand<uint32, P, vecType>::call()) << static_cast<uint64>(32)) |
- (vecType<uint64, P>(compute_rand<uint32, P, vecType>::call()) << static_cast<uint64>(0));
+ (vec<L, uint64, Q>(compute_rand<L, uint32, Q>::call()) << static_cast<uint64>(32)) |
+ (vec<L, uint64, Q>(compute_rand<L, uint32, Q>::call()) << static_cast<uint64>(0));
}
};
- template <typename T, precision P, template <class, precision> class vecType>
+ template <length_t L, typename T, qualifier Q>
struct compute_linearRand
{
- GLM_FUNC_QUALIFIER static vecType<T, P> call(vecType<T, P> const & Min, vecType<T, P> const & Max);
+ GLM_FUNC_QUALIFIER static vec<L, T, Q> call(vec<L, T, Q> const& Min, vec<L, T, Q> const& Max);
};
- template <precision P, template <class, precision> class vecType>
- struct compute_linearRand<int8, P, vecType>
+ template<length_t L, qualifier Q>
+ struct compute_linearRand<L, int8, Q>
{
- GLM_FUNC_QUALIFIER static vecType<int8, P> call(vecType<int8, P> const & Min, vecType<int8, P> const & Max)
+ GLM_FUNC_QUALIFIER static vec<L, int8, Q> call(vec<L, int8, Q> const& Min, vec<L, int8, Q> const& Max)
{
- return (vecType<int8, P>(compute_rand<uint8, P, vecType>::call() % vecType<uint8, P>(Max + static_cast<int8>(1) - Min))) + Min;
+ return (vec<L, int8, Q>(compute_rand<L, uint8, Q>::call() % vec<L, uint8, Q>(Max + static_cast<int8>(1) - Min))) + Min;
}
};
- template <precision P, template <class, precision> class vecType>
- struct compute_linearRand<uint8, P, vecType>
+ template<length_t L, qualifier Q>
+ struct compute_linearRand<L, uint8, Q>
{
- GLM_FUNC_QUALIFIER static vecType<uint8, P> call(vecType<uint8, P> const & Min, vecType<uint8, P> const & Max)
+ GLM_FUNC_QUALIFIER static vec<L, uint8, Q> call(vec<L, uint8, Q> const& Min, vec<L, uint8, Q> const& Max)
{
- return (compute_rand<uint8, P, vecType>::call() % (Max + static_cast<uint8>(1) - Min)) + Min;
+ return (compute_rand<L, uint8, Q>::call() % (Max + static_cast<uint8>(1) - Min)) + Min;
}
};
- template <precision P, template <class, precision> class vecType>
- struct compute_linearRand<int16, P, vecType>
+ template<length_t L, qualifier Q>
+ struct compute_linearRand<L, int16, Q>
{
- GLM_FUNC_QUALIFIER static vecType<int16, P> call(vecType<int16, P> const & Min, vecType<int16, P> const & Max)
+ GLM_FUNC_QUALIFIER static vec<L, int16, Q> call(vec<L, int16, Q> const& Min, vec<L, int16, Q> const& Max)
{
- return (vecType<int16, P>(compute_rand<uint16, P, vecType>::call() % vecType<uint16, P>(Max + static_cast<int16>(1) - Min))) + Min;
+ return (vec<L, int16, Q>(compute_rand<L, uint16, Q>::call() % vec<L, uint16, Q>(Max + static_cast<int16>(1) - Min))) + Min;
}
};
- template <precision P, template <class, precision> class vecType>
- struct compute_linearRand<uint16, P, vecType>
+ template<length_t L, qualifier Q>
+ struct compute_linearRand<L, uint16, Q>
{
- GLM_FUNC_QUALIFIER static vecType<uint16, P> call(vecType<uint16, P> const & Min, vecType<uint16, P> const & Max)
+ GLM_FUNC_QUALIFIER static vec<L, uint16, Q> call(vec<L, uint16, Q> const& Min, vec<L, uint16, Q> const& Max)
{
- return (compute_rand<uint16, P, vecType>::call() % (Max + static_cast<uint16>(1) - Min)) + Min;
+ return (compute_rand<L, uint16, Q>::call() % (Max + static_cast<uint16>(1) - Min)) + Min;
}
};
- template <precision P, template <class, precision> class vecType>
- struct compute_linearRand<int32, P, vecType>
+ template<length_t L, qualifier Q>
+ struct compute_linearRand<L, int32, Q>
{
- GLM_FUNC_QUALIFIER static vecType<int32, P> call(vecType<int32, P> const & Min, vecType<int32, P> const & Max)
+ GLM_FUNC_QUALIFIER static vec<L, int32, Q> call(vec<L, int32, Q> const& Min, vec<L, int32, Q> const& Max)
{
- return (vecType<int32, P>(compute_rand<uint32, P, vecType>::call() % vecType<uint32, P>(Max + static_cast<int32>(1) - Min))) + Min;
+ return (vec<L, int32, Q>(compute_rand<L, uint32, Q>::call() % vec<L, uint32, Q>(Max + static_cast<int32>(1) - Min))) + Min;
}
};
- template <precision P, template <class, precision> class vecType>
- struct compute_linearRand<uint32, P, vecType>
+ template<length_t L, qualifier Q>
+ struct compute_linearRand<L, uint32, Q>
{
- GLM_FUNC_QUALIFIER static vecType<uint32, P> call(vecType<uint32, P> const & Min, vecType<uint32, P> const & Max)
+ GLM_FUNC_QUALIFIER static vec<L, uint32, Q> call(vec<L, uint32, Q> const& Min, vec<L, uint32, Q> const& Max)
{
- return (compute_rand<uint32, P, vecType>::call() % (Max + static_cast<uint32>(1) - Min)) + Min;
- }
- };
-
- template <precision P, template <class, precision> class vecType>
- struct compute_linearRand<int64, P, vecType>
- {
- GLM_FUNC_QUALIFIER static vecType<int64, P> call(vecType<int64, P> const & Min, vecType<int64, P> const & Max)
- {
- return (vecType<int64, P>(compute_rand<uint64, P, vecType>::call() % vecType<uint64, P>(Max + static_cast<int64>(1) - Min))) + Min;
- }
- };
-
- template <precision P, template <class, precision> class vecType>
- struct compute_linearRand<uint64, P, vecType>
- {
- GLM_FUNC_QUALIFIER static vecType<uint64, P> call(vecType<uint64, P> const & Min, vecType<uint64, P> const & Max)
- {
- return (compute_rand<uint64, P, vecType>::call() % (Max + static_cast<uint64>(1) - Min)) + Min;
- }
- };
-
- template <template <class, precision> class vecType>
- struct compute_linearRand<float, lowp, vecType>
- {
- GLM_FUNC_QUALIFIER static vecType<float, lowp> call(vecType<float, lowp> const & Min, vecType<float, lowp> const & Max)
- {
- return vecType<float, lowp>(compute_rand<uint8, lowp, vecType>::call()) / static_cast<float>(std::numeric_limits<uint8>::max()) * (Max - Min) + Min;
+ return (compute_rand<L, uint32, Q>::call() % (Max + static_cast<uint32>(1) - Min)) + Min;
}
};
- template <template <class, precision> class vecType>
- struct compute_linearRand<float, mediump, vecType>
+ template<length_t L, qualifier Q>
+ struct compute_linearRand<L, int64, Q>
{
- GLM_FUNC_QUALIFIER static vecType<float, mediump> call(vecType<float, mediump> const & Min, vecType<float, mediump> const & Max)
+ GLM_FUNC_QUALIFIER static vec<L, int64, Q> call(vec<L, int64, Q> const& Min, vec<L, int64, Q> const& Max)
{
- return vecType<float, mediump>(compute_rand<uint16, mediump, vecType>::call()) / static_cast<float>(std::numeric_limits<uint16>::max()) * (Max - Min) + Min;
+ return (vec<L, int64, Q>(compute_rand<L, uint64, Q>::call() % vec<L, uint64, Q>(Max + static_cast<int64>(1) - Min))) + Min;
}
};
- template <template <class, precision> class vecType>
- struct compute_linearRand<float, highp, vecType>
+ template<length_t L, qualifier Q>
+ struct compute_linearRand<L, uint64, Q>
{
- GLM_FUNC_QUALIFIER static vecType<float, highp> call(vecType<float, highp> const & Min, vecType<float, highp> const & Max)
+ GLM_FUNC_QUALIFIER static vec<L, uint64, Q> call(vec<L, uint64, Q> const& Min, vec<L, uint64, Q> const& Max)
{
- return vecType<float, highp>(compute_rand<uint32, highp, vecType>::call()) / static_cast<float>(std::numeric_limits<uint32>::max()) * (Max - Min) + Min;
+ return (compute_rand<L, uint64, Q>::call() % (Max + static_cast<uint64>(1) - Min)) + Min;
}
};
- template <template <class, precision> class vecType>
- struct compute_linearRand<double, lowp, vecType>
+ template<length_t L, qualifier Q>
+ struct compute_linearRand<L, float, Q>
{
- GLM_FUNC_QUALIFIER static vecType<double, lowp> call(vecType<double, lowp> const & Min, vecType<double, lowp> const & Max)
+ GLM_FUNC_QUALIFIER static vec<L, float, Q> call(vec<L, float, Q> const& Min, vec<L, float, Q> const& Max)
{
- return vecType<double, lowp>(compute_rand<uint16, lowp, vecType>::call()) / static_cast<double>(std::numeric_limits<uint16>::max()) * (Max - Min) + Min;
+ return vec<L, float, Q>(compute_rand<L, uint32, Q>::call()) / static_cast<float>(std::numeric_limits<uint32>::max()) * (Max - Min) + Min;
}
};
- template <template <class, precision> class vecType>
- struct compute_linearRand<double, mediump, vecType>
+ template<length_t L, qualifier Q>
+ struct compute_linearRand<L, double, Q>
{
- GLM_FUNC_QUALIFIER static vecType<double, mediump> call(vecType<double, mediump> const & Min, vecType<double, mediump> const & Max)
+ GLM_FUNC_QUALIFIER static vec<L, double, Q> call(vec<L, double, Q> const& Min, vec<L, double, Q> const& Max)
{
- return vecType<double, mediump>(compute_rand<uint32, mediump, vecType>::call()) / static_cast<double>(std::numeric_limits<uint32>::max()) * (Max - Min) + Min;
+ return vec<L, double, Q>(compute_rand<L, uint64, Q>::call()) / static_cast<double>(std::numeric_limits<uint64>::max()) * (Max - Min) + Min;
}
};
- template <template <class, precision> class vecType>
- struct compute_linearRand<double, highp, vecType>
+ template<length_t L, qualifier Q>
+ struct compute_linearRand<L, long double, Q>
{
- GLM_FUNC_QUALIFIER static vecType<double, highp> call(vecType<double, highp> const & Min, vecType<double, highp> const & Max)
+ GLM_FUNC_QUALIFIER static vec<L, long double, Q> call(vec<L, long double, Q> const& Min, vec<L, long double, Q> const& Max)
{
- return vecType<double, highp>(compute_rand<uint64, highp, vecType>::call()) / static_cast<double>(std::numeric_limits<uint64>::max()) * (Max - Min) + Min;
- }
- };
-
- template <template <class, precision> class vecType>
- struct compute_linearRand<long double, lowp, vecType>
- {
- GLM_FUNC_QUALIFIER static vecType<long double, lowp> call(vecType<long double, lowp> const & Min, vecType<long double, lowp> const & Max)
- {
- return vecType<long double, lowp>(compute_rand<uint32, lowp, vecType>::call()) / static_cast<long double>(std::numeric_limits<uint32>::max()) * (Max - Min) + Min;
- }
- };
-
- template <template <class, precision> class vecType>
- struct compute_linearRand<long double, mediump, vecType>
- {
- GLM_FUNC_QUALIFIER static vecType<long double, mediump> call(vecType<long double, mediump> const & Min, vecType<long double, mediump> const & Max)
- {
- return vecType<long double, mediump>(compute_rand<uint64, mediump, vecType>::call()) / static_cast<long double>(std::numeric_limits<uint64>::max()) * (Max - Min) + Min;
- }
- };
-
- template <template <class, precision> class vecType>
- struct compute_linearRand<long double, highp, vecType>
- {
- GLM_FUNC_QUALIFIER static vecType<long double, highp> call(vecType<long double, highp> const & Min, vecType<long double, highp> const & Max)
- {
- return vecType<long double, highp>(compute_rand<uint64, highp, vecType>::call()) / static_cast<long double>(std::numeric_limits<uint64>::max()) * (Max - Min) + Min;
+ return vec<L, long double, Q>(compute_rand<L, uint64, Q>::call()) / static_cast<long double>(std::numeric_limits<uint64>::max()) * (Max - Min) + Min;
}
};
}//namespace detail
- template <typename genType>
+ template<typename genType>
GLM_FUNC_QUALIFIER genType linearRand(genType Min, genType Max)
{
- return detail::compute_linearRand<genType, highp, tvec1>::call(
- tvec1<genType, highp>(Min),
- tvec1<genType, highp>(Max)).x;
+ return detail::compute_linearRand<1, genType, highp>::call(
+ vec<1, genType, highp>(Min),
+ vec<1, genType, highp>(Max)).x;
}
- template <typename T, precision P, template <typename, precision> class vecType>
- GLM_FUNC_QUALIFIER vecType<T, P> linearRand(vecType<T, P> const & Min, vecType<T, P> const & Max)
+ template<length_t L, typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<L, T, Q> linearRand(vec<L, T, Q> const& Min, vec<L, T, Q> const& Max)
{
- return detail::compute_linearRand<T, P, vecType>::call(Min, Max);
+ return detail::compute_linearRand<L, T, Q>::call(Min, Max);
}
- template <typename genType>
+ template<typename genType>
GLM_FUNC_QUALIFIER genType gaussRand(genType Mean, genType Deviation)
{
genType w, x1, x2;
-
+
do
{
x1 = linearRand(genType(-1), genType(1));
x2 = linearRand(genType(-1), genType(1));
-
+
w = x1 * x1 + x2 * x2;
} while(w > genType(1));
-
+
return x2 * Deviation * Deviation * sqrt((genType(-2) * log(w)) / w) + Mean;
}
- template <typename T, precision P, template <typename, precision> class vecType>
- GLM_FUNC_QUALIFIER vecType<T, P> gaussRand(vecType<T, P> const & Mean, vecType<T, P> const & Deviation)
+ template<length_t L, typename T, qualifier Q>
+ GLM_FUNC_QUALIFIER vec<L, T, Q> gaussRand(vec<L, T, Q> const& Mean, vec<L, T, Q> const& Deviation)
{
- return detail::functor2<T, P, vecType>::call(gaussRand, Mean, Deviation);
+ return detail::functor2<L, T, Q>::call(gaussRand, Mean, Deviation);
}
- template <typename T>
- GLM_FUNC_QUALIFIER tvec2<T, defaultp> diskRand(T Radius)
- {
- tvec2<T, defaultp> Result(T(0));
+ template<typename T>
+ GLM_FUNC_QUALIFIER vec<2, T, defaultp> diskRand(T Radius)
+ {
+ vec<2, T, defaultp> Result(T(0));
T LenRadius(T(0));
-
+
do
{
Result = linearRand(
- tvec2<T, defaultp>(-Radius),
- tvec2<T, defaultp>(Radius));
+ vec<2, T, defaultp>(-Radius),
+ vec<2, T, defaultp>(Radius));
LenRadius = length(Result);
}
while(LenRadius > Radius);
-
+
return Result;
}
-
- template <typename T>
- GLM_FUNC_QUALIFIER tvec3<T, defaultp> ballRand(T Radius)
- {
- tvec3<T, defaultp> Result(T(0));
+
+ template<typename T>
+ GLM_FUNC_QUALIFIER vec<3, T, defaultp> ballRand(T Radius)
+ {
+ vec<3, T, defaultp> Result(T(0));
T LenRadius(T(0));
-
+
do
{
Result = linearRand(
- tvec3<T, defaultp>(-Radius),
- tvec3<T, defaultp>(Radius));
+ vec<3, T, defaultp>(-Radius),
+ vec<3, T, defaultp>(Radius));
LenRadius = length(Result);
}
while(LenRadius > Radius);
-
+
return Result;
}
-
- template <typename T>
- GLM_FUNC_QUALIFIER tvec2<T, defaultp> circularRand(T Radius)
+
+ template<typename T>
+ GLM_FUNC_QUALIFIER vec<2, T, defaultp> circularRand(T Radius)
{
- T a = linearRand(T(0), T(6.283185307179586476925286766559f));
- return tvec2<T, defaultp>(cos(a), sin(a)) * Radius;
+ T a = linearRand(T(0), static_cast<T>(6.283185307179586476925286766559));
+ return vec<2, T, defaultp>(glm::cos(a), glm::sin(a)) * Radius;
}
-
- template <typename T>
- GLM_FUNC_QUALIFIER tvec3<T, defaultp> sphericalRand(T Radius)
+
+ template<typename T>
+ GLM_FUNC_QUALIFIER vec<3, T, defaultp> sphericalRand(T Radius)
{
- T z = linearRand(T(-1), T(1));
- T a = linearRand(T(0), T(6.283185307179586476925286766559f));
-
- T r = sqrt(T(1) - z * z);
-
- T x = r * cos(a);
- T y = r * sin(a);
-
- return tvec3<T, defaultp>(x, y, z) * Radius;
+ T theta = linearRand(T(0), T(6.283185307179586476925286766559f));
+ T phi = std::acos(linearRand(T(-1.0f), T(1.0f)));
+
+ T x = std::sin(phi) * std::cos(theta);
+ T y = std::sin(phi) * std::sin(theta);
+ T z = std::cos(phi);
+
+ return vec<3, T, defaultp>(x, y, z) * Radius;
}
}//namespace glm