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
181 changed files with 812 additions and 818 deletions

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