From 2025b357576a242f9e184aece49e5b866cd52bb8 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 6 Jun 2019 13:18:31 +0300 Subject: [PATCH] struct: struct vesion of swizzle funcs --- include/cglm/struct/vec3.h | 18 ++++++++++++++++++ include/cglm/struct/vec4.h | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/cglm/struct/vec3.h b/include/cglm/struct/vec3.h index fbe716d..4e8d677 100644 --- a/include/cglm/struct/vec3.h +++ b/include/cglm/struct/vec3.h @@ -58,6 +58,7 @@ 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_swizzle(vec3s v, int mask); Convenient: CGLM_INLINE vec3s glms_cross(vec3s a, vec3s b); @@ -747,4 +748,21 @@ glms_normalize(vec3s v) { return v; } +/*! + * @brief swizzle vector components + * + * you can use existin masks e.g. GLM_XXX, GLM_ZYX + * + * @param[in] v source + * @param[in] mask mask + * @returns swizzled vector + */ +CGLM_INLINE +vec3s +glms_vec3_swizzle(vec3s v, int mask) { + vec3s dest; + glm_vec3_swizzle(v.raw, mask, dest.raw); + return dest; +} + #endif /* cglms_vec3s_h */ diff --git a/include/cglm/struct/vec4.h b/include/cglm/struct/vec4.h index 4fe75ba..0b403a9 100644 --- a/include/cglm/struct/vec4.h +++ b/include/cglm/struct/vec4.h @@ -48,6 +48,7 @@ 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_cubic(float s); + CGLM_INLINE vec4s glms_vec4_swizzle(vec4s v, int mask); */ #ifndef cglms_vec4s_h @@ -577,4 +578,21 @@ glms_vec4_cubic(float s) { return r; } +/*! + * @brief swizzle vector components + * + * you can use existin masks e.g. GLM_XXXX, GLM_WZYX + * + * @param[in] v source + * @param[in] mask mask + * @returns swizzled vector + */ +CGLM_INLINE +vec4s +glms_vec4_swizzle(vec4s v, int mask) { + vec4s dest; + glm_vec4_swizzle(v.raw, mask, dest.raw); + return dest; +} + #endif /* cglms_vec4s_h */