revert jeff's last commit since it breaks the build
[moon.git] / src / easing.cpp
blob27f82a002accc44d037020cff4d8d3b0a4ac1457
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * Contact:
4 * Moonlight List (moonlight-list@lists.ximian.com)
6 * Copyright 2007 Novell, Inc. (http://www.novell.com)
8 * See the LICENSE file included with the distribution for details.
9 *
12 #include <config.h>
14 #include <glib.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <malloc.h>
20 #include <math.h>
22 #include <runtime.h>
23 #include <timemanager.h>
24 #include <timesource.h>
26 #include "easing.h"
28 // base
30 EasingFunctionBase::EasingFunctionBase ()
32 SetObjectType (Type::EASINGFUNCTIONBASE);
33 easing_function_callback = NULL;
36 EasingFunctionBase::~EasingFunctionBase ()
41 double
42 EasingFunctionBase::Ease (double normalizedTime)
44 if (easing_function_callback)
45 return easing_function_callback (normalizedTime);
47 switch (GetEasingMode()) {
48 case EasingModeIn:
49 return EaseInCore (normalizedTime);
50 case EasingModeOut:
51 return 1.0 - EaseInCore (1 - normalizedTime);
52 case EasingModeInOut:
53 return (normalizedTime <= 0.5
54 ? EaseInCore (normalizedTime * 2) * 0.5
55 : 1.0 - EaseInCore ((1 - normalizedTime) * 2) * 0.5);
56 default:
57 // XXX
58 return 0.0;
62 void
63 EasingFunctionBase::SetEasingFunction (EasingFunction easing_function)
65 easing_function_callback = easing_function;
68 // Back
70 BackEase::BackEase ()
72 SetObjectType (Type::BACKEASE);
75 BackEase::~BackEase ()
79 double
80 BackEase::EaseInCore (double normalizedTime)
82 double t_cubed = normalizedTime * normalizedTime * normalizedTime;
84 return t_cubed - normalizedTime * GetAmplitude () * sin (normalizedTime * M_PI);
87 // Bounce
89 BounceEase::BounceEase ()
91 SetObjectType (Type::BOUNCEEASE);
94 BounceEase::~BounceEase ()
98 double
99 BounceEase::EaseInCore (double normalizedTime)
101 g_warning ("BounceEase::EaseInCore not implemented");
102 return EasingFunctionBase::EaseInCore (normalizedTime);
105 // Circle
107 CircleEase::CircleEase ()
109 SetObjectType (Type::CIRCLEEASE);
112 CircleEase::~CircleEase ()
116 double
117 CircleEase::EaseInCore (double normalizedTime)
119 return 1 - sqrt (1 - normalizedTime * normalizedTime);
122 // Cubic
124 CubicEase::CubicEase ()
126 SetObjectType (Type::CUBICEASE);
129 CubicEase::~CubicEase ()
133 double
134 CubicEase::EaseInCore (double normalizedTime)
136 return normalizedTime * normalizedTime * normalizedTime;
139 // Elastic
141 ElasticEase::ElasticEase ()
143 SetObjectType (Type::ELASTICEASE);
146 ElasticEase::~ElasticEase ()
150 double
151 ElasticEase::EaseInCore (double normalizedTime)
153 g_warning ("ElasticEase::EaseInCore not implemented");
154 return EasingFunctionBase::EaseInCore (normalizedTime);
157 // Exponential
159 ExponentialEase::ExponentialEase ()
161 SetObjectType (Type::EXPONENTIALEASE);
164 ExponentialEase::~ExponentialEase ()
168 double
169 ExponentialEase::EaseInCore (double normalizedTime)
171 return (exp (GetExponent () * normalizedTime) - 1) / (exp (GetExponent ()) - 1);
174 // Power
176 PowerEase::PowerEase ()
178 SetObjectType (Type::POWEREASE);
181 PowerEase::~PowerEase ()
185 double
186 PowerEase::EaseInCore (double normalizedTime)
188 return pow (normalizedTime, GetPower ());
191 // Quadratic
193 QuadraticEase::QuadraticEase ()
195 SetObjectType (Type::QUADRATICEASE);
198 QuadraticEase::~QuadraticEase ()
202 double
203 QuadraticEase::EaseInCore (double normalizedTime)
205 return normalizedTime * normalizedTime;
209 // Quartic
211 QuarticEase::QuarticEase ()
213 SetObjectType (Type::QUARTICEASE);
216 QuarticEase::~QuarticEase ()
220 double
221 QuarticEase::EaseInCore (double normalizedTime)
223 return normalizedTime * normalizedTime * normalizedTime * normalizedTime;
227 // Quintic
229 QuinticEase::QuinticEase ()
231 SetObjectType (Type::QUINTICEASE);
234 QuinticEase::~QuinticEase ()
238 double
239 QuinticEase::EaseInCore (double normalizedTime)
241 return normalizedTime * normalizedTime * normalizedTime * normalizedTime * normalizedTime;
245 // Sine
247 SineEase::SineEase ()
249 SetObjectType (Type::SINEEASE);
252 SineEase::~SineEase ()
256 double
257 SineEase::EaseInCore (double normalizedTime)
259 return 1.0 - sin ((1.0 - normalizedTime) * M_PI_2);