diff --git a/include/godot_cpp/core/math.hpp b/include/godot_cpp/core/math.hpp index 1949360a9..fd843ccb5 100644 --- a/include/godot_cpp/core/math.hpp +++ b/include/godot_cpp/core/math.hpp @@ -320,14 +320,14 @@ inline float sinh(float p_x) { } inline float sinc(float p_x) { - return p_x == 0 ? 1 : ::sin(p_x) / p_x; + return p_x == 0 ? 1 : ::sinf(p_x) / p_x; } inline double sinc(double p_x) { return p_x == 0 ? 1 : ::sin(p_x) / p_x; } inline float sincn(float p_x) { - return (float)sinc(Math_PI * p_x); + return sinc((float)Math_PI * p_x); } inline double sincn(double p_x) { return sinc(Math_PI * p_x); @@ -653,8 +653,8 @@ inline bool is_equal_approx(double a, double b) { return true; } // Then check for approximate equality. - double tolerance = CMP_EPSILON * abs(a); - if (tolerance < CMP_EPSILON) { + double tolerance = (double)CMP_EPSILON * abs(a); + if (tolerance < (double)CMP_EPSILON) { tolerance = CMP_EPSILON; } return abs(a - b) < tolerance; @@ -670,7 +670,7 @@ inline bool is_equal_approx(double a, double b, double tolerance) { } inline bool is_zero_approx(double s) { - return abs(s) < CMP_EPSILON; + return abs(s) < (double)CMP_EPSILON; } inline float absf(float g) { @@ -766,10 +766,10 @@ inline double pingpong(double value, double length) { // This function should be as fast as possible and rounding mode should not matter. inline int fast_ftoi(float a) { - static int b; + int b; -#if (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603) || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // windows 8 phone? - b = (int)((a > 0.0) ? (a + 0.5) : (a - 0.5)); +#if (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603) || (defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) // windows 8 phone? + b = (int)((a > 0.0f) ? (a + 0.5f) : (a - 0.5f)); #elif defined(_MSC_VER) && _MSC_VER < 1800 __asm fld a __asm fistp b @@ -788,9 +788,10 @@ inline int fast_ftoi(float a) { return b; } -inline double snapped(double p_value, double p_step) { +template +inline T snapped(T p_value, T p_step) { if (p_step != 0) { - p_value = Math::floor(p_value / p_step + 0.5) * p_step; + p_value = Math::floor(p_value / p_step + 0.5f) * p_step; } return p_value; } diff --git a/include/godot_cpp/templates/hashfuncs.hpp b/include/godot_cpp/templates/hashfuncs.hpp index 40b10a9e2..52c6a1d8c 100644 --- a/include/godot_cpp/templates/hashfuncs.hpp +++ b/include/godot_cpp/templates/hashfuncs.hpp @@ -154,7 +154,7 @@ static _FORCE_INLINE_ uint32_t hash_murmur3_one_double(double p_in, uint32_t p_s } u; // Normalize +/- 0.0 and NaN values so they hash the same. - if (p_in == 0.0f) { + if (p_in == 0.0) { u.d = 0.0; } else if (Math::is_nan(p_in)) { u.d = NAN; @@ -242,7 +242,7 @@ static _FORCE_INLINE_ uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev } u; // Normalize +/- 0.0 and NaN values so they hash the same. - if (p_in == 0.0f) { + if (p_in == 0.0) { u.d = 0.0; } else if (Math::is_nan(p_in)) { u.d = NAN; @@ -271,7 +271,7 @@ static _FORCE_INLINE_ uint64_t hash_djb2_one_float_64(double p_in, uint64_t p_pr } u; // Normalize +/- 0.0 and NaN values so they hash the same. - if (p_in == 0.0f) { + if (p_in == 0.0) { u.d = 0.0; } else if (Math::is_nan(p_in)) { u.d = NAN; diff --git a/include/godot_cpp/variant/color.hpp b/include/godot_cpp/variant/color.hpp index 0e837bc9f..7fa3b069b 100644 --- a/include/godot_cpp/variant/color.hpp +++ b/include/godot_cpp/variant/color.hpp @@ -141,9 +141,9 @@ struct _NO_DISCARD_ Color { float cMax = MAX(cRed, MAX(cGreen, cBlue)); - float expp = MAX(-B - 1.0f, floor(Math::log(cMax) / (real_t)Math_LN2)) + 1.0f + B; + float expp = MAX(-B - 1.0f, Math::floor(Math::log(cMax) / (real_t)Math_LN2)) + 1.0f + B; - float sMax = (float)floor((cMax / Math::pow(2.0f, expp - B - N)) + 0.5f); + float sMax = Math::floor((cMax / Math::pow(2.0f, expp - B - N)) + 0.5f); float exps = expp + 1.0f; @@ -151,9 +151,9 @@ struct _NO_DISCARD_ Color { exps = expp; } - float sRed = Math::floor((cRed / pow(2.0f, exps - B - N)) + 0.5f); - float sGreen = Math::floor((cGreen / pow(2.0f, exps - B - N)) + 0.5f); - float sBlue = Math::floor((cBlue / pow(2.0f, exps - B - N)) + 0.5f); + float sRed = Math::floor((cRed / Math::pow(2.0f, exps - B - N)) + 0.5f); + float sGreen = Math::floor((cGreen / Math::pow(2.0f, exps - B - N)) + 0.5f); + float sBlue = Math::floor((cBlue / Math::pow(2.0f, exps - B - N)) + 0.5f); return (uint32_t(Math::fast_ftoi(sRed)) & 0x1FF) | ((uint32_t(Math::fast_ftoi(sGreen)) & 0x1FF) << 9) | ((uint32_t(Math::fast_ftoi(sBlue)) & 0x1FF) << 18) | ((uint32_t(Math::fast_ftoi(exps)) & 0x1F) << 27); } diff --git a/include/godot_cpp/variant/projection.hpp b/include/godot_cpp/variant/projection.hpp index 1de6c0244..19d17b8fe 100644 --- a/include/godot_cpp/variant/projection.hpp +++ b/include/godot_cpp/variant/projection.hpp @@ -98,7 +98,7 @@ struct _NO_DISCARD_ Projection { Projection jitter_offseted(const Vector2 &p_offset) const; static real_t get_fovy(real_t p_fovx, real_t p_aspect) { - return Math::rad_to_deg(Math::atan(p_aspect * Math::tan(Math::deg_to_rad(p_fovx) * 0.5)) * 2.0); + return Math::rad_to_deg(Math::atan(p_aspect * Math::tan(Math::deg_to_rad(p_fovx) * 0.5f)) * 2.0f); } real_t get_z_far() const; diff --git a/include/godot_cpp/variant/vector2.hpp b/include/godot_cpp/variant/vector2.hpp index 8f08985f3..97826c5cb 100644 --- a/include/godot_cpp/variant/vector2.hpp +++ b/include/godot_cpp/variant/vector2.hpp @@ -292,13 +292,13 @@ Vector2 Vector2::bezier_interpolate(const Vector2 &p_control_1, const Vector2 &p Vector2 res = *this; /* Formula from Wikipedia article on Bezier curves. */ - real_t omt = (1.0 - p_t); + real_t omt = (1.0f - p_t); real_t omt2 = omt * omt; real_t omt3 = omt2 * omt; real_t t2 = p_t * p_t; real_t t3 = t2 * p_t; - return res * omt3 + p_control_1 * omt2 * p_t * 3.0 + p_control_2 * omt * t2 * 3.0 + p_end * t3; + return res * omt3 + p_control_1 * omt2 * p_t * 3.0f + p_control_2 * omt * t2 * 3.0f + p_end * t3; } Vector2 Vector2::direction_to(const Vector2 &p_to) const { diff --git a/include/godot_cpp/variant/vector3.hpp b/include/godot_cpp/variant/vector3.hpp index f256c3895..971189e14 100644 --- a/include/godot_cpp/variant/vector3.hpp +++ b/include/godot_cpp/variant/vector3.hpp @@ -277,13 +277,13 @@ Vector3 Vector3::bezier_interpolate(const Vector3 &p_control_1, const Vector3 &p Vector3 res = *this; /* Formula from Wikipedia article on Bezier curves. */ - real_t omt = (1.0 - p_t); + real_t omt = (1.0f - p_t); real_t omt2 = omt * omt; real_t omt3 = omt2 * omt; real_t t2 = p_t * p_t; real_t t3 = t2 * p_t; - return res * omt3 + p_control_1 * omt2 * p_t * 3.0 + p_control_2 * omt * t2 * 3.0 + p_end * t3; + return res * omt3 + p_control_1 * omt2 * p_t * 3.0f + p_control_2 * omt * t2 * 3.0f + p_end * t3; } real_t Vector3::distance_to(const Vector3 &p_to) const { diff --git a/src/variant/basis.cpp b/src/variant/basis.cpp index d8a991917..1efd591a5 100644 --- a/src/variant/basis.cpp +++ b/src/variant/basis.cpp @@ -470,7 +470,7 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { if (rows[1][0] == 0 && rows[0][1] == 0 && rows[1][2] == 0 && rows[2][1] == 0 && rows[1][1] == 1) { // return the simplest form (human friendlier in editor and scripts) euler.x = 0; - euler.y = atan2(rows[0][2], rows[0][0]); + euler.y = Math::atan2(rows[0][2], rows[0][0]); euler.z = 0; } else { euler.x = Math::atan2(-rows[1][2], rows[2][2]); @@ -479,12 +479,12 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { } } else { euler.x = Math::atan2(rows[2][1], rows[1][1]); - euler.y = -Math_PI / 2.0f; + euler.y = (real_t)(-Math_PI / 2.0); euler.z = 0.0f; } } else { euler.x = Math::atan2(rows[2][1], rows[1][1]); - euler.y = Math_PI / 2.0f; + euler.y = (real_t)(Math_PI / 2.0); euler.z = 0.0f; } return euler; @@ -508,13 +508,13 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { // It's -1 euler.x = -Math::atan2(rows[1][2], rows[2][2]); euler.y = 0.0f; - euler.z = Math_PI / 2.0f; + euler.z = (real_t)(Math_PI / 2.0); } } else { // It's 1 euler.x = -Math::atan2(rows[1][2], rows[2][2]); euler.y = 0.0f; - euler.z = -Math_PI / 2.0f; + euler.z = (real_t)(-Math_PI / 2.0); } return euler; } @@ -535,22 +535,22 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { // is this a pure X rotation? if (rows[1][0] == 0 && rows[0][1] == 0 && rows[0][2] == 0 && rows[2][0] == 0 && rows[0][0] == 1) { // return the simplest form (human friendlier in editor and scripts) - euler.x = atan2(-m12, rows[1][1]); + euler.x = Math::atan2(-m12, rows[1][1]); euler.y = 0; euler.z = 0; } else { - euler.x = asin(-m12); - euler.y = atan2(rows[0][2], rows[2][2]); - euler.z = atan2(rows[1][0], rows[1][1]); + euler.x = Math::asin(-m12); + euler.y = Math::atan2(rows[0][2], rows[2][2]); + euler.z = Math::atan2(rows[1][0], rows[1][1]); } } else { // m12 == -1 - euler.x = Math_PI * 0.5f; - euler.y = atan2(rows[0][1], rows[0][0]); + euler.x = (real_t)(Math_PI * 0.5); + euler.y = Math::atan2(rows[0][1], rows[0][0]); euler.z = 0; } } else { // m12 == 1 - euler.x = -Math_PI * 0.5f; - euler.y = -atan2(rows[0][1], rows[0][0]); + euler.x = (real_t)(-Math_PI * 0.5); + euler.y = -Math::atan2(rows[0][1], rows[0][0]); euler.z = 0; } @@ -575,13 +575,13 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { // It's -1 euler.x = Math::atan2(rows[2][1], rows[2][2]); euler.y = 0.0f; - euler.z = -Math_PI / 2.0f; + euler.z = (real_t)(-Math_PI / 2.0); } } else { // It's 1 euler.x = Math::atan2(rows[2][1], rows[2][2]); euler.y = 0.0f; - euler.z = Math_PI / 2.0f; + euler.z = (real_t)(Math_PI / 2.0); } return euler; } @@ -601,13 +601,13 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { euler.z = Math::atan2(-rows[0][1], rows[1][1]); } else { // It's -1 - euler.x = -Math_PI / 2.0f; + euler.x = (real_t)(-Math_PI / 2.0); euler.y = Math::atan2(rows[0][2], rows[0][0]); euler.z = 0; } } else { // It's 1 - euler.x = Math_PI / 2.0f; + euler.x = (real_t)(Math_PI / 2.0); euler.y = Math::atan2(rows[0][2], rows[0][0]); euler.z = 0; } @@ -630,13 +630,13 @@ Vector3 Basis::get_euler(EulerOrder p_order) const { } else { // It's -1 euler.x = 0; - euler.y = Math_PI / 2.0f; + euler.y = (real_t)(Math_PI / 2.0); euler.z = -Math::atan2(rows[0][1], rows[1][1]); } } else { // It's 1 euler.x = 0; - euler.y = -Math_PI / 2.0f; + euler.y = (real_t)(-Math_PI / 2.0); euler.z = -Math::atan2(rows[0][1], rows[1][1]); } return euler; @@ -816,7 +816,7 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { return; } // As we have reached here there are no singularities so we can handle normally. - double s = Math::sqrt((rows[2][1] - rows[1][2]) * (rows[2][1] - rows[1][2]) + (rows[0][2] - rows[2][0]) * (rows[0][2] - rows[2][0]) + (rows[1][0] - rows[0][1]) * (rows[1][0] - rows[0][1])); // Used to normalize. + real_t s = Math::sqrt((rows[2][1] - rows[1][2]) * (rows[2][1] - rows[1][2]) + (rows[0][2] - rows[2][0]) * (rows[0][2] - rows[2][0]) + (rows[1][0] - rows[0][1]) * (rows[1][0] - rows[0][1])); // Used to normalize. if (Math::abs(s) < CMP_EPSILON) { // Prevent divide by zero, should not happen if matrix is orthogonal and should be caught by singularity test above. @@ -939,9 +939,9 @@ void Basis::rotate_sh(real_t *p_values) { const static real_t s_c_scale = 1.0 / 0.91529123286551084; const static real_t s_c_scale_inv = 0.91529123286551084; - const static real_t s_rc2 = 1.5853309190550713 * s_c_scale; + const static real_t s_rc2 = (real_t)1.5853309190550713 * s_c_scale; const static real_t s_c4_div_c3 = s_c4 / s_c3; - const static real_t s_c4_div_c3_x2 = (s_c4 / s_c3) * 2.0; + const static real_t s_c4_div_c3_x2 = (s_c4 / s_c3) * (real_t)2.0; const static real_t s_scale_dst2 = s_c3 * s_c_scale_inv; const static real_t s_scale_dst4 = s_c5 * s_c_scale_inv; diff --git a/src/variant/projection.cpp b/src/variant/projection.cpp index ddedc93f9..d706cc357 100644 --- a/src/variant/projection.cpp +++ b/src/variant/projection.cpp @@ -253,11 +253,11 @@ Projection Projection ::jitter_offseted(const Vector2 &p_offset) const { void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov) { if (p_flip_fov) { - p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect); + p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0f / p_aspect); } real_t sine, cotangent, deltaZ; - real_t radians = Math::deg_to_rad(p_fovy_degrees / 2.0); + real_t radians = Math::deg_to_rad(p_fovy_degrees / 2.0f); deltaZ = p_z_far - p_z_near; sine = Math::sin(radians); @@ -279,30 +279,30 @@ void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist) { if (p_flip_fov) { - p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect); + p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0f / p_aspect); } real_t left, right, modeltranslation, ymax, xmax, frustumshift; - ymax = p_z_near * tan(Math::deg_to_rad(p_fovy_degrees / 2.0)); + ymax = p_z_near * Math::tan(Math::deg_to_rad(p_fovy_degrees / 2.0f)); xmax = ymax * p_aspect; - frustumshift = (p_intraocular_dist / 2.0) * p_z_near / p_convergence_dist; + frustumshift = (p_intraocular_dist / 2.0f) * p_z_near / p_convergence_dist; switch (p_eye) { case 1: { // left eye left = -xmax + frustumshift; right = xmax + frustumshift; - modeltranslation = p_intraocular_dist / 2.0; + modeltranslation = p_intraocular_dist / 2.0f; } break; case 2: { // right eye left = -xmax - frustumshift; right = xmax - frustumshift; - modeltranslation = -p_intraocular_dist / 2.0; + modeltranslation = -p_intraocular_dist / 2.0f; } break; default: { // mono, should give the same result as set_perspective(p_fovy_degrees,p_aspect,p_z_near,p_z_far,p_flip_fov) left = -xmax; right = xmax; - modeltranslation = 0.0; + modeltranslation = 0.0f; } break; } @@ -317,13 +317,13 @@ void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t void Projection::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_dist, real_t p_display_width, real_t p_display_to_lens, real_t p_oversample, real_t p_z_near, real_t p_z_far) { // we first calculate our base frustum on our values without taking our lens magnification into account. - real_t f1 = (p_intraocular_dist * 0.5) / p_display_to_lens; - real_t f2 = ((p_display_width - p_intraocular_dist) * 0.5) / p_display_to_lens; - real_t f3 = (p_display_width / 4.0) / p_display_to_lens; + real_t f1 = (p_intraocular_dist * 0.5f) / p_display_to_lens; + real_t f2 = ((p_display_width - p_intraocular_dist) * 0.5f) / p_display_to_lens; + real_t f3 = (p_display_width / 4.0f) / p_display_to_lens; // now we apply our oversample factor to increase our FOV. how much we oversample is always a balance we strike between performance and how much // we're willing to sacrifice in FOV. - real_t add = ((f1 + f2) * (p_oversample - 1.0)) / 2.0; + real_t add = ((f1 + f2) * (p_oversample - 1.0f)) / 2.0f; f1 += add; f2 += add; f3 *= p_oversample; @@ -346,13 +346,13 @@ void Projection::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_di void Projection::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) { set_identity(); - columns[0][0] = 2.0 / (p_right - p_left); + columns[0][0] = 2.0f / (p_right - p_left); columns[3][0] = -((p_right + p_left) / (p_right - p_left)); - columns[1][1] = 2.0 / (p_top - p_bottom); + columns[1][1] = 2.0f / (p_top - p_bottom); columns[3][1] = -((p_top + p_bottom) / (p_top - p_bottom)); - columns[2][2] = -2.0 / (p_zfar - p_znear); + columns[2][2] = -2.0f / (p_zfar - p_znear); columns[3][2] = -((p_zfar + p_znear) / (p_zfar - p_znear)); - columns[3][3] = 1.0; + columns[3][3] = 1.0f; } void Projection::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov) { @@ -670,7 +670,7 @@ void Projection::invert() { } /** Replace pivot by reciprocal (at last we can touch it). **/ - columns[k][k] = 1.0 / pvt_val; + columns[k][k] = 1.0f / pvt_val; } /* That was most of the work, one final pass of row/column interchange */ @@ -804,11 +804,11 @@ real_t Projection::get_aspect() const { int Projection::get_pixels_per_meter(int p_for_pixel_width) const { Vector3 result = xform(Vector3(1, 0, -1)); - return int((result.x * 0.5 + 0.5) * p_for_pixel_width); + return int((result.x * 0.5f + 0.5f) * p_for_pixel_width); } bool Projection::is_orthogonal() const { - return columns[3][3] == 1.0; + return columns[3][3] == 1.0f; } real_t Projection::get_fov() const { @@ -821,7 +821,7 @@ real_t Projection::get_fov() const { right_plane.normalize(); if ((matrix[8] == 0) && (matrix[9] == 0)) { - return Math::rad_to_deg(Math::acos(Math::abs(right_plane.normal.x))) * 2.0; + return Math::rad_to_deg(Math::acos(Math::abs(right_plane.normal.x))) * 2.0f; } else { // our frustum is asymmetrical need to calculate the left planes angle separately.. Plane left_plane = Plane(matrix[3] + matrix[0], @@ -839,8 +839,8 @@ float Projection::get_lod_multiplier() const { return get_viewport_half_extents().x; } else { float zn = get_z_near(); - float width = get_viewport_half_extents().x * 2.0; - return 1.0 / (zn / width); + float width = get_viewport_half_extents().x * 2.0f; + return 1.0f / (zn / width); } // Usage is lod_size / (lod_distance * multiplier) < threshold diff --git a/src/variant/quaternion.cpp b/src/variant/quaternion.cpp index 3dd7af54a..6f18507ff 100644 --- a/src/variant/quaternion.cpp +++ b/src/variant/quaternion.cpp @@ -137,7 +137,7 @@ Quaternion Quaternion::slerp(const Quaternion &p_to, real_t p_weight) const { // standard case (slerp) omega = Math::acos(cosom); sinom = Math::sin(omega); - scale0 = Math::sin((1.0 - p_weight) * omega) / sinom; + scale0 = Math::sin((1.0f - p_weight) * omega) / sinom; scale1 = Math::sin(p_weight * omega) / sinom; } else { // "from" and "to" quaternions are very close