glm_lerpc(), glm_step(), glm_smoothstep(), glm_smoothinterp() (#98)

* lerp, step, smoothstep

* glm_lerp() and friends are no longer clamped, use glm_lerpc() and friends
* mix() function as wrapper of lerp()
* no there are clamp and raw version of lerp functions
This commit is contained in:
Luigi Castelli
2019-08-25 21:17:36 +02:00
committed by Recep Aslantas
parent 43b36f1dc1
commit 4639f3184a
13 changed files with 978 additions and 23 deletions

View File

@@ -33,6 +33,7 @@
CGLM_INLINE mat3s glms_quat_mat3(versors q)
CGLM_INLINE mat3s glms_quat_mat3t(versors q)
CGLM_INLINE versors glms_quat_lerp(versors from, versors to, float t)
CGLM_INLINE versors glms_quat_lerpc(versors from, versors to, float t)
CGLM_INLINE versors glms_quat_slerp(versors from, versors to, float t)
CGLM_INLINE mat4s. glms_quat_look(vec3s eye, versors ori)
CGLM_INLINE versors glms_quat_for(vec3s dir, vec3s fwd, vec3s up)
@@ -372,7 +373,7 @@ glms_quat_mat3t(versors q) {
*
* @param[in] from from
* @param[in] to to
* @param[in] t interpolant (amount) clamped between 0 and 1
* @param[in] t interpolant (amount)
* @returns result quaternion
*/
CGLM_INLINE
@@ -383,6 +384,23 @@ glms_quat_lerp(versors from, versors to, float t) {
return dest;
}
/*!
* @brief interpolates between two quaternions
* using linear interpolation (LERP)
*
* @param[in] from from
* @param[in] to to
* @param[in] t interpolant (amount) clamped between 0 and 1
* @returns result quaternion
*/
CGLM_INLINE
versors
glms_quat_lerpc(versors from, versors to, float t) {
versors dest;
glm_quat_lerpc(from.raw, to.raw, t, dest.raw);
return dest;
}
/*!
* @brief interpolates between two quaternions
* using spherical linear interpolation (SLERP)

View File

@@ -58,6 +58,15 @@
CGLM_INLINE vec3s glms_vec3_ortho(vec3s v);
CGLM_INLINE vec3s glms_vec3_clamp(vec3s v, float minVal, float maxVal);
CGLM_INLINE vec3s glms_vec3_lerp(vec3s from, vec3s to, float t);
CGLM_INLINE vec3s glms_vec3_lerpc(vec3s from, vec3s to, float t);
CGLM_INLINE vec3s glms_vec3_mix(vec3s from, vec3s to, float t);
CGLM_INLINE vec3s glms_vec3_mixc(vec3s from, vec3s to, float t);
CGLM_INLINE vec3s glms_vec3_step_uni(float edge, vec3s x);
CGLM_INLINE vec3s glms_vec3_step(vec3s edge, vec3s x);
CGLM_INLINE vec3s glms_vec3_smoothstep_uni(float edge0, float edge1, vec3s x);
CGLM_INLINE vec3s glms_vec3_smoothstep(vec3s edge0, vec3s edge1, vec3s x);
CGLM_INLINE vec3s glms_vec3_smoothinterp(vec3s from, vec3s to, float t);
CGLM_INLINE vec3s glms_vec3_smoothinterpc(vec3s from, vec3s to, float t);
CGLM_INLINE vec3s glms_vec3_swizzle(vec3s v, int mask);
Convenient:
@@ -684,7 +693,25 @@ glms_vec3_clamp(vec3s v, float minVal, float maxVal) {
}
/*!
* @brief linear interpolation between two vector
* @brief linear interpolation between two vectors
*
* formula: from + s * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount)
* @returns destination
*/
CGLM_INLINE
vec3s
glms_vec3_lerp(vec3s from, vec3s to, float t) {
vec3s r;
glm_vec3_lerp(from.raw, to.raw, t, r.raw);
return r;
}
/*!
* @brief linear interpolation between two vectors (clamped)
*
* formula: from + s * (to - from)
*
@@ -695,9 +722,143 @@ glms_vec3_clamp(vec3s v, float minVal, float maxVal) {
*/
CGLM_INLINE
vec3s
glms_vec3_lerp(vec3s from, vec3s to, float t) {
glms_vec3_lerpc(vec3s from, vec3s to, float t) {
vec3s r;
glm_vec3_lerp(from.raw, to.raw, t, r.raw);
glm_vec3_lerpc(from.raw, to.raw, t, r.raw);
return r;
}
/*!
* @brief linear interpolation between two vectors
*
* formula: from + s * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount)
* @returns destination
*/
CGLM_INLINE
vec3s
glms_vec3_mix(vec3s from, vec3s to, float t) {
vec3s r;
glm_vec3_mix(from.raw, to.raw, t, r.raw);
return r;
}
/*!
* @brief linear interpolation between two vectors (clamped)
*
* formula: from + s * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount) clamped between 0 and 1
* @returns destination
*/
CGLM_INLINE
vec3s
glms_vec3_mixc(vec3s from, vec3s to, float t) {
vec3s r;
glm_vec3_mixc(from.raw, to.raw, t, r.raw);
return r;
}
/*!
* @brief threshold function (unidimensional)
*
* @param[in] edge threshold
* @param[in] x value to test against threshold
* @returns 0.0 if x < edge, else 1.0
*/
CGLM_INLINE
vec3s
glms_vec3_step_uni(float edge, vec3s x) {
vec3s r;
glm_vec3_step_uni(edge, x.raw, r.raw);
return r;
}
/*!
* @brief threshold function
*
* @param[in] edge threshold
* @param[in] x value to test against threshold
* @returns 0.0 if x < edge, else 1.0
*/
CGLM_INLINE
vec3s
glms_vec3_step(vec3s edge, vec3s x) {
vec3s r;
glm_vec3_step(edge.raw, x.raw, r.raw);
return r;
}
/*!
* @brief threshold function with a smooth transition (unidimensional)
*
* @param[in] edge0 low threshold
* @param[in] edge1 high threshold
* @param[in] x value to test against threshold
* @returns destination
*/
CGLM_INLINE
vec3s
glms_vec3_smoothstep_uni(float edge0, float edge1, vec3s x) {
vec3s r;
glm_vec3_smoothstep_uni(edge0, edge1, x.raw, r.raw);
return r;
}
/*!
* @brief threshold function with a smooth transition
*
* @param[in] edge0 low threshold
* @param[in] edge1 high threshold
* @param[in] x value to test against threshold
* @returns destination
*/
CGLM_INLINE
vec3s
glms_vec3_smoothstep(vec3s edge0, vec3s edge1, vec3s x) {
vec3s r;
glm_vec3_smoothstep(edge0.raw, edge1.raw, x.raw, r.raw);
return r;
}
/*!
* @brief smooth Hermite interpolation between two vectors
*
* formula: from + s * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount)
* @returns destination
*/
CGLM_INLINE
vec3s
glms_vec3_smoothinterp(vec3s from, vec3s to, float t) {
vec3s r;
glm_vec3_smoothinterp(from.raw, to.raw, t, r.raw);
return r;
}
/*!
* @brief smooth Hermite interpolation between two vectors (clamped)
*
* formula: from + s * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount) clamped between 0 and 1
* @returns destination
*/
CGLM_INLINE
vec3s
glms_vec3_smoothinterpc(vec3s from, vec3s to, float t) {
vec3s r;
glm_vec3_smoothinterpc(from.raw, to.raw, t, r.raw);
return r;
}

View File

@@ -48,6 +48,15 @@
CGLM_INLINE vec4s glms_vec4_minv(vec4s a, vec4s b);
CGLM_INLINE vec4s glms_vec4_clamp(vec4s v, float minVal, float maxVal);
CGLM_INLINE vec4s glms_vec4_lerp(vec4s from, vec4s to, float t);
CGLM_INLINE vec4s glms_vec4_lerpc(vec4s from, vec4s to, float t);
CGLM_INLINE vec4s glms_vec4_mix(vec4s from, vec4s to, float t);
CGLM_INLINE vec4s glms_vec4_mixc(vec4s from, vec4s to, float t);
CGLM_INLINE vec4s glms_vec4_step_uni(float edge, vec4s x);
CGLM_INLINE vec4s glms_vec4_step(vec4s edge, vec4s x);
CGLM_INLINE vec4s glms_vec4_smoothstep_uni(float edge0, float edge1, vec4s x);
CGLM_INLINE vec4s glms_vec4_smoothstep(vec4s edge0, vec4s edge1, vec4s x);
CGLM_INLINE vec4s glms_vec4_smoothinterp(vec4s from, vec4s to, float t);
CGLM_INLINE vec4s glms_vec4_smoothinterpc(vec4s from, vec4s to, float t);
CGLM_INLINE vec4s glms_vec4_cubic(float s);
CGLM_INLINE vec4s glms_vec4_swizzle(vec4s v, int mask);
*/
@@ -561,7 +570,25 @@ glms_vec4_clamp(vec4s v, float minVal, float maxVal) {
}
/*!
* @brief linear interpolation between two vector
* @brief linear interpolation between two vectors
*
* formula: from + s * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount)
* @returns destination
*/
CGLM_INLINE
vec4s
glms_vec4_lerp(vec4s from, vec4s to, float t) {
vec4s r;
glm_vec4_lerp(from.raw, to.raw, t, r.raw);
return r;
}
/*!
* @brief linear interpolation between two vectors (clamped)
*
* formula: from + s * (to - from)
*
@@ -572,9 +599,143 @@ glms_vec4_clamp(vec4s v, float minVal, float maxVal) {
*/
CGLM_INLINE
vec4s
glms_vec4_lerp(vec4s from, vec4s to, float t) {
glms_vec4_lerpc(vec4s from, vec4s to, float t) {
vec4s r;
glm_vec4_lerp(from.raw, to.raw, t, r.raw);
glm_vec4_lerpc(from.raw, to.raw, t, r.raw);
return r;
}
/*!
* @brief linear interpolation between two vectors
*
* formula: from + s * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount)
* @returns destination
*/
CGLM_INLINE
vec4s
glms_vec4_mix(vec4s from, vec4s to, float t) {
vec4s r;
glm_vec4_mix(from.raw, to.raw, t, r.raw);
return r;
}
/*!
* @brief linear interpolation between two vectors (clamped)
*
* formula: from + s * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount) clamped between 0 and 1
* @returns destination
*/
CGLM_INLINE
vec4s
glms_vec4_mixc(vec4s from, vec4s to, float t) {
vec4s r;
glm_vec4_mixc(from.raw, to.raw, t, r.raw);
return r;
}
/*!
* @brief threshold function (unidimensional)
*
* @param[in] edge threshold
* @param[in] x value to test against threshold
* @returns 0.0 if x < edge, else 1.0
*/
CGLM_INLINE
vec4s
glms_vec4_step_uni(float edge, vec4s x) {
vec4s r;
glm_vec4_step_uni(edge, x.raw, r.raw);
return r;
}
/*!
* @brief threshold function
*
* @param[in] edge threshold
* @param[in] x value to test against threshold
* @returns 0.0 if x < edge, else 1.0
*/
CGLM_INLINE
vec4s
glms_vec4_step(vec4s edge, vec4s x) {
vec4s r;
glm_vec4_step(edge.raw, x.raw, r.raw);
return r;
}
/*!
* @brief threshold function with a smooth transition (unidimensional)
*
* @param[in] edge0 low threshold
* @param[in] edge1 high threshold
* @param[in] x value to test against threshold
* @returns destination
*/
CGLM_INLINE
vec4s
glms_vec4_smoothstep_uni(float edge0, float edge1, vec4s x) {
vec4s r;
glm_vec4_smoothstep_uni(edge0, edge1, x.raw, r.raw);
return r;
}
/*!
* @brief threshold function with a smooth transition
*
* @param[in] edge0 low threshold
* @param[in] edge1 high threshold
* @param[in] x value to test against threshold
* @returns destination
*/
CGLM_INLINE
vec4s
glms_vec4_smoothstep(vec4s edge0, vec4s edge1, vec4s x) {
vec4s r;
glm_vec4_smoothstep(edge0.raw, edge1.raw, x.raw, r.raw);
return r;
}
/*!
* @brief smooth Hermite interpolation between two vectors
*
* formula: from + s * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount)
* @returns destination
*/
CGLM_INLINE
vec4s
glms_vec4_smoothinterp(vec4s from, vec4s to, float t) {
vec4s r;
glm_vec4_smoothinterp(from.raw, to.raw, t, r.raw);
return r;
}
/*!
* @brief smooth Hermite interpolation between two vectors (clamped)
*
* formula: from + s * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount) clamped between 0 and 1
* @returns destination
*/
CGLM_INLINE
vec4s
glms_vec4_smoothinterpc(vec4s from, vec4s to, float t) {
vec4s r;
glm_vec4_smoothinterpc(from.raw, to.raw, t, r.raw);
return r;
}