Compare commits

...

10 Commits

Author SHA1 Message Date
Recep Aslantas
d17c99215d Update README.md 2018-12-26 09:57:52 +03:00
Recep Aslantas
dc6eb492c1 Merge pull request #70 from recp/vec3-mat3
remove builtin alignment from vec3 and mat3 types
2018-12-26 09:54:48 +03:00
Recep Aslantas
7219b02d23 remove alignment from vec3 and mat3 2018-12-25 10:08:36 +03:00
Recep Aslantas
21834b4ffb matrix: trace of matrix 2018-12-06 18:17:02 +03:00
Recep Aslantas
2ef9c23a6c vec: normalize cross product helper 2018-12-06 18:01:52 +03:00
Recep Aslantas
92605f845a test: fix comparing two float values in tests 2018-12-05 16:34:22 +03:00
Recep Aslantas
b23d65bef5 now working on v0.5.1 2018-12-05 16:32:13 +03:00
Recep Aslantas
2f632c6311 Update README.md 2018-12-02 21:35:50 +03:00
Recep Aslantas
b47d148b81 Update README.md 2018-12-02 21:35:31 +03:00
Recep Aslantas
a5bc2f710e Merge pull request #68 from recp/vec-update
major vector update
2018-12-02 21:24:14 +03:00
22 changed files with 225 additions and 88 deletions

View File

@@ -24,6 +24,8 @@ you have the latest version
- **[major change]** by starting v0.4.0, quaternions are stored as [x, y, z, w], it was [w, x, y, z] in v0.3.5 and earlier versions - **[major change]** by starting v0.4.0, quaternions are stored as [x, y, z, w], it was [w, x, y, z] in v0.3.5 and earlier versions
- **[api rename]** by starting v0.4.5, **glm_simd** functions are renamed to **glmm_** - **[api rename]** by starting v0.4.5, **glm_simd** functions are renamed to **glmm_**
- **[new option]** by starting v0.4.5, you can disable alignment requirement, check options in docs. - **[new option]** by starting v0.4.5, you can disable alignment requirement, check options in docs.
- **[major change]** by starting v0.5.0, vec3 functions use **glm_vec3_** namespace, it was **glm_vec_** until v0.5.0
- **[major change]** by starting v0.5.1, built-in alignment is removed from **vec3** and **mat3** types
#### Note for C++ developers: #### Note for C++ developers:
If you don't aware about original GLM library yet, you may also want to look at: If you don't aware about original GLM library yet, you may also want to look at:
@@ -81,6 +83,7 @@ Currently *cglm* uses default clip space configuration (-1, 1) for camera functi
- frustum (extract view frustum planes, corners...) - frustum (extract view frustum planes, corners...)
- bounding box (AABB in Frustum (culling), crop, merge...) - bounding box (AABB in Frustum (culling), crop, merge...)
- project, unproject - project, unproject
- and other...
<hr /> <hr />
@@ -122,39 +125,6 @@ glm_mul(T, R, modelMat);
glm_inv_tr(modelMat); glm_inv_tr(modelMat);
``` ```
## Contributors
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
<a href="graphs/contributors"><img src="https://opencollective.com/cglm/contributors.svg?width=890&button=false" /></a>
## Backers
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/cglm#backer)]
<a href="https://opencollective.com/cglm#backers" target="_blank"><img src="https://opencollective.com/cglm/backers.svg?width=890"></a>
## Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/cglm#sponsor)]
<a href="https://opencollective.com/cglm/sponsor/0/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/1/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/2/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/2/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/3/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/3/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/4/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/4/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/5/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/5/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/6/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/6/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/7/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/7/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/8/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/9/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/9/avatar.svg"></a>
## License
MIT. check the LICENSE file
## Build ## Build
### Unix (Autotools) ### Unix (Autotools)
@@ -284,3 +254,35 @@ You can pass same way to another APIs e.g. Vulkan, DX...
- [ ] Unaligned operations (e.g. `glm_umat4_mul`) - [ ] Unaligned operations (e.g. `glm_umat4_mul`)
- [x] Extra documentation - [x] Extra documentation
- [ ] ARM Neon Arch (In Progress) - [ ] ARM Neon Arch (In Progress)
## Contributors
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
<a href="graphs/contributors"><img src="https://opencollective.com/cglm/contributors.svg?width=890&button=false" /></a>
## Backers
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/cglm#backer)]
<a href="https://opencollective.com/cglm#backers" target="_blank"><img src="https://opencollective.com/cglm/backers.svg?width=890"></a>
## Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/cglm#sponsor)]
<a href="https://opencollective.com/cglm/sponsor/0/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/1/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/2/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/2/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/3/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/3/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/4/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/4/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/5/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/5/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/6/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/6/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/7/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/7/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/8/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/cglm/sponsor/9/website" target="_blank"><img src="https://opencollective.com/cglm/sponsor/9/avatar.svg"></a>
## License
MIT. check the LICENSE file

View File

@@ -7,7 +7,7 @@
#***************************************************************************** #*****************************************************************************
AC_PREREQ([2.69]) AC_PREREQ([2.69])
AC_INIT([cglm], [0.5.0], [info@recp.me]) AC_INIT([cglm], [0.5.1], [info@recp.me])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])

View File

@@ -62,9 +62,9 @@ author = u'Recep Aslantas'
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = u'0.5.0' version = u'0.5.1'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = u'0.5.0' release = u'0.5.1'
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.

View File

@@ -29,6 +29,7 @@ Functions:
#. :c:func:`glm_mat3_scale` #. :c:func:`glm_mat3_scale`
#. :c:func:`glm_mat3_det` #. :c:func:`glm_mat3_det`
#. :c:func:`glm_mat3_inv` #. :c:func:`glm_mat3_inv`
#. :c:func:`glm_mat3_trace`
#. :c:func:`glm_mat3_swap_col` #. :c:func:`glm_mat3_swap_col`
#. :c:func:`glm_mat3_swap_row` #. :c:func:`glm_mat3_swap_row`
@@ -133,6 +134,16 @@ Functions documentation
| *[in]* **mat** matrix | *[in]* **mat** matrix
| *[out]* **dest** destination (inverse matrix) | *[out]* **dest** destination (inverse matrix)
.. c:function:: void glm_mat3_trace(mat3 m)
| sum of the elements on the main diagonal from upper left to the lower right
Parameters:
| *[in]* **m** matrix
Returns:
trace of matrix
.. c:function:: void glm_mat3_swap_col(mat3 mat, int col1, int col2) .. c:function:: void glm_mat3_swap_col(mat3 mat, int col1, int col2)
swap two matrix columns swap two matrix columns

View File

@@ -33,6 +33,8 @@ Functions:
#. :c:func:`glm_mat4_mulN` #. :c:func:`glm_mat4_mulN`
#. :c:func:`glm_mat4_mulv` #. :c:func:`glm_mat4_mulv`
#. :c:func:`glm_mat4_mulv3` #. :c:func:`glm_mat4_mulv3`
#. :c:func:`glm_mat3_trace`
#. :c:func:`glm_mat3_trace3`
#. :c:func:`glm_mat4_quat` #. :c:func:`glm_mat4_quat`
#. :c:func:`glm_mat4_transpose_to` #. :c:func:`glm_mat4_transpose_to`
#. :c:func:`glm_mat4_transpose` #. :c:func:`glm_mat4_transpose`
@@ -156,6 +158,27 @@ Functions documentation
| *[in]* **v** vec3 (right, column vector) | *[in]* **v** vec3 (right, column vector)
| *[out]* **dest** vec3 (result, column vector) | *[out]* **dest** vec3 (result, column vector)
.. c:function:: void glm_mat4_trace(mat4 m)
| sum of the elements on the main diagonal from upper left to the lower right
Parameters:
| *[in]* **m** matrix
Returns:
trace of matrix
.. c:function:: void glm_mat4_trace3(mat4 m)
| trace of matrix (rotation part)
| sum of the elements on the main diagonal from upper left to the lower right
Parameters:
| *[in]* **m** matrix
Returns:
trace of matrix
.. c:function:: void glm_mat4_quat(mat4 m, versor dest) .. c:function:: void glm_mat4_quat(mat4 m, versor dest)
convert mat4's rotation part to quaternion convert mat4's rotation part to quaternion

View File

@@ -39,7 +39,6 @@ Functions:
#. :c:func:`glm_vec3_zero` #. :c:func:`glm_vec3_zero`
#. :c:func:`glm_vec3_one` #. :c:func:`glm_vec3_one`
#. :c:func:`glm_vec3_dot` #. :c:func:`glm_vec3_dot`
#. :c:func:`glm_vec3_cross`
#. :c:func:`glm_vec3_norm2` #. :c:func:`glm_vec3_norm2`
#. :c:func:`glm_vec3_norm` #. :c:func:`glm_vec3_norm`
#. :c:func:`glm_vec3_add` #. :c:func:`glm_vec3_add`
@@ -65,6 +64,8 @@ Functions:
#. :c:func:`glm_vec3_negate_to` #. :c:func:`glm_vec3_negate_to`
#. :c:func:`glm_vec3_normalize` #. :c:func:`glm_vec3_normalize`
#. :c:func:`glm_vec3_normalize_to` #. :c:func:`glm_vec3_normalize_to`
#. :c:func:`glm_vec3_cross`
#. :c:func:`glm_vec3_crossn`
#. :c:func:`glm_vec3_distance2` #. :c:func:`glm_vec3_distance2`
#. :c:func:`glm_vec3_distance` #. :c:func:`glm_vec3_distance`
#. :c:func:`glm_vec3_angle` #. :c:func:`glm_vec3_angle`
@@ -125,12 +126,21 @@ Functions documentation
.. c:function:: void glm_vec3_cross(vec3 a, vec3 b, vec3 d) .. c:function:: void glm_vec3_cross(vec3 a, vec3 b, vec3 d)
cross product cross product of two vector (RH)
Parameters: Parameters:
| *[in]* **a** source 1 | *[in]* **a** vector 1
| *[in]* **b** source 2 | *[in]* **b** vector 2
| *[out]* **d** destination | *[out]* **dest** destination
.. c:function:: void glm_vec3_crossn(vec3 a, vec3 b, vec3 dest)
cross product of two vector (RH) and normalize the result
Parameters:
| *[in]* **a** vector 1
| *[in]* **b** vector 2
| *[out]* **dest** destination
.. c:function:: float glm_vec3_norm2(vec3 v) .. c:function:: float glm_vec3_norm2(vec3 v)

View File

@@ -44,6 +44,10 @@ CGLM_EXPORT
void void
glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest); glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest);
CGLM_EXPORT
float
glmc_mat3_trace(mat3 m);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat3_quat(mat3 m, versor dest); glmc_mat3_quat(mat3 m, versor dest);

View File

@@ -61,6 +61,14 @@ CGLM_EXPORT
void void
glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest); glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest);
CGLM_EXPORT
float
glmc_mat4_trace(mat4 m);
CGLM_EXPORT
float
glmc_mat4_trace3(mat4 m);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat4_quat(mat4 m, versor dest); glmc_mat4_quat(mat4 m, versor dest);

View File

@@ -42,7 +42,11 @@ glmc_vec3_dot(vec3 a, vec3 b);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec3_cross(vec3 a, vec3 b, vec3 d); glmc_vec3_cross(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_crossn(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
float float

View File

@@ -323,9 +323,7 @@ glm_lookat(vec3 eye,
glm_vec3_sub(center, eye, f); glm_vec3_sub(center, eye, f);
glm_vec3_normalize(f); glm_vec3_normalize(f);
glm_vec3_cross(f, up, s); glm_vec3_crossn(f, up, s);
glm_vec3_normalize(s);
glm_vec3_cross(s, f, u); glm_vec3_cross(s, f, u);
dest[0][0] = s[0]; dest[0][0] = s[0];

View File

@@ -21,6 +21,7 @@
CGLM_INLINE void glm_mat3_transpose_to(mat3 m, mat3 dest); CGLM_INLINE void glm_mat3_transpose_to(mat3 m, mat3 dest);
CGLM_INLINE void glm_mat3_transpose(mat3 m); CGLM_INLINE void glm_mat3_transpose(mat3 m);
CGLM_INLINE void glm_mat3_mulv(mat3 m, vec3 v, vec3 dest); CGLM_INLINE void glm_mat3_mulv(mat3 m, vec3 v, vec3 dest);
CGLM_INLINE float glm_mat3_trace(mat3 m);
CGLM_INLINE void glm_mat3_scale(mat3 m, float s); CGLM_INLINE void glm_mat3_scale(mat3 m, float s);
CGLM_INLINE float glm_mat3_det(mat3 mat); CGLM_INLINE float glm_mat3_det(mat3 mat);
CGLM_INLINE void glm_mat3_inv(mat3 mat, mat3 dest); CGLM_INLINE void glm_mat3_inv(mat3 mat, mat3 dest);
@@ -207,6 +208,18 @@ glm_mat3_mulv(mat3 m, vec3 v, vec3 dest) {
dest[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2]; dest[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2];
} }
/*!
* @brief trace of matrix
*
* sum of the elements on the main diagonal from upper left to the lower right
*
* @param[in] m matrix
*/
CGLM_INLINE
float
glm_mat3_trace(mat3 m) {
return m[0][0] + m[1][1] + m[2][2];
}
/*! /*!
* @brief convert mat3 to quaternion * @brief convert mat3 to quaternion

View File

@@ -29,6 +29,8 @@
CGLM_INLINE void glm_mat4_mulN(mat4 *matrices[], int len, mat4 dest); CGLM_INLINE void glm_mat4_mulN(mat4 *matrices[], int len, mat4 dest);
CGLM_INLINE void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); CGLM_INLINE void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest);
CGLM_INLINE void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest); CGLM_INLINE void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest);
CGLM_INLINE float glm_mat4_trace(mat4 m);
CGLM_INLINE float glm_mat4_trace3(mat4 m);
CGLM_INLINE void glm_mat4_transpose_to(mat4 m, mat4 dest); CGLM_INLINE void glm_mat4_transpose_to(mat4 m, mat4 dest);
CGLM_INLINE void glm_mat4_transpose(mat4 m); CGLM_INLINE void glm_mat4_transpose(mat4 m);
CGLM_INLINE void glm_mat4_scale_p(mat4 m, float s); CGLM_INLINE void glm_mat4_scale_p(mat4 m, float s);
@@ -338,6 +340,32 @@ glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) {
#endif #endif
} }
/*!
* @brief trace of matrix
*
* sum of the elements on the main diagonal from upper left to the lower right
*
* @param[in] m matrix
*/
CGLM_INLINE
float
glm_mat4_trace(mat4 m) {
return m[0][0] + m[1][1] + m[2][2] + m[3][3];
}
/*!
* @brief trace of matrix (rotation part)
*
* sum of the elements on the main diagonal from upper left to the lower right
*
* @param[in] m matrix
*/
CGLM_INLINE
float
glm_mat4_trace3(mat4 m) {
return m[0][0] + m[1][1] + m[2][2];
}
/*! /*!
* @brief convert mat4's rotation part to quaternion * @brief convert mat4's rotation part to quaternion
* *

View File

@@ -33,20 +33,18 @@
#endif #endif
typedef float vec2[2]; typedef float vec2[2];
typedef CGLM_ALIGN_IF(8) float vec3[3]; typedef float vec3[3];
typedef int ivec3[3]; typedef int ivec3[3];
typedef CGLM_ALIGN_IF(16) float vec4[4]; typedef CGLM_ALIGN_IF(16) float vec4[4];
typedef vec4 versor;
typedef vec3 mat3[3];
#ifdef __AVX__ #ifdef __AVX__
typedef CGLM_ALIGN_IF(32) vec3 mat3[3];
typedef CGLM_ALIGN_IF(32) vec4 mat4[4]; typedef CGLM_ALIGN_IF(32) vec4 mat4[4];
#else #else
typedef vec3 mat3[3];
typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; typedef CGLM_ALIGN_IF(16) vec4 mat4[4];
#endif #endif
typedef vec4 versor;
#define GLM_E 2.71828182845904523536028747135266250 /* e */ #define GLM_E 2.71828182845904523536028747135266250 /* e */
#define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */ #define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */
#define GLM_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */ #define GLM_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */

View File

@@ -21,7 +21,6 @@
CGLM_INLINE void glm_vec3_zero(vec3 v); CGLM_INLINE void glm_vec3_zero(vec3 v);
CGLM_INLINE void glm_vec3_one(vec3 v); CGLM_INLINE void glm_vec3_one(vec3 v);
CGLM_INLINE float glm_vec3_dot(vec3 a, vec3 b); CGLM_INLINE float glm_vec3_dot(vec3 a, vec3 b);
CGLM_INLINE void glm_vec3_cross(vec3 a, vec3 b, vec3 d);
CGLM_INLINE float glm_vec3_norm2(vec3 v); CGLM_INLINE float glm_vec3_norm2(vec3 v);
CGLM_INLINE float glm_vec3_norm(vec3 v); CGLM_INLINE float glm_vec3_norm(vec3 v);
CGLM_INLINE void glm_vec3_add(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_add(vec3 a, vec3 b, vec3 dest);
@@ -47,6 +46,8 @@
CGLM_INLINE void glm_vec3_inv_to(vec3 v, vec3 dest); CGLM_INLINE void glm_vec3_inv_to(vec3 v, vec3 dest);
CGLM_INLINE void glm_vec3_normalize(vec3 v); CGLM_INLINE void glm_vec3_normalize(vec3 v);
CGLM_INLINE void glm_vec3_normalize_to(vec3 v, vec3 dest); 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_distance(vec3 a, vec3 b);
CGLM_INLINE float glm_vec3_angle(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(vec3 v, float angle, vec3 axis);
@@ -166,22 +167,6 @@ glm_vec3_dot(vec3 a, vec3 b) {
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
} }
/*!
* @brief vec3 cross product
*
* @param[in] a source 1
* @param[in] b source 2
* @param[out] d destination
*/
CGLM_INLINE
void
glm_vec3_cross(vec3 a, vec3 b, vec3 d) {
/* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */
d[0] = a[1] * b[2] - a[2] * b[1];
d[1] = a[2] * b[0] - a[0] * b[2];
d[2] = a[0] * b[1] - a[1] * b[0];
}
/*! /*!
* @brief norm * norm (magnitude) of vec * @brief norm * norm (magnitude) of vec
* *
@@ -444,7 +429,7 @@ glm_vec3_maxadd(vec3 a, vec3 b, vec3 dest) {
* it applies += operator so dest must be initialized * it applies += operator so dest must be initialized
* *
* @param[in] a vector * @param[in] a vector
* @param[in] s scalar * @param[in] b scalar
* @param[out] dest dest += min(a, b) * @param[out] dest dest += min(a, b)
*/ */
CGLM_INLINE CGLM_INLINE
@@ -521,6 +506,36 @@ glm_vec3_normalize_to(vec3 v, vec3 dest) {
glm_vec3_scale(v, 1.0f / norm, dest); glm_vec3_scale(v, 1.0f / norm, dest);
} }
/*!
* @brief cross product of two vector (RH)
*
* @param[in] a vector 1
* @param[in] b vector 2
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_cross(vec3 a, vec3 b, vec3 dest) {
/* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */
dest[0] = a[1] * b[2] - a[2] * b[1];
dest[1] = a[2] * b[0] - a[0] * b[2];
dest[2] = a[0] * b[1] - a[1] * b[0];
}
/*!
* @brief cross product of two vector (RH) and normalize the result
*
* @param[in] a vector 1
* @param[in] b vector 2
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec3_crossn(vec3 a, vec3 b, vec3 dest) {
glm_vec3_cross(a, b, dest);
glm_vec3_normalize(dest);
}
/*! /*!
* @brief angle betwen two vector * @brief angle betwen two vector
* *

View File

@@ -333,7 +333,7 @@ glm_vec4_subs(vec4 v, float s, vec4 dest) {
* *
* @param a vector1 * @param a vector1
* @param b vector2 * @param b vector2
* @param d dest = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]) * @param dest dest = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3])
*/ */
CGLM_INLINE CGLM_INLINE
void void
@@ -426,7 +426,6 @@ glm_vec4_divs(vec4 v, float s, vec4 dest) {
#endif #endif
} }
/*! /*!
* @brief add two vectors and add result to sum * @brief add two vectors and add result to sum
* *
@@ -553,7 +552,7 @@ glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest) {
* it applies += operator so dest must be initialized * it applies += operator so dest must be initialized
* *
* @param[in] a vector * @param[in] a vector
* @param[in] s scalar * @param[in] b scalar
* @param[out] dest dest += min(a, b) * @param[out] dest dest += min(a, b)
*/ */
CGLM_INLINE CGLM_INLINE

View File

@@ -10,6 +10,6 @@
#define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MAJOR 0
#define CGLM_VERSION_MINOR 5 #define CGLM_VERSION_MINOR 5
#define CGLM_VERSION_PATCH 0 #define CGLM_VERSION_PATCH 1
#endif /* cglm_version_h */ #endif /* cglm_version_h */

View File

@@ -50,6 +50,12 @@ glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest) {
glm_mat3_mulv(m, v, dest); glm_mat3_mulv(m, v, dest);
} }
CGLM_EXPORT
float
glmc_mat3_trace(mat3 m) {
return glm_mat3_trace(m);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat3_quat(mat3 m, versor dest) { glmc_mat3_quat(mat3 m, versor dest) {

View File

@@ -74,6 +74,18 @@ glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest) {
glm_mat4_mulv3(m, v, last, dest); glm_mat4_mulv3(m, v, last, dest);
} }
CGLM_EXPORT
float
glmc_mat4_trace(mat4 m) {
return glm_mat4_trace(m);
}
CGLM_EXPORT
float
glmc_mat4_trace3(mat4 m) {
return glm_mat4_trace3(m);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat4_quat(mat4 m, versor dest) { glmc_mat4_quat(mat4 m, versor dest) {

View File

@@ -40,8 +40,14 @@ glmc_vec3_dot(vec3 a, vec3 b) {
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec3_cross(vec3 a, vec3 b, vec3 d) { glmc_vec3_cross(vec3 a, vec3 b, vec3 dest) {
glm_vec3_cross(a, b, d); glm_vec3_cross(a, b, dest);
}
CGLM_EXPORT
void
glmc_vec3_crossn(vec3 a, vec3 b, vec3 dest) {
glm_vec3_crossn(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT

View File

@@ -24,9 +24,9 @@ test_mat3(void **state) {
for (i = 0; i < m; i++) { for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) { for (j = 0; j < n; j++) {
if (i == j) if (i == j)
assert_true(m3[i][j] == 1.0f); assert_true(glm_eq(m3[i][j], 1.0f));
else else
assert_true(m3[i][j] == 0.0f); assert_true(glm_eq(m3[i][j], 0.0f));
} }
} }

View File

@@ -24,9 +24,9 @@ test_mat4(void **state) {
for (i = 0; i < m; i++) { for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) { for (j = 0; j < n; j++) {
if (i == j) if (i == j)
assert_true(m3[i][j] == 1.0f); assert_true(glm_eq(m3[i][j], 1.0f));
else else
assert_true(m3[i][j] == 0.0f); assert_true(glm_eq(m3[i][j], 0.0f));
} }
} }

View File

@@ -25,7 +25,7 @@ test_quat(void **state) {
/* 0. test identiy quat */ /* 0. test identiy quat */
glm_quat_identity(q4); glm_quat_identity(q4);
assert_true(glm_quat_real(q4) == cosf(glm_rad(0.0f) * 0.5f)); assert_true(glm_eq(glm_quat_real(q4), cosf(glm_rad(0.0f) * 0.5f)));
glm_quat_mat4(q4, rot1); glm_quat_mat4(q4, rot1);
test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009); test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009);
@@ -118,7 +118,7 @@ test_quat(void **state) {
/* 9. test imag, real */ /* 9. test imag, real */
/* 9.1 real */ /* 9.1 real */
assert_true(glm_quat_real(q4) == cosf(glm_rad(-90.0f) * 0.5f)); assert_true(glm_eq(glm_quat_real(q4), cosf(glm_rad(-90.0f) * 0.5f)));
/* 9.1 imag */ /* 9.1 imag */
glm_quat_imag(q4, imag); glm_quat_imag(q4, imag);