diff options
author | Sergey Lapin <slapinid@gmail.com> | 2016-03-30 15:54:11 +0300 |
---|---|---|
committer | Sergey Lapin <slapinid@gmail.com> | 2016-03-31 12:44:25 +0300 |
commit | e4fea5d5f9906a022ab0e83dc7a2070b8d688599 (patch) | |
tree | 1848dbce783bcf2d49fef0ca589135db8412d8d3 /modules | |
parent | 8d7a94389aeefb805fb2840c6a69af95f563f89b (diff) |
Added speed setting
Diffstat (limited to 'modules')
-rw-r--r-- | modules/ik/ik.cpp | 25 | ||||
-rw-r--r-- | modules/ik/ik.h | 3 |
2 files changed, 27 insertions, 1 deletions
diff --git a/modules/ik/ik.cpp b/modules/ik/ik.cpp index 2133894eea..660175587a 100644 --- a/modules/ik/ik.cpp +++ b/modules/ik/ik.cpp @@ -196,6 +196,25 @@ float InverseKinematics::get_precision() const return precision; } +void InverseKinematics::set_speed(float p) +{ + + if (is_inside_tree()) + _check_unbind(); + + speed=p; + + if (is_inside_tree()) + _check_bind(); +} + +float InverseKinematics::get_speed() const +{ + + return speed; +} + + void InverseKinematics::_notification(int p_what) { @@ -254,7 +273,7 @@ void InverseKinematics::_notification(int p_what) Quat q2 = Quat(mod2.basis).normalized(); if (psign < 0.0) q2 = q2.inverse(); - Quat q = q1.slerp(q2, 0.2 / (1.0 + 500.0 * depth)).normalized(); + Quat q = q1.slerp(q2, speed / (1.0 + 500.0 * depth)).normalized(); Transform fin = Transform(q); fin.origin = mod.origin; skel->set_bone_global_pose(cur_bone, fin); @@ -282,9 +301,12 @@ void InverseKinematics::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_chain_size"),&InverseKinematics::get_chain_size); ObjectTypeDB::bind_method(_MD("set_precision","precision"),&InverseKinematics::set_precision); ObjectTypeDB::bind_method(_MD("get_precision"),&InverseKinematics::get_precision); + ObjectTypeDB::bind_method(_MD("set_speed","speed"),&InverseKinematics::set_speed); + ObjectTypeDB::bind_method(_MD("get_speed"),&InverseKinematics::get_speed); ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations"), _SCS("set_iterations"), _SCS("get_iterations")); ADD_PROPERTY(PropertyInfo(Variant::INT, "chain_size"), _SCS("set_chain_size"), _SCS("get_chain_size")); ADD_PROPERTY(PropertyInfo(Variant::REAL, "precision"), _SCS("set_precision"), _SCS("get_precision")); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "speed"), _SCS("set_speed"), _SCS("get_speed")); } InverseKinematics::InverseKinematics() @@ -293,6 +315,7 @@ InverseKinematics::InverseKinematics() chain_size = 2; iterations = 100; precision = 0.001; + speed = 0.2; } diff --git a/modules/ik/ik.h b/modules/ik/ik.h index 0fa037d02f..f126e37754 100644 --- a/modules/ik/ik.h +++ b/modules/ik/ik.h @@ -44,6 +44,7 @@ class InverseKinematics : public Spatial { void _check_unbind(); int iterations; float precision; + float speed; protected: bool _set(const StringName& p_name, const Variant& p_value); @@ -62,6 +63,8 @@ public: int get_chain_size() const; void set_precision(float p); float get_precision() const; + void set_speed(float p); + float get_speed() const; InverseKinematics(); }; |