///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 – 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the “Software”), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtc_random
/// @file glm/gtc/random.inl
/// @date 2011-09-19 / 2012-04-07
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include “../geometric.hpp”
#include “../exponential.hpp”
#include
#include
#include
namespace glm{
namespace detail
{
template
struct compute_rand
{
GLM_FUNC_QUALIFIER static vecType
};
template
{
GLM_FUNC_QUALIFIER static tvec1
{
return tvec1
std::rand()) % std::numeric_limits
}
};
template
{
GLM_FUNC_QUALIFIER static tvec2
{
return tvec2
std::rand(),
std::rand()) % std::numeric_limits
}
};
template
{
GLM_FUNC_QUALIFIER static tvec3
{
return tvec3
std::rand(),
std::rand(),
std::rand()) % std::numeric_limits
}
};
template
{
GLM_FUNC_QUALIFIER static tvec4
{
return tvec4
std::rand(),
std::rand(),
std::rand(),
std::rand()) % std::numeric_limits
}
};
template
struct compute_rand
{
GLM_FUNC_QUALIFIER static vecType
{
return
(vecType
(vecType
}
};
template
struct compute_rand
{
GLM_FUNC_QUALIFIER static vecType
{
return
(vecType
(vecType
}
};
template
struct compute_rand
{
GLM_FUNC_QUALIFIER static vecType
{
return
(vecType
(vecType
}
};
template
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
};
template
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return (vecType
}
};
template
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return (compute_rand
}
};
template
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return (vecType
}
};
template
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return (compute_rand
}
};
template
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return (vecType
}
};
template
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return (compute_rand
}
};
template
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return (vecType
}
};
template
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return (compute_rand
}
};
template class vecType>
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return vecType
}
};
template class vecType>
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return vecType
}
};
template class vecType>
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return vecType
}
};
template class vecType>
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return vecType
}
};
template class vecType>
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return vecType
}
};
template class vecType>
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return vecType
}
};
template class vecType>
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return vecType
}
};
template class vecType>
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return vecType
}
};
template class vecType>
struct compute_linearRand
{
GLM_FUNC_QUALIFIER static vecType
{
return vecType
}
};
}//namespace detail
template
GLM_FUNC_QUALIFIER genType linearRand(genType Min, genType Max)
{
return detail::compute_linearRand
tvec1
tvec1
}
template
GLM_FUNC_QUALIFIER vecType
{
return detail::compute_linearRand
}
template
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
GLM_FUNC_QUALIFIER vecType
{
return detail::functor2
}
template
GLM_FUNC_QUALIFIER tvec2
{
tvec2
T LenRadius(T(0));
do
{
Result = linearRand(
tvec2
tvec2
LenRadius = length(Result);
}
while(LenRadius > Radius);
return Result;
}
template
GLM_FUNC_QUALIFIER tvec3
{
tvec3
T LenRadius(T(0));
do
{
Result = linearRand(
tvec3
tvec3
LenRadius = length(Result);
}
while(LenRadius > Radius);
return Result;
}
template
GLM_FUNC_QUALIFIER tvec2
{
T a = linearRand(T(0), T(6.283185307179586476925286766559f));
return tvec2
}
template
GLM_FUNC_QUALIFIER tvec3
{
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
}
}//namespace glm