mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-04 06:06:17 +00:00
aux/math: Add m_vec3_project, m_vec3_orthonormalize, m_vec3_lerp, m_vec2_normalize, math_lerp
This commit is contained in:
parent
cda56ddfbd
commit
7356100696
|
@ -467,6 +467,12 @@ math_map_ranges(double value, double from_low, double from_high, double to_low,
|
||||||
return (value - from_low) * (to_high - to_low) / (from_high - from_low) + to_low;
|
return (value - from_low) * (to_high - to_low) / (from_high - from_low) + to_low;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline double
|
||||||
|
math_lerp(double from, double to, double amount)
|
||||||
|
{
|
||||||
|
return (from * (1.0 - amount)) + (to * (amount));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Optics functions.
|
* Optics functions.
|
||||||
|
|
|
@ -76,6 +76,12 @@ m_vec2_len(struct xrt_vec2 l)
|
||||||
return sqrtf(m_vec2_len_sqrd(l));
|
return sqrtf(m_vec2_len_sqrd(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
m_vec2_normalize(struct xrt_vec2 *inout)
|
||||||
|
{
|
||||||
|
*inout = m_vec2_div_scalar(*inout, m_vec2_len(*inout));
|
||||||
|
}
|
||||||
|
|
||||||
static inline float
|
static inline float
|
||||||
m_vec2_dot(struct xrt_vec2 l, struct xrt_vec2 r)
|
m_vec2_dot(struct xrt_vec2 l, struct xrt_vec2 r)
|
||||||
{
|
{
|
||||||
|
|
|
@ -113,6 +113,27 @@ m_vec3_angle(struct xrt_vec3 l, struct xrt_vec3 r)
|
||||||
return acosf(dot / lengths);
|
return acosf(dot / lengths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct xrt_vec3
|
||||||
|
m_vec3_project(struct xrt_vec3 project_this, struct xrt_vec3 onto_this)
|
||||||
|
{
|
||||||
|
|
||||||
|
float amnt = (m_vec3_dot(project_this, onto_this) / m_vec3_len_sqrd(onto_this));
|
||||||
|
|
||||||
|
return m_vec3_mul_scalar(onto_this, amnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline struct xrt_vec3
|
||||||
|
m_vec3_orthonormalize(struct xrt_vec3 leave_this_alone, struct xrt_vec3 change_this_one)
|
||||||
|
{
|
||||||
|
return m_vec3_normalize(m_vec3_sub(change_this_one, m_vec3_project(change_this_one, leave_this_alone)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline struct xrt_vec3
|
||||||
|
m_vec3_lerp(struct xrt_vec3 from, struct xrt_vec3 to, float amount)
|
||||||
|
{
|
||||||
|
// Recommend amount being in [0,1]
|
||||||
|
return m_vec3_add(m_vec3_mul_scalar(from, 1.0f - amount), m_vec3_mul_scalar(to, amount));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue