diff --git a/docs/source/quat.rst b/docs/source/quat.rst index cc4b5f7..186fe83 100644 --- a/docs/source/quat.rst +++ b/docs/source/quat.rst @@ -426,7 +426,7 @@ Functions documentation Create quaternion from pointer - | NOTE: **@src** must contain 4 elements. cglm store quaternions as [x, y, z, w]. + | NOTE: **@src** must contain at least 4 elements. cglm store quaternions as [x, y, z, w]. Parameters: | *[in]* **src** pointer to an array of floats diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index 17e4824..51063d9 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -79,6 +79,7 @@ Functions: #. :c:func:`glm_vec3_ortho` #. :c:func:`glm_vec3_clamp` #. :c:func:`glm_vec3_lerp` +#. :c:func:`glm_vec3_make` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -501,3 +502,13 @@ Functions documentation | *[in]* **to** to value | *[in]* **t** interpolant (amount) clamped between 0 and 1 | *[out]* **dest** destination + +.. c:function:: void glm_vec3_make(float * __restrict src, vec3 dest) + + Create three dimensional vector from pointer + + | NOTE: **@src** must contain at least 3 elements. + + Parameters: + | *[in]* **src** pointer to an array of floats + | *[out]* **dest** destination vector diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index 58c861e..687a10f 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -59,6 +59,7 @@ Functions: #. :c:func:`glm_vec4_clamp` #. :c:func:`glm_vec4_lerp` #. :c:func:`glm_vec4_cubic` +#. :c:func:`glm_vec4_make` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -406,3 +407,12 @@ Functions documentation Parameters: | *[in]* **s** parameter | *[out]* **dest** destination + +.. c:function:: void glm_vec4_make(float * __restrict src, vec4 dest) + + Create four dimensional vector from pointer + + | NOTE: **@src** must contain at least 4 elements. + Parameters: + | *[in]* **src** pointer to an array of floats + | *[out]* **dest** destination vector diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 69fc0e2..099fe4c 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -306,6 +306,10 @@ CGLM_EXPORT void glmc_vec3_sqrt(vec3 v, vec3 dest); +CGLM_EXPORT +void +glmc_vec3_make(float * __restrict src, vec3 dest); + #ifdef __cplusplus } #endif diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index f56f599..6bda5db 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -283,6 +283,10 @@ CGLM_EXPORT void glmc_vec4_sqrt(vec4 v, vec4 dest); +CGLM_EXPORT +void +glmc_vec4_make(float * __restrict src, vec4 dest); + #ifdef __cplusplus } #endif diff --git a/include/cglm/struct/quat.h b/include/cglm/struct/quat.h index d45d4a3..a37cdc5 100644 --- a/include/cglm/struct/quat.h +++ b/include/cglm/struct/quat.h @@ -44,7 +44,7 @@ CGLM_INLINE mat4s glms_quat_rotate(mat4s m, versors q) CGLM_INLINE mat4s glms_quat_rotate_at(mat4s m, versors q, vec3s pivot) CGLM_INLINE mat4s glms_quat_rotate_atm(versors q, vec3s pivot) - CGLM_INLINE void glms_quat_make(float * restrict src) + CGLM_INLINE versors glms_quat_make(float * restrict src) */ #ifndef cglms_quat_h diff --git a/include/cglm/struct/vec3.h b/include/cglm/struct/vec3.h index 49e5665..163b2be 100644 --- a/include/cglm/struct/vec3.h +++ b/include/cglm/struct/vec3.h @@ -70,6 +70,7 @@ 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); + CGLM_INLINE vec3s glms_vec3_make(float * restrict src); Convenient: CGLM_INLINE vec3s glms_cross(vec3s a, vec3s b); @@ -967,4 +968,18 @@ glms_vec3_(swizzle)(vec3s v, int mask) { return dest; } +/*! + * @brief Create three dimensional vector from pointer + * + * @param[in] src pointer to an array of floats + * @returns constructed 3D vector from raw pointer + */ +CGLM_INLINE +vec3s +glms_vec3_(make)(float * __restrict src) { + vec3s dest; + glm_vec3_make(src, dest.raw); + return dest; +} + #endif /* cglms_vec3s_h */ diff --git a/include/cglm/struct/vec4.h b/include/cglm/struct/vec4.h index 2fa22aa..53ec3fb 100644 --- a/include/cglm/struct/vec4.h +++ b/include/cglm/struct/vec4.h @@ -61,6 +61,7 @@ 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); + CGLM_INLINE vec4s glms_vec4_make(float * restrict src); */ #ifndef cglms_vec4s_h @@ -811,4 +812,18 @@ glms_vec4_(swizzle)(vec4s v, int mask) { return dest; } +/*! + * @brief Create four dimensional vector from pointer + * + * @param[in] src pointer to an array of floats + * @returns constructed 4D vector from raw pointer + */ +CGLM_INLINE +vec4s +glms_vec4_(make)(float * __restrict src) { + vec4s dest; + glm_vec4_make(src, dest.raw); + return dest; +} + #endif /* cglms_vec4s_h */ diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index ce6affa..c610226 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -73,6 +73,7 @@ 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); + CGLM_INLINE void glm_vec3_make(float * restrict src, vec3 dest); Convenient: CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d); @@ -1079,4 +1080,18 @@ glm_normalize_to(vec3 v, vec3 dest) { glm_vec3_normalize_to(v, dest); } +/*! + * @brief Create three dimensional vector from pointer + * + * @param[in] src pointer to an array of floats + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec3_make(float * __restrict src, vec3 dest) { + dest[0] = src[0]; + dest[1] = src[1]; + dest[2] = src[2]; +} + #endif /* cglm_vec3_h */ diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 03d99bd..5c9ff6e 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -58,6 +58,7 @@ 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); + CGLM_INLINE void glm_vec4_make(float * restrict src, vec4 dest); DEPRECATED: glm_vec4_dup @@ -1133,4 +1134,17 @@ glm_vec4_swizzle(vec4 v, int mask, vec4 dest) { glm_vec4_copy(t, dest); } +/*! + * @brief Create four dimensional vector from pointer + * + * @param[in] src pointer to an array of floats + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_make(float * __restrict src, vec4 dest) { + dest[0] = src[0]; dest[1] = src[1]; + dest[2] = src[2]; dest[3] = src[3]; +} + #endif /* cglm_vec4_h */ diff --git a/src/vec3.c b/src/vec3.c index a09a2ef..e515e89 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -417,3 +417,9 @@ void glmc_vec3_sqrt(vec3 v, vec3 dest) { glm_vec3_sqrt(v, dest); } + +CGLM_EXPORT +void +glmc_vec3_make(float * __restrict src, vec3 dest) { + glm_vec3_make(src, dest); +} diff --git a/src/vec4.c b/src/vec4.c index 60c3a25..88ae54b 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -381,3 +381,9 @@ void glmc_vec4_sqrt(vec4 v, vec4 dest) { glm_vec4_sqrt(v, dest); } + +CGLM_EXPORT +void +glmc_vec4_make(float * __restrict src, vec4 dest) { + glm_vec4_make(src, dest); +} diff --git a/test/src/test_quat.h b/test/src/test_quat.h index 2197706..da831fe 100644 --- a/test/src/test_quat.h +++ b/test/src/test_quat.h @@ -1086,12 +1086,22 @@ TEST_IMPL(GLM_PREFIX, quat_rotate_atm) { } TEST_IMPL(GLM_PREFIX, quat_make) { - versor dest; - float src[4] = {7.2f, 1.0f, 2.5f, 6.1f}; + versor dest[3]; + float src[12] = { + 7.2f, 1.0f, 2.5f, 6.1f, + 0.2f, 2.8f, 17.3f, 5.1f, + 4.2f, 7.3f, 6.6f, 8.8f + }; - GLM(quat_make)(src, dest); - for (unsigned int i = 0; i < sizeof(src) / sizeof(float); i++) { - ASSERT(test_eq(src[i], dest[i])); + float *srcp = src; + unsigned int i, j; + + for (i = 0, j = 0; i < sizeof(src) / sizeof(float); i+=4,j++) { + GLM(quat_make)(srcp + i, dest[j]); + ASSERT(test_eq(src[ i ], dest[j][0])); + ASSERT(test_eq(src[i+1], dest[j][1])); + ASSERT(test_eq(src[i+2], dest[j][2])); + ASSERT(test_eq(src[i+3], dest[j][3])); } TEST_SUCCESS diff --git a/test/src/test_vec3.h b/test/src/test_vec3.h index 44a9847..bc908cd 100644 --- a/test/src/test_vec3.h +++ b/test/src/test_vec3.h @@ -1729,3 +1729,24 @@ TEST_IMPL(GLM_PREFIX, vec3_sqrt) { TEST_SUCCESS } + +TEST_IMPL(GLM_PREFIX, vec3_make) { + float src[9] = { + 7.2f, 1.0f, 5.8f, + 2.5f, 6.1f, 9.9f, + 17.7f, 4.3f, 3.2f + }; + vec3 dest[3]; + + float *srcp = src; + unsigned int i, j; + + for (i = 0, j = 0; i < sizeof(src) / sizeof(float); i+=3,j++) { + GLM(vec3_make)(srcp + i, dest[j]); + ASSERT(test_eq(src[ i ], dest[j][0])); + ASSERT(test_eq(src[i+1], dest[j][1])); + ASSERT(test_eq(src[i+2], dest[j][2])); + } + + TEST_SUCCESS +} diff --git a/test/src/test_vec4.h b/test/src/test_vec4.h index abb882f..5684e2d 100644 --- a/test/src/test_vec4.h +++ b/test/src/test_vec4.h @@ -1418,3 +1418,25 @@ TEST_IMPL(GLM_PREFIX, vec4_sqrt) { TEST_SUCCESS } + +TEST_IMPL(GLM_PREFIX, vec4_make) { + float src[12] = { + 7.2f, 1.0f, 5.8f, 0.0f, + 2.5f, 6.1f, 9.9f, 1.0f, + 17.7f, 4.3f, 3.2f, 1.0f + }; + vec4 dest[3]; + + float *srcp = src; + unsigned int i, j; + + for (i = 0, j = 0; i < sizeof(src) / sizeof(float); i+=4,j++) { + GLM(vec4_make)(srcp + i, dest[j]); + ASSERT(test_eq(src[ i ], dest[j][0])); + ASSERT(test_eq(src[i+1], dest[j][1])); + ASSERT(test_eq(src[i+2], dest[j][2])); + ASSERT(test_eq(src[i+3], dest[j][3])); + } + + TEST_SUCCESS +} diff --git a/test/tests.h b/test/tests.h index 8117b76..996102b 100644 --- a/test/tests.h +++ b/test/tests.h @@ -533,6 +533,7 @@ TEST_DECLARE(glm_vec3_abs) TEST_DECLARE(glm_vec3_fract) TEST_DECLARE(glm_vec3_hadd) TEST_DECLARE(glm_vec3_sqrt) +TEST_DECLARE(glm_vec3_make) TEST_DECLARE(glmc_vec3) TEST_DECLARE(glmc_vec3_copy) @@ -602,6 +603,7 @@ TEST_DECLARE(glmc_vec3_abs) TEST_DECLARE(glmc_vec3_fract) TEST_DECLARE(glmc_vec3_hadd) TEST_DECLARE(glmc_vec3_sqrt) +TEST_DECLARE(glmc_vec3_make) /* vec4 */ TEST_DECLARE(MACRO_GLM_VEC4_ONE_INIT) @@ -683,6 +685,7 @@ TEST_DECLARE(glm_vec4_abs) TEST_DECLARE(glm_vec4_fract) TEST_DECLARE(glm_vec4_hadd) TEST_DECLARE(glm_vec4_sqrt) +TEST_DECLARE(glm_vec4_make) TEST_DECLARE(glmc_vec4) TEST_DECLARE(glmc_vec4_copy3) @@ -748,6 +751,7 @@ TEST_DECLARE(glmc_vec4_abs) TEST_DECLARE(glmc_vec4_fract) TEST_DECLARE(glmc_vec4_hadd) TEST_DECLARE(glmc_vec4_sqrt) +TEST_DECLARE(glmc_vec4_make) /* ivec2 */ TEST_DECLARE(glm_ivec2) @@ -1382,6 +1386,7 @@ TEST_LIST { TEST_ENTRY(glm_vec3_fract) TEST_ENTRY(glm_vec3_hadd) TEST_ENTRY(glm_vec3_sqrt) + TEST_ENTRY(glm_vec3_make) TEST_ENTRY(glmc_vec3) TEST_ENTRY(glmc_vec3_copy) @@ -1451,6 +1456,7 @@ TEST_LIST { TEST_ENTRY(glmc_vec3_fract) TEST_ENTRY(glmc_vec3_hadd) TEST_ENTRY(glmc_vec3_sqrt) + TEST_ENTRY(glmc_vec3_make) /* vec4 */ TEST_ENTRY(MACRO_GLM_VEC4_ONE_INIT) @@ -1532,6 +1538,7 @@ TEST_LIST { TEST_ENTRY(glm_vec4_fract) TEST_ENTRY(glm_vec4_hadd) TEST_ENTRY(glm_vec4_sqrt) + TEST_ENTRY(glm_vec4_make) TEST_ENTRY(glmc_vec4) TEST_ENTRY(glmc_vec4_copy3) @@ -1597,6 +1604,7 @@ TEST_LIST { TEST_ENTRY(glmc_vec4_fract) TEST_ENTRY(glmc_vec4_hadd) TEST_ENTRY(glmc_vec4_sqrt) + TEST_ENTRY(glmc_vec4_make) /* ivec2 */ TEST_ENTRY(glm_ivec2)