diff --git a/glm/gtc/functions.hpp b/glm/gtc/functions.hpp new file mode 100644 index 00000000..d9449643 --- /dev/null +++ b/glm/gtc/functions.hpp @@ -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. +/// +/// 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 + GLM_FUNC_DECL T gauss( + T x, + T ExpectedValue, + T StandardDeviation); + + /// 2D gauss function + /// + /// @see gtc_epsilon + template + GLM_FUNC_DECL T gauss( + tvec2 const& Coord, + tvec2 const& ExpectedValue, + tvec2 const& StandardDeviation); + + /// @} +}//namespace glm + +#include "functions.inl" + diff --git a/glm/gtc/functions.inl b/glm/gtc/functions.inl new file mode 100644 index 00000000..1dbc4967 --- /dev/null +++ b/glm/gtc/functions.inl @@ -0,0 +1,31 @@ +/// @ref gtc_functions +/// @file glm/gtc/functions.inl + +#include "../detail/func_exponential.hpp" + +namespace glm +{ + template + GLM_FUNC_QUALIFIER T gauss + ( + T x, + T ExpectedValue, + T StandardDeviation + ) + { + return exp(-((x - ExpectedValue) * (x - ExpectedValue)) / (static_cast(2) * StandardDeviation * StandardDeviation)) / (StandardDeviation * sqrt(static_cast(6.28318530717958647692528676655900576))); + } + + template + GLM_FUNC_QUALIFIER T gauss + ( + tvec2 const& Coord, + tvec2 const& ExpectedValue, + tvec2 const& StandardDeviation + ) + { + tvec2 const Squared = ((Coord - ExpectedValue) * (Coord - ExpectedValue)) / (static_cast(2) * StandardDeviation * StandardDeviation); + return exp(-(Squared.x + Squared.y)); + } +}//namespace glm + diff --git a/readme.md b/readme.md index 0fad99aa..c9e56dac 100644 --- a/readme.md +++ b/readme.md @@ -65,6 +65,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) - Added raw SIMD API - Added 'aligned' qualifiers - Added GTC_type_aligned with aligned *vec* types +- Added GTC_functions extension ##### Improvements: - Improved SIMD and swizzle operators interactions with GCC and Clang #474 diff --git a/test/gtc/CMakeLists.txt b/test/gtc/CMakeLists.txt index 4aef24a8..ab26247a 100644 --- a/test/gtc/CMakeLists.txt +++ b/test/gtc/CMakeLists.txt @@ -2,6 +2,7 @@ glmCreateTestGTC(gtc_bitfield) glmCreateTestGTC(gtc_color_space) glmCreateTestGTC(gtc_constants) glmCreateTestGTC(gtc_epsilon) +glmCreateTestGTC(gtc_functions) glmCreateTestGTC(gtc_integer) glmCreateTestGTC(gtc_matrix_access) glmCreateTestGTC(gtc_matrix_integer) diff --git a/test/gtc/gtc_functions.cpp b/test/gtc/gtc_functions.cpp new file mode 100644 index 00000000..0bdf8ab5 --- /dev/null +++ b/test/gtc/gtc_functions.cpp @@ -0,0 +1,35 @@ +#include +#include + +int test_gauss_1d() +{ + int Error = 0; + + std::vector Result(20); + for(std::size_t i = 0, n = Result.size(); i < n; ++i) + Result[i] = glm::gauss(static_cast(i) * 0.1f, 0.0f, 1.0f); + + return Error; +} + +int test_gauss_2d() +{ + int Error = 0; + + std::vector 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; +} +