/// @ref core /// @file glm/detail/func_geometric.inl #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, length_t L, typename T, precision P, bool Aligned> struct compute_length { GLM_FUNC_QUALIFIER static T call(vecType const & v) { return sqrt(dot(v, v)); } }; template class vecType, length_t L, typename T, precision P, bool Aligned> struct compute_distance { GLM_FUNC_QUALIFIER static T call(vecType const & p0, vecType const & p1) { return length(p1 - p0); } }; template struct compute_dot{}; template struct compute_dot, T, Aligned> { GLM_FUNC_QUALIFIER static T call(vec<1, T, P> const & a, vec<1, T, P> const & b) { return a.x * b.x; } }; template struct compute_dot, T, Aligned> { GLM_FUNC_QUALIFIER static T call(vec<2, T, P> const & a, vec<2, T, P> const & b) { vec<2, T, P> tmp(a * b); return tmp.x + tmp.y; } }; template struct compute_dot, T, Aligned> { GLM_FUNC_QUALIFIER static T call(vec<3, T, P> const & a, vec<3, T, P> const & b) { vec<3, T, P> tmp(a * b); return tmp.x + tmp.y + tmp.z; } }; template struct compute_dot, T, Aligned> { GLM_FUNC_QUALIFIER static T call(vec<4, T, P> const & a, vec<4, T, P> const & b) { vec<4, T, P> tmp(a * b); return (tmp.x + tmp.y) + (tmp.z + tmp.w); } }; template struct compute_cross { GLM_FUNC_QUALIFIER static vec<3, T, P> call(vec<3, T, P> const & x, vec<3, T, P> const & y) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'cross' accepts only floating-point inputs"); return vec<3, T, P>( x.y * y.z - y.y * x.z, x.z * y.x - y.z * x.x, x.x * y.y - y.x * x.y); } }; template class vecType, bool Aligned> struct compute_normalize { GLM_FUNC_QUALIFIER static vecType call(vecType const & v) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'normalize' accepts only floating-point inputs"); return v * inversesqrt(dot(v, v)); } }; template class vecType, bool Aligned> struct compute_faceforward { GLM_FUNC_QUALIFIER static vecType call(vecType const & N, vecType const & I, vecType const & Nref) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'normalize' accepts only floating-point inputs"); return dot(Nref, I) < static_cast(0) ? N : -N; } }; template class vecType, bool Aligned> struct compute_reflect { GLM_FUNC_QUALIFIER static vecType call(vecType const & I, vecType const & N) { return I - N * dot(N, I) * static_cast(2); } }; template class vecType, bool Aligned> struct compute_refract { GLM_FUNC_QUALIFIER static vecType call(vecType const & I, vecType const & N, T eta) { T const dotValue(dot(N, I)); T const k(static_cast(1) - eta * eta * (static_cast(1) - dotValue * dotValue)); return (eta * I - (eta * dotValue + std::sqrt(k)) * N) * static_cast(k >= static_cast(0)); } }; }//namespace detail // length template GLM_FUNC_QUALIFIER genType length(genType x) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'length' accepts only floating-point inputs"); return abs(x); } template class vecType> GLM_FUNC_QUALIFIER T length(vecType const & v) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'length' accepts only floating-point inputs"); return detail::compute_length::value>::call(v); } // distance template GLM_FUNC_QUALIFIER genType distance(genType const & p0, genType const & p1) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'distance' accepts only floating-point inputs"); return length(p1 - p0); } template class vecType> GLM_FUNC_QUALIFIER T distance(vecType const & p0, vecType const & p1) { return detail::compute_distance::value>::call(p0, p1); } // dot template GLM_FUNC_QUALIFIER T dot(T x, T y) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'dot' accepts only floating-point inputs"); return x * y; } template GLM_FUNC_QUALIFIER T dot(vec const & x, vec const & y) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'dot' accepts only floating-point inputs"); return detail::compute_dot, T, detail::is_aligned

::value>::call(x, y); } template GLM_FUNC_QUALIFIER T dot(tquat const & x, tquat const & y) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'dot' accepts only floating-point inputs"); return detail::compute_dot, T, detail::is_aligned

::value>::call(x, y); } // cross template GLM_FUNC_QUALIFIER vec<3, T, P> cross(vec<3, T, P> const & x, vec<3, T, P> const & y) { return detail::compute_cross::value>::call(x, y); } // normalize template GLM_FUNC_QUALIFIER genType normalize(genType const & x) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'normalize' accepts only floating-point inputs"); return x < genType(0) ? genType(-1) : genType(1); } template class vecType> GLM_FUNC_QUALIFIER vecType normalize(vecType const & x) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'normalize' accepts only floating-point inputs"); return detail::compute_normalize::value>::call(x); } // faceforward template GLM_FUNC_QUALIFIER genType faceforward(genType const & N, genType const & I, genType const & Nref) { return dot(Nref, I) < static_cast(0) ? N : -N; } template class vecType> GLM_FUNC_QUALIFIER vecType faceforward(vecType const & N, vecType const & I, vecType const & Nref) { return detail::compute_faceforward::value>::call(N, I, Nref); } // reflect template GLM_FUNC_QUALIFIER genType reflect(genType const & I, genType const & N) { return I - N * dot(N, I) * genType(2); } template class vecType> GLM_FUNC_QUALIFIER vecType reflect(vecType const & I, vecType const & N) { return detail::compute_reflect::value>::call(I, N); } // refract template GLM_FUNC_QUALIFIER genType refract(genType const & I, genType const & N, genType eta) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'refract' accepts only floating-point inputs"); genType const dotValue(dot(N, I)); genType const k(static_cast(1) - eta * eta * (static_cast(1) - dotValue * dotValue)); return (eta * I - (eta * dotValue + sqrt(k)) * N) * static_cast(k >= static_cast(0)); } template class vecType> GLM_FUNC_QUALIFIER vecType refract(vecType const & I, vecType const & N, T eta) { GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'refract' accepts only floating-point inputs"); return detail::compute_refract::value>::call(I, N, eta); } }//namespace glm #if GLM_ARCH != GLM_ARCH_PURE && GLM_HAS_UNRESTRICTED_UNIONS # include "func_geometric_simd.inl" #endif