Graphics Reference
In-Depth Information
p /2 to 0 with a straight line
segment (indicating constant speed) inclined at 45 degrees (because the slope of the sine curve at 0 is
equal to 1) followed by a sine curve segment from 0 to p /2. The initial sine curve segment is uniformly
scaled by k 1 /( p /2) so that the length of its domain is k 1 . The length of the domain of the line segment is
k 2 k 1 . And the final sine curve segment is uniformly scaled by 1.0
The solution is formed by piecing together a sine curve segment from
k 2 /( p /2) so that the length of its
1 (first-order)
continuity at the junction of the sine curves with the straight line segment. This means that for the first
sine curve segment to have a domain from 0 to k 1 , it must have a range of length k 1 /( p /2); similarly, the
ending sine curve segment must have a range of length 1
domain is 1.0
k 2 . The sine curve segments must be uniformly scaled to preserve C
k 2 /( p /2). The middle straight line segment,
with a slope of 1, will travel a distance of k 2 k 1 .
To normalize the distance traveled, the resulting three-segment curvemust be scaled down by a factor
equal to the total distance traveled as computed by k 1 /( p /2)
k 2 /( p /2) (see Figure 3.12 ) .
The ease function described above and shown in Equation 3.19 is implemented in the code of
Figure 3.13 .
þ k 2 k 1 þ
1
1
s
0.8
1.0 k 2
π ⁄ 2
0.6
k 2 k 1
0.4
k 1
π ⁄ 2
0.2
k 1
k 2
1.0
0.2
0.4
0.6
0.8
1
Time
Ease-in/ease-out curve as it is initially pieced
together
Curve segments scaled into useful values
with points marking segment junctions
FIGURE 3.12
Using sinusoidal segments with constant speed intermediate interval.
double ease(float t, float k1, float k2)
{
double f,s;
f = k1*2/PI + k2 - k1 + (1.0 - k2)*2/PI;
if(t < k1) s = k1*(2/PI)*(sin((t/k1)*PI/2 - PI/2)+1);
else if (t < k2) s = (2*k1/PI + t - k1);
else
s = 2*k1/PI + k2 - k1 + ((1-k2)*(2/PI)) *
sin(((t - k2)/(1.0 - k2))*PI/2);
return (s/f);
}
FIGURE 3.13
Code to implement ease-in/ease-out using sinusoidal ease-in, followed by constant velocity and sinusoidal
 
Search WWH ::




Custom Search