The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

aux/math: Add m_vec3_project, m_vec3_orthonormalize, m_vec3_lerp, m_vec2_normalize, math_lerp

authored by

Moses Turner and committed by
Jakob Bornecrantz
73561006 cda56ddf

+33
+6
src/xrt/auxiliary/math/m_api.h
··· 467 467 return (value - from_low) * (to_high - to_low) / (from_high - from_low) + to_low; 468 468 } 469 469 470 + static inline double 471 + math_lerp(double from, double to, double amount) 472 + { 473 + return (from * (1.0 - amount)) + (to * (amount)); 474 + } 475 + 470 476 /* 471 477 * 472 478 * Optics functions.
+6
src/xrt/auxiliary/math/m_vec2.h
··· 76 76 return sqrtf(m_vec2_len_sqrd(l)); 77 77 } 78 78 79 + static inline void 80 + m_vec2_normalize(struct xrt_vec2 *inout) 81 + { 82 + *inout = m_vec2_div_scalar(*inout, m_vec2_len(*inout)); 83 + } 84 + 79 85 static inline float 80 86 m_vec2_dot(struct xrt_vec2 l, struct xrt_vec2 r) 81 87 {
+21
src/xrt/auxiliary/math/m_vec3.h
··· 113 113 return acosf(dot / lengths); 114 114 } 115 115 116 + static inline struct xrt_vec3 117 + m_vec3_project(struct xrt_vec3 project_this, struct xrt_vec3 onto_this) 118 + { 119 + 120 + float amnt = (m_vec3_dot(project_this, onto_this) / m_vec3_len_sqrd(onto_this)); 121 + 122 + return m_vec3_mul_scalar(onto_this, amnt); 123 + } 124 + 125 + static inline struct xrt_vec3 126 + m_vec3_orthonormalize(struct xrt_vec3 leave_this_alone, struct xrt_vec3 change_this_one) 127 + { 128 + return m_vec3_normalize(m_vec3_sub(change_this_one, m_vec3_project(change_this_one, leave_this_alone))); 129 + } 130 + 131 + static inline struct xrt_vec3 132 + m_vec3_lerp(struct xrt_vec3 from, struct xrt_vec3 to, float amount) 133 + { 134 + // Recommend amount being in [0,1] 135 + return m_vec3_add(m_vec3_mul_scalar(from, 1.0f - amount), m_vec3_mul_scalar(to, amount)); 136 + } 116 137 117 138 #ifdef __cplusplus 118 139 }