Skip to content

Commit

Permalink
Merge branch 'master' into feature/glm_vec4_make
Browse files Browse the repository at this point in the history
  • Loading branch information
recp committed Jul 2, 2023
2 parents 5833d1b + c5c997c commit b8d565c
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/source/quat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions docs/source/vec3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions include/cglm/call/vec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/cglm/struct/quat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions include/cglm/struct/vec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
15 changes: 15 additions & 0 deletions include/cglm/vec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
6 changes: 6 additions & 0 deletions src/vec3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
20 changes: 15 additions & 5 deletions test/src/test_quat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

float *srcp = src;
unsigned int i, j;

GLM(quat_make)(src, dest);
for (unsigned int i = 0; i < sizeof(src) / sizeof(float); i++) {
ASSERT(test_eq(src[i], dest[i]));
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
Expand Down
21 changes: 21 additions & 0 deletions test/src/test_vec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions test/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,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)
Expand Down Expand Up @@ -600,6 +601,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)
Expand Down Expand Up @@ -1380,6 +1382,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)
Expand Down Expand Up @@ -1449,6 +1452,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)
Expand Down

0 comments on commit b8d565c

Please sign in to comment.