Added GTC_functions extension

This commit is contained in:
Christophe Riccio 2016-07-14 15:20:44 +02:00
parent 3b1af3fe0b
commit b8b43e6a4d
5 changed files with 121 additions and 0 deletions

53
glm/gtc/functions.hpp Normal file
View File

@ -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"

31
glm/gtc/functions.inl Normal file
View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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;
}