diff --git a/src/xrt/auxiliary/math/m_api.h b/src/xrt/auxiliary/math/m_api.h index 15939f223..10af976b4 100644 --- a/src/xrt/auxiliary/math/m_api.h +++ b/src/xrt/auxiliary/math/m_api.h @@ -18,6 +18,8 @@ #include "xrt/xrt_defines.h" +#include "math/m_mathinclude.h" + #ifdef __cplusplus extern "C" { #endif @@ -75,6 +77,25 @@ extern "C" { */ #define CLAMP(X, A, B) (MIN(MAX((X), (A)), (B))) +/*! + * Degrees to radians conversion. + * + * @ingroup aux_math + */ +// clang-format off +// @todo: Remove the clang-format off/on when we move to a newer clang-format in CI. +#define DEG_TO_RAD(DEG) ((DEG) * M_PI / 180.) +// clang-format on + +/*! + * Radians to degrees conversion. + * + * @ingroup aux_math + */ +// clang-format off +#define RAD_TO_DEG(RAD) ((RAD) * 180.0 / M_PI) +// clang-format on + /* * diff --git a/src/xrt/auxiliary/util/u_hand_simulation.c b/src/xrt/auxiliary/util/u_hand_simulation.c index 0f435b1ac..0fcaf7a4c 100644 --- a/src/xrt/auxiliary/util/u_hand_simulation.c +++ b/src/xrt/auxiliary/util/u_hand_simulation.c @@ -32,8 +32,6 @@ struct orientations54 struct xrt_quat q[HAND_SIM_NUM_FINGERS][HAND_SIM_NUM_ORIENTATIONS_IN_FINGER]; }; -#define DEG_TO_RAD(DEG) (DEG * M_PI / 180.) - // For debugging. #if 0 #include diff --git a/src/xrt/auxiliary/util/u_hand_tracking.c b/src/xrt/auxiliary/util/u_hand_tracking.c index 8ca816e67..0d7dc2b43 100644 --- a/src/xrt/auxiliary/util/u_hand_tracking.c +++ b/src/xrt/auxiliary/util/u_hand_tracking.c @@ -20,8 +20,6 @@ #include "util/u_time.h" -#define DEG_TO_RAD(DEG) (DEG * M_PI / 180.) - bool u_hand_joint_is_metacarpal(enum xrt_hand_joint joint) { diff --git a/src/xrt/auxiliary/vive/vive_poses.c b/src/xrt/auxiliary/vive/vive_poses.c index 9b714caa7..7837aebe1 100644 --- a/src/xrt/auxiliary/vive/vive_poses.c +++ b/src/xrt/auxiliary/vive/vive_poses.c @@ -12,8 +12,6 @@ #include "math/m_mathinclude.h" #include "math/m_api.h" -#define DEG_TO_RAD(DEG) (DEG * M_PI / 180.) - static void vive_poses_apply_right_transform(struct xrt_vec3 *out_transform_position, struct xrt_vec3 *out_transform_rotation) { diff --git a/src/xrt/drivers/android/android_sensors.c b/src/xrt/drivers/android/android_sensors.c index 3efd1203a..94f624511 100644 --- a/src/xrt/drivers/android/android_sensors.c +++ b/src/xrt/drivers/android/android_sensors.c @@ -133,12 +133,10 @@ load_cardboard_distortion(struct android_device *d, args->tray_to_lens_distance_meters = params.tray_to_lens_distance; } -#define DEG_TO_RAD(x) (float)(x * M_PI / 180.0) args->fov = (struct xrt_fov){.angle_left = -DEG_TO_RAD(angles[0]), .angle_right = DEG_TO_RAD(angles[1]), .angle_down = -DEG_TO_RAD(angles[2]), .angle_up = DEG_TO_RAD(angles[3])}; -#undef DEG_TO_RAD ANDROID_INFO(d, "loaded calibration for device %s (%s)", model, vendor); diff --git a/src/xrt/drivers/arduino/arduino_device.c b/src/xrt/drivers/arduino/arduino_device.c index 535951836..44f9258bc 100644 --- a/src/xrt/drivers/arduino/arduino_device.c +++ b/src/xrt/drivers/arduino/arduino_device.c @@ -405,9 +405,9 @@ arduino_device_create(struct os_ble_device *ble) m_imu_3dof_init(&ad->fusion, M_IMU_3DOF_USE_GRAVITY_DUR_300MS); -#define DEG_TO_RAD ((double)M_PI / 180.0) +#define DEG_TO_RAD_MULTIPLIER ((double)M_PI / 180.0) float accel_ticks_to_float = (4.0 * MATH_GRAVITY_M_S2) / INT16_MAX; - float gyro_ticks_to_float = (2000.0 * DEG_TO_RAD) / INT16_MAX; + float gyro_ticks_to_float = (2000.0 * DEG_TO_RAD_MULTIPLIER) / INT16_MAX; m_imu_pre_filter_init(&ad->pre_filter, accel_ticks_to_float, gyro_ticks_to_float); m_imu_pre_filter_set_switch_x_and_y(&ad->pre_filter); diff --git a/src/xrt/drivers/pssense/pssense_driver.c b/src/xrt/drivers/pssense/pssense_driver.c index 3394ae3c3..9402dd138 100644 --- a/src/xrt/drivers/pssense/pssense_driver.c +++ b/src/xrt/drivers/pssense/pssense_driver.c @@ -43,8 +43,6 @@ DEBUG_GET_ONCE_LOG_OPTION(pssense_log, "PSSENSE_LOG", U_LOGGING_INFO) -#define DEG_TO_RAD(DEG) (DEG * M_PI / 180.) - static struct xrt_binding_input_pair simple_inputs_pssense[4] = { {XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_PSSENSE_TRIGGER_VALUE}, {XRT_INPUT_SIMPLE_MENU_CLICK, XRT_INPUT_PSSENSE_OPTIONS_CLICK}, diff --git a/src/xrt/drivers/rift/rift_interface.h b/src/xrt/drivers/rift/rift_interface.h index d02b9d18e..4fca569af 100644 --- a/src/xrt/drivers/rift/rift_interface.h +++ b/src/xrt/drivers/rift/rift_interface.h @@ -37,7 +37,6 @@ extern "C" { #define IMU_SAMPLE_RATE (1000) // 1000hz #define NS_PER_SAMPLE (1000 * 1000) // 1ms (1,000,000 ns) per sample -#define DEG_TO_RAD(DEG) (DEG * M_PI / 180.0) #define MICROMETERS_TO_METERS(microns) (float)microns / 1000000.0f // value taken from LibOVR 0.4.4 diff --git a/src/xrt/drivers/rift_s/rift_s_controller.c b/src/xrt/drivers/rift_s/rift_s_controller.c index 380b67b77..5529c1c6b 100644 --- a/src/xrt/drivers/rift_s/rift_s_controller.c +++ b/src/xrt/drivers/rift_s/rift_s_controller.c @@ -40,8 +40,6 @@ /* Set to 1 to print controller states continuously */ #define DUMP_CONTROLLER_STATE 0 -#define DEG_TO_RAD(D) ((D)*M_PI / 180.) - static struct xrt_binding_input_pair simple_inputs_rift_s[4] = { {XRT_INPUT_SIMPLE_SELECT_CLICK, XRT_INPUT_TOUCH_TRIGGER_VALUE}, {XRT_INPUT_SIMPLE_MENU_CLICK, XRT_INPUT_TOUCH_MENU_CLICK}, diff --git a/src/xrt/drivers/rift_s/rift_s_hmd.c b/src/xrt/drivers/rift_s/rift_s_hmd.c index 4bc2fcb66..4b5298824 100644 --- a/src/xrt/drivers/rift_s/rift_s_hmd.c +++ b/src/xrt/drivers/rift_s/rift_s_hmd.c @@ -40,8 +40,6 @@ #include "rift_s_hmd.h" -#define DEG_TO_RAD(D) ((D)*M_PI / 180.) - static xrt_result_t rift_s_get_tracked_pose(struct xrt_device *xdev, diff --git a/src/xrt/drivers/simula/svr_hmd.c b/src/xrt/drivers/simula/svr_hmd.c index 7c3b56ad9..398297de3 100644 --- a/src/xrt/drivers/simula/svr_hmd.c +++ b/src/xrt/drivers/simula/svr_hmd.c @@ -97,8 +97,6 @@ svr_hmd_get_tracked_pose(struct xrt_device *xdev, return XRT_SUCCESS; } -#define DEG_TO_RAD(DEG) (DEG * M_PI / 180.) - static xrt_result_t svr_hmd_get_view_poses(struct xrt_device *xdev, const struct xrt_vec3 *default_eye_relation, diff --git a/src/xrt/tracking/hand/mercury/hg_sync.cpp b/src/xrt/tracking/hand/mercury/hg_sync.cpp index df88251db..45db3fabf 100644 --- a/src/xrt/tracking/hand/mercury/hg_sync.cpp +++ b/src/xrt/tracking/hand/mercury/hg_sync.cpp @@ -25,7 +25,6 @@ namespace xrt::tracking::hand::mercury { -#define DEG_TO_RAD(DEG) (DEG * M_PI / 180.) DEBUG_GET_ONCE_LOG_OPTION(mercury_log, "MERCURY_LOG", U_LOGGING_WARN) DEBUG_GET_ONCE_BOOL_OPTION(mercury_optimize_hand_size, "MERCURY_optimize_hand_size", true)