mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-07 09:13:22 +08:00
Updated GLM version w/ now standard radians as angles.
This commit is contained in:
@@ -1,69 +1,72 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Created : 2006-01-09
|
||||
// Updated : 2006-01-09
|
||||
// Licence : This source is under MIT License
|
||||
// File : glm/gtx/fast_exponential.inl
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
/// 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 gtx_fast_exponential
|
||||
/// @file glm/gtx/fast_exponential.inl
|
||||
/// @date 2006-01-09 / 2011-06-07
|
||||
/// @author Christophe Riccio
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace glm
|
||||
{
|
||||
// fastPow:
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastPow(genType const & x, genType const & y)
|
||||
GLM_FUNC_QUALIFIER genType fastPow(genType x, genType y)
|
||||
{
|
||||
return exp(y * log(x));
|
||||
}
|
||||
|
||||
VECTORIZE_VEC_VEC(fastPow)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastPow(vecType<T, P> const & x, vecType<T, P> const & y)
|
||||
{
|
||||
return exp(y * log(x));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastPow(const T x, int y)
|
||||
GLM_FUNC_QUALIFIER T fastPow(T x, int y)
|
||||
{
|
||||
T f = T(1);
|
||||
T f = static_cast<T>(1);
|
||||
for(int i = 0; i < y; ++i)
|
||||
f *= x;
|
||||
return f;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER detail::tvec2<T> fastPow(
|
||||
const detail::tvec2<T>& x,
|
||||
const detail::tvec2<int>& y)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastPow(vecType<T, P> const & x, vecType<int, P> const & y)
|
||||
{
|
||||
return detail::tvec2<T>(
|
||||
fastPow(x.x, y.x),
|
||||
fastPow(x.y, y.y));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER detail::tvec3<T> fastPow(
|
||||
const detail::tvec3<T>& x,
|
||||
const detail::tvec3<int>& y)
|
||||
{
|
||||
return detail::tvec3<T>(
|
||||
fastPow(x.x, y.x),
|
||||
fastPow(x.y, y.y),
|
||||
fastPow(x.z, y.z));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER detail::tvec4<T> fastPow(
|
||||
const detail::tvec4<T>& x,
|
||||
const detail::tvec4<int>& y)
|
||||
{
|
||||
return detail::tvec4<T>(
|
||||
fastPow(x.x, y.x),
|
||||
fastPow(x.y, y.y),
|
||||
fastPow(x.z, y.z),
|
||||
fastPow(x.w, y.w));
|
||||
vecType<T, P> Result(uninitialize);
|
||||
for(detail::component_count_t i = 0; i < detail::component_count(x); ++i)
|
||||
Result[i] = fastPow(x[i], y[i]);
|
||||
return Result;
|
||||
}
|
||||
|
||||
// fastExp
|
||||
// Note: This function provides accurate results only for value between -1 and 1, else avoid it.
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER T fastExp(const T x)
|
||||
GLM_FUNC_QUALIFIER T fastExp(T x)
|
||||
{
|
||||
// This has a better looking and same performance in release mode than the following code. However, in debug mode it's slower.
|
||||
// return 1.0f + x * (1.0f + x * 0.5f * (1.0f + x * 0.3333333333f * (1.0f + x * 0.25 * (1.0f + x * 0.2f))));
|
||||
@@ -107,11 +110,15 @@ namespace glm
|
||||
}
|
||||
*/
|
||||
|
||||
VECTORIZE_VEC(fastExp)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastExp(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastExp, x);
|
||||
}
|
||||
|
||||
// fastLog
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastLog(genType const & x)
|
||||
GLM_FUNC_QUALIFIER genType fastLog(genType x)
|
||||
{
|
||||
return std::log(x);
|
||||
}
|
||||
@@ -125,24 +132,35 @@ namespace glm
|
||||
}
|
||||
*/
|
||||
|
||||
VECTORIZE_VEC(fastLog)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastLog(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastLog, x);
|
||||
}
|
||||
|
||||
//fastExp2, ln2 = 0.69314718055994530941723212145818f
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastExp2(genType const & x)
|
||||
GLM_FUNC_QUALIFIER genType fastExp2(genType x)
|
||||
{
|
||||
return fastExp(0.69314718055994530941723212145818f * x);
|
||||
}
|
||||
|
||||
VECTORIZE_VEC(fastExp2)
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastExp2(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastExp2, x);
|
||||
}
|
||||
|
||||
// fastLog2, ln2 = 0.69314718055994530941723212145818f
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType fastLog2(genType const & x)
|
||||
GLM_FUNC_QUALIFIER genType fastLog2(genType x)
|
||||
{
|
||||
return fastLog(x) / 0.69314718055994530941723212145818f;
|
||||
}
|
||||
|
||||
VECTORIZE_VEC(fastLog2)
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<T, P> fastLog2(vecType<T, P> const & x)
|
||||
{
|
||||
return detail::functor1<T, T, P, vecType>::call(fastLog2, x);
|
||||
}
|
||||
}//namespace glm
|
||||
|
||||
Reference in New Issue
Block a user