Merge pull request #105249 from Repiteo/core/math-defs-namespace

Core: Use `Math` namespace for constants
This commit is contained in:
Thaddeus Crews 2025-04-11 09:51:04 -05:00
commit 717df3ee88
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
181 changed files with 812 additions and 818 deletions

View file

@ -2864,14 +2864,14 @@ Control::CursorShape CanvasItemEditor::get_cursor_shape(const Point2 &p_pos) con
List<CanvasItem *> selection = _get_edited_canvas_items();
if (selection.size() == 1) {
const double angle = Math::fposmod((double)selection.front()->get()->get_global_transform_with_canvas().get_rotation(), Math_PI);
if (angle > Math_PI * 7.0 / 8.0) {
const double angle = Math::fposmod((double)selection.front()->get()->get_global_transform_with_canvas().get_rotation(), Math::PI);
if (angle > Math::PI * 7.0 / 8.0) {
rotation_array_index = 0;
} else if (angle > Math_PI * 5.0 / 8.0) {
} else if (angle > Math::PI * 5.0 / 8.0) {
rotation_array_index = 1;
} else if (angle > Math_PI * 3.0 / 8.0) {
} else if (angle > Math::PI * 3.0 / 8.0) {
rotation_array_index = 2;
} else if (angle > Math_PI * 1.0 / 8.0) {
} else if (angle > Math::PI * 1.0 / 8.0) {
rotation_array_index = 3;
} else {
rotation_array_index = 0;
@ -3103,7 +3103,7 @@ void CanvasItemEditor::_draw_rulers() {
viewport->draw_line(Point2(0, position.y), Point2(RULER_WIDTH, position.y), graduation_color, Math::round(EDSCALE));
real_t val = (ruler_transform * major_subdivide * minor_subdivide).xform(Point2(0, i)).y;
Transform2D text_xform = Transform2D(-Math_PI / 2.0, Point2(font->get_ascent(font_size) + Math::round(EDSCALE), position.y - 2));
Transform2D text_xform = Transform2D(-Math::PI / 2.0, Point2(font->get_ascent(font_size) + Math::round(EDSCALE), position.y - 2));
viewport->draw_set_transform_matrix(viewport->get_transform() * text_xform);
viewport->draw_string(font, Point2(), TS->format_number(vformat(((int)val == val) ? "%d" : "%.1f", val)), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color);
viewport->draw_set_transform_matrix(viewport->get_transform());
@ -3210,7 +3210,7 @@ void CanvasItemEditor::_draw_ruler_tool() {
Vector2 length_vector = (begin - end).abs() / zoom;
const real_t horizontal_angle_rad = length_vector.angle();
const real_t vertical_angle_rad = Math_PI / 2.0 - horizontal_angle_rad;
const real_t vertical_angle_rad = Math::PI / 2.0 - horizontal_angle_rad;
Ref<Font> font = get_theme_font(SNAME("bold"), EditorStringName(EditorFonts));
int font_size = 1.3 * get_theme_font_size(SNAME("bold_size"), EditorStringName(EditorFonts));
@ -3246,15 +3246,15 @@ void CanvasItemEditor::_draw_ruler_tool() {
const Vector2 end_to_begin = (end - begin);
real_t arc_1_start_angle = end_to_begin.x < 0
? (end_to_begin.y < 0 ? 3.0 * Math_PI / 2.0 - vertical_angle_rad : Math_PI / 2.0)
: (end_to_begin.y < 0 ? 3.0 * Math_PI / 2.0 : Math_PI / 2.0 - vertical_angle_rad);
? (end_to_begin.y < 0 ? 3.0 * Math::PI / 2.0 - vertical_angle_rad : Math::PI / 2.0)
: (end_to_begin.y < 0 ? 3.0 * Math::PI / 2.0 : Math::PI / 2.0 - vertical_angle_rad);
real_t arc_1_end_angle = arc_1_start_angle + vertical_angle_rad;
// Constrain arc to triangle height & max size.
real_t arc_1_radius = MIN(MIN(arc_radius_max_length_percent * ruler_length, Math::abs(end_to_begin.y)), arc_max_radius);
real_t arc_2_start_angle = end_to_begin.x < 0
? (end_to_begin.y < 0 ? 0.0 : -horizontal_angle_rad)
: (end_to_begin.y < 0 ? Math_PI - horizontal_angle_rad : Math_PI);
: (end_to_begin.y < 0 ? Math::PI - horizontal_angle_rad : Math::PI);
real_t arc_2_end_angle = arc_2_start_angle + horizontal_angle_rad;
// Constrain arc to triangle width & max size.
real_t arc_2_radius = MIN(MIN(arc_radius_max_length_percent * ruler_length, Math::abs(end_to_begin.x)), arc_max_radius);
@ -3275,8 +3275,8 @@ void CanvasItemEditor::_draw_ruler_tool() {
viewport->draw_string(font, text_pos, TS->format_number(vformat("%.1f px", length_vector.length())), HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, font_color);
if (draw_secondary_lines) {
const int horizontal_angle = round(180 * horizontal_angle_rad / Math_PI);
const int vertical_angle = round(180 * vertical_angle_rad / Math_PI);
const int horizontal_angle = round(180 * horizontal_angle_rad / Math::PI);
const int vertical_angle = round(180 * vertical_angle_rad / Math::PI);
Point2 text_pos2 = text_pos;
text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2);
@ -3655,7 +3655,7 @@ void CanvasItemEditor::_draw_selection() {
int next = (i + 1) % 4;
Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized();
ofs *= Math_SQRT2 * (select_handle->get_size().width / 2);
ofs *= Math::SQRT2 * (select_handle->get_size().width / 2);
select_handle->draw(vp_ci, (endpoints[i] + ofs - (select_handle->get_size() / 2)).floor());
@ -4257,8 +4257,8 @@ void CanvasItemEditor::_selection_changed() {
}
selected_from_canvas = false;
if (temp_pivot != Vector2(INFINITY, INFINITY)) {
temp_pivot = Vector2(INFINITY, INFINITY);
if (temp_pivot != Vector2(Math::INF, Math::INF)) {
temp_pivot = Vector2(Math::INF, Math::INF);
viewport->queue_redraw();
}
}
@ -6175,7 +6175,7 @@ void CanvasItemEditorViewport::_perform_drop_data() {
}
bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
return false;
}
Dictionary d = p_data;
@ -6309,7 +6309,7 @@ bool CanvasItemEditorViewport::_is_any_texture_selected() const {
}
void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p_data) {
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
return;
}
bool is_shift = Input::get_singleton()->is_key_pressed(Key::SHIFT);

View file

@ -252,7 +252,7 @@ private:
bool key_scale = false;
bool pan_pressed = false;
Vector2 temp_pivot = Vector2(INFINITY, INFINITY);
Vector2 temp_pivot = Vector2(Math::INF, Math::INF);
bool ruler_tool_active = false;
Point2 ruler_tool_origin;

View file

@ -393,22 +393,22 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() {
int lats = 32;
int lons = 32;
const double lat_step = Math_TAU / lats;
const double lon_step = Math_TAU / lons;
const double lat_step = Math::TAU / lats;
const double lon_step = Math::TAU / lons;
real_t radius = 1.0;
Vector<Vector3> vertices;
Vector<Vector3> normals;
Vector<Vector2> uvs;
Vector<real_t> tangents;
Basis tt = Basis(Vector3(0, 1, 0), Math_PI * 0.5);
Basis tt = Basis(Vector3(0, 1, 0), Math::PI * 0.5);
for (int i = 1; i <= lats; i++) {
double lat0 = lat_step * (i - 1) - Math_TAU / 4;
double lat0 = lat_step * (i - 1) - Math::TAU / 4;
double z0 = Math::sin(lat0);
double zr0 = Math::cos(lat0);
double lat1 = lat_step * i - Math_TAU / 4;
double lat1 = lat_step * i - Math::TAU / 4;
double z1 = Math::sin(lat1);
double zr1 = Math::cos(lat1);
@ -433,7 +433,7 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() {
vertices.push_back(v[m_idx] * radius); \
{ \
Vector2 uv(Math::atan2(v[m_idx].x, v[m_idx].z), Math::atan2(-v[m_idx].y, v[m_idx].z)); \
uv /= Math_PI; \
uv /= Math::PI; \
uv *= 4.0; \
uv = uv * 0.5 + Vector2(0.5, 0.5); \
uvs.push_back(uv); \
@ -736,8 +736,8 @@ Ref<Texture2D> EditorMeshPreviewPlugin::generate(const Ref<Resource> &p_from, co
Vector3 ofs = aabb.get_center();
aabb.position -= ofs;
Transform3D xform;
xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.125);
xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.125) * xform.basis;
xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math::PI * 0.125);
xform.basis = Basis().rotated(Vector3(1, 0, 0), Math::PI * 0.125) * xform.basis;
AABB rot_aabb = xform.xform(aabb);
real_t m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5;
if (m == 0) {

View file

@ -176,8 +176,8 @@ void AudioStreamPlayer3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
// Number of points in an octant. So there will be 8 * points_in_octant points in total.
// This corresponds to the smoothness of the circle.
const uint32_t points_in_octant = 15;
const real_t octant_angle = Math_PI / 4;
const real_t inc = (Math_PI / (4 * points_in_octant));
const real_t octant_angle = Math::PI / 4;
const real_t inc = (Math::PI / (4 * points_in_octant));
const real_t radius_squared = radius * radius;
real_t r = 0;
@ -239,8 +239,8 @@ void AudioStreamPlayer3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
const float radius = Math::sin(ha);
const uint32_t points_in_octant = 7;
const real_t octant_angle = Math_PI / 4;
const real_t inc = (Math_PI / (4 * points_in_octant));
const real_t octant_angle = Math::PI / 4;
const real_t inc = (Math::PI / (4 * points_in_octant));
const real_t radius_squared = radius * radius;
real_t r = 0;

View file

@ -271,8 +271,8 @@ float Camera3DGizmoPlugin::_find_closest_angle_to_half_pi_arc(const Vector3 &p_f
Vector3 min_p;
for (int i = 0; i < arc_test_points; i++) {
float a = i * Math_PI * 0.5 / arc_test_points;
float an = (i + 1) * Math_PI * 0.5 / arc_test_points;
float a = i * Math::PI * 0.5 / arc_test_points;
float an = (i + 1) * Math::PI * 0.5 / arc_test_points;
Vector3 p = Vector3(Math::cos(a), 0, -Math::sin(a)) * p_arc_radius;
Vector3 n = Vector3(Math::cos(an), 0, -Math::sin(an)) * p_arc_radius;
@ -287,6 +287,6 @@ float Camera3DGizmoPlugin::_find_closest_angle_to_half_pi_arc(const Vector3 &p_f
}
//min_p = p_arc_xform.affine_inverse().xform(min_p);
float a = (Math_PI * 0.5) - Vector2(min_p.x, -min_p.z).angle();
float a = (Math::PI * 0.5) - Vector2(min_p.x, -min_p.z).angle();
return Math::rad_to_deg(a);
}

View file

@ -359,7 +359,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
// Number of points in an octant. So there will be 8 * points_in_octant * 2 points in total for one circle.
// This Corresponds to the smoothness of the circle.
const uint32_t points_in_octant = 16;
const real_t inc = (Math_PI / (4 * points_in_octant));
const real_t inc = (Math::PI / (4 * points_in_octant));
const real_t radius_squared = radius * radius;
real_t r = 0;
@ -429,8 +429,8 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
// Number of points in an octant. So there will be 8 * points_in_octant points in total.
// This corresponds to the smoothness of the circle.
const uint32_t points_in_octant = 16;
const real_t octant_angle = Math_PI / 4;
const real_t inc = (Math_PI / (4 * points_in_octant));
const real_t octant_angle = Math::PI / 4;
const real_t inc = (Math::PI / (4 * points_in_octant));
const real_t radius_squared = radius * radius;
real_t r = 0;
@ -539,7 +539,7 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
// Number of points in an octant. So there will be 8 * points_in_octant * 2 points in total for one circle.
// This corresponds to the smoothness of the circle.
const uint32_t points_in_octant = 16;
const real_t inc = (Math_PI / (4 * points_in_octant));
const real_t inc = (Math::PI / (4 * points_in_octant));
const real_t radius_squared = radius * radius;
real_t r = 0;

View file

@ -200,8 +200,8 @@ void GPUParticlesCollision3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
// Number of points in an octant. So there will be 8 * points_in_octant points in total.
// This corresponds to the smoothness of the circle.
const uint32_t points_in_octant = 16;
const real_t octant_angle = Math_PI / 4;
const real_t inc = (Math_PI / (4 * points_in_octant));
const real_t octant_angle = Math::PI / 4;
const real_t inc = (Math::PI / (4 * points_in_octant));
const real_t radius_squared = radius * radius;
real_t r = 0;

View file

@ -179,8 +179,8 @@ void JointGizmosDrawer::draw_circle(Vector3::Axis p_axis, real_t p_radius, const
} else {
if (p_limit_lower > p_limit_upper) {
p_limit_lower = -Math_PI;
p_limit_upper = Math_PI;
p_limit_lower = -Math::PI;
p_limit_upper = Math::PI;
}
const int points = 32;

View file

@ -179,7 +179,7 @@ void Light3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
for (int i = 0; i < arrow_sides; i++) {
for (int j = 0; j < arrow_points; j++) {
Basis ma(Vector3(0, 0, 1), Math_PI * i / arrow_sides);
Basis ma(Vector3(0, 0, 1), Math::PI * i / arrow_sides);
Vector3 v1 = arrow[j] - Vector3(0, 0, arrow_length);
Vector3 v2 = arrow[(j + 1) % arrow_points] - Vector3(0, 0, arrow_length);
@ -295,8 +295,8 @@ float Light3DGizmoPlugin::_find_closest_angle_to_half_pi_arc(const Vector3 &p_fr
Vector3 min_p;
for (int i = 0; i < arc_test_points; i++) {
float a = i * Math_PI * 0.5 / arc_test_points;
float an = (i + 1) * Math_PI * 0.5 / arc_test_points;
float a = i * Math::PI * 0.5 / arc_test_points;
float an = (i + 1) * Math::PI * 0.5 / arc_test_points;
Vector3 p = Vector3(Math::cos(a), 0, -Math::sin(a)) * p_arc_radius;
Vector3 n = Vector3(Math::cos(an), 0, -Math::sin(an)) * p_arc_radius;
@ -311,6 +311,6 @@ float Light3DGizmoPlugin::_find_closest_angle_to_half_pi_arc(const Vector3 &p_fr
}
//min_p = p_arc_xform.affine_inverse().xform(min_p);
float a = (Math_PI * 0.5) - Vector2(min_p.x, -min_p.z).angle();
float a = (Math::PI * 0.5) - Vector2(min_p.x, -min_p.z).angle();
return Math::rad_to_deg(a);
}

View file

@ -123,8 +123,8 @@ void LightmapGIGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
int stack_count = 8;
int sector_count = 16;
float sector_step = (Math_PI * 2.0) / sector_count;
float stack_step = Math_PI / stack_count;
float sector_step = (Math::PI * 2.0) / sector_count;
float stack_step = Math::PI / stack_count;
Vector<Vector3> vertices;
Vector<Color> colors;
@ -141,7 +141,7 @@ void LightmapGIGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
}
for (int i = 0; i <= stack_count; ++i) {
float stack_angle = Math_PI / 2 - i * stack_step; // starting from pi/2 to -pi/2
float stack_angle = Math::PI / 2 - i * stack_step; // starting from pi/2 to -pi/2
float xy = radius * Math::cos(stack_angle); // r * cos(u)
float z = radius * Math::sin(stack_angle); // r * sin(u)

View file

@ -66,14 +66,14 @@ void LightmapProbeGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
int stack_count = 8;
int sector_count = 16;
float sector_step = (Math_PI * 2.0) / sector_count;
float stack_step = Math_PI / stack_count;
float sector_step = (Math::PI * 2.0) / sector_count;
float stack_step = Math::PI / stack_count;
Vector<Vector3> vertices;
float radius = 0.2;
for (int i = 0; i <= stack_count; ++i) {
float stack_angle = Math_PI / 2 - i * stack_step; // starting from pi/2 to -pi/2
float stack_angle = Math::PI / 2 - i * stack_step; // starting from pi/2 to -pi/2
float xy = radius * Math::cos(stack_angle); // r * cos(u)
float z = radius * Math::sin(stack_angle); // r * sin(u)

View file

@ -73,7 +73,7 @@ void NavigationLink3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
// Number of points in an octant. So there will be 8 * points_in_octant points in total.
// Correspond to the smoothness of the circle.
const uint32_t points_in_octant = 8;
real_t inc = (Math_PI / (4 * points_in_octant));
real_t inc = (Math::PI / (4 * points_in_octant));
Vector<Vector3> lines;
// points_in_octant * 8 * 2 per circle * 2 circles. 2 for the start-end. 4 for the arrow, and another 4 if bidirectionnal.

View file

@ -171,7 +171,7 @@ void SpringBoneSimulator3DGizmoPlugin::draw_sphere(Ref<SurfaceTool> &p_surface_t
static const Vector3 VECTOR3_UP = Vector3(0, 1, 0);
static const Vector3 VECTOR3_FORWARD = Vector3(0, 0, 1);
static const int STEP = 16;
static const float SPPI = Math_TAU / (float)STEP;
static const float SPPI = Math::TAU / (float)STEP;
for (int i = 1; i <= STEP; i++) {
p_surface_tool->set_color(p_color);
@ -302,7 +302,7 @@ void SpringBoneCollision3DGizmoPlugin::draw_sphere(Ref<SurfaceTool> &p_surface_t
static const Vector3 VECTOR3_UP = Vector3(0, 1, 0);
static const Vector3 VECTOR3_FORWARD = Vector3(0, 0, 1);
static const int STEP = 16;
static const float SPPI = Math_TAU / (float)STEP;
static const float SPPI = Math::TAU / (float)STEP;
for (int i = 1; i <= STEP; i++) {
p_surface_tool->set_color(p_color);
@ -330,8 +330,8 @@ void SpringBoneCollision3DGizmoPlugin::draw_capsule(Ref<SurfaceTool> &p_surface_
static const Vector3 VECTOR3_FORWARD = Vector3(0, 0, 1);
static const int STEP = 16;
static const int HALF_STEP = 8;
static const float SPPI = Math_TAU / (float)STEP;
static const float HALF_PI = Math_PI * 0.5;
static const float SPPI = Math::TAU / (float)STEP;
static const float HALF_PI = Math::PI * 0.5;
Vector3 top = VECTOR3_UP * (p_height * 0.5 - p_radius);
Vector3 bottom = -top;
@ -376,7 +376,7 @@ void SpringBoneCollision3DGizmoPlugin::draw_capsule(Ref<SurfaceTool> &p_surface_
void SpringBoneCollision3DGizmoPlugin::draw_plane(Ref<SurfaceTool> &p_surface_tool, const Color &p_color) {
static const Vector3 VECTOR3_UP = Vector3(0, 1, 0);
static const float HALF_PI = Math_PI * 0.5;
static const float HALF_PI = Math::PI * 0.5;
static const float ARROW_LENGTH = 0.3;
static const float ARROW_HALF_WIDTH = 0.05;
static const float ARROW_TOP_HALF_WIDTH = 0.1;

View file

@ -62,7 +62,7 @@ void MaterialEditor::gui_input(const Ref<InputEvent> &p_event) {
const real_t limit = Math::deg_to_rad(80.0);
rot = rot.clampf(-limit, limit);
} else {
rot.x = CLAMP(rot.x, -Math_PI / 2, Math_PI / 2);
rot.x = CLAMP(rot.x, -Math::PI / 2, Math::PI / 2);
}
_update_rotation();
_store_rotation_metadata();

View file

@ -43,7 +43,7 @@ void MeshEditor::gui_input(const Ref<InputEvent> &p_event) {
rot_x -= mm->get_relative().y * 0.01;
rot_y -= mm->get_relative().x * 0.01;
rot_x = CLAMP(rot_x, -Math_PI / 2, Math_PI / 2);
rot_x = CLAMP(rot_x, -Math::PI / 2, Math::PI / 2);
_update_rotation();
}
}

View file

@ -174,10 +174,10 @@ void MultiMeshEditor::_populate() {
Transform3D axis_xform;
if (axis == Vector3::AXIS_Z) {
axis_xform.rotate(Vector3(1, 0, 0), -Math_PI * 0.5);
axis_xform.rotate(Vector3(1, 0, 0), -Math::PI * 0.5);
}
if (axis == Vector3::AXIS_X) {
axis_xform.rotate(Vector3(0, 0, 1), -Math_PI * 0.5);
axis_xform.rotate(Vector3(0, 0, 1), -Math::PI * 0.5);
}
for (int i = 0; i < instance_count; i++) {
@ -203,9 +203,9 @@ void MultiMeshEditor::_populate() {
Basis post_xform;
post_xform.rotate(xform.basis.get_column(1), -Math::random(-_rotate_random, _rotate_random) * Math_PI);
post_xform.rotate(xform.basis.get_column(2), -Math::random(-_tilt_random, _tilt_random) * Math_PI);
post_xform.rotate(xform.basis.get_column(0), -Math::random(-_tilt_random, _tilt_random) * Math_PI);
post_xform.rotate(xform.basis.get_column(1), -Math::random(-_rotate_random, _rotate_random) * Math::PI);
post_xform.rotate(xform.basis.get_column(2), -Math::random(-_tilt_random, _tilt_random) * Math::PI);
post_xform.rotate(xform.basis.get_column(0), -Math::random(-_tilt_random, _tilt_random) * Math::PI);
xform.basis = post_xform * xform.basis;
//xform.basis.orthonormalize();

View file

@ -2389,28 +2389,28 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
if (ED_IS_SHORTCUT("spatial_editor/orbit_view_down", p_event)) {
// Clamp rotation to roughly -90..90 degrees so the user can't look upside-down and end up disoriented.
cursor.x_rot = CLAMP(cursor.x_rot - Math_PI / 12.0, -1.57, 1.57);
cursor.x_rot = CLAMP(cursor.x_rot - Math::PI / 12.0, -1.57, 1.57);
view_type = VIEW_TYPE_USER;
_update_name();
}
if (ED_IS_SHORTCUT("spatial_editor/orbit_view_up", p_event)) {
// Clamp rotation to roughly -90..90 degrees so the user can't look upside-down and end up disoriented.
cursor.x_rot = CLAMP(cursor.x_rot + Math_PI / 12.0, -1.57, 1.57);
cursor.x_rot = CLAMP(cursor.x_rot + Math::PI / 12.0, -1.57, 1.57);
view_type = VIEW_TYPE_USER;
_update_name();
}
if (ED_IS_SHORTCUT("spatial_editor/orbit_view_right", p_event)) {
cursor.y_rot -= Math_PI / 12.0;
cursor.y_rot -= Math::PI / 12.0;
view_type = VIEW_TYPE_USER;
_update_name();
}
if (ED_IS_SHORTCUT("spatial_editor/orbit_view_left", p_event)) {
cursor.y_rot += Math_PI / 12.0;
cursor.y_rot += Math::PI / 12.0;
view_type = VIEW_TYPE_USER;
_update_name();
}
if (ED_IS_SHORTCUT("spatial_editor/orbit_view_180", p_event)) {
cursor.y_rot += Math_PI;
cursor.y_rot += Math::PI;
view_type = VIEW_TYPE_USER;
_update_name();
}
@ -3505,7 +3505,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
switch (p_option) {
case VIEW_TOP: {
cursor.y_rot = 0;
cursor.x_rot = Math_PI / 2.0;
cursor.x_rot = Math::PI / 2.0;
set_message(TTR("Top View."), 2);
view_type = VIEW_TYPE_TOP;
_set_auto_orthogonal();
@ -3514,7 +3514,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
} break;
case VIEW_BOTTOM: {
cursor.y_rot = 0;
cursor.x_rot = -Math_PI / 2.0;
cursor.x_rot = -Math::PI / 2.0;
set_message(TTR("Bottom View."), 2);
view_type = VIEW_TYPE_BOTTOM;
_set_auto_orthogonal();
@ -3523,7 +3523,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
} break;
case VIEW_LEFT: {
cursor.x_rot = 0;
cursor.y_rot = Math_PI / 2.0;
cursor.y_rot = Math::PI / 2.0;
set_message(TTR("Left View."), 2);
view_type = VIEW_TYPE_LEFT;
_set_auto_orthogonal();
@ -3532,7 +3532,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
} break;
case VIEW_RIGHT: {
cursor.x_rot = 0;
cursor.y_rot = -Math_PI / 2.0;
cursor.y_rot = -Math::PI / 2.0;
set_message(TTR("Right View."), 2);
view_type = VIEW_TYPE_RIGHT;
_set_auto_orthogonal();
@ -3550,7 +3550,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
} break;
case VIEW_REAR: {
cursor.x_rot = 0;
cursor.y_rot = Math_PI;
cursor.y_rot = Math::PI;
set_message(TTR("Rear View."), 2);
view_type = VIEW_TYPE_REAR;
_set_auto_orthogonal();
@ -3599,7 +3599,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
// Adjust rotation to match Decal's default orientation.
// This makes the decal "look" in the same direction as the camera,
// rather than pointing down relative to the camera orientation.
xform.basis.rotate_local(Vector3(1, 0, 0), Math_TAU * 0.25);
xform.basis.rotate_local(Vector3(1, 0, 0), Math::TAU * 0.25);
}
Node3D *parent = sp->get_parent_node_3d();
@ -3637,7 +3637,7 @@ void Node3DEditorViewport::_menu_option(int p_option) {
// Adjust rotation to match Decal's default orientation.
// This makes the decal "look" in the same direction as the camera,
// rather than pointing down relative to the camera orientation.
basis.rotate_local(Vector3(1, 0, 0), Math_TAU * 0.25);
basis.rotate_local(Vector3(1, 0, 0), Math::TAU * 0.25);
}
undo_redo->add_do_method(sp, "set_rotation", basis.get_euler_normalized());
@ -4911,7 +4911,7 @@ void Node3DEditorViewport::_perform_drop_data() {
}
bool Node3DEditorViewport::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
return false;
}
preview_node_viewport_pos = p_point;
@ -5376,7 +5376,7 @@ void Node3DEditorViewport::update_transform(bool p_shift) {
Vector3 projection_axis = plane.normal.cross(global_axis);
Vector3 delta = intersection - click;
float projection = delta.dot(projection_axis);
angle = (projection * (Math_PI / 2.0f)) / (gizmo_scale * GIZMO_CIRCLE_SIZE);
angle = (projection * (Math::PI / 2.0f)) / (gizmo_scale * GIZMO_CIRCLE_SIZE);
} else {
_edit.show_rotation_line = true;
Vector3 click_axis = (click - _edit.center).normalized();
@ -7324,7 +7324,7 @@ void fragment() {
int arrow_sides = 16;
const real_t arrow_sides_step = Math_TAU / arrow_sides;
const real_t arrow_sides_step = Math::TAU / arrow_sides;
for (int k = 0; k < arrow_sides; k++) {
Basis ma(ivec, k * arrow_sides_step);
Basis mb(ivec, (k + 1) * arrow_sides_step);
@ -7363,7 +7363,7 @@ void fragment() {
vec * GIZMO_PLANE_DST - ivec3 * GIZMO_PLANE_SIZE
};
Basis ma(ivec, Math_PI / 2);
Basis ma(ivec, Math::PI / 2);
Vector3 points[4] = {
ma.xform(plane[0]),
@ -7403,14 +7403,14 @@ void fragment() {
int n = 128; // number of circle segments
int m = 3; // number of thickness segments
real_t step = Math_TAU / n;
real_t step = Math::TAU / n;
for (int j = 0; j < n; ++j) {
Basis basis = Basis(ivec, j * step);
Vector3 vertex = basis.xform(ivec2 * GIZMO_CIRCLE_SIZE);
for (int k = 0; k < m; ++k) {
Vector2 ofs = Vector2(Math::cos((Math_TAU * k) / m), Math::sin((Math_TAU * k) / m));
Vector2 ofs = Vector2(Math::cos((Math::TAU * k) / m), Math::sin((Math::TAU * k) / m));
Vector3 normal = ivec * ofs.x + ivec2 * ofs.y;
surftool->set_normal(basis.xform(normal));
@ -7547,7 +7547,7 @@ void fragment() {
int arrow_sides = 4;
const real_t arrow_sides_step = Math_TAU / arrow_sides;
const real_t arrow_sides_step = Math::TAU / arrow_sides;
for (int k = 0; k < 4; k++) {
Basis ma(ivec, k * arrow_sides_step);
Basis mb(ivec, (k + 1) * arrow_sides_step);
@ -7586,7 +7586,7 @@ void fragment() {
vec * GIZMO_PLANE_DST - ivec3 * GIZMO_PLANE_SIZE
};
Basis ma(ivec, Math_PI / 2);
Basis ma(ivec, Math::PI / 2);
Vector3 points[4] = {
ma.xform(plane[0]),
@ -8915,7 +8915,7 @@ void Node3DEditor::_sun_direction_input(const Ref<InputEvent> &p_event) {
if (mm.is_valid() && mm->get_button_mask().has_flag(MouseButtonMask::LEFT)) {
sun_rotation.x += mm->get_relative().y * (0.02 * EDSCALE);
sun_rotation.y -= mm->get_relative().x * (0.02 * EDSCALE);
sun_rotation.x = CLAMP(sun_rotation.x, -Math_TAU / 4, Math_TAU / 4);
sun_rotation.x = CLAMP(sun_rotation.x, -Math::TAU / 4, Math::TAU / 4);
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Set Preview Sun Direction"), UndoRedo::MergeMode::MERGE_ENDS);

View file

@ -472,7 +472,7 @@ void Path3DGizmo::redraw() {
const int n = 36;
for (int i = 0; i <= n; i++) {
const float a = Math_TAU * i / n;
const float a = Math::TAU * i / n;
const Vector3 edge = sin(a) * side + cos(a) * up;
disk.append(pos + edge * disk_size);
}

View file

@ -253,7 +253,7 @@ void ResourcePreloaderEditor::edit(ResourcePreloader *p_preloader) {
}
Variant ResourcePreloaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
TreeItem *ti = (p_point == Vector2(INFINITY, INFINITY)) ? tree->get_selected() : tree->get_item_at_position(p_point);
TreeItem *ti = (p_point == Vector2(Math::INF, Math::INF)) ? tree->get_selected() : tree->get_item_at_position(p_point);
if (!ti) {
return Variant();
}

View file

@ -3273,7 +3273,7 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
int new_index = 0;
if (script_list->get_item_count() > 0) {
int pos = 0;
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
if (script_list->is_anything_selected()) {
pos = script_list->get_selected_items()[0];
}
@ -3301,7 +3301,7 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
int new_index = 0;
if (script_list->get_item_count() > 0) {
int pos = 0;
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
if (script_list->is_anything_selected()) {
pos = script_list->get_selected_items()[0];
}
@ -3322,7 +3322,7 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co
int new_index = 0;
if (script_list->get_item_count() > 0) {
int pos = 0;
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
if (script_list->is_anything_selected()) {
pos = script_list->get_selected_items()[0];
}

View file

@ -1958,7 +1958,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
Dictionary d = p_data;
CodeEdit *te = code_editor->get_text_editor();
Point2i pos = (p_point == Vector2(INFINITY, INFINITY)) ? Point2i(te->get_caret_line(0), te->get_caret_column(0)) : te->get_line_column_at_pos(p_point);
Point2i pos = (p_point == Vector2(Math::INF, Math::INF)) ? Point2i(te->get_caret_line(0), te->get_caret_column(0)) : te->get_line_column_at_pos(p_point);
int drop_at_line = pos.y;
int drop_at_column = pos.x;
int selection_index = te->get_selection_at_line_column(drop_at_line, drop_at_column);

View file

@ -642,7 +642,7 @@ Variant ShaderEditorPlugin::get_drag_data_fw(const Point2 &p_point, Control *p_f
}
int idx = 0;
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
if (shader_list->is_anything_selected()) {
idx = shader_list->get_selected_items()[0];
}
@ -726,7 +726,7 @@ void ShaderEditorPlugin::drop_data_fw(const Point2 &p_point, const Variant &p_da
if (String(d["type"]) == "shader_list_element") {
int idx = d["shader_list_element"];
int new_idx = 0;
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
if (shader_list->is_anything_selected()) {
new_idx = shader_list->get_selected_items()[0];
}

View file

@ -701,7 +701,7 @@ Variant Skeleton3DEditor::get_drag_data_fw(const Point2 &p_point, Control *p_fro
}
bool Skeleton3DEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
TreeItem *target = (p_point == Vector2(INFINITY, INFINITY)) ? joint_tree->get_selected() : joint_tree->get_item_at_position(p_point);
TreeItem *target = (p_point == Vector2(Math::INF, Math::INF)) ? joint_tree->get_selected() : joint_tree->get_item_at_position(p_point);
if (!target) {
return false;
}
@ -729,7 +729,7 @@ void Skeleton3DEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
return;
}
TreeItem *target = (p_point == Vector2(INFINITY, INFINITY)) ? joint_tree->get_selected() : joint_tree->get_item_at_position(p_point);
TreeItem *target = (p_point == Vector2(Math::INF, Math::INF)) ? joint_tree->get_selected() : joint_tree->get_item_at_position(p_point);
TreeItem *selected = Object::cast_to<TreeItem>(Dictionary(p_data)["node"]);
const BoneId target_boneidx = String(target->get_metadata(0)).get_slicec('/', 1).to_int();

View file

@ -1662,7 +1662,7 @@ Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f
}
int idx = -1;
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
if (frame_list->is_anything_selected()) {
idx = frame_list->get_selected_items()[0];
}
@ -1744,7 +1744,7 @@ void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
}
int at_pos = -1;
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
if (frame_list->is_anything_selected()) {
at_pos = frame_list->get_selected_items()[0];
}

View file

@ -171,7 +171,7 @@ void TextureRegionEditor::_texture_overlay_draw() {
int next = (i + 1) % 4;
Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized();
ofs *= Math_SQRT2 * (select_handle->get_size().width / 2);
ofs *= Math::SQRT2 * (select_handle->get_size().width / 2);
texture_overlay->draw_line(endpoints[i] - draw_ofs * draw_zoom, endpoints[next] - draw_ofs * draw_zoom, color, 2);

View file

@ -80,14 +80,14 @@ struct FloatConstantDef {
};
static FloatConstantDef float_constant_defs[] = {
{ "E", Math_E, TTRC("E constant (2.718282). Represents the base of the natural logarithm.") },
{ "E", Math::E, TTRC("E constant (2.718282). Represents the base of the natural logarithm.") },
{ "Epsilon", CMP_EPSILON, TTRC("Epsilon constant (0.00001). Smallest possible scalar number.") },
{ "Phi", 1.618034f, TTRC("Phi constant (1.618034). Golden ratio.") },
{ "Pi/4", Math_PI / 4, TTRC("Pi/4 constant (0.785398) or 45 degrees.") },
{ "Pi/2", Math_PI / 2, TTRC("Pi/2 constant (1.570796) or 90 degrees.") },
{ "Pi", Math_PI, TTRC("Pi constant (3.141593) or 180 degrees.") },
{ "Tau", Math_TAU, TTRC("Tau constant (6.283185) or 360 degrees.") },
{ "Sqrt2", Math_SQRT2, TTRC("Sqrt2 constant (1.414214). Square root of 2.") }
{ "Pi/4", Math::PI / 4, TTRC("Pi/4 constant (0.785398) or 45 degrees.") },
{ "Pi/2", Math::PI / 2, TTRC("Pi/2 constant (1.570796) or 90 degrees.") },
{ "Pi", Math::PI, TTRC("Pi constant (3.141593) or 180 degrees.") },
{ "Tau", Math::TAU, TTRC("Tau constant (6.283185) or 360 degrees.") },
{ "Sqrt2", Math::SQRT2, TTRC("Sqrt2 constant (1.414214). Square root of 2.") }
};
constexpr int MAX_FLOAT_CONST_DEFS = std::size(float_constant_defs);
@ -6122,7 +6122,7 @@ void VisualShaderEditor::_connection_menu_id_pressed(int p_idx) {
}
Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
return Variant();
}
@ -6151,7 +6151,7 @@ Variant VisualShaderEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f
}
bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
return false;
}
@ -6170,7 +6170,7 @@ bool VisualShaderEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
}
void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
if (p_point == Vector2(INFINITY, INFINITY)) {
if (p_point == Vector2(Math::INF, Math::INF)) {
return;
}