--- /dev/null
+/*******************************************************************************\r
+ * Copyright 2011 See AUTHORS file.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ ******************************************************************************/\r
+package com.badlogic.gdx.scenes.scene2d.interpolators;\r
+\r
+import com.badlogic.gdx.scenes.scene2d.Interpolator;\r
+import com.badlogic.gdx.utils.Pool;\r
+\r
+/**\r
+ * An interpolator where the rate of change starts out slowly, grows over time and ends slowly.\r
+ * \r
+ * @author Moritz Post <moritzpost@gmail.com>\r
+ */\r
+public class AccelerateDecelerateInterpolator implements Interpolator {\r
+\r
+ private static final float DEFAULT_FACTOR = 1.0f;\r
+\r
+ private static final Pool<AccelerateDecelerateInterpolator> pool = new Pool<AccelerateDecelerateInterpolator>(4, 100) {\r
+ @Override protected AccelerateDecelerateInterpolator newObject () {\r
+ return new AccelerateDecelerateInterpolator();\r
+ }\r
+ };\r
+\r
+ private float factor;\r
+\r
+ private double doubledFactor;\r
+\r
+ AccelerateDecelerateInterpolator () {\r
+ // hide constructor\r
+ }\r
+\r
+ /**\r
+ * Gets a new {@link AccelerateDecelerateInterpolator} from a maintained pool of {@link Interpolator}s.\r
+ * \r
+ * @param factor the factor controlling the rate of speed change\r
+ * @return the obtained {@link AccelerateDecelerateInterpolator}\r
+ */\r
+ public static AccelerateDecelerateInterpolator $ (float factor) {\r
+ AccelerateDecelerateInterpolator inter = pool.obtain();\r
+ inter.factor = factor;\r
+ inter.doubledFactor = factor * 2;\r
+ return inter;\r
+ }\r
+\r
+ /**\r
+ * Gets a new {@link AccelerateDecelerateInterpolator} from a maintained pool of {@link Interpolator}s.\r
+ * <p>\r
+ * The initial factor is set to <code>{@value AccelerateDecelerateInterpolator#DEFAULT_FACTOR}</code>.\r
+ * \r
+ * @return the obtained {@link AccelerateDecelerateInterpolator}\r
+ */\r
+ public static AccelerateDecelerateInterpolator $ () {\r
+ return $(DEFAULT_FACTOR);\r
+ }\r
+\r
+ @Override public void finished () {\r
+ pool.free(this);\r
+ }\r
+\r
+ public float getInterpolation (float input) {\r
+ return (float)(Math.cos((input + 1) * Math.PI) / 2.0f) + 0.5f;\r
+ }\r
+\r
+ @Override public Interpolator copy () {\r
+ return $(factor);\r
+ }\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright 2011 See AUTHORS file.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ ******************************************************************************/\r
+package com.badlogic.gdx.scenes.scene2d.interpolators;\r
+\r
+import com.badlogic.gdx.scenes.scene2d.Interpolator;\r
+import com.badlogic.gdx.utils.Pool;\r
+\r
+/**\r
+ * An interpolator where the change overshoots the target and springs back to the target position. \r
+ * <p>\r
+ * The factor defines the rate of overshoot.\r
+ * \r
+ * @author Moritz Post <moritzpost@gmail.com>\r
+ */\r
+public class OvershootInterpolator implements Interpolator {\r
+\r
+ private static final float DEFAULT_FACTOR = 1.0f;\r
+\r
+ private static final Pool<OvershootInterpolator> pool = new Pool<OvershootInterpolator>(4, 100) {\r
+ @Override protected OvershootInterpolator newObject () {\r
+ return new OvershootInterpolator();\r
+ }\r
+ };\r
+\r
+ private float factor;\r
+\r
+ private double doubledFactor;\r
+\r
+ OvershootInterpolator () {\r
+ // hide constructor\r
+ }\r
+\r
+ /**\r
+ * Gets a new {@link OvershootInterpolator} from a maintained pool of {@link Interpolator}s.\r
+ * \r
+ * @param factor the factor controlling the rate of overshoot energy change\r
+ * @return the obtained {@link OvershootInterpolator}\r
+ */\r
+ public static OvershootInterpolator $ (float factor) {\r
+ OvershootInterpolator inter = pool.obtain();\r
+ inter.factor = factor;\r
+ inter.doubledFactor = factor * 2;\r
+ return inter;\r
+ }\r
+\r
+ /**\r
+ * Gets a new {@link OvershootInterpolator} from a maintained pool of {@link Interpolator}s.\r
+ * <p>\r
+ * The initial factor is set to <code>{@value OvershootInterpolator#DEFAULT_FACTOR}</code>.\r
+ * \r
+ * @return the obtained {@link OvershootInterpolator}\r
+ */\r
+ public static OvershootInterpolator $ () {\r
+ return $(DEFAULT_FACTOR);\r
+ }\r
+\r
+ @Override public void finished () {\r
+ pool.free(this);\r
+ }\r
+\r
+ public float getInterpolation (float t) {\r
+ t -= 1.0f;\r
+ return t * t * ((factor + 1) * t + factor) + 1.0f;\r
+ }\r
+\r
+ @Override public Interpolator copy () {\r
+ return $(factor);\r
+ }\r
+}\r