1 /*
2 * Copyright 2008, Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Alexandre Deckner <alex@zappotek.com>
7 */
8
9 // Some math utils, useful for animation
10
11
12 #include "MathUtils.h"
13
14 #include <math.h>
15
16
17 float
EaseInOutCubic(float time,float start,float distance,float duration)18 MathUtils::EaseInOutCubic(float time, float start, float distance,
19 float duration)
20 {
21 time /= duration / 2.0;
22 if (time < 1.0)
23 return distance / 2.0 * time * time * time + start;
24 time -= 2.0;
25 return distance / 2.0 * (time * time * time + 2.0) + start;
26 }
27
28
29 float
EaseInOutQuart(float time,float start,float distance,float duration)30 MathUtils::EaseInOutQuart(float time, float start, float distance,
31 float duration)
32 {
33 time /= duration / 2;
34
35 if (time < 1)
36 return distance / 2 * time * time * time * time + start;
37
38 time -= 2;
39
40 return -distance / 2 * (time * time * time * time - 2) + start;
41 }
42
43
44 float
EaseInOutQuint(float time,float start,float distance,float duration)45 MathUtils::EaseInOutQuint(float time, float start, float distance,
46 float duration)
47 {
48 time /= duration / 2;
49 if (time < 1)
50 return distance / 2 * time * time * time * time * time + start;
51 time -= 2;
52 return distance / 2 *(time * time * time * time * time + 2) + start;
53 }
54
55
56 float
EaseInOutSine(float time,float start,float distance,float duration)57 MathUtils::EaseInOutSine(float time, float start, float distance,
58 float duration)
59 {
60 return -distance / 2 * (cos(3.14159 * time / distance) - 1) + start;
61 }
62