parent
3b1af3fe0b
commit
b8b43e6a4d
5 changed files with 121 additions and 0 deletions
@ -0,0 +1,53 @@ |
||||
/// @ref gtc_functions
|
||||
/// @file glm/gtc/functions.hpp
|
||||
///
|
||||
/// @see core (dependence)
|
||||
/// @see gtc_half_float (dependence)
|
||||
/// @see gtc_quaternion (dependence)
|
||||
///
|
||||
/// @defgroup gtc_functions GLM_GTC_functions
|
||||
/// @ingroup gtc
|
||||
///
|
||||
/// @brief List of useful common functions.
|
||||
///
|
||||
/// <glm/gtc/functions.hpp> need to be included to use these functionalities.
|
||||
|
||||
#pragma once |
||||
|
||||
// Dependencies
|
||||
#include "../detail/setup.hpp" |
||||
#include "../detail/precision.hpp" |
||||
#include "../detail/type_vec2.hpp" |
||||
|
||||
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED)) |
||||
# pragma message("GLM: GLM_GTC_functions extension included") |
||||
#endif |
||||
|
||||
namespace glm |
||||
{ |
||||
/// @addtogroup gtc_functions
|
||||
/// @{
|
||||
|
||||
/// 1D gauss function
|
||||
///
|
||||
/// @see gtc_epsilon
|
||||
template <typename T> |
||||
GLM_FUNC_DECL T gauss( |
||||
T x, |
||||
T ExpectedValue, |
||||
T StandardDeviation); |
||||
|
||||
/// 2D gauss function
|
||||
///
|
||||
/// @see gtc_epsilon
|
||||
template <typename T, precision P> |
||||
GLM_FUNC_DECL T gauss( |
||||
tvec2<T, P> const& Coord, |
||||
tvec2<T, P> const& ExpectedValue, |
||||
tvec2<T, P> const& StandardDeviation); |
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
||||
#include "functions.inl" |
||||
|
@ -0,0 +1,31 @@ |
||||
/// @ref gtc_functions |
||||
/// @file glm/gtc/functions.inl |
||||
|
||||
#include "../detail/func_exponential.hpp" |
||||
|
||||
namespace glm |
||||
{ |
||||
template <typename T> |
||||
GLM_FUNC_QUALIFIER T gauss |
||||
( |
||||
T x, |
||||
T ExpectedValue, |
||||
T StandardDeviation |
||||
) |
||||
{ |
||||
return exp(-((x - ExpectedValue) * (x - ExpectedValue)) / (static_cast<T>(2) * StandardDeviation * StandardDeviation)) / (StandardDeviation * sqrt(static_cast<T>(6.28318530717958647692528676655900576))); |
||||
} |
||||
|
||||
template <typename T, precision P> |
||||
GLM_FUNC_QUALIFIER T gauss |
||||
( |
||||
tvec2<T, P> const& Coord, |
||||
tvec2<T, P> const& ExpectedValue, |
||||
tvec2<T, P> const& StandardDeviation |
||||
) |
||||
{ |
||||
tvec2<T, P> const Squared = ((Coord - ExpectedValue) * (Coord - ExpectedValue)) / (static_cast<T>(2) * StandardDeviation * StandardDeviation); |
||||
return exp(-(Squared.x + Squared.y)); |
||||
} |
||||
}//namespace glm |
||||
|
@ -0,0 +1,35 @@ |
||||
#include <glm/gtc/functions.hpp> |
||||
#include <vector> |
||||
|
||||
int test_gauss_1d() |
||||
{ |
||||
int Error = 0; |
||||
|
||||
std::vector<float> Result(20); |
||||
for(std::size_t i = 0, n = Result.size(); i < n; ++i) |
||||
Result[i] = glm::gauss(static_cast<float>(i) * 0.1f, 0.0f, 1.0f); |
||||
|
||||
return Error; |
||||
} |
||||
|
||||
int test_gauss_2d() |
||||
{ |
||||
int Error = 0; |
||||
|
||||
std::vector<float> Result(20); |
||||
for(std::size_t i = 0, n = Result.size(); i < n; ++i) |
||||
Result[i] = glm::gauss(glm::vec2(i) * 0.1f, glm::vec2(0.0f), glm::vec2(1.0f)); |
||||
|
||||
return Error; |
||||
} |
||||
|
||||
int main() |
||||
{ |
||||
int Error = 0; |
||||
|
||||
Error += test_gauss_1d(); |
||||
Error += test_gauss_2d(); |
||||
|
||||
return Error; |
||||
} |
||||
|
Loading…
Reference in New Issue