additional utils

This commit is contained in:
Recep Aslantas
2018-06-18 17:55:25 +03:00
parent 02f6c67393
commit 669777eb37
2 changed files with 76 additions and 0 deletions

View File

@@ -19,6 +19,7 @@
#define cglm_util_h
#include "common.h"
#include <stdbool.h>
/*!
* @brief get sign of 32 bit integer as +1, -1, 0
@@ -157,4 +158,44 @@ glm_lerp(float from, float to, float t) {
return from + glm_clamp(t, 0.0f, 1.0f) * (to - from);
}
/*!
* @brief check if two float equal with using EPSILON
*
* @param[in] a a
* @param[in] b b
*/
CGLM_INLINE
bool
glm_eq(float a, float b) {
return fabsf(a - b) <= FLT_EPSILON;
}
/*!
* @brief percentage of current value between start and end value
*
* maybe fraction could be alternative name.
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t current value
*/
CGLM_INLINE
float
glm_percent(float from, float to, float current) {
return (current - from) / (to - from);
}
/*!
* @brief clamped percentage of current value between start and end value
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t current value
*/
CGLM_INLINE
float
glm_percentc(float from, float to, float current) {
return glm_clamp(glm_percent(from, to, current), 0.0f, 1.0f);
}
#endif /* cglm_util_h */