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 18 MathUtils::EaseInOutCubic(float t /*time*/, float b /*begin*/, float c /*distance*/, float d /*duration*/) 19 { 20 t /= d / 2.0; 21 if (t < 1.0) 22 return c / 2.0 * t * t * t + b; 23 t -= 2.0; 24 return c / 2.0 * (t * t * t + 2.0) + b; 25 } 26 27 28 float 29 MathUtils::EaseInOutQuart(float t /*time*/, float b /*begin*/, float c /*distance*/, float d /*duration*/) 30 { 31 t /= d / 2; 32 33 if (t < 1) 34 return c / 2 * t * t * t * t + b; 35 36 t -= 2; 37 38 return -c / 2 * (t * t * t * t - 2) + b; 39 } 40 41 42 float 43 MathUtils::EaseInOutQuint(float t /*time*/, float b /*begin*/, float c /*distance*/, float d /*duration*/) 44 { 45 t /= d / 2; 46 if (t < 1) 47 return c / 2 * t * t * t * t * t + b; 48 t -= 2; 49 return c / 2 *(t * t * t * t * t + 2) + b; 50 } 51 52 53 float 54 MathUtils::EaseInOutSine(float t /*time*/, float b /*begin*/, float c /*distance*/, float d /*duration*/) 55 { 56 return -c / 2 * (cos(3.14159 * t / d) - 1) + b; 57 } 58