diff options
Diffstat (limited to 'modules/gdscript/gdscript_functions.cpp')
-rw-r--r-- | modules/gdscript/gdscript_functions.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index c6066ceefb..ca0a9582a7 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -84,6 +84,8 @@ const char *GDScriptFunctions::get_func_name(Function p_func) { "rad2deg", "linear2db", "db2linear", + "polar2cartesian", + "cartesian2polar", "wrapi", "wrapf", "max", @@ -408,6 +410,22 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ VALIDATE_ARG_NUM(0); r_ret = Math::db2linear((double)*p_args[0]); } break; + case MATH_POLAR2CARTESIAN: { + VALIDATE_ARG_COUNT(2); + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + double r = *p_args[0]; + double th = *p_args[1]; + r_ret = Vector2(r * Math::cos(th), r * Math::sin(th)); + } break; + case MATH_CARTESIAN2POLAR: { + VALIDATE_ARG_COUNT(2); + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + double x = *p_args[0]; + double y = *p_args[1]; + r_ret = Vector2(Math::sqrt(x * x + y * y), Math::atan2(y, x)); + } break; case MATH_WRAP: { VALIDATE_ARG_COUNT(3); r_ret = Math::wrapi((int64_t)*p_args[0], (int64_t)*p_args[1], (int64_t)*p_args[2]); @@ -1296,6 +1314,8 @@ bool GDScriptFunctions::is_deterministic(Function p_func) { case MATH_RAD2DEG: case MATH_LINEAR2DB: case MATH_DB2LINEAR: + case MATH_POLAR2CARTESIAN: + case MATH_CARTESIAN2POLAR: case MATH_WRAP: case MATH_WRAPF: case LOGIC_MAX: @@ -1526,6 +1546,16 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { mi.return_val.type = Variant::REAL; return mi; } break; + case MATH_POLAR2CARTESIAN: { + MethodInfo mi("polar2cartesian", PropertyInfo(Variant::REAL, "r"), PropertyInfo(Variant::REAL, "th")); + mi.return_val.type = Variant::VECTOR2; + return mi; + } break; + case MATH_CARTESIAN2POLAR: { + MethodInfo mi("cartesian2polar", PropertyInfo(Variant::REAL, "x"), PropertyInfo(Variant::REAL, "y")); + mi.return_val.type = Variant::VECTOR2; + return mi; + } break; case MATH_WRAP: { MethodInfo mi("wrapi", PropertyInfo(Variant::INT, "value"), PropertyInfo(Variant::INT, "min"), PropertyInfo(Variant::INT, "max")); mi.return_val.type = Variant::INT; |