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.

43 lines
1.5 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2009-03-06
  5. // Updated : 2009-03-09
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/gradient_paint.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. namespace glm
  10. {
  11. template <typename valType>
  12. valType radialGradient
  13. (
  14. detail::tvec2<valType> const & Center,
  15. valType const & Radius,
  16. detail::tvec2<valType> const & Focal,
  17. detail::tvec2<valType> const & Position
  18. )
  19. {
  20. detail::tvec2<valType> F = Focal - Center;
  21. detail::tvec2<valType> D = Position - Focal;
  22. valType Radius2 = pow2(Radius);
  23. valType Fx2 = pow2(F.x);
  24. valType Fy2 = pow2(F.y);
  25. valType 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));
  26. valType Denominator = Radius2 - (Fx2 + Fy2);
  27. return Numerator / Denominator;
  28. }
  29. template <typename valType>
  30. valType linearGradient
  31. (
  32. detail::tvec2<valType> const & Point0,
  33. detail::tvec2<valType> const & Point1,
  34. detail::tvec2<valType> const & Position
  35. )
  36. {
  37. detail::tvec2<valType> Dist = Point1 - Point0;
  38. return (Dist.x * (Position.x - Point0.x) + Dist.y * (Position.y - Point0.y)) / glm::dot(Dist, Dist);
  39. }
  40. }//namespace glm