mirror of
https://github.com/godotengine/godot.git
synced 2024-11-22 12:12:28 +00:00
Merge pull request #628 from sanikoyes/PR-tween-support
thanks sanikoyes this is great!
This commit is contained in:
commit
574a84b40c
11
demos/misc/tween/engine.cfg
Normal file
11
demos/misc/tween/engine.cfg
Normal file
@ -0,0 +1,11 @@
|
||||
[application]
|
||||
|
||||
name="Tween Demo"
|
||||
main_scene="res://main.xml"
|
||||
icon="icon.png"
|
||||
target_fps=60
|
||||
|
||||
[display]
|
||||
|
||||
stretch_mode="2d"
|
||||
stretch_aspect="keep_width"
|
164
demos/misc/tween/main.gd
Normal file
164
demos/misc/tween/main.gd
Normal file
@ -0,0 +1,164 @@
|
||||
|
||||
extends Control
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
var trans = ["linear", "sine", "quint", "quart", "quad", "expo", "elastic", "cubic", "circ", "bounce", "back"]
|
||||
var eases = ["in", "out", "in_out", "out_in"]
|
||||
var modes = ["move", "color", "scale", "rotate", "callback", "follow", "repeat", "pause"]
|
||||
|
||||
var state = {
|
||||
trans = Tween.TRANS_LINEAR,
|
||||
eases = Tween.EASE_IN,
|
||||
}
|
||||
|
||||
func _ready():
|
||||
for index in range(trans.size()):
|
||||
var name = trans[index]
|
||||
get_node("trans/" + name).connect("pressed", self, "on_trans_changed", [name, index])
|
||||
|
||||
for index in range(eases.size()):
|
||||
var name = eases[index]
|
||||
get_node("eases/" + name).connect("pressed", self, "on_eases_changed", [name, index])
|
||||
|
||||
for index in range(modes.size()):
|
||||
var name = modes[index]
|
||||
get_node("modes/" + name).connect("pressed", self, "on_modes_changed", [name])
|
||||
|
||||
get_node("color/color_from").set_color(Color(1, 0, 0, 1))
|
||||
get_node("color/color_from").connect("color_changed", self, "on_color_changed")
|
||||
|
||||
get_node("color/color_to").set_color(Color(0, 1, 1, 1))
|
||||
get_node("color/color_to").connect("color_changed", self, "on_color_changed")
|
||||
|
||||
get_node("trans/linear").set_pressed(true)
|
||||
get_node("eases/in").set_pressed(true)
|
||||
get_node("modes/move").set_pressed(true)
|
||||
get_node("modes/repeat").set_pressed(true)
|
||||
|
||||
reset_tween()
|
||||
|
||||
# Initalization here
|
||||
pass
|
||||
|
||||
func on_trans_changed(name, index):
|
||||
for index in range(trans.size()):
|
||||
var pressed = trans[index] == name
|
||||
var btn = get_node("trans/" + trans[index])
|
||||
|
||||
btn.set_pressed(pressed)
|
||||
btn.set_ignore_mouse(pressed)
|
||||
|
||||
state.trans = index
|
||||
reset_tween()
|
||||
|
||||
func on_eases_changed(name, index):
|
||||
for index in range(eases.size()):
|
||||
var pressed = eases[index] == name
|
||||
var btn = get_node("eases/" + eases[index])
|
||||
|
||||
btn.set_pressed(pressed)
|
||||
btn.set_ignore_mouse(pressed)
|
||||
|
||||
state.eases = index
|
||||
reset_tween()
|
||||
|
||||
func on_modes_changed(name):
|
||||
var tween = get_node("tween")
|
||||
if name == "pause":
|
||||
if get_node("modes/pause").is_pressed():
|
||||
tween.stop_all()
|
||||
get_node("timeline").set_ignore_mouse(false)
|
||||
else:
|
||||
tween.resume_all()
|
||||
get_node("timeline").set_ignore_mouse(true)
|
||||
else:
|
||||
reset_tween()
|
||||
|
||||
func on_color_changed(color):
|
||||
reset_tween()
|
||||
|
||||
func reset_tween():
|
||||
var tween = get_node("tween")
|
||||
var pos = tween.tell()
|
||||
tween.reset_all()
|
||||
tween.remove_all()
|
||||
|
||||
var sprite = get_node("tween/area/sprite")
|
||||
var follow = get_node("tween/area/follow")
|
||||
var follow_2 = get_node("tween/area/follow_2")
|
||||
var size = get_node("tween/area").get_size()
|
||||
|
||||
if get_node("modes/move").is_pressed():
|
||||
tween.interpolate_method(sprite, "set_pos", Vector2(0,0), Vector2(size.width, size.height), 2, state.trans, state.eases)
|
||||
tween.interpolate_property(sprite, "transform/pos", Vector2(size.width,size.height), Vector2(0, 0), 2, state.trans, state.eases, 2)
|
||||
|
||||
if get_node("modes/color").is_pressed():
|
||||
tween.interpolate_method(sprite, "set_modulate", get_node("color/color_from").get_color(), get_node("color/color_to").get_color(), 2, state.trans, state.eases)
|
||||
tween.interpolate_property(sprite, "modulate", get_node("color/color_to").get_color(), get_node("color/color_from").get_color(), 2, state.trans, state.eases, 2)
|
||||
else:
|
||||
sprite.set_modulate(Color(1, 1, 1, 1))
|
||||
|
||||
if get_node("modes/scale").is_pressed():
|
||||
tween.interpolate_method(sprite, "set_scale", Vector2(0.5,0.5), Vector2(1.5, 1.5), 2, state.trans, state.eases)
|
||||
tween.interpolate_property(sprite, "transform/scale", Vector2(1.5,1.5), Vector2(0.5, 0.5), 2, state.trans, state.eases, 2)
|
||||
else:
|
||||
sprite.set_scale(Vector2(1, 1))
|
||||
|
||||
if get_node("modes/rotate").is_pressed():
|
||||
tween.interpolate_method(sprite, "_set_rotd", 0, 360, 2, state.trans, state.eases)
|
||||
tween.interpolate_property(sprite, "transform/rot", 360, 0, 2, state.trans, state.eases, 2)
|
||||
|
||||
if get_node("modes/callback").is_pressed():
|
||||
tween.interpolate_callback(self, "on_callback", 0.5, "0.5 second's after")
|
||||
tween.interpolate_callback(self, "on_callback", 1.2, "1.2 second's after")
|
||||
|
||||
if get_node("modes/follow").is_pressed():
|
||||
follow.show()
|
||||
follow_2.show()
|
||||
|
||||
tween.follow_method(follow, "set_pos", Vector2(0, size.height), sprite, "get_pos", 2, state.trans, state.eases)
|
||||
tween.targeting_method(follow, "set_pos", sprite, "get_pos", Vector2(0, size.height), 2, state.trans, state.eases, 2)
|
||||
|
||||
tween.targeting_property(follow_2, "transform/pos", sprite, "transform/pos", Vector2(size.width, 0), 2, state.trans, state.eases)
|
||||
tween.follow_property(follow_2, "transform/pos", Vector2(size.width, 0), sprite, "transform/pos", 2, state.trans, state.eases, 2)
|
||||
else:
|
||||
follow.hide()
|
||||
follow_2.hide()
|
||||
|
||||
tween.set_repeat(get_node("modes/repeat").is_pressed())
|
||||
tween.start()
|
||||
tween.seek(pos)
|
||||
|
||||
if get_node("modes/pause").is_pressed():
|
||||
tween.stop_all()
|
||||
get_node("timeline").set_ignore_mouse(false)
|
||||
get_node("timeline").set_value(0)
|
||||
else:
|
||||
tween.resume_all()
|
||||
get_node("timeline").set_ignore_mouse(true)
|
||||
|
||||
func _on_tween_step( object, key, elapsed, value ):
|
||||
|
||||
var timeline = get_node("timeline")
|
||||
|
||||
var tween = get_node("tween")
|
||||
var runtime = tween.get_runtime()
|
||||
|
||||
var ratio = 100 * (elapsed / runtime)
|
||||
timeline.set_value(ratio)
|
||||
|
||||
|
||||
func _on_timeline_value_changed( value ):
|
||||
if !get_node("modes/pause").is_pressed():
|
||||
return
|
||||
|
||||
var tween = get_node("tween")
|
||||
var runtime = tween.get_runtime()
|
||||
tween.seek(runtime * value / 100)
|
||||
|
||||
func on_callback(arg):
|
||||
var label = get_node("tween/area/label")
|
||||
label.add_text("on_callback -> " + arg + "\n")
|
367
demos/misc/tween/main.xml
Normal file
367
demos/misc/tween/main.xml
Normal file
File diff suppressed because one or more lines are too long
1219
scene/animation/tween.cpp
Normal file
1219
scene/animation/tween.cpp
Normal file
File diff suppressed because it is too large
Load Diff
239
scene/animation/tween.h
Normal file
239
scene/animation/tween.h
Normal file
@ -0,0 +1,239 @@
|
||||
/*************************************************************************/
|
||||
/* tween.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#ifndef TWEEN_H
|
||||
#define TWEEN_H
|
||||
|
||||
#include "scene/main/node.h"
|
||||
|
||||
|
||||
class Tween : public Node {
|
||||
|
||||
OBJ_TYPE( Tween, Node );
|
||||
|
||||
public:
|
||||
enum TweenProcessMode {
|
||||
TWEEN_PROCESS_FIXED,
|
||||
TWEEN_PROCESS_IDLE,
|
||||
};
|
||||
|
||||
enum TransitionType {
|
||||
TRANS_LINEAR,
|
||||
TRANS_SINE,
|
||||
TRANS_QUINT,
|
||||
TRANS_QUART,
|
||||
TRANS_QUAD,
|
||||
TRANS_EXPO,
|
||||
TRANS_ELASTIC,
|
||||
TRANS_CUBIC,
|
||||
TRANS_CIRC,
|
||||
TRANS_BOUNCE,
|
||||
TRANS_BACK,
|
||||
|
||||
TRANS_COUNT,
|
||||
};
|
||||
|
||||
enum EaseType {
|
||||
EASE_IN,
|
||||
EASE_OUT,
|
||||
EASE_IN_OUT,
|
||||
EASE_OUT_IN,
|
||||
|
||||
EASE_COUNT,
|
||||
};
|
||||
|
||||
private:
|
||||
enum InterpolateType {
|
||||
|
||||
INTER_PROPERTY,
|
||||
INTER_METHOD,
|
||||
FOLLOW_PROPERTY,
|
||||
FOLLOW_METHOD,
|
||||
TARGETING_PROPERTY,
|
||||
TARGETING_METHOD,
|
||||
INTER_CALLBACK,
|
||||
};
|
||||
|
||||
struct InterpolateData {
|
||||
bool active;
|
||||
InterpolateType type;
|
||||
bool finish;
|
||||
real_t elapsed;
|
||||
NodePath path;
|
||||
StringName key;
|
||||
Variant initial_val;
|
||||
Variant delta_val;
|
||||
Variant final_val;
|
||||
NodePath target;
|
||||
StringName target_key;
|
||||
real_t times_in_sec;
|
||||
TransitionType trans_type;
|
||||
EaseType ease_type;
|
||||
real_t delay;
|
||||
Variant arg;
|
||||
};
|
||||
|
||||
String autoplay;
|
||||
TweenProcessMode tween_process_mode;
|
||||
bool processing;
|
||||
bool active;
|
||||
bool repeat;
|
||||
float speed_scale;
|
||||
|
||||
List<InterpolateData> interpolates;
|
||||
|
||||
typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d);
|
||||
static interpolater interpolaters[TRANS_COUNT][EASE_COUNT];
|
||||
|
||||
real_t _run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d);
|
||||
Variant& _get_delta_val(InterpolateData& p_data);
|
||||
Variant& _get_initial_val(InterpolateData& p_data);
|
||||
Variant _run_equation(InterpolateData& p_data);
|
||||
bool _calc_delta_val(const Variant& p_initial_val, const Variant& p_final_val, Variant& p_delta_val);
|
||||
bool _apply_tween_value(InterpolateData& p_data, Variant& value);
|
||||
|
||||
void _tween_process(float p_delta);
|
||||
void _set_process(bool p_process,bool p_force=false);
|
||||
|
||||
protected:
|
||||
|
||||
bool _set(const StringName& p_name, const Variant& p_value);
|
||||
bool _get(const StringName& p_name,Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
||||
bool is_active() const;
|
||||
void set_active(bool p_active);
|
||||
|
||||
bool is_repeat() const;
|
||||
void set_repeat(bool p_repeat);
|
||||
|
||||
void set_tween_process_mode(TweenProcessMode p_mode);
|
||||
TweenProcessMode get_tween_process_mode() const;
|
||||
|
||||
void set_speed(float p_speed);
|
||||
float get_speed() const;
|
||||
|
||||
bool start();
|
||||
bool reset(Node *p_node, String p_key);
|
||||
bool reset_all();
|
||||
bool stop(Node *p_node, String p_key);
|
||||
bool stop_all();
|
||||
bool resume(Node *p_node, String p_key);
|
||||
bool resume_all();
|
||||
bool remove(Node *p_node, String p_key);
|
||||
bool remove_all();
|
||||
|
||||
bool seek(real_t p_time);
|
||||
real_t tell() const;
|
||||
real_t get_runtime() const;
|
||||
|
||||
bool interpolate_property(Node *p_node
|
||||
, String p_property
|
||||
, Variant p_initial_val
|
||||
, Variant p_final_val
|
||||
, real_t p_times_in_sec
|
||||
, TransitionType p_trans_type
|
||||
, EaseType p_ease_type
|
||||
, real_t p_delay = 0
|
||||
);
|
||||
|
||||
bool interpolate_method(Node *p_node
|
||||
, String p_method
|
||||
, Variant p_initial_val
|
||||
, Variant p_final_val
|
||||
, real_t p_times_in_sec
|
||||
, TransitionType p_trans_type
|
||||
, EaseType p_ease_type
|
||||
, real_t p_delay = 0
|
||||
);
|
||||
|
||||
bool interpolate_callback(Node *p_node
|
||||
, String p_callback
|
||||
, real_t p_times_in_sec
|
||||
, Variant p_arg = Variant()
|
||||
);
|
||||
|
||||
bool follow_property(Node *p_node
|
||||
, String p_property
|
||||
, Variant p_initial_val
|
||||
, Node *p_target
|
||||
, String p_target_property
|
||||
, real_t p_times_in_sec
|
||||
, TransitionType p_trans_type
|
||||
, EaseType p_ease_type
|
||||
, real_t p_delay = 0
|
||||
);
|
||||
|
||||
bool follow_method(Node *p_node
|
||||
, String p_method
|
||||
, Variant p_initial_val
|
||||
, Node *p_target
|
||||
, String p_target_method
|
||||
, real_t p_times_in_sec
|
||||
, TransitionType p_trans_type
|
||||
, EaseType p_ease_type
|
||||
, real_t p_delay = 0
|
||||
);
|
||||
|
||||
bool targeting_property(Node *p_node
|
||||
, String p_property
|
||||
, Node *p_initial
|
||||
, String p_initial_property
|
||||
, Variant p_final_val
|
||||
, real_t p_times_in_sec
|
||||
, TransitionType p_trans_type
|
||||
, EaseType p_ease_type
|
||||
, real_t p_delay = 0
|
||||
);
|
||||
|
||||
bool targeting_method(Node *p_node
|
||||
, String p_method
|
||||
, Node *p_initial
|
||||
, String p_initial_method
|
||||
, Variant p_final_val
|
||||
, real_t p_times_in_sec
|
||||
, TransitionType p_trans_type
|
||||
, EaseType p_ease_type
|
||||
, real_t p_delay = 0
|
||||
);
|
||||
|
||||
Tween();
|
||||
~Tween();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST( Tween::TweenProcessMode );
|
||||
VARIANT_ENUM_CAST( Tween::TransitionType );
|
||||
VARIANT_ENUM_CAST( Tween::EaseType );
|
||||
|
||||
#endif
|
||||
|
407
scene/animation/tween_interpolaters.cpp
Normal file
407
scene/animation/tween_interpolaters.cpp
Normal file
@ -0,0 +1,407 @@
|
||||
/*************************************************************************/
|
||||
/* tween.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* http://www.godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
#include "tween.h"
|
||||
|
||||
const real_t pi = 3.1415926535898;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// linear
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace linear {
|
||||
static real_t in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c * t / d + b;
|
||||
}
|
||||
|
||||
static real_t out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c * t / d + b;
|
||||
}
|
||||
|
||||
static real_t in_out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c * t / d + b;
|
||||
}
|
||||
|
||||
static real_t out_in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c * t / d + b;
|
||||
}
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// sine
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace sine {
|
||||
static real_t in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return -c * cos(t / d * (pi / 2)) + c + b;
|
||||
}
|
||||
|
||||
static real_t out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c * sin(t / d * (pi / 2)) + b;
|
||||
}
|
||||
|
||||
static real_t in_out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return -c / 2 * (cos(pi * t / d) - 1) + b;
|
||||
}
|
||||
|
||||
static real_t out_in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return (t < d / 2)
|
||||
? out(t * 2, b, c / 2, d)
|
||||
: in((t * 2) - d, b + c / 2, c / 2, d)
|
||||
;
|
||||
}
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// quint
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace quint {
|
||||
static real_t in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c * pow(t / d, 5) + b;
|
||||
}
|
||||
|
||||
static real_t out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c * (pow(t / d - 1, 5) + 1) + b;
|
||||
}
|
||||
|
||||
static real_t in_out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
t = t / d * 2;
|
||||
if (t < 1) return c / 2 * pow(t, 5) + b;
|
||||
return c / 2 * (pow(t - 2, 5) + 2) + b;
|
||||
}
|
||||
|
||||
static real_t out_in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return (t < d / 2)
|
||||
? out(t * 2, b, c / 2, d)
|
||||
: in((t * 2) - d, b + c / 2, c / 2, d)
|
||||
;
|
||||
}
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// quart
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace quart {
|
||||
static real_t in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c * pow(t / d, 4) + b;
|
||||
}
|
||||
|
||||
static real_t out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return -c * (pow(t / d - 1, 4) - 1) + b;
|
||||
}
|
||||
|
||||
static real_t in_out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
t = t / d * 2;
|
||||
if (t < 1) return c / 2 * pow(t, 4) + b;
|
||||
return -c / 2 * (pow(t - 2, 4) - 2) + b;
|
||||
}
|
||||
|
||||
static real_t out_in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return (t < d / 2)
|
||||
? out(t * 2, b, c / 2, d)
|
||||
: in((t * 2) - d, b + c / 2, c / 2, d)
|
||||
;
|
||||
}
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// quad
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace quad {
|
||||
static real_t in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c * pow(t / d, 2) + b;
|
||||
}
|
||||
|
||||
static real_t out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
t = t / d;
|
||||
return -c * t * (t - 2) + b;
|
||||
}
|
||||
|
||||
static real_t in_out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
t = t / d * 2;
|
||||
if (t < 1) return c / 2 * pow(t, 2) + b;
|
||||
return -c / 2 * ((t - 1) * (t - 3) - 1) + b;
|
||||
}
|
||||
|
||||
static real_t out_in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return (t < d / 2)
|
||||
? out(t * 2, b, c / 2, d)
|
||||
: in((t * 2) - d, b + c / 2, c / 2, d)
|
||||
;
|
||||
}
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// expo
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace expo {
|
||||
static real_t in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
if (t == 0) return b;
|
||||
return c * pow(2, 10 * (t / d - 1)) + b - c * 0.001;
|
||||
}
|
||||
|
||||
static real_t out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
if (t == d) return b + c;
|
||||
return c * 1.001 * (-pow(2, -10 * t / d) + 1) + b;
|
||||
}
|
||||
|
||||
static real_t in_out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
if (t == 0) return b;
|
||||
if (t == d) return b + c;
|
||||
t = t / d * 2;
|
||||
if (t < 1) return c / 2 * pow(2, 10 * (t - 1)) + b - c * 0.0005;
|
||||
return c / 2 * 1.0005 * (-pow(2, -10 * (t - 1)) + 2) + b;
|
||||
}
|
||||
|
||||
static real_t out_in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return (t < d / 2)
|
||||
? out(t * 2, b, c / 2, d)
|
||||
: in((t * 2) - d, b + c / 2, c / 2, d)
|
||||
;
|
||||
}
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// elastic
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace elastic {
|
||||
static real_t in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
if (t == 0) return b;
|
||||
if ((t /= d) == 1) return b + c;
|
||||
float p = d * 0.3f;
|
||||
float a = c;
|
||||
float s = p / 4;
|
||||
float postFix = a * pow(2,10 * (t -= 1)); // this is a fix, again, with post-increment operators
|
||||
return -(postFix * sin((t * d - s) * (2 * pi) / p )) + b;
|
||||
}
|
||||
|
||||
static real_t out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
if (t == 0) return b;
|
||||
if ((t /= d) == 1) return b + c;
|
||||
float p = d * 0.3f;
|
||||
float a = c;
|
||||
float s = p / 4;
|
||||
return (a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p ) + c + b);
|
||||
}
|
||||
|
||||
static real_t in_out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
if (t == 0) return b;
|
||||
if ((t /= d / 2) == 2) return b + c;
|
||||
float p = d * (0.3f * 1.5f);
|
||||
float a = c;
|
||||
float s = p / 4;
|
||||
|
||||
if (t < 1) {
|
||||
float postFix = a * pow(2, 10 * (t -= 1)); // postIncrement is evil
|
||||
return -0.5f * (postFix * sin((t * d - s) * (2 * pi) / p)) + b;
|
||||
}
|
||||
float postFix = a * pow(2, -10 * (t -= 1)); // postIncrement is evil
|
||||
return postFix * sin((t * d - s) * (2 * pi) / p ) * 0.5f + c + b;
|
||||
}
|
||||
|
||||
static real_t out_in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return (t < d / 2)
|
||||
? out(t * 2, b, c / 2, d)
|
||||
: in((t * 2) - d, b + c / 2, c / 2, d)
|
||||
;
|
||||
}
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// cubic
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace cubic {
|
||||
static real_t in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c * (t /= d) * t * t + b;
|
||||
}
|
||||
|
||||
static real_t out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c * ((t = t / d - 1) * t * t + 1) + b;
|
||||
}
|
||||
|
||||
static real_t in_out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
|
||||
return c / 2 * ((t -= 2) * t * t + 2) + b;
|
||||
}
|
||||
|
||||
static real_t out_in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return (t < d / 2)
|
||||
? out(t * 2, b, c / 2, d)
|
||||
: in((t * 2) - d, b + c / 2, c / 2, d)
|
||||
;
|
||||
}
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// circ
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace circ {
|
||||
static real_t in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return -c * (sqrt(1 - (t /= d) * t) - 1) + b;
|
||||
}
|
||||
|
||||
static real_t out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c * sqrt(1 - (t = t / d - 1) * t) + b;
|
||||
}
|
||||
|
||||
static real_t in_out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
if ((t /= d / 2) < 1) return -c / 2 * (sqrt(1 - t * t) - 1) + b;
|
||||
return c / 2 * (sqrt(1 - t * (t -= 2)) + 1) + b;
|
||||
}
|
||||
|
||||
static real_t out_in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return (t < d / 2)
|
||||
? out(t * 2, b, c / 2, d)
|
||||
: in((t * 2) - d, b + c / 2, c / 2, d)
|
||||
;
|
||||
}
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// bounce
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace bounce {
|
||||
static real_t out(real_t t, real_t b, real_t c, real_t d);
|
||||
|
||||
static real_t in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return c - out(d - t, 0, c, d) + b;
|
||||
}
|
||||
|
||||
static real_t out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
if ((t /= d) < (1 / 2.75f)) {
|
||||
return c*(7.5625f*t*t) + b;
|
||||
} else if (t < (2/2.75f)) {
|
||||
float postFix = t-=(1.5f/2.75f);
|
||||
return c*(7.5625f*(postFix)*t + .75f) + b;
|
||||
} else if (t < (2.5/2.75)) {
|
||||
float postFix = t-=(2.25f/2.75f);
|
||||
return c*(7.5625f*(postFix)*t + .9375f) + b;
|
||||
} else {
|
||||
float postFix = t-=(2.625f/2.75f);
|
||||
return c*(7.5625f*(postFix)*t + .984375f) + b;
|
||||
}
|
||||
}
|
||||
|
||||
static real_t in_out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return (t < d / 2)
|
||||
? in(t * 2, b, c / 2, d)
|
||||
: out((t * 2) - d, b + c / 2, c / 2, d)
|
||||
;
|
||||
}
|
||||
|
||||
static real_t out_in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return (t < d / 2)
|
||||
? out(t * 2, b, c / 2, d)
|
||||
: in((t * 2) - d, b + c / 2, c / 2, d)
|
||||
;
|
||||
}
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// back
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace back {
|
||||
static real_t in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
float s = 1.70158f;
|
||||
float postFix = t /= d;
|
||||
return c * (postFix) * t * ((s + 1) * t - s) + b;
|
||||
}
|
||||
|
||||
static real_t out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
float s = 1.70158f;
|
||||
return c * ((t = t / d- 1) * t * ((s + 1) * t + s) + 1) + b;
|
||||
}
|
||||
|
||||
static real_t in_out(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
float s = 1.70158f;
|
||||
if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525f)) + 1) * t - s)) + b;
|
||||
float postFix = t -= 2;
|
||||
return c / 2 * ((postFix) * t * (((s *= (1.525f)) + 1) * t + s) + 2) + b;
|
||||
}
|
||||
|
||||
static real_t out_in(real_t t, real_t b, real_t c, real_t d)
|
||||
{
|
||||
return (t < d / 2)
|
||||
? out(t * 2, b, c / 2, d)
|
||||
: in((t * 2) - d, b + c / 2, c / 2, d)
|
||||
;
|
||||
}
|
||||
};
|
||||
|
||||
Tween::interpolater Tween::interpolaters[Tween::TRANS_COUNT][Tween::EASE_COUNT] = {
|
||||
{ &linear::in, &linear::out, &linear::in_out, &linear::out_in },
|
||||
{ &sine::in, &sine::out, &sine::in_out, &sine::out_in },
|
||||
{ &quint::in, &quint::out, &quint::in_out, &quint::out_in },
|
||||
{ &quart::in, &quart::out, &quart::in_out, &quart::out_in },
|
||||
{ &quad::in, &quad::out, &quad::in_out, &quad::out_in },
|
||||
{ &expo::in, &expo::out, &expo::in_out, &expo::out_in },
|
||||
{ &elastic::in, &elastic::out, &elastic::in_out, &elastic::out_in },
|
||||
{ &cubic::in, &cubic::out, &cubic::in_out, &cubic::out_in },
|
||||
{ &circ::in, &circ::out, &circ::in_out, &circ::out_in },
|
||||
{ &bounce::in, &bounce::out, &bounce::in_out, &bounce::out_in },
|
||||
{ &back::in, &back::out, &back::in_out, &back::out_in },
|
||||
};
|
||||
|
||||
real_t Tween::_run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d) {
|
||||
|
||||
interpolater cb = interpolaters[p_trans_type][p_ease_type];
|
||||
ERR_FAIL_COND_V(cb == NULL, b);
|
||||
return cb(t, b, c, d);
|
||||
}
|
||||
|
@ -108,6 +108,7 @@
|
||||
|
||||
#include "scene/animation/animation_player.h"
|
||||
#include "scene/animation/animation_tree_player.h"
|
||||
#include "scene/animation/tween.h"
|
||||
#include "scene/main/scene_main_loop.h"
|
||||
#include "scene/main/resource_preloader.h"
|
||||
#include "scene/resources/packed_scene.h"
|
||||
@ -369,6 +370,7 @@ void register_scene_types() {
|
||||
ObjectTypeDB::register_type<Spatial>();
|
||||
ObjectTypeDB::register_type<Skeleton>();
|
||||
ObjectTypeDB::register_type<AnimationPlayer>();
|
||||
ObjectTypeDB::register_type<Tween>();
|
||||
|
||||
OS::get_singleton()->yield(); //may take time to init
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user