vec2 swizzle

This commit is contained in:
Marcin
2025-01-18 19:27:21 +00:00
parent b45bf1d571
commit 4b0e7dadd6
5 changed files with 46 additions and 0 deletions

View File

@@ -201,6 +201,10 @@ CGLM_EXPORT
void
glmc_vec2_mods(vec2 v, float s, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_swizzle(vec2 v, int mask, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest);

View File

@@ -51,6 +51,7 @@
#define GLM_SHUFFLE4(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w))
#define GLM_SHUFFLE3(z, y, x) (((z) << 4) | ((y) << 2) | (x))
#define GLM_SHUFFLE2(y, x) (((y) << 2) | (x))
#include "types.h"
#include "simd/intrin.h"

View File

@@ -53,6 +53,7 @@
CGLM_INLINE void glm_vec2_maxv(vec2 v1, vec2 v2, vec2 dest)
CGLM_INLINE void glm_vec2_minv(vec2 v1, vec2 v2, vec2 dest)
CGLM_INLINE void glm_vec2_clamp(vec2 v, float minVal, float maxVal)
CGLM_INLINE void glm_vec2_swizzle(vec2 v, int mask, vec2 dest)
CGLM_INLINE void glm_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest)
CGLM_INLINE void glm_vec2_step(vec2 edge, vec2 x, vec2 dest)
CGLM_INLINE void glm_vec2_make(float * restrict src, vec2 dest)
@@ -680,6 +681,24 @@ glm_vec2_clamp(vec2 v, float minval, float maxval) {
v[1] = glm_clamp(v[1], minval, maxval);
}
/*!
* @brief swizzle vector components
*
* @param[in] v source
* @param[in] mask mask
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec2_swizzle(vec2 v, int mask, vec2 dest) {
vec2 t;
t[0] = v[(mask & (3 << 0))];
t[1] = v[(mask & (3 << 2)) >> 2];
glm_vec2_copy(t, dest);
}
/*!
* @brief linear interpolation between two vector
*