Core: Use Math namespace for constants

This commit is contained in:
Thaddeus Crews 2025-04-10 11:21:05 -05:00
parent 06c71fbf40
commit 94282d88f9
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
181 changed files with 812 additions and 818 deletions

View file

@ -34,7 +34,7 @@
#include "godot_space_3d.h"
#define MIN_VELOCITY 0.0001
#define MAX_BIAS_ROTATION (Math_PI / 8)
#define MAX_BIAS_ROTATION (Math::PI / 8)
void GodotBodyPair3D::_contact_added_callback(const Vector3 &p_point_A, int p_index_A, const Vector3 &p_point_B, int p_index_B, const Vector3 &normal, void *p_userdata) {
GodotBodyPair3D *pair = static_cast<GodotBodyPair3D *>(p_userdata);

View file

@ -61,8 +61,8 @@ bool GodotCollisionSolver3D::solve_static_world_boundary(const GodotShape3D *p_s
// Use 3 equidistant points on the circle.
for (int i = 0; i < 3; ++i) {
Vector3 vertex_pos = circle_pos;
vertex_pos += circle_axis_1 * Math::cos(2.0 * Math_PI * i / 3.0);
vertex_pos += circle_axis_2 * Math::sin(2.0 * Math_PI * i / 3.0);
vertex_pos += circle_axis_1 * Math::cos(2.0 * Math::PI * i / 3.0);
vertex_pos += circle_axis_2 * Math::sin(2.0 * Math::PI * i / 3.0);
supports[i] = vertex_pos;
}
}
@ -488,8 +488,8 @@ bool GodotCollisionSolver3D::solve_distance_world_boundary(const GodotShape3D *p
// Use 3 equidistant points on the circle.
for (int i = 0; i < 3; ++i) {
Vector3 vertex_pos = circle_pos;
vertex_pos += circle_axis_1 * Math::cos(2.0 * Math_PI * i / 3.0);
vertex_pos += circle_axis_2 * Math::sin(2.0 * Math_PI * i / 3.0);
vertex_pos += circle_axis_1 * Math::cos(2.0 * Math::PI * i / 3.0);
vertex_pos += circle_axis_2 * Math::sin(2.0 * Math::PI * i / 3.0);
supports[i] = vertex_pos;
}
}

View file

@ -381,7 +381,7 @@ static void _generate_contacts_face_circle(const Vector3 *p_points_A, int p_poin
static const int circle_segments = 8;
Vector3 circle_points[circle_segments];
real_t angle_delta = 2.0 * Math_PI / circle_segments;
real_t angle_delta = 2.0 * Math::PI / circle_segments;
for (int i = 0; i < circle_segments; ++i) {
Vector3 point_pos = circle_B_pos;
@ -511,8 +511,8 @@ static void _generate_contacts_circle_circle(const Vector3 *p_points_A, int p_po
// Circle A inside circle B.
for (int i = 0; i < 3; ++i) {
Vector3 circle_A_point = circle_A_pos;
circle_A_point += circle_A_line_1 * Math::cos(2.0 * Math_PI * i / 3.0);
circle_A_point += circle_A_line_2 * Math::sin(2.0 * Math_PI * i / 3.0);
circle_A_point += circle_A_line_1 * Math::cos(2.0 * Math::PI * i / 3.0);
circle_A_point += circle_A_line_2 * Math::sin(2.0 * Math::PI * i / 3.0);
contact_points[num_points] = circle_A_point;
++num_points;
@ -521,8 +521,8 @@ static void _generate_contacts_circle_circle(const Vector3 *p_points_A, int p_po
// Circle B inside circle A.
for (int i = 0; i < 3; ++i) {
Vector3 circle_B_point = circle_B_pos;
circle_B_point += circle_B_line_1 * Math::cos(2.0 * Math_PI * i / 3.0);
circle_B_point += circle_B_line_2 * Math::sin(2.0 * Math_PI * i / 3.0);
circle_B_point += circle_B_line_1 * Math::cos(2.0 * Math::PI * i / 3.0);
circle_B_point += circle_B_line_2 * Math::sin(2.0 * Math::PI * i / 3.0);
Vector3 circle_A_point = circle_B_point - norm_proj;

View file

@ -39,7 +39,7 @@ protected:
bool dynamic_B = false;
void plane_space(const Vector3 &n, Vector3 &p, Vector3 &q) {
if (Math::abs(n.z) > Math_SQRT12) {
if (Math::abs(n.z) > Math::SQRT12) {
// choose p in y-z plane
real_t a = n[1] * n[1] + n[2] * n[2];
real_t k = 1.0 / Math::sqrt(a);
@ -57,7 +57,7 @@ protected:
}
_FORCE_INLINE_ real_t atan2fast(real_t y, real_t x) {
real_t coeff_1 = Math_PI / 4.0f;
real_t coeff_1 = Math::PI / 4.0f;
real_t coeff_2 = 3.0f * coeff_1;
real_t abs_y = Math::abs(y);
real_t angle;

View file

@ -119,7 +119,7 @@ class GodotWorldBoundaryShape3D : public GodotShape3D {
public:
Plane get_plane() const;
virtual real_t get_volume() const override { return INFINITY; }
virtual real_t get_volume() const override { return Math::INF; }
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_WORLD_BOUNDARY; }
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
virtual Vector3 get_support(const Vector3 &p_normal) const override;
@ -172,7 +172,7 @@ class GodotSphereShape3D : public GodotShape3D {
public:
real_t get_radius() const;
virtual real_t get_volume() const override { return 4.0 / 3.0 * Math_PI * radius * radius * radius; }
virtual real_t get_volume() const override { return 4.0 / 3.0 * Math::PI * radius * radius * radius; }
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_SPHERE; }
@ -226,7 +226,7 @@ public:
_FORCE_INLINE_ real_t get_height() const { return height; }
_FORCE_INLINE_ real_t get_radius() const { return radius; }
virtual real_t get_volume() const override { return 4.0 / 3.0 * Math_PI * radius * radius * radius + (height - radius * 2.0) * Math_PI * radius * radius; }
virtual real_t get_volume() const override { return 4.0 / 3.0 * Math::PI * radius * radius * radius + (height - radius * 2.0) * Math::PI * radius * radius; }
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CAPSULE; }
@ -255,7 +255,7 @@ public:
_FORCE_INLINE_ real_t get_height() const { return height; }
_FORCE_INLINE_ real_t get_radius() const { return radius; }
virtual real_t get_volume() const override { return height * Math_PI * radius * radius; }
virtual real_t get_volume() const override { return height * Math::PI * radius * radius; }
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CYLINDER; }

View file

@ -1245,7 +1245,7 @@ struct _SoftBodyIntersectSegmentInfo {
Vector3 dir;
Vector3 hit_position;
uint32_t hit_face_index = -1;
real_t hit_dist_sq = INFINITY;
real_t hit_dist_sq = Math::INF;
static bool process_hit(uint32_t p_face_index, void *p_userdata) {
_SoftBodyIntersectSegmentInfo &query_info = *(static_cast<_SoftBodyIntersectSegmentInfo *>(p_userdata));
@ -1276,7 +1276,7 @@ bool GodotSoftBodyShape3D::intersect_segment(const Vector3 &p_begin, const Vecto
soft_body->query_ray(p_begin, p_end, _SoftBodyIntersectSegmentInfo::process_hit, &query_info);
if (query_info.hit_dist_sq != INFINITY) {
if (query_info.hit_dist_sq != Math::INF) {
r_result = query_info.hit_position;
r_normal = soft_body->get_face_normal(query_info.hit_face_index);
return true;

View file

@ -79,7 +79,7 @@ public:
real_t m_biasFactor = 0.3;
real_t m_relaxationFactor = 1.0;
real_t m_swingSpan1 = Math_TAU / 8.0;
real_t m_swingSpan1 = Math::TAU / 8.0;
real_t m_swingSpan2 = 0.0;
real_t m_twistSpan = 0.0;

View file

@ -75,8 +75,8 @@ class GodotHingeJoint3D : public GodotJoint3D {
real_t m_biasFactor = 0.3;
real_t m_relaxationFactor = 1.0;
real_t m_lowerLimit = Math_PI;
real_t m_upperLimit = -Math_PI;
real_t m_lowerLimit = Math::PI;
real_t m_upperLimit = -Math::PI;
real_t m_kHinge = 0.0;