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

@ -1348,14 +1348,14 @@ CSGBrush *CSGSphere3D::_build_brush() {
// We want to follow an order that's convenient for UVs.
// For latitude step we start at the top and move down like in an image.
const double latitude_step = -Math_PI / rings;
const double longitude_step = Math_TAU / radial_segments;
const double latitude_step = -Math::PI / rings;
const double longitude_step = Math::TAU / radial_segments;
int face = 0;
for (int i = 0; i < rings; i++) {
double cos0 = 0;
double sin0 = 1;
if (i > 0) {
double latitude0 = latitude_step * i + Math_TAU / 4;
double latitude0 = latitude_step * i + Math::TAU / 4;
cos0 = Math::cos(latitude0);
sin0 = Math::sin(latitude0);
}
@ -1364,7 +1364,7 @@ CSGBrush *CSGSphere3D::_build_brush() {
double cos1 = 0;
double sin1 = -1;
if (i < rings - 1) {
double latitude1 = latitude_step * (i + 1) + Math_TAU / 4;
double latitude1 = latitude_step * (i + 1) + Math::TAU / 4;
cos1 = Math::cos(latitude1);
sin1 = Math::sin(latitude1);
}
@ -1727,8 +1727,8 @@ CSGBrush *CSGCylinder3D::_build_brush() {
inc_n = 0;
}
float ang = inc * Math_TAU;
float ang_n = inc_n * Math_TAU;
float ang = inc * Math::TAU;
float ang_n = inc_n * Math::TAU;
Vector3 face_base(Math::cos(ang), 0, Math::sin(ang));
Vector3 face_base_n(Math::cos(ang_n), 0, Math::sin(ang_n));
@ -1970,8 +1970,8 @@ CSGBrush *CSGTorus3D::_build_brush() {
inci_n = 0;
}
float angi = inci * Math_TAU;
float angi_n = inci_n * Math_TAU;
float angi = inci * Math::TAU;
float angi_n = inci_n * Math::TAU;
Vector3 normali = Vector3(Math::cos(angi), 0, Math::sin(angi));
Vector3 normali_n = Vector3(Math::cos(angi_n), 0, Math::sin(angi_n));
@ -1983,8 +1983,8 @@ CSGBrush *CSGTorus3D::_build_brush() {
incj_n = 0;
}
float angj = incj * Math_TAU;
float angj_n = incj_n * Math_TAU;
float angj = incj * Math::TAU;
float angj_n = incj_n * Math::TAU;
Vector2 normalj = Vector2(Math::cos(angj), Math::sin(angj)) * radius + Vector2(min_radius + radius, 0);
Vector2 normalj_n = Vector2(Math::cos(angj_n), Math::sin(angj_n)) * radius + Vector2(min_radius + radius, 0);

View file

@ -2254,10 +2254,10 @@ void GDScriptLanguage::init() {
_add_global(StaticCString::create(CoreConstants::get_global_constant_name(i)), CoreConstants::get_global_constant_value(i));
}
_add_global(StaticCString::create("PI"), Math_PI);
_add_global(StaticCString::create("TAU"), Math_TAU);
_add_global(StaticCString::create("INF"), INFINITY);
_add_global(StaticCString::create("NAN"), NAN);
_add_global(StaticCString::create("PI"), Math::PI);
_add_global(StaticCString::create("TAU"), Math::TAU);
_add_global(StaticCString::create("INF"), Math::INF);
_add_global(StaticCString::create("NAN"), Math::NaN);
//populate native classes

View file

@ -488,22 +488,22 @@ void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const
void GDScriptLanguage::get_public_constants(List<Pair<String, Variant>> *p_constants) const {
Pair<String, Variant> pi;
pi.first = "PI";
pi.second = Math_PI;
pi.second = Math::PI;
p_constants->push_back(pi);
Pair<String, Variant> tau;
tau.first = "TAU";
tau.second = Math_TAU;
tau.second = Math::TAU;
p_constants->push_back(tau);
Pair<String, Variant> infinity;
infinity.first = "INF";
infinity.second = INFINITY;
infinity.second = Math::INF;
p_constants->push_back(infinity);
Pair<String, Variant> nan;
nan.first = "NAN";
nan.second = NAN;
nan.second = Math::NaN;
p_constants->push_back(nan);
}

View file

@ -2720,16 +2720,16 @@ GDScriptParser::ExpressionNode *GDScriptParser::parse_builtin_constant(Expressio
switch (op_type) {
case GDScriptTokenizer::Token::CONST_PI:
constant->value = Math_PI;
constant->value = Math::PI;
break;
case GDScriptTokenizer::Token::CONST_TAU:
constant->value = Math_TAU;
constant->value = Math::TAU;
break;
case GDScriptTokenizer::Token::CONST_INF:
constant->value = INFINITY;
constant->value = Math::INF;
break;
case GDScriptTokenizer::Token::CONST_NAN:
constant->value = NAN;
constant->value = Math::NaN;
break;
default:
return nullptr; // Unreachable.

View file

@ -232,7 +232,7 @@ Dictionary GLTFLight::to_dictionary() const {
if (intensity != 1.0f) {
d["intensity"] = intensity;
}
if (light_type != "directional" && range != INFINITY) {
if (light_type != "directional" && range != Math::INF) {
d["range"] = range;
}
if (light_type == "spot") {

View file

@ -48,9 +48,9 @@ private:
Color color = Color(1.0f, 1.0f, 1.0f);
float intensity = 1.0f;
String light_type;
float range = INFINITY;
float range = Math::INF;
float inner_cone_angle = 0.0f;
float outer_cone_angle = Math_TAU / 8.0f;
float outer_cone_angle = Math::TAU / 8.0f;
Dictionary additional_data;
public:

View file

@ -6973,7 +6973,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_
animation->set_loop_mode(Animation::LOOP_LINEAR);
}
double anim_start = p_trimming ? INFINITY : 0.0;
double anim_start = p_trimming ? Math::INF : 0.0;
double anim_end = 0.0;
for (const KeyValue<int, GLTFAnimation::NodeTrack> &track_i : anim->get_node_tracks()) {
@ -7660,7 +7660,7 @@ bool GLTFDocument::_convert_animation_node_track(Ref<GLTFState> p_state, GLTFAni
} else {
Vector3 rotation_euler = p_godot_animation->track_get_key_value(p_godot_anim_track_index, key_i);
if (node_prop == "rotation_degrees") {
rotation_euler *= Math_TAU / 360.0;
rotation_euler *= Math::TAU / 360.0;
}
rotation_quaternion = Quaternion::from_euler(rotation_euler);
}

View file

@ -563,7 +563,7 @@ void GodotBody2D::integrate_forces(real_t p_step) {
linear_velocity = constant_linear_velocity + motion / p_step;
real_t rot = new_transform.get_rotation() - get_transform().get_rotation();
angular_velocity = constant_angular_velocity + remainder(rot, 2.0 * Math_PI) / p_step;
angular_velocity = constant_angular_velocity + remainder(rot, 2.0 * Math::PI) / p_step;
do_motion = true;

View file

@ -36,7 +36,7 @@
#define ACCUMULATE_IMPULSES
#define MIN_VELOCITY 0.001
#define MAX_BIAS_ROTATION (Math_PI / 8)
#define MAX_BIAS_ROTATION (Math::PI / 8)
void GodotBodyPair2D::_add_contact(const Vector2 &p_point_A, const Vector2 &p_point_B, void *p_self) {
GodotBodyPair2D *self = static_cast<GodotBodyPair2D *>(p_self);

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;

View file

@ -98,14 +98,14 @@ void GridMapEditor::_menu_option(int p_option) {
Basis r;
if (input_action == INPUT_PASTE) {
r = node->get_basis_with_orthogonal_index(paste_indicator.orientation);
r.rotate(Vector3(0, 1, 0), -Math_PI / 2.0);
r.rotate(Vector3(0, 1, 0), -Math::PI / 2.0);
paste_indicator.orientation = node->get_orthogonal_index_from_basis(r);
_update_paste_indicator();
break;
}
r = node->get_basis_with_orthogonal_index(cursor_rot);
r.rotate(Vector3(0, 1, 0), -Math_PI / 2.0);
r.rotate(Vector3(0, 1, 0), -Math::PI / 2.0);
cursor_rot = node->get_orthogonal_index_from_basis(r);
_update_cursor_transform();
} break;
@ -113,14 +113,14 @@ void GridMapEditor::_menu_option(int p_option) {
Basis r;
if (input_action == INPUT_PASTE) {
r = node->get_basis_with_orthogonal_index(paste_indicator.orientation);
r.rotate(Vector3(1, 0, 0), -Math_PI / 2.0);
r.rotate(Vector3(1, 0, 0), -Math::PI / 2.0);
paste_indicator.orientation = node->get_orthogonal_index_from_basis(r);
_update_paste_indicator();
break;
}
r = node->get_basis_with_orthogonal_index(cursor_rot);
r.rotate(Vector3(1, 0, 0), -Math_PI / 2.0);
r.rotate(Vector3(1, 0, 0), -Math::PI / 2.0);
cursor_rot = node->get_orthogonal_index_from_basis(r);
_update_cursor_transform();
} break;
@ -128,14 +128,14 @@ void GridMapEditor::_menu_option(int p_option) {
Basis r;
if (input_action == INPUT_PASTE) {
r = node->get_basis_with_orthogonal_index(paste_indicator.orientation);
r.rotate(Vector3(0, 0, 1), -Math_PI / 2.0);
r.rotate(Vector3(0, 0, 1), -Math::PI / 2.0);
paste_indicator.orientation = node->get_orthogonal_index_from_basis(r);
_update_paste_indicator();
break;
}
r = node->get_basis_with_orthogonal_index(cursor_rot);
r.rotate(Vector3(0, 0, 1), -Math_PI / 2.0);
r.rotate(Vector3(0, 0, 1), -Math::PI / 2.0);
cursor_rot = node->get_orthogonal_index_from_basis(r);
_update_cursor_transform();
} break;
@ -143,14 +143,14 @@ void GridMapEditor::_menu_option(int p_option) {
Basis r;
if (input_action == INPUT_PASTE) {
r = node->get_basis_with_orthogonal_index(paste_indicator.orientation);
r.rotate(Vector3(0, 1, 0), Math_PI / 2.0);
r.rotate(Vector3(0, 1, 0), Math::PI / 2.0);
paste_indicator.orientation = node->get_orthogonal_index_from_basis(r);
_update_paste_indicator();
break;
}
r = node->get_basis_with_orthogonal_index(cursor_rot);
r.rotate(Vector3(0, 1, 0), Math_PI / 2.0);
r.rotate(Vector3(0, 1, 0), Math::PI / 2.0);
cursor_rot = node->get_orthogonal_index_from_basis(r);
_update_cursor_transform();
} break;
@ -158,14 +158,14 @@ void GridMapEditor::_menu_option(int p_option) {
Basis r;
if (input_action == INPUT_PASTE) {
r = node->get_basis_with_orthogonal_index(paste_indicator.orientation);
r.rotate(Vector3(1, 0, 0), Math_PI / 2.0);
r.rotate(Vector3(1, 0, 0), Math::PI / 2.0);
paste_indicator.orientation = node->get_orthogonal_index_from_basis(r);
_update_paste_indicator();
break;
}
r = node->get_basis_with_orthogonal_index(cursor_rot);
r.rotate(Vector3(1, 0, 0), Math_PI / 2.0);
r.rotate(Vector3(1, 0, 0), Math::PI / 2.0);
cursor_rot = node->get_orthogonal_index_from_basis(r);
_update_cursor_transform();
} break;
@ -173,14 +173,14 @@ void GridMapEditor::_menu_option(int p_option) {
Basis r;
if (input_action == INPUT_PASTE) {
r = node->get_basis_with_orthogonal_index(paste_indicator.orientation);
r.rotate(Vector3(0, 0, 1), Math_PI / 2.0);
r.rotate(Vector3(0, 0, 1), Math::PI / 2.0);
paste_indicator.orientation = node->get_orthogonal_index_from_basis(r);
_update_paste_indicator();
break;
}
r = node->get_basis_with_orthogonal_index(cursor_rot);
r.rotate(Vector3(0, 0, 1), Math_PI / 2.0);
r.rotate(Vector3(0, 0, 1), Math::PI / 2.0);
cursor_rot = node->get_orthogonal_index_from_basis(r);
_update_cursor_transform();
} break;

View file

@ -111,7 +111,7 @@ bool JoltPhysicsDirectSpaceState3D::_cast_motion_impl(const JPH::Shape &p_jolt_s
};
// Figure out the number of steps we need in our binary search in order to achieve millimeter precision, within reason.
const int step_count = CLAMP(int(logf(1000.0f * motion_length) / (float)Math_LN2), 4, 16);
const int step_count = CLAMP(int(logf(1000.0f * motion_length) / (float)Math::LN2), 4, 16);
bool collided = false;

View file

@ -57,7 +57,7 @@ constexpr double DEFAULT_CONTACT_MAX_SEPARATION = 0.05;
constexpr double DEFAULT_CONTACT_MAX_ALLOWED_PENETRATION = 0.01;
constexpr double DEFAULT_CONTACT_DEFAULT_BIAS = 0.8;
constexpr double DEFAULT_SLEEP_THRESHOLD_LINEAR = 0.1;
constexpr double DEFAULT_SLEEP_THRESHOLD_ANGULAR = 8.0 * Math_PI / 180;
constexpr double DEFAULT_SLEEP_THRESHOLD_ANGULAR = 8.0 * Math::PI / 180;
constexpr double DEFAULT_SOLVER_ITERATIONS = 8;
} // namespace

View file

@ -253,7 +253,7 @@ void OpenXRHandTrackingExtension::on_process() {
// SKELETON_RIG_HUMANOID bone adjustment. This rotation performs:
// OpenXR Z+ -> Godot Humanoid Y- (Back along the bone)
// OpenXR Y+ -> Godot Humanoid Z- (Out the back of the hand)
const Quaternion bone_adjustment(0.0, -Math_SQRT12, Math_SQRT12, 0.0);
const Quaternion bone_adjustment(0.0, -Math::SQRT12, Math::SQRT12, 0.0);
for (int joint = 0; joint < XR_HAND_JOINT_COUNT_EXT; joint++) {
const XrHandJointLocationEXT &location = hand_trackers[i].joint_locations[joint];

View file

@ -77,7 +77,7 @@ Ref<Mesh> OpenXRCompositionLayerCylinder::_create_fallback_mesh() {
Vector<int> indices;
float delta_angle = central_angle / fallback_segments;
float start_angle = (-Math_PI / 2.0) - (central_angle / 2.0);
float start_angle = (-Math::PI / 2.0) - (central_angle / 2.0);
for (uint32_t i = 0; i < fallback_segments + 1; i++) {
float current_angle = start_angle + (delta_angle * i);
@ -192,7 +192,7 @@ Vector2 OpenXRCompositionLayerCylinder::intersects_ray(const Vector3 &p_origin,
Vector3 intersection = p_origin + p_direction * t;
Basis correction = cylinder_transform.basis.inverse();
correction.rotate(Vector3(0.0, 1.0, 0.0), -Math_PI / 2.0);
correction.rotate(Vector3(0.0, 1.0, 0.0), -Math::PI / 2.0);
Vector3 relative_point = correction.xform(intersection - cylinder_transform.origin);
Vector2 projected_point = Vector2(relative_point.x, relative_point.z);

View file

@ -46,13 +46,13 @@ class OpenXRCompositionLayerCylinder : public OpenXRCompositionLayer {
{}, // subImage
{ { 0, 0, 0, 0 }, { 0, 0, 0 } }, // pose
1.0, // radius
Math_PI / 2.0, // centralAngle
Math::PI / 2.0, // centralAngle
1.0, // aspectRatio
};
float radius = 1.0;
float aspect_ratio = 1.0;
float central_angle = Math_PI / 2.0;
float central_angle = Math::PI / 2.0;
uint32_t fallback_segments = 10;
protected:

View file

@ -80,7 +80,7 @@ Ref<Mesh> OpenXRCompositionLayerEquirect::_create_fallback_mesh() {
float step_horizontal = central_horizontal_angle / fallback_segments;
float step_vertical = (upper_vertical_angle + lower_vertical_angle) / fallback_segments;
float start_horizontal_angle = Math_PI - (central_horizontal_angle / 2.0);
float start_horizontal_angle = Math::PI - (central_horizontal_angle / 2.0);
for (uint32_t i = 0; i < fallback_segments + 1; i++) {
for (uint32_t j = 0; j < fallback_segments + 1; j++) {
@ -155,7 +155,7 @@ float OpenXRCompositionLayerEquirect::get_central_horizontal_angle() const {
}
void OpenXRCompositionLayerEquirect::set_upper_vertical_angle(float p_angle) {
ERR_FAIL_COND(p_angle <= 0 || p_angle > (Math_PI / 2.0));
ERR_FAIL_COND(p_angle <= 0 || p_angle > (Math::PI / 2.0));
upper_vertical_angle = p_angle;
composition_layer.upperVerticalAngle = p_angle;
update_fallback_mesh();
@ -166,7 +166,7 @@ float OpenXRCompositionLayerEquirect::get_upper_vertical_angle() const {
}
void OpenXRCompositionLayerEquirect::set_lower_vertical_angle(float p_angle) {
ERR_FAIL_COND(p_angle <= 0 || p_angle > (Math_PI / 2.0));
ERR_FAIL_COND(p_angle <= 0 || p_angle > (Math::PI / 2.0));
lower_vertical_angle = p_angle;
composition_layer.lowerVerticalAngle = -p_angle;
update_fallback_mesh();
@ -209,7 +209,7 @@ Vector2 OpenXRCompositionLayerEquirect::intersects_ray(const Vector3 &p_origin,
Vector3 intersection = p_origin + p_direction * t;
Basis correction = equirect_transform.basis.inverse();
correction.rotate(Vector3(0.0, 1.0, 0.0), -Math_PI / 2.0);
correction.rotate(Vector3(0.0, 1.0, 0.0), -Math::PI / 2.0);
Vector3 relative_point = correction.xform(intersection - equirect_transform.origin);
float horizontal_intersection_angle = Math::atan2(relative_point.z, relative_point.x);
@ -217,7 +217,7 @@ Vector2 OpenXRCompositionLayerEquirect::intersects_ray(const Vector3 &p_origin,
return Vector2(-1.0, -1.0);
}
float vertical_intersection_angle = Math::acos(relative_point.y / radius) - (Math_PI / 2.0);
float vertical_intersection_angle = Math::acos(relative_point.y / radius) - (Math::PI / 2.0);
if (vertical_intersection_angle < 0) {
if (Math::abs(vertical_intersection_angle) > upper_vertical_angle) {
return Vector2(-1.0, -1.0);

View file

@ -46,15 +46,15 @@ class OpenXRCompositionLayerEquirect : public OpenXRCompositionLayer {
{}, // subImage
{ { 0, 0, 0, 0 }, { 0, 0, 0 } }, // pose
1.0, // radius
Math_PI / 2.0, // centralHorizontalAngle
Math_PI / 4.0, // upperVerticalAngle
-Math_PI / 4.0, // lowerVerticalAngle
Math::PI / 2.0, // centralHorizontalAngle
Math::PI / 4.0, // upperVerticalAngle
-Math::PI / 4.0, // lowerVerticalAngle
};
float radius = 1.0;
float central_horizontal_angle = Math_PI / 2.0;
float upper_vertical_angle = Math_PI / 4.0;
float lower_vertical_angle = Math_PI / 4.0;
float central_horizontal_angle = Math::PI / 2.0;
float upper_vertical_angle = Math::PI / 4.0;
float lower_vertical_angle = Math::PI / 4.0;
uint32_t fallback_segments = 10;
protected:

View file

@ -311,7 +311,7 @@ void OpenXRHand::_update_skeleton() {
// SKELETON_RIG_HUMANOID bone adjustment. This rotation performs:
// OpenXR Z+ -> Godot Humanoid Y- (Back along the bone)
// OpenXR Y+ -> Godot Humanoid Z- (Out the back of the hand)
Quaternion(0.0, -Math_SQRT12, Math_SQRT12, 0.0),
Quaternion(0.0, -Math::SQRT12, Math::SQRT12, 0.0),
};
// we cache our transforms so we can quickly calculate local transforms