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