Monado OpenXR Runtime

C interface to some transform-related math functions. More...

Collaboration diagram for Math:

Files

file  m_api.h
 C interface to math library.
 
file  m_base.cpp
 Base implementations for math library.
 
file  m_clock_offset.h
 Helpers to estimate offsets between clocks.
 
file  m_documentation.hpp
 Header with only documentation.
 
file  m_eigen_interop.hpp
 Interoperability helpers connecting internal math types and Eigen.
 
file  m_filter_fifo.c
 A fifo that also lets you dynamically filter.
 
file  m_filter_fifo.h
 A fifo that also lets you dynamically filter.
 
file  m_filter_one_euro.c
 The "One Euro Filter" for filtering interaction data.
 
file  m_filter_one_euro.h
 Header for a "One Euro Filter" implementation.
 
file  m_hash.cpp
 Hashing function.
 
file  m_imu_3dof.c
 A IMU fusion specially made for 3dof devices.
 
file  m_imu_3dof.h
 A IMU fusion specially made for 3dof devices.
 
file  m_imu_pre.c
 IMU pre filter struct.
 
file  m_imu_pre.h
 IMU pre filter struct.
 
file  m_lowpass_float.cpp
 Wrap float filters for C.
 
file  m_lowpass_float.h
 Low-pass IIR filter for floats - C wrapper.
 
file  m_lowpass_float.hpp
 Low-pass IIR filter.
 
file  m_lowpass_float_vector.hpp
 Low-pass IIR filter on vectors.
 
file  m_lowpass_integer.cpp
 Wrap integer filters for C.
 
file  m_lowpass_integer.h
 Low-pass IIR filter for integers - C wrapper.
 
file  m_lowpass_integer.hpp
 Low-pass IIR filter for integers.
 
file  m_mathinclude.h
 Wrapper header for <math.h> to ensure pi-related math constants are defined.
 
file  m_matrix_2x2.h
 C matrix_2x2 math library.
 
file  m_matrix_4x4_f64.h
 C matrix 4x4 f64 math library.
 
file  m_matrix_projection.cpp
 Matrix function for creating projection matrices.
 
file  m_optics.c
 Functions related to field-of-view.
 
file  m_permutation.c
 Code to generate permutation of indices.
 
file  m_permutation.h
 Code to generate permutation of indices.
 
file  m_predict.c
 Simple function to predict a new pose from a given pose.
 
file  m_predict.h
 Simple function to predict a new pose from a given pose.
 
file  m_quatexpmap.cpp
 Base implementations for math library.
 
file  m_rational.hpp
 A very simple rational number type.
 
file  m_relation_history.cpp
 Small utility for keeping track of the history of an xrt_space_relation, ie.
 
file  m_space.cpp
 Functions for manipulating a xrt_relation_chain struct.
 
file  m_space.h
 Functions for manipulating xrt_pose, xrt_space_relation and xrt_relation_chain structs.
 
file  m_vec2.h
 C vec2 math library.
 
file  m_vec3.h
 C vec3 math library.
 

Data Structures

struct  m_filter_one_euro_base
 Base data type for One Euro filter instances. More...
 
struct  m_filter_euro_f32
 One Euro filter for a single float measurement. More...
 
struct  m_filter_euro_vec2
 One Euro filter for a 2D float measurement. More...
 
struct  m_filter_euro_vec3
 One Euro filter for a 3D float measurement. More...
 
struct  m_filter_euro_quat
 One Euro filter for a unit quaternion (used as 3D rotation). More...
 

Macros

#define MATH_GRAVITY_M_S2   (9.8066)
 Standard gravity acceleration constant. More...
 
#define MIN(A, B)   ((A) < (B) ? (A) : (B))
 Minimum of A and B. More...
 
#define MAX(A, B)   ((A) > (B) ? (A) : (B))
 Maximum of A and B. More...
 
#define CLAMP(X, A, B)   (MIN(MAX((X), (A)), (B)))
 X clamped to the range [A, B]. More...
 

Functions

size_t math_hash_string (const char *str_c, size_t length)
 Generate a hash value from the given string, trailing zero not included. More...
 
void math_matrix_3x3_identity (struct xrt_matrix_3x3 *mat)
 Initialize a 3x3 matrix to the identity matrix. More...
 
void math_matrix_3x3_from_quat (const struct xrt_quat *q, struct xrt_matrix_3x3 *result_out)
 Initialize a 3x3 matrix from a quaternion. More...
 
void math_matrix_3x3_f64_identity (struct xrt_matrix_3x3_f64 *mat)
 Initialize a double 3x3 matrix to the identity matrix. More...
 
void math_matrix_3x3_transform_vec3 (const struct xrt_matrix_3x3 *left, const struct xrt_vec3 *right, struct xrt_vec3 *result_out)
 Transform a vec3 by a 3x3 matrix. More...
 
void math_matrix_4x4_transform_vec3 (const struct xrt_matrix_4x4 *left, const struct xrt_vec3 *right, struct xrt_vec3 *result_out)
 Transform a vec3 by a 4x4 matrix, extending the vector with w = 1.0. More...
 
void math_matrix_3x3_f64_transform_vec3_f64 (const struct xrt_matrix_3x3_f64 *left, const struct xrt_vec3_f64 *right, struct xrt_vec3_f64 *result_out)
 Transform a double vec3 by a 3x3 double matrix. More...
 
bool math_compute_fovs (double w_total, double w_1, double horizfov_total, double h_total, double h_1, double vertfov_total, struct xrt_fov *fov)
 Perform the computations from "Computing Half-Fields-Of-View from Simpler Display Models", to get half-FOVs from things we can retrieve from other APIs. More...
 
void m_predict_relation (const struct xrt_space_relation *rel, double delta_s, struct xrt_space_relation *out_rel)
 Using the given xrt_space_relation predicts a new xrt_space_relation delta_s into the future. More...
 
static bool m_pose_is_identity (const struct xrt_pose *pose)
 
static void m_space_relation_from_pose (const struct xrt_pose *pose, bool set_tracked, struct xrt_space_relation *out_relation)
 Create an xrt_space_relation from a pose. More...
 
static void m_space_relation_ident (struct xrt_space_relation *out_relation)
 Create an xrt_space_relation with only orientation and position valid flags. More...
 
void m_space_relation_invert (struct xrt_space_relation *relation, struct xrt_space_relation *out_relation)
 
void m_space_relation_interpolate (struct xrt_space_relation *a, struct xrt_space_relation *b, float t, enum xrt_space_relation_flags flags, struct xrt_space_relation *out_relation)
 Linearly interpolate between two relations a and b. More...
 
bool math_vec3_validate (const struct xrt_vec3 *vec3)
 Check if this vec3 is valid for math operations. More...
 
void math_vec3_accum (const struct xrt_vec3 *additional, struct xrt_vec3 *inAndOut)
 Accumulate a vector by adding in-place. More...
 
void math_vec3_subtract (const struct xrt_vec3 *subtrahend, struct xrt_vec3 *inAndOut)
 Subtract from a vector in-place. More...
 
void math_vec3_scalar_mul (float scalar, struct xrt_vec3 *inAndOut)
 Multiply a vector in-place. More...
 
void math_vec3_cross (const struct xrt_vec3 *l, const struct xrt_vec3 *r, struct xrt_vec3 *result)
 Cross product of a vector. More...
 
void math_vec3_translation_from_isometry (const struct xrt_matrix_4x4 *isometry, struct xrt_vec3 *result)
 Get translation vector from isometry matrix (col-major). More...
 
void math_vec3_normalize (struct xrt_vec3 *in)
 Normalize a vec3 in place. More...
 
void math_vec3_f64_cross (const struct xrt_vec3_f64 *l, const struct xrt_vec3_f64 *r, struct xrt_vec3_f64 *result)
 Cross product of a vec3_f64. More...
 
void math_vec3_f64_normalize (struct xrt_vec3_f64 *in)
 Normalize a vec3_f64 in place. More...
 
void math_quat_from_angle_vector (float angle_rads, const struct xrt_vec3 *vector, struct xrt_quat *result)
 Create a rotation from an angle in radians and a unit vector. More...
 
void math_quat_from_euler_angles (const struct xrt_vec3 *angles, struct xrt_quat *result)
 Create a rotation from euler angles to a quaternion. More...
 
void math_quat_from_matrix_3x3 (const struct xrt_matrix_3x3 *mat, struct xrt_quat *result)
 Create a rotation from a 3x3 rotation (row major) matrix. More...
 
void math_quat_from_plus_x_z (const struct xrt_vec3 *plus_x, const struct xrt_vec3 *plus_z, struct xrt_quat *result)
 Create a rotation from two vectors plus x and z, by creating a rotation matrix by crossing z and x to get the y axis. More...
 
bool math_quat_validate (const struct xrt_quat *quat)
 Check if this quat can be used in transformation operations. More...
 
bool math_quat_validate_within_1_percent (const struct xrt_quat *quat)
 Check if this quat is within 1% of unit length. More...
 
void math_quat_invert (const struct xrt_quat *quat, struct xrt_quat *out_quat)
 Invert a quaternion. More...
 
float math_quat_len (const struct xrt_quat *quat)
 The euclidean norm or length of a quaternion. More...
 
void math_quat_normalize (struct xrt_quat *inout)
 Normalize a quaternion. More...
 
bool math_quat_ensure_normalized (struct xrt_quat *inout)
 Normalizes a quaternion if it has accumulated float precision errors. More...
 
void math_quat_rotate_vec3 (const struct xrt_quat *left, const struct xrt_vec3 *right, struct xrt_vec3 *result)
 Rotate a vector. More...
 
void math_quat_rotate (const struct xrt_quat *left, const struct xrt_quat *right, struct xrt_quat *result)
 Rotate a quaternion (compose rotations). More...
 
void math_quat_unrotate (const struct xrt_quat *left, const struct xrt_quat *right, struct xrt_quat *result)
 Inverse of math_quat_rotate. More...
 
void math_quat_integrate_velocity (const struct xrt_quat *quat, const struct xrt_vec3 *ang_vel, float dt, struct xrt_quat *result)
 Integrate a local angular velocity vector (exponential map) and apply to a quaternion. More...
 
void math_quat_finite_difference (const struct xrt_quat *quat0, const struct xrt_quat *quat1, float dt, struct xrt_vec3 *out_ang_vel)
 Compute a global angular velocity vector (exponential map format) by taking the finite difference of two quaternions. More...
 
void math_quat_exp (const struct xrt_vec3 *axis_angle, struct xrt_quat *out_quat)
 Takes a rotation vector equal to half of a Rodrigues rotation vector and returns its corresponding unit quaternion. More...
 
void math_quat_ln (const struct xrt_quat *quat, struct xrt_vec3 *out_axis_angle)
 Takes a unit quaternion and returns a rotation vector equal to half of its corresponding Rodrigues rotation vector. More...
 
void math_quat_rotate_derivative (const struct xrt_quat *quat, const struct xrt_vec3 *deriv, struct xrt_vec3 *result)
 Used to rotate a derivative like a angular velocity. More...
 
void math_quat_slerp (const struct xrt_quat *left, const struct xrt_quat *right, float t, struct xrt_quat *result)
 Slerp (spherical linear interpolation) between two quaternions. More...
 
void math_quat_from_swing (const struct xrt_vec2 *swing, struct xrt_quat *result)
 Converts a 2D vector to a quaternion. More...
 
void math_quat_from_swing_twist (const struct xrt_vec2 *swing, const float twist, struct xrt_quat *result)
 Converts a 2D vector and a float to a quaternion. More...
 
void math_quat_to_swing_twist (const struct xrt_quat *in, struct xrt_vec2 *out_swing, float *out_twist)
 Converts a quaternion to XY-swing and Z-twist. More...
 
void math_matrix_3x3_multiply (const struct xrt_matrix_3x3 *left, const struct xrt_matrix_3x3 *right, struct xrt_matrix_3x3 *result_out)
 Multiply Matrix3x3. More...
 
void math_matrix_3x3_inverse (const struct xrt_matrix_3x3 *in, struct xrt_matrix_3x3 *result)
 Invert Matrix3x3. More...
 
void math_matrix_3x3_transpose (const struct xrt_matrix_3x3 *in, struct xrt_matrix_3x3 *result)
 Transpose Matrix3x3. More...
 
void math_matrix_3x3_f64_from_plus_x_z (const struct xrt_vec3_f64 *plus_x, const struct xrt_vec3_f64 *plus_z, struct xrt_matrix_3x3_f64 *result)
 Create a rotation from two vectors plus x and z, by creating a rotation matrix by crossing z and x to get the y axis. More...
 
void math_matrix_3x3_rotation_from_isometry (const struct xrt_matrix_4x4 *isometry, struct xrt_matrix_3x3 *result)
 Get the rotation matrix from an isomertry matrix (col-major). More...
 
void math_matrix_4x4_identity (struct xrt_matrix_4x4 *result)
 Initialize Matrix4x4 with identity. More...
 
void math_matrix_4x4_multiply (const struct xrt_matrix_4x4 *left, const struct xrt_matrix_4x4 *right, struct xrt_matrix_4x4 *result)
 Multiply Matrix4x4. More...
 
void math_matrix_4x4_inverse (const struct xrt_matrix_4x4 *in, struct xrt_matrix_4x4 *result)
 Invert Matrix4x4. More...
 
void math_matrix_4x4_isometry_inverse (const struct xrt_matrix_4x4 *in, struct xrt_matrix_4x4 *result)
 Invert a homogeneous isometry 4x4 (col-major) matrix in SE(3). More...
 
void math_matrix_4x4_transpose (const struct xrt_matrix_4x4 *in, struct xrt_matrix_4x4 *result)
 Transpose Matrix4x4. More...
 
void math_matrix_4x4_view_from_pose (const struct xrt_pose *pose, struct xrt_matrix_4x4 *result)
 Compute view matrix from xrt_pose. More...
 
void math_matrix_4x4_isometry_from_rt (const struct xrt_matrix_3x3 *rotation, const struct xrt_vec3 *translation, struct xrt_matrix_4x4 *result)
 Get an isometry matrix —in SE(3)— from a rotation matrix —SO(3)— and a translation vector. More...
 
void math_matrix_4x4_isometry_from_pose (const struct xrt_pose *pose, struct xrt_matrix_4x4 *result)
 Get a col-major isometry matrix —in SE(3)— from a pose. More...
 
void math_matrix_4x4_model (const struct xrt_pose *pose, const struct xrt_vec3 *size, struct xrt_matrix_4x4 *result)
 Compute quad layer model matrix from xrt_pose and xrt_vec2 size. More...
 
void math_matrix_4x4_inverse_view_projection (const struct xrt_matrix_4x4 *view, const struct xrt_matrix_4x4 *projection, struct xrt_matrix_4x4 *result)
 Compute inverse view projection matrix, using only the starting 3x3 block of the view. More...
 
void math_matrix_4x4_projection_vulkan_infinite_reverse (const struct xrt_fov *fov, float near_plane, struct xrt_matrix_4x4 *result)
 Compute a projection matrix with settings for Vulkan, it will also have it's far plane at infinite and the NDC depth will be reversed. More...
 
void math_pose_identity (struct xrt_pose *pose)
 Somewhat laboriously make an xrt_pose identity. More...
 
bool math_pose_validate (const struct xrt_pose *pose)
 Check if this pose can be used in transformation operations. More...
 
void math_pose_invert (const struct xrt_pose *pose, struct xrt_pose *outPose)
 Invert pose. More...
 
void math_pose_from_isometry (const struct xrt_matrix_4x4 *transform, struct xrt_pose *result)
 Converts a (col-major) isometry into a pose. More...
 
void math_pose_interpolate (const struct xrt_pose *a, const struct xrt_pose *b, float t, struct xrt_pose *outPose)
 Interpolated pose between poses a and b by lerping position and slerping orientation by t. More...
 
void math_pose_transform (const struct xrt_pose *transform, const struct xrt_pose *pose, struct xrt_pose *outPose)
 Apply a rigid-body transformation to a pose. More...
 
void math_pose_transform_point (const struct xrt_pose *transform, const struct xrt_vec3 *point, struct xrt_vec3 *out_point)
 Apply a rigid-body transformation to a point. More...
 
void m_mat4_f64_identity (struct xrt_matrix_4x4_f64 *result)
 Initialize Matrix4x4 F64 with identity. More...
 
void m_mat4_f64_invert (const struct xrt_matrix_4x4_f64 *matrix, struct xrt_matrix_4x4_f64 *result)
 Invert a Matrix4x4 F64. More...
 
void m_mat4_f64_multiply (const struct xrt_matrix_4x4_f64 *left, const struct xrt_matrix_4x4_f64 *right, struct xrt_matrix_4x4_f64 *result)
 Multiply Matrix4x4 F64. More...
 
void m_mat4_f64_orientation (const struct xrt_quat *quat, struct xrt_matrix_4x4_f64 *result)
 Initialize Matrix4x4 F64 with a orientation. More...
 
void m_mat4_f64_model (const struct xrt_pose *pose, const struct xrt_vec3 *size, struct xrt_matrix_4x4_f64 *result)
 Initialize Matrix4x4 F64 with a pose and size that can be used as a model matrix. More...
 
void m_mat4_f64_view (const struct xrt_pose *pose, const struct xrt_vec3 *size, struct xrt_matrix_4x4_f64 *result)
 Initialize Matrix4x4 F64 with a pose that can be used as a view martix. More...
 
static struct xrt_space_relationxrt_relation_chain::m_relation_chain_reserve (struct xrt_relation_chain *xrc)
 Reserve a step in the chain and return a pointer to the relation. More...
 
static void xrt_relation_chain::m_relation_chain_push_relation (struct xrt_relation_chain *xrc, const struct xrt_space_relation *relation)
 Append a new relation. More...
 
static void xrt_relation_chain::m_relation_chain_push_inverted_relation (struct xrt_relation_chain *xrc, const struct xrt_space_relation *relation)
 Append the inverse of the provided relation. More...
 
static void xrt_relation_chain::m_relation_chain_push_pose (struct xrt_relation_chain *xrc, const struct xrt_pose *pose)
 Append a new pose as a fully tracked relation. More...
 
static void xrt_relation_chain::m_relation_chain_push_pose_if_not_identity (struct xrt_relation_chain *xrc, const struct xrt_pose *pose)
 Append a new pose as a relation without velocity, if it is not the identity pose. More...
 
static void xrt_relation_chain::m_relation_chain_push_inverted_pose_if_not_identity (struct xrt_relation_chain *xrc, const struct xrt_pose *pose)
 Append the inverse of a pose as a relation without velocity, if it is not the identity pose. More...
 
void xrt_relation_chain::m_relation_chain_resolve (const struct xrt_relation_chain *xrc, struct xrt_space_relation *out_relation)
 Compute the equivalent single relation from flattening a relation chain. More...
 

Detailed Description

C interface to some transform-related math functions.

Macro Definition Documentation

◆ CLAMP

#define CLAMP (   X,
  A,
 
)    (MIN(MAX((X), (A)), (B)))

#include <auxiliary/math/m_api.h>

X clamped to the range [A, B].

◆ MATH_GRAVITY_M_S2

#define MATH_GRAVITY_M_S2   (9.8066)

#include <auxiliary/math/m_api.h>

Standard gravity acceleration constant.

◆ MAX

#define MAX (   A,
 
)    ((A) > (B) ? (A) : (B))

#include <auxiliary/math/m_api.h>

Maximum of A and B.

◆ MIN

#define MIN (   A,
 
)    ((A) < (B) ? (A) : (B))

#include <auxiliary/math/m_api.h>

Minimum of A and B.

Function Documentation

◆ m_mat4_f64_identity()

void m_mat4_f64_identity ( struct xrt_matrix_4x4_f64 result)
related

Initialize Matrix4x4 F64 with identity.

◆ m_mat4_f64_invert()

void m_mat4_f64_invert ( const struct xrt_matrix_4x4_f64 matrix,
struct xrt_matrix_4x4_f64 result 
)
related

Invert a Matrix4x4 F64.

Referenced by render_calc_time_warp_matrix().

◆ m_mat4_f64_model()

void m_mat4_f64_model ( const struct xrt_pose pose,
const struct xrt_vec3 size,
struct xrt_matrix_4x4_f64 result 
)
related

Initialize Matrix4x4 F64 with a pose and size that can be used as a model matrix.

◆ m_mat4_f64_multiply()

void m_mat4_f64_multiply ( const struct xrt_matrix_4x4_f64 left,
const struct xrt_matrix_4x4_f64 right,
struct xrt_matrix_4x4_f64 result 
)
related

Multiply Matrix4x4 F64.

Referenced by render_calc_time_warp_matrix().

◆ m_mat4_f64_orientation()

void m_mat4_f64_orientation ( const struct xrt_quat quat,
struct xrt_matrix_4x4_f64 result 
)
related

Initialize Matrix4x4 F64 with a orientation.

Referenced by render_calc_time_warp_matrix().

◆ m_mat4_f64_view()

void m_mat4_f64_view ( const struct xrt_pose pose,
const struct xrt_vec3 size,
struct xrt_matrix_4x4_f64 result 
)
related

Initialize Matrix4x4 F64 with a pose that can be used as a view martix.

◆ m_predict_relation()

void m_predict_relation ( const struct xrt_space_relation rel,
double  delta_s,
struct xrt_space_relation out_rel 
)

#include <auxiliary/math/m_predict.h>

Using the given xrt_space_relation predicts a new xrt_space_relation delta_s into the future.

Assumes that angular velocity is relative to the space the relation is in, not relative to relation::pose.

◆ m_relation_chain_push_inverted_pose_if_not_identity()

static void m_relation_chain_push_inverted_pose_if_not_identity ( struct xrt_relation_chain xrc,
const struct xrt_pose pose 
)
inline

Append the inverse of a pose as a relation without velocity, if it is not the identity pose.

Validity flags stay the same, only the pose is inverted.

Referenced by qwerty_controller::qwerty_follow_hmd().

◆ m_relation_chain_push_inverted_relation()

static void m_relation_chain_push_inverted_relation ( struct xrt_relation_chain xrc,
const struct xrt_space_relation relation 
)
inline

Append the inverse of the provided relation.

Validity flags stay the same, only the pose and velocities are inverted.

◆ m_relation_chain_push_pose()

static void m_relation_chain_push_pose ( struct xrt_relation_chain xrc,
const struct xrt_pose pose 
)
inline

Append a new pose as a fully tracked relation.

This follows OpenXR conventions where a space that is purely an offset to another space is fully tracked in that space. Conceptually, a pose is only considered not fully tracked when it is related to an xrt_space_relation that is not fully tracked.

References xrt_relation_chain::m_relation_chain_push_relation(), and m_space_relation_from_pose().

Referenced by qwerty_controller::qwerty_follow_hmd().

◆ m_relation_chain_push_pose_if_not_identity()

static void m_relation_chain_push_pose_if_not_identity ( struct xrt_relation_chain xrc,
const struct xrt_pose pose 
)
inline

Append a new pose as a relation without velocity, if it is not the identity pose.

Referenced by CDeviceDriver_Monado::GetPose().

◆ m_relation_chain_push_relation()

static void m_relation_chain_push_relation ( struct xrt_relation_chain xrc,
const struct xrt_space_relation relation 
)
inline

◆ m_relation_chain_reserve()

static struct xrt_space_relation * m_relation_chain_reserve ( struct xrt_relation_chain xrc)
inline

Reserve a step in the chain and return a pointer to the relation.

Note
The data pointed to by the returned pointer is not initialized: you must populate it before using m_relation_chain_resolve

References xrt_relation_chain::XRT_RELATION_CHAIN_CAPACITY.

◆ m_relation_chain_resolve()

void m_relation_chain_resolve ( const struct xrt_relation_chain xrc,
struct xrt_space_relation out_relation 
)

Compute the equivalent single relation from flattening a relation chain.

The input chain is not modified.

Referenced by qwerty_controller::qwerty_follow_hmd().

◆ m_space_relation_from_pose()

static void m_space_relation_from_pose ( const struct xrt_pose pose,
bool  set_tracked,
struct xrt_space_relation out_relation 
)
inlinestatic

#include <auxiliary/math/m_space.h>

Create an xrt_space_relation from a pose.

If set_tracked is false, only orientation and position valid flags are set.

Referenced by xrt_relation_chain::m_relation_chain_push_pose().

◆ m_space_relation_ident()

static void m_space_relation_ident ( struct xrt_space_relation out_relation)
inlinestatic

#include <auxiliary/math/m_space.h>

Create an xrt_space_relation with only orientation and position valid flags.

◆ m_space_relation_interpolate()

void m_space_relation_interpolate ( struct xrt_space_relation a,
struct xrt_space_relation b,
float  t,
enum xrt_space_relation_flags  flags,
struct xrt_space_relation out_relation 
)

#include <auxiliary/math/m_space.h>

Linearly interpolate between two relations a and b.

Uses slerp for their orientations. Sets flags in out_relation.

◆ math_compute_fovs()

bool math_compute_fovs ( double  w_total,
double  w_1,
double  horizfov_total,
double  h_total,
double  h_1,
double  vertfov_total,
struct xrt_fov fov 
)

#include <auxiliary/math/m_api.h>

Perform the computations from "Computing Half-Fields-Of-View from Simpler Display Models", to get half-FOVs from things we can retrieve from other APIs.

The origin is in the lower-left corner of the display, so w_1 is the width to the left of CoP, and h_1 is the height below CoP.

If vertfov_total is set to 0, it will be computed from h_total.

Distances are in arbitrary but consistent units. Angles are in radians.

In the diagram below, treating it like a FOV for horizontal, the top angle is horizfov_total, the length of the bottom is w_total, and the distance between the vertical line and the left corner is w_1. Vertical is similar - h_1 is above the center line. The triangle need not be symmetrical, despite how the diagram looks.

horizfov_total
*
angle_left (neg) -> / | \ <- angle_right
/ | \
/ | \
/ | \
-------------
[ w_1 ]
[ --- w --- ]
------- --- |\
| \
h_1 | \ angle_up
h_total ___ |-------* vertfov_total
| / angle_down (neg)
| /
| /
------- |/
Returns
true if successful.

References math_solve_triangle().

◆ math_hash_string()

size_t math_hash_string ( const char *  str_c,
size_t  length 
)

#include <auxiliary/math/m_api.h>

Generate a hash value from the given string, trailing zero not included.

Hashing function used is not specified so no guarantee of staying the same between different versions of the software, or even when the same version is compiled on different platforms/libc++ as it might use std::hash.

◆ math_matrix_3x3_f64_from_plus_x_z()

void math_matrix_3x3_f64_from_plus_x_z ( const struct xrt_vec3_f64 plus_x,
const struct xrt_vec3_f64 plus_z,
struct xrt_matrix_3x3_f64 result 
)
related

Create a rotation from two vectors plus x and z, by creating a rotation matrix by crossing z and x to get the y axis.

Input vectors should be normalized.

◆ math_matrix_3x3_f64_identity()

void math_matrix_3x3_f64_identity ( struct xrt_matrix_3x3_f64 mat)

#include <auxiliary/math/m_api.h>

Initialize a double 3x3 matrix to the identity matrix.

See also
xrt_matrix_3x3

References xrt::auxiliary::math::map_matrix_3x3_f64().

◆ math_matrix_3x3_f64_transform_vec3_f64()

void math_matrix_3x3_f64_transform_vec3_f64 ( const struct xrt_matrix_3x3_f64 left,
const struct xrt_vec3_f64 right,
struct xrt_vec3_f64 result_out 
)

#include <auxiliary/math/m_api.h>

Transform a double vec3 by a 3x3 double matrix.

See also
xrt_matrix_3x3

References xrt::auxiliary::math::map_vec3_f64().

◆ math_matrix_3x3_from_quat()

void math_matrix_3x3_from_quat ( const struct xrt_quat q,
struct xrt_matrix_3x3 result_out 
)

#include <auxiliary/math/m_api.h>

Initialize a 3x3 matrix from a quaternion.

See also
xrt_matrix_3x3

◆ math_matrix_3x3_identity()

void math_matrix_3x3_identity ( struct xrt_matrix_3x3 mat)

#include <auxiliary/math/m_api.h>

Initialize a 3x3 matrix to the identity matrix.

See also
xrt_matrix_3x3

References xrt::auxiliary::math::map_matrix_3x3().

Referenced by wmr_hmd_config_init_defaults().

◆ math_matrix_3x3_inverse()

void math_matrix_3x3_inverse ( const struct xrt_matrix_3x3 in,
struct xrt_matrix_3x3 result 
)
related

Invert Matrix3x3.

◆ math_matrix_3x3_multiply()

void math_matrix_3x3_multiply ( const struct xrt_matrix_3x3 left,
const struct xrt_matrix_3x3 right,
struct xrt_matrix_3x3 result_out 
)
related

Multiply Matrix3x3.

◆ math_matrix_3x3_rotation_from_isometry()

void math_matrix_3x3_rotation_from_isometry ( const struct xrt_matrix_4x4 isometry,
struct xrt_matrix_3x3 result 
)
related

Get the rotation matrix from an isomertry matrix (col-major).

◆ math_matrix_3x3_transform_vec3()

void math_matrix_3x3_transform_vec3 ( const struct xrt_matrix_3x3 left,
const struct xrt_vec3 right,
struct xrt_vec3 result_out 
)

#include <auxiliary/math/m_api.h>

Transform a vec3 by a 3x3 matrix.

See also
xrt_matrix_3x3

References xrt::auxiliary::math::map_vec3().

◆ math_matrix_3x3_transpose()

void math_matrix_3x3_transpose ( const struct xrt_matrix_3x3 in,
struct xrt_matrix_3x3 result 
)
related

Transpose Matrix3x3.

◆ math_matrix_4x4_identity()

void math_matrix_4x4_identity ( struct xrt_matrix_4x4 result)
related

Initialize Matrix4x4 with identity.

◆ math_matrix_4x4_inverse()

void math_matrix_4x4_inverse ( const struct xrt_matrix_4x4 in,
struct xrt_matrix_4x4 result 
)
related

Invert Matrix4x4.

◆ math_matrix_4x4_inverse_view_projection()

void math_matrix_4x4_inverse_view_projection ( const struct xrt_matrix_4x4 view,
const struct xrt_matrix_4x4 projection,
struct xrt_matrix_4x4 result 
)
related

Compute inverse view projection matrix, using only the starting 3x3 block of the view.

◆ math_matrix_4x4_isometry_from_pose()

void math_matrix_4x4_isometry_from_pose ( const struct xrt_pose pose,
struct xrt_matrix_4x4 result 
)
related

Get a col-major isometry matrix —in SE(3)— from a pose.

Referenced by wmr_hmd_fill_slam_cams_calibration().

◆ math_matrix_4x4_isometry_from_rt()

void math_matrix_4x4_isometry_from_rt ( const struct xrt_matrix_3x3 rotation,
const struct xrt_vec3 translation,
struct xrt_matrix_4x4 result 
)
related

Get an isometry matrix —in SE(3)— from a rotation matrix —SO(3)— and a translation vector.

All col-major matrices.

◆ math_matrix_4x4_isometry_inverse()

void math_matrix_4x4_isometry_inverse ( const struct xrt_matrix_4x4 in,
struct xrt_matrix_4x4 result 
)
related

Invert a homogeneous isometry 4x4 (col-major) matrix in SE(3).

◆ math_matrix_4x4_model()

void math_matrix_4x4_model ( const struct xrt_pose pose,
const struct xrt_vec3 size,
struct xrt_matrix_4x4 result 
)
related

Compute quad layer model matrix from xrt_pose and xrt_vec2 size.

◆ math_matrix_4x4_multiply()

void math_matrix_4x4_multiply ( const struct xrt_matrix_4x4 left,
const struct xrt_matrix_4x4 right,
struct xrt_matrix_4x4 result 
)
related

Multiply Matrix4x4.

◆ math_matrix_4x4_projection_vulkan_infinite_reverse()

void math_matrix_4x4_projection_vulkan_infinite_reverse ( const struct xrt_fov fov,
float  near_plane,
struct xrt_matrix_4x4 result 
)
related

Compute a projection matrix with settings for Vulkan, it will also have it's far plane at infinite and the NDC depth will be reversed.

◆ math_matrix_4x4_transform_vec3()

void math_matrix_4x4_transform_vec3 ( const struct xrt_matrix_4x4 left,
const struct xrt_vec3 right,
struct xrt_vec3 result_out 
)

#include <auxiliary/math/m_api.h>

Transform a vec3 by a 4x4 matrix, extending the vector with w = 1.0.

See also
xrt_matrix_4x4

◆ math_matrix_4x4_transpose()

void math_matrix_4x4_transpose ( const struct xrt_matrix_4x4 in,
struct xrt_matrix_4x4 result 
)
related

Transpose Matrix4x4.

◆ math_matrix_4x4_view_from_pose()

void math_matrix_4x4_view_from_pose ( const struct xrt_pose pose,
struct xrt_matrix_4x4 result 
)
related

Compute view matrix from xrt_pose.

Referenced by comp_render_cs_layer().

◆ math_pose_from_isometry()

void math_pose_from_isometry ( const struct xrt_matrix_4x4 transform,
struct xrt_pose result 
)
related

Converts a (col-major) isometry into a pose.

Referenced by rift_s_fill_slam_cameras_calibration().

◆ math_pose_identity()

void math_pose_identity ( struct xrt_pose pose)
related

Somewhat laboriously make an xrt_pose identity.

Referenced by wmr_hmd_config_init_defaults().

◆ math_pose_interpolate()

void math_pose_interpolate ( const struct xrt_pose a,
const struct xrt_pose b,
float  t,
struct xrt_pose outPose 
)
related

Interpolated pose between poses a and b by lerping position and slerping orientation by t.

◆ math_pose_invert()

void math_pose_invert ( const struct xrt_pose pose,
struct xrt_pose outPose 
)
related

Invert pose.

OK if input and output are the same addresses.

Referenced by multi_create_tracking_override(), precompute_sensor_transforms(), and rift_s_fill_slam_cameras_calibration().

◆ math_pose_transform()

void math_pose_transform ( const struct xrt_pose transform,
const struct xrt_pose pose,
struct xrt_pose outPose 
)
related

Apply a rigid-body transformation to a pose.

OK if input and output are the same addresses.

Referenced by precompute_sensor_transforms().

◆ math_pose_transform_point()

void math_pose_transform_point ( const struct xrt_pose transform,
const struct xrt_vec3 point,
struct xrt_vec3 out_point 
)
related

Apply a rigid-body transformation to a point.

The input point and output may be the same pointer.

See also
xrt_vec3

◆ math_pose_validate()

bool math_pose_validate ( const struct xrt_pose pose)
related

Check if this pose can be used in transformation operations.

◆ math_quat_ensure_normalized()

bool math_quat_ensure_normalized ( struct xrt_quat inout)
related

Normalizes a quaternion if it has accumulated float precision errors.

Returns true if the quaternion was already normalized or was normalized after being found within a small float precision tolerance. Returns false if the quaternion was not at all normalized.

◆ math_quat_exp()

void math_quat_exp ( const struct xrt_vec3 axis_angle,
struct xrt_quat out_quat 
)
related

Takes a rotation vector equal to half of a Rodrigues rotation vector and returns its corresponding unit quaternion.

Useful for head tracking and pose-prediction.

See also
xrt_vec3

◆ math_quat_finite_difference()

void math_quat_finite_difference ( const struct xrt_quat quat0,
const struct xrt_quat quat1,
float  dt,
struct xrt_vec3 out_ang_vel 
)
related

Compute a global angular velocity vector (exponential map format) by taking the finite difference of two quaternions.

quat1 is the orientation dt time after the orientation was quat0

out_ang_vel and dt share the same units of time, and out_ang_vel is be in radians per unit of time.

See also
xrt_vec3

◆ math_quat_from_angle_vector()

void math_quat_from_angle_vector ( float  angle_rads,
const struct xrt_vec3 vector,
struct xrt_quat result 
)
related

Create a rotation from an angle in radians and a unit vector.

See also
xrt_vec3

Referenced by svr_hmd_get_view_poses().

◆ math_quat_from_euler_angles()

void math_quat_from_euler_angles ( const struct xrt_vec3 angles,
struct xrt_quat result 
)
related

Create a rotation from euler angles to a quaternion.

◆ math_quat_from_matrix_3x3()

void math_quat_from_matrix_3x3 ( const struct xrt_matrix_3x3 mat,
struct xrt_quat result 
)
related

Create a rotation from a 3x3 rotation (row major) matrix.

See also
xrt_matrix_3x3

◆ math_quat_from_plus_x_z()

void math_quat_from_plus_x_z ( const struct xrt_vec3 plus_x,
const struct xrt_vec3 plus_z,
struct xrt_quat result 
)
related

Create a rotation from two vectors plus x and z, by creating a rotation matrix by crossing z and x to get the y axis.

Input vectors should be normalized.

See also
xrt_vec3

◆ math_quat_from_swing()

void math_quat_from_swing ( const struct xrt_vec2 swing,
struct xrt_quat result 
)
related

Converts a 2D vector to a quaternion.

◆ math_quat_from_swing_twist()

void math_quat_from_swing_twist ( const struct xrt_vec2 swing,
const float  twist,
struct xrt_quat result 
)
related

Converts a 2D vector and a float to a quaternion.

◆ math_quat_integrate_velocity()

void math_quat_integrate_velocity ( const struct xrt_quat quat,
const struct xrt_vec3 ang_vel,
float  dt,
struct xrt_quat result 
)
related

Integrate a local angular velocity vector (exponential map) and apply to a quaternion.

ang_vel and dt should share the same units of time, and the ang_vel vector should be in radians per unit of time.

See also
xrt_vec3

◆ math_quat_invert()

void math_quat_invert ( const struct xrt_quat quat,
struct xrt_quat out_quat 
)
related

Invert a quaternion.

◆ math_quat_len()

float math_quat_len ( const struct xrt_quat quat)
related

The euclidean norm or length of a quaternion.

Same as if it were a vec4.

◆ math_quat_ln()

void math_quat_ln ( const struct xrt_quat quat,
struct xrt_vec3 out_axis_angle 
)
related

Takes a unit quaternion and returns a rotation vector equal to half of its corresponding Rodrigues rotation vector.

Useful for head tracking and pose-prediction.

See also
xrt_vec3

Referenced by m_filter_euro_quat::m_filter_euro_quat_run().

◆ math_quat_normalize()

void math_quat_normalize ( struct xrt_quat inout)
related

Normalize a quaternion.

Referenced by hydra_device_parse_controller().

◆ math_quat_rotate()

void math_quat_rotate ( const struct xrt_quat left,
const struct xrt_quat right,
struct xrt_quat result 
)
related

Rotate a quaternion (compose rotations).

Referenced by precompute_sensor_transforms(), and rift_s_tracker_correct_pose_from_basalt().

◆ math_quat_rotate_derivative()

void math_quat_rotate_derivative ( const struct xrt_quat quat,
const struct xrt_vec3 deriv,
struct xrt_vec3 result 
)
related

Used to rotate a derivative like a angular velocity.

See also
xrt_vec3

Referenced by psmv_get_fusion_pose(), pssense_get_fusion_pose(), and rift_s_controller_get_fusion_pose().

◆ math_quat_rotate_vec3()

void math_quat_rotate_vec3 ( const struct xrt_quat left,
const struct xrt_vec3 right,
struct xrt_vec3 result 
)
related

Rotate a vector.

See also
xrt_vec3

Referenced by rift_s_tracker_correct_pose_from_basalt().

◆ math_quat_slerp()

void math_quat_slerp ( const struct xrt_quat left,
const struct xrt_quat right,
float  t,
struct xrt_quat result 
)
related

Slerp (spherical linear interpolation) between two quaternions.

◆ math_quat_to_swing_twist()

void math_quat_to_swing_twist ( const struct xrt_quat in,
struct xrt_vec2 out_swing,
float *  out_twist 
)
related

Converts a quaternion to XY-swing and Z-twist.

References xrt::auxiliary::math::map_quat().

◆ math_quat_unrotate()

void math_quat_unrotate ( const struct xrt_quat left,
const struct xrt_quat right,
struct xrt_quat result 
)
related

Inverse of math_quat_rotate.

Removes left rotation from right.

Referenced by m_filter_euro_quat::m_filter_euro_quat_run().

◆ math_quat_validate()

bool math_quat_validate ( const struct xrt_quat quat)
related

Check if this quat can be used in transformation operations.

◆ math_quat_validate_within_1_percent()

bool math_quat_validate_within_1_percent ( const struct xrt_quat quat)
related

Check if this quat is within 1% of unit length.

◆ math_vec3_accum()

void math_vec3_accum ( const struct xrt_vec3 additional,
struct xrt_vec3 inAndOut 
)
related

Accumulate a vector by adding in-place.

Logically, *inAndOut += *additional OK if the two arguments are the same addresses.

◆ math_vec3_cross()

void math_vec3_cross ( const struct xrt_vec3 l,
const struct xrt_vec3 r,
struct xrt_vec3 result 
)
related

Cross product of a vector.

◆ math_vec3_f64_cross()

void math_vec3_f64_cross ( const struct xrt_vec3_f64 l,
const struct xrt_vec3_f64 r,
struct xrt_vec3_f64 result 
)
related

Cross product of a vec3_f64.

◆ math_vec3_f64_normalize()

void math_vec3_f64_normalize ( struct xrt_vec3_f64 in)
related

Normalize a vec3_f64 in place.

◆ math_vec3_normalize()

void math_vec3_normalize ( struct xrt_vec3 in)
related

Normalize a vec3 in place.

References xrt::auxiliary::math::map_vec3().

◆ math_vec3_scalar_mul()

void math_vec3_scalar_mul ( float  scalar,
struct xrt_vec3 inAndOut 
)
related

Multiply a vector in-place.

Logically, *inAndOut *= scalar

◆ math_vec3_subtract()

void math_vec3_subtract ( const struct xrt_vec3 subtrahend,
struct xrt_vec3 inAndOut 
)
related

Subtract from a vector in-place.

Logically, *inAndOut -= *subtrahend OK if the two arguments are the same addresses.

◆ math_vec3_translation_from_isometry()

void math_vec3_translation_from_isometry ( const struct xrt_matrix_4x4 isometry,
struct xrt_vec3 result 
)
related

Get translation vector from isometry matrix (col-major).

◆ math_vec3_validate()

bool math_vec3_validate ( const struct xrt_vec3 vec3)
related

Check if this vec3 is valid for math operations.