mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
a/math: Add m_relation_history_result return from m_relation_history_get
This commit is contained in:
parent
01e3d9871c
commit
217dee2ce3
|
@ -80,11 +80,13 @@ m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation
|
|||
os_mutex_unlock(&rh->mutex);
|
||||
}
|
||||
|
||||
void
|
||||
enum m_relation_history_result
|
||||
m_relation_history_get(struct m_relation_history *rh, struct xrt_space_relation *out_relation, uint64_t at_timestamp_ns)
|
||||
{
|
||||
XRT_TRACE_MARKER();
|
||||
os_mutex_lock(&rh->mutex);
|
||||
m_relation_history_result ret = M_RELATION_HISTORY_RESULT_INVALID;
|
||||
|
||||
if (rh->has_first_sample == 0) {
|
||||
// Do nothing. You push nothing to the buffer you get nothing from the buffer.
|
||||
goto end;
|
||||
|
@ -104,6 +106,7 @@ m_relation_history_get(struct m_relation_history *rh, struct xrt_space_relation
|
|||
U_LOG_T("Extrapolating %f s after the head of the buffer!", delta_s);
|
||||
|
||||
m_predict_relation(&rh->impl[0]->relation, delta_s, out_relation);
|
||||
ret = M_RELATION_HISTORY_RESULT_PREDICTED;
|
||||
goto end;
|
||||
|
||||
} else if (at_timestamp_ns < oldest_in_buffer) {
|
||||
|
@ -114,6 +117,8 @@ m_relation_history_get(struct m_relation_history *rh, struct xrt_space_relation
|
|||
double delta_s = time_ns_to_s(diff_prediction_ns);
|
||||
U_LOG_T("Extrapolating %f s before the tail of the buffer!", delta_s);
|
||||
m_predict_relation(&rh->impl[rh->impl.length() - 1]->relation, delta_s, out_relation);
|
||||
ret = M_RELATION_HISTORY_RESULT_REVERSE_PREDICTED;
|
||||
|
||||
goto end;
|
||||
}
|
||||
U_LOG_T("Interpolating within buffer!");
|
||||
|
@ -196,9 +201,11 @@ m_relation_history_get(struct m_relation_history *rh, struct xrt_space_relation
|
|||
m_vec3_lerp(before.angular_velocity, after.angular_velocity, amount_to_lerp);
|
||||
out_relation->linear_velocity =
|
||||
m_vec3_lerp(before.linear_velocity, after.linear_velocity, amount_to_lerp);
|
||||
ret = M_RELATION_HISTORY_RESULT_INTERPOLATED;
|
||||
}
|
||||
end:
|
||||
os_mutex_unlock(&rh->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -7,44 +7,68 @@
|
|||
* @author Moses Turner <moses@collabora.com>
|
||||
* @ingroup drv_ht
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "xrt/xrt_defines.h"
|
||||
struct m_relation_history;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* Creates an opaque relation_history object.
|
||||
/**
|
||||
* @brief Opaque type for storing the history of a space relation in a ring buffer
|
||||
*
|
||||
* @ingroup aux_util
|
||||
*/
|
||||
struct m_relation_history;
|
||||
|
||||
/**
|
||||
* @brief Describes how the resulting space relation for the desired time stamp was generated.
|
||||
*
|
||||
* @relates m_relation_history
|
||||
*/
|
||||
enum m_relation_history_result
|
||||
{
|
||||
M_RELATION_HISTORY_RESULT_INVALID = 0, //!< The supplied timestamp was invalid (0) or buffer was empty
|
||||
M_RELATION_HISTORY_RESULT_EXACT, //!< The exact desired timestamp was found
|
||||
M_RELATION_HISTORY_RESULT_INTERPOLATED, //!< The desired timestamp was between two entries
|
||||
M_RELATION_HISTORY_RESULT_PREDICTED, //!< The desired timestamp was newer than the most recent entry
|
||||
M_RELATION_HISTORY_RESULT_REVERSE_PREDICTED, //!< The desired timestamp was older than the oldest entry
|
||||
};
|
||||
|
||||
/*!
|
||||
* @brief Creates an opaque relation_history object.
|
||||
*
|
||||
* @public @memberof m_relation_history
|
||||
*/
|
||||
void
|
||||
m_relation_history_create(struct m_relation_history **rh);
|
||||
|
||||
/*!
|
||||
* Pushes a new pose to the history - if the history is full, it will also pop a pose out of the other side of the
|
||||
* buffer.
|
||||
* Pushes a new pose to the history.
|
||||
*
|
||||
* @ingroup aux_util
|
||||
* If the history is full, it will also pop a pose out of the other side of the buffer.
|
||||
*
|
||||
* @public @memberof m_relation_history
|
||||
*/
|
||||
void
|
||||
m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation *in_relation, uint64_t ts);
|
||||
|
||||
/*!
|
||||
* Interpolates or extrapolates to the desired timestamp. Read-only operation - doesn't remove anything from the buffer
|
||||
* or anything like that - you can call this as often as you want.
|
||||
* @brief Interpolates or extrapolates to the desired timestamp.
|
||||
*
|
||||
* @ingroup aux_util
|
||||
* Read-only operation - doesn't remove anything from the buffer or anything like that - you can call this as often as
|
||||
* you want.
|
||||
*
|
||||
* @public @memberof m_relation_history
|
||||
*/
|
||||
void
|
||||
enum m_relation_history_result
|
||||
m_relation_history_get(struct m_relation_history *rh, struct xrt_space_relation *out_relation, uint64_t at_time_ns);
|
||||
|
||||
/*!
|
||||
* Destroys an opaque relation_history object.
|
||||
*
|
||||
* @ingroup aux_util
|
||||
* @public @memberof m_relation_history
|
||||
*/
|
||||
void
|
||||
m_relation_history_destroy(struct m_relation_history **rh);
|
||||
|
|
Loading…
Reference in a new issue