FastUIDraw
fastuidraw_circular_interpolate.glsl.hpp
Go to the documentation of this file.
1 /*!
2  * \file fastuidraw_circular_interpolate.glsl.hpp
3  * \brief file fastuidraw_circular_interpolate.glsl.hpp
4  *
5  * Copyright 2018 by Intel.
6  *
7  * Contact: kevin.rogovin@gmail.com
8  *
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
16  *
17  */
18 
19 /*!\addtogroup GLSLVertFragCode
20  * @{
21  */
22 
23 /*!
24  * \brief compute interpolation along a circle.
25  * \param v0 starting point on circle, must have unit length
26  * \param v1 end point on circle, must have unit length
27  * \param d the cosine of the angle (in radians) between v0 and v1, i.e. the value of dot(v0, v1).
28  * \param interpolate value in range [0, 1] providing the interpolate of the interpolation
29  */
30 vec2
31 fastuidraw_circular_interpolate(in vec2 v0, in vec2 v1, in float d, in float interpolate)
32 {
33  float angle, c, s;
34  angle = acos(d);
35  /* we multiple by the cross of v0 and v1
36  * to make sure we are interpolating from v0
37  * to v1 because acos always gives a positive
38  * angle
39  */
40  c = cos(angle * interpolate);
41  s = sin(angle * interpolate) * sign(v0.x * v1.y - v1.x * v0.y);
42  return vec2(c * v0.x - s * v0.y,
43  s * v0.x + c * v0.y);
44 }
45 /*! @} */
vecN< float, 2 > vec2
Definition: vecN.hpp:1231
vec2 fastuidraw_circular_interpolate(in vec2 v0, in vec2 v1, in float d, in float interpolate)
compute interpolation along a circle.