diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/math/camera_matrix.cpp | 4 | ||||
-rw-r--r-- | core/math/color.cpp | 2 | ||||
-rw-r--r-- | core/math/color.h | 13 | ||||
-rw-r--r-- | core/math/geometry_3d.cpp | 15 | ||||
-rw-r--r-- | core/math/math_funcs.h | 8 | ||||
-rw-r--r-- | core/variant/variant.cpp | 2 | ||||
-rw-r--r-- | core/variant/variant_construct.cpp | 2 |
7 files changed, 33 insertions, 13 deletions
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index 7dbda1d149..1066cf5e30 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -89,7 +89,7 @@ void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_ } real_t sine, cotangent, deltaZ; - real_t radians = p_fovy_degrees / 2.0 * Math_PI / 180.0; + real_t radians = Math::deg2rad(p_fovy_degrees / 2.0); deltaZ = p_z_far - p_z_near; sine = Math::sin(radians); @@ -116,7 +116,7 @@ void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_ real_t left, right, modeltranslation, ymax, xmax, frustumshift; - ymax = p_z_near * tan(p_fovy_degrees * Math_PI / 360.0f); + ymax = p_z_near * tan(Math::deg2rad(p_fovy_degrees / 2.0)); xmax = ymax * p_aspect; frustumshift = (p_intraocular_dist / 2.0) * p_z_near / p_convergence_dist; diff --git a/core/math/color.cpp b/core/math/color.cpp index 0398d43838..e1b45cac9c 100644 --- a/core/math/color.cpp +++ b/core/math/color.cpp @@ -408,6 +408,8 @@ Color Color::get_named_color(int p_idx) { return named_colors[p_idx].color; } +// For a version that errors on invalid values instead of returning +// a default color, use the Color(String) constructor instead. Color Color::from_string(const String &p_string, const Color &p_default) { if (html_is_valid(p_string)) { return html(p_string); diff --git a/core/math/color.h b/core/math/color.h index d3b27a9c65..5eb8b1119a 100644 --- a/core/math/color.h +++ b/core/math/color.h @@ -241,6 +241,19 @@ struct Color { b = p_c.b; a = p_a; } + + Color(const String &p_code) { + if (html_is_valid(p_code)) { + *this = html(p_code); + } else { + *this = named(p_code); + } + } + + Color(const String &p_code, float p_a) { + *this = Color(p_code); + a = p_a; + } }; bool Color::operator<(const Color &p_color) const { diff --git a/core/math/geometry_3d.cpp b/core/math/geometry_3d.cpp index 553184303d..a4a7463bfd 100644 --- a/core/math/geometry_3d.cpp +++ b/core/math/geometry_3d.cpp @@ -777,10 +777,11 @@ Vector<Plane> Geometry3D::build_box_planes(const Vector3 &p_extents) { Vector<Plane> Geometry3D::build_cylinder_planes(real_t p_radius, real_t p_height, int p_sides, Vector3::Axis p_axis) { Vector<Plane> planes; + const double sides_step = Math_TAU / p_sides; for (int i = 0; i < p_sides; i++) { Vector3 normal; - normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_sides); - normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_sides); + normal[(p_axis + 1) % 3] = Math::cos(i * sides_step); + normal[(p_axis + 2) % 3] = Math::sin(i * sides_step); planes.push_back(Plane(normal, p_radius)); } @@ -805,10 +806,11 @@ Vector<Plane> Geometry3D::build_sphere_planes(real_t p_radius, int p_lats, int p axis_neg[(p_axis + 2) % 3] = 1.0; axis_neg[p_axis] = -1.0; + const double lon_step = Math_TAU / p_lons; for (int i = 0; i < p_lons; i++) { Vector3 normal; - normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_lons); - normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_lons); + normal[(p_axis + 1) % 3] = Math::cos(i * lon_step); + normal[(p_axis + 2) % 3] = Math::sin(i * lon_step); planes.push_back(Plane(normal, p_radius)); @@ -835,10 +837,11 @@ Vector<Plane> Geometry3D::build_capsule_planes(real_t p_radius, real_t p_height, axis_neg[(p_axis + 2) % 3] = 1.0; axis_neg[p_axis] = -1.0; + const double sides_step = Math_TAU / p_sides; for (int i = 0; i < p_sides; i++) { Vector3 normal; - normal[(p_axis + 1) % 3] = Math::cos(i * (2.0 * Math_PI) / p_sides); - normal[(p_axis + 2) % 3] = Math::sin(i * (2.0 * Math_PI) / p_sides); + normal[(p_axis + 1) % 3] = Math::cos(i * sides_step); + normal[(p_axis + 2) % 3] = Math::sin(i * sides_step); planes.push_back(Plane(normal, p_radius)); diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index c7d24e9c58..267f6a4fe2 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -223,11 +223,11 @@ public: return value; } - static _ALWAYS_INLINE_ double deg2rad(double p_y) { return p_y * Math_PI / 180.0; } - static _ALWAYS_INLINE_ float deg2rad(float p_y) { return p_y * Math_PI / 180.0; } + static _ALWAYS_INLINE_ double deg2rad(double p_y) { return p_y * (Math_PI / 180.0); } + static _ALWAYS_INLINE_ float deg2rad(float p_y) { return p_y * (Math_PI / 180.0); } - static _ALWAYS_INLINE_ double rad2deg(double p_y) { return p_y * 180.0 / Math_PI; } - static _ALWAYS_INLINE_ float rad2deg(float p_y) { return p_y * 180.0 / Math_PI; } + static _ALWAYS_INLINE_ double rad2deg(double p_y) { return p_y * (180.0 / Math_PI); } + static _ALWAYS_INLINE_ float rad2deg(float p_y) { return p_y * (180.0 / Math_PI); } static _ALWAYS_INLINE_ double lerp(double p_from, double p_to, double p_weight) { return p_from + (p_to - p_from) * p_weight; } static _ALWAYS_INLINE_ float lerp(float p_from, float p_to, float p_weight) { return p_from + (p_to - p_from) * p_weight; } diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index 7824776fdb..015cee09a7 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -2023,7 +2023,7 @@ Variant::operator Color() const { if (type == COLOR) { return *reinterpret_cast<const Color *>(_data._mem); } else if (type == STRING) { - return Color::html(operator String()); + return Color(operator String()); } else if (type == INT) { return Color::hex(operator int()); } else { diff --git a/core/variant/variant_construct.cpp b/core/variant/variant_construct.cpp index 9835734583..52f9f6060e 100644 --- a/core/variant/variant_construct.cpp +++ b/core/variant/variant_construct.cpp @@ -688,6 +688,8 @@ void Variant::_register_variant_constructors() { add_constructor<VariantConstructor<Color, Color, double>>(sarray("from", "alpha")); add_constructor<VariantConstructor<Color, double, double, double>>(sarray("r", "g", "b")); add_constructor<VariantConstructor<Color, double, double, double, double>>(sarray("r", "g", "b", "a")); + add_constructor<VariantConstructor<Color, String>>(sarray("code")); + add_constructor<VariantConstructor<Color, String, double>>(sarray("code", "alpha")); add_constructor<VariantConstructNoArgs<StringName>>(sarray()); add_constructor<VariantConstructor<StringName, StringName>>(sarray("from")); |