From c64de635f16f20ca03dbcb5dcdacfc14523a7d84 Mon Sep 17 00:00:00 2001 From: Nicolas Gramlich Date: Mon, 18 Jul 2011 17:10:41 +0200 Subject: [PATCH] Improved all IEaseFunction. (Performance and readability). --- .../modifier/CubicBezierMoveModifier.java | 14 ++++++- .../modifier/QuadraticBezierMoveModifier.java | 2 +- .../atlas/bitmap/BitmapTextureAtlas.java | 8 ++-- .../bitmap/BuildableBitmapTextureAtlas.java | 8 ++-- .../buildable/BuildableTextureAtlas.java | 6 +-- .../opengl/util/FastFloatBuffer.java | 2 +- .../andengine/opengl/view/GLSurfaceView.java | 14 +++---- .../opengl/view/SimpleEGLConfigChooser.java | 2 +- .../modifier/BaseSingleValueSpanModifier.java | 2 +- .../util/modifier/ease/EaseBackIn.java | 14 +++++-- .../util/modifier/ease/EaseBackInOut.java | 17 ++++---- .../util/modifier/ease/EaseBackOut.java | 13 ++++-- .../util/modifier/ease/EaseBounceIn.java | 13 ++++-- .../util/modifier/ease/EaseBounceInOut.java | 14 ++++--- .../util/modifier/ease/EaseBounceOut.java | 31 ++++++++------ .../util/modifier/ease/EaseCircularIn.java | 13 ++++-- .../util/modifier/ease/EaseCircularInOut.java | 17 ++++---- .../util/modifier/ease/EaseCircularOut.java | 14 +++++-- .../util/modifier/ease/EaseCubicIn.java | 13 ++++-- .../util/modifier/ease/EaseCubicInOut.java | 16 ++++--- .../util/modifier/ease/EaseCubicOut.java | 14 +++++-- .../util/modifier/ease/EaseElasticIn.java | 42 +++++++++---------- .../util/modifier/ease/EaseElasticInOut.java | 34 ++++----------- .../util/modifier/ease/EaseElasticOut.java | 41 +++++++++--------- .../util/modifier/ease/EaseExponentialIn.java | 14 +++++-- .../modifier/ease/EaseExponentialInOut.java | 22 +++++----- .../modifier/ease/EaseExponentialOut.java | 13 ++++-- .../util/modifier/ease/EaseLinear.java | 9 ++-- .../util/modifier/ease/EaseQuadIn.java | 13 ++++-- .../util/modifier/ease/EaseQuadInOut.java | 16 ++++--- .../util/modifier/ease/EaseQuadOut.java | 13 ++++-- .../util/modifier/ease/EaseQuartIn.java | 12 ++++-- .../util/modifier/ease/EaseQuartInOut.java | 16 ++++--- .../util/modifier/ease/EaseQuartOut.java | 14 +++++-- .../util/modifier/ease/EaseQuintIn.java | 13 ++++-- .../util/modifier/ease/EaseQuintInOut.java | 16 ++++--- .../util/modifier/ease/EaseQuintOut.java | 14 +++++-- .../util/modifier/ease/EaseSineIn.java | 13 ++++-- .../util/modifier/ease/EaseSineInOut.java | 14 ++++--- .../util/modifier/ease/EaseSineOut.java | 13 ++++-- .../util/modifier/ease/EaseStrongIn.java | 13 ++++-- .../util/modifier/ease/EaseStrongInOut.java | 16 ++++--- .../util/modifier/ease/EaseStrongOut.java | 14 +++++-- .../util/modifier/ease/IEaseFunction.java | 6 +-- 44 files changed, 381 insertions(+), 257 deletions(-) diff --git a/src/org/anddev/andengine/entity/modifier/CubicBezierMoveModifier.java b/src/org/anddev/andengine/entity/modifier/CubicBezierMoveModifier.java index 2e22ca1ea..49fbca3aa 100644 --- a/src/org/anddev/andengine/entity/modifier/CubicBezierMoveModifier.java +++ b/src/org/anddev/andengine/entity/modifier/CubicBezierMoveModifier.java @@ -35,6 +35,18 @@ public class CubicBezierMoveModifier extends DurationEntityModifier { // Constructors // =========================================================== + /** + * @param pDuration + * @param pX1 x coordinate of the start point. + * @param pY1 y coordinate of the start point. + * @param pX2 x coordinate of the first control point. + * @param pY2 y coordinate of the first control point. + * @param pX3 x coordinate of the second control point. + * @param pY3 y coordinate of the second control point. + * @param pX4 x coordinate of the end point. + * @param pY4 y coordinate of the end point. + * @param pEaseFunction + */ public CubicBezierMoveModifier(final float pDuration, final float pX1, final float pY1, final float pX2, final float pY2, final float pX3, final float pY3, final float pX4, final float pY4, final IEaseFunction pEaseFunction) { super(pDuration); @@ -65,7 +77,7 @@ public CubicBezierMoveModifier clone() { @Override protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntity) { - final float percentageDone = this.mEaseFunction.getPercentageDone(this.getSecondsElapsed(), this.mDuration, 0, 1); + final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration); final float u = 1 - percentageDone; final float tt = percentageDone * percentageDone; diff --git a/src/org/anddev/andengine/entity/modifier/QuadraticBezierMoveModifier.java b/src/org/anddev/andengine/entity/modifier/QuadraticBezierMoveModifier.java index c184d5628..7a1ff7670 100644 --- a/src/org/anddev/andengine/entity/modifier/QuadraticBezierMoveModifier.java +++ b/src/org/anddev/andengine/entity/modifier/QuadraticBezierMoveModifier.java @@ -60,7 +60,7 @@ public QuadraticBezierMoveModifier clone() { @Override protected void onManagedUpdate(final float pSecondsElapsed, final IEntity pEntity) { - final float percentageDone = this.mEaseFunction.getPercentageDone(this.getSecondsElapsed(), this.mDuration, 0, 1); + final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration); final float u = 1 - percentageDone; final float tt = percentageDone*percentageDone; diff --git a/src/org/anddev/andengine/opengl/texture/atlas/bitmap/BitmapTextureAtlas.java b/src/org/anddev/andengine/opengl/texture/atlas/bitmap/BitmapTextureAtlas.java index 63c1a9a38..b0614410b 100644 --- a/src/org/anddev/andengine/opengl/texture/atlas/bitmap/BitmapTextureAtlas.java +++ b/src/org/anddev/andengine/opengl/texture/atlas/bitmap/BitmapTextureAtlas.java @@ -50,7 +50,7 @@ public BitmapTextureAtlas(final int pWidth, final int pHeight) { /** * @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). * @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). - * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency. + * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency. */ public BitmapTextureAtlas(final int pWidth, final int pHeight, final BitmapTextureFormat pBitmapTextureFormat) { this(pWidth, pHeight, pBitmapTextureFormat, TextureOptions.DEFAULT, null); @@ -70,7 +70,7 @@ public BitmapTextureAtlas(final int pWidth, final int pHeight, final ITextureAtl /** * @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). * @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). - * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency. + * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency. * @param pTextureAtlasStateListener to be informed when this {@link BitmapTextureAtlas} is loaded, unloaded or a {@link ITextureAtlasSource} failed to load. */ public BitmapTextureAtlas(final int pWidth, final int pHeight, final BitmapTextureFormat pBitmapTextureFormat, final ITextureAtlasStateListener pTextureAtlasStateListener) { @@ -91,7 +91,7 @@ public BitmapTextureAtlas(final int pWidth, final int pHeight, final TextureOpti /** * @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). * @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). - * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency. + * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency. * @param pTextureOptions the (quality) settings of the BitmapTexture. */ public BitmapTextureAtlas(final int pWidth, final int pHeight, final BitmapTextureFormat pBitmapTextureFormat, final TextureOptions pTextureOptions) throws IllegalArgumentException { @@ -113,7 +113,7 @@ public BitmapTextureAtlas(final int pWidth, final int pHeight, final TextureOpti /** * @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). * @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). - * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency. + * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency. * @param pTextureOptions the (quality) settings of the BitmapTexture. * @param pTextureAtlasStateListener to be informed when this {@link BitmapTextureAtlas} is loaded, unloaded or a {@link ITextureAtlasSource} failed to load. */ diff --git a/src/org/anddev/andengine/opengl/texture/atlas/bitmap/BuildableBitmapTextureAtlas.java b/src/org/anddev/andengine/opengl/texture/atlas/bitmap/BuildableBitmapTextureAtlas.java index 72494612d..58b159be8 100644 --- a/src/org/anddev/andengine/opengl/texture/atlas/bitmap/BuildableBitmapTextureAtlas.java +++ b/src/org/anddev/andengine/opengl/texture/atlas/bitmap/BuildableBitmapTextureAtlas.java @@ -39,7 +39,7 @@ public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight) { /** * @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). * @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). - * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency. + * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency. */ public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight, final BitmapTextureFormat pBitmapTextureFormat) { this(pWidth, pHeight, pBitmapTextureFormat, TextureOptions.DEFAULT, null); @@ -59,7 +59,7 @@ public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight, final IT /** * @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). * @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). - * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency. + * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency. * @param pTextureStateListener to be informed when this {@link BitmapTextureAtlas} is loaded, unloaded or a {@link ITextureAtlasSource} failed to load. */ public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight, final BitmapTextureFormat pBitmapTextureFormat, final ITextureAtlasStateListener pTextureStateListener) { @@ -80,7 +80,7 @@ public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight, final Te /** * @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). * @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). - * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency. + * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency. * @param pTextureOptions the (quality) settings of the BitmapTexture. */ public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight, final BitmapTextureFormat pBitmapTextureFormat, final TextureOptions pTextureOptions) throws IllegalArgumentException { @@ -102,7 +102,7 @@ public BuildableBitmapTextureAtlas(final int pWidth, final int pHeight, final Te /** * @param pWidth must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). * @param pHeight must be a power of 2 (i.e. 32, 64, 128, 256, 512, 1024). - * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}s with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}s without transparency. + * @param pBitmapTextureFormat use {@link BitmapTextureFormat#RGBA_8888} for {@link BitmapTextureAtlas}MAGIC_CONSTANT with transparency and {@link BitmapTextureFormat#RGB_565} for {@link BitmapTextureAtlas}MAGIC_CONSTANT without transparency. * @param pTextureOptions the (quality) settings of the BitmapTexture. * @param pTextureStateListener to be informed when this {@link BitmapTextureAtlas} is loaded, unloaded or a {@link ITextureAtlasSource} failed to load. */ diff --git a/src/org/anddev/andengine/opengl/texture/buildable/BuildableTextureAtlas.java b/src/org/anddev/andengine/opengl/texture/buildable/BuildableTextureAtlas.java index e80f104b4..7fb13f345 100644 --- a/src/org/anddev/andengine/opengl/texture/buildable/BuildableTextureAtlas.java +++ b/src/org/anddev/andengine/opengl/texture/buildable/BuildableTextureAtlas.java @@ -144,7 +144,7 @@ public ITextureAtlasStateListener getTextureStateListener() { // =========================================================== /** - * When all {@link ITextureAtlasSource}s are added you have to call {@link BuildableBitmapTextureAtlas#build(ITextureBuilder)}. + * When all {@link ITextureAtlasSource}MAGIC_CONSTANT are added you have to call {@link BuildableBitmapTextureAtlas#build(ITextureBuilder)}. * @param pTextureAtlasSource to be added. * @param pTextureRegion */ @@ -169,10 +169,10 @@ public void removeTextureAtlasSource(final ITextureAtlasSource pTextureAtlasSour } /** - * May draw over already added {@link ITextureAtlasSource}s. + * May draw over already added {@link ITextureAtlasSource}MAGIC_CONSTANT. * * @param pTextureAtlasSourcePackingAlgorithm the {@link ITextureBuilder} to use for packing the {@link ITextureAtlasSource} in this {@link BuildableBitmapTextureAtlas}. - * @throws TextureAtlasSourcePackingException i.e. when the {@link ITextureAtlasSource}s didn't fit into this {@link BuildableBitmapTextureAtlas}. + * @throws TextureAtlasSourcePackingException i.e. when the {@link ITextureAtlasSource}MAGIC_CONSTANT didn't fit into this {@link BuildableBitmapTextureAtlas}. */ public void build(final ITextureBuilder pTextureAtlasSourcePackingAlgorithm) throws TextureAtlasSourcePackingException { pTextureAtlasSourcePackingAlgorithm.pack(this.mTextureAtlas, this.mTextureAtlasSourcesToPlace); diff --git a/src/org/anddev/andengine/opengl/util/FastFloatBuffer.java b/src/org/anddev/andengine/opengl/util/FastFloatBuffer.java index aee5aebcf..bb17fb6d0 100644 --- a/src/org/anddev/andengine/opengl/util/FastFloatBuffer.java +++ b/src/org/anddev/andengine/opengl/util/FastFloatBuffer.java @@ -84,7 +84,7 @@ public void put(final float f) { } /** - * It's like {@link FloatBuffer#put(float[])}, but about 10 times faster + * It'MAGIC_CONSTANT like {@link FloatBuffer#put(float[])}, but about 10 times faster */ public void put(final float[] data) { final int length = data.length; diff --git a/src/org/anddev/andengine/opengl/view/GLSurfaceView.java b/src/org/anddev/andengine/opengl/view/GLSurfaceView.java index e31cad1b9..f2f735dde 100644 --- a/src/org/anddev/andengine/opengl/view/GLSurfaceView.java +++ b/src/org/anddev/andengine/opengl/view/GLSurfaceView.java @@ -42,7 +42,7 @@ *
  • Renders on a dedicated thread to decouple rendering performance from the * UI thread. *
  • Supports both on-demand and continuous rendering. - *
  • Optionally wraps, traces, and/or error-checks the renderer's OpenGL + *
  • Optionally wraps, traces, and/or error-checks the renderer'MAGIC_CONSTANT OpenGL * calls. * * @@ -76,7 +76,7 @@ * the first thing GLSurfaceView has to do when starting to render is choose * what type of surface to use. *

    - * By default GLSurfaceView chooses an available surface that's closest to a + * By default GLSurfaceView chooses an available surface that'MAGIC_CONSTANT closest to a * 16-bit R5G6B5 surface with a 16-bit depth buffer and no stencil. If you would * prefer a different surface (for example, if you do not need a depth buffer) * you can override the default behavior by calling one of the @@ -110,7 +110,7 @@ * To handle an event you will typically subclass GLSurfaceView and override the * appropriate method, just as you would with any other View. However, when * handling the event, you may need to communicate with the Renderer object - * that's running in the rendering thread. You can do this using any standard + * that'MAGIC_CONSTANT running in the rendering thread. You can do this using any standard * Java cross-thread communication mechanism. In addition, one relatively easy * way to communicate with your renderer is to call * {@link #queueEvent(Runnable)}. For example: @@ -237,7 +237,7 @@ private void init() { /** * Set the glWrapper. If the glWrapper is not null, its * {@link GLWrapper#wrap(GL)} method is called whenever a surface is - * created. A GLWrapper can be used to wrap the GL object that's passed to + * created. A GLWrapper can be used to wrap the GL object that'MAGIC_CONSTANT passed to * the renderer. Wrapping a GL object enables examining and modifying the * behavior of the GL calls made by the renderer. *

    @@ -534,7 +534,7 @@ class GLThread extends Thread { public void run() { /* * When the android framework launches a second instance of an - * activity, the new instance's onCreate() method may be called + * activity, the new instance'MAGIC_CONSTANT onCreate() method may be called * before the first instance returns from onDestroy(). * * This semaphore ensures that only one instance at a time accesses @@ -563,7 +563,7 @@ private void guardedRun() throws InterruptedException { boolean tellRendererSurfaceChanged = true; /* - * This is our main activity thread's loop, we go until asked to + * This is our main activity thread'MAGIC_CONSTANT loop, we go until asked to * quit. */ while(!this.mDone) { @@ -893,7 +893,7 @@ public void finish() { *

    Threading

    * The renderer will be called on a separate thread, so that rendering * performance is decoupled from the UI thread. Clients typically need to - * communicate with the renderer from the UI thread, because that's where + * communicate with the renderer from the UI thread, because that'MAGIC_CONSTANT where * input events are received. Clients can communicate using any of the * standard Java techniques for cross-thread communication, or they can use * the {@link GLSurfaceView#queueEvent(Runnable)} convenience method. diff --git a/src/org/anddev/andengine/opengl/view/SimpleEGLConfigChooser.java b/src/org/anddev/andengine/opengl/view/SimpleEGLConfigChooser.java index 6916b72e5..86670735c 100644 --- a/src/org/anddev/andengine/opengl/view/SimpleEGLConfigChooser.java +++ b/src/org/anddev/andengine/opengl/view/SimpleEGLConfigChooser.java @@ -27,7 +27,7 @@ class SimpleEGLConfigChooser extends ComponentSizeChooser { public SimpleEGLConfigChooser(final boolean pWithDepthBuffer) { super(4, 4, 4, 0, pWithDepthBuffer ? 16 : 0, 0); // Adjust target values. This way we'll accept a 4444 or - // 555 buffer if there's no 565 buffer available. + // 555 buffer if there'MAGIC_CONSTANT no 565 buffer available. this.mRedSize = 5; this.mGreenSize = 6; this.mBlueSize = 5; diff --git a/src/org/anddev/andengine/util/modifier/BaseSingleValueSpanModifier.java b/src/org/anddev/andengine/util/modifier/BaseSingleValueSpanModifier.java index 17bd5ee15..a8d5c56fb 100644 --- a/src/org/anddev/andengine/util/modifier/BaseSingleValueSpanModifier.java +++ b/src/org/anddev/andengine/util/modifier/BaseSingleValueSpanModifier.java @@ -71,7 +71,7 @@ protected void onManagedInitialize(final T pItem) { @Override protected void onManagedUpdate(final float pSecondsElapsed, final T pItem) { - final float percentageDone = this.mEaseFunction.getPercentageDone(this.getSecondsElapsed(), this.mDuration, 0, 1); + final float percentageDone = this.mEaseFunction.getPercentage(this.getSecondsElapsed(), this.mDuration); this.onSetValue(pItem, percentageDone, this.mFromValue + percentageDone * this.mValueSpan); } diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseBackIn.java b/src/org/anddev/andengine/util/modifier/ease/EaseBackIn.java index be2dea6b6..54d73ccfc 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseBackIn.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseBackIn.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -13,6 +13,8 @@ public class EaseBackIn implements IEaseFunction { // Constants // =========================================================== + private static final float OVERSHOOT_CONSTANT = 1.70158f; + // =========================================================== // Fields // =========================================================== @@ -43,14 +45,18 @@ public static EaseBackIn getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return pMaxValue * (pSecondsElapsed /= pDuration) * pSecondsElapsed * ((1.70158f + 1) * pSecondsElapsed - 1.70158f) + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseBackIn.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + return pPercentage * pPercentage * ((OVERSHOOT_CONSTANT + 1) * pPercentage - OVERSHOOT_CONSTANT); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseBackInOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseBackInOut.java index 64b0d3492..c41f2ce0d 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseBackInOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseBackInOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -43,13 +43,14 @@ public static EaseBackInOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - float s = 1.70158f; - if((pSecondsElapsed /= pDuration * 0.5f) < 1) { - return pMaxValue * 0.5f * (pSecondsElapsed * pSecondsElapsed * (((s *= (1.525f)) + 1) * pSecondsElapsed - s)) + pMinValue; - } + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + final float percentage = pSecondsElapsed / pDuration; - return pMaxValue / 2 * ((pSecondsElapsed -= 2) * pSecondsElapsed * (((s *= (1.525f)) + 1) * pSecondsElapsed + s) + 2) + pMinValue; + if(percentage < 0.5f) { + return 0.5f * EaseBackIn.getValue(2 * percentage); + } else { + return 0.5f + 0.5f * EaseBackOut.getValue(percentage * 2 - 1); + } } // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseBackOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseBackOut.java index 8cdde5052..44c7e25ce 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseBackOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseBackOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -43,14 +43,19 @@ public static EaseBackOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return pMaxValue * ((pSecondsElapsed = pSecondsElapsed / pDuration - 1) * pSecondsElapsed * ((1.70158f + 1) * pSecondsElapsed + 1.70158f) + 1) + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseBackOut.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + final float t = pPercentage - 1; + return 1 + t * t * ((1.70158f + 1) * t + 1.70158f); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseBounceIn.java b/src/org/anddev/andengine/util/modifier/ease/EaseBounceIn.java index 32c83e475..a8ce95904 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseBounceIn.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseBounceIn.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -43,14 +43,19 @@ public static EaseBounceIn getInstance() { // =========================================================== @Override - public float getPercentageDone(final float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return pMaxValue - EaseBounceOut.getInstance().getPercentageDone(pDuration - pSecondsElapsed, pDuration, 0, pMaxValue) + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseBounceIn.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + // TODO Inline? + return 1 - EaseBounceOut.getValue(1 - pPercentage); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseBounceInOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseBounceInOut.java index 504db38d4..f1338e3ff 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseBounceInOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseBounceInOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -43,11 +43,13 @@ public static EaseBounceInOut getInstance() { // =========================================================== @Override - public float getPercentageDone(final float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - if(pSecondsElapsed < pDuration * 0.5) { - return EaseBounceIn.getInstance().getPercentageDone(pSecondsElapsed * 2, pDuration, 0, pMaxValue) * 0.5f + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + final float percentage = pSecondsElapsed / pDuration; + + if(percentage < 0.5f) { + return 0.5f * EaseBounceIn.getValue(2 * percentage); } else { - return EaseBounceOut.getInstance().getPercentageDone(pSecondsElapsed * 2 - pDuration, pDuration, 0, pMaxValue) * 0.5f + pMaxValue * 0.5f + pMinValue; + return 0.5f + 0.5f * EaseBounceOut.getValue(percentage * 2 - 1); } } diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseBounceOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseBounceOut.java index 49643306c..597bad70b 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseBounceOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseBounceOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -43,22 +43,29 @@ public static EaseBounceOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - if((pSecondsElapsed /= pDuration) < (1 / 2.75)) { - return pMaxValue * (7.5625f * pSecondsElapsed * pSecondsElapsed) + pMinValue; - } else if(pSecondsElapsed < (2 / 2.75)) { - return pMaxValue * (7.5625f * (pSecondsElapsed -= (1.5f / 2.75f)) * pSecondsElapsed + 0.75f) + pMinValue; - } else if(pSecondsElapsed < (2.5 / 2.75)) { - return pMaxValue * (7.5625f * (pSecondsElapsed -= (2.25f / 2.75f)) * pSecondsElapsed + 0.9375f) + pMinValue; - } else { - return pMaxValue * (7.5625f * (pSecondsElapsed -= (2.625f / 2.75f)) * pSecondsElapsed + 0.984375f) + pMinValue; - } + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseBounceOut.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + if(pPercentage < (1f / 2.75f)) { + return 7.5625f * pPercentage * pPercentage; + } else if(pPercentage < (2f / 2.75f)) { + final float t = pPercentage - (1.5f / 2.75f); + return 7.5625f * t * t + 0.75f; + } else if(pPercentage < (2.5f / 2.75f)) { + final float t = pPercentage - (2.25f / 2.75f); + return 7.5625f * t * t + 0.9375f; + } else { + final float t = pPercentage - (2.625f / 2.75f); + return 7.5625f * t * t + 0.984375f; + } + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseCircularIn.java b/src/org/anddev/andengine/util/modifier/ease/EaseCircularIn.java index 9b4a70c8e..84f5b6853 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseCircularIn.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseCircularIn.java @@ -3,9 +3,9 @@ import android.util.FloatMath; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -26,6 +26,7 @@ public class EaseCircularIn implements IEaseFunction { // =========================================================== private EaseCircularIn() { + } public static EaseCircularIn getInstance() { @@ -44,14 +45,18 @@ public static EaseCircularIn getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return (-pMaxValue * (FloatMath.sqrt(1 - (pSecondsElapsed /= pDuration) * pSecondsElapsed) - 1.0f) + pMinValue); + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseCircularIn.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + return -(FloatMath.sqrt(1 - pPercentage * pPercentage) - 1.0f); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseCircularInOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseCircularInOut.java index 3e7703e14..4f890bb7f 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseCircularInOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseCircularInOut.java @@ -1,11 +1,10 @@ package org.anddev.andengine.util.modifier.ease; -import android.util.FloatMath; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -44,12 +43,14 @@ public static EaseCircularInOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - if((pSecondsElapsed /= pDuration * 0.5) < 1) { - return (float) (-pMaxValue * 0.5 * (FloatMath.sqrt(1 - pSecondsElapsed * pSecondsElapsed) - 1) + pMinValue); - } + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + final float percentage = pSecondsElapsed / pDuration; - return (float) (pMaxValue * 0.5 * (FloatMath.sqrt(1 - (pSecondsElapsed -= 2) * pSecondsElapsed) + 1) + pMinValue); + if(percentage < 0.5f) { + return 0.5f * EaseCircularIn.getValue(2 * percentage); + } else { + return 0.5f + 0.5f * EaseCircularOut.getValue(percentage * 2 - 1); + } } // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseCircularOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseCircularOut.java index b0f5119e8..117e7a61a 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseCircularOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseCircularOut.java @@ -3,9 +3,9 @@ import android.util.FloatMath; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -26,6 +26,7 @@ public class EaseCircularOut implements IEaseFunction { // =========================================================== private EaseCircularOut() { + } public static EaseCircularOut getInstance() { @@ -44,14 +45,19 @@ public static EaseCircularOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return (pMaxValue * FloatMath.sqrt(1 - (pSecondsElapsed = pSecondsElapsed / pDuration - 1) * pSecondsElapsed) + pMinValue); + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseCircularOut.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + final float t = pPercentage - 1; + return FloatMath.sqrt(1 - t * t); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseCubicIn.java b/src/org/anddev/andengine/util/modifier/ease/EaseCubicIn.java index 45f0f0fd9..76e2258ea 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseCubicIn.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseCubicIn.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseCubicIn implements IEaseFunction { // =========================================================== private EaseCubicIn() { + } public static EaseCubicIn getInstance() { @@ -42,14 +43,18 @@ public static EaseCubicIn getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return pMaxValue * (pSecondsElapsed /= pDuration) * pSecondsElapsed * pSecondsElapsed + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseCubicIn.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + return pPercentage * pPercentage * pPercentage; + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseCubicInOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseCubicInOut.java index 4a58ecfb8..39226b0a7 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseCubicInOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseCubicInOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseCubicInOut implements IEaseFunction { // =========================================================== private EaseCubicInOut() { + } public static EaseCubicInOut getInstance() { @@ -42,11 +43,14 @@ public static EaseCubicInOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - if((pSecondsElapsed /= pDuration * 0.5f) < 1) { - return pMaxValue * 0.5f * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + final float percentage = pSecondsElapsed / pDuration; + + if(percentage < 0.5f) { + return 0.5f * EaseCubicIn.getValue(2 * percentage); + } else { + return 0.5f + 0.5f * EaseCubicOut.getValue(percentage * 2 - 1); } - return pMaxValue * 0.5f * ((pSecondsElapsed -= 2) * pSecondsElapsed * pSecondsElapsed + 2) + pMinValue; } // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseCubicOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseCubicOut.java index 059473048..530a797d3 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseCubicOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseCubicOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseCubicOut implements IEaseFunction { // =========================================================== private EaseCubicOut() { + } public static EaseCubicOut getInstance() { @@ -42,14 +43,19 @@ public static EaseCubicOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return pMaxValue * ((pSecondsElapsed = pSecondsElapsed / pDuration - 1) * pSecondsElapsed * pSecondsElapsed + 1) + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseCubicOut.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + final float t = pPercentage - 1; + return 1 + (t * t * t); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseElasticIn.java b/src/org/anddev/andengine/util/modifier/ease/EaseElasticIn.java index 26ee4d61e..eed6866d2 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseElasticIn.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseElasticIn.java @@ -5,9 +5,9 @@ import android.util.FloatMath; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -28,6 +28,7 @@ public class EaseElasticIn implements IEaseFunction, MathConstants { // =========================================================== private EaseElasticIn() { + } public static EaseElasticIn getInstance() { @@ -46,32 +47,29 @@ public static EaseElasticIn getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - float s; - float p = 0.0f; - float a = 0.0f; - if(pSecondsElapsed == 0) { - return pMinValue; - } - if((pSecondsElapsed /= pDuration) == 1) { - return pMinValue + pMaxValue; - } - if(p == 0) { - p = pDuration * 0.3f; - } - if(a == 0 || (pMaxValue > 0 && a < pMaxValue) || (pMaxValue < 0 && a < -pMaxValue)) { - a = pMaxValue; - s = p / 4; - } else { - s = (float) (p / PI_TWICE * Math.asin(pMaxValue / a)); - } - return (float) (-(a * Math.pow(2, 10 * (pSecondsElapsed -= 1)) * FloatMath.sin((pSecondsElapsed * pDuration - s) * PI_TWICE / p)) + pMinValue); + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseElasticIn.getValue(pSecondsElapsed, pDuration, pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pSecondsElapsed, final float pDuration, final float pPercentage) { + if(pSecondsElapsed == 0) { + return 0; + } + if(pSecondsElapsed == pDuration) { + return 1; + } + + final float p = pDuration * 0.3f; + final float s = p / 4; + + final float t = pPercentage - 1; + return -(float)Math.pow(2, 10 * t) * FloatMath.sin((t * pDuration - s) * PI_TWICE / p); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseElasticInOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseElasticInOut.java index 4ce8341ee..3b57f106c 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseElasticInOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseElasticInOut.java @@ -2,12 +2,10 @@ import org.anddev.andengine.util.constants.MathConstants; -import android.util.FloatMath; - /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -28,6 +26,7 @@ public class EaseElasticInOut implements IEaseFunction, MathConstants { // =========================================================== private EaseElasticInOut() { + } public static EaseElasticInOut getInstance() { @@ -46,29 +45,14 @@ public static EaseElasticInOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - float s; - float p = 0.0f; - float a = 0.0f; - if(pSecondsElapsed == 0) { - return pMinValue; - } - if((pSecondsElapsed /= pDuration * 0.5) == 2) { - return pMinValue + pMaxValue; - } - if(p == 0) { - p = pDuration * (0.3f * 1.5f); - } - if(a == 0 || (pMaxValue > 0 && a < pMaxValue) || (pMaxValue < 0 && a < -pMaxValue)) { - a = pMaxValue; - s = p / 4; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + final float percentage = pSecondsElapsed / pDuration; + + if(percentage < 0.5f) { + return 0.5f * EaseElasticIn.getValue(2 * pSecondsElapsed, pDuration, 2 * percentage); } else { - s = (float) (p / PI_TWICE * Math.asin(pMaxValue / a)); - } - if(pSecondsElapsed < 1) { - return (float) (-0.5 * (a * Math.pow(2, 10 * (pSecondsElapsed -= 1)) * FloatMath.sin((pSecondsElapsed * pDuration - s) * PI_TWICE / p)) + pMinValue); + return 0.5f + 0.5f * EaseElasticOut.getValue(pSecondsElapsed * 2 - pDuration, pDuration, percentage * 2 - 1); } - return (float) (a * Math.pow(2, -10 * (pSecondsElapsed -= 1)) * FloatMath.sin((pSecondsElapsed * pDuration - s) * PI_TWICE / p) * .5 + pMaxValue + pMinValue); } // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseElasticOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseElasticOut.java index a6da97abd..feac17216 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseElasticOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseElasticOut.java @@ -5,9 +5,9 @@ import android.util.FloatMath; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -28,6 +28,7 @@ public class EaseElasticOut implements IEaseFunction, MathConstants { // =========================================================== private EaseElasticOut() { + } public static EaseElasticOut getInstance() { @@ -46,32 +47,28 @@ public static EaseElasticOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - float s; - float p = 0.0f; - float a = 0.0f; - if(pSecondsElapsed == 0) { - return pMinValue; - } - if((pSecondsElapsed /= pDuration) == 1) { - return pMinValue + pMaxValue; - } - if(p == 0) { - p = pDuration * 0.3f; - } - if(a == 0 || (pMaxValue > 0 && a < pMaxValue) || (pMaxValue < 0 && a < -pMaxValue)) { - a = pMaxValue; - s = p / 4; - } else { - s = (float) (p / PI_TWICE * Math.asin(pMaxValue / a)); - } - return (float) (a * Math.pow(2, -10 * pSecondsElapsed) * FloatMath.sin((pSecondsElapsed * pDuration - s) * PI_TWICE / p) + pMaxValue + pMinValue); + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseElasticOut.getValue(pSecondsElapsed, pDuration, pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pSecondsElapsed, final float pDuration, final float pPercentageDone) { + if(pSecondsElapsed == 0) { + return 0; + } + if(pSecondsElapsed == pDuration) { + return 1; + } + + final float p = pDuration * 0.3f; + final float s = p / 4; + + return 1 + (float)Math.pow(2, -10 * pPercentageDone) * FloatMath.sin((pPercentageDone * pDuration - s) * PI_TWICE / p); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseExponentialIn.java b/src/org/anddev/andengine/util/modifier/ease/EaseExponentialIn.java index 7dfbda38b..ecaa57a6e 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseExponentialIn.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseExponentialIn.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseExponentialIn implements IEaseFunction { // =========================================================== private EaseExponentialIn() { + } public static EaseExponentialIn getInstance() { @@ -42,14 +43,19 @@ public static EaseExponentialIn getInstance() { // =========================================================== @Override - public float getPercentageDone(final float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return (float) ((pSecondsElapsed == 0) ? pMinValue : pMaxValue * Math.pow(2, 10 * (pSecondsElapsed / pDuration - 1)) + pMinValue - pMaxValue * 0.001f); + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseExponentialIn.getValue(pSecondsElapsed / pDuration); + } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + return (float) ((pPercentage == 0) ? 0 : Math.pow(2, 10 * (pPercentage - 1)) - 0.001f); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseExponentialInOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseExponentialInOut.java index c23409dd4..8e21889c8 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseExponentialInOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseExponentialInOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseExponentialInOut implements IEaseFunction { // =========================================================== private EaseExponentialInOut() { + } public static EaseExponentialInOut getInstance() { @@ -42,17 +43,14 @@ public static EaseExponentialInOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - if(pSecondsElapsed == 0) { - return pMinValue; - } - if(pSecondsElapsed == pDuration) { - return pMinValue + pMaxValue; - } - if((pSecondsElapsed /= pDuration * 0.5f) < 1) { - return (float) (pMaxValue * 0.5f * Math.pow(2, 10 * (pSecondsElapsed - 1)) + pMinValue); + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + final float percentage = pSecondsElapsed / pDuration; + + if(percentage < 0.5f) { + return 0.5f * EaseExponentialIn.getValue(2 * percentage); + } else { + return 0.5f + 0.5f * EaseExponentialOut.getValue(percentage * 2 - 1); } - return (float) (pMaxValue * 0.5f * (-Math.pow(2, -10 * --pSecondsElapsed) + 2) + pMinValue); } // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseExponentialOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseExponentialOut.java index 78ac66a1b..933d16ef2 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseExponentialOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseExponentialOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseExponentialOut implements IEaseFunction { // =========================================================== private EaseExponentialOut() { + } public static EaseExponentialOut getInstance() { @@ -42,14 +43,18 @@ public static EaseExponentialOut getInstance() { // =========================================================== @Override - public float getPercentageDone(final float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return (float) ((pSecondsElapsed == pDuration) ? pMinValue + pMaxValue : pMaxValue * (-Math.pow(2, -10 * pSecondsElapsed / pDuration) + 1) + pMinValue); + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseExponentialOut.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + return (pPercentage == 1) ? 1 : (-(float)Math.pow(2, -10 * pPercentage) + 1); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseLinear.java b/src/org/anddev/andengine/util/modifier/ease/EaseLinear.java index 4ac962dea..74b1d37dd 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseLinear.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseLinear.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:50:40 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseLinear implements IEaseFunction { // =========================================================== private EaseLinear() { + } public static EaseLinear getInstance() { @@ -42,8 +43,8 @@ public static EaseLinear getInstance() { // =========================================================== @Override - public float getPercentageDone(final float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return pMaxValue * pSecondsElapsed / pDuration + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return pSecondsElapsed / pDuration; } // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseQuadIn.java b/src/org/anddev/andengine/util/modifier/ease/EaseQuadIn.java index 0fec064f5..cdb88455a 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseQuadIn.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseQuadIn.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseQuadIn implements IEaseFunction { // =========================================================== private EaseQuadIn() { + } public static EaseQuadIn getInstance() { @@ -42,14 +43,18 @@ public static EaseQuadIn getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return pMaxValue * (pSecondsElapsed /= pDuration) * pSecondsElapsed + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseQuadIn.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + return pPercentage * pPercentage; + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseQuadInOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseQuadInOut.java index 82b5e1382..b93496c13 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseQuadInOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseQuadInOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseQuadInOut implements IEaseFunction { // =========================================================== private EaseQuadInOut() { + } public static EaseQuadInOut getInstance() { @@ -42,11 +43,14 @@ public static EaseQuadInOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - if((pSecondsElapsed /= pDuration * 0.5f) < 1) { - return pMaxValue * 0.5f * pSecondsElapsed * pSecondsElapsed + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + final float percentage = pSecondsElapsed / pDuration; + + if(percentage < 0.5f) { + return 0.5f * EaseQuadIn.getValue(2 * percentage); + } else { + return 0.5f + 0.5f * EaseQuadOut.getValue(percentage * 2 - 1); } - return -pMaxValue * 0.5f * ((--pSecondsElapsed) * (pSecondsElapsed - 2) - 1) + pMinValue; } // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseQuadOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseQuadOut.java index c40bf0fcd..1aaa5cd72 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseQuadOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseQuadOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseQuadOut implements IEaseFunction { // =========================================================== private EaseQuadOut() { + } public static EaseQuadOut getInstance() { @@ -42,14 +43,18 @@ public static EaseQuadOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return -pMaxValue * (pSecondsElapsed /= pDuration) * (pSecondsElapsed - 2) + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseQuadOut.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + return -pPercentage * (pPercentage - 2); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseQuartIn.java b/src/org/anddev/andengine/util/modifier/ease/EaseQuartIn.java index 5bb522784..fee684e5a 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseQuartIn.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseQuartIn.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -43,14 +43,18 @@ public static EaseQuartIn getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return pMaxValue * (pSecondsElapsed /= pDuration) * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseQuartIn.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + return pPercentage * pPercentage * pPercentage * pPercentage; + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseQuartInOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseQuartInOut.java index e69cf9591..56b3da028 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseQuartInOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseQuartInOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseQuartInOut implements IEaseFunction { // =========================================================== private EaseQuartInOut() { + } public static EaseQuartInOut getInstance() { @@ -42,11 +43,14 @@ public static EaseQuartInOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - if((pSecondsElapsed /= pDuration * 0.5f) < 1) { - return pMaxValue * 0.5f * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + final float percentage = pSecondsElapsed / pDuration; + + if(percentage < 0.5f) { + return 0.5f * EaseQuartIn.getValue(2 * percentage); + } else { + return 0.5f + 0.5f * EaseQuartOut.getValue(percentage * 2 - 1); } - return -pMaxValue * 0.5f * ((pSecondsElapsed -= 2) * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed - 2) + pMinValue; } // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseQuartOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseQuartOut.java index 6361e903e..ef7160a20 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseQuartOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseQuartOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseQuartOut implements IEaseFunction { // =========================================================== private EaseQuartOut() { + } public static EaseQuartOut getInstance() { @@ -42,14 +43,19 @@ public static EaseQuartOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return -pMaxValue * ((pSecondsElapsed = pSecondsElapsed / pDuration - 1) * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed - 1) + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseQuartOut.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + final float t = pPercentage - 1; + return 1 - (t * t * t * t); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseQuintIn.java b/src/org/anddev/andengine/util/modifier/ease/EaseQuintIn.java index 91d396a8f..aee3872dd 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseQuintIn.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseQuintIn.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseQuintIn implements IEaseFunction { // =========================================================== private EaseQuintIn() { + } public static EaseQuintIn getInstance() { @@ -42,14 +43,18 @@ public static EaseQuintIn getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return pMaxValue * (pSecondsElapsed /= pDuration) * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseQuintIn.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + return pPercentage * pPercentage * pPercentage * pPercentage * pPercentage; + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseQuintInOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseQuintInOut.java index a9c303a08..0e0d666c9 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseQuintInOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseQuintInOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseQuintInOut implements IEaseFunction { // =========================================================== private EaseQuintInOut() { + } public static EaseQuintInOut getInstance() { @@ -42,11 +43,14 @@ public static EaseQuintInOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - if((pSecondsElapsed /= pDuration * 0.5f) < 1) { - return pMaxValue * 0.5f * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + final float percentage = pSecondsElapsed / pDuration; + + if(percentage < 0.5f) { + return 0.5f * EaseQuintIn.getValue(2 * percentage); + } else { + return 0.5f + 0.5f * EaseQuintOut.getValue(percentage * 2 - 1); } - return pMaxValue * 0.5f * ((pSecondsElapsed -= 2) * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed + 2) + pMinValue; } // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseQuintOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseQuintOut.java index 5649b27b0..4646416ea 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseQuintOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseQuintOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseQuintOut implements IEaseFunction { // =========================================================== private EaseQuintOut() { + } public static EaseQuintOut getInstance() { @@ -42,14 +43,19 @@ public static EaseQuintOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return pMaxValue * ((pSecondsElapsed = pSecondsElapsed / pDuration - 1) * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed + 1) + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseQuintOut.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + final float t = pPercentage - 1; + return 1 + (t * t * t * t * t); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseSineIn.java b/src/org/anddev/andengine/util/modifier/ease/EaseSineIn.java index 9903cdf75..07d4fc4b5 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseSineIn.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseSineIn.java @@ -5,9 +5,9 @@ import android.util.FloatMath; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -28,6 +28,7 @@ public class EaseSineIn implements IEaseFunction, MathConstants { // =========================================================== private EaseSineIn() { + } public static EaseSineIn getInstance() { @@ -46,14 +47,18 @@ public static EaseSineIn getInstance() { // =========================================================== @Override - public float getPercentageDone(final float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return (-pMaxValue * FloatMath.cos(pSecondsElapsed / pDuration * PI_HALF) + pMaxValue + pMinValue); + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseSineIn.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + return -FloatMath.cos(pPercentage * PI_HALF) + 1; + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseSineInOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseSineInOut.java index 07cbf51f2..5184e4358 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseSineInOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseSineInOut.java @@ -1,13 +1,12 @@ package org.anddev.andengine.util.modifier.ease; -import org.anddev.andengine.util.constants.MathConstants; - +import static org.anddev.andengine.util.constants.MathConstants.PI; import android.util.FloatMath; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -28,6 +27,7 @@ public class EaseSineInOut implements IEaseFunction { // =========================================================== private EaseSineInOut() { + } public static EaseSineInOut getInstance() { @@ -46,8 +46,10 @@ public static EaseSineInOut getInstance() { // =========================================================== @Override - public float getPercentageDone(final float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return (-pMaxValue * 0.5f * (FloatMath.cos(MathConstants.PI * pSecondsElapsed / pDuration) - 1) + pMinValue); + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + final float percentage = pSecondsElapsed / pDuration; + + return -0.5f * (FloatMath.cos(percentage * PI) - 1); } // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseSineOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseSineOut.java index f57efb11e..4478bc3cb 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseSineOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseSineOut.java @@ -5,9 +5,9 @@ import android.util.FloatMath; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -28,6 +28,7 @@ public class EaseSineOut implements IEaseFunction, MathConstants { // =========================================================== private EaseSineOut() { + } public static EaseSineOut getInstance() { @@ -46,14 +47,18 @@ public static EaseSineOut getInstance() { // =========================================================== @Override - public float getPercentageDone(final float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return (pMaxValue * FloatMath.sin(pSecondsElapsed / pDuration * PI_HALF) + pMinValue); + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseSineOut.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + return FloatMath.sin(pPercentage * PI_HALF); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseStrongIn.java b/src/org/anddev/andengine/util/modifier/ease/EaseStrongIn.java index 0255f2fd3..a379885e1 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseStrongIn.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseStrongIn.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseStrongIn implements IEaseFunction { // =========================================================== private EaseStrongIn() { + } public static EaseStrongIn getInstance() { @@ -42,14 +43,18 @@ public static EaseStrongIn getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return pMaxValue * (pSecondsElapsed /= pDuration) * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseStrongIn.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + return pPercentage * pPercentage * pPercentage * pPercentage * pPercentage; + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseStrongInOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseStrongInOut.java index 6a765ca1a..51e92cdd8 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseStrongInOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseStrongInOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseStrongInOut implements IEaseFunction { // =========================================================== private EaseStrongInOut() { + } public static EaseStrongInOut getInstance() { @@ -42,11 +43,14 @@ public static EaseStrongInOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - if((pSecondsElapsed /= pDuration * 0.5f) < 1) { - return pMaxValue * 0.5f * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + final float percentage = pSecondsElapsed / pDuration; + + if(percentage < 0.5f) { + return 0.5f * EaseStrongIn.getValue(2 * percentage); + } else { + return 0.5f + 0.5f * EaseStrongOut.getValue(percentage * 2 - 1); } - return pMaxValue * 0.5f * ((pSecondsElapsed -= 2) * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed + 2) + pMinValue; } // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/EaseStrongOut.java b/src/org/anddev/andengine/util/modifier/ease/EaseStrongOut.java index acc71da16..d7a9804a4 100644 --- a/src/org/anddev/andengine/util/modifier/ease/EaseStrongOut.java +++ b/src/org/anddev/andengine/util/modifier/ease/EaseStrongOut.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 16:52:11 - 26.07.2010 @@ -24,6 +24,7 @@ public class EaseStrongOut implements IEaseFunction { // =========================================================== private EaseStrongOut() { + } public static EaseStrongOut getInstance() { @@ -42,14 +43,19 @@ public static EaseStrongOut getInstance() { // =========================================================== @Override - public float getPercentageDone(float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue) { - return pMaxValue * ((pSecondsElapsed = pSecondsElapsed / pDuration - 1) * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed * pSecondsElapsed + 1) + pMinValue; + public float getPercentage(final float pSecondsElapsed, final float pDuration) { + return EaseStrongOut.getValue(pSecondsElapsed / pDuration); } // =========================================================== // Methods // =========================================================== + public static float getValue(final float pPercentage) { + final float t = pPercentage - 1; + return 1 + (t * t * t * t * t); + } + // =========================================================== // Inner and Anonymous Classes // =========================================================== diff --git a/src/org/anddev/andengine/util/modifier/ease/IEaseFunction.java b/src/org/anddev/andengine/util/modifier/ease/IEaseFunction.java index 6980e7298..e36efbee7 100644 --- a/src/org/anddev/andengine/util/modifier/ease/IEaseFunction.java +++ b/src/org/anddev/andengine/util/modifier/ease/IEaseFunction.java @@ -1,9 +1,9 @@ package org.anddev.andengine.util.modifier.ease; /** - * (c) 2010 Nicolas Gramlich + * (c) 2010 Nicolas Gramlich * (c) 2011 Zynga Inc. - * + * * @author Gil * @author Nicolas Gramlich * @since 17:13:17 - 26.07.2010 @@ -19,5 +19,5 @@ public interface IEaseFunction { // Methods // =========================================================== - public abstract float getPercentageDone(final float pSecondsElapsed, final float pDuration, final float pMinValue, final float pMaxValue); + public float getPercentage(final float pSecondsElapsed, final float pDuration); }