AHFloat BounceEaseInOut(AHFloat p) { if (p < 0.5) { return 0.5 * BounceEaseIn(p * 2); } else { return 0.5 * BounceEaseOut(p * 2 - 1) + 0.5; } }
double BounceEaseInOut(double t, double b, double c, double d) { if( t < d/2 ) return BounceEaseIn( t*2, 0, c, d ) * .5f + b; else return BounceEaseOut( t*2-d, 0, c, d ) * .5f + c*.5f + b; }
float TweenInterpolation::BounceEaseInOut(float from, float change, float factor) { if (factor < 0.5f) { return BounceEaseIn(0, change, factor * 2) * 0.5f + from; } return BounceEaseOut(0, change, factor * 2 - 1.0f) * .5f + change * 0.5f + from; }
double MathUtil::BounceEaseInOut(double p) { if(p < 0.5) { return 0.5 * BounceEaseIn(p*2); } else { return 0.5 * BounceEaseOut(p * 2 - 1) + 0.5; } }
void MyTweener::Tick(double timepassed) { if( m_Done && m_HoldPositionWhenDone == false ) return; m_TimePassed += timepassed; m_Done = true; for( unsigned int i=0; i<m_ListOfVars.Count(); i++ ) { TweenVar* pVar = m_ListOfVars[i]; if( pVar->m_Done && m_HoldVarPositionsWhenIndividualVarsAreDone == false ) continue; double passed = m_TimePassed - pVar->m_Delay; if( passed < 0 ) { m_Done = false; if( pVar->m_UseStartValueWhileWaitingForDelay == false ) return; // don't affect value until delay is over... passed = 0; } double totaltime = pVar->m_TweenTime; double timeperc = passed/totaltime; if( timeperc > 1 ) { timeperc = 1; pVar->m_Done = true; } else { m_Done = false; } double startvalue = 0; double valuerange = 0; if( pVar->m_VarType == MTVT_UnsignedChar ) { startvalue = ((TweenUnsignedChar*)pVar)->m_StartValue; valuerange = ((TweenUnsignedChar*)pVar)->m_EndValue - ((TweenUnsignedChar*)pVar)->m_StartValue; } else if( pVar->m_VarType == MTVT_Char ) { startvalue = ((TweenChar*)pVar)->m_StartValue; valuerange = ((TweenChar*)pVar)->m_EndValue - ((TweenChar*)pVar)->m_StartValue; } else if( pVar->m_VarType == MTVT_Int ) { startvalue = ((TweenInt*)pVar)->m_StartValue; valuerange = ((TweenInt*)pVar)->m_EndValue - ((TweenInt*)pVar)->m_StartValue; } else if( pVar->m_VarType == MTVT_Float ) { startvalue = ((TweenFloat*)pVar)->m_StartValue; valuerange = ((TweenFloat*)pVar)->m_EndValue - ((TweenFloat*)pVar)->m_StartValue; } double newvalue = 0; if( pVar->m_Done ) { newvalue = startvalue + valuerange; } else { switch( pVar->m_TweenType ) { case MTT_Linear: newvalue = startvalue + valuerange*timeperc; break; case MTT_SineEaseIn: // -5 * cos(x * 3.1415927/2) + 5 newvalue = startvalue + -valuerange * cos(timeperc * PI/2) + valuerange; break; case MTT_SineEaseOut: // 5 * sin(x * 3.1415927/2) newvalue = startvalue + valuerange * sin(timeperc * PI/2); break; case MTT_SineEaseInOut: // -5/2 * (cos(x * 3.1415927)-1) newvalue = startvalue + -valuerange/2 * (cos(timeperc * PI)-1); break; case MTT_BounceEaseIn: newvalue = BounceEaseIn( passed, startvalue, valuerange, totaltime ); break; case MTT_BounceEaseOut: newvalue = BounceEaseOut( passed, startvalue, valuerange, totaltime ); break; case MTT_BounceEaseInOut: newvalue = BounceEaseInOut( passed, startvalue, valuerange, totaltime ); break; case MTT_ElasticEaseIn: newvalue = ElasticEaseIn( passed, startvalue, valuerange, totaltime, pVar->m_Elasticity ); break; case MTT_ElasticEaseOut: newvalue = ElasticEaseOut( passed, startvalue, valuerange, totaltime, pVar->m_Elasticity ); break; case MTT_ElasticEaseInOut: newvalue = ElasticEaseInOut( passed, startvalue, valuerange, totaltime, pVar->m_Elasticity ); break; } } if( pVar->m_VarType == MTVT_UnsignedChar ) { *((TweenUnsignedChar*)pVar)->m_pVariable = (unsigned char)newvalue; } else if( pVar->m_VarType == MTVT_Char ) { *((TweenChar*)pVar)->m_pVariable = (char)newvalue; } else if( pVar->m_VarType == MTVT_Int ) { *((TweenInt*)pVar)->m_pVariable = (int)newvalue; } else if( pVar->m_VarType == MTVT_Float ) { *((TweenFloat*)pVar)->m_pVariable = (float)newvalue; } } }
MathUtil::MathUtil() { int SizeOfFloat = sizeof(float); InitSin(); m_easeQuadIn = (float *)malloc(100 * SizeOfFloat); m_easeQuadOut = (float *)malloc(100 * SizeOfFloat); m_easeQuadInOut = (float *)malloc(100 * SizeOfFloat); m_easeCubeIn = (float *)malloc(100 * SizeOfFloat); m_easeCubeOut = (float *)malloc(100 * SizeOfFloat); m_easeCubeInOut = (float *)malloc(100 * SizeOfFloat); m_easeQuartIn = (float *)malloc(100 * SizeOfFloat); m_easeQuartOut = (float *)malloc(100 * SizeOfFloat); m_easeQuartInOut = (float *)malloc(100 * SizeOfFloat); m_easeQuintIn = (float *)malloc(100 * SizeOfFloat); m_easeQuintOut = (float *)malloc(100 * SizeOfFloat); m_easeQuintInOut = (float *)malloc(100 * SizeOfFloat); m_easeElasticIn = (float *)malloc(100 * SizeOfFloat); m_easeElasticOut = (float *)malloc(100 * SizeOfFloat); m_easeElasticInOut = (float *)malloc(100 * SizeOfFloat); m_easeBackIn = (float *)malloc(100 * SizeOfFloat); m_easeBackOut = (float *)malloc(100 * SizeOfFloat); m_easeBackInOut = (float *)malloc(100 * SizeOfFloat); m_easeBounceIn = (float *)malloc(100 * SizeOfFloat); m_easeBounceOut = (float *)malloc(100 * SizeOfFloat); m_easeBounceInOut = (float *)malloc(100 * SizeOfFloat); for (int i = 0; i < 100; i++) { double t = i / 100.0; m_easeQuadIn[i] = QuadraticEaseIn(t); m_easeQuadOut[i] = QuadraticEaseOut(t); m_easeQuadInOut[i] = QuadraticEaseInOut(t); m_easeCubeIn[i] = CubicEaseIn(t); m_easeCubeOut[i] = CubicEaseOut(t); m_easeCubeInOut[i] = CubicEaseInOut(t); m_easeQuartIn[i] = QuarticEaseIn(t); m_easeQuartOut[i] = QuarticEaseOut(t); m_easeQuartInOut[i] = QuarticEaseInOut(t); m_easeQuintIn[i] = QuinticEaseIn(t); m_easeQuintOut[i] = QuinticEaseOut(t); m_easeQuintInOut[i] = QuinticEaseInOut(t); m_easeElasticIn[i] = ElasticEaseIn(t); m_easeElasticOut[i] = ElasticEaseOut(t); m_easeElasticInOut[i] = ElasticEaseInOut(t); m_easeBackIn[i] = BackEaseIn(t); m_easeBackOut[i] = BackEaseOut(t); m_easeBackInOut[i] = BackEaseInOut(t); m_easeBounceIn[i] = BounceEaseIn(t); m_easeBounceOut[i] = BounceEaseOut(t); m_easeBounceInOut[i] = BounceEaseInOut(t); } }
float Easing::BounceEaseInOut(float t,float b , float c, float d) { if (t < d/2) return BounceEaseIn (t*2, 0, c, d) * .5f + b; else return BounceEaseOut (t*2-d, 0, c, d) * .5f + c*.5f + b; }