1/// @ref gtx_gradient_paint 2/// @file glm/gtx/gradient_paint.inl 3 4namespace glm 5{ 6 template <typename T, precision P> 7 GLM_FUNC_QUALIFIER T radialGradient 8 ( 9 tvec2<T, P> const & Center, 10 T const & Radius, 11 tvec2<T, P> const & Focal, 12 tvec2<T, P> const & Position 13 ) 14 { 15 tvec2<T, P> F = Focal - Center; 16 tvec2<T, P> D = Position - Focal; 17 T Radius2 = pow2(Radius); 18 T Fx2 = pow2(F.x); 19 T Fy2 = pow2(F.y); 20 21 T Numerator = (D.x * F.x + D.y * F.y) + sqrt(Radius2 * (pow2(D.x) + pow2(D.y)) - pow2(D.x * F.y - D.y * F.x)); 22 T Denominator = Radius2 - (Fx2 + Fy2); 23 return Numerator / Denominator; 24 } 25 26 template <typename T, precision P> 27 GLM_FUNC_QUALIFIER T linearGradient 28 ( 29 tvec2<T, P> const & Point0, 30 tvec2<T, P> const & Point1, 31 tvec2<T, P> const & Position 32 ) 33 { 34 tvec2<T, P> Dist = Point1 - Point0; 35 return (Dist.x * (Position.x - Point0.x) + Dist.y * (Position.y - Point0.y)) / glm::dot(Dist, Dist); 36 } 37}//namespace glm 38