Merge branch 'master' into vec2_mat2

This commit is contained in:
Recep Aslantas
2019-08-30 21:34:23 +03:00
committed by GitHub
22 changed files with 1178 additions and 56 deletions

24
.github/workflows/ccpp.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
name: C/C++ CI
on: [push]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
steps:
- uses: actions/checkout@v1
- name: dependencies
run: sh ./build-deps.sh
- name: autogen
run: sh autogen.sh
- name: configure
run: ./configure
- name: make
run: make
- name: make check
run: make check

View File

@@ -158,7 +158,8 @@ Functions documentation
.. c:function:: float glm_vec3_norm(vec3 vec)
norm (magnitude) of vec3
| euclidean norm (magnitude), also called L2 norm
| this will give magnitude of vector in euclidean space
Parameters:
| *[in]* **vec** vector

View File

@@ -134,7 +134,8 @@ Functions documentation
.. c:function:: float glm_vec4_norm(vec4 vec)
norm (magnitude) of vec4
| euclidean norm (magnitude), also called L2 norm
| this will give magnitude of vector in euclidean space
Parameters:
| *[in]* **vec** vector

View File

@@ -116,6 +116,10 @@ glmc_quat_mat3t(versor q, mat3 dest);
CGLM_EXPORT
void
glmc_quat_lerp(versor from, versor to, float t, versor dest);
CGLM_EXPORT
void
glmc_quat_lerpc(versor from, versor to, float t, versor dest);
CGLM_EXPORT
void

View File

@@ -179,10 +179,50 @@ glmc_vec3_clamp(vec3 v, float minVal, float maxVal);
CGLM_EXPORT
void
glmc_vec3_ortho(vec3 v, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_lerpc(vec3 from, vec3 to, float t, vec3 dest);
CGLM_INLINE
void
glmc_vec3_mix(vec3 from, vec3 to, float t, vec3 dest) {
glmc_vec3_lerp(from, to, t, dest);
}
CGLM_INLINE
void
glmc_vec3_mixc(vec3 from, vec3 to, float t, vec3 dest) {
glmc_vec3_lerpc(from, to, t, dest);
}
CGLM_EXPORT
void
glmc_vec3_step_uni(float edge, vec3 x, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_step(vec3 edge, vec3 x, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_smoothstep_uni(float edge0, float edge1, vec3 x, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_smoothstep(vec3 edge0, vec3 edge1, vec3 x, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_smoothinterp(vec3 from, vec3 to, float t, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_smoothinterpc(vec3 from, vec3 to, float t, vec3 dest);
/* ext */
@@ -193,6 +233,10 @@ glmc_vec3_mulv(vec3 a, vec3 b, vec3 d);
CGLM_EXPORT
void
glmc_vec3_broadcast(float val, vec3 d);
CGLM_EXPORT
void
glmc_vec3_fill(vec3 v, float val);
CGLM_EXPORT
bool

View File

@@ -132,10 +132,14 @@ glmc_vec4_negate(vec4 v);
CGLM_EXPORT
void
glmc_vec4_negate_to(vec4 v, vec4 dest);
CGLM_EXPORT
float
glmc_vec4_distance(vec4 a, vec4 b);
CGLM_EXPORT
float
glmc_vec4_distance2(vec4 a, vec4 b);
CGLM_EXPORT
void
@@ -148,10 +152,50 @@ glmc_vec4_minv(vec4 a, vec4 b, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_clamp(vec4 v, float minVal, float maxVal);
CGLM_EXPORT
void
glmc_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_lerpc(vec4 from, vec4 to, float t, vec4 dest);
CGLM_INLINE
void
glmc_vec4_mix(vec4 from, vec4 to, float t, vec4 dest) {
glmc_vec4_lerp(from, to, t, dest);
}
CGLM_INLINE
void
glmc_vec4_mixc(vec4 from, vec4 to, float t, vec4 dest) {
glmc_vec4_lerpc(from, to, t, dest);
}
CGLM_EXPORT
void
glmc_vec4_step_uni(float edge, vec4 x, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_step(vec4 edge, vec4 x, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_smoothstep_uni(float edge0, float edge1, vec4 x, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_smoothstep(vec4 edge0, vec4 edge1, vec4 x, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_smoothinterp(vec4 from, vec4 to, float t, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_smoothinterpc(vec4 from, vec4 to, float t, vec4 dest);
CGLM_EXPORT
void
@@ -166,6 +210,10 @@ glmc_vec4_mulv(vec4 a, vec4 b, vec4 d);
CGLM_EXPORT
void
glmc_vec4_broadcast(float val, vec4 d);
CGLM_EXPORT
void
glmc_vec4_fill(vec4 v, float val);
CGLM_EXPORT
bool

View File

@@ -36,6 +36,7 @@
CGLM_INLINE void glm_quat_mat3(versor q, mat3 dest);
CGLM_INLINE void glm_quat_mat3t(versor q, mat3 dest);
CGLM_INLINE void glm_quat_lerp(versor from, versor to, float t, versor dest);
CGLM_INLINE void glm_quat_lerpc(versor from, versor to, float t, versor dest);
CGLM_INLINE void glm_quat_slerp(versor q, versor r, float t, versor dest);
CGLM_INLINE void glm_quat_look(vec3 eye, versor ori, mat4 dest);
CGLM_INLINE void glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest);
@@ -601,7 +602,7 @@ glm_quat_mat3t(versor q, mat3 dest) {
*
* @param[in] from from
* @param[in] to to
* @param[in] t interpolant (amount) clamped between 0 and 1
* @param[in] t interpolant (amount)
* @param[out] dest result quaternion
*/
CGLM_INLINE
@@ -610,6 +611,21 @@ glm_quat_lerp(versor from, versor to, float t, versor dest) {
glm_vec4_lerp(from, to, t, 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
* @param[out] dest result quaternion
*/
CGLM_INLINE
void
glm_quat_lerpc(versor from, versor to, float t, versor dest) {
glm_vec4_lerpc(from, to, t, dest);
}
/*!
* @brief interpolates between two quaternions
* using spherical linear interpolation (SLERP)

View File

@@ -37,5 +37,11 @@ glmm_norm(float32x4_t a) {
return sqrtf(glmm_dot(a, a));
}
static inline
float
glmm_norm2(float32x4_t a) {
return glmm_dot(a, a);
}
#endif
#endif /* cglm_simd_arm_h */

View File

@@ -113,6 +113,12 @@ glmm_norm(__m128 a) {
return _mm_cvtss_f32(_mm_sqrt_ss(glmm_vhadds(_mm_mul_ps(a, a))));
}
static inline
float
glmm_norm2(__m128 a) {
return _mm_cvtss_f32(glmm_vhadds(_mm_mul_ps(a, a)));
}
static inline
__m128
glmm_load3(float v[3]) {
@@ -127,7 +133,7 @@ glmm_load3(float v[3]) {
static inline
void
glmm_store3(__m128 vx, float v[3]) {
glmm_store3(float v[3], __m128 vx) {
_mm_storel_pi((__m64 *)&v[0], vx);
_mm_store_ss(&v[2], glmm_shuff1(vx, 2, 2, 2, 2));
}

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

@@ -12,6 +12,7 @@
/*
Functions:
CGLM_INLINE vec3s glms_vec3_broadcast(float val);
CGLM_INLINE vec3s glms_vec3_fill(float val);
CGLM_INLINE bool glms_vec3_eq(vec3s v, float val);
CGLM_INLINE bool glms_vec3_eq_eps(vec3s v, float val);
CGLM_INLINE bool glms_vec3_eq_all(vec3s v);
@@ -48,6 +49,20 @@ glms_vec3_broadcast(float val) {
return r;
}
/*!
* @brief fill a vector with specified value
*
* @param[in] val value
* @returns dest
*/
CGLM_INLINE
vec3s
glms_vec3_fill(float val) {
vec3s r;
glm_vec3_fill(r.raw, val);
return r;
}
/*!
* @brief check if vector is equal to value (without epsilon)
*

View File

@@ -45,19 +45,28 @@
CGLM_INLINE vec3s glms_vec3_normalize(vec3s v);
CGLM_INLINE vec3s glms_vec3_cross(vec3s a, vec3s b);
CGLM_INLINE vec3s glms_vec3_crossn(vec3s a, vec3s b);
CGLM_INLINE float glms_vec3_distance(vec3s a, vec3s b);
CGLM_INLINE float glms_vec3_angle(vec3s a, vec3s b);
CGLM_INLINE vec3s glms_vec3_rotate(vec3s v, float angle, vec3s axis);
CGLM_INLINE vec3s glms_vec3_rotate_m4(mat4s m, vec3s v);
CGLM_INLINE vec3s glms_vec3_rotate_m3(mat3s m, vec3s v);
CGLM_INLINE vec3s glms_vec3_proj(vec3s a, vec3s b);
CGLM_INLINE vec3s glms_vec3_center(vec3s a, vec3s b);
CGLM_INLINE float glms_vec3_distance(vec3s a, vec3s b);
CGLM_INLINE float glms_vec3_distance2(vec3s a, vec3s b);
CGLM_INLINE vec3s glms_vec3_maxv(vec3s a, vec3s b);
CGLM_INLINE vec3s glms_vec3_minv(vec3s a, vec3s b);
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:
@@ -598,19 +607,6 @@ glms_vec3_center(vec3s a, vec3s b) {
return r;
}
/**
* @brief squared distance between two vectors
*
* @param[in] a vector1
* @param[in] b vector2
* @return squared distance (distance * distance)
*/
CGLM_INLINE
float
glms_vec3_distance2(vec3s a, vec3s b) {
return glm_vec3_distance2(a.raw, b.raw);
}
/**
* @brief distance between two vectors
*
@@ -624,6 +620,19 @@ glms_vec3_distance(vec3s a, vec3s b) {
return glm_vec3_distance(a.raw, b.raw);
}
/**
* @brief squared distance between two vectors
*
* @param[in] a vector1
* @param[in] b vector2
* @return squared distance (distance * distance)
*/
CGLM_INLINE
float
glms_vec3_distance2(vec3s a, vec3s b) {
return glm_vec3_distance2(a.raw, b.raw);
}
/*!
* @brief max values of vectors
*
@@ -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

@@ -12,6 +12,7 @@
/*
Functions:
CGLM_INLINE vec4s glms_vec4_broadcast(float val);
CGLM_INLINE vec4s glms_vec4_fill(float val);
CGLM_INLINE bool glms_vec4_eq(vec4s v, float val);
CGLM_INLINE bool glms_vec4_eq_eps(vec4s v, float val);
CGLM_INLINE bool glms_vec4_eq_all(vec4s v);
@@ -48,6 +49,20 @@ glms_vec4_broadcast(float val) {
return r;
}
/*!
* @brief fill a vector with specified value
*
* @param val value
* @returns dest
*/
CGLM_INLINE
vec4s
glms_vec4_fill(float val) {
vec4s r;
glm_vec4_fill(r.raw, val);
return r;
}
/*!
* @brief check if vector is equal to value (without epsilon)
*

View File

@@ -43,10 +43,20 @@
CGLM_INLINE vec4s glms_vec4_inv(vec4s v);
CGLM_INLINE vec4s glms_vec4_normalize(vec4s v);
CGLM_INLINE float glms_vec4_distance(vec4s a, vec4s b);
CGLM_INLINE float glms_vec4_distance2(vec4s a, vec4s b);
CGLM_INLINE vec4s glms_vec4_maxv(vec4s a, vec4s b);
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);
*/
@@ -501,6 +511,19 @@ glms_vec4_distance(vec4s a, vec4s b) {
return glm_vec4_distance(a.raw, b.raw);
}
/**
* @brief squared distance between two vectors
*
* @param[in] a vector1
* @param[in] b vector2
* @return returns squared distance
*/
CGLM_INLINE
float
glms_vec4_distance2(vec4s a, vec4s b) {
return glm_vec4_distance2(a.raw, b.raw);
}
/*!
* @brief max values of vectors
*
@@ -547,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)
*
@@ -558,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;
}

View File

@@ -8,11 +8,26 @@
/*
Functions:
CGLM_INLINE int glm_sign(int val);
CGLM_INLINE float glm_signf(float val);
CGLM_INLINE float glm_rad(float deg);
CGLM_INLINE float glm_deg(float rad);
CGLM_INLINE void glm_make_rad(float *deg);
CGLM_INLINE void glm_make_deg(float *rad);
CGLM_INLINE float glm_pow2(float x);
CGLM_INLINE float glm_min(float a, float b);
CGLM_INLINE float glm_max(float a, float b);
CGLM_INLINE float glm_clamp(float val, float minVal, float maxVal);
CGLM_INLINE float glm_clamp_zo(float val, float minVal, float maxVal);
CGLM_INLINE float glm_lerp(float from, float to, float t);
CGLM_INLINE float glm_lerpc(float from, float to, float t);
CGLM_INLINE float glm_step(float edge, float x);
CGLM_INLINE float glm_smooth(float t);
CGLM_INLINE float glm_smoothstep(float edge0, float edge1, float x);
CGLM_INLINE float glm_smoothinterp(float from, float to, float t);
CGLM_INLINE float glm_smoothinterpc(float from, float to, float t);
CGLM_INLINE bool glm_eq(float a, float b);
CGLM_INLINE float glm_percent(float from, float to, float current);
CGLM_INLINE float glm_percentc(float from, float to, float current);
*/
#ifndef cglm_util_h
@@ -157,9 +172,103 @@ glm_clamp_zo(float val) {
}
/*!
* @brief linear interpolation between two number
* @brief linear interpolation between two numbers
*
* formula: from + s * (to - from)
* formula: from + t * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount)
*/
CGLM_INLINE
float
glm_lerp(float from, float to, float t) {
return from + t * (to - from);
}
/*!
* @brief clamped linear interpolation between two numbers
*
* formula: from + t * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount) clamped between 0 and 1
*/
CGLM_INLINE
float
glm_lerpc(float from, float to, float t) {
return glm_lerp(from, to, glm_clamp_zo(t));
}
/*!
* @brief threshold function
*
* @param[in] edge threshold
* @param[in] x value to test against threshold
* @return returns 0.0 if x < edge, else 1.0
*/
CGLM_INLINE
float
glm_step(float edge, float x) {
/* branching - no type conversion */
return (x < edge) ? 0.0f : 1.0f;
/*
* An alternative implementation without branching
* but with type conversion could be:
* return !(x < edge);
*/
}
/*!
* @brief smooth Hermite interpolation
*
* formula: t^2 * (3-2t)
*
* @param[in] t interpolant (amount)
*/
CGLM_INLINE
float
glm_smooth(float t) {
return t * t * (3.0f - 2.0f * t);
}
/*!
* @brief threshold function with a smooth transition (according to OpenCL specs)
*
* formula: t^2 * (3-2t)
*
* @param[in] edge0 low threshold
* @param[in] edge1 high threshold
* @param[in] x interpolant (amount)
*/
CGLM_INLINE
float
glm_smoothstep(float edge0, float edge1, float x) {
float t;
t = glm_clamp_zo((x - edge0) / (edge1 - edge0));
return glm_smooth(t);
}
/*!
* @brief smoothstep interpolation between two numbers
*
* formula: from + smoothstep(t) * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount)
*/
CGLM_INLINE
float
glm_smoothinterp(float from, float to, float t) {
return from + glm_smooth(t) * (to - from);
}
/*!
* @brief clamped smoothstep interpolation between two numbers
*
* formula: from + smoothstep(t) * (to - from)
*
* @param[in] from from value
* @param[in] to to value
@@ -167,8 +276,8 @@ glm_clamp_zo(float val) {
*/
CGLM_INLINE
float
glm_lerp(float from, float to, float t) {
return from + glm_clamp_zo(t) * (to - from);
glm_smoothinterpc(float from, float to, float t) {
return glm_smoothinterp(from, to, glm_clamp_zo(t));
}
/*!

View File

@@ -12,6 +12,7 @@
/*
Functions:
CGLM_INLINE void glm_vec3_broadcast(float val, vec3 d);
CGLM_INLINE void glm_vec3_fill(vec3 v, float val);
CGLM_INLINE bool glm_vec3_eq(vec3 v, float val);
CGLM_INLINE bool glm_vec3_eq_eps(vec3 v, float val);
CGLM_INLINE bool glm_vec3_eq_all(vec3 v);
@@ -44,6 +45,18 @@ glm_vec3_broadcast(float val, vec3 d) {
d[0] = d[1] = d[2] = val;
}
/*!
* @brief fill a vector with specified value
*
* @param[out] v dest
* @param[in] val value
*/
CGLM_INLINE
void
glm_vec3_fill(vec3 v, float val) {
v[0] = v[1] = v[2] = val;
}
/*!
* @brief check if vector is equal to value (without epsilon)
*

View File

@@ -48,19 +48,28 @@
CGLM_INLINE void glm_vec3_normalize_to(vec3 v, vec3 dest);
CGLM_INLINE void glm_vec3_cross(vec3 a, vec3 b, vec3 d);
CGLM_INLINE void glm_vec3_crossn(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE float glm_vec3_distance(vec3 a, vec3 b);
CGLM_INLINE float glm_vec3_angle(vec3 a, vec3 b);
CGLM_INLINE void glm_vec3_rotate(vec3 v, float angle, vec3 axis);
CGLM_INLINE void glm_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest);
CGLM_INLINE void glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest);
CGLM_INLINE void glm_vec3_proj(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec3_center(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE float glm_vec3_distance(vec3 a, vec3 b);
CGLM_INLINE float glm_vec3_distance2(vec3 a, vec3 b);
CGLM_INLINE void glm_vec3_maxv(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec3_minv(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec3_ortho(vec3 v, vec3 dest);
CGLM_INLINE void glm_vec3_clamp(vec3 v, float minVal, float maxVal);
CGLM_INLINE void glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest);
CGLM_INLINE void glm_vec3_lerpc(vec3 from, vec3 to, float t, vec3 dest);
CGLM_INLINE void glm_vec3_mix(vec3 from, vec3 to, float t, vec3 dest);
CGLM_INLINE void glm_vec3_mixc(vec3 from, vec3 to, float t, vec3 dest);
CGLM_INLINE void glm_vec3_step_uni(float edge, vec3 x, vec3 dest);
CGLM_INLINE void glm_vec3_step(vec3 edge, vec3 x, vec3 dest);
CGLM_INLINE void glm_vec3_smoothstep_uni(float edge0, float edge1, vec3 x, vec3 dest);
CGLM_INLINE void glm_vec3_smoothstep(vec3 edge0, vec3 edge1, vec3 x, vec3 dest);
CGLM_INLINE void glm_vec3_smoothinterp(vec3 from, vec3 to, float t, vec3 dest);
CGLM_INLINE void glm_vec3_smoothinterpc(vec3 from, vec3 to, float t, vec3 dest);
CGLM_INLINE void glm_vec3_swizzle(vec3 v, int mask, vec3 dest);
Convenient:
@@ -191,7 +200,8 @@ glm_vec3_norm2(vec3 v) {
}
/*!
* @brief norm (magnitude) of vec3
* @brief euclidean norm (magnitude), also called L2 norm
* this will give magnitude of vector in euclidean space
*
* @param[in] v vector
*
@@ -694,9 +704,9 @@ glm_vec3_center(vec3 a, vec3 b, vec3 dest) {
CGLM_INLINE
float
glm_vec3_distance2(vec3 a, vec3 b) {
return glm_pow2(b[0] - a[0])
+ glm_pow2(b[1] - a[1])
+ glm_pow2(b[2] - a[2]);
return glm_pow2(a[0] - b[0])
+ glm_pow2(a[1] - b[1])
+ glm_pow2(a[2] - b[2]);
}
/**
@@ -772,7 +782,29 @@ glm_vec3_clamp(vec3 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)
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) {
vec3 s, v;
/* from + s * (to - from) */
glm_vec3_broadcast(t, s);
glm_vec3_sub(to, from, v);
glm_vec3_mul(s, v, v);
glm_vec3_add(from, v, dest);
}
/*!
* @brief linear interpolation between two vectors (clamped)
*
* formula: from + s * (to - from)
*
@@ -783,16 +815,142 @@ glm_vec3_clamp(vec3 v, float minVal, float maxVal) {
*/
CGLM_INLINE
void
glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) {
vec3 s, v;
glm_vec3_lerpc(vec3 from, vec3 to, float t, vec3 dest) {
glm_vec3_lerp(from, to, glm_clamp_zo(t), dest);
}
/*!
* @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)
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_mix(vec3 from, vec3 to, float t, vec3 dest) {
glm_vec3_lerp(from, to, t, dest);
}
/*!
* @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
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_mixc(vec3 from, vec3 to, float t, vec3 dest) {
glm_vec3_lerpc(from, to, t, dest);
}
/*!
* @brief threshold function (unidimensional)
*
* @param[in] edge threshold
* @param[in] x value to test against threshold
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_step_uni(float edge, vec3 x, vec3 dest) {
dest[0] = glm_step(edge, x[0]);
dest[1] = glm_step(edge, x[1]);
dest[2] = glm_step(edge, x[2]);
}
/*!
* @brief threshold function
*
* @param[in] edge threshold
* @param[in] x value to test against threshold
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_step(vec3 edge, vec3 x, vec3 dest) {
dest[0] = glm_step(edge[0], x[0]);
dest[1] = glm_step(edge[1], x[1]);
dest[2] = glm_step(edge[2], x[2]);
}
/*!
* @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
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_smoothstep_uni(float edge0, float edge1, vec3 x, vec3 dest) {
dest[0] = glm_smoothstep(edge0, edge1, x[0]);
dest[1] = glm_smoothstep(edge0, edge1, x[1]);
dest[2] = glm_smoothstep(edge0, edge1, x[2]);
}
/*!
* @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
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_smoothstep(vec3 edge0, vec3 edge1, vec3 x, vec3 dest) {
dest[0] = glm_smoothstep(edge0[0], edge1[0], x[0]);
dest[1] = glm_smoothstep(edge0[1], edge1[1], x[1]);
dest[2] = glm_smoothstep(edge0[2], edge1[2], x[2]);
}
/*!
* @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)
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_smoothinterp(vec3 from, vec3 to, float t, vec3 dest) {
vec3 s, v;
/* from + s * (to - from) */
glm_vec3_broadcast(glm_clamp_zo(t), s);
glm_vec3_broadcast(glm_smooth(t), s);
glm_vec3_sub(to, from, v);
glm_vec3_mul(s, v, v);
glm_vec3_add(from, v, dest);
}
/*!
* @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
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_smoothinterpc(vec3 from, vec3 to, float t, vec3 dest) {
glm_vec3_smoothinterp(from, to, glm_clamp_zo(t), dest);
}
/*!
* @brief vec3 cross product
*

View File

@@ -12,6 +12,7 @@
/*
Functions:
CGLM_INLINE void glm_vec4_broadcast(float val, vec4 d);
CGLM_INLINE void glm_vec4_fill(vec4 v, float val);
CGLM_INLINE bool glm_vec4_eq(vec4 v, float val);
CGLM_INLINE bool glm_vec4_eq_eps(vec4 v, float val);
CGLM_INLINE bool glm_vec4_eq_all(vec4 v);
@@ -48,6 +49,22 @@ glm_vec4_broadcast(float val, vec4 d) {
#endif
}
/*!
* @brief fill a vector with specified value
*
* @param v dest
* @param val value
*/
CGLM_INLINE
void
glm_vec4_fill(vec4 v, float val) {
#if defined( __SSE__ ) || defined( __SSE2__ )
glmm_store(v, _mm_set1_ps(val));
#else
v[0] = v[1] = v[2] = v[3] = val;
#endif
}
/*!
* @brief check if vector is equal to value (without epsilon)
*

View File

@@ -43,10 +43,18 @@
CGLM_INLINE void glm_vec4_normalize(vec4 v);
CGLM_INLINE void glm_vec4_normalize_to(vec4 vec, vec4 dest);
CGLM_INLINE float glm_vec4_distance(vec4 a, vec4 b);
CGLM_INLINE float glm_vec4_distance2(vec4 a, vec4 b);
CGLM_INLINE void glm_vec4_maxv(vec4 a, vec4 b, vec4 dest);
CGLM_INLINE void glm_vec4_minv(vec4 a, vec4 b, vec4 dest);
CGLM_INLINE void glm_vec4_clamp(vec4 v, float minVal, float maxVal);
CGLM_INLINE void glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest)
CGLM_INLINE void glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest);
CGLM_INLINE void glm_vec4_lerpc(vec4 from, vec4 to, float t, vec4 dest);
CGLM_INLINE void glm_vec4_step_uni(float edge, vec4 x, vec4 dest);
CGLM_INLINE void glm_vec4_step(vec4 edge, vec4 x, vec4 dest);
CGLM_INLINE void glm_vec4_smoothstep_uni(float edge0, float edge1, vec4 x, vec4 dest);
CGLM_INLINE void glm_vec4_smoothstep(vec4 edge0, vec4 edge1, vec4 x, vec4 dest);
CGLM_INLINE void glm_vec4_smoothinterp(vec4 from, vec4 to, float t, vec4 dest);
CGLM_INLINE void glm_vec4_smoothinterpc(vec4 from, vec4 to, float t, vec4 dest);
CGLM_INLINE void glm_vec4_swizzle(vec4 v, int mask, vec4 dest);
DEPRECATED:
@@ -232,7 +240,8 @@ glm_vec4_norm2(vec4 v) {
}
/*!
* @brief norm (magnitude) of vec4
* @brief euclidean norm (magnitude), also called L2 norm
* this will give magnitude of vector in euclidean space
*
* @param[in] v vector
*
@@ -697,14 +706,36 @@ CGLM_INLINE
float
glm_vec4_distance(vec4 a, vec4 b) {
#if defined( __SSE__ ) || defined( __SSE2__ )
return glmm_norm(_mm_sub_ps(glmm_load(b), glmm_load(a)));
return glmm_norm(_mm_sub_ps(glmm_load(a), glmm_load(b)));
#elif defined(CGLM_NEON_FP)
return glmm_norm(vsubq_f32(glmm_load(a), glmm_load(b)));
#else
return sqrtf(glm_pow2(b[0] - a[0])
+ glm_pow2(b[1] - a[1])
+ glm_pow2(b[2] - a[2])
+ glm_pow2(b[3] - a[3]));
return sqrtf(glm_pow2(a[0] - b[0])
+ glm_pow2(a[1] - b[1])
+ glm_pow2(a[2] - b[2])
+ glm_pow2(a[3] - b[3]));
#endif
}
/**
* @brief squared distance between two vectors
*
* @param[in] a vector1
* @param[in] b vector2
* @return returns squared distance
*/
CGLM_INLINE
float
glm_vec4_distance2(vec4 a, vec4 b) {
#if defined( __SSE__ ) || defined( __SSE2__ )
return glmm_norm2(_mm_sub_ps(glmm_load(a), glmm_load(b)));
#elif defined(CGLM_NEON_FP)
return glmm_norm2(vsubq_f32(glmm_load(a), glmm_load(b)));
#else
return glm_pow2(a[0] - b[0])
+ glm_pow2(a[1] - b[1])
+ glm_pow2(a[2] - b[2])
+ glm_pow2(a[3] - b[3]);
#endif
}
@@ -777,13 +808,13 @@ glm_vec4_clamp(vec4 v, float minVal, float maxVal) {
}
/*!
* @brief linear interpolation between two vector
* @brief linear interpolation between two vectors
*
* formula: from + s * (to - from)
* formula: from + t * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount) clamped between 0 and 1
* @param[in] t interpolant (amount)
* @param[out] dest destination
*/
CGLM_INLINE
@@ -792,12 +823,164 @@ glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) {
vec4 s, v;
/* from + s * (to - from) */
glm_vec4_broadcast(glm_clamp_zo(t), s);
glm_vec4_broadcast(t, s);
glm_vec4_sub(to, from, v);
glm_vec4_mul(s, v, v);
glm_vec4_add(from, v, dest);
}
/*!
* @brief linear interpolation between two vectors (clamped)
*
* formula: from + t * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount) clamped between 0 and 1
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec4_lerpc(vec4 from, vec4 to, float t, vec4 dest) {
glm_vec4_lerp(from, to, glm_clamp_zo(t), dest);
}
/*!
* @brief linear interpolation between two vectors
*
* formula: from + t * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount)
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec4_mix(vec4 from, vec4 to, float t, vec4 dest) {
glm_vec4_lerp(from, to, t, dest);
}
/*!
* @brief linear interpolation between two vectors (clamped)
*
* formula: from + t * (to - from)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount) clamped between 0 and 1
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec4_mixc(vec4 from, vec4 to, float t, vec4 dest) {
glm_vec4_lerpc(from, to, t, dest);
}
/*!
* @brief threshold function (unidimensional)
*
* @param[in] edge threshold
* @param[in] x value to test against threshold
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec4_step_uni(float edge, vec4 x, vec4 dest) {
dest[0] = glm_step(edge, x[0]);
dest[1] = glm_step(edge, x[1]);
dest[2] = glm_step(edge, x[2]);
dest[3] = glm_step(edge, x[3]);
}
/*!
* @brief threshold function
*
* @param[in] edge threshold
* @param[in] x value to test against threshold
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec4_step(vec4 edge, vec4 x, vec4 dest) {
dest[0] = glm_step(edge[0], x[0]);
dest[1] = glm_step(edge[1], x[1]);
dest[2] = glm_step(edge[2], x[2]);
dest[3] = glm_step(edge[3], x[3]);
}
/*!
* @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
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec4_smoothstep_uni(float edge0, float edge1, vec4 x, vec4 dest) {
dest[0] = glm_smoothstep(edge0, edge1, x[0]);
dest[1] = glm_smoothstep(edge0, edge1, x[1]);
dest[2] = glm_smoothstep(edge0, edge1, x[2]);
dest[3] = glm_smoothstep(edge0, edge1, x[3]);
}
/*!
* @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
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec4_smoothstep(vec4 edge0, vec4 edge1, vec4 x, vec4 dest) {
dest[0] = glm_smoothstep(edge0[0], edge1[0], x[0]);
dest[1] = glm_smoothstep(edge0[1], edge1[1], x[1]);
dest[2] = glm_smoothstep(edge0[2], edge1[2], x[2]);
dest[3] = glm_smoothstep(edge0[3], edge1[3], x[3]);
}
/*!
* @brief smooth Hermite interpolation between two vectors
*
* formula: t^2 * (3 - 2*t)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount)
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec4_smoothinterp(vec4 from, vec4 to, float t, vec4 dest) {
vec4 s, v;
/* from + smoothstep * (to - from) */
glm_vec4_broadcast(glm_smooth(t), s);
glm_vec4_sub(to, from, v);
glm_vec4_mul(s, v, v);
glm_vec4_add(from, v, dest);
}
/*!
* @brief smooth Hermite interpolation between two vectors (clamped)
*
* formula: t^2 * (3 - 2*t)
*
* @param[in] from from value
* @param[in] to to value
* @param[in] t interpolant (amount) clamped between 0 and 1
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec4_smoothinterpc(vec4 from, vec4 to, float t, vec4 dest) {
glm_vec4_smoothinterp(from, to, glm_clamp_zo(t), dest);
}
/*!
* @brief helper to fill vec4 as [S^3, S^2, S, 1]
*

View File

@@ -164,6 +164,12 @@ glmc_quat_lerp(versor from, versor to, float t, versor dest) {
glm_quat_lerp(from, to, t, dest);
}
CGLM_EXPORT
void
glmc_quat_lerpc(versor from, versor to, float t, versor dest) {
glm_quat_lerpc(from, to, t, dest);
}
CGLM_EXPORT
void
glmc_quat_slerp(versor from, versor to, float t, versor dest) {

View File

@@ -214,14 +214,14 @@ glmc_vec3_center(vec3 a, vec3 b, vec3 dest) {
CGLM_EXPORT
float
glmc_vec3_distance2(vec3 a, vec3 b) {
return glm_vec3_distance2(a, b);
glmc_vec3_distance(vec3 a, vec3 b) {
return glm_vec3_distance(a, b);
}
CGLM_EXPORT
float
glmc_vec3_distance(vec3 a, vec3 b) {
return glm_vec3_distance(a, b);
glmc_vec3_distance2(vec3 a, vec3 b) {
return glm_vec3_distance2(a, b);
}
CGLM_EXPORT
@@ -254,6 +254,48 @@ glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) {
glm_vec3_lerp(from, to, t, dest);
}
CGLM_EXPORT
void
glmc_vec3_lerpc(vec3 from, vec3 to, float t, vec3 dest) {
glm_vec3_lerpc(from, to, t, dest);
}
CGLM_EXPORT
void
glmc_vec3_step_uni(float edge, vec3 x, vec3 dest) {
glm_vec3_step_uni(edge, x, dest);
}
CGLM_EXPORT
void
glmc_vec3_step(vec3 edge, vec3 x, vec3 dest) {
glm_vec3_step(edge, x, dest);
}
CGLM_EXPORT
void
glmc_vec3_smoothstep_uni(float edge0, float edge1, vec3 x, vec3 dest) {
glm_vec3_smoothstep_uni(edge0, edge1, x, dest);
}
CGLM_EXPORT
void
glmc_vec3_smoothstep(vec3 edge0, vec3 edge1, vec3 x, vec3 dest) {
glm_vec3_smoothstep(edge0, edge1, x, dest);
}
CGLM_EXPORT
void
glmc_vec3_smoothinterp(vec3 from, vec3 to, float t, vec3 dest) {
glm_vec3_smoothinterp(from, to, t, dest);
}
CGLM_EXPORT
void
glmc_vec3_smoothinterpc(vec3 from, vec3 to, float t, vec3 dest) {
glm_vec3_smoothinterpc(from, to, t, dest);
}
/* ext */
CGLM_EXPORT
@@ -268,6 +310,12 @@ glmc_vec3_broadcast(float val, vec3 d) {
glm_vec3_broadcast(val, d);
}
CGLM_EXPORT
void
glmc_vec3_fill(vec3 v, float val) {
glm_vec3_fill(v, val);
}
CGLM_EXPORT
bool
glmc_vec3_eq(vec3 v, float val) {

View File

@@ -182,6 +182,12 @@ glmc_vec4_distance(vec4 a, vec4 b) {
return glm_vec4_distance(a, b);
}
CGLM_EXPORT
float
glmc_vec4_distance2(vec4 a, vec4 b) {
return glm_vec4_distance2(a, b);
}
CGLM_EXPORT
void
glmc_vec4_maxv(vec4 a, vec4 b, vec4 dest) {
@@ -206,6 +212,48 @@ glmc_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) {
glm_vec4_lerp(from, to, t, dest);
}
CGLM_EXPORT
void
glmc_vec4_lerpc(vec4 from, vec4 to, float t, vec4 dest) {
glm_vec4_lerpc(from, to, t, dest);
}
CGLM_EXPORT
void
glmc_vec4_step_uni(float edge, vec4 x, vec4 dest) {
glm_vec4_step_uni(edge, x, dest);
}
CGLM_EXPORT
void
glmc_vec4_step(vec4 edge, vec4 x, vec4 dest) {
glm_vec4_step(edge, x, dest);
}
CGLM_EXPORT
void
glmc_vec4_smoothstep_uni(float edge0, float edge1, vec4 x, vec4 dest) {
glm_vec4_smoothstep_uni(edge0, edge1, x, dest);
}
CGLM_EXPORT
void
glmc_vec4_smoothstep(vec4 edge0, vec4 edge1, vec4 x, vec4 dest) {
glm_vec4_smoothstep(edge0, edge1, x, dest);
}
CGLM_EXPORT
void
glmc_vec4_smoothinterp(vec4 from, vec4 to, float t, vec4 dest) {
glm_vec4_smoothinterp(from, to, t, dest);
}
CGLM_EXPORT
void
glmc_vec4_smoothinterpc(vec4 from, vec4 to, float t, vec4 dest) {
glm_vec4_smoothinterpc(from, to, t, dest);
}
CGLM_EXPORT
void
glmc_vec4_cubic(float s, vec4 dest) {
@@ -226,6 +274,12 @@ glmc_vec4_broadcast(float val, vec4 d) {
glm_vec4_broadcast(val, d);
}
CGLM_EXPORT
void
glmc_vec4_fill(vec4 v, float val) {
glm_vec4_fill(v, val);
}
CGLM_EXPORT
bool
glmc_vec4_eq(vec4 v, float val) {