BCSTM-Player |
This commit is contained in:
525
external/tween-engine/src/BaseTween.cpp
vendored
Normal file
525
external/tween-engine/src/BaseTween.cpp
vendored
Normal file
@ -0,0 +1,525 @@
|
||||
//
|
||||
// BaseTween.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
//#define NDEBUG
|
||||
|
||||
#include <TweenEngine/BaseTween.h>
|
||||
#include <TweenEngine/TweenManager.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
void BaseTween::reset()
|
||||
{
|
||||
step = -2;
|
||||
repeatCnt = 0;
|
||||
isIterationStep = isYoyoFlag = false;
|
||||
|
||||
delayStart = duration = repeatDelay = currentTime = deltaTime = 0;
|
||||
isStartedFlag = isInitializedFlag = isFinishedFlag = isKilledFlag = isPausedFlag = false;
|
||||
|
||||
callback = nullptr;
|
||||
callbackTriggers = TweenCallback::COMPLETE;
|
||||
userData = nullptr;
|
||||
callbacks.clear();
|
||||
|
||||
isAutoRemoveEnabled = isAutoStartEnabled = true;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
/**
|
||||
* Builds and validates the object. Only needed if you want to finalize a
|
||||
* tween or timeline without starting it, since a call to ".start()" also
|
||||
* calls this method.
|
||||
*
|
||||
* @return The current object, for chaining instructions.
|
||||
*/
|
||||
BaseTween &BaseTween::build()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts or restarts the object unmanaged. You will need to take care of
|
||||
* its life-cycle. If you want the tween to be managed for you, use a
|
||||
* {@link TweenManager}.
|
||||
*
|
||||
* @return The current object, for chaining instructions.
|
||||
*/
|
||||
BaseTween &BaseTween::start()
|
||||
{
|
||||
build();
|
||||
currentTime = 0;
|
||||
isStartedFlag = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to add an object to a manager. Its life-cycle will be
|
||||
* handled for you. Relax and enjoy the animation.
|
||||
*
|
||||
* @return The current object, for chaining instructions.
|
||||
*/
|
||||
BaseTween &BaseTween::start(TweenManager &manager) {
|
||||
manager.add(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a delay to the tween or timeline.
|
||||
*
|
||||
* @param delay A duration.
|
||||
* @return The current object, for chaining instructions.
|
||||
*/
|
||||
BaseTween &BaseTween::delay(float delay)
|
||||
{
|
||||
this->delayStart += delay;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kills the tween or timeline. If you are using a TweenManager, this object
|
||||
* will be removed automatically.
|
||||
*/
|
||||
void BaseTween::kill()
|
||||
{
|
||||
isKilledFlag = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops and resets the tween or timeline, and sends it to its pool, for
|
||||
+ * later reuse. Note that if you use a {@link TweenManager}, this method
|
||||
+ * is automatically called once the animation is finished.
|
||||
*/
|
||||
void BaseTween::free()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Pauses the tween or timeline. Further update calls won't have any effect.
|
||||
*/
|
||||
void BaseTween::pause()
|
||||
{
|
||||
isPausedFlag = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resumes the tween or timeline. Has no effect is it was no already paused.
|
||||
*/
|
||||
void BaseTween::resume()
|
||||
{
|
||||
isPausedFlag = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats the tween or timeline for a given number of times.
|
||||
* @param count The number of repetitions. For infinite repetition,
|
||||
* use Tween.INFINITY, or a negative number.
|
||||
*
|
||||
* @param delay A delay between each iteration.
|
||||
* @return The current tween or timeline, for chaining instructions.
|
||||
*/
|
||||
BaseTween &BaseTween::repeat(int count, float delay)
|
||||
{
|
||||
if (isStartedFlag)
|
||||
{
|
||||
//throw new RuntimeException("You can't change the repetitions of a tween or timeline once it is started");
|
||||
}
|
||||
else
|
||||
{
|
||||
repeatCnt = count;
|
||||
repeatDelay = delay >= 0 ? delay : 0;
|
||||
isYoyoFlag = false;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats the tween or timeline for a given number of times.
|
||||
* Every two iterations, it will be played backwards.
|
||||
*
|
||||
* @param count The number of repetitions. For infinite repetition,
|
||||
* use Tween.INFINITY, or '-1'.
|
||||
* @param delay A delay before each repetition.
|
||||
* @return The current tween or timeline, for chaining instructions.
|
||||
*/
|
||||
BaseTween &BaseTween::repeatYoyo(int count, float delay)
|
||||
{
|
||||
if (isStartedFlag)
|
||||
{
|
||||
//throw new RuntimeException("You can't change the repetitions of a tween or timeline once it is started");
|
||||
}
|
||||
else
|
||||
{
|
||||
repeatCnt = count;
|
||||
repeatDelay = delay >= 0 ? delay : 0;
|
||||
isYoyoFlag = true;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the callback. By default, it will be fired at the completion of the
|
||||
* tween or timeline (event COMPLETE). If you want to change this behavior
|
||||
* and add more triggers, use the {@link setCallbackTriggers()} method.
|
||||
*
|
||||
* @see TweenCallback
|
||||
*/
|
||||
BaseTween &BaseTween::setCallback(TweenCallback *callback)
|
||||
{
|
||||
this->callback = callback;
|
||||
return *this;
|
||||
}
|
||||
|
||||
BaseTween &BaseTween::setCallback(int type, const TweenCallbackFunction& callback)
|
||||
{
|
||||
callbacks[type] = callback;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the triggers of the callback. The available triggers, listed as
|
||||
* members of the {@link TweenCallback} interface, are:
|
||||
* <p/>
|
||||
*
|
||||
* <b>BEGIN</b>: right after the delay (if any)<br/>
|
||||
* <b>START</b>: at each iteration beginning<br/>
|
||||
* <b>END</b>: at each iteration ending, before the repeat delay<br/>
|
||||
* <b>COMPLETE</b>: at last END event<br/>
|
||||
* <b>BACK_BEGIN</b>: at the beginning of the first backward iteration<br/>
|
||||
* <b>BACK_START</b>: at each backward iteration beginning, after the repeat delay<br/>
|
||||
* <b>BACK_END</b>: at each backward iteration ending<br/>
|
||||
* <b>BACK_COMPLETE</b>: at last BACK_END event
|
||||
* <p/>
|
||||
*
|
||||
* <pre> {@code
|
||||
* forward : BEGIN COMPLETE
|
||||
* forward : START END START END START END
|
||||
* |--------------[XXXXXXXXXX]------[XXXXXXXXXX]------[XXXXXXXXXX]
|
||||
* backward: bEND bSTART bEND bSTART bEND bSTART
|
||||
* backward: bCOMPLETE bBEGIN
|
||||
* }</pre>
|
||||
*
|
||||
* @param flags one or more triggers, separated by the '|' operator.
|
||||
* @see TweenCallback
|
||||
*/
|
||||
BaseTween &BaseTween::setCallbackTriggers(int flags)
|
||||
{
|
||||
this->callbackTriggers = flags;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches an object to this tween or timeline. It can be useful in order
|
||||
* to retrieve some data from a TweenCallback.
|
||||
*
|
||||
* @param data Any kind of object.
|
||||
* @return The current tween or timeline, for chaining instructions.
|
||||
*/
|
||||
BaseTween &BaseTween::setUserData(void *data)
|
||||
{
|
||||
userData = data;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Getters
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Gets the delay of the tween or timeline. Nothing will happen before
|
||||
* this delay.
|
||||
*/
|
||||
float BaseTween::getDelay() { return delayStart; }
|
||||
|
||||
/**
|
||||
* Gets the duration of a single iteration.
|
||||
*/
|
||||
float BaseTween::getDuration() { return duration; }
|
||||
|
||||
/**
|
||||
* Gets the number of iterations that will be played.
|
||||
*/
|
||||
int BaseTween::getRepeatCount() { return repeatCnt; }
|
||||
|
||||
/**
|
||||
* Gets the delay occuring between two iterations.
|
||||
*/
|
||||
float BaseTween::getRepeatDelay() { return repeatDelay; }
|
||||
|
||||
/**
|
||||
* Returns the complete duration, including initial delay and repetitions.
|
||||
* The formula is as follows:
|
||||
* <pre>
|
||||
* fullDuration = delay + duration + (repeatDelay + duration) * repeatCnt
|
||||
* </pre>
|
||||
*/
|
||||
float BaseTween::getFullDuration()
|
||||
{
|
||||
if (repeatCnt < 0) return -1;
|
||||
return delayStart + duration + (repeatDelay + duration) * repeatCnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attached data, or null if none.
|
||||
*/
|
||||
void *BaseTween::getUserData() { return userData; }
|
||||
|
||||
/**
|
||||
* Gets the id of the current step. Values are as follows:<br/>
|
||||
* <ul>
|
||||
* <li>even numbers mean that an iteration is playing,<br/>
|
||||
* <li>odd numbers mean that we are between two iterations,<br/>
|
||||
* <li>-2 means that the initial delay has not ended,<br/>
|
||||
* <li>-1 means that we are before the first iteration,<br/>
|
||||
* <li>repeatCount*2 + 1 means that we are after the last iteration
|
||||
*/
|
||||
int BaseTween::getStep() { return step; }
|
||||
|
||||
/**
|
||||
* Gets the local time.
|
||||
*/
|
||||
float BaseTween::getCurrentTime() { return currentTime; }
|
||||
|
||||
/**
|
||||
* Returns true if the tween or timeline has been started.
|
||||
*/
|
||||
bool BaseTween::isStarted() { return isStartedFlag; }
|
||||
|
||||
/**
|
||||
* Returns true if the tween or timeline has been initialized. Starting
|
||||
* values for tweens are stored at initialization time. This initialization
|
||||
* takes place right after the initial delay, if any.
|
||||
*/
|
||||
bool BaseTween::isInitialized() { return isInitializedFlag; }
|
||||
|
||||
/**
|
||||
* Returns true if the tween is finished (i.e. if the tween has reached
|
||||
* its end or has been killed). If you don't use a TweenManager, you may
|
||||
* want to call {@link free()} to reuse the object later.
|
||||
*/
|
||||
bool BaseTween::isFinished() { return isFinishedFlag || isKilledFlag; }
|
||||
|
||||
/**
|
||||
* Returns true if the iterations are played as yoyo. Yoyo means that
|
||||
* every two iterations, the animation will be played backwards.
|
||||
*/
|
||||
bool BaseTween::isYoyo() { return isYoyoFlag; }
|
||||
|
||||
/**
|
||||
* Returns true if the tween or timeline is currently paused.
|
||||
*/
|
||||
bool BaseTween::isPaused() { return isPausedFlag; }
|
||||
|
||||
void BaseTween::initializeOverride() {}
|
||||
|
||||
void BaseTween::updateOverride(int step, int lastStep, bool isIterationStep, float delta) {}
|
||||
|
||||
void BaseTween::forceToStart()
|
||||
{
|
||||
currentTime = -delayStart;
|
||||
step = -1;
|
||||
isIterationStep = false;
|
||||
if (isReverse(0)) forceEndValues();
|
||||
else forceStartValues();
|
||||
}
|
||||
|
||||
void BaseTween::forceToEnd(float time)
|
||||
{
|
||||
currentTime = time - getFullDuration();
|
||||
step = repeatCnt*2 + 1;
|
||||
isIterationStep = false;
|
||||
if (isReverse(repeatCnt*2)) forceStartValues();
|
||||
else forceEndValues();
|
||||
}
|
||||
|
||||
void BaseTween::callCallback(int type)
|
||||
{
|
||||
auto callback = callbacks.find(type);
|
||||
if (callback != callbacks.end()) {
|
||||
callback->second(this);
|
||||
}
|
||||
// if (callback != nullptr && (callbackTriggers & type) > 0) callback->onEvent(type, this);
|
||||
}
|
||||
|
||||
bool BaseTween::isReverse(int step)
|
||||
{
|
||||
return isYoyoFlag && abs(step%4) == 2;
|
||||
}
|
||||
|
||||
bool BaseTween::isValid(int step)
|
||||
{
|
||||
return (step >= 0 && step <= repeatCnt*2) || repeatCnt < 0;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Update engine
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Updates the tween or timeline state. <b>You may want to use a
|
||||
* TweenManager to update objects for you.</b>
|
||||
*
|
||||
* Slow motion, fast motion and backward play can be easily achieved by
|
||||
* tweaking this delta time. Multiply it by -1 to play the animation
|
||||
* backward, or by 0.5 to play it twice slower than its normal speed.
|
||||
*
|
||||
* @param delta A delta time between now and the last call.
|
||||
*/
|
||||
void BaseTween::update(float delta)
|
||||
{
|
||||
if (!isStartedFlag || isPausedFlag || isKilledFlag) return;
|
||||
|
||||
deltaTime = delta;
|
||||
|
||||
if (!isInitializedFlag) initialize();
|
||||
|
||||
if (isInitializedFlag)
|
||||
{
|
||||
testRelaunch();
|
||||
updateStep();
|
||||
testCompletion();
|
||||
}
|
||||
|
||||
currentTime += deltaTime;
|
||||
deltaTime = 0;
|
||||
}
|
||||
|
||||
void BaseTween::initialize() {
|
||||
if (currentTime+deltaTime >= delayStart)
|
||||
{
|
||||
initializeOverride();
|
||||
isInitializedFlag = true;
|
||||
isIterationStep = true;
|
||||
step = 0;
|
||||
deltaTime -= delayStart-currentTime;
|
||||
currentTime = 0;
|
||||
callCallback(TweenCallback::BEGIN);
|
||||
callCallback(TweenCallback::START);
|
||||
}
|
||||
}
|
||||
|
||||
void BaseTween::testRelaunch()
|
||||
{
|
||||
if (!isIterationStep && repeatCnt >= 0 && step < 0 && currentTime+deltaTime >= 0)
|
||||
{
|
||||
// assert(step == -1);
|
||||
isIterationStep = true;
|
||||
step = 0;
|
||||
float delta = 0-currentTime;
|
||||
deltaTime -= delta;
|
||||
currentTime = 0;
|
||||
callCallback(TweenCallback::BEGIN);
|
||||
callCallback(TweenCallback::START);
|
||||
updateOverride(step, step-1, isIterationStep, delta);
|
||||
|
||||
}
|
||||
else if (!isIterationStep && repeatCnt >= 0 && step > repeatCnt*2 && currentTime+deltaTime < 0)
|
||||
{
|
||||
// assert(step == repeatCnt*2 + 1);
|
||||
isIterationStep = true;
|
||||
step = repeatCnt*2;
|
||||
float delta = 0-currentTime;
|
||||
deltaTime -= delta;
|
||||
currentTime = duration;
|
||||
callCallback(TweenCallback::BACK_BEGIN);
|
||||
callCallback(TweenCallback::BACK_START);
|
||||
updateOverride(step, step+1, isIterationStep, delta);
|
||||
}
|
||||
}
|
||||
|
||||
void BaseTween::updateStep()
|
||||
{
|
||||
while (isValid(step))
|
||||
{
|
||||
if (!isIterationStep && currentTime+deltaTime <= 0)
|
||||
{
|
||||
isIterationStep = true;
|
||||
step -= 1;
|
||||
|
||||
float delta = 0-currentTime;
|
||||
deltaTime -= delta;
|
||||
currentTime = duration;
|
||||
|
||||
if (isReverse(step)) forceStartValues();
|
||||
else forceEndValues();
|
||||
callCallback(TweenCallback::BACK_START);
|
||||
updateOverride(step, step+1, isIterationStep, delta);
|
||||
|
||||
}
|
||||
else if (!isIterationStep && currentTime+deltaTime >= repeatDelay)
|
||||
{
|
||||
isIterationStep = true;
|
||||
step += 1;
|
||||
|
||||
float delta = repeatDelay-currentTime;
|
||||
deltaTime -= delta;
|
||||
currentTime = 0;
|
||||
|
||||
if (isReverse(step)) forceEndValues(); else forceStartValues();
|
||||
callCallback(TweenCallback::START);
|
||||
updateOverride(step, step-1, isIterationStep, delta);
|
||||
|
||||
}
|
||||
else if (isIterationStep && currentTime+deltaTime < 0)
|
||||
{
|
||||
isIterationStep = false;
|
||||
step -= 1;
|
||||
|
||||
float delta = 0-currentTime;
|
||||
deltaTime -= delta;
|
||||
currentTime = 0;
|
||||
|
||||
updateOverride(step, step+1, isIterationStep, delta);
|
||||
callCallback(TweenCallback::BACK_END);
|
||||
|
||||
if (step < 0 && repeatCnt >= 0) callCallback(TweenCallback::BACK_COMPLETE);
|
||||
else currentTime = repeatDelay;
|
||||
|
||||
}
|
||||
else if (isIterationStep && currentTime+deltaTime > duration)
|
||||
{
|
||||
isIterationStep = false;
|
||||
step += 1;
|
||||
|
||||
float delta = duration-currentTime;
|
||||
deltaTime -= delta;
|
||||
currentTime = duration;
|
||||
|
||||
updateOverride(step, step-1, isIterationStep, delta);
|
||||
callCallback(TweenCallback::END);
|
||||
|
||||
if (step > repeatCnt*2 && repeatCnt >= 0) callCallback(TweenCallback::COMPLETE);
|
||||
currentTime = 0;
|
||||
|
||||
}
|
||||
else if (isIterationStep)
|
||||
{
|
||||
float delta = deltaTime;
|
||||
deltaTime -= delta;
|
||||
currentTime += delta;
|
||||
updateOverride(step, step, isIterationStep, delta);
|
||||
break;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
float delta = deltaTime;
|
||||
deltaTime -= delta;
|
||||
currentTime += delta;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BaseTween::testCompletion()
|
||||
{
|
||||
isFinishedFlag = repeatCnt >= 0 && (step > repeatCnt*2 || step < 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
796
external/tween-engine/src/Tween.cpp
vendored
Normal file
796
external/tween-engine/src/Tween.cpp
vendored
Normal file
@ -0,0 +1,796 @@
|
||||
//
|
||||
// Tween.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
/**
|
||||
* Core class of the Tween Engine. A Tween is basically an interpolation
|
||||
* between two values of an object attribute. However, the main interest of a
|
||||
* Tween is that you can apply an easing formula on this interpolation, in
|
||||
* order to smooth the transitions or to achieve cool effects like springs or
|
||||
* bounces.
|
||||
* <p/>
|
||||
*
|
||||
* The Universal Tween Engine is called "universal" because it is able to apply
|
||||
* interpolations on every attribute from every possible object. Therefore,
|
||||
* every object in your application can be animated with cool effects: it does
|
||||
* not matter if your application is a game, a desktop interface or even a
|
||||
* console program! If it makes sense to animate something, then it can be
|
||||
* animated through this engine.
|
||||
* <p/>
|
||||
*
|
||||
* This class contains many static factory methods to create and instantiate
|
||||
* new interpolations easily. The common way to create a Tween is by using one
|
||||
* of these factories:
|
||||
* <p/>
|
||||
*
|
||||
* - Tween.to(...)<br/>
|
||||
* - Tween.from(...)<br/>
|
||||
* - Tween.set(...)<br/>
|
||||
* - Tween.call(...)
|
||||
* <p/>
|
||||
*
|
||||
* <h2>Example - firing a Tween</h2>
|
||||
*
|
||||
* The following example will move the target horizontal position from its
|
||||
* current value to x=200 and y=300, during 500ms, but only after a delay of
|
||||
* 1000ms. The animation will also be repeated 2 times (the starting position
|
||||
* is registered at the end of the delay, so the animation will automatically
|
||||
* restart from this registered position).
|
||||
* <p/>
|
||||
*
|
||||
* <pre> {@code
|
||||
* Tween.to(myObject, POSITION_XY, 0.5f)
|
||||
* .target(200, 300)
|
||||
* .ease(Quad.INOUT)
|
||||
* .delay(1.0f)
|
||||
* .repeat(2, 0.2f)
|
||||
* .start(myManager);
|
||||
* }</pre>
|
||||
*
|
||||
* Tween life-cycles can be automatically managed for you, thanks to the
|
||||
* {@link TweenManager} class. If you choose to manage your tween when you start
|
||||
* it, then you don't need to care about it anymore. <b>Tweens are
|
||||
* <i>fire-and-forget</i>: don't think about them anymore once you started
|
||||
* them (if they are managed of course).</b>
|
||||
* <p/>
|
||||
*
|
||||
* You need to periodicaly update the tween engine, in order to compute the new
|
||||
* values. If your tweens are managed, only update the manager; else you need
|
||||
* to call {@link #update()} on your tweens periodically.
|
||||
* <p/>
|
||||
*
|
||||
* <h2>Example - setting up the engine</h2>
|
||||
*
|
||||
* The engine cannot directly change your objects attributes, since it doesn't
|
||||
* know them. Therefore, you need to tell him how to get and set the different
|
||||
* attributes of your objects: <b>you need to implement the {@link
|
||||
* TweenAccessor} interface for each object class you will animate</b>. Once
|
||||
* done, don't forget to register these implementations, using the static method
|
||||
* {@link registerAccessor()}, when you start your application.
|
||||
*
|
||||
* @see TweenAccessor
|
||||
* @see TweenManager
|
||||
* @see TweenEquation
|
||||
* @see Timeline
|
||||
* @author Aurelien Ribon | http://www.aurelienribon.com/
|
||||
*/
|
||||
|
||||
//#define NDEBUG
|
||||
|
||||
#include <TweenEngine/Tween.h>
|
||||
#include <TweenEngine/TweenPool.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
int Tween::combinedAttrsLimit = 3;
|
||||
int Tween::waypointsLimit = 0;
|
||||
|
||||
/**
|
||||
* Changes the limit for combined attributes. Defaults to 3 to reduce
|
||||
* memory footprint.
|
||||
*/
|
||||
void Tween::setCombinedAttributesLimit(int limit) { Tween::combinedAttrsLimit = limit; }
|
||||
|
||||
/**
|
||||
* Changes the limit of allowed waypoints for each tween. Defaults to 0 to
|
||||
* reduce memory footprint.
|
||||
*/
|
||||
void Tween::setWaypointsLimit(int limit) { Tween::waypointsLimit = limit; }
|
||||
|
||||
/**
|
||||
* Gets the version number of the library.
|
||||
*/
|
||||
const char *Tween::getVersion() { return "6.3.3"; }
|
||||
|
||||
/**
|
||||
* Used for debug purpose. Gets the current number of objects that are
|
||||
* waiting in the Tween pool.
|
||||
*/
|
||||
int Tween::getPoolSize() { return pool.size(); }
|
||||
|
||||
/**
|
||||
* Increases the minimum capacity of the pool. Capacity defaults to 20.
|
||||
*/
|
||||
void Tween::ensurePoolCapacity(int minCapacity) { pool.ensureCapacity(minCapacity); }
|
||||
|
||||
TweenPool &Tween::pool = *(new TweenPool());
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Static -- factories
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Factory creating a new standard interpolation. This is the most common
|
||||
* type of interpolation. The starting values are retrieved automatically
|
||||
* after the delay (if any).
|
||||
* <br/><br/>
|
||||
*
|
||||
* <b>You need to set the target values of the interpolation by using one
|
||||
* of the target() methods</b>. The interpolation will run from the
|
||||
* starting values to these target values.
|
||||
* <br/><br/>
|
||||
*
|
||||
* The common use of Tweens is "fire-and-forget": you do not need to care
|
||||
* for tweens once you added them to a TweenManager, they will be updated
|
||||
* automatically, and cleaned once finished. Common call:
|
||||
* <br/><br/>
|
||||
*
|
||||
* <pre> {@code
|
||||
* Tween.to(myObject, POSITION, 1.0f)
|
||||
* .target(50, 70)
|
||||
* .ease(Quad.INOUT)
|
||||
* .start(myManager);
|
||||
* }</pre>
|
||||
*
|
||||
* Several options such as delay, repetitions and callbacks can be added to
|
||||
* the tween.
|
||||
*
|
||||
* @param target The target object of the interpolation.
|
||||
* @param tweenType The desired type of interpolation.
|
||||
* @param duration The duration of the interpolation, in milliseconds.
|
||||
* @return The generated Tween.
|
||||
*/
|
||||
Tween &Tween::to(Tweenable& target, int tweenType, float duration)
|
||||
{
|
||||
Tween &tween = *(pool.get());
|
||||
tween.setup(&target, tweenType, duration);
|
||||
tween.ease(TweenEquations::easeInOutQuad);
|
||||
tween.path(TweenPaths::catmullRom);
|
||||
return tween;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory creating a new reversed interpolation. The ending values are
|
||||
* retrieved automatically after the delay (if any).
|
||||
* <br/><br/>
|
||||
*
|
||||
* <b>You need to set the starting values of the interpolation by using one
|
||||
* of the target() methods</b>. The interpolation will run from the
|
||||
* starting values to these target values.
|
||||
* <br/><br/>
|
||||
*
|
||||
* The common use of Tweens is "fire-and-forget": you do not need to care
|
||||
* for tweens once you added them to a TweenManager, they will be updated
|
||||
* automatically, and cleaned once finished. Common call:
|
||||
* <br/><br/>
|
||||
*
|
||||
* <pre> {@code
|
||||
* Tween.from(myObject, POSITION, 1.0f)
|
||||
* .target(0, 0)
|
||||
* .ease(Quad.INOUT)
|
||||
* .start(myManager);
|
||||
* }</pre>
|
||||
*
|
||||
* Several options such as delay, repetitions and callbacks can be added to
|
||||
* the tween.
|
||||
*
|
||||
* @param target The target object of the interpolation.
|
||||
* @param tweenType The desired type of interpolation.
|
||||
* @param duration The duration of the interpolation, in milliseconds.
|
||||
* @return The generated Tween.
|
||||
*/
|
||||
Tween &Tween::from(Tweenable& target, int tweenType, float duration)
|
||||
{
|
||||
Tween &tween = *(pool.get());
|
||||
tween.setup(&target, tweenType, duration);
|
||||
tween.ease(TweenEquations::easeInOutQuad);
|
||||
tween.path(TweenPaths::catmullRom);
|
||||
tween.isFrom = true;
|
||||
return tween;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory creating a new instantaneous interpolation (thus this is not
|
||||
* really an interpolation).
|
||||
* <br/><br/>
|
||||
*
|
||||
* <b>You need to set the target values of the interpolation by using one
|
||||
* of the target() methods</b>. The interpolation will set the target
|
||||
* attribute to these values after the delay (if any).
|
||||
* <br/><br/>
|
||||
*
|
||||
* The common use of Tweens is "fire-and-forget": you do not need to care
|
||||
* for tweens once you added them to a TweenManager, they will be updated
|
||||
* automatically, and cleaned once finished. Common call:
|
||||
* <br/><br/>
|
||||
*
|
||||
* <pre> {@code
|
||||
* Tween.set(myObject, POSITION)
|
||||
* .target(50, 70)
|
||||
* .delay(1.0f)
|
||||
* .start(myManager);
|
||||
* }</pre>
|
||||
*
|
||||
* Several options such as delay, repetitions and callbacks can be added to
|
||||
* the tween.
|
||||
*
|
||||
* @param target The target object of the interpolation.
|
||||
* @param tweenType The desired type of interpolation.
|
||||
* @return The generated Tween.
|
||||
*/
|
||||
Tween &Tween::set(Tweenable& target, int tweenType)
|
||||
{
|
||||
Tween &tween = *(pool.get());
|
||||
tween.setup(&target, tweenType, 0);
|
||||
tween.ease(TweenEquations::easeInOutQuad);
|
||||
return tween;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory creating a new timer. The given callback will be triggered on
|
||||
* each iteration start, after the delay.
|
||||
* <br/><br/>
|
||||
*
|
||||
* The common use of Tweens is "fire-and-forget": you do not need to care
|
||||
* for tweens once you added them to a TweenManager, they will be updated
|
||||
* automatically, and cleaned once finished. Common call:
|
||||
* <br/><br/>
|
||||
*
|
||||
* <pre> {@code
|
||||
* Tween.call(myCallback)
|
||||
* .delay(1.0f)
|
||||
* .repeat(10, 1000)
|
||||
* .start(myManager);
|
||||
* }</pre>
|
||||
*
|
||||
* @param callback The callback that will be triggered on each iteration
|
||||
* start.
|
||||
* @return The generated Tween.
|
||||
* @see TweenCallback
|
||||
*/
|
||||
Tween &Tween::call(TweenCallback &callback)
|
||||
{
|
||||
Tween &tween = *(pool.get());
|
||||
tween.setup(nullptr, -1, 0);
|
||||
tween.setCallback(&callback);
|
||||
tween.setCallbackTriggers(TweenCallback::START);
|
||||
return tween;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to create an empty tween. Such object is only useful
|
||||
* when placed inside animation sequences (see {@link Timeline}), in which
|
||||
* it may act as a beacon, so you can set a callback on it in order to
|
||||
* trigger some action at the right moment.
|
||||
*
|
||||
* @return The generated Tween.
|
||||
* @see Timeline
|
||||
*/
|
||||
Tween &Tween::mark()
|
||||
{
|
||||
Tween &tween = *(pool.get());
|
||||
tween.setup(nullptr, -1, 0);
|
||||
return tween;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Setup
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Tween::Tween()
|
||||
{
|
||||
startValues = new float[combinedAttrsLimit];
|
||||
targetValues = new float[combinedAttrsLimit];
|
||||
waypoints = new float[waypointsLimit*combinedAttrsLimit];
|
||||
accessorBuffer = new float[combinedAttrsLimit];
|
||||
accessorBufferSize = combinedAttrsLimit;
|
||||
pathBuffer = new float[(2+waypointsLimit)*combinedAttrsLimit];
|
||||
pathBufferSize = (2+waypointsLimit)*combinedAttrsLimit;
|
||||
targetObj = nullptr;
|
||||
}
|
||||
|
||||
Tween::~Tween()
|
||||
{
|
||||
delete startValues;
|
||||
delete targetValues;
|
||||
delete waypoints;
|
||||
delete accessorBuffer;
|
||||
delete pathBuffer;
|
||||
// if (accessor != nullptr) Block_release(accessor);
|
||||
}
|
||||
|
||||
void Tween::reset()
|
||||
{
|
||||
BaseTween::reset();
|
||||
|
||||
equation = nullptr;
|
||||
pathAlgorithm = nullptr;
|
||||
isFrom = isRelative = false;
|
||||
combinedAttrsCnt = waypointsCnt = 0;
|
||||
|
||||
if (accessorBufferSize != combinedAttrsLimit) {
|
||||
accessorBuffer = new float[combinedAttrsLimit];
|
||||
}
|
||||
|
||||
if (pathBufferSize != (2+waypointsLimit)*combinedAttrsLimit) {
|
||||
pathBuffer = new float[(2+waypointsLimit)*combinedAttrsLimit];
|
||||
}
|
||||
|
||||
// if (accessor != nullptr)
|
||||
// {
|
||||
// Block_release(accessor);
|
||||
targetObj = nullptr;
|
||||
// }
|
||||
type = -1;
|
||||
}
|
||||
|
||||
void Tween::setup(Tweenable *target, int tweenType, float duration)
|
||||
{
|
||||
// assert(duration >= 0);
|
||||
this->targetObj = target;
|
||||
this->type = tweenType;
|
||||
this->duration = duration;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Public API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Sets the easing equation of the tween. Existing equations are located in
|
||||
* <i>aurelienribon.tweenengine.equations</i> package, but you can of course
|
||||
* implement your owns, see {@link TweenEquation}. You can also use the
|
||||
* {@link TweenEquations} static instances to quickly access all the
|
||||
* equations. Default equation is Quad.INOUT.
|
||||
* <p/>
|
||||
*
|
||||
* <b>Proposed equations are:</b><br/>
|
||||
* - Linear.INOUT,<br/>
|
||||
* - Quad.IN | OUT | INOUT,<br/>
|
||||
* - Cubic.IN | OUT | INOUT,<br/>
|
||||
* - Quart.IN | OUT | INOUT,<br/>
|
||||
* - Quint.IN | OUT | INOUT,<br/>
|
||||
* - Circ.IN | OUT | INOUT,<br/>
|
||||
* - Sine.IN | OUT | INOUT,<br/>
|
||||
* - Expo.IN | OUT | INOUT,<br/>
|
||||
* - Back.IN | OUT | INOUT,<br/>
|
||||
* - Bounce.IN | OUT | INOUT,<br/>
|
||||
* - Elastic.IN | OUT | INOUT
|
||||
*
|
||||
* @return The current tween, for chaining instructions.
|
||||
* @see TweenEquation
|
||||
* @see TweenEquations
|
||||
*/
|
||||
Tween &Tween::ease(TweenEquation &easeEquation)
|
||||
{
|
||||
this->equation = &easeEquation;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target value of the interpolation. The interpolation will run
|
||||
* from the <b>value at start time (after the delay, if any)</b> to this
|
||||
* target value.
|
||||
* <p/>
|
||||
*
|
||||
* To sum-up:<br/>
|
||||
* - start value: value at start time, after delay<br/>
|
||||
* - end value: param
|
||||
*
|
||||
* @param targetValue The target value of the interpolation.
|
||||
* @return The current tween, for chaining instructions.
|
||||
*/
|
||||
Tween &Tween::target(float targetValue)
|
||||
{
|
||||
targetValues[0] = targetValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target values of the interpolation. The interpolation will run
|
||||
* from the <b>values at start time (after the delay, if any)</b> to these
|
||||
* target values.
|
||||
* <p/>
|
||||
*
|
||||
* To sum-up:<br/>
|
||||
* - start values: values at start time, after delay<br/>
|
||||
* - end values: params
|
||||
*
|
||||
* @param targetValue1 The 1st target value of the interpolation.
|
||||
* @param targetValue2 The 2nd target value of the interpolation.
|
||||
* @return The current tween, for chaining instructions.
|
||||
*/
|
||||
Tween &Tween::target(float targetValue1, float targetValue2)
|
||||
{
|
||||
targetValues[0] = targetValue1;
|
||||
targetValues[1] = targetValue2;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target values of the interpolation. The interpolation will run
|
||||
* from the <b>values at start time (after the delay, if any)</b> to these
|
||||
* target values.
|
||||
* <p/>
|
||||
*
|
||||
* To sum-up:<br/>
|
||||
* - start values: values at start time, after delay<br/>
|
||||
* - end values: params
|
||||
*
|
||||
* @param targetValue1 The 1st target value of the interpolation.
|
||||
* @param targetValue2 The 2nd target value of the interpolation.
|
||||
* @param targetValue3 The 3rd target value of the interpolation.
|
||||
* @return The current tween, for chaining instructions.
|
||||
*/
|
||||
Tween &Tween::target(float targetValue1, float targetValue2, float targetValue3)
|
||||
{
|
||||
targetValues[0] = targetValue1;
|
||||
targetValues[1] = targetValue2;
|
||||
targetValues[2] = targetValue3;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Tween &Tween::target(float *targetValues, int len)
|
||||
{
|
||||
if (len <= combinedAttrsLimit)
|
||||
{
|
||||
for (int i=0; i<len; i++)
|
||||
this->targetValues[i] = targetValues[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target value of the interpolation, relatively to the <b>value
|
||||
* at start time (after the delay, if any)</b>.
|
||||
* <p/>
|
||||
*
|
||||
* To sum-up:<br/>
|
||||
* - start value: value at start time, after delay<br/>
|
||||
* - end value: param + value at start time, after delay
|
||||
*
|
||||
* @param targetValue The relative target value of the interpolation.
|
||||
* @return The current tween, for chaining instructions.
|
||||
*/
|
||||
Tween &Tween::targetRelative(float targetValue)
|
||||
{
|
||||
isRelative = true;
|
||||
targetValues[0] = isInitialized() ? targetValue + startValues[0] : targetValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target values of the interpolation, relatively to the <b>values
|
||||
* at start time (after the delay, if any)</b>.
|
||||
* <p/>
|
||||
*
|
||||
* To sum-up:<br/>
|
||||
* - start values: values at start time, after delay<br/>
|
||||
* - end values: params + values at start time, after delay
|
||||
*
|
||||
* @param targetValue1 The 1st relative target value of the interpolation.
|
||||
* @param targetValue2 The 2nd relative target value of the interpolation.
|
||||
* @return The current tween, for chaining instructions.
|
||||
*/
|
||||
Tween &Tween::targetRelative(float targetValue1, float targetValue2)
|
||||
{
|
||||
isRelative = true;
|
||||
targetValues[0] = isInitialized() ? targetValue1 + startValues[0] : targetValue1;
|
||||
targetValues[1] = isInitialized() ? targetValue2 + startValues[1] : targetValue2;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target values of the interpolation, relatively to the <b>values
|
||||
* at start time (after the delay, if any)</b>.
|
||||
* <p/>
|
||||
*
|
||||
* To sum-up:<br/>
|
||||
* - start values: values at start time, after delay<br/>
|
||||
* - end values: params + values at start time, after delay
|
||||
*
|
||||
* @param targetValue1 The 1st relative target value of the interpolation.
|
||||
* @param targetValue2 The 2nd relative target value of the interpolation.
|
||||
* @param targetValue3 The 3rd relative target value of the interpolation.
|
||||
* @return The current tween, for chaining instructions.
|
||||
*/
|
||||
Tween &Tween::targetRelative(float targetValue1, float targetValue2, float targetValue3)
|
||||
{
|
||||
isRelative = true;
|
||||
targetValues[0] = isInitialized() ? targetValue1 + startValues[0] : targetValue1;
|
||||
targetValues[1] = isInitialized() ? targetValue2 + startValues[1] : targetValue2;
|
||||
targetValues[2] = isInitialized() ? targetValue3 + startValues[2] : targetValue3;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the target values of the interpolation, relatively to the <b>values
|
||||
* at start time (after the delay, if any)</b>.
|
||||
* <p/>
|
||||
*
|
||||
* To sum-up:<br/>
|
||||
* - start values: values at start time, after delay<br/>
|
||||
* - end values: params + values at start time, after delay
|
||||
*
|
||||
* @param targetValues The relative target values of the interpolation.
|
||||
* @return The current tween, for chaining instructions.
|
||||
*/
|
||||
Tween &Tween::targetRelative(float *targetValues, int len)
|
||||
{
|
||||
if (len <= combinedAttrsLimit)
|
||||
{
|
||||
for (int i=0; i<len; i++)
|
||||
this->targetValues[i] = isInitialized() ? targetValues[i] + startValues[i] : targetValues[i];
|
||||
}
|
||||
|
||||
isRelative = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a waypoint to the path. The default path runs from the start values
|
||||
* to the end values linearly. If you add waypoints, the default path will
|
||||
* use a smooth catmull-rom spline to navigate between the waypoints, but
|
||||
* you can change this behavior by using the {@link #path(TweenPath)}
|
||||
* method.
|
||||
* <p/>
|
||||
* Note that if you want waypoints relative to the start values, use one of
|
||||
* the .targetRelative() methods to define your target.
|
||||
*
|
||||
* @param targetValue The target of this waypoint.
|
||||
* @return The current tween, for chaining instructions.
|
||||
*/
|
||||
Tween &Tween::waypoint(float targetValue)
|
||||
{
|
||||
if (waypointsCnt < waypointsLimit)
|
||||
{
|
||||
waypoints[waypointsCnt] = targetValue;
|
||||
waypointsCnt += 1;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a waypoint to the path. The default path runs from the start values
|
||||
* to the end values linearly. If you add waypoints, the default path will
|
||||
* use a smooth catmull-rom spline to navigate between the waypoints, but
|
||||
* you can change this behavior by using the {@link #path(TweenPath)}
|
||||
* method.
|
||||
* <p/>
|
||||
* Note that if you want waypoints relative to the start values, use one of
|
||||
* the .targetRelative() methods to define your target.
|
||||
*
|
||||
* @param targetValue1 The 1st target of this waypoint.
|
||||
* @param targetValue2 The 2nd target of this waypoint.
|
||||
* @return The current tween, for chaining instructions.
|
||||
*/
|
||||
Tween &Tween::waypoint(float targetValue1, float targetValue2)
|
||||
{
|
||||
if (waypointsCnt < waypointsLimit)
|
||||
{
|
||||
waypoints[waypointsCnt*2] = targetValue1;
|
||||
waypoints[waypointsCnt*2+1] = targetValue2;
|
||||
waypointsCnt += 1;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a waypoint to the path. The default path runs from the start values
|
||||
* to the end values linearly. If you add waypoints, the default path will
|
||||
* use a smooth catmull-rom spline to navigate between the waypoints, but
|
||||
* you can change this behavior by using the {@link #path(TweenPath)}
|
||||
* method.
|
||||
* <p/>
|
||||
* Note that if you want waypoints relative to the start values, use one of
|
||||
* the .targetRelative() methods to define your target.
|
||||
*
|
||||
* @param targetValue1 The 1st target of this waypoint.
|
||||
* @param targetValue2 The 2nd target of this waypoint.
|
||||
* @param targetValue3 The 3rd target of this waypoint.
|
||||
* @return The current tween, for chaining instructions.
|
||||
*/
|
||||
Tween &Tween::waypoint(float targetValue1, float targetValue2, float targetValue3)
|
||||
{
|
||||
if (waypointsCnt < waypointsLimit)
|
||||
{
|
||||
waypoints[waypointsCnt*3] = targetValue1;
|
||||
waypoints[waypointsCnt*3+1] = targetValue2;
|
||||
waypoints[waypointsCnt*3+2] = targetValue3;
|
||||
waypointsCnt += 1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a waypoint to the path. The default path runs from the start values
|
||||
* to the end values linearly. If you add waypoints, the default path will
|
||||
* use a smooth catmull-rom spline to navigate between the waypoints, but
|
||||
* you can change this behavior by using the {@link #path(TweenPath)}
|
||||
* method.
|
||||
* <p/>
|
||||
* Note that if you want waypoints relative to the start values, use one of
|
||||
* the .targetRelative() methods to define your target.
|
||||
*
|
||||
* @param targetValues The targets of this waypoint.
|
||||
* @return The current tween, for chaining instructions.
|
||||
*/
|
||||
Tween &Tween::waypoint(float *targetValues, int len)
|
||||
{
|
||||
if (waypointsCnt < waypointsLimit)
|
||||
{
|
||||
for (int i=0; i<len; i++)
|
||||
this->waypoints[waypointsCnt*len+i] = targetValues[i];
|
||||
waypointsCnt += 1;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the algorithm that will be used to navigate through the waypoints,
|
||||
* from the start values to the end values. Default is a catmull-rom spline,
|
||||
* but you can find other paths in the {@link TweenPaths} class.
|
||||
*
|
||||
* @param path A TweenPath implementation.
|
||||
* @return The current tween, for chaining instructions.
|
||||
* @see TweenPath
|
||||
* @see TweenPaths
|
||||
*/
|
||||
Tween &Tween::path(TweenPath &path)
|
||||
{
|
||||
this->pathAlgorithm = &path;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Getters
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Gets the easing equation.
|
||||
*/
|
||||
TweenEquation *Tween::getEasing() { return equation; }
|
||||
|
||||
/**
|
||||
* Gets the target values. The returned buffer is as long as the maximum
|
||||
* allowed combined values. Therefore, you're surely not interested in all
|
||||
* its content. Use {@link #getCombinedTweenCount()} to get the number of
|
||||
* interesting slots.
|
||||
*/
|
||||
float *Tween::getTargetValues() { return targetValues; }
|
||||
|
||||
/**
|
||||
* Gets the number of combined animations.
|
||||
*/
|
||||
int Tween::getCombinedAttributesCount() { return combinedAttrsCnt; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Base Class
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Tween &Tween::build()
|
||||
{
|
||||
if (targetObj != nullptr) {
|
||||
combinedAttrsCnt = targetObj->getValues(type, accessorBuffer);
|
||||
}
|
||||
// assert(combinedAttrsCnt <= combinedAttrsLimit);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Tween::free() { pool.free(this); }
|
||||
|
||||
void Tween::initializeOverride()
|
||||
{
|
||||
targetObj->getValues(type, startValues);
|
||||
|
||||
for (int i=0; i<combinedAttrsCnt; i++) {
|
||||
targetValues[i] += isRelative ? startValues[i] : 0;
|
||||
|
||||
for (int ii=0; ii<waypointsCnt; ii++) {
|
||||
waypoints[ii*combinedAttrsCnt+i] += isRelative ? startValues[i] : 0;
|
||||
}
|
||||
|
||||
if (isFrom) {
|
||||
float tmp = startValues[i];
|
||||
startValues[i] = targetValues[i];
|
||||
targetValues[i] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Tween::updateOverride(int step, int lastStep, bool isIterationStep, float delta)
|
||||
{
|
||||
if (equation == nullptr) return;
|
||||
|
||||
// Case iteration end has been reached
|
||||
|
||||
if (!isIterationStep && step > lastStep)
|
||||
{
|
||||
targetObj->setValues(type, isReverse(lastStep) ? startValues : targetValues);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isIterationStep && step < lastStep)
|
||||
{
|
||||
targetObj->setValues(type, isReverse(lastStep) ? targetValues : startValues);
|
||||
return;
|
||||
}
|
||||
|
||||
// Validation
|
||||
|
||||
// assert(isIterationStep);
|
||||
// assert(getCurrentTime() >= 0);
|
||||
// assert(getCurrentTime() <= duration);
|
||||
|
||||
// Case duration equals zero
|
||||
|
||||
if (duration < 0.00000000001f && delta > -0.00000000001f)
|
||||
{
|
||||
targetObj->setValues(type, isReverse(step) ? targetValues : startValues);
|
||||
return;
|
||||
}
|
||||
|
||||
if (duration < 0.00000000001f && delta < 0.00000000001f) {
|
||||
targetObj->setValues(type, isReverse(step) ? startValues : targetValues);
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal behavior
|
||||
|
||||
float time = isReverse(step) ? duration - getCurrentTime() : getCurrentTime();
|
||||
float t = equation->compute(time/duration);
|
||||
|
||||
if (waypointsCnt == 0 || pathAlgorithm == nullptr)
|
||||
{
|
||||
for (int i=0; i<combinedAttrsCnt; i++)
|
||||
{
|
||||
accessorBuffer[i] = startValues[i] + t * (targetValues[i] - startValues[i]);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=0; i<combinedAttrsCnt; i++)
|
||||
{
|
||||
pathBuffer[0] = startValues[i];
|
||||
pathBuffer[1+waypointsCnt] = targetValues[i];
|
||||
for (int ii=0; ii<waypointsCnt; ii++)
|
||||
{
|
||||
pathBuffer[ii+1] = waypoints[ii*combinedAttrsCnt+i];
|
||||
}
|
||||
|
||||
accessorBuffer[i] = pathAlgorithm->compute(t, pathBuffer, waypointsCnt+2);
|
||||
}
|
||||
}
|
||||
|
||||
targetObj->setValues(type, accessorBuffer);
|
||||
}
|
||||
|
||||
void Tween::forceStartValues(){
|
||||
targetObj->setValues(type, startValues);
|
||||
}
|
||||
|
||||
void Tween::forceEndValues(){
|
||||
targetObj->setValues(type, targetValues);
|
||||
}
|
||||
|
||||
int Tween::getTweenCount() { return 1; }
|
||||
|
||||
int Tween::getTimelineCount() { return 0; }
|
||||
|
||||
}
|
53
external/tween-engine/src/TweenEquations.cpp
vendored
Normal file
53
external/tween-engine/src/TweenEquations.cpp
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
//
|
||||
// Equations.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <TweenEngine/TweenEquations.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
TweenEquation &TweenEquations::easeInQuad = *(new QuadIn());
|
||||
TweenEquation &TweenEquations::easeOutQuad = *(new QuadOut());
|
||||
TweenEquation &TweenEquations::easeInOutQuad = *(new QuadInOut());
|
||||
|
||||
TweenEquation &TweenEquations::easeInOutLinear = *(new LinearInOut());
|
||||
|
||||
TweenEquation &TweenEquations::easeInBack = *(new BackIn());
|
||||
TweenEquation &TweenEquations::easeOutBack = *(new BackOut());
|
||||
TweenEquation &TweenEquations::easeInOutBack = *(new BackInOut());
|
||||
|
||||
TweenEquation &TweenEquations::easeInBounce = *(new BounceIn());
|
||||
TweenEquation &TweenEquations::easeOutBounce = *(new BounceOut());
|
||||
TweenEquation &TweenEquations::easeInOutBounce = *(new BounceInOut());
|
||||
|
||||
TweenEquation &TweenEquations::easeInCirc = *(new CircIn());
|
||||
TweenEquation &TweenEquations::easeOutCirc = *(new CircOut());
|
||||
TweenEquation &TweenEquations::easeInOutCirc = *(new CircInOut());
|
||||
|
||||
TweenEquation &TweenEquations::easeInCubic = *(new CubicIn());
|
||||
TweenEquation &TweenEquations::easeOutCubic = *(new CubicOut());
|
||||
TweenEquation &TweenEquations::easeInOutCubic = *(new CubicInOut());
|
||||
|
||||
TweenEquation &TweenEquations::easeInElastic = *(new ElasticIn());
|
||||
TweenEquation &TweenEquations::easeOutElastic = *(new ElasticOut());
|
||||
TweenEquation &TweenEquations::easeInOutElastic = *(new ElasticInOut());
|
||||
|
||||
TweenEquation &TweenEquations::easeInExpo = *(new ExpoIn());
|
||||
TweenEquation &TweenEquations::easeOutExpo = *(new ExpoOut());
|
||||
TweenEquation &TweenEquations::easeInOutExpo = *(new ExpoInOut());
|
||||
|
||||
TweenEquation &TweenEquations::easeInQuart = *(new QuartIn());
|
||||
TweenEquation &TweenEquations::easeOutQuart = *(new QuartOut());
|
||||
TweenEquation &TweenEquations::easeInOutQuart = *(new QuartInOut());
|
||||
|
||||
TweenEquation &TweenEquations::easeInQuint = *(new QuintIn());
|
||||
TweenEquation &TweenEquations::easeOutQuint = *(new QuintOut());
|
||||
TweenEquation &TweenEquations::easeInOutQuint = *(new QuintInOut());
|
||||
|
||||
TweenEquation &TweenEquations::easeInSine = *(new SineIn());
|
||||
TweenEquation &TweenEquations::easeOutSine = *(new SineOut());
|
||||
TweenEquation &TweenEquations::easeInOutSine = *(new SineInOut());
|
||||
}
|
186
external/tween-engine/src/TweenManager.cpp
vendored
Normal file
186
external/tween-engine/src/TweenManager.cpp
vendored
Normal file
@ -0,0 +1,186 @@
|
||||
//
|
||||
// TweenManager.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <TweenEngine/TweenManager.h>
|
||||
#include <TweenEngine/BaseTween.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
// -------------------------------------------------------------------------
|
||||
// Static API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Disables or enables the "auto remove" mode of any tween manager for a
|
||||
* particular tween or timeline. This mode is activated by default. The
|
||||
* interest of desactivating it is to prevent some tweens or timelines from
|
||||
* being automatically removed from a manager once they are finished.
|
||||
* Therefore, if you update a manager backwards, the tweens or timelines
|
||||
* will be played again, even if they were finished.
|
||||
*/
|
||||
void TweenManager::setAutoRemove(BaseTween &object, bool value)
|
||||
{
|
||||
object.isAutoRemoveEnabled = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables or enables the "auto start" mode of any tween manager for a
|
||||
* particular tween or timeline. This mode is activated by default. If it
|
||||
* is not enabled, add a tween or timeline to any manager won't start it
|
||||
* automatically, and you'll need to call .start() manually on your object.
|
||||
*/
|
||||
void TweenManager::setAutoStart(BaseTween &object, bool value)
|
||||
{
|
||||
object.isAutoStartEnabled = value;
|
||||
}
|
||||
|
||||
int getTweensCount(std::vector<BaseTween *> objs)
|
||||
{
|
||||
int cnt = 0;
|
||||
for (int i=0, n=objs.size(); i<n; i++)
|
||||
{
|
||||
cnt += objs[i]->getTweenCount();
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
int getTimelinesCount(std::vector<BaseTween *> objs)
|
||||
{
|
||||
int cnt = 0;
|
||||
for (int i=0, n=objs.size(); i<n; i++)
|
||||
{
|
||||
cnt += objs[i]->getTimelineCount();
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
bool isTweenFinished(BaseTween *obj)
|
||||
{
|
||||
if (obj->isFinished() && obj->isAutoRemoveEnabled)
|
||||
{
|
||||
obj->free();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// API
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
TweenManager::TweenManager() : objects()
|
||||
{
|
||||
objects.reserve(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a tween or timeline to the manager and starts or restarts it.
|
||||
*
|
||||
* @return The manager, for instruction chaining.
|
||||
*/
|
||||
TweenManager &TweenManager::add(BaseTween &object)
|
||||
{
|
||||
bool isPresent = (std::find(objects.begin(), objects.end(), &object) != objects.end());
|
||||
if (!isPresent) objects.push_back(&object);
|
||||
if (object.isAutoStartEnabled) object.start();
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kills every managed tweens and timelines.
|
||||
*/
|
||||
void TweenManager::killAll()
|
||||
{
|
||||
for (int i=0, n=objects.size(); i<n; i++)
|
||||
{
|
||||
BaseTween *obj = objects[i];
|
||||
obj->kill();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the minimum capacity of the manager. Defaults to 20.
|
||||
*/
|
||||
void TweenManager::ensureCapacity(int minCapacity) { objects.reserve(minCapacity); }
|
||||
|
||||
/**
|
||||
* Pauses the manager. Further update calls won't have any effect.
|
||||
*/
|
||||
void TweenManager::pause() { isPaused = true; }
|
||||
|
||||
/**
|
||||
* Resumes the manager, if paused.
|
||||
*/
|
||||
void TweenManager::resume() { isPaused = false; }
|
||||
|
||||
/**
|
||||
* Updates every tweens with a delta time ang handles the tween life-cycles
|
||||
* automatically. If a tween is finished, it will be removed from the
|
||||
* manager. The delta time represents the elapsed time between now and the
|
||||
* last update call. Each tween or timeline manages its local time, and adds
|
||||
* this delta to its local time to update itself.
|
||||
* <p/>
|
||||
*
|
||||
* Slow motion, fast motion and backward play can be easily achieved by
|
||||
* tweaking this delta time. Multiply it by -1 to play the animation
|
||||
* backward, or by 0.5 to play it twice slower than its normal speed.
|
||||
*/
|
||||
|
||||
void TweenManager::update(float delta)
|
||||
{
|
||||
// Remove tweens that are finished
|
||||
objects.erase(std::remove_if(objects.begin(),objects.end(),isTweenFinished), objects.end());
|
||||
|
||||
if (!isPaused)
|
||||
{
|
||||
if (delta >= 0)
|
||||
{
|
||||
for (int i=0, n=objects.size(); i<n; i++) objects[i]->update(delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=objects.size()-1; i>=0; i--) objects[i]->update(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of managed objects. An object may be a tween or a
|
||||
* timeline. Note that a timeline only counts for 1 object, since it
|
||||
* manages its children itself.
|
||||
* <p/>
|
||||
* To get the count of running tweens, see {@link #getRunningTweensCount()}.
|
||||
*/
|
||||
int TweenManager::size() { return objects.size(); }
|
||||
|
||||
/**
|
||||
* Gets the number of running tweens. This number includes the tweens
|
||||
* located inside timelines (and nested timelines).
|
||||
* <p/>
|
||||
* <b>Provided for debug purpose only.</b>
|
||||
*/
|
||||
int TweenManager::getRunningTweensCount() { return getTweensCount(objects); }
|
||||
|
||||
/**
|
||||
* Gets the number of running timelines. This number includes the timelines
|
||||
* nested inside other timelines.
|
||||
* <p/>
|
||||
* <b>Provided for debug purpose only.</b>
|
||||
*/
|
||||
int TweenManager::getRunningTimelinesCount() { return getTimelinesCount(objects); }
|
||||
|
||||
/**
|
||||
* Gets a list of every managed object.
|
||||
* <p/>
|
||||
* <b>Provided for debug purpose only.</b>
|
||||
*/
|
||||
std::vector<BaseTween *> &TweenManager::getObjects()
|
||||
{
|
||||
return objects;
|
||||
}
|
||||
|
||||
}
|
17
external/tween-engine/src/TweenPaths.cpp
vendored
Normal file
17
external/tween-engine/src/TweenPaths.cpp
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// TweenPaths.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <TweenEngine/TweenPaths.h>
|
||||
|
||||
#include <TweenEngine/paths/LinearPath.h>
|
||||
#include <TweenEngine/paths/CatmullRom.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
TweenPath &TweenPaths::linear = *(new LinearPath());
|
||||
TweenPath &TweenPaths::catmullRom = *(new CatmullRom());
|
||||
}
|
39
external/tween-engine/src/TweenPool.cpp
vendored
Normal file
39
external/tween-engine/src/TweenPool.cpp
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// TweenPool.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <TweenEngine/TweenPool.h>
|
||||
#include <TweenEngine/Tween.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
void TweenPoolCallback::onPool(Tween *obj)
|
||||
{
|
||||
obj->reset();
|
||||
}
|
||||
|
||||
void TweenPoolCallback::onUnPool(Tween *obj)
|
||||
{
|
||||
obj->reset();
|
||||
}
|
||||
|
||||
TweenPool::TweenPool() : Pool<TweenEngine::Tween>(20, new TweenPoolCallback())
|
||||
{
|
||||
}
|
||||
|
||||
Tween *TweenPool::create() { return new Tween(); }
|
||||
|
||||
//TweenPoolCallback *Tween::poolCallback = new TweenPoolCallback();
|
||||
//TweenPool *Tween::pool = new TweenPool(20, Tween::poolCallback);
|
||||
|
||||
/*
|
||||
private static final Pool<Tween> pool = new Pool<Tween>(20, poolCallback) {
|
||||
@Override protected Tween create() {return new Tween();}
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
}
|
34
external/tween-engine/src/equations/Back.cpp
vendored
Normal file
34
external/tween-engine/src/equations/Back.cpp
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
//
|
||||
// Back.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <TweenEngine/equations/Back.h>
|
||||
|
||||
#define S (1.70158f)
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
float BackIn::compute(float t) { return t*t*((S+1)*t - S); }
|
||||
const char *BackIn::toString() { return "Back.IN"; }
|
||||
|
||||
float BackOut::compute(float t) {
|
||||
t -= 1;
|
||||
return (t*t*((S+1)*t + S) + 1);
|
||||
}
|
||||
const char *BackOut::toString() { return "Back.OUT"; }
|
||||
|
||||
float BackInOut::compute(float t) {
|
||||
float s=S*1.525;
|
||||
t*=2;
|
||||
if (t < 1) {
|
||||
return 0.5f*(t*t*((s+1)*t - s));
|
||||
} else {
|
||||
t -= 2;
|
||||
return 0.5f*(t*t*((s+1)*t + s) + 2);
|
||||
}
|
||||
}
|
||||
const char *BackInOut::toString() { return "Back.INOUT"; }
|
||||
}
|
42
external/tween-engine/src/equations/Bounce.cpp
vendored
Normal file
42
external/tween-engine/src/equations/Bounce.cpp
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
//
|
||||
// Bounce.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <TweenEngine/equations/Bounce.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
inline float outBounce(float t) {
|
||||
if (t < (1/2.75)) {
|
||||
return 7.5625f*t*t;
|
||||
} else if (t < (2/2.75)) {
|
||||
t = t - (1.5 / 2.75);
|
||||
return (7.5625 * t * t + 0.75);
|
||||
} else if (t < (2.5/2.75)) {
|
||||
t = t - (2.25 / 2.75);
|
||||
return (7.5625 * t * t + 0.9375);
|
||||
} else {
|
||||
t = t - (2.625 / 2.75);
|
||||
return (7.5625 * t * t + 0.984375);
|
||||
}
|
||||
}
|
||||
|
||||
inline float inBounce(float t) {
|
||||
return 1 - outBounce(1-t);
|
||||
}
|
||||
|
||||
float BounceIn::compute(float t) { return inBounce(t); }
|
||||
const char *BounceIn::toString() { return "Bounce.IN"; }
|
||||
|
||||
float BounceOut::compute(float t) { return outBounce(t); }
|
||||
const char *BounceOut::toString() { return "Bounce.OUT"; }
|
||||
|
||||
float BounceInOut::compute(float t) {
|
||||
if (t < 0.5f) return (inBounce(t*2) * 0.5f);
|
||||
else return (outBounce(t*2-1) * 0.5f + 0.5f);
|
||||
}
|
||||
const char *BounceInOut::toString() { return "Bounce.INOUT"; }
|
||||
}
|
30
external/tween-engine/src/equations/Circ.cpp
vendored
Normal file
30
external/tween-engine/src/equations/Circ.cpp
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
//
|
||||
// Circ.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include <TweenEngine/equations/Circ.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
float CircIn::compute(float t) { return (float) -sqrt(1 - t*t) - 1; }
|
||||
const char *CircIn::toString() { return "Circ.IN"; }
|
||||
|
||||
float CircOut::compute(float t) { return (float) sqrt(1 - (t-1)*(t-1)); }
|
||||
const char *CircOut::toString() { return "Circ.OUT"; }
|
||||
|
||||
float CircInOut::compute(float t) {
|
||||
t *= 2;
|
||||
if (t < 1) {
|
||||
return (-0.5 * (sqrt(1 - t*t) - 1));
|
||||
} else {
|
||||
t -= 2;
|
||||
return (0.5 * (sqrt(1 - t*t) + 1));
|
||||
}
|
||||
}
|
||||
|
||||
const char *CircInOut::toString() { return "Circ.INOUT"; }
|
||||
}
|
31
external/tween-engine/src/equations/Cubic.cpp
vendored
Normal file
31
external/tween-engine/src/equations/Cubic.cpp
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
//
|
||||
// Cubic.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <TweenEngine/equations/Cubic.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
float CubicIn::compute(float t) { return t*t*t; }
|
||||
const char *CubicIn::toString() { return "Cubic.IN"; }
|
||||
|
||||
float CubicOut::compute(float t) {
|
||||
t -= 1;
|
||||
return t*t*t + 1;
|
||||
}
|
||||
const char *CubicOut::toString() { return "Cubic.OUT"; }
|
||||
|
||||
float CubicInOut::compute(float t) {
|
||||
t *= 2;
|
||||
if (t < 1) {
|
||||
return 0.5f * t*t*t;
|
||||
} else {
|
||||
t -= 2;
|
||||
return 0.5f * (t*t*t + 2);
|
||||
}
|
||||
}
|
||||
const char *CubicInOut::toString() { return "Cubic.INOUT"; }
|
||||
}
|
80
external/tween-engine/src/equations/Elastic.cpp
vendored
Normal file
80
external/tween-engine/src/equations/Elastic.cpp
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
//
|
||||
// Elastic.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include <TweenEngine/equations/Elastic.h>
|
||||
|
||||
#define M_PI 3.14159265358979323846
|
||||
#define M_TWOPI (M_PI * 2.0)
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
float ElasticIn::compute(float t) {
|
||||
float a = amplitude;
|
||||
float p = period;
|
||||
if (t == 0) return 0;
|
||||
if (t == 1) return 1;
|
||||
if (!isPeriodSet) p = 0.3;
|
||||
float s;
|
||||
if (!isAmplitudeSet || a < 1) {
|
||||
a = 1;
|
||||
s = p/4.0;
|
||||
} else {
|
||||
s = p/(M_TWOPI) * (float)asin(1/a);
|
||||
}
|
||||
t -= 1;
|
||||
return -(a*(float)pow(2,10*t) * (float)sin((t-s)*(M_TWOPI)/p ));
|
||||
}
|
||||
const char *ElasticIn::toString() { return "Elastic.IN"; }
|
||||
void ElasticIn::setAmplitude(float a) { this->amplitude = a; this->isAmplitudeSet = true; }
|
||||
void ElasticIn::setPeriod(float p) { this->period = p; this->isPeriodSet = true; }
|
||||
|
||||
float ElasticOut::compute(float t) {
|
||||
float a = amplitude;
|
||||
float p = period;
|
||||
if (t==0) return 0;
|
||||
if (t==1) return 1;
|
||||
if (!isPeriodSet) p = 0.3f;
|
||||
float s;
|
||||
if (!isAmplitudeSet || a < 1) {
|
||||
a = 1;
|
||||
s = p/4.0;
|
||||
} else {
|
||||
s = p/(M_TWOPI) * (float)asin(1/a);
|
||||
}
|
||||
return a*(float)pow(2,-10*t) * (float)sin((t-s)*(M_TWOPI)/p ) + 1;
|
||||
}
|
||||
const char *ElasticOut::toString() { return "Elastic.OUT"; }
|
||||
void ElasticOut::setAmplitude(float a) { this->amplitude = a; this->isAmplitudeSet = true; }
|
||||
void ElasticOut::setPeriod(float p) { this->period = p; this->isPeriodSet = true; }
|
||||
|
||||
float ElasticInOut::compute(float t) {
|
||||
float a = amplitude;
|
||||
float p = period;
|
||||
if (t==0) return 0;
|
||||
t *= 2;
|
||||
if (t==2) return 1;
|
||||
if (!isPeriodSet) p = 0.3f*1.5f;
|
||||
float s;
|
||||
if (!isAmplitudeSet || a < 1) {
|
||||
a = 1;
|
||||
s = p/4.0;
|
||||
} else {
|
||||
s = p/(M_TWOPI) * (float)asin(1/a);
|
||||
}
|
||||
if (t < 1) {
|
||||
t -= 1;
|
||||
return -0.5f*(a*(float)pow(2,10*t) * (float)sin((t-s)*(M_TWOPI)/p));
|
||||
} else {
|
||||
t -= 1;
|
||||
return a*(float)pow(2,-10*t) * (float)sin((t-s)*(M_TWOPI)/p)*0.5f + 1;
|
||||
}
|
||||
}
|
||||
const char *ElasticInOut::toString() { return "Elastic.INOUT"; }
|
||||
void ElasticInOut::setAmplitude(float a) { this->amplitude = a; this->isAmplitudeSet = true; }
|
||||
void ElasticInOut::setPeriod(float p) { this->period = p; this->isPeriodSet = true; }
|
||||
}
|
35
external/tween-engine/src/equations/Expo.cpp
vendored
Normal file
35
external/tween-engine/src/equations/Expo.cpp
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// Expo.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include <TweenEngine/equations/Expo.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
float ExpoIn::compute(float t) {
|
||||
return (t==0) ? 0 : (float)pow(2,10*(t-1));
|
||||
}
|
||||
const char *ExpoIn::toString() { return "Expo.IN"; }
|
||||
|
||||
float ExpoOut::compute(float t) {
|
||||
return (t==1) ? 1 : -(float)pow(2,-10*t) + 1;
|
||||
}
|
||||
const char *ExpoOut::toString() { return "Expo.OUT"; }
|
||||
|
||||
float ExpoInOut::compute(float t) {
|
||||
if (t==0) return 0;
|
||||
if (t==1) return 1;
|
||||
t *= 2;
|
||||
if (t < 1) {
|
||||
return 0.5f * (float)pow(2,10*(t-1));
|
||||
} else {
|
||||
t -= 1;
|
||||
return 0.5f * (-(float)pow(2,-10*t) + 2);
|
||||
}
|
||||
}
|
||||
const char *ExpoInOut::toString() { return "Expo.INOUT"; }
|
||||
}
|
20
external/tween-engine/src/equations/Linear.cpp
vendored
Normal file
20
external/tween-engine/src/equations/Linear.cpp
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// Linear.cpp
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
/**
|
||||
* Easing equation based on Robert Penner's work:
|
||||
* http://robertpenner.com/easing/
|
||||
* @author Aurelien Ribon | http://www.aurelienribon.com/
|
||||
*/
|
||||
|
||||
#include <TweenEngine/equations/Linear.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
float LinearInOut::compute(float t) { return t; }
|
||||
const char *LinearInOut::toString() { return "Linear.INOUT"; }
|
||||
|
||||
}
|
31
external/tween-engine/src/equations/Quad.cpp
vendored
Normal file
31
external/tween-engine/src/equations/Quad.cpp
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
//
|
||||
// Quad.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
/**
|
||||
* Easing equation based on Robert Penner's work:
|
||||
* http://robertpenner.com/easing/
|
||||
* @author Aurelien Ribon | http://www.aurelienribon.com/
|
||||
*/
|
||||
|
||||
#include <TweenEngine/equations/Quad.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
float QuadIn::compute(float t) { return t*t; }
|
||||
const char *QuadIn::toString() { return "Quad.IN"; }
|
||||
|
||||
float QuadOut::compute(float t) { return -t*(t-2); }
|
||||
const char *QuadOut::toString() { return "Quad.OUT"; }
|
||||
|
||||
float QuadInOut::compute(float t)
|
||||
{
|
||||
t*=2;
|
||||
if (t < 1) return 0.5f*t*t;
|
||||
return -0.5f * ((t-1)*(t-3) - 1);
|
||||
}
|
||||
const char *QuadInOut::toString() { return "Quad.INOUT"; }
|
||||
}
|
31
external/tween-engine/src/equations/Quart.cpp
vendored
Normal file
31
external/tween-engine/src/equations/Quart.cpp
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
//
|
||||
// Quart.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <TweenEngine/equations/Quart.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
float QuartIn::compute(float t) { return t*t*t*t; }
|
||||
const char *QuartIn::toString() { return "Quart.IN"; }
|
||||
|
||||
float QuartOut::compute(float t) {
|
||||
t-=1;
|
||||
return -(t*t*t*t - 1);
|
||||
}
|
||||
const char *QuartOut::toString() { return "Quart.OUT"; }
|
||||
|
||||
float QuartInOut::compute(float t) {
|
||||
t *= 2;
|
||||
if (t < 1) {
|
||||
return 0.5f*t*t*t*t;
|
||||
} else {
|
||||
t -= 2;
|
||||
return -0.5f * (t*t*t*t - 2);
|
||||
}
|
||||
}
|
||||
const char *QuartInOut::toString() { return "Quart.INOUT"; }
|
||||
}
|
31
external/tween-engine/src/equations/Quint.cpp
vendored
Normal file
31
external/tween-engine/src/equations/Quint.cpp
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
//
|
||||
// Quint.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <TweenEngine/equations/Quint.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
float QuintIn::compute(float t) { return t*t*t*t*t; }
|
||||
const char *QuintIn::toString() { return "Quint.IN"; }
|
||||
|
||||
float QuintOut::compute(float t) {
|
||||
t-=1;
|
||||
return -(t*t*t*t*t - 1);
|
||||
}
|
||||
const char *QuintOut::toString() { return "Quint.OUT"; }
|
||||
|
||||
float QuintInOut::compute(float t) {
|
||||
t *= 2;
|
||||
if (t < 1) {
|
||||
return 0.5f*t*t*t*t*t;
|
||||
} else {
|
||||
t -= 2;
|
||||
return -0.5f * (t*t*t*t*t - 2);
|
||||
}
|
||||
}
|
||||
const char *QuintInOut::toString() { return "Quint.INOUT"; }
|
||||
}
|
24
external/tween-engine/src/equations/Sine.cpp
vendored
Normal file
24
external/tween-engine/src/equations/Sine.cpp
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// Sine.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include <TweenEngine/equations/Sine.h>
|
||||
|
||||
#define M_PI 3.14159265358979323846
|
||||
#define M_PI_2 1.57079632679489661923
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
float SineIn::compute(float t) { return (float)-cos(t * (M_PI_2)) + 1; }
|
||||
const char *SineIn::toString() { return "Sine.IN"; }
|
||||
|
||||
float SineOut::compute(float t) { return (float)sin(t * (M_PI_2)); }
|
||||
const char *SineOut::toString() { return "Sine.OUT"; }
|
||||
|
||||
float SineInOut::compute(float t) { return -0.5f * ((float)cos(M_PI*t) - 1); }
|
||||
const char *SineInOut::toString() { return "Sine.INOUT"; }
|
||||
}
|
47
external/tween-engine/src/paths/CatmullRom.cpp
vendored
Normal file
47
external/tween-engine/src/paths/CatmullRom.cpp
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
//
|
||||
// CatmullRom.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include <TweenEngine/paths/CatmullRom.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
float CatmullRom::compute(float t, float *points, int pointsCnt)
|
||||
{
|
||||
int segment = (int) floor((pointsCnt-1) * t);
|
||||
segment = segment > 0 ? segment : 0;
|
||||
segment = segment < (pointsCnt-2) ? segment : pointsCnt-2;
|
||||
|
||||
t = t * (pointsCnt-1) - segment;
|
||||
|
||||
if (segment == 0)
|
||||
{
|
||||
return catmullRomSpline(points[0], points[0], points[1], points[2], t);
|
||||
}
|
||||
|
||||
if (segment == pointsCnt-2)
|
||||
{
|
||||
return catmullRomSpline(points[pointsCnt-3], points[pointsCnt-2], points[pointsCnt-1], points[pointsCnt-1], t);
|
||||
}
|
||||
|
||||
return catmullRomSpline(points[segment-1], points[segment], points[segment+1], points[segment+2], t);
|
||||
}
|
||||
|
||||
float CatmullRom::catmullRomSpline(float a, float b, float c, float d, float t)
|
||||
{
|
||||
float t1 = (c - a) * 0.5f;
|
||||
float t2 = (d - b) * 0.5f;
|
||||
|
||||
float h1 = +2 * t * t * t - 3 * t * t + 1;
|
||||
float h2 = -2 * t * t * t + 3 * t * t;
|
||||
float h3 = t * t * t - 2 * t * t + t;
|
||||
float h4 = t * t * t - t * t;
|
||||
|
||||
return b * h1 + c * h2 + t1 * h3 + t2 * h4;
|
||||
}
|
||||
|
||||
}
|
23
external/tween-engine/src/paths/LinearPath.cpp
vendored
Normal file
23
external/tween-engine/src/paths/LinearPath.cpp
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// Linear.cpp
|
||||
//
|
||||
// This code is derived from Universal Tween Engine
|
||||
// Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
|
||||
#include <math.h>
|
||||
#include <TweenEngine/paths/LinearPath.h>
|
||||
|
||||
namespace TweenEngine
|
||||
{
|
||||
float LinearPath::compute(float t, float *points, int pointsCnt)
|
||||
{
|
||||
int segment = (int) floor((pointsCnt-1) * t);
|
||||
segment = segment > 0 ? segment : 0;
|
||||
segment = segment < (pointsCnt-2) ? segment : pointsCnt-2;
|
||||
|
||||
t = t * (pointsCnt-1) - segment;
|
||||
|
||||
return points[segment] + t * (points[segment+1] - points[segment]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user