DNESS / cocos2d-iphone

Automatically exported from code.google.com/p/cocos2d-iphone
1 stars 0 forks source link

Enhanced Feature - Exponential Ease Action using Polynomial Functions #1469

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
*** Description of issue and solution ***

The issue with exponential functions is that they exhibit asymptotes.
The effects of the asymptotes become visible when performing large changes over 
a short time.
i.e. rotate 6000 degrees in 2.5 seconds with an exponential ease out, the 
effect is that as it comes to a stop, it jumps to its final position.

ExponentialEaseOut will asymptote at newT = 1 while ExponentialEaseIn will 
asymptote at newT = 0, hence the original version hard coded these values for 
newT.

I have replaced the exponential mathematical routine with a nth order 
polynomial which resembles an exponential curve for values of 0 <= t <= 1 and 
an order of 6.
The advantage of using polynomial curves is that they do not asymptote.
I have allowed for odd and even values of polynomial orders as odd values will 
exhibit an inflection in the curve.

As a feature of this curve, you can now control the acceleration at which it 
eases in or out by adjusting the polynomial value, polynomial must be greater 
than 1.

*** Demonstration of theory ***

The attached image shows the following:
Purple curve = Exponential Curve for EaseOut, asymptotes at y = 1
Red curve = 6th order polynomial for EaseOut, y =1 when x = 1
Green curve = Exponential Curve for EaseIn, asymptotes at y = 0
Dark Blue curve = 6th order polynomial for EaseIn, y =0 when x = 0
Brown and light blue curve represent an EaseInOut 6th order polynomial were y = 
0 when x = 0 and y = 1 when x = 1.

*** Code Details ***

- added an abstract class called CCEaseExponential where it will store 
polynomial order, inflection attribute and intersect point for InOut action 
based on the polynomial order
- added property for abstract class to change the order of the polynomial to 
control acceleration of the ease function
- Modified CCEaseExponentialIn to use polynomial curves of newT = t^n  where n 
> 1
- Modified CCEaseExponentialOut to use polynomial curves of newT = (t - 1)^n + 
1  where n > 1 and is an odd integer, newT = -( (t - 1)^n ) + 1  where n > 1 
and is an even integer
- Modified CCEaseExponentialInOut (for 0 <= t < 0.5) to use polynomial curves 
of newT = (t * intersect)^n  where n > 1,
- Modified CCEaseExponentialInOut (for 0.5 <= t <= 1) to use polynomial curves 
of newT = ( (t - 1) * intersect)^n + 1  where n > 1 and is an odd integer, newT 
= -( ( (t - 1) * * intersect ) ^n ) + 1  where n > 1 and is an even integer

Original issue reported on code.google.com by nader.el...@gmail.com on 6 Mar 2013 at 11:50

Attachments:

GoogleCodeExporter commented 9 years ago
Forgot to give the details:

Pull Request: https://github.com/cocos2d/cocos2d-iphone/pull/297

Commit: 
https://github.com/nader-eloshaiker/cocos2d-iphone/commit/ef31e975063d1d93421564
8d7a7fbae0aa03d18a

Files Changed:
cocos2d/CCActionEase.h
cocos2d/CCActionEase.m

Original comment by nader.el...@gmail.com on 6 Mar 2013 at 11:55

GoogleCodeExporter commented 9 years ago
Please ignore my previous pull request and use the below. I was merging into 
the wrong branch and was merging all 1000 commits.

https://github.com/cocos2d/cocos2d-iphone/pull/298

Original comment by nader.el...@gmail.com on 6 Mar 2013 at 7:24

GoogleCodeExporter commented 9 years ago
thanks. I will review it later.

Original comment by ricardoq...@gmail.com on 6 Mar 2013 at 8:57

GoogleCodeExporter commented 9 years ago
Would it be more desirable to just create a new ease class instead of replacing 
 CCEaseExponential. Perhaps CCEasePolynomial?

Original comment by nader.el...@gmail.com on 26 Mar 2013 at 8:51