Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
941B

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