Compare commits

..

31 Commits

Author SHA1 Message Date
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
Recep Aslantas
6d6954b208 vec: minnadd and maxadd helpers 2018-11-29 10:50:24 +03:00
Recep Aslantas
4e08b7e335 vec: rename parameter names 2018-11-29 09:55:27 +03:00
Recep Aslantas
aee381d869 vec: deprecate glm_vec_inv and glm_vec4_inv
* because in the current implementation, `glm_vec3_negate` does same thing. It is duplicate.
2018-11-29 09:23:14 +03:00
Recep Aslantas
b4bf8f3537 vec: rename glm_vec_ to glm_vec3_ (continue)
* add missing functions to vec4
* update docs
2018-11-29 09:07:48 +03:00
Recep Aslantas
0b8c63a90e vec: rename glm_vec_ namespace to glm_vec3_ 2018-11-28 23:22:30 +03:00
Recep Aslantas
ef6134263e vec: improve angle between two vector
* because `acosf()` may return NaN if cosine/dot is out of range
2018-11-28 14:48:12 +03:00
Recep Aslantas
9af61d2101 vec: use _negate instead of _flipsign and _inv 2018-11-28 10:50:21 +03:00
Recep Aslantas
463099350a vec: use _negate instead of _flipsign and _inv
* negate is better and common name, flipsign is deprecated now.
2018-11-28 10:28:00 +03:00
Recep Aslantas
89f64f0794 Merge pull request #65 from sinisterchipmunk/fix-versor-alignment
fix versor alignment
2018-11-17 22:36:12 +03:00
Recep Aslantas
d794f17e51 Merge branch 'master' into fix-versor-alignment 2018-11-17 22:32:48 +03:00
Recep Aslantas
a7cdbcec2b now working on v0.5.0 2018-11-17 22:31:51 +03:00
Colin MacKenzie IV
20a2312351 fix versor alignment 2018-11-16 19:25:44 -05:00
Recep Aslantas
08479f38ce Merge pull request #63 from recp/avx
avx: replace binary constants (resolve https://github.com/recp/cglm/issues/62) with hex and fix glm_mul_avx
2018-10-19 09:52:32 +03:00
Recep Aslantas
dadae4b773 avx: fix glm_mul_avx
* use glm_mat4_mul_avx here. because it seems there is no big difference for now.
2018-10-19 09:40:40 +03:00
Recep Aslantas
20360f2296 avx: replace binary constants with hex 2018-10-12 09:05:42 +03:00
Recep Aslantas
aa2b0f2631 code style and minor optimization[s] 2018-09-22 00:10:50 +03:00
Recep Aslantas
280ac72fd8 Merge pull request #61 from hartenfels/master
Replace non-standard M_PI* constants
2018-09-21 23:39:10 +03:00
Recep Aslantas
7405d5e1d0 Update types.h 2018-09-21 23:33:42 +03:00
Carsten Hartenfels
eefafefbae Also add a load of other number constants
These are all missing from standard C, so we might as well define em.

See https://github.com/recp/cglm/pull/61#discussion_r219406859
2018-09-21 20:03:28 +02:00
Carsten Hartenfels
b9021978cb Replace the use of deprecated CGLM_PI* constants 2018-09-21 19:59:23 +02:00
Carsten Hartenfels
3fd12032e6 Clean up pi constants, deprecating the old names
GLM_PI* is now used for the double versions, GLM_PI*f for the float
versions. The CGLM_ prefixed versions are now deprecated, since that
prefix is kinda only used for constants.

See https://github.com/recp/cglm/pull/61#issuecomment-423069770
2018-09-21 07:29:54 +02:00
Carsten Hartenfels
59ee8c1fd2 Use even more precise definitions for pi constants
See https://github.com/recp/cglm/pull/61#issuecomment-422955122
2018-09-21 07:26:55 +02:00
Carsten Hartenfels
b00f2b9ccc Replace M_PI_4 in test_affine with CGLM_PI_4
As in the previous commit, because it's non-standard and depending on
your settings it can fail to compile because of it.
2018-09-19 20:46:37 +02:00
Carsten Hartenfels
d3c50147cb Replace non-standard M_PI* constants with literals
M_PI, M_PI_2 and M_PI_4 aren't part of the C standard. If you put your
gcc into strict standards mode, like `-std=c11`, you won't get these
constants and including cglm.h will fail.

This commit replaces those constants with their literal values. The cast
to a float remains, to keep exactly the same behavior as before.
2018-09-19 20:42:05 +02:00
Recep Aslantas
98da3daf82 identiy helper for arrays (matrix/quaternion)
this helpers makes all array elements identity
2018-09-12 12:44:11 +03:00
Recep Aslantas
2e1790ccf9 Merge pull request #59 from jonathanplatzer/avx
Fix alignment issue when using AVX
2018-07-19 11:38:55 +03:00
Jonathan Platzer
cc5f533fc9 Add macro for automatic alignment of matrices 2018-07-19 10:14:30 +02:00
Jonathan Platzer
2d63d7e0cd Fix alignment issue when using AVX 2018-07-18 12:03:38 +02:00
53 changed files with 1224 additions and 1076 deletions

View File

@@ -16,7 +16,7 @@ Complete documentation: http://cglm.readthedocs.io
#### Note for previous versions: #### Note for previous versions:
- _dup (duplicate) is changed to _copy. For instance `glm_vec_dup -> glm_vec_copy` - _dup (duplicate) is changed to _copy. For instance `glm_vec_dup -> glm_vec3_copy`
- OpenGL related functions are dropped to make this lib platform/third-party independent - OpenGL related functions are dropped to make this lib platform/third-party independent
- make sure you have latest version and feel free to report bugs, troubles - make sure you have latest version and feel free to report bugs, troubles
- **[bugfix]** euler angles was implemented in reverse order (extrinsic) it was fixed, now they are intrinsic. Make sure that - **[bugfix]** euler angles was implemented in reverse order (extrinsic) it was fixed, now they are intrinsic. Make sure that
@@ -24,6 +24,7 @@ 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
#### 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 +82,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 +124,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)
@@ -201,15 +170,15 @@ If you want to use inline versions of funcstions then; include main header
``` ```
the header will include all headers. Then call func you want e.g. rotate vector by axis: the header will include all headers. Then call func you want e.g. rotate vector by axis:
```C ```C
glm_vec_rotate(v1, glm_rad(45), (vec3){1.0f, 0.0f, 0.0f}); glm_vec3_rotate(v1, glm_rad(45), (vec3){1.0f, 0.0f, 0.0f});
``` ```
some functions are overloaded :) e.g you can normalize vector: some functions are overloaded :) e.g you can normalize vector:
```C ```C
glm_vec_normalize(vec); glm_vec3_normalize(vec);
``` ```
this will normalize vec and store normalized vector into `vec` but if you will store normalized vector into another vector do this: this will normalize vec and store normalized vector into `vec` but if you will store normalized vector into another vector do this:
```C ```C
glm_vec_normalize_to(vec, result); glm_vec3_normalize_to(vec, result);
``` ```
like this function you may see `_to` postfix, this functions store results to another variables and save temp memory like this function you may see `_to` postfix, this functions store results to another variables and save temp memory
@@ -220,7 +189,7 @@ to call pre-compiled versions include header with `c` postfix, c means call. Pre
``` ```
this header will include all headers with c postfix. You need to call functions with c posfix: this header will include all headers with c postfix. You need to call functions with c posfix:
```C ```C
glmc_vec_normalize(vec); glmc_vec3_normalize(vec);
``` ```
Function usage and parameters are documented inside related headers. You may see same parameter passed twice in some examples like this: Function usage and parameters are documented inside related headers. You may see same parameter passed twice in some examples like this:
@@ -284,3 +253,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.4.8], [info@recp.me]) AC_INIT([cglm], [0.5.0], [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

@@ -5,14 +5,14 @@ Some functions may exist twice,
once for their namespace and once for global namespace once for their namespace and once for global namespace
to make easier to write very common functions to make easier to write very common functions
For instance, in general we use :code:`glm_vec_dot` to get dot product For instance, in general we use :code:`glm_vec3_dot` to get dot product
of two **vec3**. Now we can also do this with :code:`glm_dot`, of two **vec3**. Now we can also do this with :code:`glm_dot`,
same for *_cross* and so on... same for *_cross* and so on...
The original function stays where it is, the function in global namespace The original function stays where it is, the function in global namespace
of same name is just an alias, so there is no call version of those functions. of same name is just an alias, so there is no call version of those functions.
e.g there is no func like :code:`glmc_dot` because *glm_dot* is just alias for e.g there is no func like :code:`glmc_dot` because *glm_dot* is just alias for
:code:`glm_vec_dot` :code:`glm_vec3_dot`
By including **cglm/cglm.h** header you will include all inline version By including **cglm/cglm.h** header you will include all inline version
of functions. Since functions in this header[s] are inline you don't need to of functions. Since functions in this header[s] are inline you don't need to

View File

@@ -9,7 +9,7 @@ There are many convenient functions for camera. For instance :c:func:`glm_look`
is just wrapper for :c:func:`glm_lookat`. Sometimes you only have direction is just wrapper for :c:func:`glm_lookat`. Sometimes you only have direction
instead of target, so that makes easy to build view matrix using direction. instead of target, so that makes easy to build view matrix using direction.
There is also :c:func:`glm_look_anyup` function which can help build view matrix There is also :c:func:`glm_look_anyup` function which can help build view matrix
without providing UP axis. It uses :c:func:`glm_vec_ortho` to get a UP axis and without providing UP axis. It uses :c:func:`glm_vec3_ortho` to get a UP axis and
builds view matrix. builds view matrix.
You can also *_default* versions of ortho and perspective to build projection You can also *_default* versions of ortho and perspective to build projection

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.4.8' version = u'0.5.0'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = u'0.4.8' release = u'0.5.0'
# 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

@@ -127,7 +127,7 @@ Functions documentation
.. code-block:: c .. code-block:: c
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
glm_vec_center(corners[i], corners[i + 4], centerCorners[i]); glm_vec3_center(corners[i], corners[i + 4], centerCorners[i]);
} }
corners[i + 4] is far of corners[i] point. corners[i + 4] is far of corners[i] point.

View File

@@ -20,6 +20,7 @@ Functions:
1. :c:func:`glm_mat3_copy` 1. :c:func:`glm_mat3_copy`
#. :c:func:`glm_mat3_identity` #. :c:func:`glm_mat3_identity`
#. :c:func:`glm_mat3_identity_array`
#. :c:func:`glm_mat3_mul` #. :c:func:`glm_mat3_mul`
#. :c:func:`glm_mat3_transpose_to` #. :c:func:`glm_mat3_transpose_to`
#. :c:func:`glm_mat3_transpose` #. :c:func:`glm_mat3_transpose`
@@ -49,6 +50,14 @@ Functions documentation
Parameters: Parameters:
| *[out]* **mat** matrix | *[out]* **mat** matrix
.. c:function:: void glm_mat3_identity_array(mat3 * __restrict mat, size_t count)
make given matrix array's each element identity matrix
Parameters:
| *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled)
| *[in]* **count** count of matrices
.. c:function:: void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest) .. c:function:: void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest)
multiply m1 and m2 to dest multiply m1 and m2 to dest

View File

@@ -25,6 +25,7 @@ Functions:
1. :c:func:`glm_mat4_ucopy` 1. :c:func:`glm_mat4_ucopy`
#. :c:func:`glm_mat4_copy` #. :c:func:`glm_mat4_copy`
#. :c:func:`glm_mat4_identity` #. :c:func:`glm_mat4_identity`
#. :c:func:`glm_mat4_identity_array`
#. :c:func:`glm_mat4_pick3` #. :c:func:`glm_mat4_pick3`
#. :c:func:`glm_mat4_pick3t` #. :c:func:`glm_mat4_pick3t`
#. :c:func:`glm_mat4_ins3` #. :c:func:`glm_mat4_ins3`
@@ -69,6 +70,14 @@ Functions documentation
Parameters: Parameters:
| *[out]* **mat** matrix | *[out]* **mat** matrix
.. c:function:: void glm_mat4_identity_array(mat4 * __restrict mat, size_t count)
make given matrix array's each element identity matrix
Parameters:
| *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled)
| *[in]* **count** count of matrices
.. c:function:: void glm_mat4_pick3(mat4 mat, mat3 dest) .. c:function:: void glm_mat4_pick3(mat4 mat, mat3 dest)
copy upper-left of mat4 to mat3 copy upper-left of mat4 to mat3

View File

@@ -27,6 +27,7 @@ Macros:
Functions: Functions:
1. :c:func:`glm_quat_identity` 1. :c:func:`glm_quat_identity`
#. :c:func:`glm_quat_identity_array`
#. :c:func:`glm_quat_init` #. :c:func:`glm_quat_init`
#. :c:func:`glm_quat` #. :c:func:`glm_quat`
#. :c:func:`glm_quatv` #. :c:func:`glm_quatv`
@@ -70,6 +71,14 @@ Functions documentation
Parameters: Parameters:
| *[in, out]* **q** quaternion | *[in, out]* **q** quaternion
.. c:function:: void glm_quat_identity_array(versor * __restrict q, size_t count)
| make given quaternion array's each element identity quaternion
Parameters:
| *[in, out]* **q** quat array (must be aligned (16) if alignment is not disabled)
| *[in]* **count** count of quaternions
.. c:function:: void glm_quat_init(versor q, float x, float y, float z, float w) .. c:function:: void glm_quat_init(versor q, float x, float y, float z, float w)
| inits quaternion with given values | inits quaternion with given values

View File

@@ -62,7 +62,7 @@ Wrong Results:
Again, you may used wrong function. Again, you may used wrong function.
For instance if you use **glm_normalize()** or **glm_vec_normalize()** for **vec4**, For instance if you use **glm_normalize()** or **glm_vec3_normalize()** for **vec4**,
it will assume that passed param is **vec3** and will normalize it for **vec3**. it will assume that passed param is **vec3** and will normalize it for **vec3**.
Since you need to **vec4** to be normalized in your case, you will get wrong results. Since you need to **vec4** to be normalized in your case, you will get wrong results.

View File

@@ -14,25 +14,25 @@ Table of contents (click to go):
Functions: Functions:
1. :c:func:`glm_vec_mulv` 1. :c:func:`glm_vec3_mulv`
#. :c:func:`glm_vec_broadcast` #. :c:func:`glm_vec3_broadcast`
#. :c:func:`glm_vec_eq` #. :c:func:`glm_vec3_eq`
#. :c:func:`glm_vec_eq_eps` #. :c:func:`glm_vec3_eq_eps`
#. :c:func:`glm_vec_eq_all` #. :c:func:`glm_vec3_eq_all`
#. :c:func:`glm_vec_eqv` #. :c:func:`glm_vec3_eqv`
#. :c:func:`glm_vec_eqv_eps` #. :c:func:`glm_vec3_eqv_eps`
#. :c:func:`glm_vec_max` #. :c:func:`glm_vec3_max`
#. :c:func:`glm_vec_min` #. :c:func:`glm_vec3_min`
#. :c:func:`glm_vec_isnan` #. :c:func:`glm_vec3_isnan`
#. :c:func:`glm_vec_isinf` #. :c:func:`glm_vec3_isinf`
#. :c:func:`glm_vec_isvalid` #. :c:func:`glm_vec3_isvalid`
#. :c:func:`glm_vec_sign` #. :c:func:`glm_vec3_sign`
#. :c:func:`glm_vec_sqrt` #. :c:func:`glm_vec3_sqrt`
Functions documentation Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
.. c:function:: void glm_vec_mulv(vec3 a, vec3 b, vec3 d) .. c:function:: void glm_vec3_mulv(vec3 a, vec3 b, vec3 d)
multiplies individual items multiplies individual items
@@ -41,7 +41,7 @@ Functions documentation
| *[in]* **b** vec2 | *[in]* **b** vec2
| *[out]* **d** destination (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]) | *[out]* **d** destination (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2])
.. c:function:: void glm_vec_broadcast(float val, vec3 d) .. c:function:: void glm_vec3_broadcast(float val, vec3 d)
fill a vector with specified value fill a vector with specified value
@@ -49,7 +49,7 @@ Functions documentation
| *[in]* **val** value | *[in]* **val** value
| *[out]* **dest** destination | *[out]* **dest** destination
.. c:function:: bool glm_vec_eq(vec3 v, float val) .. c:function:: bool glm_vec3_eq(vec3 v, float val)
check if vector is equal to value (without epsilon) check if vector is equal to value (without epsilon)
@@ -57,7 +57,7 @@ Functions documentation
| *[in]* **v** vector | *[in]* **v** vector
| *[in]* **val** value | *[in]* **val** value
.. c:function:: bool glm_vec_eq_eps(vec3 v, float val) .. c:function:: bool glm_vec3_eq_eps(vec3 v, float val)
check if vector is equal to value (with epsilon) check if vector is equal to value (with epsilon)
@@ -65,14 +65,14 @@ Functions documentation
| *[in]* **v** vector | *[in]* **v** vector
| *[in]* **val** value | *[in]* **val** value
.. c:function:: bool glm_vec_eq_all(vec3 v) .. c:function:: bool glm_vec3_eq_all(vec3 v)
check if vectors members are equal (without epsilon) check if vectors members are equal (without epsilon)
Parameters: Parameters:
| *[in]* **v** vector | *[in]* **v** vector
.. c:function:: bool glm_vec_eqv(vec3 v1, vec3 v2) .. c:function:: bool glm_vec3_eqv(vec3 v1, vec3 v2)
check if vector is equal to another (without epsilon) vector check if vector is equal to another (without epsilon) vector
@@ -80,7 +80,7 @@ Functions documentation
| *[in]* **vec** vector 1 | *[in]* **vec** vector 1
| *[in]* **vec** vector 2 | *[in]* **vec** vector 2
.. c:function:: bool glm_vec_eqv_eps(vec3 v1, vec3 v2) .. c:function:: bool glm_vec3_eqv_eps(vec3 v1, vec3 v2)
check if vector is equal to another (with epsilon) check if vector is equal to another (with epsilon)
@@ -88,21 +88,21 @@ Functions documentation
| *[in]* **v1** vector1 | *[in]* **v1** vector1
| *[in]* **v2** vector2 | *[in]* **v2** vector2
.. c:function:: float glm_vec_max(vec3 v) .. c:function:: float glm_vec3_max(vec3 v)
max value of vector max value of vector
Parameters: Parameters:
| *[in]* **v** vector | *[in]* **v** vector
.. c:function:: float glm_vec_min(vec3 v) .. c:function:: float glm_vec3_min(vec3 v)
min value of vector min value of vector
Parameters: Parameters:
| *[in]* **v** vector | *[in]* **v** vector
.. c:function:: bool glm_vec_isnan(vec3 v) .. c:function:: bool glm_vec3_isnan(vec3 v)
| check if one of items is NaN (not a number) | check if one of items is NaN (not a number)
| you should only use this in DEBUG mode or very critical asserts | you should only use this in DEBUG mode or very critical asserts
@@ -110,7 +110,7 @@ Functions documentation
Parameters: Parameters:
| *[in]* **v** vector | *[in]* **v** vector
.. c:function:: bool glm_vec_isinf(vec3 v) .. c:function:: bool glm_vec3_isinf(vec3 v)
| check if one of items is INFINITY | check if one of items is INFINITY
| you should only use this in DEBUG mode or very critical asserts | you should only use this in DEBUG mode or very critical asserts
@@ -118,7 +118,7 @@ Functions documentation
Parameters: Parameters:
| *[in]* **v** vector | *[in]* **v** vector
.. c:function:: bool glm_vec_isvalid(vec3 v) .. c:function:: bool glm_vec3_isvalid(vec3 v)
| check if all items are valid number | check if all items are valid number
| you should only use this in DEBUG mode or very critical asserts | you should only use this in DEBUG mode or very critical asserts
@@ -126,7 +126,7 @@ Functions documentation
Parameters: Parameters:
| *[in]* **v** vector | *[in]* **v** vector
.. c:function:: void glm_vec_sign(vec3 v, vec3 dest) .. c:function:: void glm_vec3_sign(vec3 v, vec3 dest)
get sign of 32 bit float as +1, -1, 0 get sign of 32 bit float as +1, -1, 0
@@ -134,7 +134,7 @@ Functions documentation
| *[in]* **v** vector | *[in]* **v** vector
| *[out]* **dest** sign vector (only keeps signs as -1, 0, -1) | *[out]* **dest** sign vector (only keeps signs as -1, 0, -1)
.. c:function:: void glm_vec_sqrt(vec3 v, vec3 dest) .. c:function:: void glm_vec3_sqrt(vec3 v, vec3 dest)
square root of each vector item square root of each vector item

View File

@@ -5,9 +5,14 @@ vec3
Header: cglm/vec3.h Header: cglm/vec3.h
**Important:** *cglm* was used **glm_vec_** namespace for vec3 functions until
**v0.5.0**, since **v0.5.0** cglm uses **glm_vec3_** namespace for vec3.
Also `glm_vec3_flipsign` has been renamed to `glm_vec3_negate`
We mostly use vectors in graphics math, to make writing code faster We mostly use vectors in graphics math, to make writing code faster
and easy to read, some *vec3* functions are aliased in global namespace. and easy to read, some *vec3* functions are aliased in global namespace.
For instance :c:func:`glm_dot` is alias of :c:func:`glm_vec_dot`, For instance :c:func:`glm_dot` is alias of :c:func:`glm_vec3_dot`,
alias means inline wrapper here. There is no call verison of alias functions alias means inline wrapper here. There is no call verison of alias functions
There are also functions for rotating *vec3* vector. **_m4**, **_m3** prefixes There are also functions for rotating *vec3* vector. **_m4**, **_m3** prefixes
@@ -18,7 +23,7 @@ Table of contents (click to go):
Macros: Macros:
1. glm_vec_dup(v, dest) 1. glm_vec3_dup(v, dest)
#. GLM_VEC3_ONE_INIT #. GLM_VEC3_ONE_INIT
#. GLM_VEC3_ZERO_INIT #. GLM_VEC3_ZERO_INIT
#. GLM_VEC3_ONE #. GLM_VEC3_ONE
@@ -30,45 +35,49 @@ Macros:
Functions: Functions:
1. :c:func:`glm_vec3` 1. :c:func:`glm_vec3`
#. :c:func:`glm_vec_copy` #. :c:func:`glm_vec3_copy`
#. :c:func:`glm_vec_zero` #. :c:func:`glm_vec3_zero`
#. :c:func:`glm_vec_one` #. :c:func:`glm_vec3_one`
#. :c:func:`glm_vec_dot` #. :c:func:`glm_vec3_dot`
#. :c:func:`glm_vec_cross` #. :c:func:`glm_vec3_cross`
#. :c:func:`glm_vec_norm2` #. :c:func:`glm_vec3_norm2`
#. :c:func:`glm_vec_norm` #. :c:func:`glm_vec3_norm`
#. :c:func:`glm_vec_add` #. :c:func:`glm_vec3_add`
#. :c:func:`glm_vec_adds` #. :c:func:`glm_vec3_adds`
#. :c:func:`glm_vec_sub` #. :c:func:`glm_vec3_sub`
#. :c:func:`glm_vec_subs` #. :c:func:`glm_vec3_subs`
#. :c:func:`glm_vec_mul` #. :c:func:`glm_vec3_mul`
#. :c:func:`glm_vec_scale` #. :c:func:`glm_vec3_scale`
#. :c:func:`glm_vec_scale_as` #. :c:func:`glm_vec3_scale_as`
#. :c:func:`glm_vec_div` #. :c:func:`glm_vec3_div`
#. :c:func:`glm_vec_divs` #. :c:func:`glm_vec3_divs`
#. :c:func:`glm_vec_addadd` #. :c:func:`glm_vec3_addadd`
#. :c:func:`glm_vec_subadd` #. :c:func:`glm_vec3_subadd`
#. :c:func:`glm_vec_muladd` #. :c:func:`glm_vec3_muladd`
#. :c:func:`glm_vec_muladds` #. :c:func:`glm_vec3_muladds`
#. :c:func:`glm_vec_flipsign` #. :c:func:`glm_vec3_maxadd`
#. :c:func:`glm_vec_flipsign_to` #. :c:func:`glm_vec3_minadd`
#. :c:func:`glm_vec_inv` #. :c:func:`glm_vec3_flipsign`
#. :c:func:`glm_vec_inv_to` #. :c:func:`glm_vec3_flipsign_to`
#. :c:func:`glm_vec_normalize` #. :c:func:`glm_vec3_inv`
#. :c:func:`glm_vec_normalize_to` #. :c:func:`glm_vec3_inv_to`
#. :c:func:`glm_vec_distance2` #. :c:func:`glm_vec3_negate`
#. :c:func:`glm_vec_distance` #. :c:func:`glm_vec3_negate_to`
#. :c:func:`glm_vec_angle` #. :c:func:`glm_vec3_normalize`
#. :c:func:`glm_vec_rotate` #. :c:func:`glm_vec3_normalize_to`
#. :c:func:`glm_vec_rotate_m4` #. :c:func:`glm_vec3_distance2`
#. :c:func:`glm_vec_rotate_m3` #. :c:func:`glm_vec3_distance`
#. :c:func:`glm_vec_proj` #. :c:func:`glm_vec3_angle`
#. :c:func:`glm_vec_center` #. :c:func:`glm_vec3_rotate`
#. :c:func:`glm_vec_maxv` #. :c:func:`glm_vec3_rotate_m4`
#. :c:func:`glm_vec_minv` #. :c:func:`glm_vec3_rotate_m3`
#. :c:func:`glm_vec_ortho` #. :c:func:`glm_vec3_proj`
#. :c:func:`glm_vec_clamp` #. :c:func:`glm_vec3_center`
#. :c:func:`glm_vec_lerp` #. :c:func:`glm_vec3_maxv`
#. :c:func:`glm_vec3_minv`
#. :c:func:`glm_vec3_ortho`
#. :c:func:`glm_vec3_clamp`
#. :c:func:`glm_vec3_lerp`
Functions documentation Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
@@ -81,7 +90,7 @@ Functions documentation
| *[in]* **v4** vector4 | *[in]* **v4** vector4
| *[out]* **dest** destination | *[out]* **dest** destination
.. c:function:: void glm_vec_copy(vec3 a, vec3 dest) .. c:function:: void glm_vec3_copy(vec3 a, vec3 dest)
copy all members of [a] to [dest] copy all members of [a] to [dest]
@@ -89,21 +98,21 @@ Functions documentation
| *[in]* **a** source | *[in]* **a** source
| *[out]* **dest** destination | *[out]* **dest** destination
.. c:function:: void glm_vec_zero(vec3 v) .. c:function:: void glm_vec3_zero(vec3 v)
makes all members 0.0f (zero) makes all members 0.0f (zero)
Parameters: Parameters:
| *[in, out]* **v** vector | *[in, out]* **v** vector
.. c:function:: void glm_vec_one(vec3 v) .. c:function:: void glm_vec3_one(vec3 v)
makes all members 1.0f (one) makes all members 1.0f (one)
Parameters: Parameters:
| *[in, out]* **v** vector | *[in, out]* **v** vector
.. c:function:: float glm_vec_dot(vec3 a, vec3 b) .. c:function:: float glm_vec3_dot(vec3 a, vec3 b)
dot product of vec3 dot product of vec3
@@ -114,7 +123,7 @@ Functions documentation
Returns: Returns:
dot product dot product
.. c:function:: void glm_vec_cross(vec3 a, vec3 b, vec3 d) .. c:function:: void glm_vec3_cross(vec3 a, vec3 b, vec3 d)
cross product cross product
@@ -123,7 +132,7 @@ Functions documentation
| *[in]* **b** source 2 | *[in]* **b** source 2
| *[out]* **d** destination | *[out]* **d** destination
.. c:function:: float glm_vec_norm2(vec3 v) .. c:function:: float glm_vec3_norm2(vec3 v)
norm * norm (magnitude) of vector norm * norm (magnitude) of vector
@@ -137,14 +146,14 @@ Functions documentation
Returns: Returns:
square of norm / magnitude square of norm / magnitude
.. c:function:: float glm_vec_norm(vec3 vec) .. c:function:: float glm_vec3_norm(vec3 vec)
norm (magnitude) of vec3 norm (magnitude) of vec3
Parameters: Parameters:
| *[in]* **vec** vector | *[in]* **vec** vector
.. c:function:: void glm_vec_add(vec3 a, vec3 b, vec3 dest) .. c:function:: void glm_vec3_add(vec3 a, vec3 b, vec3 dest)
add a vector to b vector store result in dest add a vector to b vector store result in dest
@@ -153,7 +162,7 @@ Functions documentation
| *[in]* **b** vector2 | *[in]* **b** vector2
| *[out]* **dest** destination vector | *[out]* **dest** destination vector
.. c:function:: void glm_vec_adds(vec3 a, float s, vec3 dest) .. c:function:: void glm_vec3_adds(vec3 a, float s, vec3 dest)
add scalar to v vector store result in dest (d = v + vec(s)) add scalar to v vector store result in dest (d = v + vec(s))
@@ -162,7 +171,7 @@ Functions documentation
| *[in]* **s** scalar | *[in]* **s** scalar
| *[out]* **dest** destination vector | *[out]* **dest** destination vector
.. c:function:: void glm_vec_sub(vec3 v1, vec3 v2, vec3 dest) .. c:function:: void glm_vec3_sub(vec3 v1, vec3 v2, vec3 dest)
subtract b vector from a vector store result in dest (d = v1 - v2) subtract b vector from a vector store result in dest (d = v1 - v2)
@@ -171,7 +180,7 @@ Functions documentation
| *[in]* **b** vector2 | *[in]* **b** vector2
| *[out]* **dest** destination vector | *[out]* **dest** destination vector
.. c:function:: void glm_vec_subs(vec3 v, float s, vec3 dest) .. c:function:: void glm_vec3_subs(vec3 v, float s, vec3 dest)
subtract scalar from v vector store result in dest (d = v - vec(s)) subtract scalar from v vector store result in dest (d = v - vec(s))
@@ -180,7 +189,7 @@ Functions documentation
| *[in]* **s** scalar | *[in]* **s** scalar
| *[out]* **dest** destination vector | *[out]* **dest** destination vector
.. c:function:: void glm_vec_mul(vec3 a, vec3 b, vec3 d) .. c:function:: void glm_vec3_mul(vec3 a, vec3 b, vec3 d)
multiply two vector (component-wise multiplication) multiply two vector (component-wise multiplication)
@@ -189,7 +198,7 @@ Functions documentation
| *[in]* **b** scalar | *[in]* **b** scalar
| *[out]* **d** result = (a[0] * b[0], a[1] * b[1], a[2] * b[2]) | *[out]* **d** result = (a[0] * b[0], a[1] * b[1], a[2] * b[2])
.. c:function:: void glm_vec_scale(vec3 v, float s, vec3 dest) .. c:function:: void glm_vec3_scale(vec3 v, float s, vec3 dest)
multiply/scale vec3 vector with scalar: result = v * s multiply/scale vec3 vector with scalar: result = v * s
@@ -199,7 +208,7 @@ Functions documentation
| *[in]* **s** scalar | *[in]* **s** scalar
| *[out]* **dest** destination vector | *[out]* **dest** destination vector
.. c:function:: void glm_vec_scale_as(vec3 v, float s, vec3 dest) .. c:function:: void glm_vec3_scale_as(vec3 v, float s, vec3 dest)
make vec3 vector scale as specified: result = unit(v) * s make vec3 vector scale as specified: result = unit(v) * s
@@ -208,7 +217,7 @@ Functions documentation
| *[in]* **s** scalar | *[in]* **s** scalar
| *[out]* **dest** destination vector | *[out]* **dest** destination vector
.. c:function:: void glm_vec_div(vec3 a, vec3 b, vec3 dest) .. c:function:: void glm_vec3_div(vec3 a, vec3 b, vec3 dest)
div vector with another component-wise division: d = a / b div vector with another component-wise division: d = a / b
@@ -217,7 +226,7 @@ Functions documentation
| *[in]* **b** vector 2 | *[in]* **b** vector 2
| *[out]* **dest** result = (a[0] / b[0], a[1] / b[1], a[2] / b[2]) | *[out]* **dest** result = (a[0] / b[0], a[1] / b[1], a[2] / b[2])
.. c:function:: void glm_vec_divs(vec3 v, float s, vec3 dest) .. c:function:: void glm_vec3_divs(vec3 v, float s, vec3 dest)
div vector with scalar: d = v / s div vector with scalar: d = v / s
@@ -226,7 +235,7 @@ Functions documentation
| *[in]* **s** scalar | *[in]* **s** scalar
| *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s]) | *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s])
.. c:function:: void glm_vec_addadd(vec3 a, vec3 b, vec3 dest) .. c:function:: void glm_vec3_addadd(vec3 a, vec3 b, vec3 dest)
| add two vectors and add result to sum | add two vectors and add result to sum
| it applies += operator so dest must be initialized | it applies += operator so dest must be initialized
@@ -236,7 +245,7 @@ Functions documentation
| *[in]* **b** vector 2 | *[in]* **b** vector 2
| *[out]* **dest** dest += (a + b) | *[out]* **dest** dest += (a + b)
.. c:function:: void glm_vec_subadd(vec3 a, vec3 b, vec3 dest) .. c:function:: void glm_vec3_subadd(vec3 a, vec3 b, vec3 dest)
| sub two vectors and add result to sum | sub two vectors and add result to sum
| it applies += operator so dest must be initialized | it applies += operator so dest must be initialized
@@ -246,7 +255,7 @@ Functions documentation
| *[in]* **b** vector 2 | *[in]* **b** vector 2
| *[out]* **dest** dest += (a - b) | *[out]* **dest** dest += (a - b)
.. c:function:: void glm_vec_muladd(vec3 a, vec3 b, vec3 dest) .. c:function:: void glm_vec3_muladd(vec3 a, vec3 b, vec3 dest)
| mul two vectors and add result to sum | mul two vectors and add result to sum
| it applies += operator so dest must be initialized | it applies += operator so dest must be initialized
@@ -256,7 +265,7 @@ Functions documentation
| *[in]* **b** vector 2 | *[in]* **b** vector 2
| *[out]* **dest** dest += (a * b) | *[out]* **dest** dest += (a * b)
.. c:function:: void glm_vec_muladds(vec3 a, float s, vec3 dest) .. c:function:: void glm_vec3_muladds(vec3 a, float s, vec3 dest)
| mul vector with scalar and add result to sum | mul vector with scalar and add result to sum
| it applies += operator so dest must be initialized | it applies += operator so dest must be initialized
@@ -266,44 +275,87 @@ Functions documentation
| *[in]* **s** scalar | *[in]* **s** scalar
| *[out]* **dest** dest += (a * b) | *[out]* **dest** dest += (a * b)
.. c:function:: void glm_vec_flipsign(vec3 v) .. c:function:: void glm_vec3_maxadd(vec3 a, vec3 b, vec3 dest)
flip sign of all vec3 members | add max of two vector to result/dest
| it applies += operator so dest must be initialized
Parameters:
| *[in]* **a** vector 1
| *[in]* **b** vector 2
| *[out]* **dest** dest += (a * b)
.. c:function:: void glm_vec3_minadd(vec3 a, vec3 b, vec3 dest)
| add min of two vector to result/dest
| it applies += operator so dest must be initialized
Parameters:
| *[in]* **a** vector 1
| *[in]* **b** vector 2
| *[out]* **dest** dest += (a * b)
.. c:function:: void glm_vec3_flipsign(vec3 v)
**DEPRACATED!**
use :c:func:`glm_vec3_negate`
Parameters: Parameters:
| *[in, out]* **v** vector | *[in, out]* **v** vector
.. c:function:: void glm_vec_flipsign_to(vec3 v, vec3 dest) .. c:function:: void glm_vec3_flipsign_to(vec3 v, vec3 dest)
flip sign of all vec3 members and store result in dest **DEPRACATED!**
use :c:func:`glm_vec3_negate_to`
Parameters: Parameters:
| *[in]* **v** vector | *[in]* **v** vector
| *[out]* **dest** negated vector | *[out]* **dest** negated vector
.. c:function:: void glm_vec_inv(vec3 v) .. c:function:: void glm_vec3_inv(vec3 v)
make vector as inverse/opposite of itself **DEPRACATED!**
use :c:func:`glm_vec3_negate`
Parameters: Parameters:
| *[in, out]* **v** vector | *[in, out]* **v** vector
.. c:function:: void glm_vec_inv_to(vec3 v, vec3 dest) .. c:function:: void glm_vec3_inv_to(vec3 v, vec3 dest)
inverse/opposite vector **DEPRACATED!**
use :c:func:`glm_vec3_negate_to`
Parameters: Parameters:
| *[in]* **v** source | *[in]* **v** source
| *[out]* **dest** destination | *[out]* **dest** destination
.. c:function:: void glm_vec_normalize(vec3 v) .. c:function:: void glm_vec3_negate(vec3 v)
negate vector components
Parameters:
| *[in, out]* **v** vector
.. c:function:: void glm_vec3_negate_to(vec3 v, vec3 dest)
negate vector components and store result in dest
Parameters:
| *[in]* **v** vector
| *[out]* **dest** negated vector
.. c:function:: void glm_vec3_normalize(vec3 v)
normalize vec3 and store result in same vec normalize vec3 and store result in same vec
Parameters: Parameters:
| *[in, out]* **v** vector | *[in, out]* **v** vector
.. c:function:: void glm_vec_normalize_to(vec3 vec, vec3 dest) .. c:function:: void glm_vec3_normalize_to(vec3 vec, vec3 dest)
normalize vec3 to dest normalize vec3 to dest
@@ -311,7 +363,7 @@ Functions documentation
| *[in]* **vec** source | *[in]* **vec** source
| *[out]* **dest** destination | *[out]* **dest** destination
.. c:function:: float glm_vec_angle(vec3 v1, vec3 v2) .. c:function:: float glm_vec3_angle(vec3 v1, vec3 v2)
angle betwen two vector angle betwen two vector
@@ -322,7 +374,7 @@ Functions documentation
Return: Return:
| angle as radians | angle as radians
.. c:function:: void glm_vec_rotate(vec3 v, float angle, vec3 axis) .. c:function:: void glm_vec3_rotate(vec3 v, float angle, vec3 axis)
rotate vec3 around axis by angle using Rodrigues' rotation formula rotate vec3 around axis by angle using Rodrigues' rotation formula
@@ -331,7 +383,7 @@ Functions documentation
| *[in]* **axis** axis vector (will be normalized) | *[in]* **axis** axis vector (will be normalized)
| *[out]* **angle** angle (radians) | *[out]* **angle** angle (radians)
.. c:function:: void glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) .. c:function:: void glm_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest)
apply rotation matrix to vector apply rotation matrix to vector
@@ -340,7 +392,7 @@ Functions documentation
| *[in]* **v** vector | *[in]* **v** vector
| *[out]* **dest** rotated vector | *[out]* **dest** rotated vector
.. c:function:: void glm_vec_rotate_m3(mat3 m, vec3 v, vec3 dest) .. c:function:: void glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest)
apply rotation matrix to vector apply rotation matrix to vector
@@ -349,7 +401,7 @@ Functions documentation
| *[in]* **v** vector | *[in]* **v** vector
| *[out]* **dest** rotated vector | *[out]* **dest** rotated vector
.. c:function:: void glm_vec_proj(vec3 a, vec3 b, vec3 dest) .. c:function:: void glm_vec3_proj(vec3 a, vec3 b, vec3 dest)
project a vector onto b vector project a vector onto b vector
@@ -358,7 +410,7 @@ Functions documentation
| *[in]* **b** vector2 | *[in]* **b** vector2
| *[out]* **dest** projected vector | *[out]* **dest** projected vector
.. c:function:: void glm_vec_center(vec3 v1, vec3 v2, vec3 dest) .. c:function:: void glm_vec3_center(vec3 v1, vec3 v2, vec3 dest)
find center point of two vector find center point of two vector
@@ -367,7 +419,7 @@ Functions documentation
| *[in]* **v2** vector2 | *[in]* **v2** vector2
| *[out]* **dest** center point | *[out]* **dest** center point
.. c:function:: float glm_vec_distance2(vec3 v1, vec3 v2) .. c:function:: float glm_vec3_distance2(vec3 v1, vec3 v2)
squared distance between two vectors squared distance between two vectors
@@ -378,7 +430,7 @@ Functions documentation
Returns: Returns:
| squared distance (distance * distance) | squared distance (distance * distance)
.. c:function:: float glm_vec_distance(vec3 v1, vec3 v2) .. c:function:: float glm_vec3_distance(vec3 v1, vec3 v2)
distance between two vectors distance between two vectors
@@ -389,7 +441,7 @@ Functions documentation
Returns: Returns:
| distance | distance
.. c:function:: void glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest) .. c:function:: void glm_vec3_maxv(vec3 v1, vec3 v2, vec3 dest)
max values of vectors max values of vectors
@@ -398,7 +450,7 @@ Functions documentation
| *[in]* **v2** vector2 | *[in]* **v2** vector2
| *[out]* **dest** destination | *[out]* **dest** destination
.. c:function:: void glm_vec_minv(vec3 v1, vec3 v2, vec3 dest) .. c:function:: void glm_vec3_minv(vec3 v1, vec3 v2, vec3 dest)
min values of vectors min values of vectors
@@ -407,7 +459,7 @@ Functions documentation
| *[in]* **v2** vector2 | *[in]* **v2** vector2
| *[out]* **dest** destination | *[out]* **dest** destination
.. c:function:: void glm_vec_ortho(vec3 v, vec3 dest) .. c:function:: void glm_vec3_ortho(vec3 v, vec3 dest)
possible orthogonal/perpendicular vector possible orthogonal/perpendicular vector
@@ -415,7 +467,7 @@ Functions documentation
| *[in]* **mat** vector | *[in]* **mat** vector
| *[out]* **dest** orthogonal/perpendicular vector | *[out]* **dest** orthogonal/perpendicular vector
.. c:function:: void glm_vec_clamp(vec3 v, float minVal, float maxVal) .. c:function:: void glm_vec3_clamp(vec3 v, float minVal, float maxVal)
constrain a value to lie between two further values constrain a value to lie between two further values
@@ -424,7 +476,7 @@ Functions documentation
| *[in]* **minVal** minimum value | *[in]* **minVal** minimum value
| *[in]* **maxVal** maximum value | *[in]* **maxVal** maximum value
.. c:function:: void glm_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) .. c:function:: void glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest)
linear interpolation between two vector linear interpolation between two vector

View File

@@ -43,10 +43,14 @@ Functions:
#. :c:func:`glm_vec4_subadd` #. :c:func:`glm_vec4_subadd`
#. :c:func:`glm_vec4_muladd` #. :c:func:`glm_vec4_muladd`
#. :c:func:`glm_vec4_muladds` #. :c:func:`glm_vec4_muladds`
#. :c:func:`glm_vec4_maxadd`
#. :c:func:`glm_vec4_minadd`
#. :c:func:`glm_vec4_flipsign` #. :c:func:`glm_vec4_flipsign`
#. :c:func:`glm_vec_flipsign_to` #. :c:func:`glm_vec4_flipsign_to`
#. :c:func:`glm_vec4_inv` #. :c:func:`glm_vec4_inv`
#. :c:func:`glm_vec4_inv_to` #. :c:func:`glm_vec4_inv_to`
#. :c:func:`glm_vec4_negate`
#. :c:func:`glm_vec4_negate_to`
#. :c:func:`glm_vec4_normalize` #. :c:func:`glm_vec4_normalize`
#. :c:func:`glm_vec4_normalize_to` #. :c:func:`glm_vec4_normalize_to`
#. :c:func:`glm_vec4_distance` #. :c:func:`glm_vec4_distance`
@@ -260,16 +264,40 @@ Functions documentation
| *[in]* **s** scalar | *[in]* **s** scalar
| *[out]* **dest** dest += (a * b) | *[out]* **dest** dest += (a * b)
.. c:function:: void glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest)
| add max of two vector to result/dest
| it applies += operator so dest must be initialized
Parameters:
| *[in]* **a** vector 1
| *[in]* **b** vector 2
| *[out]* **dest** dest += (a * b)
.. c:function:: void glm_vec4_minadd(vec4 a, vec4 b, vec4 dest)
| add min of two vector to result/dest
| it applies += operator so dest must be initialized
Parameters:
| *[in]* **a** vector 1
| *[in]* **b** vector 2
| *[out]* **dest** dest += (a * b)
.. c:function:: void glm_vec4_flipsign(vec4 v) .. c:function:: void glm_vec4_flipsign(vec4 v)
flip sign of all vec4 members **DEPRACATED!**
use :c:func:`glm_vec4_negate`
Parameters: Parameters:
| *[in, out]* **v** vector | *[in, out]* **v** vector
.. c:function:: void glm_vec4_flipsign_to(vec4 v, vec4 dest) .. c:function:: void glm_vec4_flipsign_to(vec4 v, vec4 dest)
flip sign of all vec4 members and store result in dest **DEPRACATED!**
use :c:func:`glm_vec4_negate_to`
Parameters: Parameters:
| *[in]* **v** vector | *[in]* **v** vector
@@ -277,19 +305,38 @@ Functions documentation
.. c:function:: void glm_vec4_inv(vec4 v) .. c:function:: void glm_vec4_inv(vec4 v)
make vector as inverse/opposite of itself **DEPRACATED!**
use :c:func:`glm_vec4_negate`
Parameters: Parameters:
| *[in, out]* **v** vector | *[in, out]* **v** vector
.. c:function:: void glm_vec4_inv_to(vec4 v, vec4 dest) .. c:function:: void glm_vec4_inv_to(vec4 v, vec4 dest)
inverse/opposite vector **DEPRACATED!**
use :c:func:`glm_vec4_negate_to`
Parameters: Parameters:
| *[in]* **v** source | *[in]* **v** source
| *[out]* **dest** destination | *[out]* **dest** destination
.. c:function:: void glm_vec4_negate(vec4 v)
negate vector components
Parameters:
| *[in, out]* **v** vector
.. c:function:: void glm_vec4_negate_to(vec4 v, vec4 dest)
negate vector components and store result in dest
Parameters:
| *[in]* **v** vector
| *[out]* **dest** negated vector
.. c:function:: void glm_vec4_normalize(vec4 v) .. c:function:: void glm_vec4_normalize(vec4 v)
normalize vec4 and store result in same vec normalize vec4 and store result in same vec

View File

@@ -151,7 +151,7 @@ glm_inv_tr(mat4 mat) {
#if defined( __SSE__ ) || defined( __SSE2__ ) #if defined( __SSE__ ) || defined( __SSE2__ )
glm_inv_tr_sse2(mat); glm_inv_tr_sse2(mat);
#else #else
CGLM_ALIGN(16) mat3 r; CGLM_ALIGN_MAT mat3 r;
CGLM_ALIGN(16) vec3 t; CGLM_ALIGN(16) vec3 t;
/* rotate */ /* rotate */
@@ -160,8 +160,8 @@ glm_inv_tr(mat4 mat) {
/* translate */ /* translate */
glm_mat3_mulv(r, mat[3], t); glm_mat3_mulv(r, mat[3], t);
glm_vec_flipsign(t); glm_vec3_negate(t);
glm_vec_copy(t, mat[3]); glm_vec3_copy(t, mat[3]);
#endif #endif
} }

View File

@@ -170,7 +170,7 @@ CGLM_INLINE
void void
glm_translate_make(mat4 m, vec3 v) { glm_translate_make(mat4 m, vec3 v) {
glm_mat4_identity(m); glm_mat4_identity(m);
glm_vec_copy(v, m[3]); glm_vec3_copy(v, m[3]);
} }
/*! /*!
@@ -244,7 +244,7 @@ glm_scale_uni(mat4 m, float s) {
CGLM_INLINE CGLM_INLINE
void void
glm_rotate_x(mat4 m, float angle, mat4 dest) { glm_rotate_x(mat4 m, float angle, mat4 dest) {
CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
float c, s; float c, s;
c = cosf(angle); c = cosf(angle);
@@ -269,7 +269,7 @@ glm_rotate_x(mat4 m, float angle, mat4 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_rotate_y(mat4 m, float angle, mat4 dest) { glm_rotate_y(mat4 m, float angle, mat4 dest) {
CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
float c, s; float c, s;
c = cosf(angle); c = cosf(angle);
@@ -294,7 +294,7 @@ glm_rotate_y(mat4 m, float angle, mat4 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_rotate_z(mat4 m, float angle, mat4 dest) { glm_rotate_z(mat4 m, float angle, mat4 dest) {
CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
float c, s; float c, s;
c = cosf(angle); c = cosf(angle);
@@ -325,13 +325,13 @@ glm_rotate_make(mat4 m, float angle, vec3 axis) {
c = cosf(angle); c = cosf(angle);
glm_vec_normalize_to(axis, axisn); glm_vec3_normalize_to(axis, axisn);
glm_vec_scale(axisn, 1.0f - c, v); glm_vec3_scale(axisn, 1.0f - c, v);
glm_vec_scale(axisn, sinf(angle), vs); glm_vec3_scale(axisn, sinf(angle), vs);
glm_vec_scale(axisn, v[0], m[0]); glm_vec3_scale(axisn, v[0], m[0]);
glm_vec_scale(axisn, v[1], m[1]); glm_vec3_scale(axisn, v[1], m[1]);
glm_vec_scale(axisn, v[2], m[2]); glm_vec3_scale(axisn, v[2], m[2]);
m[0][0] += c; m[1][0] -= vs[2]; m[2][0] += vs[1]; m[0][0] += c; m[1][0] -= vs[2]; m[2][0] += vs[1];
m[0][1] += vs[2]; m[1][1] += c; m[2][1] -= vs[0]; m[0][1] += vs[2]; m[1][1] += c; m[2][1] -= vs[0];
@@ -351,7 +351,7 @@ glm_rotate_make(mat4 m, float angle, vec3 axis) {
CGLM_INLINE CGLM_INLINE
void void
glm_rotate(mat4 m, float angle, vec3 axis) { glm_rotate(mat4 m, float angle, vec3 axis) {
CGLM_ALIGN(16) mat4 rot; CGLM_ALIGN_MAT mat4 rot;
glm_rotate_make(rot, angle, axis); glm_rotate_make(rot, angle, axis);
glm_mul_rot(m, rot, m); glm_mul_rot(m, rot, m);
} }
@@ -370,7 +370,7 @@ void
glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) { glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) {
CGLM_ALIGN(8) vec3 pivotInv; CGLM_ALIGN(8) vec3 pivotInv;
glm_vec_inv_to(pivot, pivotInv); glm_vec3_negate_to(pivot, pivotInv);
glm_translate(m, pivot); glm_translate(m, pivot);
glm_rotate(m, angle, axis); glm_rotate(m, angle, axis);
@@ -395,7 +395,7 @@ void
glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) { glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) {
CGLM_ALIGN(8) vec3 pivotInv; CGLM_ALIGN(8) vec3 pivotInv;
glm_vec_inv_to(pivot, pivotInv); glm_vec3_negate_to(pivot, pivotInv);
glm_translate_make(m, pivot); glm_translate_make(m, pivot);
glm_rotate(m, angle, axis); glm_rotate(m, angle, axis);
@@ -411,9 +411,9 @@ glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) {
CGLM_INLINE CGLM_INLINE
void void
glm_decompose_scalev(mat4 m, vec3 s) { glm_decompose_scalev(mat4 m, vec3 s) {
s[0] = glm_vec_norm(m[0]); s[0] = glm_vec3_norm(m[0]);
s[1] = glm_vec_norm(m[1]); s[1] = glm_vec3_norm(m[1]);
s[2] = glm_vec_norm(m[2]); s[2] = glm_vec3_norm(m[2]);
} }
/*! /*!
@@ -429,7 +429,7 @@ bool
glm_uniscaled(mat4 m) { glm_uniscaled(mat4 m) {
CGLM_ALIGN(8) vec3 s; CGLM_ALIGN(8) vec3 s;
glm_decompose_scalev(m, s); glm_decompose_scalev(m, s);
return glm_vec_eq_all(s); return glm_vec3_eq_all(s);
} }
/*! /*!
@@ -451,9 +451,9 @@ glm_decompose_rs(mat4 m, mat4 r, vec3 s) {
glm_vec4_copy(m[2], r[2]); glm_vec4_copy(m[2], r[2]);
glm_vec4_copy(t, r[3]); glm_vec4_copy(t, r[3]);
s[0] = glm_vec_norm(m[0]); s[0] = glm_vec3_norm(m[0]);
s[1] = glm_vec_norm(m[1]); s[1] = glm_vec3_norm(m[1]);
s[2] = glm_vec_norm(m[2]); s[2] = glm_vec3_norm(m[2]);
glm_vec4_scale(r[0], 1.0f/s[0], r[0]); glm_vec4_scale(r[0], 1.0f/s[0], r[0]);
glm_vec4_scale(r[1], 1.0f/s[1], r[1]); glm_vec4_scale(r[1], 1.0f/s[1], r[1]);
@@ -462,12 +462,12 @@ glm_decompose_rs(mat4 m, mat4 r, vec3 s) {
/* Note from Apple Open Source (asume that the matrix is orthonormal): /* Note from Apple Open Source (asume that the matrix is orthonormal):
check for a coordinate system flip. If the determinant check for a coordinate system flip. If the determinant
is -1, then negate the matrix and the scaling factors. */ is -1, then negate the matrix and the scaling factors. */
glm_vec_cross(m[0], m[1], v); glm_vec3_cross(m[0], m[1], v);
if (glm_vec_dot(v, m[2]) < 0.0f) { if (glm_vec3_dot(v, m[2]) < 0.0f) {
glm_vec4_flipsign(r[0]); glm_vec4_negate(r[0]);
glm_vec4_flipsign(r[1]); glm_vec4_negate(r[1]);
glm_vec4_flipsign(r[2]); glm_vec4_negate(r[2]);
glm_vec_flipsign(s); glm_vec3_negate(s);
} }
} }

View File

@@ -1,124 +0,0 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglm_bezier_h
#define cglm_bezier_h
#include "common.h"
/*!
* @brief cubic bezier interpolation
*
* @param[in] t time between 0 and 1
* @param[in] p0 begin point
* @param[in] c0 control point 1
* @param[in] c1 control point 2
* @param[in] p1 end point
*
* @return B(s)
*/
CGLM_INLINE
float
glm_bezier_cubic(float t, float p0, float c0, float c1, float p1) {
float s, ss, tt;
s = 1.0f - t;
ss = s * s;
tt = t * t;
return p0 * ss * s + 3.0f * c0 * t * ss + 3.0f * c1 * tt * s + p1 * tt * t;
}
/*!
* @brief cubic bezier interpolation for vec3
*
* @param[in] t time between 0 and 1
* @param[in] p0 begin point
* @param[in] c0 control point 1
* @param[in] c1 control point 2
* @param[in] p1 end point
* @param[in] dest destination
*/
CGLM_INLINE
void
glm_bezier_cubicv3(float t, vec3 p0, vec3 c0, vec3 c1, vec3 p1, vec3 dest) {
vec3 Bs, tmp0, tmp1, tmp2;
float s, ss, tt;
s = 1.0f - t;
ss = s * s;
tt = t * t;
glm_vec_scale(p0, ss * s, Bs);
glm_vec_scale(c0, 3.0f * t * ss, tmp0);
glm_vec_scale(c1, 3.0f * tt * s, tmp1);
glm_vec_scale(p1, tt * t, tmp2);
glm_vec_add(Bs, tmp0, Bs);
glm_vec_add(Bs, tmp1, Bs);
glm_vec_add(Bs, tmp2, Bs);
glm_vec_copy(Bs, dest);
}
/*!
* @brief cubic hermite interpolation
*
* @param[in] t time between 0 and 1
* @param[in] p0 begin point
* @param[in] t0 tangent 1
* @param[in] t1 tangent 2
* @param[in] p1 end point
*
* @return B(s)
*/
CGLM_INLINE
float
glm_hermite_cubic(float t, float p0, float t0, float t1, float p1) {
float tt, ttt;
tt = t * t;
ttt = tt * t;
return p0 * (2.0f * ttt - 3.0f * tt + 1)
+ t0 * (ttt - 2.0f * tt + t)
+ p1 * (3.0f * tt - 2.0f * ttt)
- t1 * (ttt - tt);
}
/*!
* @brief cubic hermite interpolation for vec3
*
* @param[in] t time between 0 and 1
* @param[in] p0 begin point
* @param[in] t0 tangent 1
* @param[in] t1 tangent 2
* @param[in] p1 end point
* @param[in] dest destination
*/
CGLM_INLINE
void
glm_hermite_cubicv3(float t, vec3 p0, vec3 t0, vec3 t1, vec3 p1, vec3 dest) {
vec3 Hs, tmp0, tmp1, tmp2;
float tt, ttt;
tt = t * t;
ttt = tt * t;
glm_vec_scale(p0, 2.0f * ttt - 3.0f * tt + 1, Hs);
glm_vec_scale(t0, ttt - 2.0f * tt + t, tmp0);
glm_vec_scale(p1, 3.0f * tt - 2.0f * ttt, tmp1);
glm_vec_scale(t1, ttt - tt, tmp2);
glm_vec_add(Hs, tmp0, Hs);
glm_vec_add(Hs, tmp1, Hs);
glm_vec_add(Hs, tmp2, Hs);
glm_vec_copy(Hs, dest);
}
#endif /* cglm_bezier_h */

View File

@@ -23,35 +23,31 @@
CGLM_INLINE CGLM_INLINE
void void
glm_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]) { glm_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]) {
vec3 v[2], xa, xb, ya, yb, za, zb, tmp; vec3 v[2], xa, xb, ya, yb, za, zb;
glm_vec_scale(m[0], box[0][0], xa); glm_vec3_scale(m[0], box[0][0], xa);
glm_vec_scale(m[0], box[1][0], xb); glm_vec3_scale(m[0], box[1][0], xb);
glm_vec_scale(m[1], box[0][1], ya); glm_vec3_scale(m[1], box[0][1], ya);
glm_vec_scale(m[1], box[1][1], yb); glm_vec3_scale(m[1], box[1][1], yb);
glm_vec_scale(m[2], box[0][2], za); glm_vec3_scale(m[2], box[0][2], za);
glm_vec_scale(m[2], box[1][2], zb); glm_vec3_scale(m[2], box[1][2], zb);
/* min(xa, xb) + min(ya, yb) + min(za, zb) + translation */ /* translation + min(xa, xb) + min(ya, yb) + min(za, zb) */
glm_vec_minv(xa, xb, v[0]); glm_vec3(m[3], v[0]);
glm_vec_minv(ya, yb, tmp); glm_vec3_minadd(xa, xb, v[0]);
glm_vec_add(v[0], tmp, v[0]); glm_vec3_minadd(ya, yb, v[0]);
glm_vec_minv(za, zb, tmp); glm_vec3_minadd(za, zb, v[0]);
glm_vec_add(v[0], tmp, v[0]);
glm_vec_add(v[0], m[3], v[0]);
/* max(xa, xb) + max(ya, yb) + max(za, zb) + translation */ /* translation + max(xa, xb) + max(ya, yb) + max(za, zb) */
glm_vec_maxv(xa, xb, v[1]); glm_vec3(m[3], v[1]);
glm_vec_maxv(ya, yb, tmp); glm_vec3_maxadd(xa, xb, v[1]);
glm_vec_add(v[1], tmp, v[1]); glm_vec3_maxadd(ya, yb, v[1]);
glm_vec_maxv(za, zb, tmp); glm_vec3_maxadd(za, zb, v[1]);
glm_vec_add(v[1], tmp, v[1]);
glm_vec_add(v[1], m[3], v[1]);
glm_vec_copy(v[0], dest[0]); glm_vec3_copy(v[0], dest[0]);
glm_vec_copy(v[1], dest[1]); glm_vec3_copy(v[1], dest[1]);
} }
/*! /*!
@@ -162,8 +158,8 @@ glm_aabb_frustum(vec3 box[2], vec4 planes[6]) {
CGLM_INLINE CGLM_INLINE
void void
glm_aabb_invalidate(vec3 box[2]) { glm_aabb_invalidate(vec3 box[2]) {
glm_vec_broadcast(FLT_MAX, box[0]); glm_vec3_broadcast(FLT_MAX, box[0]);
glm_vec_broadcast(-FLT_MAX, box[1]); glm_vec3_broadcast(-FLT_MAX, box[1]);
} }
/*! /*!
@@ -174,8 +170,8 @@ glm_aabb_invalidate(vec3 box[2]) {
CGLM_INLINE CGLM_INLINE
bool bool
glm_aabb_isvalid(vec3 box[2]) { glm_aabb_isvalid(vec3 box[2]) {
return glm_vec_max(box[0]) != FLT_MAX return glm_vec3_max(box[0]) != FLT_MAX
&& glm_vec_min(box[1]) != -FLT_MAX; && glm_vec3_min(box[1]) != -FLT_MAX;
} }
/*! /*!
@@ -186,7 +182,7 @@ glm_aabb_isvalid(vec3 box[2]) {
CGLM_INLINE CGLM_INLINE
float float
glm_aabb_size(vec3 box[2]) { glm_aabb_size(vec3 box[2]) {
return glm_vec_distance(box[0], box[1]); return glm_vec3_distance(box[0], box[1]);
} }
/*! /*!
@@ -209,7 +205,7 @@ glm_aabb_radius(vec3 box[2]) {
CGLM_INLINE CGLM_INLINE
void void
glm_aabb_center(vec3 box[2], vec3 dest) { glm_aabb_center(vec3 box[2], vec3 dest) {
glm_vec_center(box[0], box[1], dest); glm_vec3_center(box[0], box[1], dest);
} }
/*! /*!

View File

@@ -24,6 +24,10 @@ CGLM_EXPORT
void void
glmc_mat3_identity(mat3 mat); glmc_mat3_identity(mat3 mat);
CGLM_EXPORT
void
glmc_mat3_identity_array(mat3 * __restrict mat, size_t count);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest); glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest);

View File

@@ -29,6 +29,10 @@ CGLM_EXPORT
void void
glmc_mat4_identity(mat4 mat); glmc_mat4_identity(mat4 mat);
CGLM_EXPORT
void
glmc_mat4_identity_array(mat4 * __restrict mat, size_t count);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat4_pick3(mat4 mat, mat3 dest); glmc_mat4_pick3(mat4 mat, mat3 dest);

View File

@@ -17,6 +17,10 @@ CGLM_EXPORT
void void
glmc_quat_identity(versor q); glmc_quat_identity(versor q);
CGLM_EXPORT
void
glmc_quat_identity_array(versor * __restrict q, size_t count);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_quat_init(versor q, float x, float y, float z, float w); glmc_quat_init(versor q, float x, float y, float z, float w);

View File

@@ -14,7 +14,11 @@ extern "C" {
#include "../cglm.h" #include "../cglm.h"
/* DEPRECATED! use _copy, _ucopy versions */ /* DEPRECATED! use _copy, _ucopy versions */
#define glmc_vec_dup(v, dest) glmc_vec_copy(v, dest) #define glmc_vec_dup(v, dest) glmc_vec3_copy(v, dest)
#define glmc_vec3_flipsign(v) glmc_vec3_negate(v)
#define glmc_vec3_flipsign_to(v, dest) glmc_vec3_negate_to(v, dest)
#define glmc_vec3_inv(v) glmc_vec3_negate(v)
#define glmc_vec3_inv_to(v, dest) glmc_vec3_negate_to(v, dest)
CGLM_EXPORT CGLM_EXPORT
void void
@@ -22,217 +26,217 @@ glmc_vec3(vec4 v4, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_copy(vec3 a, vec3 dest); glmc_vec3_copy(vec3 a, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_zero(vec3 v); glmc_vec3_zero(vec3 v);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_one(vec3 v); glmc_vec3_one(vec3 v);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_dot(vec3 a, vec3 b); glmc_vec3_dot(vec3 a, vec3 b);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_cross(vec3 a, vec3 b, vec3 d); glmc_vec3_cross(vec3 a, vec3 b, vec3 d);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_norm(vec3 vec); glmc_vec3_norm(vec3 v);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_norm2(vec3 vec); glmc_vec3_norm2(vec3 v);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_normalize_to(vec3 vec, vec3 dest); glmc_vec3_normalize_to(vec3 v, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_normalize(vec3 v); glmc_vec3_normalize(vec3 v);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_add(vec3 v1, vec3 v2, vec3 dest); glmc_vec3_add(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_adds(vec3 v, float s, vec3 dest); glmc_vec3_adds(vec3 v, float s, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_sub(vec3 a, vec3 b, vec3 dest); glmc_vec3_sub(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_subs(vec3 v, float s, vec3 dest); glmc_vec3_subs(vec3 v, float s, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_mul(vec3 a, vec3 b, vec3 d); glmc_vec3_mul(vec3 a, vec3 b, vec3 d);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_scale(vec3 v, float s, vec3 dest); glmc_vec3_scale(vec3 v, float s, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_scale_as(vec3 v, float s, vec3 dest); glmc_vec3_scale_as(vec3 v, float s, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_div(vec3 a, vec3 b, vec3 dest); glmc_vec3_div(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_divs(vec3 a, float s, vec3 dest); glmc_vec3_divs(vec3 a, float s, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_addadd(vec3 a, vec3 b, vec3 dest); glmc_vec3_addadd(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_subadd(vec3 a, vec3 b, vec3 dest); glmc_vec3_subadd(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_muladd(vec3 a, vec3 b, vec3 dest); glmc_vec3_muladd(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_muladds(vec3 a, float s, vec3 dest); glmc_vec3_muladds(vec3 a, float s, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_flipsign(vec3 v); glmc_vec3_maxadd(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_flipsign_to(vec3 v, vec3 dest); glmc_vec3_minadd(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_inv(vec3 v); glmc_vec3_negate(vec3 v);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_inv_to(vec3 v, vec3 dest); glmc_vec3_negate_to(vec3 v, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_angle(vec3 v1, vec3 v2); glmc_vec3_angle(vec3 a, vec3 b);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_rotate(vec3 v, float angle, vec3 axis); glmc_vec3_rotate(vec3 v, float angle, vec3 axis);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_rotate_m4(mat4 m, vec3 v, vec3 dest); glmc_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_rotate_m3(mat3 m, vec3 v, vec3 dest); glmc_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_proj(vec3 a, vec3 b, vec3 dest); glmc_vec3_proj(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_center(vec3 v1, vec3 v2, vec3 dest); glmc_vec3_center(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_distance2(vec3 v1, vec3 v2); glmc_vec3_distance2(vec3 a, vec3 b);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_distance(vec3 v1, vec3 v2); glmc_vec3_distance(vec3 a, vec3 b);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_maxv(vec3 v1, vec3 v2, vec3 dest); glmc_vec3_maxv(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_minv(vec3 v1, vec3 v2, vec3 dest); glmc_vec3_minv(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_clamp(vec3 v, float minVal, float maxVal); glmc_vec3_clamp(vec3 v, float minVal, float maxVal);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_ortho(vec3 v, vec3 dest); glmc_vec3_ortho(vec3 v, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_lerp(vec3 from, vec3 to, float t, vec3 dest); glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest);
/* ext */ /* ext */
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_mulv(vec3 a, vec3 b, vec3 d); glmc_vec3_mulv(vec3 a, vec3 b, vec3 d);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_broadcast(float val, vec3 d); glmc_vec3_broadcast(float val, vec3 d);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_eq(vec3 v, float val); glmc_vec3_eq(vec3 v, float val);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_eq_eps(vec3 v, float val); glmc_vec3_eq_eps(vec3 v, float val);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_eq_all(vec3 v); glmc_vec3_eq_all(vec3 v);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_eqv(vec3 v1, vec3 v2); glmc_vec3_eqv(vec3 a, vec3 b);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_eqv_eps(vec3 v1, vec3 v2); glmc_vec3_eqv_eps(vec3 a, vec3 b);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_max(vec3 v); glmc_vec3_max(vec3 v);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_min(vec3 v); glmc_vec3_min(vec3 v);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_isnan(vec3 v); glmc_vec3_isnan(vec3 v);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_isinf(vec3 v); glmc_vec3_isinf(vec3 v);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_isvalid(vec3 v); glmc_vec3_isvalid(vec3 v);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_sign(vec3 v, vec3 dest); glmc_vec3_sign(vec3 v, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_sqrt(vec3 v, vec3 dest); glmc_vec3_sqrt(vec3 v, vec3 dest);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -14,8 +14,12 @@ extern "C" {
#include "../cglm.h" #include "../cglm.h"
/* DEPRECATED! use _copy, _ucopy versions */ /* DEPRECATED! use _copy, _ucopy versions */
#define glmc_vec4_dup3(v, dest) glmc_vec4_copy3(v, dest) #define glmc_vec4_dup3(v, dest) glmc_vec4_copy3(v, dest)
#define glmc_vec4_dup(v, dest) glmc_vec4_copy(v, dest) #define glmc_vec4_dup(v, dest) glmc_vec4_copy(v, dest)
#define glmc_vec4_flipsign(v) glmc_vec4_negate(v)
#define glmc_vec4_flipsign_to(v, dest) glmc_vec4_negate_to(v, dest)
#define glmc_vec4_inv(v) glmc_vec4_negate(v)
#define glmc_vec4_inv_to(v, dest) glmc_vec4_negate_to(v, dest)
CGLM_EXPORT CGLM_EXPORT
void void
@@ -31,7 +35,7 @@ glmc_vec4_one(vec4 v);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_copy3(vec4 a, vec3 dest); glmc_vec4_copy3(vec4 v, vec3 dest);
CGLM_EXPORT CGLM_EXPORT
void void
@@ -47,15 +51,15 @@ glmc_vec4_dot(vec4 a, vec4 b);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec4_norm(vec4 vec); glmc_vec4_norm(vec4 v);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec4_norm2(vec4 vec); glmc_vec4_norm2(vec4 v);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_normalize_to(vec4 vec, vec4 dest); glmc_vec4_normalize_to(vec4 v, vec4 dest);
CGLM_EXPORT CGLM_EXPORT
void void
@@ -115,31 +119,31 @@ glmc_vec4_muladds(vec4 a, float s, vec4 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_flipsign(vec4 v); glmc_vec4_maxadd(vec4 a, vec4 b, vec4 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_flipsign_to(vec4 v, vec4 dest); glmc_vec4_minadd(vec4 a, vec4 b, vec4 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_inv(vec4 v); glmc_vec4_negate(vec4 v);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_inv_to(vec4 v, vec4 dest); glmc_vec4_negate_to(vec4 v, vec4 dest);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec4_distance(vec4 v1, vec4 v2); glmc_vec4_distance(vec4 a, vec4 b);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_maxv(vec4 v1, vec4 v2, vec4 dest); glmc_vec4_maxv(vec4 a, vec4 b, vec4 dest);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_minv(vec4 v1, vec4 v2, vec4 dest); glmc_vec4_minv(vec4 a, vec4 b, vec4 dest);
CGLM_EXPORT CGLM_EXPORT
void void
@@ -173,11 +177,11 @@ glmc_vec4_eq_all(vec4 v);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec4_eqv(vec4 v1, vec4 v2); glmc_vec4_eqv(vec4 a, vec4 b);
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec4_eqv_eps(vec4 v1, vec4 v2); glmc_vec4_eqv_eps(vec4 a, vec4 b);
CGLM_EXPORT CGLM_EXPORT
float float

View File

@@ -198,26 +198,15 @@ glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_ortho_default(float aspect, glm_ortho_default(float aspect, mat4 dest) {
mat4 dest) {
if (aspect >= 1.0f) { if (aspect >= 1.0f) {
glm_ortho(-1.0f * aspect, glm_ortho(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest);
1.0f * aspect, return;
-1.0f,
1.0f,
-100.0f,
100.0f,
dest);
return;
} }
glm_ortho(-1.0f, aspect = 1.0f / aspect;
1.0f,
-1.0f / aspect, glm_ortho(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest);
1.0f / aspect,
-100.0f,
100.0f,
dest);
} }
/*! /*!
@@ -240,7 +229,7 @@ glm_ortho_default_s(float aspect,
-size - 100.0f, -size - 100.0f,
size + 100.0f, size + 100.0f,
dest); dest);
return; return;
} }
glm_ortho(-size, glm_ortho(-size,
@@ -291,13 +280,8 @@ glm_perspective(float fovy,
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_perspective_default(float aspect, glm_perspective_default(float aspect, mat4 dest) {
mat4 dest) { glm_perspective(GLM_PI_4f, aspect, 0.01f, 100.0f, dest);
glm_perspective((float)CGLM_PI_4,
aspect,
0.01f,
100.0f,
dest);
} }
/*! /*!
@@ -310,8 +294,7 @@ glm_perspective_default(float aspect,
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_perspective_resize(float aspect, glm_perspective_resize(float aspect, mat4 proj) {
mat4 proj) {
if (proj[0][0] == 0.0f) if (proj[0][0] == 0.0f)
return; return;
@@ -337,13 +320,13 @@ glm_lookat(vec3 eye,
mat4 dest) { mat4 dest) {
CGLM_ALIGN(8) vec3 f, u, s; CGLM_ALIGN(8) vec3 f, u, s;
glm_vec_sub(center, eye, f); glm_vec3_sub(center, eye, f);
glm_vec_normalize(f); glm_vec3_normalize(f);
glm_vec_cross(f, up, s); glm_vec3_cross(f, up, s);
glm_vec_normalize(s); glm_vec3_normalize(s);
glm_vec_cross(s, f, u); glm_vec3_cross(s, f, u);
dest[0][0] = s[0]; dest[0][0] = s[0];
dest[0][1] = u[0]; dest[0][1] = u[0];
@@ -354,9 +337,9 @@ glm_lookat(vec3 eye,
dest[2][0] = s[2]; dest[2][0] = s[2];
dest[2][1] = u[2]; dest[2][1] = u[2];
dest[2][2] =-f[2]; dest[2][2] =-f[2];
dest[3][0] =-glm_vec_dot(s, eye); dest[3][0] =-glm_vec3_dot(s, eye);
dest[3][1] =-glm_vec_dot(u, eye); dest[3][1] =-glm_vec3_dot(u, eye);
dest[3][2] = glm_vec_dot(f, eye); dest[3][2] = glm_vec3_dot(f, eye);
dest[0][3] = dest[1][3] = dest[2][3] = 0.0f; dest[0][3] = dest[1][3] = dest[2][3] = 0.0f;
dest[3][3] = 1.0f; dest[3][3] = 1.0f;
} }
@@ -379,7 +362,7 @@ CGLM_INLINE
void void
glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) {
CGLM_ALIGN(8) vec3 target; CGLM_ALIGN(8) vec3 target;
glm_vec_add(eye, dir, target); glm_vec3_add(eye, dir, target);
glm_lookat(eye, target, up, dest); glm_lookat(eye, target, up, dest);
} }
@@ -397,7 +380,7 @@ CGLM_INLINE
void void
glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) { glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) {
CGLM_ALIGN(8) vec3 up; CGLM_ALIGN(8) vec3 up;
glm_vec_ortho(dir, up); glm_vec3_ortho(dir, up);
glm_look(eye, dir, up, dest); glm_look(eye, dir, up, dest);
} }

View File

@@ -26,6 +26,5 @@
#include "project.h" #include "project.h"
#include "sphere.h" #include "sphere.h"
#include "ease.h" #include "ease.h"
#include "bezier.h"
#endif /* cglm_h */ #endif /* cglm_h */

View File

@@ -19,19 +19,19 @@ glm_ease_linear(float t) {
CGLM_INLINE CGLM_INLINE
float float
glm_ease_sine_in(float t) { glm_ease_sine_in(float t) {
return sinf((t - 1.0f) * CGLM_PI_2) + 1.0f; return sinf((t - 1.0f) * GLM_PI_2f) + 1.0f;
} }
CGLM_INLINE CGLM_INLINE
float float
glm_ease_sine_out(float t) { glm_ease_sine_out(float t) {
return sinf(t * CGLM_PI_2); return sinf(t * GLM_PI_2f);
} }
CGLM_INLINE CGLM_INLINE
float float
glm_ease_sine_inout(float t) { glm_ease_sine_inout(float t) {
return 0.5f * (1.0f - cosf(t * CGLM_PI)); return 0.5f * (1.0f - cosf(t * GLM_PIf));
} }
CGLM_INLINE CGLM_INLINE
@@ -254,13 +254,13 @@ glm_ease_back_inout(float t) {
CGLM_INLINE CGLM_INLINE
float float
glm_ease_elast_in(float t) { glm_ease_elast_in(float t) {
return sinf(13.0f * CGLM_PI_2 * t) * powf(2.0f, 10.0f * (t - 1.0f)); return sinf(13.0f * GLM_PI_2f * t) * powf(2.0f, 10.0f * (t - 1.0f));
} }
CGLM_INLINE CGLM_INLINE
float float
glm_ease_elast_out(float t) { glm_ease_elast_out(float t) {
return sinf(-13.0f * CGLM_PI_2 * (t + 1.0f)) * powf(2.0f, -10.0f * t) + 1.0f; return sinf(-13.0f * GLM_PI_2f * (t + 1.0f)) * powf(2.0f, -10.0f * t) + 1.0f;
} }
CGLM_INLINE CGLM_INLINE
@@ -271,10 +271,10 @@ glm_ease_elast_inout(float t) {
a = 2.0f * t; a = 2.0f * t;
if (t < 0.5f) if (t < 0.5f)
return 0.5f * sinf(13.0f * CGLM_PI_2 * a) return 0.5f * sinf(13.0f * GLM_PI_2f * a)
* powf(2.0f, 10.0f * (a - 1.0f)); * powf(2.0f, 10.0f * (a - 1.0f));
return 0.5f * (sinf(-13.0f * CGLM_PI_2 * a) return 0.5f * (sinf(-13.0f * GLM_PI_2f * a)
* powf(2.0f, -10.0f * (a - 1.0f)) + 2.0f); * powf(2.0f, -10.0f * (a - 1.0f)) + 2.0f);
} }

View File

@@ -84,12 +84,12 @@ glm_euler_angles(mat4 m, vec3 dest) {
thetaZ = atan2f(-m10, m00); thetaZ = atan2f(-m10, m00);
} else { /* m20 == -1 */ } else { /* m20 == -1 */
/* Not a unique solution */ /* Not a unique solution */
thetaY = -CGLM_PI_2; thetaY = -GLM_PI_2f;
thetaX = -atan2f(m01, m11); thetaX = -atan2f(m01, m11);
thetaZ = 0.0f; thetaZ = 0.0f;
} }
} else { /* m20 == +1 */ } else { /* m20 == +1 */
thetaY = CGLM_PI_2; thetaY = GLM_PI_2f;
thetaX = atan2f(m01, m11); thetaX = atan2f(m01, m11);
thetaZ = 0.0f; thetaZ = 0.0f;
} }

View File

@@ -106,7 +106,7 @@ glm_frustum_planes(mat4 m, vec4 dest[6]) {
* *
* Find center coordinates: * Find center coordinates:
* for (j = 0; j < 4; j++) { * for (j = 0; j < 4; j++) {
* glm_vec_center(corners[i], corners[i + 4], centerCorners[i]); * glm_vec3_center(corners[i], corners[i + 4], centerCorners[i]);
* } * }
* *
* @param[in] invMat matrix (see brief) * @param[in] invMat matrix (see brief)
@@ -187,8 +187,8 @@ glm_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) {
vec3 min, max; vec3 min, max;
int i; int i;
glm_vec_broadcast(FLT_MAX, min); glm_vec3_broadcast(FLT_MAX, min);
glm_vec_broadcast(-FLT_MAX, max); glm_vec3_broadcast(-FLT_MAX, max);
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
glm_mat4_mulv(m, corners[i], v); glm_mat4_mulv(m, corners[i], v);
@@ -202,8 +202,8 @@ glm_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) {
max[2] = glm_max(max[2], v[2]); max[2] = glm_max(max[2], v[2]);
} }
glm_vec_copy(min, box[0]); glm_vec3_copy(min, box[0]);
glm_vec_copy(max, box[1]); glm_vec3_copy(max, box[1]);
} }
/*! /*!
@@ -228,7 +228,7 @@ glm_frustum_corners_at(vec4 corners[8],
float dist, sc; float dist, sc;
/* because distance and scale is same for all */ /* because distance and scale is same for all */
dist = glm_vec_distance(corners[GLM_RTF], corners[GLM_RTN]); dist = glm_vec3_distance(corners[GLM_RTF], corners[GLM_RTN]);
sc = dist * (splitDist / farDist); sc = dist * (splitDist / farDist);
/* left bottom */ /* left bottom */

View File

@@ -25,7 +25,7 @@
CGLM_INLINE CGLM_INLINE
void void
glm_mat4_print(mat4 matrix, glm_mat4_print(mat4 matrix,
FILE * __restrict ostream) { FILE * __restrict ostream) {
int i; int i;
int j; int j;
@@ -55,7 +55,7 @@ glm_mat4_print(mat4 matrix,
CGLM_INLINE CGLM_INLINE
void void
glm_mat3_print(mat3 matrix, glm_mat3_print(mat3 matrix,
FILE * __restrict ostream) { FILE * __restrict ostream) {
int i; int i;
int j; int j;
@@ -85,7 +85,7 @@ glm_mat3_print(mat3 matrix,
CGLM_INLINE CGLM_INLINE
void void
glm_vec4_print(vec4 vec, glm_vec4_print(vec4 vec,
FILE * __restrict ostream) { FILE * __restrict ostream) {
int i; int i;
@@ -107,7 +107,7 @@ glm_vec4_print(vec4 vec,
CGLM_INLINE CGLM_INLINE
void void
glm_vec3_print(vec3 vec, glm_vec3_print(vec3 vec,
FILE * __restrict ostream) { FILE * __restrict ostream) {
int i; int i;
@@ -129,7 +129,7 @@ glm_vec3_print(vec3 vec,
CGLM_INLINE CGLM_INLINE
void void
glm_ivec3_print(ivec3 vec, glm_ivec3_print(ivec3 vec,
FILE * __restrict ostream) { FILE * __restrict ostream) {
int i; int i;
@@ -151,7 +151,7 @@ glm_ivec3_print(ivec3 vec,
CGLM_INLINE CGLM_INLINE
void void
glm_versor_print(versor vec, glm_versor_print(versor vec,
FILE * __restrict ostream) { FILE * __restrict ostream) {
int i; int i;

View File

@@ -16,6 +16,7 @@
Functions: Functions:
CGLM_INLINE void glm_mat3_copy(mat3 mat, mat3 dest); CGLM_INLINE void glm_mat3_copy(mat3 mat, mat3 dest);
CGLM_INLINE void glm_mat3_identity(mat3 mat); CGLM_INLINE void glm_mat3_identity(mat3 mat);
CGLM_INLINE void glm_mat3_identity_array(mat3 * restrict mat, size_t count);
CGLM_INLINE void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest); CGLM_INLINE void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest);
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);
@@ -81,10 +82,29 @@ glm_mat3_copy(mat3 mat, mat3 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_mat3_identity(mat3 mat) { glm_mat3_identity(mat3 mat) {
CGLM_ALIGN(16) mat3 t = GLM_MAT3_IDENTITY_INIT; CGLM_ALIGN_MAT mat3 t = GLM_MAT3_IDENTITY_INIT;
glm_mat3_copy(t, mat); glm_mat3_copy(t, mat);
} }
/*!
* @brief make given matrix array's each element identity matrix
*
* @param[in, out] mat matrix array (must be aligned (16/32)
* if alignment is not disabled)
*
* @param[in] count count of matrices
*/
CGLM_INLINE
void
glm_mat3_identity_array(mat3 * __restrict mat, size_t count) {
CGLM_ALIGN_MAT mat3 t = GLM_MAT3_IDENTITY_INIT;
size_t i;
for (i = 0; i < count; i++) {
glm_mat3_copy(t, mat[i]);
}
}
/*! /*!
* @brief multiply m1 and m2 to dest * @brief multiply m1 and m2 to dest
* *
@@ -155,7 +175,7 @@ glm_mat3_transpose_to(mat3 m, mat3 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_mat3_transpose(mat3 m) { glm_mat3_transpose(mat3 m) {
CGLM_ALIGN(16) mat3 tmp; CGLM_ALIGN_MAT mat3 tmp;
tmp[0][1] = m[1][0]; tmp[0][1] = m[1][0];
tmp[0][2] = m[2][0]; tmp[0][2] = m[2][0];
@@ -310,9 +330,9 @@ CGLM_INLINE
void void
glm_mat3_swap_col(mat3 mat, int col1, int col2) { glm_mat3_swap_col(mat3 mat, int col1, int col2) {
vec3 tmp; vec3 tmp;
glm_vec_copy(mat[col1], tmp); glm_vec3_copy(mat[col1], tmp);
glm_vec_copy(mat[col2], mat[col1]); glm_vec3_copy(mat[col2], mat[col1]);
glm_vec_copy(tmp, mat[col2]); glm_vec3_copy(tmp, mat[col2]);
} }
/*! /*!

View File

@@ -16,13 +16,12 @@
GLM_MAT4_ZERO_INIT GLM_MAT4_ZERO_INIT
GLM_MAT4_IDENTITY GLM_MAT4_IDENTITY
GLM_MAT4_ZERO GLM_MAT4_ZERO
glm_mat4_udup(mat, dest)
glm_mat4_dup(mat, dest)
Functions: Functions:
CGLM_INLINE void glm_mat4_ucopy(mat4 mat, mat4 dest); CGLM_INLINE void glm_mat4_ucopy(mat4 mat, mat4 dest);
CGLM_INLINE void glm_mat4_copy(mat4 mat, mat4 dest); CGLM_INLINE void glm_mat4_copy(mat4 mat, mat4 dest);
CGLM_INLINE void glm_mat4_identity(mat4 mat); CGLM_INLINE void glm_mat4_identity(mat4 mat);
CGLM_INLINE void glm_mat4_identity_array(mat4 * restrict mat, size_t count);
CGLM_INLINE void glm_mat4_pick3(mat4 mat, mat3 dest); CGLM_INLINE void glm_mat4_pick3(mat4 mat, mat3 dest);
CGLM_INLINE void glm_mat4_pick3t(mat4 mat, mat3 dest); CGLM_INLINE void glm_mat4_pick3t(mat4 mat, mat3 dest);
CGLM_INLINE void glm_mat4_ins3(mat3 mat, mat4 dest); CGLM_INLINE void glm_mat4_ins3(mat3 mat, mat4 dest);
@@ -139,10 +138,29 @@ glm_mat4_copy(mat4 mat, mat4 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_mat4_identity(mat4 mat) { glm_mat4_identity(mat4 mat) {
CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
glm_mat4_copy(t, mat); glm_mat4_copy(t, mat);
} }
/*!
* @brief make given matrix array's each element identity matrix
*
* @param[in, out] mat matrix array (must be aligned (16/32)
* if alignment is not disabled)
*
* @param[in] count count of matrices
*/
CGLM_INLINE
void
glm_mat4_identity_array(mat4 * __restrict mat, size_t count) {
CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT;
size_t i;
for (i = 0; i < count; i++) {
glm_mat4_copy(t, mat[i]);
}
}
/*! /*!
* @brief copy upper-left of mat4 to mat3 * @brief copy upper-left of mat4 to mat3
* *

View File

@@ -30,7 +30,7 @@
CGLM_INLINE CGLM_INLINE
void void
glm_plane_normalize(vec4 plane) { glm_plane_normalize(vec4 plane) {
glm_vec4_scale(plane, 1.0f / glm_vec_norm(plane), plane); glm_vec4_scale(plane, 1.0f / glm_vec3_norm(plane), plane);
} }
#endif /* cglm_plane_h */ #endif /* cglm_plane_h */

View File

@@ -19,7 +19,7 @@
CGLM_INLINE float glm_quat_norm(versor q); CGLM_INLINE float glm_quat_norm(versor q);
CGLM_INLINE void glm_quat_normalize(versor q); CGLM_INLINE void glm_quat_normalize(versor q);
CGLM_INLINE void glm_quat_normalize_to(versor q, versor dest); CGLM_INLINE void glm_quat_normalize_to(versor q, versor dest);
CGLM_INLINE float glm_quat_dot(versor q1, versor q2); CGLM_INLINE float glm_quat_dot(versor p, versor q);
CGLM_INLINE void glm_quat_conjugate(versor q, versor dest); CGLM_INLINE void glm_quat_conjugate(versor q, versor dest);
CGLM_INLINE void glm_quat_inv(versor q, versor dest); CGLM_INLINE void glm_quat_inv(versor q, versor dest);
CGLM_INLINE void glm_quat_add(versor p, versor q, versor dest); CGLM_INLINE void glm_quat_add(versor p, versor q, versor dest);
@@ -103,6 +103,25 @@ glm_quat_identity(versor q) {
glm_vec4_copy(v, q); glm_vec4_copy(v, q);
} }
/*!
* @brief make given quaternion array's each element identity quaternion
*
* @param[in, out] q quat array (must be aligned (16)
* if alignment is not disabled)
*
* @param[in] count count of quaternions
*/
CGLM_INLINE
void
glm_quat_identity_array(versor * __restrict q, size_t count) {
CGLM_ALIGN(16) versor v = GLM_QUAT_IDENTITY_INIT;
size_t i;
for (i = 0; i < count; i++) {
glm_vec4_copy(v, q[i]);
}
}
/*! /*!
* @brief inits quaterion with raw values * @brief inits quaterion with raw values
* *
@@ -254,7 +273,7 @@ glm_quat_dot(versor p, versor q) {
CGLM_INLINE CGLM_INLINE
void void
glm_quat_conjugate(versor q, versor dest) { glm_quat_conjugate(versor q, versor dest) {
glm_vec4_flipsign_to(q, dest); glm_vec4_negate_to(q, dest);
dest[3] = -dest[3]; dest[3] = -dest[3];
} }
@@ -267,7 +286,7 @@ glm_quat_conjugate(versor q, versor dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_quat_inv(versor q, versor dest) { glm_quat_inv(versor q, versor dest) {
CGLM_ALIGN(8) versor conj; CGLM_ALIGN(16) versor conj;
glm_quat_conjugate(q, conj); glm_quat_conjugate(q, conj);
glm_vec4_scale(conj, 1.0f / glm_vec4_norm2(q), dest); glm_vec4_scale(conj, 1.0f / glm_vec4_norm2(q), dest);
} }
@@ -342,7 +361,7 @@ glm_quat_imagn(versor q, vec3 dest) {
CGLM_INLINE CGLM_INLINE
float float
glm_quat_imaglen(versor q) { glm_quat_imaglen(versor q) {
return glm_vec_norm(q); return glm_vec3_norm(q);
} }
/*! /*!
@@ -615,7 +634,7 @@ glm_quat_slerp(versor from, versor to, float t, versor dest) {
} }
if (cosTheta < 0.0f) { if (cosTheta < 0.0f) {
glm_vec4_flipsign(q1); glm_vec4_negate(q1);
cosTheta = -cosTheta; cosTheta = -cosTheta;
} }
@@ -651,7 +670,7 @@ glm_quat_look(vec3 eye, versor ori, mat4 dest) {
/* translate */ /* translate */
glm_mat4_mulv3(dest, eye, 1.0f, dest[3]); glm_mat4_mulv3(dest, eye, 1.0f, dest[3]);
glm_vec_flipsign(dest[3]); glm_vec3_negate(dest[3]);
} }
/*! /*!
@@ -668,9 +687,9 @@ glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) {
CGLM_ALIGN(8) vec3 axis; CGLM_ALIGN(8) vec3 axis;
float dot, angle; float dot, angle;
dot = glm_vec_dot(dir, fwd); dot = glm_vec3_dot(dir, fwd);
if (fabsf(dot + 1.0f) < 0.000001f) { if (fabsf(dot + 1.0f) < 0.000001f) {
glm_quat_init(dest, up[0], up[1], up[2], CGLM_PI); glm_quat_init(dest, up[0], up[1], up[2], GLM_PIf);
return; return;
} }
@@ -700,7 +719,7 @@ CGLM_INLINE
void void
glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) {
CGLM_ALIGN(8) vec3 dir; CGLM_ALIGN(8) vec3 dir;
glm_vec_sub(to, from, dir); glm_vec3_sub(to, from, dir);
glm_quat_for(dir, fwd, up, dest); glm_quat_for(dir, fwd, up, dest);
} }
@@ -722,14 +741,14 @@ glm_quat_rotatev(versor q, vec3 v, vec3 dest) {
glm_quat_imag(p, u); glm_quat_imag(p, u);
s = glm_quat_real(p); s = glm_quat_real(p);
glm_vec_scale(u, 2.0f * glm_vec_dot(u, v), v1); glm_vec3_scale(u, 2.0f * glm_vec3_dot(u, v), v1);
glm_vec_scale(v, s * s - glm_vec_dot(u, u), v2); glm_vec3_scale(v, s * s - glm_vec3_dot(u, u), v2);
glm_vec_add(v1, v2, v1); glm_vec3_add(v1, v2, v1);
glm_vec_cross(u, v, v2); glm_vec3_cross(u, v, v2);
glm_vec_scale(v2, 2.0f * s, v2); glm_vec3_scale(v2, 2.0f * s, v2);
glm_vec_add(v1, v2, dest); glm_vec3_add(v1, v2, dest);
} }
/*! /*!
@@ -742,7 +761,7 @@ glm_quat_rotatev(versor q, vec3 v, vec3 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_quat_rotate(mat4 m, versor q, mat4 dest) { glm_quat_rotate(mat4 m, versor q, mat4 dest) {
CGLM_ALIGN(16) mat4 rot; CGLM_ALIGN_MAT mat4 rot;
glm_quat_mat4(q, rot); glm_quat_mat4(q, rot);
glm_mul_rot(m, rot, dest); glm_mul_rot(m, rot, dest);
} }
@@ -759,7 +778,7 @@ void
glm_quat_rotate_at(mat4 m, versor q, vec3 pivot) { glm_quat_rotate_at(mat4 m, versor q, vec3 pivot) {
CGLM_ALIGN(8) vec3 pivotInv; CGLM_ALIGN(8) vec3 pivotInv;
glm_vec_inv_to(pivot, pivotInv); glm_vec3_negate_to(pivot, pivotInv);
glm_translate(m, pivot); glm_translate(m, pivot);
glm_quat_rotate(m, q, m); glm_quat_rotate(m, q, m);
@@ -783,7 +802,7 @@ void
glm_quat_rotate_atm(mat4 m, versor q, vec3 pivot) { glm_quat_rotate_atm(mat4 m, versor q, vec3 pivot) {
CGLM_ALIGN(8) vec3 pivotInv; CGLM_ALIGN(8) vec3 pivotInv;
glm_vec_inv_to(pivot, pivotInv); glm_vec3_negate_to(pivot, pivotInv);
glm_translate_make(m, pivot); glm_translate_make(m, pivot);
glm_quat_rotate(m, q, m); glm_quat_rotate(m, q, m);

View File

@@ -27,21 +27,24 @@ glm_mul_avx(mat4 m1, mat4 m2, mat4 dest) {
y2 = glmm_load256(m1[0]); /* h g f e d c b a */ y2 = glmm_load256(m1[0]); /* h g f e d c b a */
y3 = glmm_load256(m1[2]); /* p o n m l k j i */ y3 = glmm_load256(m1[2]); /* p o n m l k j i */
y4 = _mm256_permute2f128_ps(y2, y2, 0b00000011); /* d c b a h g f e */ /* 0x03: 0b00000011 */
y5 = _mm256_permute2f128_ps(y3, y3, 0b00000000); /* l k j i l k j i */ y4 = _mm256_permute2f128_ps(y2, y2, 0x03); /* d c b a h g f e */
y5 = _mm256_permute2f128_ps(y3, y3, 0x03); /* l k j i p o n m */
/* f f f f a a a a */ /* f f f f a a a a */
/* g g g g c c c c */ /* h h h h c c c c */
/* e e e e b b b b */ /* e e e e b b b b */
y7 = _mm256_permute_ps(y0, 0b10101010); /* g g g g d d d d */
y6 = _mm256_permutevar_ps(y0, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); y6 = _mm256_permutevar_ps(y0, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0));
y7 = _mm256_permutevar_ps(y0, _mm256_set_epi32(3, 3, 3, 3, 2, 2, 2, 2));
y8 = _mm256_permutevar_ps(y0, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); y8 = _mm256_permutevar_ps(y0, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1));
y9 = _mm256_permutevar_ps(y0, _mm256_set_epi32(2, 2, 2, 2, 3, 3, 3, 3));
glmm_store256(dest[0], glmm_store256(dest[0],
_mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6),
_mm256_mul_ps(y4, y8)), _mm256_mul_ps(y3, y7)),
_mm256_mul_ps(y5, y7))); _mm256_add_ps(_mm256_mul_ps(y4, y8),
_mm256_mul_ps(y5, y9))));
/* n n n n i i i i */ /* n n n n i i i i */
/* p p p p k k k k */ /* p p p p k k k k */

View File

@@ -27,8 +27,9 @@ glm_mat4_mul_avx(mat4 m1, mat4 m2, mat4 dest) {
y2 = glmm_load256(m1[0]); /* h g f e d c b a */ y2 = glmm_load256(m1[0]); /* h g f e d c b a */
y3 = glmm_load256(m1[2]); /* p o n m l k j i */ y3 = glmm_load256(m1[2]); /* p o n m l k j i */
y4 = _mm256_permute2f128_ps(y2, y2, 0b00000011); /* d c b a h g f e */ /* 0x03: 0b00000011 */
y5 = _mm256_permute2f128_ps(y3, y3, 0b00000011); /* l k j i p o n m */ y4 = _mm256_permute2f128_ps(y2, y2, 0x03); /* d c b a h g f e */
y5 = _mm256_permute2f128_ps(y3, y3, 0x03); /* l k j i p o n m */
/* f f f f a a a a */ /* f f f f a a a a */
/* h h h h c c c c */ /* h h h h c c c c */

View File

@@ -16,7 +16,7 @@
CGLM_INLINE CGLM_INLINE
void void
glm_mat4_scale_sse2(mat4 m, float s){ glm_mat4_scale_sse2(mat4 m, float s) {
__m128 x0; __m128 x0;
x0 = _mm_set1_ps(s); x0 = _mm_set1_ps(s);
@@ -28,7 +28,7 @@ glm_mat4_scale_sse2(mat4 m, float s){
CGLM_INLINE CGLM_INLINE
void void
glm_mat4_transp_sse2(mat4 m, mat4 dest){ glm_mat4_transp_sse2(mat4 m, mat4 dest) {
__m128 r0, r1, r2, r3; __m128 r0, r1, r2, r3;
r0 = glmm_load(m[0]); r0 = glmm_load(m[0]);

View File

@@ -60,13 +60,13 @@ void
glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) {
float dist, radii; float dist, radii;
dist = glm_vec_distance(s1, s2); dist = glm_vec3_distance(s1, s2);
radii = dist + s1[3] + s2[3]; radii = dist + s1[3] + s2[3];
radii = glm_max(radii, s1[3]); radii = glm_max(radii, s1[3]);
radii = glm_max(radii, s2[3]); radii = glm_max(radii, s2[3]);
glm_vec_center(s1, s2, dest); glm_vec3_center(s1, s2, dest);
dest[3] = radii; dest[3] = radii;
} }
@@ -79,7 +79,7 @@ glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) {
CGLM_INLINE CGLM_INLINE
bool bool
glm_sphere_sphere(vec4 s1, vec4 s2) { glm_sphere_sphere(vec4 s1, vec4 s2) {
return glm_vec_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]); return glm_vec3_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]);
} }
/*! /*!
@@ -93,7 +93,7 @@ bool
glm_sphere_point(vec4 s, vec3 point) { glm_sphere_point(vec4 s, vec3 point) {
float rr; float rr;
rr = s[3] * s[3]; rr = s[3] * s[3];
return glm_vec_distance2(point, s) <= rr; return glm_vec3_distance2(point, s) <= rr;
} }
#endif /* cglm_sphere_h */ #endif /* cglm_sphere_h */

View File

@@ -26,18 +26,58 @@
# define CGLM_ALIGN_IF(X) /* no alignment */ # define CGLM_ALIGN_IF(X) /* no alignment */
#endif #endif
#ifdef __AVX__
# define CGLM_ALIGN_MAT CGLM_ALIGN(32)
#else
# define CGLM_ALIGN_MAT CGLM_ALIGN(16)
#endif
typedef float vec2[2]; typedef float vec2[2];
typedef CGLM_ALIGN_IF(8) float vec3[3]; typedef CGLM_ALIGN_IF(8) 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 vec3 mat3[3]; #ifdef __AVX__
typedef CGLM_ALIGN_IF(32) vec3 mat3[3];
typedef CGLM_ALIGN_IF(32) vec4 mat4[4];
#else
typedef vec3 mat3[3];
typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; typedef CGLM_ALIGN_IF(16) vec4 mat4[4];
#endif
typedef vec4 versor; typedef vec4 versor;
#define CGLM_PI ((float)M_PI) #define GLM_E 2.71828182845904523536028747135266250 /* e */
#define CGLM_PI_2 ((float)M_PI_2) #define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */
#define CGLM_PI_4 ((float)M_PI_4) #define GLM_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */
#define GLM_LN2 0.693147180559945309417232121458176568 /* loge(2) */
#define GLM_LN10 2.30258509299404568401799145468436421 /* loge(10) */
#define GLM_PI 3.14159265358979323846264338327950288 /* pi */
#define GLM_PI_2 1.57079632679489661923132169163975144 /* pi/2 */
#define GLM_PI_4 0.785398163397448309615660845819875721 /* pi/4 */
#define GLM_1_PI 0.318309886183790671537767526745028724 /* 1/pi */
#define GLM_2_PI 0.636619772367581343075535053490057448 /* 2/pi */
#define GLM_2_SQRTPI 1.12837916709551257389615890312154517 /* 2/sqrt(pi) */
#define GLM_SQRT2 1.41421356237309504880168872420969808 /* sqrt(2) */
#define GLM_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */
#define GLM_Ef ((float)GLM_E)
#define GLM_LOG2Ef ((float)GLM_LOG2E)
#define GLM_LOG10Ef ((float)GLM_LOG10E)
#define GLM_LN2f ((float)GLM_LN2)
#define GLM_LN10f ((float)GLM_LN10)
#define GLM_PIf ((float)GLM_PI)
#define GLM_PI_2f ((float)GLM_PI_2)
#define GLM_PI_4f ((float)GLM_PI_4)
#define GLM_1_PIf ((float)GLM_1_PI)
#define GLM_2_PIf ((float)GLM_2_PI)
#define GLM_2_SQRTPIf ((float)GLM_2_SQRTPI)
#define GLM_SQRT2f ((float)GLM_SQRT2)
#define GLM_SQRT1_2f ((float)GLM_SQRT1_2)
/* DEPRECATED! use GLM_PI and friends */
#define CGLM_PI GLM_PIf
#define CGLM_PI_2 GLM_PI_2f
#define CGLM_PI_4 GLM_PI_4f
#endif /* cglm_types_h */ #endif /* cglm_types_h */

View File

@@ -58,7 +58,7 @@ glm_signf(float val) {
CGLM_INLINE CGLM_INLINE
float float
glm_rad(float deg) { glm_rad(float deg) {
return deg * CGLM_PI / 180.0f; return deg * GLM_PIf / 180.0f;
} }
/*! /*!
@@ -69,7 +69,7 @@ glm_rad(float deg) {
CGLM_INLINE CGLM_INLINE
float float
glm_deg(float rad) { glm_deg(float rad) {
return rad * 180.0f / CGLM_PI; return rad * 180.0f / GLM_PIf;
} }
/*! /*!
@@ -80,7 +80,7 @@ glm_deg(float rad) {
CGLM_INLINE CGLM_INLINE
void void
glm_make_rad(float *deg) { glm_make_rad(float *deg) {
*deg = *deg * CGLM_PI / 180.0f; *deg = *deg * GLM_PIf / 180.0f;
} }
/*! /*!
@@ -91,7 +91,7 @@ glm_make_rad(float *deg) {
CGLM_INLINE CGLM_INLINE
void void
glm_make_deg(float *rad) { glm_make_deg(float *rad) {
*rad = *rad * 180.0f / CGLM_PI; *rad = *rad * 180.0f / GLM_PIf;
} }
/*! /*!

View File

@@ -11,15 +11,19 @@
/* /*
Functions: Functions:
CGLM_INLINE void glm_vec_mulv(vec3 a, vec3 b, vec3 d); CGLM_INLINE void glm_vec3_broadcast(float val, vec3 d);
CGLM_INLINE void glm_vec_broadcast(float val, vec3 d); CGLM_INLINE bool glm_vec3_eq(vec3 v, float val);
CGLM_INLINE bool glm_vec_eq(vec3 v, float val); CGLM_INLINE bool glm_vec3_eq_eps(vec3 v, float val);
CGLM_INLINE bool glm_vec_eq_eps(vec3 v, float val); CGLM_INLINE bool glm_vec3_eq_all(vec3 v);
CGLM_INLINE bool glm_vec_eq_all(vec3 v); CGLM_INLINE bool glm_vec3_eqv(vec3 a, vec3 b);
CGLM_INLINE bool glm_vec_eqv(vec3 v1, vec3 v2); CGLM_INLINE bool glm_vec3_eqv_eps(vec3 a, vec3 b);
CGLM_INLINE bool glm_vec_eqv_eps(vec3 v1, vec3 v2); CGLM_INLINE float glm_vec3_max(vec3 v);
CGLM_INLINE float glm_vec_max(vec3 v); CGLM_INLINE float glm_vec3_min(vec3 v);
CGLM_INLINE float glm_vec_min(vec3 v); CGLM_INLINE bool glm_vec3_isnan(vec3 v);
CGLM_INLINE bool glm_vec3_isinf(vec3 v);
CGLM_INLINE bool glm_vec3_isvalid(vec3 v);
CGLM_INLINE void glm_vec3_sign(vec3 v, vec3 dest);
CGLM_INLINE void glm_vec3_sqrt(vec3 v, vec3 dest);
*/ */
#ifndef cglm_vec3_ext_h #ifndef cglm_vec3_ext_h
@@ -31,21 +35,6 @@
#include <math.h> #include <math.h>
#include <float.h> #include <float.h>
/*!
* @brief DEPRECATED! use glm_vec_mul
*
* @param[in] a vec1
* @param[in] b vec2
* @param[out] d vec3 = (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2])
*/
CGLM_INLINE
void
glm_vec_mulv(vec3 a, vec3 b, vec3 d) {
d[0] = a[0] * b[0];
d[1] = a[1] * b[1];
d[2] = a[2] * b[2];
}
/*! /*!
* @brief fill a vector with specified value * @brief fill a vector with specified value
* *
@@ -54,7 +43,7 @@ glm_vec_mulv(vec3 a, vec3 b, vec3 d) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_broadcast(float val, vec3 d) { glm_vec3_broadcast(float val, vec3 d) {
d[0] = d[1] = d[2] = val; d[0] = d[1] = d[2] = val;
} }
@@ -66,7 +55,7 @@ glm_vec_broadcast(float val, vec3 d) {
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec_eq(vec3 v, float val) { glm_vec3_eq(vec3 v, float val) {
return v[0] == val && v[0] == v[1] && v[0] == v[2]; return v[0] == val && v[0] == v[1] && v[0] == v[2];
} }
@@ -78,7 +67,7 @@ glm_vec_eq(vec3 v, float val) {
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec_eq_eps(vec3 v, float val) { glm_vec3_eq_eps(vec3 v, float val) {
return fabsf(v[0] - val) <= FLT_EPSILON return fabsf(v[0] - val) <= FLT_EPSILON
&& fabsf(v[1] - val) <= FLT_EPSILON && fabsf(v[1] - val) <= FLT_EPSILON
&& fabsf(v[2] - val) <= FLT_EPSILON; && fabsf(v[2] - val) <= FLT_EPSILON;
@@ -91,36 +80,36 @@ glm_vec_eq_eps(vec3 v, float val) {
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec_eq_all(vec3 v) { glm_vec3_eq_all(vec3 v) {
return v[0] == v[1] && v[0] == v[2]; return v[0] == v[1] && v[0] == v[2];
} }
/*! /*!
* @brief check if vector is equal to another (without epsilon) * @brief check if vector is equal to another (without epsilon)
* *
* @param[in] v1 vector * @param[in] a vector
* @param[in] v2 vector * @param[in] b vector
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec_eqv(vec3 v1, vec3 v2) { glm_vec3_eqv(vec3 a, vec3 b) {
return v1[0] == v2[0] return a[0] == b[0]
&& v1[1] == v2[1] && a[1] == b[1]
&& v1[2] == v2[2]; && a[2] == b[2];
} }
/*! /*!
* @brief check if vector is equal to another (with epsilon) * @brief check if vector is equal to another (with epsilon)
* *
* @param[in] v1 vector * @param[in] a vector
* @param[in] v2 vector * @param[in] b vector
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec_eqv_eps(vec3 v1, vec3 v2) { glm_vec3_eqv_eps(vec3 a, vec3 b) {
return fabsf(v1[0] - v2[0]) <= FLT_EPSILON return fabsf(a[0] - b[0]) <= FLT_EPSILON
&& fabsf(v1[1] - v2[1]) <= FLT_EPSILON && fabsf(a[1] - b[1]) <= FLT_EPSILON
&& fabsf(v1[2] - v2[2]) <= FLT_EPSILON; && fabsf(a[2] - b[2]) <= FLT_EPSILON;
} }
/*! /*!
@@ -130,7 +119,7 @@ glm_vec_eqv_eps(vec3 v1, vec3 v2) {
*/ */
CGLM_INLINE CGLM_INLINE
float float
glm_vec_max(vec3 v) { glm_vec3_max(vec3 v) {
float max; float max;
max = v[0]; max = v[0];
@@ -149,7 +138,7 @@ glm_vec_max(vec3 v) {
*/ */
CGLM_INLINE CGLM_INLINE
float float
glm_vec_min(vec3 v) { glm_vec3_min(vec3 v) {
float min; float min;
min = v[0]; min = v[0];
@@ -169,7 +158,7 @@ glm_vec_min(vec3 v) {
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec_isnan(vec3 v) { glm_vec3_isnan(vec3 v) {
return isnan(v[0]) || isnan(v[1]) || isnan(v[2]); return isnan(v[0]) || isnan(v[1]) || isnan(v[2]);
} }
@@ -181,7 +170,7 @@ glm_vec_isnan(vec3 v) {
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec_isinf(vec3 v) { glm_vec3_isinf(vec3 v) {
return isinf(v[0]) || isinf(v[1]) || isinf(v[2]); return isinf(v[0]) || isinf(v[1]) || isinf(v[2]);
} }
@@ -193,8 +182,8 @@ glm_vec_isinf(vec3 v) {
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec_isvalid(vec3 v) { glm_vec3_isvalid(vec3 v) {
return !glm_vec_isnan(v) && !glm_vec_isinf(v); return !glm_vec3_isnan(v) && !glm_vec3_isinf(v);
} }
/*! /*!
@@ -206,7 +195,7 @@ glm_vec_isvalid(vec3 v) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_sign(vec3 v, vec3 dest) { glm_vec3_sign(vec3 v, vec3 dest) {
dest[0] = glm_signf(v[0]); dest[0] = glm_signf(v[0]);
dest[1] = glm_signf(v[1]); dest[1] = glm_signf(v[1]);
dest[2] = glm_signf(v[2]); dest[2] = glm_signf(v[2]);
@@ -220,7 +209,7 @@ glm_vec_sign(vec3 v, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_sqrt(vec3 v, vec3 dest) { glm_vec3_sqrt(vec3 v, vec3 dest) {
dest[0] = sqrtf(v[0]); dest[0] = sqrtf(v[0]);
dest[1] = sqrtf(v[1]); dest[1] = sqrtf(v[1]);
dest[2] = sqrtf(v[2]); dest[2] = sqrtf(v[2]);

View File

@@ -5,14 +5,8 @@
* Full license can be found in the LICENSE file * Full license can be found in the LICENSE file
*/ */
/*!
* vec3 functions dont have suffix e.g glm_vec_dot (not glm_vec3_dot)
* all functions without suffix are vec3 functions
*/
/* /*
Macros: Macros:
glm_vec_dup(v, dest)
GLM_VEC3_ONE_INIT GLM_VEC3_ONE_INIT
GLM_VEC3_ZERO_INIT GLM_VEC3_ZERO_INIT
GLM_VEC3_ONE GLM_VEC3_ONE
@@ -23,44 +17,63 @@
Functions: Functions:
CGLM_INLINE void glm_vec3(vec4 v4, vec3 dest); CGLM_INLINE void glm_vec3(vec4 v4, vec3 dest);
CGLM_INLINE void glm_vec_copy(vec3 a, vec3 dest); CGLM_INLINE void glm_vec3_copy(vec3 a, vec3 dest);
CGLM_INLINE float glm_vec_dot(vec3 a, vec3 b); CGLM_INLINE void glm_vec3_zero(vec3 v);
CGLM_INLINE void glm_vec_cross(vec3 a, vec3 b, vec3 d); CGLM_INLINE void glm_vec3_one(vec3 v);
CGLM_INLINE float glm_vec_norm2(vec3 v); CGLM_INLINE float glm_vec3_dot(vec3 a, vec3 b);
CGLM_INLINE float glm_vec_norm(vec3 vec); CGLM_INLINE void glm_vec3_cross(vec3 a, vec3 b, vec3 d);
CGLM_INLINE void glm_vec_add(vec3 a, vec3 b, vec3 dest); CGLM_INLINE float glm_vec3_norm2(vec3 v);
CGLM_INLINE void glm_vec_adds(vec3 a, float s, vec3 dest); CGLM_INLINE float glm_vec3_norm(vec3 v);
CGLM_INLINE void glm_vec_sub(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_add(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec_subs(vec3 a, float s, vec3 dest); CGLM_INLINE void glm_vec3_adds(vec3 a, float s, vec3 dest);
CGLM_INLINE void glm_vec_mul(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_sub(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec_scale(vec3 v, float s, vec3 dest); CGLM_INLINE void glm_vec3_subs(vec3 a, float s, vec3 dest);
CGLM_INLINE void glm_vec_scale_as(vec3 v, float s, vec3 dest); CGLM_INLINE void glm_vec3_mul(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec_div(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_scale(vec3 v, float s, vec3 dest);
CGLM_INLINE void glm_vec_divs(vec3 a, float s, vec3 dest); CGLM_INLINE void glm_vec3_scale_as(vec3 v, float s, vec3 dest);
CGLM_INLINE void glm_vec_addadd(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_div(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec_subadd(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_divs(vec3 a, float s, vec3 dest);
CGLM_INLINE void glm_vec_muladd(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_addadd(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec_flipsign(vec3 v); CGLM_INLINE void glm_vec3_subadd(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec_inv(vec3 v); CGLM_INLINE void glm_vec3_muladd(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec_inv_to(vec3 v, vec3 dest); CGLM_INLINE void glm_vec3_muladds(vec3 a, float s, vec3 dest);
CGLM_INLINE void glm_vec_normalize(vec3 v); CGLM_INLINE void glm_vec3_maxadd(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec_normalize_to(vec3 vec, vec3 dest); CGLM_INLINE void glm_vec3_minadd(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE float glm_vec_distance(vec3 v1, vec3 v2); CGLM_INLINE void glm_vec3_flipsign(vec3 v);
CGLM_INLINE float glm_vec_angle(vec3 v1, vec3 v2); CGLM_INLINE void glm_vec3_flipsign_to(vec3 v, vec3 dest);
CGLM_INLINE void glm_vec_rotate(vec3 v, float angle, vec3 axis); CGLM_INLINE void glm_vec3_negate_to(vec3 v, vec3 dest);
CGLM_INLINE void glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest); CGLM_INLINE void glm_vec3_negate(vec3 v);
CGLM_INLINE void glm_vec_proj(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_inv(vec3 v);
CGLM_INLINE void glm_vec_center(vec3 v1, vec3 v2, vec3 dest); CGLM_INLINE void glm_vec3_inv_to(vec3 v, vec3 dest);
CGLM_INLINE void glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest); CGLM_INLINE void glm_vec3_normalize(vec3 v);
CGLM_INLINE void glm_vec_minv(vec3 v1, vec3 v2, vec3 dest); CGLM_INLINE void glm_vec3_normalize_to(vec3 v, vec3 dest);
CGLM_INLINE void glm_vec_ortho(vec3 v, vec3 dest); CGLM_INLINE float glm_vec3_distance(vec3 a, vec3 b);
CGLM_INLINE void glm_vec_clamp(vec3 v, float minVal, float maxVal); 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_m4(mat4 m, vec3 v, vec3 dest);
CGLM_INLINE void glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest);
CGLM_INLINE void glm_vec3_proj(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec3_center(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE float glm_vec3_distance2(vec3 a, vec3 b);
CGLM_INLINE void glm_vec3_maxv(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec3_minv(vec3 a, vec3 b, vec3 dest);
CGLM_INLINE void glm_vec3_ortho(vec3 v, vec3 dest);
CGLM_INLINE void glm_vec3_clamp(vec3 v, float minVal, float maxVal);
CGLM_INLINE void glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest);
Convenient: Convenient:
CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d); CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d);
CGLM_INLINE float glm_dot(vec3 a, vec3 b); CGLM_INLINE float glm_dot(vec3 a, vec3 b);
CGLM_INLINE void glm_normalize(vec3 v); CGLM_INLINE void glm_normalize(vec3 v);
CGLM_INLINE void glm_normalize_to(vec3 v, vec3 dest); CGLM_INLINE void glm_normalize_to(vec3 v, vec3 dest);
DEPRECATED:
glm_vec3_dup
glm_vec3_flipsign
glm_vec3_flipsign_to
glm_vec3_inv
glm_vec3_inv_to
glm_vec3_mulv
*/ */
#ifndef cglm_vec3_h #ifndef cglm_vec3_h
@@ -72,7 +85,12 @@
#include "util.h" #include "util.h"
/* DEPRECATED! use _copy, _ucopy versions */ /* DEPRECATED! use _copy, _ucopy versions */
#define glm_vec_dup(v, dest) glm_vec_copy(v, dest) #define glm_vec3_dup(v, dest) glm_vec3_copy(v, dest)
#define glm_vec3_flipsign(v) glm_vec3_negate(v)
#define glm_vec3_flipsign_to(v, dest) glm_vec3_negate_to(v, dest)
#define glm_vec3_inv(v) glm_vec3_negate(v)
#define glm_vec3_inv_to(v, dest) glm_vec3_negate_to(v, dest)
#define glm_vec3_mulv(a, b, d) glm_vec3_mul(a, b, d)
#define GLM_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f} #define GLM_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f}
#define GLM_VEC3_ZERO_INIT {0.0f, 0.0f, 0.0f} #define GLM_VEC3_ZERO_INIT {0.0f, 0.0f, 0.0f}
@@ -106,7 +124,7 @@ glm_vec3(vec4 v4, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_copy(vec3 a, vec3 dest) { glm_vec3_copy(vec3 a, vec3 dest) {
dest[0] = a[0]; dest[0] = a[0];
dest[1] = a[1]; dest[1] = a[1];
dest[2] = a[2]; dest[2] = a[2];
@@ -119,10 +137,8 @@ glm_vec_copy(vec3 a, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_zero(vec3 v) { glm_vec3_zero(vec3 v) {
v[0] = 0.0f; v[0] = v[1] = v[2] = 0.0f;
v[1] = 0.0f;
v[2] = 0.0f;
} }
/*! /*!
@@ -132,10 +148,8 @@ glm_vec_zero(vec3 v) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_one(vec3 v) { glm_vec3_one(vec3 v) {
v[0] = 1.0f; v[0] = v[1] = v[2] = 1.0f;
v[1] = 1.0f;
v[2] = 1.0f;
} }
/*! /*!
@@ -148,7 +162,7 @@ glm_vec_one(vec3 v) {
*/ */
CGLM_INLINE CGLM_INLINE
float float
glm_vec_dot(vec3 a, vec3 b) { 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];
} }
@@ -161,7 +175,7 @@ glm_vec_dot(vec3 a, vec3 b) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_cross(vec3 a, vec3 b, vec3 d) { glm_vec3_cross(vec3 a, vec3 b, vec3 d) {
/* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */
d[0] = a[1] * b[2] - a[2] * b[1]; d[0] = a[1] * b[2] - a[2] * b[1];
d[1] = a[2] * b[0] - a[0] * b[2]; d[1] = a[2] * b[0] - a[0] * b[2];
@@ -181,21 +195,21 @@ glm_vec_cross(vec3 a, vec3 b, vec3 d) {
*/ */
CGLM_INLINE CGLM_INLINE
float float
glm_vec_norm2(vec3 v) { glm_vec3_norm2(vec3 v) {
return glm_vec_dot(v, v); return glm_vec3_dot(v, v);
} }
/*! /*!
* @brief norm (magnitude) of vec3 * @brief norm (magnitude) of vec3
* *
* @param[in] vec vector * @param[in] v vector
* *
* @return norm * @return norm
*/ */
CGLM_INLINE CGLM_INLINE
float float
glm_vec_norm(vec3 vec) { glm_vec3_norm(vec3 v) {
return sqrtf(glm_vec_norm2(vec)); return sqrtf(glm_vec3_norm2(v));
} }
/*! /*!
@@ -207,7 +221,7 @@ glm_vec_norm(vec3 vec) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_add(vec3 a, vec3 b, vec3 dest) { glm_vec3_add(vec3 a, vec3 b, vec3 dest) {
dest[0] = a[0] + b[0]; dest[0] = a[0] + b[0];
dest[1] = a[1] + b[1]; dest[1] = a[1] + b[1];
dest[2] = a[2] + b[2]; dest[2] = a[2] + b[2];
@@ -222,14 +236,14 @@ glm_vec_add(vec3 a, vec3 b, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_adds(vec3 v, float s, vec3 dest) { glm_vec3_adds(vec3 v, float s, vec3 dest) {
dest[0] = v[0] + s; dest[0] = v[0] + s;
dest[1] = v[1] + s; dest[1] = v[1] + s;
dest[2] = v[2] + s; dest[2] = v[2] + s;
} }
/*! /*!
* @brief subtract v2 vector from v1 vector store result in dest * @brief subtract b vector from a vector store result in dest
* *
* @param[in] a vector1 * @param[in] a vector1
* @param[in] b vector2 * @param[in] b vector2
@@ -237,7 +251,7 @@ glm_vec_adds(vec3 v, float s, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_sub(vec3 a, vec3 b, vec3 dest) { glm_vec3_sub(vec3 a, vec3 b, vec3 dest) {
dest[0] = a[0] - b[0]; dest[0] = a[0] - b[0];
dest[1] = a[1] - b[1]; dest[1] = a[1] - b[1];
dest[2] = a[2] - b[2]; dest[2] = a[2] - b[2];
@@ -252,7 +266,7 @@ glm_vec_sub(vec3 a, vec3 b, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_subs(vec3 v, float s, vec3 dest) { glm_vec3_subs(vec3 v, float s, vec3 dest) {
dest[0] = v[0] - s; dest[0] = v[0] - s;
dest[1] = v[1] - s; dest[1] = v[1] - s;
dest[2] = v[2] - s; dest[2] = v[2] - s;
@@ -261,16 +275,16 @@ glm_vec_subs(vec3 v, float s, vec3 dest) {
/*! /*!
* @brief multiply two vector (component-wise multiplication) * @brief multiply two vector (component-wise multiplication)
* *
* @param a v1 * @param a vector1
* @param b v2 * @param b vector2
* @param d v3 = (a[0] * b[0], a[1] * b[1], a[2] * b[2]) * @param dest v3 = (a[0] * b[0], a[1] * b[1], a[2] * b[2])
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_mul(vec3 a, vec3 b, vec3 d) { glm_vec3_mul(vec3 a, vec3 b, vec3 dest) {
d[0] = a[0] * b[0]; dest[0] = a[0] * b[0];
d[1] = a[1] * b[1]; dest[1] = a[1] * b[1];
d[2] = a[2] * b[2]; dest[2] = a[2] * b[2];
} }
/*! /*!
@@ -282,7 +296,7 @@ glm_vec_mul(vec3 a, vec3 b, vec3 d) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_scale(vec3 v, float s, vec3 dest) { glm_vec3_scale(vec3 v, float s, vec3 dest) {
dest[0] = v[0] * s; dest[0] = v[0] * s;
dest[1] = v[1] * s; dest[1] = v[1] * s;
dest[2] = v[2] * s; dest[2] = v[2] * s;
@@ -297,16 +311,16 @@ glm_vec_scale(vec3 v, float s, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_scale_as(vec3 v, float s, vec3 dest) { glm_vec3_scale_as(vec3 v, float s, vec3 dest) {
float norm; float norm;
norm = glm_vec_norm(v); norm = glm_vec3_norm(v);
if (norm == 0.0f) { if (norm == 0.0f) {
glm_vec_zero(dest); glm_vec3_zero(dest);
return; return;
} }
glm_vec_scale(v, s / norm, dest); glm_vec3_scale(v, s / norm, dest);
} }
/*! /*!
@@ -318,7 +332,7 @@ glm_vec_scale_as(vec3 v, float s, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_div(vec3 a, vec3 b, vec3 dest) { glm_vec3_div(vec3 a, vec3 b, vec3 dest) {
dest[0] = a[0] / b[0]; dest[0] = a[0] / b[0];
dest[1] = a[1] / b[1]; dest[1] = a[1] / b[1];
dest[2] = a[2] / b[2]; dest[2] = a[2] / b[2];
@@ -333,7 +347,7 @@ glm_vec_div(vec3 a, vec3 b, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_divs(vec3 v, float s, vec3 dest) { glm_vec3_divs(vec3 v, float s, vec3 dest) {
dest[0] = v[0] / s; dest[0] = v[0] / s;
dest[1] = v[1] / s; dest[1] = v[1] / s;
dest[2] = v[2] / s; dest[2] = v[2] / s;
@@ -350,7 +364,7 @@ glm_vec_divs(vec3 v, float s, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_addadd(vec3 a, vec3 b, vec3 dest) { glm_vec3_addadd(vec3 a, vec3 b, vec3 dest) {
dest[0] += a[0] + b[0]; dest[0] += a[0] + b[0];
dest[1] += a[1] + b[1]; dest[1] += a[1] + b[1];
dest[2] += a[2] + b[2]; dest[2] += a[2] + b[2];
@@ -367,7 +381,7 @@ glm_vec_addadd(vec3 a, vec3 b, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_subadd(vec3 a, vec3 b, vec3 dest) { glm_vec3_subadd(vec3 a, vec3 b, vec3 dest) {
dest[0] += a[0] - b[0]; dest[0] += a[0] - b[0];
dest[1] += a[1] - b[1]; dest[1] += a[1] - b[1];
dest[2] += a[2] - b[2]; dest[2] += a[2] - b[2];
@@ -384,7 +398,7 @@ glm_vec_subadd(vec3 a, vec3 b, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_muladd(vec3 a, vec3 b, vec3 dest) { glm_vec3_muladd(vec3 a, vec3 b, vec3 dest) {
dest[0] += a[0] * b[0]; dest[0] += a[0] * b[0];
dest[1] += a[1] * b[1]; dest[1] += a[1] * b[1];
dest[2] += a[2] * b[2]; dest[2] += a[2] * b[2];
@@ -401,60 +415,69 @@ glm_vec_muladd(vec3 a, vec3 b, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_muladds(vec3 a, float s, vec3 dest) { glm_vec3_muladds(vec3 a, float s, vec3 dest) {
dest[0] += a[0] * s; dest[0] += a[0] * s;
dest[1] += a[1] * s; dest[1] += a[1] * s;
dest[2] += a[2] * s; dest[2] += a[2] * s;
} }
/*! /*!
* @brief flip sign of all vec3 members * @brief add max of two vector to result/dest
* *
* @param[in, out] v vector * it applies += operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @param[out] dest dest += max(a, b)
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_flipsign(vec3 v) { glm_vec3_maxadd(vec3 a, vec3 b, vec3 dest) {
v[0] = -v[0]; dest[0] += glm_max(a[0], b[0]);
v[1] = -v[1]; dest[1] += glm_max(a[1], b[1]);
v[2] = -v[2]; dest[2] += glm_max(a[2], b[2]);
} }
/*! /*!
* @brief flip sign of all vec3 members and store result in dest * @brief add min of two vector to result/dest
*
* it applies += operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest += min(a, b)
*/
CGLM_INLINE
void
glm_vec3_minadd(vec3 a, vec3 b, vec3 dest) {
dest[0] += glm_min(a[0], b[0]);
dest[1] += glm_min(a[1], b[1]);
dest[2] += glm_min(a[2], b[2]);
}
/*!
* @brief negate vector components and store result in dest
* *
* @param[in] v vector * @param[in] v vector
* @param[out] dest result vector * @param[out] dest result vector
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_flipsign_to(vec3 v, vec3 dest) { glm_vec3_negate_to(vec3 v, vec3 dest) {
dest[0] = -v[0]; dest[0] = -v[0];
dest[1] = -v[1]; dest[1] = -v[1];
dest[2] = -v[2]; dest[2] = -v[2];
} }
/*! /*!
* @brief make vector as inverse/opposite of itself * @brief negate vector components
* *
* @param[in, out] v vector * @param[in, out] v vector
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_inv(vec3 v) { glm_vec3_negate(vec3 v) {
glm_vec_flipsign(v); glm_vec3_negate_to(v, v);
}
/*!
* @brief inverse/opposite vector
*
* @param[in] v source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec_inv_to(vec3 v, vec3 dest) {
glm_vec_flipsign_to(v, dest);
} }
/*! /*!
@@ -464,56 +487,63 @@ glm_vec_inv_to(vec3 v, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_normalize(vec3 v) { glm_vec3_normalize(vec3 v) {
float norm; float norm;
norm = glm_vec_norm(v); norm = glm_vec3_norm(v);
if (norm == 0.0f) { if (norm == 0.0f) {
v[0] = v[1] = v[2] = 0.0f; v[0] = v[1] = v[2] = 0.0f;
return; return;
} }
glm_vec_scale(v, 1.0f / norm, v); glm_vec3_scale(v, 1.0f / norm, v);
} }
/*! /*!
* @brief normalize vec3 to dest * @brief normalize vec3 to dest
* *
* @param[in] vec source * @param[in] v source
* @param[out] dest destination * @param[out] dest destination
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_normalize_to(vec3 vec, vec3 dest) { glm_vec3_normalize_to(vec3 v, vec3 dest) {
float norm; float norm;
norm = glm_vec_norm(vec); norm = glm_vec3_norm(v);
if (norm == 0.0f) { if (norm == 0.0f) {
glm_vec_zero(dest); glm_vec3_zero(dest);
return; return;
} }
glm_vec_scale(vec, 1.0f / norm, dest); glm_vec3_scale(v, 1.0f / norm, dest);
} }
/*! /*!
* @brief angle betwen two vector * @brief angle betwen two vector
* *
* @param[in] v1 vector1 * @param[in] a vector1
* @param[in] v2 vector2 * @param[in] b vector2
* *
* @return angle as radians * @return angle as radians
*/ */
CGLM_INLINE CGLM_INLINE
float float
glm_vec_angle(vec3 v1, vec3 v2) { glm_vec3_angle(vec3 a, vec3 b) {
float norm; float norm, dot;
/* maybe compiler generate approximation instruction (rcp) */ /* maybe compiler generate approximation instruction (rcp) */
norm = 1.0f / (glm_vec_norm(v1) * glm_vec_norm(v2)); norm = 1.0f / (glm_vec3_norm(a) * glm_vec3_norm(b));
return acosf(glm_vec_dot(v1, v2) * norm); dot = glm_vec3_dot(a, b) * norm;
if (dot > 1.0f)
return 0.0f;
else if (dot < -1.0f)
return CGLM_PI;
return acosf(dot);
} }
/*! /*!
@@ -525,27 +555,27 @@ glm_vec_angle(vec3 v1, vec3 v2) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_rotate(vec3 v, float angle, vec3 axis) { glm_vec3_rotate(vec3 v, float angle, vec3 axis) {
vec3 v1, v2, k; vec3 v1, v2, k;
float c, s; float c, s;
c = cosf(angle); c = cosf(angle);
s = sinf(angle); s = sinf(angle);
glm_vec_normalize_to(axis, k); glm_vec3_normalize_to(axis, k);
/* Right Hand, Rodrigues' rotation formula: /* Right Hand, Rodrigues' rotation formula:
v = v*cos(t) + (kxv)sin(t) + k*(k.v)(1 - cos(t)) v = v*cos(t) + (kxv)sin(t) + k*(k.v)(1 - cos(t))
*/ */
glm_vec_scale(v, c, v1); glm_vec3_scale(v, c, v1);
glm_vec_cross(k, v, v2); glm_vec3_cross(k, v, v2);
glm_vec_scale(v2, s, v2); glm_vec3_scale(v2, s, v2);
glm_vec_add(v1, v2, v1); glm_vec3_add(v1, v2, v1);
glm_vec_scale(k, glm_vec_dot(k, v) * (1.0f - c), v2); glm_vec3_scale(k, glm_vec3_dot(k, v) * (1.0f - c), v2);
glm_vec_add(v1, v2, v); glm_vec3_add(v1, v2, v);
} }
/*! /*!
@@ -563,7 +593,7 @@ glm_vec_rotate(vec3 v, float angle, vec3 axis) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) { glm_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest) {
vec4 x, y, z, res; vec4 x, y, z, res;
glm_vec4_normalize_to(m[0], x); glm_vec4_normalize_to(m[0], x);
@@ -586,7 +616,7 @@ glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_rotate_m3(mat3 m, vec3 v, vec3 dest) { glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest) {
vec4 res, x, y, z; vec4 res, x, y, z;
glm_vec4(m[0], 0.0f, x); glm_vec4(m[0], 0.0f, x);
@@ -607,88 +637,88 @@ glm_vec_rotate_m3(mat3 m, vec3 v, vec3 dest) {
/*! /*!
* @brief project a vector onto b vector * @brief project a vector onto b vector
* *
* @param[in] a vector1 * @param[in] a vector1
* @param[in] b vector2 * @param[in] b vector2
* @param[out] dest projected vector * @param[out] dest projected vector
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_proj(vec3 a, vec3 b, vec3 dest) { glm_vec3_proj(vec3 a, vec3 b, vec3 dest) {
glm_vec_scale(b, glm_vec3_scale(b,
glm_vec_dot(a, b) / glm_vec_norm2(b), glm_vec3_dot(a, b) / glm_vec3_norm2(b),
dest); dest);
} }
/** /**
* @brief find center point of two vector * @brief find center point of two vector
* *
* @param[in] v1 vector1 * @param[in] a vector1
* @param[in] v2 vector2 * @param[in] b vector2
* @param[out] dest center point * @param[out] dest center point
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_center(vec3 v1, vec3 v2, vec3 dest) { glm_vec3_center(vec3 a, vec3 b, vec3 dest) {
glm_vec_add(v1, v2, dest); glm_vec3_add(a, b, dest);
glm_vec_scale(dest, 0.5f, dest); glm_vec3_scale(dest, 0.5f, dest);
} }
/** /**
* @brief squared distance between two vectors * @brief squared distance between two vectors
* *
* @param[in] v1 vector1 * @param[in] a vector1
* @param[in] v2 vector2 * @param[in] b vector2
* @return returns squared distance (distance * distance) * @return returns squared distance (distance * distance)
*/ */
CGLM_INLINE CGLM_INLINE
float float
glm_vec_distance2(vec3 v1, vec3 v2) { glm_vec3_distance2(vec3 a, vec3 b) {
return glm_pow2(v2[0] - v1[0]) return glm_pow2(b[0] - a[0])
+ glm_pow2(v2[1] - v1[1]) + glm_pow2(b[1] - a[1])
+ glm_pow2(v2[2] - v1[2]); + glm_pow2(b[2] - a[2]);
} }
/** /**
* @brief distance between two vectors * @brief distance between two vectors
* *
* @param[in] v1 vector1 * @param[in] a vector1
* @param[in] v2 vector2 * @param[in] b vector2
* @return returns distance * @return returns distance
*/ */
CGLM_INLINE CGLM_INLINE
float float
glm_vec_distance(vec3 v1, vec3 v2) { glm_vec3_distance(vec3 a, vec3 b) {
return sqrtf(glm_vec_distance2(v1, v2)); return sqrtf(glm_vec3_distance2(a, b));
} }
/*! /*!
* @brief max values of vectors * @brief max values of vectors
* *
* @param[in] v1 vector1 * @param[in] a vector1
* @param[in] v2 vector2 * @param[in] b vector2
* @param[out] dest destination * @param[out] dest destination
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest) { glm_vec3_maxv(vec3 a, vec3 b, vec3 dest) {
dest[0] = glm_max(v1[0], v2[0]); dest[0] = glm_max(a[0], b[0]);
dest[1] = glm_max(v1[1], v2[1]); dest[1] = glm_max(a[1], b[1]);
dest[2] = glm_max(v1[2], v2[2]); dest[2] = glm_max(a[2], b[2]);
} }
/*! /*!
* @brief min values of vectors * @brief min values of vectors
* *
* @param[in] v1 vector1 * @param[in] a vector1
* @param[in] v2 vector2 * @param[in] b vector2
* @param[out] dest destination * @param[out] dest destination
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_minv(vec3 v1, vec3 v2, vec3 dest) { glm_vec3_minv(vec3 a, vec3 b, vec3 dest) {
dest[0] = glm_min(v1[0], v2[0]); dest[0] = glm_min(a[0], b[0]);
dest[1] = glm_min(v1[1], v2[1]); dest[1] = glm_min(a[1], b[1]);
dest[2] = glm_min(v1[2], v2[2]); dest[2] = glm_min(a[2], b[2]);
} }
/*! /*!
@@ -699,7 +729,7 @@ glm_vec_minv(vec3 v1, vec3 v2, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_ortho(vec3 v, vec3 dest) { glm_vec3_ortho(vec3 v, vec3 dest) {
dest[0] = v[1] - v[2]; dest[0] = v[1] - v[2];
dest[1] = v[2] - v[0]; dest[1] = v[2] - v[0];
dest[2] = v[0] - v[1]; dest[2] = v[0] - v[1];
@@ -714,7 +744,7 @@ glm_vec_ortho(vec3 v, vec3 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_clamp(vec3 v, float minVal, float maxVal) { glm_vec3_clamp(vec3 v, float minVal, float maxVal) {
v[0] = glm_clamp(v[0], minVal, maxVal); v[0] = glm_clamp(v[0], minVal, maxVal);
v[1] = glm_clamp(v[1], minVal, maxVal); v[1] = glm_clamp(v[1], minVal, maxVal);
v[2] = glm_clamp(v[2], minVal, maxVal); v[2] = glm_clamp(v[2], minVal, maxVal);
@@ -732,14 +762,14 @@ glm_vec_clamp(vec3 v, float minVal, float maxVal) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) { glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) {
vec3 s, v; vec3 s, v;
/* from + s * (to - from) */ /* from + s * (to - from) */
glm_vec_broadcast(glm_clamp_zo(t), s); glm_vec3_broadcast(glm_clamp_zo(t), s);
glm_vec_sub(to, from, v); glm_vec3_sub(to, from, v);
glm_vec_mulv(s, v, v); glm_vec3_mul(s, v, v);
glm_vec_add(from, v, dest); glm_vec3_add(from, v, dest);
} }
/*! /*!
@@ -754,7 +784,7 @@ glm_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_cross(vec3 a, vec3 b, vec3 d) { glm_cross(vec3 a, vec3 b, vec3 d) {
glm_vec_cross(a, b, d); glm_vec3_cross(a, b, d);
} }
/*! /*!
@@ -770,7 +800,7 @@ glm_cross(vec3 a, vec3 b, vec3 d) {
CGLM_INLINE CGLM_INLINE
float float
glm_dot(vec3 a, vec3 b) { glm_dot(vec3 a, vec3 b) {
return glm_vec_dot(a, b); return glm_vec3_dot(a, b);
} }
/*! /*!
@@ -783,7 +813,7 @@ glm_dot(vec3 a, vec3 b) {
CGLM_INLINE CGLM_INLINE
void void
glm_normalize(vec3 v) { glm_normalize(vec3 v) {
glm_vec_normalize(v); glm_vec3_normalize(v);
} }
/*! /*!
@@ -797,7 +827,7 @@ glm_normalize(vec3 v) {
CGLM_INLINE CGLM_INLINE
void void
glm_normalize_to(vec3 v, vec3 dest) { glm_normalize_to(vec3 v, vec3 dest) {
glm_vec_normalize_to(v, dest); glm_vec3_normalize_to(v, dest);
} }
#endif /* cglm_vec3_h */ #endif /* cglm_vec3_h */

View File

@@ -11,15 +11,19 @@
/* /*
Functions: Functions:
CGLM_INLINE void glm_vec4_mulv(vec4 a, vec4 b, vec4 d);
CGLM_INLINE void glm_vec4_broadcast(float val, vec4 d); CGLM_INLINE void glm_vec4_broadcast(float val, vec4 d);
CGLM_INLINE bool glm_vec4_eq(vec4 v, float val); CGLM_INLINE bool glm_vec4_eq(vec4 v, float val);
CGLM_INLINE bool glm_vec4_eq_eps(vec4 v, float val); CGLM_INLINE bool glm_vec4_eq_eps(vec4 v, float val);
CGLM_INLINE bool glm_vec4_eq_all(vec4 v); CGLM_INLINE bool glm_vec4_eq_all(vec4 v);
CGLM_INLINE bool glm_vec4_eqv(vec4 v1, vec4 v2); CGLM_INLINE bool glm_vec4_eqv(vec4 a, vec4 b);
CGLM_INLINE bool glm_vec4_eqv_eps(vec4 v1, vec4 v2); CGLM_INLINE bool glm_vec4_eqv_eps(vec4 a, vec4 b);
CGLM_INLINE float glm_vec4_max(vec4 v); CGLM_INLINE float glm_vec4_max(vec4 v);
CGLM_INLINE float glm_vec4_min(vec4 v); CGLM_INLINE float glm_vec4_min(vec4 v);
CGLM_INLINE bool glm_vec4_isnan(vec4 v);
CGLM_INLINE bool glm_vec4_isinf(vec4 v);
CGLM_INLINE bool glm_vec4_isvalid(vec4 v);
CGLM_INLINE void glm_vec4_sign(vec4 v, vec4 dest);
CGLM_INLINE void glm_vec4_sqrt(vec4 v, vec4 dest);
*/ */
#ifndef cglm_vec4_ext_h #ifndef cglm_vec4_ext_h
@@ -31,26 +35,6 @@
#include <math.h> #include <math.h>
#include <float.h> #include <float.h>
/*!
* @brief DEPRECATED! use glm_vec4_mul
*
* @param a v1
* @param b v2
* @param d v3 = (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2], v1[3] * v2[3])
*/
CGLM_INLINE
void
glm_vec4_mulv(vec4 a, vec4 b, vec4 d) {
#if defined( __SSE__ ) || defined( __SSE2__ )
glmm_store(d, _mm_mul_ps(glmm_load(a), glmm_load(b)));
#else
d[0] = a[0] * b[0];
d[1] = a[1] * b[1];
d[2] = a[2] * b[2];
d[3] = a[3] * b[3];
#endif
}
/*! /*!
* @brief fill a vector with specified value * @brief fill a vector with specified value
* *
@@ -113,31 +97,31 @@ glm_vec4_eq_all(vec4 v) {
/*! /*!
* @brief check if vector is equal to another (without epsilon) * @brief check if vector is equal to another (without epsilon)
* *
* @param v1 vector * @param a vector
* @param v2 vector * @param b vector
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec4_eqv(vec4 v1, vec4 v2) { glm_vec4_eqv(vec4 a, vec4 b) {
return v1[0] == v2[0] return a[0] == b[0]
&& v1[1] == v2[1] && a[1] == b[1]
&& v1[2] == v2[2] && a[2] == b[2]
&& v1[3] == v2[3]; && a[3] == b[3];
} }
/*! /*!
* @brief check if vector is equal to another (with epsilon) * @brief check if vector is equal to another (with epsilon)
* *
* @param v1 vector * @param a vector
* @param v2 vector * @param b vector
*/ */
CGLM_INLINE CGLM_INLINE
bool bool
glm_vec4_eqv_eps(vec4 v1, vec4 v2) { glm_vec4_eqv_eps(vec4 a, vec4 b) {
return fabsf(v1[0] - v2[0]) <= FLT_EPSILON return fabsf(a[0] - b[0]) <= FLT_EPSILON
&& fabsf(v1[1] - v2[1]) <= FLT_EPSILON && fabsf(a[1] - b[1]) <= FLT_EPSILON
&& fabsf(v1[2] - v2[2]) <= FLT_EPSILON && fabsf(a[2] - b[2]) <= FLT_EPSILON
&& fabsf(v1[3] - v2[3]) <= FLT_EPSILON; && fabsf(a[3] - b[3]) <= FLT_EPSILON;
} }
/*! /*!
@@ -150,7 +134,7 @@ float
glm_vec4_max(vec4 v) { glm_vec4_max(vec4 v) {
float max; float max;
max = glm_vec_max(v); max = glm_vec3_max(v);
if (v[3] > max) if (v[3] > max)
max = v[3]; max = v[3];
@@ -167,7 +151,7 @@ float
glm_vec4_min(vec4 v) { glm_vec4_min(vec4 v) {
float min; float min;
min = glm_vec_min(v); min = glm_vec3_min(v);
if (v[3] < min) if (v[3] < min)
min = v[3]; min = v[3];

View File

@@ -5,15 +5,8 @@
* Full license can be found in the LICENSE file * Full license can be found in the LICENSE file
*/ */
/*!
* vec3 functions dont have suffix e.g glm_vec_dot (not glm_vec3_dot)
* all functions without suffix are vec3 functions
*/
/* /*
Macros: Macros:
glm_vec4_dup3(v, dest)
glm_vec4_dup(v, dest)
GLM_VEC4_ONE_INIT GLM_VEC4_ONE_INIT
GLM_VEC4_BLACK_INIT GLM_VEC4_BLACK_INIT
GLM_VEC4_ZERO_INIT GLM_VEC4_ZERO_INIT
@@ -28,7 +21,7 @@
CGLM_INLINE void glm_vec4_ucopy(vec4 v, vec4 dest); CGLM_INLINE void glm_vec4_ucopy(vec4 v, vec4 dest);
CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b); CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b);
CGLM_INLINE float glm_vec4_norm2(vec4 v); CGLM_INLINE float glm_vec4_norm2(vec4 v);
CGLM_INLINE float glm_vec4_norm(vec4 vec); CGLM_INLINE float glm_vec4_norm(vec4 v);
CGLM_INLINE void glm_vec4_add(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_add(vec4 a, vec4 b, vec4 dest);
CGLM_INLINE void glm_vec4_adds(vec4 v, float s, vec4 dest); CGLM_INLINE void glm_vec4_adds(vec4 v, float s, vec4 dest);
CGLM_INLINE void glm_vec4_sub(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_sub(vec4 a, vec4 b, vec4 dest);
@@ -41,16 +34,27 @@
CGLM_INLINE void glm_vec4_addadd(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_addadd(vec4 a, vec4 b, vec4 dest);
CGLM_INLINE void glm_vec4_subadd(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_subadd(vec4 a, vec4 b, vec4 dest);
CGLM_INLINE void glm_vec4_muladd(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_muladd(vec4 a, vec4 b, vec4 dest);
CGLM_INLINE void glm_vec4_flipsign(vec4 v); CGLM_INLINE void glm_vec4_muladds(vec4 a, float s, vec4 dest);
CGLM_INLINE void glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest);
CGLM_INLINE void glm_vec4_minadd(vec4 a, vec4 b, vec4 dest);
CGLM_INLINE void glm_vec4_negate(vec4 v);
CGLM_INLINE void glm_vec4_inv(vec4 v); CGLM_INLINE void glm_vec4_inv(vec4 v);
CGLM_INLINE void glm_vec4_inv_to(vec4 v, vec4 dest); CGLM_INLINE void glm_vec4_inv_to(vec4 v, vec4 dest);
CGLM_INLINE void glm_vec4_normalize(vec4 v); CGLM_INLINE void glm_vec4_normalize(vec4 v);
CGLM_INLINE void glm_vec4_normalize_to(vec4 vec, vec4 dest); CGLM_INLINE void glm_vec4_normalize_to(vec4 vec, vec4 dest);
CGLM_INLINE float glm_vec4_distance(vec4 v1, vec4 v2); CGLM_INLINE float glm_vec4_distance(vec4 a, vec4 b);
CGLM_INLINE void glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest); CGLM_INLINE void glm_vec4_maxv(vec4 a, vec4 b, vec4 dest);
CGLM_INLINE void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest); CGLM_INLINE void glm_vec4_minv(vec4 a, vec4 b, vec4 dest);
CGLM_INLINE void glm_vec4_clamp(vec4 v, float minVal, float maxVal); CGLM_INLINE void glm_vec4_clamp(vec4 v, float minVal, float maxVal);
CGLM_INLINE void glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) CGLM_INLINE void glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest)
DEPRECATED:
glm_vec4_dup
glm_vec4_flipsign
glm_vec4_flipsign_to
glm_vec4_inv
glm_vec4_inv_to
glm_vec4_mulv
*/ */
#ifndef cglm_vec4_h #ifndef cglm_vec4_h
@@ -60,9 +64,14 @@
#include "vec4-ext.h" #include "vec4-ext.h"
#include "util.h" #include "util.h"
/* DEPRECATED! use _copy, _ucopy versions */ /* DEPRECATED! functions */
#define glm_vec4_dup3(v, dest) glm_vec4_copy3(v, dest) #define glm_vec4_dup3(v, dest) glm_vec4_copy3(v, dest)
#define glm_vec4_dup(v, dest) glm_vec4_copy(v, dest) #define glm_vec4_dup(v, dest) glm_vec4_copy(v, dest)
#define glm_vec4_flipsign(v) glm_vec4_negate(v)
#define glm_vec4_flipsign_to(v, dest) glm_vec4_negate_to(v, dest)
#define glm_vec4_inv(v) glm_vec4_negate(v)
#define glm_vec4_inv_to(v, dest) glm_vec4_negate_to(v, dest)
#define glm_vec4_mulv(a, b, d) glm_vec4_mul(a, b, d)
#define GLM_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f} #define GLM_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f}
#define GLM_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f} #define GLM_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f}
@@ -223,24 +232,24 @@ glm_vec4_norm2(vec4 v) {
/*! /*!
* @brief norm (magnitude) of vec4 * @brief norm (magnitude) of vec4
* *
* @param[in] vec vector * @param[in] v vector
* *
* @return norm * @return norm
*/ */
CGLM_INLINE CGLM_INLINE
float float
glm_vec4_norm(vec4 vec) { glm_vec4_norm(vec4 v) {
#if defined( __SSE__ ) || defined( __SSE2__ ) #if defined( __SSE__ ) || defined( __SSE2__ )
__m128 x0; __m128 x0;
x0 = glmm_load(vec); x0 = glmm_load(v);
return _mm_cvtss_f32(_mm_sqrt_ss(glmm_dot(x0, x0))); return _mm_cvtss_f32(_mm_sqrt_ss(glmm_dot(x0, x0)));
#else #else
return sqrtf(glm_vec4_norm2(vec)); return sqrtf(glm_vec4_norm2(v));
#endif #endif
} }
/*! /*!
* @brief add v2 vector to v1 vector store result in dest * @brief add b vector to a vector store result in dest
* *
* @param[in] a vector1 * @param[in] a vector1
* @param[in] b vector2 * @param[in] b vector2
@@ -280,7 +289,7 @@ glm_vec4_adds(vec4 v, float s, vec4 dest) {
} }
/*! /*!
* @brief subtract b vector from a vector store result in dest (d = v1 - v2) * @brief subtract b vector from a vector store result in dest (d = a - b)
* *
* @param[in] a vector1 * @param[in] a vector1
* @param[in] b vector2 * @param[in] b vector2
@@ -322,20 +331,20 @@ glm_vec4_subs(vec4 v, float s, vec4 dest) {
/*! /*!
* @brief multiply two vector (component-wise multiplication) * @brief multiply two vector (component-wise multiplication)
* *
* @param a v1 * @param a vector1
* @param b v2 * @param b vector2
* @param d v3 = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]) * @param d dest = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3])
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec4_mul(vec4 a, vec4 b, vec4 d) { glm_vec4_mul(vec4 a, vec4 b, vec4 dest) {
#if defined( __SSE__ ) || defined( __SSE2__ ) #if defined( __SSE__ ) || defined( __SSE2__ )
glmm_store(d, _mm_mul_ps(glmm_load(a), glmm_load(b))); glmm_store(dest, _mm_mul_ps(glmm_load(a), glmm_load(b)));
#else #else
d[0] = a[0] * b[0]; dest[0] = a[0] * b[0];
d[1] = a[1] * b[1]; dest[1] = a[1] * b[1];
d[2] = a[2] * b[2]; dest[2] = a[2] * b[2];
d[3] = a[3] * b[3]; dest[3] = a[3] * b[3];
#endif #endif
} }
@@ -381,7 +390,7 @@ glm_vec4_scale_as(vec4 v, float s, vec4 dest) {
} }
/*! /*!
* @brief div vector with another component-wise division: d = v1 / v2 * @brief div vector with another component-wise division: d = a / b
* *
* @param[in] a vector 1 * @param[in] a vector 1
* @param[in] b vector 2 * @param[in] b vector 2
@@ -515,32 +524,62 @@ glm_vec4_muladds(vec4 a, float s, vec4 dest) {
} }
/*! /*!
* @brief flip sign of all vec4 members * @brief add max of two vector to result/dest
* *
* @param[in, out] v vector * it applies += operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @param[out] dest dest += max(a, b)
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec4_flipsign(vec4 v) { glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest) {
#if defined( __SSE__ ) || defined( __SSE2__ ) #if defined( __SSE__ ) || defined( __SSE2__ )
glmm_store(v, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); glmm_store(dest, _mm_add_ps(glmm_load(dest),
_mm_max_ps(glmm_load(a),
glmm_load(b))));
#else #else
v[0] = -v[0]; dest[0] += glm_max(a[0], b[0]);
v[1] = -v[1]; dest[1] += glm_max(a[1], b[1]);
v[2] = -v[2]; dest[2] += glm_max(a[2], b[2]);
v[3] = -v[3]; dest[3] += glm_max(a[3], b[3]);
#endif #endif
} }
/*! /*!
* @brief flip sign of all vec4 members and store result in dest * @brief add min of two vector to result/dest
* *
* @param[in] v vector * it applies += operator so dest must be initialized
* @param[out] dest vector *
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest += min(a, b)
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec4_flipsign_to(vec4 v, vec4 dest) { glm_vec4_minadd(vec4 a, vec4 b, vec4 dest) {
#if defined( __SSE__ ) || defined( __SSE2__ )
glmm_store(dest, _mm_add_ps(glmm_load(dest),
_mm_min_ps(glmm_load(a),
glmm_load(b))));
#else
dest[0] += glm_min(a[0], b[0]);
dest[1] += glm_min(a[1], b[1]);
dest[2] += glm_min(a[2], b[2]);
dest[3] += glm_min(a[3], b[3]);
#endif
}
/*!
* @brief negate vector components and store result in dest
*
* @param[in] v vector
* @param[out] dest result vector
*/
CGLM_INLINE
void
glm_vec4_negate_to(vec4 v, vec4 dest) {
#if defined( __SSE__ ) || defined( __SSE2__ ) #if defined( __SSE__ ) || defined( __SSE2__ )
glmm_store(dest, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); glmm_store(dest, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f)));
#else #else
@@ -552,43 +591,30 @@ glm_vec4_flipsign_to(vec4 v, vec4 dest) {
} }
/*! /*!
* @brief make vector as inverse/opposite of itself * @brief flip sign of all vec4 members
* *
* @param[in, out] v vector * @param[in, out] v vector
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec4_inv(vec4 v) { glm_vec4_negate(vec4 v) {
glm_vec4_flipsign(v); glm_vec4_negate_to(v, v);
} }
/*! /*!
* @brief inverse/opposite vector * @brief normalize vec4 to dest
* *
* @param[in] v source * @param[in] v source
* @param[out] dest destination * @param[out] dest destination
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec4_inv_to(vec4 v, vec4 dest) { glm_vec4_normalize_to(vec4 v, vec4 dest) {
glm_vec4_copy(v, dest);
glm_vec4_flipsign(dest);
}
/*!
* @brief normalize vec4 to dest
*
* @param[in] vec source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_vec4_normalize_to(vec4 vec, vec4 dest) {
#if defined( __SSE__ ) || defined( __SSE2__ ) #if defined( __SSE__ ) || defined( __SSE2__ )
__m128 xdot, x0; __m128 xdot, x0;
float dot; float dot;
x0 = glmm_load(vec); x0 = glmm_load(v);
xdot = glmm_dot(x0, x0); xdot = glmm_dot(x0, x0);
dot = _mm_cvtss_f32(xdot); dot = _mm_cvtss_f32(xdot);
@@ -601,14 +627,14 @@ glm_vec4_normalize_to(vec4 vec, vec4 dest) {
#else #else
float norm; float norm;
norm = glm_vec4_norm(vec); norm = glm_vec4_norm(v);
if (norm == 0.0f) { if (norm == 0.0f) {
glm_vec4_zero(dest); glm_vec4_zero(dest);
return; return;
} }
glm_vec4_scale(vec, 1.0f / norm, dest); glm_vec4_scale(v, 1.0f / norm, dest);
#endif #endif
} }
@@ -626,56 +652,56 @@ glm_vec4_normalize(vec4 v) {
/** /**
* @brief distance between two vectors * @brief distance between two vectors
* *
* @param[in] v1 vector1 * @param[in] a vector1
* @param[in] v2 vector2 * @param[in] b vector2
* @return returns distance * @return returns distance
*/ */
CGLM_INLINE CGLM_INLINE
float float
glm_vec4_distance(vec4 v1, vec4 v2) { glm_vec4_distance(vec4 a, vec4 b) {
return sqrtf(glm_pow2(v2[0] - v1[0]) return sqrtf(glm_pow2(b[0] - a[0])
+ glm_pow2(v2[1] - v1[1]) + glm_pow2(b[1] - a[1])
+ glm_pow2(v2[2] - v1[2]) + glm_pow2(b[2] - a[2])
+ glm_pow2(v2[3] - v1[3])); + glm_pow2(b[3] - a[3]));
} }
/*! /*!
* @brief max values of vectors * @brief max values of vectors
* *
* @param[in] v1 vector1 * @param[in] a vector1
* @param[in] v2 vector2 * @param[in] b vector2
* @param[out] dest destination * @param[out] dest destination
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest) { glm_vec4_maxv(vec4 a, vec4 b, vec4 dest) {
#if defined( __SSE__ ) || defined( __SSE2__ ) #if defined( __SSE__ ) || defined( __SSE2__ )
glmm_store(dest, _mm_max_ps(glmm_load(v1), glmm_load(v2))); glmm_store(dest, _mm_max_ps(glmm_load(a), glmm_load(b)));
#else #else
dest[0] = glm_max(v1[0], v2[0]); dest[0] = glm_max(a[0], b[0]);
dest[1] = glm_max(v1[1], v2[1]); dest[1] = glm_max(a[1], b[1]);
dest[2] = glm_max(v1[2], v2[2]); dest[2] = glm_max(a[2], b[2]);
dest[3] = glm_max(v1[3], v2[3]); dest[3] = glm_max(a[3], b[3]);
#endif #endif
} }
/*! /*!
* @brief min values of vectors * @brief min values of vectors
* *
* @param[in] v1 vector1 * @param[in] a vector1
* @param[in] v2 vector2 * @param[in] b vector2
* @param[out] dest destination * @param[out] dest destination
*/ */
CGLM_INLINE CGLM_INLINE
void void
glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { glm_vec4_minv(vec4 a, vec4 b, vec4 dest) {
#if defined( __SSE__ ) || defined( __SSE2__ ) #if defined( __SSE__ ) || defined( __SSE2__ )
glmm_store(dest, _mm_min_ps(glmm_load(v1), glmm_load(v2))); glmm_store(dest, _mm_min_ps(glmm_load(a), glmm_load(b)));
#else #else
dest[0] = glm_min(v1[0], v2[0]); dest[0] = glm_min(a[0], b[0]);
dest[1] = glm_min(v1[1], v2[1]); dest[1] = glm_min(a[1], b[1]);
dest[2] = glm_min(v1[2], v2[2]); dest[2] = glm_min(a[2], b[2]);
dest[3] = glm_min(v1[3], v2[3]); dest[3] = glm_min(a[3], b[3]);
#endif #endif
} }
@@ -718,7 +744,7 @@ glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) {
/* from + s * (to - from) */ /* from + s * (to - from) */
glm_vec4_broadcast(glm_clamp_zo(t), s); glm_vec4_broadcast(glm_clamp_zo(t), s);
glm_vec4_sub(to, from, v); glm_vec4_sub(to, from, v);
glm_vec4_mulv(s, v, v); glm_vec4_mul(s, v, v);
glm_vec4_add(from, v, dest); glm_vec4_add(from, v, dest);
} }

View File

@@ -9,7 +9,7 @@
#define cglm_version_h #define cglm_version_h
#define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MAJOR 0
#define CGLM_VERSION_MINOR 4 #define CGLM_VERSION_MINOR 5
#define CGLM_VERSION_PATCH 8 #define CGLM_VERSION_PATCH 0
#endif /* cglm_version_h */ #endif /* cglm_version_h */

View File

@@ -20,6 +20,12 @@ glmc_mat3_identity(mat3 mat) {
glm_mat3_identity(mat); glm_mat3_identity(mat);
} }
CGLM_EXPORT
void
glmc_mat3_identity_array(mat3 * __restrict mat, size_t count) {
glm_mat3_identity_array(mat, count);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest) { glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest) {

View File

@@ -26,6 +26,12 @@ glmc_mat4_identity(mat4 mat) {
glm_mat4_identity(mat); glm_mat4_identity(mat);
} }
CGLM_EXPORT
void
glmc_mat4_identity_array(mat4 * __restrict mat, size_t count) {
glm_mat4_identity_array(mat, count);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat4_pick3(mat4 mat, mat3 dest) { glmc_mat4_pick3(mat4 mat, mat3 dest) {

View File

@@ -8,13 +8,18 @@
#include "../include/cglm/cglm.h" #include "../include/cglm/cglm.h"
#include "../include/cglm/call.h" #include "../include/cglm/call.h"
CGLM_EXPORT CGLM_EXPORT
void void
glmc_quat_identity(versor q) { glmc_quat_identity(versor q) {
glm_quat_identity(q); glm_quat_identity(q);
} }
CGLM_EXPORT
void
glmc_quat_identity_array(versor * __restrict q, size_t count) {
glm_quat_identity_array(q, count);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_quat_init(versor q, float x, float y, float z, float w) { glmc_quat_init(versor q, float x, float y, float z, float w) {

View File

@@ -16,320 +16,320 @@ glmc_vec3(vec4 v4, vec3 dest) {
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_copy(vec3 a, vec3 dest) { glmc_vec3_copy(vec3 a, vec3 dest) {
glm_vec_copy(a, dest); glm_vec3_copy(a, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_zero(vec3 v) { glmc_vec3_zero(vec3 v) {
glm_vec_zero(v); glm_vec3_zero(v);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_one(vec3 v) { glmc_vec3_one(vec3 v) {
glm_vec_one(v); glm_vec3_one(v);
} }
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_dot(vec3 a, vec3 b) { glmc_vec3_dot(vec3 a, vec3 b) {
return glm_vec_dot(a, b); return glm_vec3_dot(a, b);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_cross(vec3 a, vec3 b, vec3 d) { glmc_vec3_cross(vec3 a, vec3 b, vec3 d) {
glm_vec_cross(a, b, d); glm_vec3_cross(a, b, d);
} }
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_norm(vec3 vec) { glmc_vec3_norm(vec3 v) {
return glm_vec_norm(vec); return glm_vec3_norm(v);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_normalize_to(vec3 vec, vec3 dest) { glmc_vec3_normalize_to(vec3 v, vec3 dest) {
glm_vec_normalize_to(vec, dest); glm_vec3_normalize_to(v, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_normalize(vec3 v) { glmc_vec3_normalize(vec3 v) {
glm_vec_normalize(v); glm_vec3_normalize(v);
} }
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_norm2(vec3 vec) { glmc_vec3_norm2(vec3 v) {
return glm_vec_norm2(vec); return glm_vec3_norm2(v);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_add(vec3 v1, vec3 v2, vec3 dest) { glmc_vec3_add(vec3 a, vec3 b, vec3 dest) {
glm_vec_add(v1, v2, dest); glm_vec3_add(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_adds(vec3 v, float s, vec3 dest) { glmc_vec3_adds(vec3 v, float s, vec3 dest) {
glm_vec_adds(v, s, dest); glm_vec3_adds(v, s, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_sub(vec3 a, vec3 b, vec3 dest) { glmc_vec3_sub(vec3 a, vec3 b, vec3 dest) {
glm_vec_sub(a, b, dest); glm_vec3_sub(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_subs(vec3 v, float s, vec3 dest) { glmc_vec3_subs(vec3 v, float s, vec3 dest) {
glm_vec_subs(v, s, dest); glm_vec3_subs(v, s, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_mul(vec3 a, vec3 b, vec3 d) { glmc_vec3_mul(vec3 a, vec3 b, vec3 d) {
glm_vec_mul(a, b, d); glm_vec3_mul(a, b, d);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_scale(vec3 v, float s, vec3 dest) { glmc_vec3_scale(vec3 v, float s, vec3 dest) {
glm_vec_scale(v, s, dest); glm_vec3_scale(v, s, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_scale_as(vec3 v, float s, vec3 dest) { glmc_vec3_scale_as(vec3 v, float s, vec3 dest) {
glm_vec_scale_as(v, s, dest); glm_vec3_scale_as(v, s, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_div(vec3 a, vec3 b, vec3 dest) { glmc_vec3_div(vec3 a, vec3 b, vec3 dest) {
glm_vec_div(a, b, dest); glm_vec3_div(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_divs(vec3 a, float s, vec3 dest) { glmc_vec3_divs(vec3 a, float s, vec3 dest) {
glm_vec_divs(a, s, dest); glm_vec3_divs(a, s, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_addadd(vec3 a, vec3 b, vec3 dest) { glmc_vec3_addadd(vec3 a, vec3 b, vec3 dest) {
glm_vec_addadd(a, b, dest); glm_vec3_addadd(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_subadd(vec3 a, vec3 b, vec3 dest) { glmc_vec3_subadd(vec3 a, vec3 b, vec3 dest) {
glm_vec_subadd(a, b, dest); glm_vec3_subadd(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_muladd(vec3 a, vec3 b, vec3 dest) { glmc_vec3_muladd(vec3 a, vec3 b, vec3 dest) {
glm_vec_muladd(a, b, dest); glm_vec3_muladd(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_muladds(vec3 a, float s, vec3 dest) { glmc_vec3_muladds(vec3 a, float s, vec3 dest) {
glm_vec_muladds(a, s, dest); glm_vec3_muladds(a, s, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_flipsign(vec3 v) { glmc_vec3_maxadd(vec3 a, vec3 b, vec3 dest) {
glm_vec_flipsign(v); glm_vec3_maxadd(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_flipsign_to(vec3 v, vec3 dest) { glmc_vec3_minadd(vec3 a, vec3 b, vec3 dest) {
glm_vec_flipsign_to(v, dest); glm_vec3_minadd(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_inv(vec3 v) { glmc_vec3_negate(vec3 v) {
glm_vec_inv(v); glm_vec3_negate(v);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_inv_to(vec3 v, vec3 dest) { glmc_vec3_negate_to(vec3 v, vec3 dest) {
glm_vec_inv_to(v, dest); glm_vec3_negate_to(v, dest);
} }
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_angle(vec3 v1, vec3 v2) { glmc_vec3_angle(vec3 a, vec3 b) {
return glm_vec_angle(v1, v2); return glm_vec3_angle(a, b);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_rotate(vec3 v, float angle, vec3 axis) { glmc_vec3_rotate(vec3 v, float angle, vec3 axis) {
glm_vec_rotate(v, angle, axis); glm_vec3_rotate(v, angle, axis);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) { glmc_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest) {
glm_vec_rotate_m4(m, v, dest); glm_vec3_rotate_m4(m, v, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_rotate_m3(mat3 m, vec3 v, vec3 dest) { glmc_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest) {
glm_vec_rotate_m3(m, v, dest); glm_vec3_rotate_m3(m, v, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_proj(vec3 a, vec3 b, vec3 dest) { glmc_vec3_proj(vec3 a, vec3 b, vec3 dest) {
glm_vec_proj(a, b, dest); glm_vec3_proj(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_center(vec3 v1, vec3 v2, vec3 dest) { glmc_vec3_center(vec3 a, vec3 b, vec3 dest) {
glm_vec_center(v1, v2, dest); glm_vec3_center(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_distance2(vec3 v1, vec3 v2) { glmc_vec3_distance2(vec3 a, vec3 b) {
return glm_vec_distance2(v1, v2); return glm_vec3_distance2(a, b);
} }
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_distance(vec3 v1, vec3 v2) { glmc_vec3_distance(vec3 a, vec3 b) {
return glm_vec_distance(v1, v2); return glm_vec3_distance(a, b);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_maxv(vec3 v1, vec3 v2, vec3 dest) { glmc_vec3_maxv(vec3 a, vec3 b, vec3 dest) {
glm_vec_minv(v1, v2, dest); glm_vec3_minv(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_minv(vec3 v1, vec3 v2, vec3 dest) { glmc_vec3_minv(vec3 a, vec3 b, vec3 dest) {
glm_vec_maxv(v1, v2, dest); glm_vec3_maxv(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_clamp(vec3 v, float minVal, float maxVal) { glmc_vec3_clamp(vec3 v, float minVal, float maxVal) {
glm_vec_clamp(v, minVal, maxVal); glm_vec3_clamp(v, minVal, maxVal);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_ortho(vec3 v, vec3 dest) { glmc_vec3_ortho(vec3 v, vec3 dest) {
glm_vec_ortho(v, dest); glm_vec3_ortho(v, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) { glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) {
glm_vec_lerp(from, to, t, dest); glm_vec3_lerp(from, to, t, dest);
} }
/* ext */ /* ext */
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_mulv(vec3 a, vec3 b, vec3 d) { glmc_vec3_mulv(vec3 a, vec3 b, vec3 d) {
glm_vec_mulv(a, b, d); glm_vec3_mulv(a, b, d);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_broadcast(float val, vec3 d) { glmc_vec3_broadcast(float val, vec3 d) {
glm_vec_broadcast(val, d); glm_vec3_broadcast(val, d);
} }
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_eq(vec3 v, float val) { glmc_vec3_eq(vec3 v, float val) {
return glm_vec_eq(v, val); return glm_vec3_eq(v, val);
} }
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_eq_eps(vec3 v, float val) { glmc_vec3_eq_eps(vec3 v, float val) {
return glm_vec_eq_eps(v, val); return glm_vec3_eq_eps(v, val);
} }
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_eq_all(vec3 v) { glmc_vec3_eq_all(vec3 v) {
return glm_vec_eq_all(v); return glm_vec3_eq_all(v);
} }
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_eqv(vec3 v1, vec3 v2) { glmc_vec3_eqv(vec3 a, vec3 b) {
return glm_vec_eqv(v1, v2); return glm_vec3_eqv(a, b);
} }
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_eqv_eps(vec3 v1, vec3 v2) { glmc_vec3_eqv_eps(vec3 a, vec3 b) {
return glm_vec_eqv_eps(v1, v2); return glm_vec3_eqv_eps(a, b);
} }
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_max(vec3 v) { glmc_vec3_max(vec3 v) {
return glm_vec_max(v); return glm_vec3_max(v);
} }
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec_min(vec3 v) { glmc_vec3_min(vec3 v) {
return glm_vec_min(v); return glm_vec3_min(v);
} }
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_isnan(vec3 v) { glmc_vec3_isnan(vec3 v) {
return glm_vec_isnan(v); return glm_vec3_isnan(v);
} }
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_isinf(vec3 v) { glmc_vec3_isinf(vec3 v) {
return glm_vec_isinf(v); return glm_vec3_isinf(v);
} }
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec_isvalid(vec3 v) { glmc_vec3_isvalid(vec3 v) {
return glm_vec_isvalid(v); return glm_vec3_isvalid(v);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_sign(vec3 v, vec3 dest) { glmc_vec3_sign(vec3 v, vec3 dest) {
glm_vec_sign(v, dest); glm_vec3_sign(v, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec_sqrt(vec3 v, vec3 dest) { glmc_vec3_sqrt(vec3 v, vec3 dest) {
glm_vec_sqrt(v, dest); glm_vec3_sqrt(v, dest);
} }

View File

@@ -28,8 +28,8 @@ glmc_vec4_one(vec4 v) {
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_copy3(vec4 a, vec3 dest) { glmc_vec4_copy3(vec4 v, vec3 dest) {
glm_vec4_copy3(a, dest); glm_vec4_copy3(v, dest);
} }
CGLM_EXPORT CGLM_EXPORT
@@ -52,14 +52,14 @@ glmc_vec4_dot(vec4 a, vec4 b) {
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec4_norm(vec4 vec) { glmc_vec4_norm(vec4 v) {
return glm_vec4_norm(vec); return glm_vec4_norm(v);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_normalize_to(vec4 vec, vec4 dest) { glmc_vec4_normalize_to(vec4 v, vec4 dest) {
glm_vec4_normalize_to(vec, dest); glm_vec4_normalize_to(v, dest);
} }
CGLM_EXPORT CGLM_EXPORT
@@ -70,8 +70,8 @@ glmc_vec4_normalize(vec4 v) {
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec4_norm2(vec4 vec) { glmc_vec4_norm2(vec4 v) {
return glm_vec4_norm2(vec); return glm_vec4_norm2(v);
} }
CGLM_EXPORT CGLM_EXPORT
@@ -154,44 +154,44 @@ glmc_vec4_muladds(vec4 a, float s, vec4 dest) {
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_flipsign(vec4 v) { glmc_vec4_maxadd(vec4 a, vec4 b, vec4 dest) {
glm_vec4_flipsign(v); glm_vec4_maxadd(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_flipsign_to(vec4 v, vec4 dest) { glmc_vec4_minadd(vec4 a, vec4 b, vec4 dest) {
glm_vec4_flipsign_to(v, dest); glm_vec4_minadd(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_inv(vec4 v) { glmc_vec4_negate(vec4 v) {
glm_vec4_inv(v); glm_vec4_negate(v);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_inv_to(vec4 v, vec4 dest) { glmc_vec4_negate_to(vec4 v, vec4 dest) {
glm_vec4_inv_to(v, dest); glm_vec4_negate_to(v, dest);
} }
CGLM_EXPORT CGLM_EXPORT
float float
glmc_vec4_distance(vec4 v1, vec4 v2) { glmc_vec4_distance(vec4 a, vec4 b) {
return glm_vec4_distance(v1, v2); return glm_vec4_distance(a, b);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_maxv(vec4 v1, vec4 v2, vec4 dest) { glmc_vec4_maxv(vec4 a, vec4 b, vec4 dest) {
glm_vec4_minv(v1, v2, dest); glm_vec4_minv(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
void void
glmc_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { glmc_vec4_minv(vec4 a, vec4 b, vec4 dest) {
glm_vec4_maxv(v1, v2, dest); glm_vec4_maxv(a, b, dest);
} }
CGLM_EXPORT CGLM_EXPORT
@@ -240,14 +240,14 @@ glmc_vec4_eq_all(vec4 v) {
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec4_eqv(vec4 v1, vec4 v2) { glmc_vec4_eqv(vec4 a, vec4 b) {
return glm_vec4_eqv(v1, v2); return glm_vec4_eqv(a, b);
} }
CGLM_EXPORT CGLM_EXPORT
bool bool
glmc_vec4_eqv_eps(vec4 v1, vec4 v2) { glmc_vec4_eqv_eps(vec4 a, vec4 b) {
return glm_vec4_eqv_eps(v1, v2); return glm_vec4_eqv_eps(a, b);
} }
CGLM_EXPORT CGLM_EXPORT

View File

@@ -12,7 +12,7 @@ test_affine(void **state) {
mat4 t1, t2, t3, t4, t5; mat4 t1, t2, t3, t4, t5;
/* test translate is postmultiplied */ /* test translate is postmultiplied */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glmc_mat4_mul(t1, t2, t3); /* R * T */ glmc_mat4_mul(t1, t2, t3); /* R * T */
@@ -21,16 +21,16 @@ test_affine(void **state) {
test_assert_mat4_eq(t1, t3); test_assert_mat4_eq(t1, t3);
/* test rotate is postmultiplied */ /* test rotate is postmultiplied */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glmc_mat4_mul(t2, t1, t3); /* T * R */ glmc_mat4_mul(t2, t1, t3); /* T * R */
glm_rotate(t2, M_PI_4, GLM_YUP); glm_rotate(t2, GLM_PI_4f, GLM_YUP);
test_assert_mat4_eq(t2, t3); test_assert_mat4_eq(t2, t3);
/* test scale is postmultiplied */ /* test scale is postmultiplied */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glm_scale_make(t4, (vec3){3, 5, 6}); glm_scale_make(t4, (vec3){3, 5, 6});
@@ -41,7 +41,7 @@ test_affine(void **state) {
test_assert_mat4_eq(t3, t5); test_assert_mat4_eq(t3, t5);
/* test translate_x */ /* test translate_x */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){34, 0, 0}); glm_translate_make(t2, (vec3){34, 0, 0});
glmc_mat4_mul(t1, t2, t3); /* R * T */ glmc_mat4_mul(t1, t2, t3); /* R * T */
@@ -49,7 +49,7 @@ test_affine(void **state) {
test_assert_mat4_eq(t1, t3); test_assert_mat4_eq(t1, t3);
/* test translate_y */ /* test translate_y */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){0, 57, 0}); glm_translate_make(t2, (vec3){0, 57, 0});
glmc_mat4_mul(t1, t2, t3); /* R * T */ glmc_mat4_mul(t1, t2, t3); /* R * T */
@@ -57,7 +57,7 @@ test_affine(void **state) {
test_assert_mat4_eq(t1, t3); test_assert_mat4_eq(t1, t3);
/* test translate_z */ /* test translate_z */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){0, 0, 36}); glm_translate_make(t2, (vec3){0, 0, 36});
glmc_mat4_mul(t1, t2, t3); /* R * T */ glmc_mat4_mul(t1, t2, t3); /* R * T */
@@ -65,43 +65,43 @@ test_affine(void **state) {
test_assert_mat4_eq(t1, t3); test_assert_mat4_eq(t1, t3);
/* test rotate_x */ /* test rotate_x */
glmc_rotate_make(t1, M_PI_4, (vec3){1, 0, 0}); glmc_rotate_make(t1, GLM_PI_4f, (vec3){1, 0, 0});
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glmc_mat4_mul(t2, t1, t3); /* T * R */ glmc_mat4_mul(t2, t1, t3); /* T * R */
glm_rotate_x(t2, M_PI_4, t2); glm_rotate_x(t2, GLM_PI_4f, t2);
test_assert_mat4_eq(t2, t3); test_assert_mat4_eq(t2, t3);
/* test rotate_y */ /* test rotate_y */
glmc_rotate_make(t1, M_PI_4, (vec3){0, 1, 0}); glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 1, 0});
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glmc_mat4_mul(t2, t1, t3); /* T * R */ glmc_mat4_mul(t2, t1, t3); /* T * R */
glm_rotate_y(t2, M_PI_4, t2); glm_rotate_y(t2, GLM_PI_4f, t2);
test_assert_mat4_eq(t2, t3); test_assert_mat4_eq(t2, t3);
/* test rotate_z */ /* test rotate_z */
glmc_rotate_make(t1, M_PI_4, (vec3){0, 0, 1}); glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 0, 1});
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glmc_mat4_mul(t2, t1, t3); /* T * R */ glmc_mat4_mul(t2, t1, t3); /* T * R */
glm_rotate_z(t2, M_PI_4, t2); glm_rotate_z(t2, GLM_PI_4f, t2);
test_assert_mat4_eq(t2, t3); test_assert_mat4_eq(t2, t3);
/* test rotate */ /* test rotate */
glmc_rotate_make(t1, M_PI_4, (vec3){0, 0, 1}); glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 0, 1});
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glmc_mat4_mul(t2, t1, t3); /* T * R */ glmc_mat4_mul(t2, t1, t3); /* T * R */
glmc_rotate(t2, M_PI_4, (vec3){0, 0, 1}); glmc_rotate(t2, GLM_PI_4f, (vec3){0, 0, 1});
test_assert_mat4_eq(t3, t2); test_assert_mat4_eq(t3, t2);
/* test scale_uni */ /* test scale_uni */
glmc_rotate_make(t1, M_PI_4, GLM_YUP); glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
glm_translate_make(t2, (vec3){34, 57, 36}); glm_translate_make(t2, (vec3){34, 57, 36});
glm_scale_make(t4, (vec3){3, 3, 3}); glm_scale_make(t4, (vec3){3, 3, 3});

View File

@@ -16,7 +16,7 @@ test_camera_lookat(void **state) {
up = {0.0f, 1.0f, 0.0f} up = {0.0f, 1.0f, 0.0f}
; ;
glm_vec_add(eye, dir, center); glm_vec3_add(eye, dir, center);
glm_lookat(eye, center, up, view1); glm_lookat(eye, center, up, view1);
glm_look(eye, dir, up, view2); glm_look(eye, dir, up, view2);

View File

@@ -16,7 +16,7 @@ test_clamp(void **state) {
assert_true(glm_clamp(-1.6f, 0.0f, 1.0f) == 0.0f); assert_true(glm_clamp(-1.6f, 0.0f, 1.0f) == 0.0f);
assert_true(glm_clamp(0.6f, 0.0f, 1.0f) == 0.6f); assert_true(glm_clamp(0.6f, 0.0f, 1.0f) == 0.6f);
glm_vec_clamp(v3, 0.0, 1.0); glm_vec3_clamp(v3, 0.0, 1.0);
glm_vec4_clamp(v4, 1.5, 3.0); glm_vec4_clamp(v4, 1.5, 3.0);
assert_true(v3[0] == 1.0f); assert_true(v3[0] == 1.0f);

View File

@@ -128,7 +128,7 @@ test_quat(void **state) {
axis[1] = sinf(glm_rad(-90.0f) * 0.5f) * 1.0f; axis[1] = sinf(glm_rad(-90.0f) * 0.5f) * 1.0f;
axis[2] = 0.0f; axis[2] = 0.0f;
assert_true(glm_vec_eqv_eps(imag, axis)); assert_true(glm_vec3_eqv_eps(imag, axis));
/* 9.2 axis */ /* 9.2 axis */
glm_quat_axis(q4, axis); glm_quat_axis(q4, axis);
@@ -143,7 +143,7 @@ test_quat(void **state) {
v1[0] = 0.0f; v1[1] = 0.0f; v1[2] = -1.0f; v1[0] = 0.0f; v1[1] = 0.0f; v1[2] = -1.0f;
v2[0] = 0.0f; v2[1] = 0.0f; v2[2] = -1.0f; v2[0] = 0.0f; v2[1] = 0.0f; v2[2] = -1.0f;
glm_vec_rotate(v1, glm_rad(90.0f), (vec3){1.0f, 0.0f, 0.0f}); glm_vec3_rotate(v1, glm_rad(90.0f), (vec3){1.0f, 0.0f, 0.0f});
glm_quatv(q3, glm_rad(90.0f), (vec3){1.0f, 0.0f, 0.0f}); glm_quatv(q3, glm_rad(90.0f), (vec3){1.0f, 0.0f, 0.0f});
glm_vec4_scale(q3, 1.5, q3); glm_vec4_scale(q3, 1.5, q3);

View File

@@ -14,64 +14,64 @@ test_vec3(void **state) {
vec3 v, v1, v2; vec3 v, v1, v2;
/* test zero */ /* test zero */
glm_vec_zero(v); glm_vec3_zero(v);
test_assert_vec3_eq(GLM_VEC3_ZERO, v); test_assert_vec3_eq(GLM_VEC3_ZERO, v);
/* test one */ /* test one */
glm_vec_one(v); glm_vec3_one(v);
test_assert_vec3_eq(GLM_VEC3_ONE, v); test_assert_vec3_eq(GLM_VEC3_ONE, v);
/* adds, subs, div, divs, mul */ /* adds, subs, div, divs, mul */
glm_vec_add(v, GLM_VEC3_ONE, v); glm_vec3_add(v, GLM_VEC3_ONE, v);
assert_true(glmc_vec_eq_eps(v, 2)); assert_true(glmc_vec3_eq_eps(v, 2));
glm_vec_adds(v, 10, v); glm_vec3_adds(v, 10, v);
assert_true(glmc_vec_eq_eps(v, 12)); assert_true(glmc_vec3_eq_eps(v, 12));
glm_vec_sub(v, GLM_VEC3_ONE, v); glm_vec3_sub(v, GLM_VEC3_ONE, v);
assert_true(glmc_vec_eq_eps(v, 11)); assert_true(glmc_vec3_eq_eps(v, 11));
glm_vec_subs(v, 1, v); glm_vec3_subs(v, 1, v);
assert_true(glmc_vec_eq_eps(v, 10)); assert_true(glmc_vec3_eq_eps(v, 10));
glm_vec_broadcast(2, v1); glm_vec3_broadcast(2, v1);
glm_vec_div(v, v1, v); glm_vec3_div(v, v1, v);
assert_true(glmc_vec_eq_eps(v, 5)); assert_true(glmc_vec3_eq_eps(v, 5));
glm_vec_divs(v, 0.5, v); glm_vec3_divs(v, 0.5, v);
assert_true(glmc_vec_eq_eps(v, 10)); assert_true(glmc_vec3_eq_eps(v, 10));
glm_vec_mul(v, v1, v); glm_vec3_mul(v, v1, v);
assert_true(glmc_vec_eq_eps(v, 20)); assert_true(glmc_vec3_eq_eps(v, 20));
glm_vec_scale(v, 0.5, v); glm_vec3_scale(v, 0.5, v);
assert_true(glmc_vec_eq_eps(v, 10)); assert_true(glmc_vec3_eq_eps(v, 10));
glm_vec_normalize_to(v, v1); glm_vec3_normalize_to(v, v1);
glm_vec_scale(v1, 0.8, v1); glm_vec3_scale(v1, 0.8, v1);
glm_vec_scale_as(v, 0.8, v); glm_vec3_scale_as(v, 0.8, v);
test_assert_vec3_eq(v1, v); test_assert_vec3_eq(v1, v);
/* addadd, subadd, muladd */ /* addadd, subadd, muladd */
glm_vec_one(v); glm_vec3_one(v);
glm_vec_addadd(GLM_VEC3_ONE, GLM_VEC3_ONE, v); glm_vec3_addadd(GLM_VEC3_ONE, GLM_VEC3_ONE, v);
assert_true(glmc_vec_eq_eps(v, 3)); assert_true(glmc_vec3_eq_eps(v, 3));
glm_vec_subadd(GLM_VEC3_ONE, GLM_VEC3_ZERO, v); glm_vec3_subadd(GLM_VEC3_ONE, GLM_VEC3_ZERO, v);
assert_true(glmc_vec_eq_eps(v, 4)); assert_true(glmc_vec3_eq_eps(v, 4));
glm_vec_broadcast(2, v1); glm_vec3_broadcast(2, v1);
glm_vec_broadcast(3, v2); glm_vec3_broadcast(3, v2);
glm_vec_muladd(v1, v2, v); glm_vec3_muladd(v1, v2, v);
assert_true(glmc_vec_eq_eps(v, 10)); assert_true(glmc_vec3_eq_eps(v, 10));
/* rotate */ /* rotate */
glm_vec_copy(GLM_YUP, v); glm_vec3_copy(GLM_YUP, v);
glm_rotate_make(rot1, glm_rad(90), GLM_XUP); glm_rotate_make(rot1, glm_rad(90), GLM_XUP);
glm_vec_rotate_m4(rot1, v, v1); glm_vec3_rotate_m4(rot1, v, v1);
glm_mat4_pick3(rot1, rot1m3); glm_mat4_pick3(rot1, rot1m3);
glm_vec_rotate_m3(rot1m3, v, v2); glm_vec3_rotate_m3(rot1m3, v, v2);
test_assert_vec3_eq(v1, v2); test_assert_vec3_eq(v1, v2);
test_assert_vec3_eq(v1, GLM_ZUP); test_assert_vec3_eq(v1, GLM_ZUP);