9
3

gradient_paint.inl 904 B

123456789101112131415161718192021222324252627282930313233343536
  1. /// @ref gtx_gradient_paint
  2. namespace glm
  3. {
  4. template<typename T, qualifier Q>
  5. GLM_FUNC_QUALIFIER T radialGradient
  6. (
  7. vec<2, T, Q> const& Center,
  8. T const& Radius,
  9. vec<2, T, Q> const& Focal,
  10. vec<2, T, Q> const& Position
  11. )
  12. {
  13. vec<2, T, Q> F = Focal - Center;
  14. vec<2, T, Q> D = Position - Focal;
  15. T Radius2 = pow2(Radius);
  16. T Fx2 = pow2(F.x);
  17. T Fy2 = pow2(F.y);
  18. 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));
  19. T Denominator = Radius2 - (Fx2 + Fy2);
  20. return Numerator / Denominator;
  21. }
  22. template<typename T, qualifier Q>
  23. GLM_FUNC_QUALIFIER T linearGradient
  24. (
  25. vec<2, T, Q> const& Point0,
  26. vec<2, T, Q> const& Point1,
  27. vec<2, T, Q> const& Position
  28. )
  29. {
  30. vec<2, T, Q> Dist = Point1 - Point0;
  31. return (Dist.x * (Position.x - Point0.x) + Dist.y * (Position.y - Point0.y)) / glm::dot(Dist, Dist);
  32. }
  33. }//namespace glm