m/space: Add m_space_relation_interpolate

This commit is contained in:
Mateo de Mayo 2021-12-30 17:30:37 -03:00
parent dd81085a04
commit cf5574a4e9
2 changed files with 34 additions and 0 deletions

View file

@ -29,6 +29,29 @@ m_space_relation_invert(struct xrt_space_relation *relation, struct xrt_space_re
out_relation->angular_velocity = m_vec3_mul_scalar(relation->angular_velocity, -1);
}
extern "C" 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)
{
out_relation->relation_flags = flags;
if (flags & XRT_SPACE_RELATION_ORIENTATION_VALID_BIT) {
math_quat_slerp(&a->pose.orientation, &b->pose.orientation, t, &out_relation->pose.orientation);
}
if (flags & XRT_SPACE_RELATION_POSITION_VALID_BIT) {
out_relation->pose.position = m_vec3_lerp(a->pose.position, b->pose.position, t);
}
if (flags & XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT) {
out_relation->linear_velocity = m_vec3_lerp(a->linear_velocity, b->linear_velocity, t);
}
if (flags & XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT) {
out_relation->angular_velocity = m_vec3_lerp(a->angular_velocity, b->angular_velocity, t);
}
}
/*
*
* Dump functions.

View file

@ -83,6 +83,17 @@ m_space_relation_ident(struct xrt_space_relation *out_relation)
void
m_space_relation_invert(struct xrt_space_relation *relation, struct xrt_space_relation *out_relation);
/*!
* Linearly interpolate between two relations @p a and @p b. Uses slerp for
* their orientations. Sets @p flags in @p 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);
/*
*
* Relation chain functions.