///////////////////////////////////////////////////////////////////////////////////
/// 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 core
/// @file glm/detail/func_geometric.inl
/// @date 2008-08-03 / 2011-06-15
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include “func_exponential.hpp”
#include “func_common.hpp”
#include “type_vec2.hpp”
#include “type_vec4.hpp”
#include “type_float.hpp”
namespace glm{
namespace detail
{
template class vecType, typename T, precision P>
struct compute_dot{};
template
struct compute_dot
{
GLM_FUNC_QUALIFIER static T call(tvec1
{
return a.x * b.x;
}
};
template
struct compute_dot
{
GLM_FUNC_QUALIFIER static T call(tvec2
{
tvec2
return tmp.x + tmp.y;
}
};
template
struct compute_dot
{
GLM_FUNC_QUALIFIER static T call(tvec3
{
tvec3
return tmp.x + tmp.y + tmp.z;
}
};
template
struct compute_dot
{
GLM_FUNC_QUALIFIER static T call(tvec4
{
tvec4
return (tmp.x + tmp.y) + (tmp.z + tmp.w);
}
};
}//namespace detail
// length
template
GLM_FUNC_QUALIFIER genType length(genType x)
{
GLM_STATIC_ASSERT(std::numeric_limits
return abs(x);
}
template
GLM_FUNC_QUALIFIER T length(vecType
{
GLM_STATIC_ASSERT(std::numeric_limits
return sqrt(dot(v, v));
}
// distance
template
GLM_FUNC_QUALIFIER genType distance(genType const & p0, genType const & p1)
{
GLM_STATIC_ASSERT(std::numeric_limits
return length(p1 – p0);
}
template
GLM_FUNC_QUALIFIER T distance(vecType
{
return length(p1 – p0);
}
// dot
template
GLM_FUNC_QUALIFIER T dot(T x, T y)
{
GLM_STATIC_ASSERT(std::numeric_limits
return x * y;
}
template
GLM_FUNC_QUALIFIER T dot(vecType
{
GLM_STATIC_ASSERT(std::numeric_limits
return detail::compute_dot
}
// cross
template
GLM_FUNC_QUALIFIER tvec3
{
GLM_STATIC_ASSERT(std::numeric_limits
return tvec3
x.y * y.z – y.y * x.z,
x.z * y.x – y.z * x.x,
x.x * y.y – y.x * x.y);
}
// normalize
template
GLM_FUNC_QUALIFIER genType normalize(genType const & x)
{
GLM_STATIC_ASSERT(std::numeric_limits
return x < genType(0) ? genType(-1) : genType(1);
}
template
GLM_FUNC_QUALIFIER vecType
{
GLM_STATIC_ASSERT(std::numeric_limits
return x * inversesqrt(dot(x, x));
}
// faceforward
template
GLM_FUNC_QUALIFIER genType faceforward(genType const & N, genType const & I, genType const & Nref)
{
return dot(Nref, I) < static_cast
}
template
GLM_FUNC_QUALIFIER vecType
{
return dot(Nref, I) < static_cast
}
// reflect
template
GLM_FUNC_QUALIFIER genType reflect(genType const & I, genType const & N)
{
return I – N * dot(N, I) * static_cast
}
// refract
template
GLM_FUNC_QUALIFIER genType refract(genType const & I, genType const & N, genType const & eta)
{
GLM_STATIC_ASSERT(std::numeric_limits
genType const dotValue(dot(N, I));
genType const k(static_cast
return (eta * I – (eta * dotValue + sqrt(k)) * N) * static_cast
}
template
GLM_FUNC_QUALIFIER vecType
{
GLM_STATIC_ASSERT(std::numeric_limits
T const dotValue(dot(N, I));
T const k(static_cast
return (eta * I – (eta * dotValue + std::sqrt(k)) * N) * static_cast
}
}//namespace glm