From c00427add34f505cff275ea33423f1053423d646 Mon Sep 17 00:00:00 2001 From: Giacom Date: Sun, 7 Apr 2019 22:40:56 +0100 Subject: Added move_toward functions for float, Vector2 and Vector3 --- .../doc_classes/VisualScriptBuiltinFunc.xml | 75 +++++++++++----------- .../visual_script/visual_script_builtin_funcs.cpp | 20 ++++++ .../visual_script/visual_script_builtin_funcs.h | 1 + 3 files changed, 60 insertions(+), 36 deletions(-) (limited to 'modules/visual_script') diff --git a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml index 74d5f29c02..21e8a38c16 100644 --- a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml +++ b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml @@ -102,114 +102,117 @@ - + + Moves the number toward a value, based on the third input. + + Return the result of 'value' decreased by 'step' * 'amount'. - + Randomize the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time. - + Return a random 32 bits integer value. To obtain a random value between 0 to N (where N is smaller than 2^32 - 1), you can use it with the remainder function. - + Return a random floating-point value between 0 and 1. To obtain a random value between 0 to N, you can use it with multiplication. - + Return a random floating-point value between the two inputs. - + Set the seed for the random number generator. - + Return a random value from the given seed, along with the new seed. - + Convert the input from degrees to radians. - + Convert the input from radians to degrees. - + Convert the input from linear volume to decibel volume. - + Convert the input from decibel volume to linear volume. - + Converts a 2D point expressed in the polar coordinate system (a distance from the origin [code]r[/code] and an angle [code]th[/code]) to the cartesian coordinate system (x and y axis). - + Converts a 2D point expressed in the cartesian coordinate system (x and y axis) to the polar coordinate system (a distance from the origin and an angle). - + - + - + Return the greater of the two numbers, also known as their maximum. - + Return the lesser of the two numbers, also known as their minimum. - + Return the input clamped inside the given range, ensuring the result is never outside it. Equivalent to [code]min(max(input, range_low), range_high)[/code]. - + Return the nearest power of 2 to the input. - + Create a [WeakRef] from the input. - + Create a [FuncRef] from the input. - + Convert between types. - + Return the type of the input as an integer. Check [enum Variant.Type] for the integers that might be returned. - + Checks if a type is registered in the [ClassDB]. - + Return a character with the given ascii value. - + Convert the input to a string. - + Print the given string to the output window. - + Print the given string to the standard error output. - + Print the given string to the standard output, without adding a newline. - + Serialize a [Variant] to a string. - + Deserialize a [Variant] from a string serialized using [code]VAR_TO_STR[/code]. - + Serialize a [Variant] to a [PoolByteArray]. - + Deserialize a [Variant] from a [PoolByteArray] serialized using [code]VAR_TO_BYTES[/code]. - + Return the [Color] with the given name and alpha ranging from 0 to 1. Note: names are defined in color_names.inc. - + Return a number smoothly interpolated between the first two inputs, based on the third input. Similar to [code]MATH_LERP[/code], but interpolates faster at the beginning and slower at the end. Using Hermite interpolation formula: [codeblock] var t = clamp((weight - from) / (to - from), 0.0, 1.0) return t * t * (3.0 - 2.0 * t) [/codeblock] - + The maximum value the [member function] property can have. diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index d207656705..75b79f8929 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -68,6 +68,7 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX "lerp", "inverse_lerp", "range_lerp", + "move_toward", "dectime", "randomize", "randi", @@ -206,6 +207,7 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) { case MATH_LERP: case MATH_INVERSE_LERP: case MATH_SMOOTHSTEP: + case MATH_MOVE_TOWARD: case MATH_DECTIME: case MATH_WRAP: case MATH_WRAPF: @@ -347,6 +349,14 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const else return PropertyInfo(Variant::REAL, "weight"); } break; + case MATH_MOVE_TOWARD: { + if (p_idx == 0) + return PropertyInfo(Variant::REAL, "from"); + else if (p_idx == 1) + return PropertyInfo(Variant::REAL, "to"); + else + return PropertyInfo(Variant::REAL, "delta"); + } break; case MATH_DECTIME: { if (p_idx == 0) return PropertyInfo(Variant::REAL, "value"); @@ -580,6 +590,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons case MATH_INVERSE_LERP: case MATH_RANGE_LERP: case MATH_SMOOTHSTEP: + case MATH_MOVE_TOWARD: case MATH_DECTIME: { t = Variant::REAL; @@ -916,6 +927,13 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in VALIDATE_ARG_NUM(2); *r_return = Math::smoothstep((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; + case VisualScriptBuiltinFunc::MATH_MOVE_TOWARD: { + + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + VALIDATE_ARG_NUM(2); + *r_return = Math::move_toward((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); + } break; case VisualScriptBuiltinFunc::MATH_DECTIME: { VALIDATE_ARG_NUM(0); @@ -1363,6 +1381,7 @@ void VisualScriptBuiltinFunc::_bind_methods() { BIND_ENUM_CONSTANT(MATH_LERP); BIND_ENUM_CONSTANT(MATH_INVERSE_LERP); BIND_ENUM_CONSTANT(MATH_RANGE_LERP); + BIND_ENUM_CONSTANT(MATH_MOVE_TOWARD); BIND_ENUM_CONSTANT(MATH_DECTIME); BIND_ENUM_CONSTANT(MATH_RANDOMIZE); BIND_ENUM_CONSTANT(MATH_RAND); @@ -1453,6 +1472,7 @@ void register_visual_script_builtin_func_node() { VisualScriptLanguage::singleton->add_register_func("functions/built_in/inverse_lerp", create_builtin_func_node); VisualScriptLanguage::singleton->add_register_func("functions/built_in/range_lerp", create_builtin_func_node); VisualScriptLanguage::singleton->add_register_func("functions/built_in/smoothstep", create_builtin_func_node); + VisualScriptLanguage::singleton->add_register_func("functions/built_in/move_toward", create_builtin_func_node); VisualScriptLanguage::singleton->add_register_func("functions/built_in/dectime", create_builtin_func_node); VisualScriptLanguage::singleton->add_register_func("functions/built_in/randomize", create_builtin_func_node); VisualScriptLanguage::singleton->add_register_func("functions/built_in/rand", create_builtin_func_node); diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index 50854c16b1..3e452cd94f 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -67,6 +67,7 @@ public: MATH_LERP, MATH_INVERSE_LERP, MATH_RANGE_LERP, + MATH_MOVE_TOWARD, MATH_DECTIME, MATH_RANDOMIZE, MATH_RAND, -- cgit v1.2.3