Compare commits

...

144 Commits

Author SHA1 Message Date
Recep Aslantas
6d8dd42ac2 simd: use new glmm_min/max in vec4 where possible 2024-01-11 00:14:28 +03:00
Recep Aslantas
dab86796a4 simd: min / max helpers 2024-01-09 21:35:39 +03:00
Recep Aslantas
4b93cb3e05 Merge pull request #378 from recp/win32_intrin
win32, simd: ensure we are on msvc when checking MSVC specific headers
2024-01-08 00:10:43 +03:00
Recep Aslantas
a682b9e6cf win32, tests: fix drand48() error on mingw 2024-01-04 12:49:45 +03:00
Recep Aslantas
bca93a379d win32, simd: ensure we are on msvc when checking MSVC specific headers 2024-01-04 11:54:42 +03:00
Recep Aslantas
34f0d59f5a now working on v0.9.3 2023-12-31 15:19:36 +03:00
Recep Aslantas
c878161518 Update project.h 2023-12-31 13:49:06 +03:00
Recep Aslantas
3b1d4fc546 struct: add missing glms_project_z() 2023-12-31 13:46:51 +03:00
Recep Aslantas
5be1c2f059 struct: fix glms_rotate_atm signature 2023-12-31 13:21:08 +03:00
Recep Aslantas
67ce1519c5 tests: fix comparing integers in tests 2023-12-30 23:47:58 +03:00
Recep Aslantas
86743c98e5 build: add missing files 2023-12-30 23:35:03 +03:00
Recep Aslantas
015e859075 fix some doc typos & warnings 2023-12-30 23:11:15 +03:00
Recep Aslantas
3a2a26e5a4 Merge pull request #377 from telephone001/euler_to_quat_lh 2023-12-30 21:31:28 +03:00
John Choi
1ccd9af866 added comment about rh vs lh zsin 2023-12-30 12:06:40 -06:00
John Choi
aa20b8ae7f added implementation of euler_to_quat_lh and fixed the tests. Now I gotta decide what to name the macros for controlling lefthand and also make call functions for rh and lh conditionally declared 2023-12-28 11:01:01 -06:00
John Choi
fa6244c42b added tests for euler_to_quat_lh. Currently they don't have any euler->mat4->quat tests because there is no left handed version of those. But I could try to find a way to change it 2023-12-28 10:31:14 -06:00
John Choi
c998d0186a made struct versions of euler to quat. Also fixed up documentation in euler to quat struct. 2023-12-28 09:52:17 -06:00
John Choi
a94861dd5d cleaned up documentation for euler to quat functions and also created the lh file. Made a handed struct file so I remember to do that 2023-12-28 09:21:05 -06:00
Recep Aslantas
040926999a Merge pull request #369 from telephone001/master
euler to quat functions
2023-12-25 10:42:04 +03:00
Recep Aslantas
40cfbe9717 Merge pull request #373 from BeeverFeever/master
ivec += and -= functions
2023-12-25 10:34:10 +03:00
John Choi
d820410435 Merge remote-tracking branch 'refs/remotes/origin/master' 2023-12-24 23:59:34 -06:00
John Choi
39c0c1e784 added handed folder and also made rh tests for the euler->quat functions. Still deciding on what to name the macro for lefthanded stuff 2023-12-24 23:58:29 -06:00
BeeverFeever
4c9b32324d Add tests for ivec -= and += functions 2023-12-25 12:51:33 +11:00
BeeverFeever
921ab6640b Implement -= and += functions for ivecs 2023-12-25 12:51:10 +11:00
BeeverFeever
7701a1a789 Add int min and max functions 2023-12-25 12:50:29 +11:00
telephone001.mdl
46aaf250fa Merge branch 'master' into master 2023-12-14 14:19:22 -06:00
John Choi
42b5e834d1 re-added the euler->mat4->quat tests 2023-12-14 12:00:58 -06:00
John Choi
732a403112 changed last parameter to be destination and also removed the euler->mat4->quat test. 2023-12-13 08:57:10 -06:00
Recep Aslantas
559a6588c8 readthedocs 2023-12-12 13:19:19 +03:00
Recep Aslantas
8277473202 Create .readthedocs.yaml 2023-12-12 13:02:04 +03:00
Recep Aslantas
97575bdcd6 fix glmm_fmsub() on arm-neon: https://github.com/recp/cglm/pull/364 thanks to @gottfriedleibniz 2023-12-12 11:24:25 +03:00
Recep Aslantas
bc2a918ad0 Merge pull request #374 from waywardmonkeys/update-ci-checkout-action
ci: Update to `actions/checkout@v4` from `v3`.
2023-12-11 21:49:09 +03:00
Bruce Mitchener
8ebcc3aceb ci: Update to actions/checkout@v4 from v3. 2023-12-11 22:33:29 +07:00
BeeverFeever
d341478342 testing new ivec* funcs 2023-12-11 20:18:18 +11:00
John Choi
7e4383cb3d found out I was using glm_euler_xyz_quat in some testers that tests other types. I thought I changed it yesterday. Also there is still a problem with quaternion axis multiplication vs euler to mat4 to quat 2023-12-10 11:46:50 -06:00
Recep Aslantas
b45657f673 Update tests.h 2023-12-10 20:39:52 +03:00
telephone001.mdl
e24675c6e0 Merge branch 'recp:master' into master 2023-12-10 11:38:51 -06:00
Recep Aslantas
2e6e4a9a44 Merge branch 'master' of https://github.com/recp/cglm 2023-12-10 20:30:52 +03:00
Recep Aslantas
4f88a027bc Merge pull request #364 from BeeverFeever/master
New subtraction family of vector functions
2023-12-10 20:29:19 +03:00
Recep Aslantas
673263265b fix glmm_fmsub() on arm-neon 2023-12-10 20:28:39 +03:00
Recep Aslantas
dd9235dfee fix glmm_fmsub() on arm-neon 2023-12-10 17:13:11 +03:00
BeeverFeever
4c4a69ddfe Should be all 2023-12-11 01:08:10 +11:00
John Choi
d6139559b6 Merge remote-tracking branch 'refs/remotes/origin/master' 2023-12-10 01:19:12 -06:00
John Choi
2eb9a67a3a fixed up the code to fit with the style, Also found out that I was calculating my quaternion rotations the opposite way (zyx order instead of xyz order) 2023-12-10 01:16:09 -06:00
Recep Aslantas
8a1d1cf35d fix glmm_fmsub() on arm-neon 2023-12-10 10:06:36 +03:00
telephone001.mdl
fee2b7d344 Merge branch 'recp:master' into master 2023-12-09 23:41:25 -06:00
BeeverFeever
865faad116 Fix simd versions 2023-12-10 15:49:59 +11:00
Recep Aslantas
7ccf199066 Merge pull request #372 from EasyIP2023/bugfix/docs-non-square
docs: 2/2 fixes https://github.com/recp/cglm/issues/371
2023-12-09 23:08:29 +03:00
Vincent Davis Jr
047138321c docs: 2/2 fixes https://github.com/recp/cglm/issues/371
Second commit for fixing non-square matrix
multiplication docs.

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-12-09 14:28:57 -05:00
Recep Aslantas
75b99ef87d fixes: https://github.com/recp/cglm/issues/371 2023-12-09 21:28:53 +03:00
John Choi
036fd4848b moved all my stuff to euler because it fits there better. Also, had to move my tests into a single euler test because it wouldn't work outside that one test. Maybe later I will create test_euler.h like how test_quat.h works 2023-12-09 00:38:38 -06:00
John Choi
666d692dfb fixed the bug with the tester. Its weird that the broken tester worked on my computer 2023-12-08 23:06:36 -06:00
John Choi
ec3796973e finished but trying to figure out why its not running in wasm 2023-12-08 14:15:49 -06:00
telephone001.mdl
45f2fff22f Merge branch 'recp:master' into master 2023-12-08 13:09:24 -06:00
John Choi
4ee6aea037 made quat struct and also exported it 2023-12-08 13:05:53 -06:00
John Choi
2f7dbad6a8 finally done with tests and all euler to quaternion functions 2023-12-08 12:19:09 -06:00
Recep Aslantas
5ae0cd4618 Merge pull request #367 from v1993/struct-clipspace-fixes
Fix struct clipspace headers
2023-12-08 15:12:12 +03:00
Valeri Ochinski
23d03ffe6c Fix struct clipspace headers
Add missing includes, fix signatures
2023-12-08 10:14:43 +03:00
John Choi
c5694c5c17 made all the functions. I have miscalculated some stuff and am currently trying to test them. I have created all the testing functions as well 2023-12-08 00:26:33 -06:00
John Choi
d67ac97323 got the euler to quat xyz working and got the tests to pass 2023-12-07 12:21:55 -06:00
John Choi
05ea35ffec made euler to quat xyz. Now I'm trying to test if it works or not 2023-12-07 10:29:07 -06:00
Recep Aslantas
05d45872a3 Merge pull request #355 from duarm/aabb2d
aabb2d
2023-12-06 22:58:31 +03:00
duarm
c431bbf190 fix procedure comment on transform 2023-12-06 16:54:46 -03:00
duarm
340292c0fb fix transform 2023-12-06 16:52:55 -03:00
duarm
2106f9ebcb remove _aabb2d_frustum 2023-12-06 16:48:48 -03:00
duarm
c1d78d835b changing from mat4 to mat3 2023-12-06 16:34:18 -03:00
duarm
de80b8325f Merge branch 'master' into aabb2d 2023-12-06 16:14:00 -03:00
duarm
7061df0066 circle docs fixup 2023-12-06 16:14:59 -03:00
duarm
eb73e4123b docs fix 2023-12-06 16:13:08 -03:00
BeeverFeever
22140d8e1b Fix test 2023-12-05 19:48:54 +11:00
BeeverFeever
39602ef4d7 Fix vec4 functions 2023-12-05 18:49:10 +11:00
Recep Aslantas
abb71a8e32 fixes: https://github.com/recp/cglm/pull/360#issuecomment-1838122934 2023-12-05 10:31:46 +03:00
BeeverFeever
f8b6573de8 Write tests for new functions 2023-12-04 23:28:56 +11:00
BeeverFeever
15f29e05eb Fixed missed function 2023-12-04 23:28:29 +11:00
BeeverFeever
7696374f1e Vector subtraction functions
Add subtraction family of functions for vectors.
2023-12-04 21:32:19 +11:00
duarm
44d103fa00 typos 2023-12-03 02:36:04 -03:00
duarm
c29f077bed Merge branch 'master' into aabb2d 2023-12-02 21:02:20 -03:00
duarm
2a975a7d0a circle fix, new copy func 2023-12-02 21:00:21 -03:00
Recep Aslantas
049db64a0f Merge pull request #360 from v1993/meson-header-only-subproject
meson: don't build by default if used in a subproject
2023-12-02 15:49:24 +03:00
Recep Aslantas
e71694bb57 Merge branch 'master' into meson-header-only-subproject 2023-12-02 15:48:54 +03:00
Recep Aslantas
8754158fbe Merge pull request #362 from myfreeer/patch-1
ci: initial support of meson and emscripten
2023-12-02 11:13:20 +03:00
Recep Aslantas
e1a0892097 Merge branch 'master' into patch-1 2023-12-02 11:12:43 +03:00
Recep Aslantas
9b26aff466 Merge pull request #361 from myfreeer/myfreeer-patch-4
wasm: prefer pmin/pmax
2023-12-02 11:12:15 +03:00
myfreeer
24e417107b ci: initial support of meson and emscripten
It seems that meson only supports emscripten as a compiler to wasm at present, wasi-sdk support is not completed yet, so this only adds ci build scripts for emscripten.

References:
* <f41bdae368>
* <https://github.com/mesonbuild/meson/pull/11862>
2023-12-02 11:08:33 +08:00
myfreeer
009405adcd wasm: prefer pmin/pmax
According to [emscripten](https://emscripten.org/docs/porting/simd.html) and [v8](b6520eda5e/src/compiler/backend/x64/code-generator-x64.cc (L2661-L2699)), `[f32x4|f64x2].[min|max]` compiles to much more instructions than `[f32x4|f64x2].[pmin|pmax]`.
It is defined in [spec](https://github.com/WebAssembly/spec/blob/main/proposals/simd/SIMD.md#floating-point-min-and-max) that the difference between pmin/pmax and min/max is NaN-propagating behavior, and the equivalent to the x86 `_mm_min_ps`/`_mm_max_ps` is pmin/pmax in [v8](b6520eda5e/src/compiler/backend/x64/code-generator-x64.cc (L2740-L2747)).
This should make functions with min/max faster on webassembly, and align with the existing behavior with x86 sse.
2023-12-02 09:54:49 +08:00
Valeri
0b2006dd47 meson: don't build by default if used in a subproject 2023-12-02 01:44:54 +03:00
Recep Aslantas
1fdc1c8675 struct: remove _vec_inv from struct function lists 2023-12-01 11:18:48 +03:00
Recep Aslantas
6e1d6d505b Merge pull request #357 from v1993/vs-fix
Use the appropriate version of alignof
2023-12-01 11:11:11 +03:00
Valeri
45cf4710c4 Use the appropriate version of alignof 2023-12-01 04:19:47 +03:00
duarm
056b28e4da Merge branch 'master' into aabb2d 2023-11-19 10:00:00 -03:00
Recep Aslantas
c6e58bd44a Update vec4-ext.h 2023-11-16 13:06:51 +03:00
Recep Aslantas
a81c0f076a Merge pull request #356 from havrik/patch-1
Fix definition logic misspell in 'glm_quat_normalize_to' -> cglm/quat.h
2023-11-16 13:05:42 +03:00
havrik
ab684b7c66 Fix definition logic misspell in 'glm_quat_normalize_to' -> cglm/quat.h 2023-11-16 11:38:47 +03:00
duarm
53bde05bd9 aabb2d functions 2023-11-11 08:13:28 -03:00
Recep Aslantas
58a4b47830 Merge pull request #354 from One234Fi/revise_troubleshooting_page
Fix spelling and grammar on troubleshooting page
2023-11-09 10:44:06 +03:00
One234Fi
1bfa53f44c spelling and grammar revision 2023-11-08 16:41:07 -06:00
Recep Aslantas
d93b46bab7 Merge pull request #350 from duarm/vec2_center
adding glm_vec2_center
2023-10-15 00:17:47 +03:00
duarm
9efc255451 struct api 2023-10-14 14:24:25 -03:00
duarm
9484155c98 adding vec2_center 2023-10-11 16:51:14 -03:00
Recep Aslantas
509078817c fix glm_ivec2|3_fill and glm_ivec2|3_eq params continue 2023-09-05 20:41:55 +03:00
Recep Aslantas
126f809dae fix glm_ivec2|3_fill and glm_ivec2|3_eq params 2023-09-05 20:19:33 +03:00
Recep Aslantas
e0e7e380e5 Merge pull request #346 from duarm/master
eqv, eq, fill for ivec2 and ivec3, documentation fixes
2023-09-05 09:34:28 +03:00
duarm
d3169b12a7 missing call functions from vec2 2023-09-04 20:14:59 -03:00
duarm
9d0c9fdb87 adding ivec2, ivec3, ivec4 prints, eqv, eq and fill, documentation fixes 2023-09-04 20:07:37 -03:00
Recep Aslantas
f496146bce Merge pull request #345 from telephone001/ins3_bugfix
Fixed glms_mat4_ins3 bug.
2023-08-30 13:03:16 +03:00
LAPTOP-GHFRJ92J\John
54632ecce5 mat4_ins3 should copy mat3s to upper left mat4s. Previously, it just made a new mat4s r and put the mat3 into that and returned it. Now it takes in a mat4s and copies the mat3s to that. 2023-08-29 02:13:24 -05:00
Recep Aslantas
61478d2563 now working on v0.9.2 2023-08-10 09:20:39 +03:00
Recep Aslantas
cdd4d0e83e Merge pull request #340 from recp/non-square-matrix
add some missing non-square matrix funcs
2023-08-07 17:58:05 +03:00
Recep Aslantas
54dfc4b4f0 Merge branch 'master' into non-square-matrix 2023-08-07 15:37:44 +03:00
Recep Aslantas
f6cb3ba31a Merge pull request #343 from EasyIP2023/non-square-matrix
add docs and tests to non-square-matrix branch
2023-08-07 14:41:08 +03:00
Vincent Davis Jr
da51741c50 test: add missing mat4x3 tests
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-08-06 14:12:46 -04:00
Vincent Davis Jr
a5d8e61c2b test: add missing mat4x2 tests
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-08-06 14:12:26 -04:00
Vincent Davis Jr
f0f7b67ef4 test: add missing mat3x4 tests
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-08-06 14:12:26 -04:00
Vincent Davis Jr
eece0b7bc9 test: add missing mat3x2 tests
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-08-06 14:12:26 -04:00
Vincent Davis Jr
37d20f7da8 test: add missing mat2x4 tests
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-08-06 14:12:26 -04:00
Vincent Davis Jr
006e4ffbdf test: add missing mat2x3 tests
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-08-06 14:12:26 -04:00
Vincent Davis Jr
aa37c1aa74 fix array subscript is outside array bounds
warning: array subscript # is outside array bounds
of ‘float[#]’ [-Warray-bounds]

Commit also fixes variable order when calculating
multiplication between two matrices.

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-08-06 14:12:24 -04:00
Vincent Davis Jr
0fb9e73ec1 docs: add missing non-square matrix funcs
Functions include:
	* glm_mat#x#_copy
	* glm_mat#x#_zero
	* glm_mat#x#_mul
	* glm_mat#x#_mulv
	* glm_mat#x#_transpose
	* glm_mat#x#_scale

Commit also includes some minor changes to
	* mat2
	* mat3
	* mat4

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-08-05 20:54:24 -04:00
Recep Aslantas
129287b809 Merge pull request #341 from taisei-project/assume-aligned-detection
more robust __builtin_assume_aligned detection
2023-08-01 18:22:24 +03:00
Andrei Alexeyev
2724620d83 more robust __builtin_assume_aligned detection
__builtin_assume_aligned is available since GCC 4.7, but __has_builtin
was added much later. Check for the GCC version if __has_builtin is not
available.

Users can also define CGLM_HAVE_BUILTIN_ASSUME_ALIGNED to either 1 or 0
to explicitly enable/disable the use of __builtin_assume_aligned. Meson
will do it automatically (by performing a configure-time test).
2023-07-31 22:33:51 +02:00
Recep Aslantas
4d5653b1f6 add some missing non-square matrix funcs in struct api 2023-07-22 14:17:26 +03:00
Recep Aslantas
dbb85f24c8 add some missing non-square matrix funcs 2023-07-22 13:37:36 +03:00
Recep Aslantas
6e9e91be05 add _mul for non-square matrices 2023-07-22 12:00:23 +03:00
Recep Aslantas
1e077fd125 add some missing non-square matrix funcs 2023-07-22 01:21:14 +03:00
Recep Aslantas
cb4a1b2677 Merge pull request #338 from EasyIP2023/feature/mat4x3
add new matrix mat4x3
2023-07-18 09:09:00 +03:00
Recep Aslantas
924db3307e Merge pull request #339 from EasyIP2023/bug/fix-mat4x2s
types-struct: fix mat4x2s struct members
2023-07-18 09:07:41 +03:00
Vincent Davis Jr
e9df003e56 types-struct: fix mat4x2s struct members
union mat4x2s { struct {  } } contains
members with incorrect naming.

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-07-17 23:09:40 -04:00
Vincent Davis Jr
3d292c3a2e add new matrix mat4x3
Initial function being

glm_mat4x3_make

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-07-17 22:57:52 -04:00
Recep Aslantas
4bb7e778c4 Merge pull request #337 from EasyIP2023/feature/mat4x2
add new matrix mat4x2
2023-07-17 10:41:09 +03:00
Vincent Davis Jr
2df26c0ecf add new matrix mat4x2
Initial function being

glm_mat4x2_make

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-07-16 20:19:25 -04:00
Recep Aslantas
5193b50133 Merge pull request #334 from EasyIP2023/feature/mat3x4
add new matrix mat3x4
2023-07-16 23:32:05 +03:00
Recep Aslantas
ef8954ccbc Merge branch 'master' into feature/mat3x4 2023-07-16 23:31:33 +03:00
Recep Aslantas
91b40eb7eb Merge pull request #335 from EasyIP2023/fix/comments-docs
docs: fix mat#x# comments and documentation
2023-07-16 23:29:38 +03:00
Vincent Davis Jr
82892085b3 docs: fix mat#x# comments and documentation
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-07-16 15:46:35 -04:00
Vincent Davis Jr
e09cf11f1c add new matrix mat3x4
Initial function being

glm_mat3x4_make

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-07-16 15:41:36 -04:00
Recep Aslantas
8966f296ac Merge pull request #333 from EasyIP2023/feature/mat3x2
add new matrix mat3x2
2023-07-16 12:10:45 +03:00
Vincent Davis Jr
4e44e74d48 add new matrix mat3x2
Initial function being

glm_mat3x2_make

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-07-15 18:48:50 -04:00
Recep Aslantas
f817c4cbb0 Merge pull request #332 from EasyIP2023/fix/mat2x3
add missing mat2x# test and mat2x3 window headers
2023-07-15 23:55:19 +03:00
Vincent Davis Jr
dd6a0b3175 add missing mat2x# test and mat2x3 window headers
Missing tests where
	* MACRO_GLM_MAT2X3_ZERO_INIT
	* MACRO_GLM_MAT2X3_ZERO
	* mat2x3s_zero_init
	* mat2x3s_zero
	* mat2x4s_zero_init
	* mat2x4s_zero

Commit:
	* removes (mat2x3) from
	  ((mat2x3)GLM_MAT2X3_ZERO_INIT) to fix
	  error: array initialized from non-constant array expression
	* removes test_assert_mat2x3_eq_zero
	  from test/src/test_struct.c
	* adds TEST_IMPL(mat2x3s_zero) to
	  test/src/test_struct.c

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-07-15 16:16:03 -04:00
Recep Aslantas
1401af4c34 Merge pull request #331 from EasyIP2023/feature/mat2x4
add new matrix mat2x4
2023-07-15 22:33:54 +03:00
Vincent Davis Jr
fe7471e8f8 add new matrix mat2x4
Initial function being

glm_mat2x4_make

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-07-15 14:32:48 -04:00
Recep Aslantas
1ca261b118 Merge pull request #330 from EasyIP2023/feature/mat2x3
add new matrix mat2x3
2023-07-15 11:03:59 +03:00
Vincent Davis Jr
6317ed90e7 add new matrix mat2x3
Initial function being

glm_mat2x3_make

Signed-off-by: Vincent Davis Jr <vince@underview.tech>
2023-07-14 18:57:45 -04:00
Recep Aslantas
3b683cf28c Merge pull request #328 from recp/werror
drop "-Werror" to allow skip warnings on production build
2023-07-13 11:09:16 +03:00
143 changed files with 11949 additions and 162 deletions

View File

@@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Downloading wasi-sdk
run: |
@@ -64,7 +64,7 @@ jobs:
C_FLAGS: ['', '-msimd128', '-msse -msse2 -msimd128', '-msse -msse2 -msse3 -msse4 -msimd128']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v12

79
.github/workflows/meson-wasm.yml vendored Normal file
View File

@@ -0,0 +1,79 @@
name: Meson WebAssembly
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
env:
wasmtime_version: v7.0.0
wasmer_version: v3.1.1
jobs:
build_emsdk:
strategy:
matrix:
BUILD_TYPE: [debug, debugoptimized, release, minsize]
C_FLAGS: ['', '-msimd128', '-msse -msse2 -msimd128', '-msse -msse2 -msse3 -msse4 -msimd128']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v13
- name: Verify emsdk
run: emcc -v
- name: Creating cross file
run: |
cat << EOF > ${{github.workspace}}/meson_cross_emsdk.txt
[binaries]
c = '`which emcc`'
cpp = '`which em++`'
ar = '`which emar`'
[built-in options]
c_args = ['-Wno-unused-parameter']
c_link_args = ['-s', 'STANDALONE_WASM']
cpp_args = ['-Wno-unused-parameter']
cpp_link_args = ['-s', 'STANDALONE_WASM']
[host_machine]
system = 'emscripten'
cpu_family = 'wasm32'
cpu = 'wasm32'
endian = 'little'
EOF
cat ${{github.workspace}}/meson_cross_emsdk.txt
- uses: actions/setup-python@v4
- name: Install meson
run: |
sudo python3 -m pip install meson ninja
- name: Build with meson
run: |
meson setup build -Dbuildtype=${{matrix.BUILD_TYPE}} --cross-file ${{github.workspace}}/meson_cross_emsdk.txt --default-library=static -Dbuild_tests=true
meson test -C build
- name: Test with wasmtime
run: |
cd ${{github.workspace}}
ls -lh ${{github.workspace}}/build/
wget --no-verbose https://github.com/bytecodealliance/wasmtime/releases/download/${{env.wasmtime_version}}/wasmtime-${{env.wasmtime_version}}-x86_64-linux.tar.xz
tar xf wasmtime-${{env.wasmtime_version}}-x86_64-linux.tar.xz
./wasmtime-${{env.wasmtime_version}}-x86_64-linux/wasmtime run --wasm-features simd ${{github.workspace}}/build/tests.wasm
- name: Test with wasmer
run: |
cd ${{github.workspace}}
mkdir wasmer
cd wasmer
wget --no-verbose https://github.com/wasmerio/wasmer/releases/download/${{env.wasmer_version}}/wasmer-linux-amd64.tar.gz
tar xf wasmer-linux-amd64.tar.gz
./bin/wasmer run --enable-simd ${{github.workspace}}/build/tests.wasm

39
.readthedocs.yaml Normal file
View File

@@ -0,0 +1,39 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
# Required
version: 2
# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
# golang: "1.20"
# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/source/conf.py
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
# fail_on_warning: true
# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub
# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt
python:
install:
- requirements: docs/requirements.txt

View File

@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.8.2)
project(cglm
VERSION 0.9.1
VERSION 0.9.3
HOMEPAGE_URL https://github.com/recp/cglm
DESCRIPTION "OpenGL Mathematics (glm) for C"
LANGUAGES C
@@ -79,8 +79,14 @@ add_library(${PROJECT_NAME}
src/vec4.c
src/ivec4.c
src/mat2.c
src/mat2x3.c
src/mat2x4.c
src/mat3.c
src/mat3x2.c
src/mat3x4.c
src/mat4.c
src/mat4x2.c
src/mat4x3.c
src/plane.c
src/frustum.c
src/box.c

View File

@@ -42,8 +42,14 @@ cglm_HEADERS = include/cglm/version.h \
include/cglm/cam.h \
include/cglm/io.h \
include/cglm/mat4.h \
include/cglm/mat4x2.h \
include/cglm/mat4x3.h \
include/cglm/mat3.h \
include/cglm/mat3x2.h \
include/cglm/mat3x4.h \
include/cglm/mat2.h \
include/cglm/mat2x3.h \
include/cglm/mat2x4.h \
include/cglm/affine-pre.h \
include/cglm/affine-post.h \
include/cglm/affine.h \
@@ -63,6 +69,7 @@ cglm_HEADERS = include/cglm/version.h \
include/cglm/plane.h \
include/cglm/frustum.h \
include/cglm/box.h \
include/cglm/aabb2d.h \
include/cglm/color.h \
include/cglm/project.h \
include/cglm/sphere.h \
@@ -94,8 +101,14 @@ cglm_clipspace_HEADERS = include/cglm/clipspace/persp.h \
cglm_calldir=$(includedir)/cglm/call
cglm_call_HEADERS = include/cglm/call/mat4.h \
include/cglm/call/mat4x2.h \
include/cglm/call/mat4x3.h \
include/cglm/call/mat3.h \
include/cglm/call/mat3x2.h \
include/cglm/call/mat3x4.h \
include/cglm/call/mat2.h \
include/cglm/call/mat2x3.h \
include/cglm/call/mat2x4.h \
include/cglm/call/vec2.h \
include/cglm/call/vec3.h \
include/cglm/call/vec4.h \
@@ -137,7 +150,8 @@ cglm_call_clipspace_HEADERS = include/cglm/call/clipspace/persp_lh_no.h \
cglm_simddir=$(includedir)/cglm/simd
cglm_simd_HEADERS = include/cglm/simd/intrin.h \
include/cglm/simd/x86.h \
include/cglm/simd/arm.h
include/cglm/simd/arm.h \
include/cglm/simd/wasm.h
cglm_simd_sse2dir=$(includedir)/cglm/simd/sse2
cglm_simd_sse2_HEADERS = include/cglm/simd/sse2/affine.h \
@@ -156,10 +170,27 @@ cglm_simd_neon_HEADERS = include/cglm/simd/neon/affine.h \
include/cglm/simd/neon/mat4.h \
include/cglm/simd/neon/quat.h
cglm_simd_wasmdir=$(includedir)/cglm/simd/wasm
cglm_simd_wasm_HEADERS = include/cglm/simd/wasm/affine.h \
include/cglm/simd/wasm/mat2.h \
include/cglm/simd/wasm/mat3.h \
include/cglm/simd/wasm/mat4.h \
include/cglm/simd/wasm/quat.h
cglm_handeddir=$(includedir)/cglm/handed
cglm_handed_HEADERS = include/cglm/handed/euler_to_quat_lh.h \
include/cglm/handed/euler_to_quat_rh.h
cglm_structdir=$(includedir)/cglm/struct
cglm_struct_HEADERS = include/cglm/struct/mat4.h \
include/cglm/struct/mat4x2.h \
include/cglm/struct/mat4x3.h \
include/cglm/struct/mat3.h \
include/cglm/struct/mat3x2.h \
include/cglm/struct/mat3x4.h \
include/cglm/struct/mat2.h \
include/cglm/struct/mat2x3.h \
include/cglm/struct/mat2x4.h \
include/cglm/struct/affine-pre.h \
include/cglm/struct/affine-post.h \
include/cglm/struct/affine-mat.h \
@@ -178,6 +209,7 @@ cglm_struct_HEADERS = include/cglm/struct/mat4.h \
include/cglm/struct/plane.h \
include/cglm/struct/frustum.h \
include/cglm/struct/box.h \
include/cglm/struct/aabb2d.h \
include/cglm/struct/project.h \
include/cglm/struct/sphere.h \
include/cglm/struct/color.h \
@@ -199,6 +231,10 @@ cglm_struct_clipspace_HEADERS = include/cglm/struct/clipspace/persp_lh_no.h \
include/cglm/struct/clipspace/project_no.h \
include/cglm/struct/clipspace/project_zo.h
cglm_struct_handeddir=$(includedir)/cglm/struct/handed
cglm_struct_handed_HEADERS = include/cglm/struct/handed/euler_to_quat_lh.h \
include/cglm/struct/handed/euler_to_quat_rh.h
libcglm_la_SOURCES=\
src/euler.c \
src/affine.c \
@@ -212,8 +248,14 @@ libcglm_la_SOURCES=\
src/vec4.c \
src/ivec4.c \
src/mat2.c \
src/mat2x3.c \
src/mat2x4.c \
src/mat3.c \
src/mat3x2.c \
src/mat3x4.c \
src/mat4.c \
src/mat4x2.c \
src/mat4x3.c \
src/plane.c \
src/frustum.c \
src/box.c \

View File

@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
# Description
s.name = "cglm"
s.version = "0.9.0"
s.version = "0.9.2"
s.summary = "📽 Highly Optimized Graphics Math (glm) for C"
s.description = <<-DESC
cglm is math library for graphics programming for C. See the documentation or README for all features.

View File

@@ -7,7 +7,7 @@
#*****************************************************************************
AC_PREREQ([2.69])
AC_INIT([cglm], [0.9.1], [info@recp.me])
AC_INIT([cglm], [0.9.3], [info@recp.me])
AM_INIT_AUTOMAKE([-Wall foreign subdir-objects serial-tests])
# Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am.

4
docs/requirements.txt Normal file
View File

@@ -0,0 +1,4 @@
# Defining the exact version will make sure things don't break
sphinx==5.3.0
sphinx_rtd_theme==1.1.1
readthedocs-sphinx-search==0.1.1

173
docs/source/aabb2d.rst Normal file
View File

@@ -0,0 +1,173 @@
.. default-domain:: C
2d axis aligned bounding box (AABB)
================================================================================
Header: cglm/aabb2d.h
Some convenient functions provided for AABB.
**Definition of aabb:**
cglm defines an aabb as a two dimensional array of vec2's.
The first element is the **min** point and the second one is the **max** point.
If you have another type e.g. struct or even another representation then you must
convert it before and after calling a cglm aabb2d function.
Table of contents (click to go):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Functions:
1. :c:func:`glm_aabb2d_copy`
#. :c:func:`glm_aabb2d_transform`
#. :c:func:`glm_aabb2d_merge`
#. :c:func:`glm_aabb2d_crop`
#. :c:func:`glm_aabb2d_crop_until`
#. :c:func:`glm_aabb2d_invalidate`
#. :c:func:`glm_aabb2d_isvalid`
#. :c:func:`glm_aabb2d_size`
#. :c:func:`glm_aabb2d_radius`
#. :c:func:`glm_aabb2d_center`
#. :c:func:`glm_aabb2d_aabb`
#. :c:func:`glm_aabb2d_circle`
#. :c:func:`glm_aabb2d_point`
#. :c:func:`glm_aabb2d_contains`
Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~
.. c:function:: void glm_aabb2d_copy(vec2 aabb[2], vec2 dest[2])
| copy all members of [aabb] to [dest]
Parameters:
| *[in]* **aabb** bounding box
| *[out]* **dest** destination
.. c:function:: void glm_aabb2d_transform(vec2 aabb[2], mat3 m, vec2 dest[2])
| apply transform to Axis-Aligned Bounding Box
Parameters:
| *[in]* **aabb** bounding box
| *[in]* **m** transform matrix
| *[out]* **dest** transformed bounding box
.. c:function:: void glm_aabb2d_merge(vec2 aabb1[2], vec2 aabb2[2], vec2 dest[2])
| merges two AABB bounding box and creates new one
two aabb must be in the same space
Parameters:
| *[in]* **aabb1** bounding box 1
| *[in]* **aabb2** bounding box 2
| *[out]* **dest** merged bounding box
.. c:function:: void glm_aabb2d_crop(vec2 aabb[2], vec2 cropAabb[2], vec2 dest[2])
| crops a bounding box with another one.
this could be useful for gettng a bbox which fits with view frustum and
object bounding boxes. In this case you crop view frustum box with objects
box
Parameters:
| *[in]* **aabb** bounding box 1
| *[in]* **cropAabb** crop box
| *[out]* **dest** cropped bounding box
.. c:function:: void glm_aabb2d_crop_until(vec2 aabb[2], vec2 cropAabb[2], vec2 clampAabb[2], vec2 dest[2])
| crops a bounding box with another one.
this could be useful for gettng a bbox which fits with view frustum and
object bounding boxes. In this case you crop view frustum box with objects
box
Parameters:
| *[in]* **aabb** bounding box
| *[in]* **cropAabb** crop box
| *[in]* **clampAabb** miniumum box
| *[out]* **dest** cropped bounding box
.. c:function:: void glm_aabb2d_invalidate(vec2 aabb[2])
| invalidate AABB min and max values
| It fills *max* values with -FLT_MAX and *min* values with +FLT_MAX
Parameters:
| *[in, out]* **aabb** bounding box
.. c:function:: bool glm_aabb2d_isvalid(vec2 aabb[2])
| check if AABB is valid or not
Parameters:
| *[in]* **aabb** bounding box
Returns:
returns true if aabb is valid otherwise false
.. c:function:: float glm_aabb2d_size(vec2 aabb[2])
| distance between of min and max
Parameters:
| *[in]* **aabb** bounding box
Returns:
distance between min - max
.. c:function:: float glm_aabb2d_radius(vec2 aabb[2])
| radius of sphere which surrounds AABB
Parameters:
| *[in]* **aabb** bounding box
.. c:function:: void glm_aabb2d_center(vec2 aabb[2], vec2 dest)
| computes center point of AABB
Parameters:
| *[in]* **aabb** bounding box
| *[out]* **dest** center of bounding box
.. c:function:: bool glm_aabb2d_aabb(vec2 aabb[2], vec2 other[2])
| check if two AABB intersects
Parameters:
| *[in]* **aabb** bounding box
| *[out]* **other** other bounding box
.. c:function:: bool glm_aabb2d_circle(vec2 aabb[2], vec3 c)
| check if AABB intersects with sphere
| https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c
| Solid Box - Solid Sphere test.
Parameters:
| *[in]* **aabb** solid bounding box
| *[out]* **c** solid circle
.. c:function:: bool glm_aabb2d_point(vec2 aabb[2], vec2 point)
| check if point is inside of AABB
Parameters:
| *[in]* **aabb** bounding box
| *[out]* **point** point
.. c:function:: bool glm_aabb2d_contains(vec2 aabb[2], vec2 other[2])
| check if AABB contains other AABB
Parameters:
| *[in]* **aabb** bounding box
| *[out]* **other** other bounding box

View File

@@ -46,8 +46,14 @@ Follow the :doc:`build` documentation for this
quat
euler
mat2
mat2x3
mat2x4
mat3
mat3x2
mat3x4
mat4
mat4x2
mat4x3
vec2
vec2-ext
vec3

View File

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

View File

@@ -18,6 +18,7 @@ Features
* inline or pre-compiled function call
* frustum (extract view frustum planes, corners...)
* bounding box (AABB in Frustum (culling), crop, merge...)
* 2d bounding box (crop, merge...)
* bounding sphere
* project, unproject
* easing functions

View File

@@ -53,8 +53,11 @@ Functions:
1. :c:func:`glm_mat4_print`
#. :c:func:`glm_mat3_print`
#. :c:func:`glm_vec4_print`
#. :c:func:`glm_ivec4_print`
#. :c:func:`glm_vec3_print`
#. :c:func:`glm_ivec3_print`
#. :c:func:`glm_vec2_print`
#. :c:func:`glm_ivec2_print`
#. :c:func:`glm_versor_print`
#. :c:func:`glm_aabb_print`
@@ -63,7 +66,7 @@ Functions documentation
.. c:function:: void glm_mat4_print(mat4 matrix, FILE * __restrict ostream)
| print mat4 to given stream
| print matrix to given stream
Parameters:
| *[in]* **matrix** matrix
@@ -71,7 +74,7 @@ Functions documentation
.. c:function:: void glm_mat3_print(mat3 matrix, FILE * __restrict ostream)
| print mat3 to given stream
| print matrix to given stream
Parameters:
| *[in]* **matrix** matrix
@@ -79,7 +82,15 @@ Functions documentation
.. c:function:: void glm_vec4_print(vec4 vec, FILE * __restrict ostream)
| print vec4 to given stream
| print vector to given stream
Parameters:
| *[in]* **vec** vector
| *[in]* **ostream** FILE to write
.. c:function:: void glm_ivec4_print(ivec4 vec, FILE * __restrict ostream)
| print vector to given stream
Parameters:
| *[in]* **vec** vector
@@ -87,7 +98,7 @@ Functions documentation
.. c:function:: void glm_vec3_print(vec3 vec, FILE * __restrict ostream)
| print vec3 to given stream
| print vector to given stream
Parameters:
| *[in]* **vec** vector
@@ -95,12 +106,29 @@ Functions documentation
.. c:function:: void glm_ivec3_print(ivec3 vec, FILE * __restrict ostream)
| print ivec3 to given stream
| print vector to given stream
Parameters:
| *[in]* **vec** vector
| *[in]* **ostream** FILE to write
.. c:function:: void glm_vec2_print(vec2 vec, FILE * __restrict ostream)
| print vector to given stream
Parameters:
| *[in]* **vec** vector
| *[in]* **ostream** FILE to write
.. c:function:: void glm_ivec2_print(ivec2 vec, FILE * __restrict ostream)
| print vector to given stream
Parameters:
| *[in]* **vec** vector
| *[in]* **ostream** FILE to write
.. c:function:: void glm_versor_print(versor vec, FILE * __restrict ostream)
| print quaternion to given stream

View File

@@ -143,6 +143,31 @@ Functions documentation
Returns:
distance
.. c:function:: void glm_ivec2_fill(ivec2 v, int val)
fill a vector with specified value
Parameters:
| *[out]* **v** vector
| *[in]* **val** value
.. c:function:: bool glm_ivec2_eq(ivec2 v, int val)
check if vector is equal to value
Parameters:
| *[in]* **v** vector
| *[in]* **val** value
.. c:function:: bool glm_ivec2_eqv(ivec2 v1, ivec2 v2)
check if vector is equal to another vector
Parameters:
| *[in]* **vec** vector 1
| *[in]* **vec** vector 2
.. c:function:: void glm_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest)
set each member of dest to greater of vector a and b

View File

@@ -29,6 +29,9 @@ Functions:
#. :c:func:`glm_ivec3_scale`
#. :c:func:`glm_ivec3_distance2`
#. :c:func:`glm_ivec3_distance`
#. :c:func:`glm_ivec3_fill`
#. :c:func:`glm_ivec3_eq`
#. :c:func:`glm_ivec3_eqv`
#. :c:func:`glm_ivec3_maxv`
#. :c:func:`glm_ivec3_minv`
#. :c:func:`glm_ivec3_clamp`
@@ -143,6 +146,30 @@ Functions documentation
Returns:
distance
.. c:function:: void glm_ivec3_fill(ivec3 v, int val)
fill a vector with specified value
Parameters:
| *[out]* **v** vector
| *[in]* **val** value
.. c:function:: bool glm_ivec3_eq(ivec3 v, int val)
check if vector is equal to value
Parameters:
| *[in]* **v** vector
| *[in]* **val** value
.. c:function:: bool glm_ivec3_eqv(ivec3 v1, ivec3 v2)
check if vector is equal to another vector
Parameters:
| *[in]* **vec** vector 1
| *[in]* **vec** vector 2
.. c:function:: void glm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest)
set each member of dest to greater of vector a and b

View File

@@ -65,11 +65,12 @@ Functions documentation
make given matrix zero
Parameters:
| *[in,out]* **mat** matrix to
| *[in,out]* **mat** matrix
.. c:function:: void glm_mat2_mul(mat2 m1, mat2 m2, mat2 dest)
multiply m1 and m2 to dest
m1, m2 and dest matrices can be same matrix, it is possible to write this:
.. code-block:: c
@@ -101,7 +102,7 @@ Functions documentation
.. c:function:: void glm_mat2_mulv(mat2 m, vec2 v, vec2 dest)
multiply mat4 with vec4 (column vector) and store in dest vector
multiply mat2 with vec2 (column vector) and store in dest vector
Parameters:
| *[in]* **mat** mat2 (left)
@@ -113,8 +114,8 @@ Functions documentation
multiply matrix with scalar
Parameters:
| *[in, out]* **mat** matrix
| *[in]* **dest** scalar
| *[in, out]* **m** matrix
| *[in]* **s** scalar
.. c:function:: float glm_mat2_det(mat2 mat)
@@ -183,7 +184,7 @@ Functions documentation
Create mat2 matrix from pointer
| NOTE: **@src** must contain 4 elements.
| NOTE: **@src** must contain at least 4 elements.
Parameters:
| *[in]* **src** pointer to an array of floats

90
docs/source/mat2x3.rst Normal file
View File

@@ -0,0 +1,90 @@
.. default-domain:: C
mat2x3
======
Header: cglm/mat2x3.h
Table of contents (click to go):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Macros:
1. GLM_MAT2X3_ZERO_INIT
#. GLM_MAT2X3_ZERO
Functions:
1. :c:func:`glm_mat2x3_copy`
#. :c:func:`glm_mat2x3_zero`
#. :c:func:`glm_mat2x3_make`
#. :c:func:`glm_mat2x3_mul`
#. :c:func:`glm_mat2x3_mulv`
#. :c:func:`glm_mat2x3_transpose`
#. :c:func:`glm_mat2x3_scale`
Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~
.. c:function:: void glm_mat2x3_copy(mat2x3 mat, mat2x3 dest)
copy mat2x3 to another one (dest).
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination
.. c:function:: void glm_mat2x3_zero(mat2x3 mat)
make given matrix zero
Parameters:
| *[in,out]* **mat** matrix
.. c:function:: void glm_mat2x3_make(float * __restrict src, mat2x3 dest)
Create mat2x3 matrix from pointer
| NOTE: **@src** must contain at least 6 elements.
Parameters:
| *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination matrix2x3
.. c:function:: void glm_mat2x3_mul(mat2x3 m1, mat3x2 m2, mat2 dest)
multiply m1 and m2 to dest
.. code-block:: c
glm_mat2x3_mul(mat2x3, mat3x2, mat2);
Parameters:
| *[in]* **m1** left matrix (mat2x3)
| *[in]* **m2** right matrix (mat3x2)
| *[out]* **dest** destination matrix (mat2)
.. c:function:: void glm_mat2x3_mulv(mat2x3 m, vec3 v, vec2 dest)
multiply mat2x3 with vec3 (column vector) and store in dest vector
Parameters:
| *[in]* **m** mat2x3 (left)
| *[in]* **v** vec3 (right, column vector)
| *[out]* **dest** destination (result, column vector)
.. c:function:: void glm_mat2x3_transpose(mat2x3 m, mat3x2 dest)
transpose matrix and store in dest
Parameters:
| *[in]* **m** matrix
| *[out]* **dest** destination
.. c:function:: void glm_mat2x3_scale(mat2x3 m, float s)
multiply matrix with scalar
Parameters:
| *[in, out]* **m** matrix
| *[in]* **s** scalar

90
docs/source/mat2x4.rst Normal file
View File

@@ -0,0 +1,90 @@
.. default-domain:: C
mat2x4
======
Header: cglm/mat2x4.h
Table of contents (click to go):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Macros:
1. GLM_MAT2X4_ZERO_INIT
#. GLM_MAT2X4_ZERO
Functions:
1. :c:func:`glm_mat2x4_copy`
#. :c:func:`glm_mat2x4_zero`
#. :c:func:`glm_mat2x4_make`
#. :c:func:`glm_mat2x4_mul`
#. :c:func:`glm_mat2x4_mulv`
#. :c:func:`glm_mat2x4_transpose`
#. :c:func:`glm_mat2x4_scale`
Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~
.. c:function:: void glm_mat2x4_copy(mat2x4 mat, mat2x4 dest)
copy mat2x4 to another one (dest).
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination
.. c:function:: void glm_mat2x4_zero(mat2x4 mat)
make given matrix zero
Parameters:
| *[in,out]* **mat** matrix
.. c:function:: void glm_mat2x4_make(float * __restrict src, mat2x4 dest)
Create mat2x4 matrix from pointer
| NOTE: **@src** must contain at least 8 elements.
Parameters:
| *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination matrix2x4
.. c:function:: void glm_mat2x4_mul(mat2x4 m1, mat4x2 m2, mat2 dest)
multiply m1 and m2 to dest
.. code-block:: c
glm_mat2x4_mul(mat2x4, mat4x2, mat2);
Parameters:
| *[in]* **m1** left matrix (mat2x4)
| *[in]* **m2** right matrix (mat4x2)
| *[out]* **dest** destination matrix (mat2)
.. c:function:: void glm_mat2x4_mulv(mat2x4 m, vec4 v, vec2 dest)
multiply mat2x4 with vec4 (column vector) and store in dest vector
Parameters:
| *[in]* **m** mat2x4 (left)
| *[in]* **v** vec4 (right, column vector)
| *[out]* **dest** destination (result, column vector)
.. c:function:: void glm_mat2x4_transpose(mat2x4 m, mat4x2 dest)
transpose matrix and store in dest
Parameters:
| *[in]* **m** matrix
| *[out]* **dest** destination
.. c:function:: void glm_mat2x4_scale(mat2x4 m, float s)
multiply matrix with scalar
Parameters:
| *[in, out]* **m** matrix
| *[in]* **s** scalar

View File

@@ -72,6 +72,7 @@ Functions documentation
.. c:function:: void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest)
multiply m1 and m2 to dest
m1, m2 and dest matrices can be same matrix, it is possible to write this:
.. code-block:: c
@@ -103,10 +104,10 @@ Functions documentation
.. c:function:: void glm_mat3_mulv(mat3 m, vec3 v, vec3 dest)
multiply mat4 with vec4 (column vector) and store in dest vector
multiply mat3 with vec3 (column vector) and store in dest vector
Parameters:
| *[in]* **mat** mat3 (left)
| *[in]* **m** mat3 (left)
| *[in]* **v** vec3 (right, column vector)
| *[out]* **dest** destination (result, column vector)
@@ -123,8 +124,8 @@ Functions documentation
multiply matrix with scalar
Parameters:
| *[in, out]* **mat** matrix
| *[in]* **dest** scalar
| *[in, out]* **m** matrix
| *[in]* **s** scalar
.. c:function:: float glm_mat3_det(mat3 mat)
@@ -193,7 +194,7 @@ Functions documentation
Create mat3 matrix from pointer
| NOTE: **@src** must contain 9 elements.
| NOTE: **@src** must contain at least 9 elements.
Parameters:
| *[in]* **src** pointer to an array of floats

89
docs/source/mat3x2.rst Normal file
View File

@@ -0,0 +1,89 @@
.. default-domain:: C
mat3x2
======
Header: cglm/mat3x2.h
Table of contents (click to go):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Macros:
1. GLM_MAT3X2_ZERO_INIT
#. GLM_MAT3X2_ZERO
Functions:
1. :c:func:`glm_mat3x2_copy`
#. :c:func:`glm_mat3x2_zero`
#. :c:func:`glm_mat3x2_make`
#. :c:func:`glm_mat3x2_mul`
#. :c:func:`glm_mat3x2_mulv`
#. :c:func:`glm_mat3x2_transpose`
#. :c:func:`glm_mat3x2_scale`
Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~
.. c:function:: void glm_mat3x2_copy(mat3x2 mat, mat3x2 dest)
copy mat3x2 to another one (dest).
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination
.. c:function:: void glm_mat3x2_zero(mat3x2 mat)
make given matrix zero
Parameters:
| *[in,out]* **mat** matrix
.. c:function:: void glm_mat3x2_make(float * __restrict src, mat3x2 dest)
Create mat3x2 matrix from pointer
| NOTE: **@src** must contain at least 6 elements.
Parameters:
| *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination matrix3x2
.. c:function:: void glm_mat3x2_mul(mat3x2 m1, mat2x3 m2, mat3 dest)
multiply m1 and m2 to dest
.. code-block:: c
glm_mat3x2_mul(mat3x2, mat2x3, mat3);
Parameters:
| *[in]* **m1** left matrix (mat3x2)
| *[in]* **m2** right matrix (mat2x3)
| *[out]* **dest** destination matrix (mat3)
.. c:function:: void glm_mat3x2_mulv(mat3x2 m, vec2 v, vec3 dest)
multiply mat3x2 with vec2 (column vector) and store in dest vector
Parameters:
| *[in]* **m** mat3x2 (left)
| *[in]* **v** vec3 (right, column vector)
| *[out]* **dest** destination (result, column vector)
.. c:function:: void glm_mat3x2_transpose(mat3x2 m, mat2x3 dest)
transpose matrix and store in dest
Parameters:
| *[in]* **m** matrix
| *[out]* **dest** destination
.. c:function:: void glm_mat3x2_scale(mat3x2 m, float s)
multiply matrix with scalar
Parameters:
| *[in, out]* **m** matrix
| *[in]* **s** scalar

89
docs/source/mat3x4.rst Normal file
View File

@@ -0,0 +1,89 @@
.. default-domain:: C
mat3x4
======
Header: cglm/mat3x4.h
Table of contents (click to go):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Macros:
1. GLM_MAT3X4_ZERO_INIT
#. GLM_MAT3X4_ZERO
Functions:
1. :c:func:`glm_mat3x4_copy`
#. :c:func:`glm_mat3x4_zero`
#. :c:func:`glm_mat3x4_make`
#. :c:func:`glm_mat3x4_mul`
#. :c:func:`glm_mat3x4_mulv`
#. :c:func:`glm_mat3x4_transpose`
#. :c:func:`glm_mat3x4_scale`
Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~
.. c:function:: void glm_mat3x4_copy(mat3x4 mat, mat3x4 dest)
copy mat3x4 to another one (dest).
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination
.. c:function:: void glm_mat3x4_zero(mat3x4 mat)
make given matrix zero
Parameters:
| *[in,out]* **mat** matrix
.. c:function:: void glm_mat3x4_make(float * __restrict src, mat3x4 dest)
Create mat3x4 matrix from pointer
| NOTE: **@src** must contain at least 12 elements.
Parameters:
| *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination matrix3x4
.. c:function:: void glm_mat3x4_mul(mat3x4 m1, mat4x3 m2, mat3 dest)
multiply m1 and m2 to dest
.. code-block:: c
glm_mat3x4_mul(mat3x4, mat4x3, mat3);
Parameters:
| *[in]* **m1** left matrix (mat3x4)
| *[in]* **m2** right matrix (mat4x3)
| *[out]* **dest** destination matrix (mat3)
.. c:function:: void glm_mat3x4_mulv(mat3x4 m, vec4 v, vec3 dest)
multiply mat3x4 with vec4 (column vector) and store in dest vector
Parameters:
| *[in]* **m** mat3x4 (left)
| *[in]* **v** vec4 (right, column vector)
| *[out]* **dest** destination (result, column vector)
.. c:function:: void glm_mat3x4_transpose(mat3x4 m, mat4x3 dest)
transpose matrix and store in dest
Parameters:
| *[in]* **m** matrix
| *[out]* **dest** destination
.. c:function:: void glm_mat3x4_scale(mat3x4 m, float s)
multiply matrix with scalar
Parameters:
| *[in, out]* **m** matrix
| *[in]* **s** scalar

View File

@@ -119,6 +119,7 @@ Functions documentation
.. c:function:: void glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest)
multiply m1 and m2 to dest
m1, m2 and dest matrices can be same matrix, it is possible to write this:
.. code-block:: c
@@ -157,7 +158,6 @@ Functions documentation
Parameters:
| *[in]* **m** mat4 (left)
| *[in]* **v** vec4 (right, column vector)
| *[in]* **last** 4th item to make it vec4
| *[out]* **dest** vec4 (result, column vector)
.. c:function:: void glm_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest)
@@ -308,7 +308,7 @@ Functions documentation
Create mat4 matrix from pointer
| NOTE: **@src** must contain 16 elements.
| NOTE: **@src** must contain at least 16 elements.
Parameters:
| *[in]* **src** pointer to an array of floats

89
docs/source/mat4x2.rst Normal file
View File

@@ -0,0 +1,89 @@
.. default-domain:: C
mat4x2
======
Header: cglm/mat4x2.h
Table of contents (click to go):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Macros:
1. GLM_MAT4X2_ZERO_INIT
#. GLM_MAT4X2_ZERO
Functions:
1. :c:func:`glm_mat4x2_copy`
#. :c:func:`glm_mat4x2_zero`
#. :c:func:`glm_mat4x2_make`
#. :c:func:`glm_mat4x2_mul`
#. :c:func:`glm_mat4x2_mulv`
#. :c:func:`glm_mat4x2_transpose`
#. :c:func:`glm_mat4x2_scale`
Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~
.. c:function:: void glm_mat4x2_copy(mat4x2 mat, mat4x2 dest)
copy mat4x2 to another one (dest).
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination
.. c:function:: void glm_mat4x2_zero(mat4x2 mat)
make given matrix zero
Parameters:
| *[in,out]* **mat** matrix
.. c:function:: void glm_mat4x2_make(float * __restrict src, mat4x2 dest)
Create mat4x2 matrix from pointer
| NOTE: **@src** must contain at least 8 elements.
Parameters:
| *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination matrix4x2
.. c:function:: void glm_mat4x2_mul(mat4x2 m1, mat2x4 m2, mat4 dest)
multiply m1 and m2 to dest
.. code-block:: c
glm_mat4x2_mul(mat4x2, mat2x4, mat4);
Parameters:
| *[in]* **m1** left matrix (mat4x2)
| *[in]* **m2** right matrix (mat2x4)
| *[out]* **dest** destination matrix (mat4)
.. c:function:: void glm_mat4x2_mulv(mat4x2 m, vec2 v, vec4 dest)
multiply mat4x2 with vec2 (column vector) and store in dest vector
Parameters:
| *[in]* **m** mat4x2 (left)
| *[in]* **v** vec2 (right, column vector)
| *[out]* **dest** destination (result, column vector)
.. c:function:: void glm_mat4x2_transpose(mat4x2 m, mat2x4 dest)
transpose matrix and store in dest
Parameters:
| *[in]* **m** matrix
| *[out]* **dest** destination
.. c:function:: void glm_mat4x2_scale(mat4x2 m, float s)
multiply matrix with scalar
Parameters:
| *[in, out]* **m** matrix
| *[in]* **s** scalar

89
docs/source/mat4x3.rst Normal file
View File

@@ -0,0 +1,89 @@
.. default-domain:: C
mat4x3
======
Header: cglm/mat4x3.h
Table of contents (click to go):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Macros:
1. GLM_MAT4X3_ZERO_INIT
#. GLM_MAT4X3_ZERO
Functions:
1. :c:func:`glm_mat4x3_copy`
#. :c:func:`glm_mat4x3_zero`
#. :c:func:`glm_mat4x3_make`
#. :c:func:`glm_mat4x3_mul`
#. :c:func:`glm_mat4x3_mulv`
#. :c:func:`glm_mat4x3_transpose`
#. :c:func:`glm_mat4x3_scale`
Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~
.. c:function:: void glm_mat4x3_copy(mat4x3 mat, mat4x3 dest)
copy mat4x3 to another one (dest).
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination
.. c:function:: void glm_mat4x3_zero(mat4x3 mat)
make given matrix zero
Parameters:
| *[in,out]* **mat** matrix
.. c:function:: void glm_mat4x3_make(float * __restrict src, mat4x3 dest)
Create mat4x3 matrix from pointer
| NOTE: **@src** must contain at least 12 elements.
Parameters:
| *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination matrix4x3
.. c:function:: void glm_mat4x3_mul(mat4x3 m1, mat3x4 m2, mat4 dest)
multiply m1 and m2 to dest
.. code-block:: c
glm_mat4x3_mul(mat4x3, mat3x4, mat4);
Parameters:
| *[in]* **m1** left matrix (mat4x3)
| *[in]* **m2** right matrix (mat3x4)
| *[out]* **dest** destination matrix (mat4)
.. c:function:: void glm_mat4x3_mulv(mat4x3 m, vec3 v, vec4 dest)
multiply mat4x3 with vec3 (column vector) and store in dest vector
Parameters:
| *[in]* **m** mat4x3 (left)
| *[in]* **v** vec3 (right, column vector)
| *[out]* **dest** destination (result, column vector)
.. c:function:: void glm_mat4x3_transpose(mat4x3 m, mat3x4 dest)
transpose matrix and store in dest
Parameters:
| *[in]* **m** matrix
| *[out]* **dest** destination
.. c:function:: void glm_mat4x3_scale(mat4x3 m, float s)
multiply matrix with scalar
Parameters:
| *[in, out]* **m** matrix
| *[in]* **s** scalar

View File

@@ -3,30 +3,30 @@
Troubleshooting
================================================================================
It is possible that sometimes you may get crashes or wrong results.
It is possible that you may sometimes get crashes or wrong results.
Follow these topics
Memory Allocation:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Again, **cglm** doesn't alloc any memory on heap.
cglm functions works like memcpy; it copies data from src,
makes calculations then copy the result to dest.
Recall that **cglm** does not alloc any memory on the heap.
cglm functions work like memcpy; they copy data from src,
make calculations, then copy the result to dest.
You are responsible for allocation of **src** and **dest** parameters.
Alignment:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**vec4** and **mat4** types requires 16 byte alignment.
These types are marked with align attribute to let compiler know about this
**vec4** and **mat4** types require 16 byte alignment.
These types are marked with the align attribute to let the compiler know about this
requirement.
But since MSVC (Windows) throws the error:
Since MSVC (Windows) throws this error:
**"formal parameter with requested alignment of 16 won't be aligned"**
The alignment attribute has been commented for MSVC
The alignment attribute has been commented out for MSVC
.. code-block:: c
@@ -37,61 +37,61 @@ The alignment attribute has been commented for MSVC
#endif.
So MSVC may not know about alignment requirements when creating variables.
The interesting thing is that, if I remember correctly Visual Studio 2017
The interesting thing is that, if I remember correctly, Visual Studio 2017
doesn't throw the above error. So we may uncomment that line for Visual Studio 2017,
you may do it yourself.
**This MSVC issue is still in TODOs.**
**UPDATE:** By starting v0.4.5 cglm provides an option to disable alignment requirement.
Also alignment is disabled for older msvc verisons as default. Now alignment is only required in Visual Studio 2017 version 15.6+ if CGLM_ALL_UNALIGNED macro is not defined.
**UPDATE:** Starting with v0.4.5, cglm provides an option to disable the alignment requirement.
Also, alignment is disabled for older msvc versions by default. Now alignment is only required in Visual Studio 2017 version 15.6+ if the CGLM_ALL_UNALIGNED macro is not defined.
Crashes, Invalid Memory Access:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Probably you are trying to write to invalid memory location.
Most likely, you are trying to write to an invalid memory location.
You may used wrong function for what you want to do.
You may have used a wrong function for what you want to do.
For instance you may called **glm_vec4_** functions for **vec3** data type.
It will try to write 32 byte but since **vec3** is 24 byte it should throw
memory access error or exit the app without saying anything.
For example, you may have called a **glm_vec4_** function for a **vec3** data type.
It will try to write 32 bytes, but since **vec3** is 24 bytes, it should throw
a memory access error or exit the app without saying anything.
**UPDATE - IMPORTANT:**
| On MSVC or some other compilers, if alignment is enabled (default) then double check alignment requirements if you got a crash.
| If you send GLM_VEC4_ONE or similar macros directly to a function, it may be crashed.
| Because compiler may not apply alignment as defined on **typedef** to that macro while passing it (on stack) to a function.
| If you send GLM_VEC4_ONE or similar macros directly to a function, it may crash.
| Because the compiler may not apply alignment as defined on **typedef** to that macro while passing it (on stack) to a function.
Wrong Results:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Again, you may used wrong function.
Again, you may have used a wrong function.
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**.
Since you need to **vec4** to be normalized in your case, you will get wrong results.
For instance if you use **glm_normalize()** or **glm_vec3_normalize()** for a **vec4**,
it will assume that the passed param is a **vec3**, and will normalize it for **vec3**.
Since you need a **vec4** to be normalized in your case, you will get wrong results.
Accessing vec4 type with vec3 functions is valid, you will not get any error, exception or crash.
Accessing a vec4 type with vec3 functions is valid, you will not get any error, exception or crash.
You only get wrong results if you don't know what you are doing!
So be carefull, when your IDE (Xcode, Visual Studio ...) tried to autocomplete function names, READ IT :)
So be careful, when your IDE (Xcode, Visual Studio ...) tries to autocomplete function names, READ IT :)
**Also implementation may be wrong please let us know by creating an issue on Github.**
**Also implementation may be wrong, please let us know by creating an issue on Github.**
BAD_ACCESS : Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT) or Similar Errors/Crashes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is similar issue with alignment. For instance if you compiled **cglm** with
This is a similar issue with alignment. For instance if you compiled **cglm** with
AVX (**-mavx**, intentionally or not) and if you use **cglm** in an environment that doesn't
support AVX (or if AVX is disabled intentionally) e.g. environment that max support SSE2/3/4,
then you probably get **BAD ACCESS** or similar...
Because if you compile **cglm** with AVX it aligns **mat4** with 32 byte boundary,
and your project aligns that as 16 byte boundary...
and your project aligns that as a 16 byte boundary...
Check alignment, supported vector extension or simd in **cglm** and linked projects...
Check alignment, supported vector extension, or simd in **cglm** and linked projects...
Other Issues?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@@ -45,6 +45,7 @@ Functions:
#. :c:func:`glm_vec2_normalize`
#. :c:func:`glm_vec2_normalize_to`
#. :c:func:`glm_vec2_rotate`
#. :c:func:`glm_vec2_center`
#. :c:func:`glm_vec2_distance2`
#. :c:func:`glm_vec2_distance`
#. :c:func:`glm_vec2_maxv`
@@ -314,6 +315,15 @@ Functions documentation
| *[in]* **axis** axis vector
| *[out]* **dest** destination
.. c:function:: void glm_vec2_center(vec2 v1, vec2 v2, vec2 dest)
find center point of two vector
Parameters:
| *[in]* **v1** vector1
| *[in]* **v2** vector2
| *[out]* **dest** center point
.. c:function:: float glm_vec2_distance2(vec2 v1, vec2 v2)
squared distance between two vectors

View File

@@ -50,6 +50,14 @@ Functions documentation
| *[in]* **val** value
| *[out]* **dest** destination
.. c:function:: void glm_vec3_fill(vec3 v, float val)
fill a vector with specified value
Parameters:
| *[out]* **v** vector
| *[in]* **val** value
.. c:function:: bool glm_vec3_eq(vec3 v, float val)
check if vector is equal to value (without epsilon)

245
include/cglm/aabb2d.h Normal file
View File

@@ -0,0 +1,245 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglm_aabb2d_h
#define cglm_aabb2d_h
#include "common.h"
#include "vec2.h"
#include "vec4.h"
#include "util.h"
/*!
* @brief copy all members of [aabb] to [dest]
*
* @param[in] aabb source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_aabb2d_copy(vec2 aabb[2], vec2 dest[2]) {
glm_vec2_copy(aabb[0], dest[0]);
glm_vec2_copy(aabb[1], dest[1]);
}
/*!
* @brief apply transform to Axis-Aligned Bounding aabb
*
* @param[in] aabb bounding aabb
* @param[in] m transform matrix
* @param[out] dest transformed bounding aabb
*/
CGLM_INLINE
void
glm_aabb2d_transform(vec2 aabb[2], mat3 m, vec2 dest[2]) {
vec2 v[2], xa, xb, ya, yb;
glm_vec2_scale(m[0], aabb[0][0], xa);
glm_vec2_scale(m[0], aabb[1][0], xb);
glm_vec2_scale(m[1], aabb[0][1], ya);
glm_vec2_scale(m[1], aabb[1][1], yb);
/* translation + min(xa, xb) + min(ya, yb) */
glm_vec2(m[2], v[0]);
glm_vec2_minadd(xa, xb, v[0]);
glm_vec2_minadd(ya, yb, v[0]);
/* translation + max(xa, xb) + max(ya, yb) */
glm_vec2(m[2], v[1]);
glm_vec2_maxadd(xa, xb, v[1]);
glm_vec2_maxadd(ya, yb, v[1]);
glm_vec2_copy(v[0], dest[0]);
glm_vec2_copy(v[1], dest[1]);
}
/*!
* @brief merges two AABB bounding aabb and creates new one
*
* two aabb must be in same space, if one of aabb is in different space then
* you should consider to convert it's space by glm_aabb_space
*
* @param[in] aabb1 bounding aabb 1
* @param[in] aabb2 bounding aabb 2
* @param[out] dest merged bounding aabb
*/
CGLM_INLINE
void
glm_aabb2d_merge(vec2 aabb1[2], vec2 aabb2[2], vec2 dest[2]) {
dest[0][0] = glm_min(aabb1[0][0], aabb2[0][0]);
dest[0][1] = glm_min(aabb1[0][1], aabb2[0][1]);
dest[1][0] = glm_max(aabb1[1][0], aabb2[1][0]);
dest[1][1] = glm_max(aabb1[1][1], aabb2[1][1]);
}
/*!
* @brief crops a bounding aabb with another one.
*
* this could be useful for gettng a baabb which fits with view frustum and
* object bounding aabbes. In this case you crop view frustum aabb with objects
* aabb
*
* @param[in] aabb bounding aabb 1
* @param[in] cropAabb crop aabb
* @param[out] dest cropped bounding aabb
*/
CGLM_INLINE
void
glm_aabb2d_crop(vec2 aabb[2], vec2 cropAabb[2], vec2 dest[2]) {
dest[0][0] = glm_max(aabb[0][0], cropAabb[0][0]);
dest[0][1] = glm_max(aabb[0][1], cropAabb[0][1]);
dest[1][0] = glm_min(aabb[1][0], cropAabb[1][0]);
dest[1][1] = glm_min(aabb[1][1], cropAabb[1][1]);
}
/*!
* @brief crops a bounding aabb with another one.
*
* this could be useful for gettng a baabb which fits with view frustum and
* object bounding aabbes. In this case you crop view frustum aabb with objects
* aabb
*
* @param[in] aabb bounding aabb
* @param[in] cropAabb crop aabb
* @param[in] clampAabb miniumum aabb
* @param[out] dest cropped bounding aabb
*/
CGLM_INLINE
void
glm_aabb2d_crop_until(vec2 aabb[2],
vec2 cropAabb[2],
vec2 clampAabb[2],
vec2 dest[2]) {
glm_aabb2d_crop(aabb, cropAabb, dest);
glm_aabb2d_merge(clampAabb, dest, dest);
}
/*!
* @brief invalidate AABB min and max values
*
* @param[in, out] aabb bounding aabb
*/
CGLM_INLINE
void
glm_aabb2d_invalidate(vec2 aabb[2]) {
glm_vec2_fill(aabb[0], FLT_MAX);
glm_vec2_fill(aabb[1], -FLT_MAX);
}
/*!
* @brief check if AABB is valid or not
*
* @param[in] aabb bounding aabb
*/
CGLM_INLINE
bool
glm_aabb2d_isvalid(vec2 aabb[2]) {
return glm_vec2_max(aabb[0]) != FLT_MAX
&& glm_vec2_min(aabb[1]) != -FLT_MAX;
}
/*!
* @brief distance between of min and max
*
* @param[in] aabb bounding aabb
*/
CGLM_INLINE
float
glm_aabb2d_size(vec2 aabb[2]) {
return glm_vec2_distance(aabb[0], aabb[1]);
}
/*!
* @brief radius of sphere which surrounds AABB
*
* @param[in] aabb bounding aabb
*/
CGLM_INLINE
float
glm_aabb2d_radius(vec2 aabb[2]) {
return glm_aabb2d_size(aabb) * 0.5f;
}
/*!
* @brief computes center point of AABB
*
* @param[in] aabb bounding aabb
* @param[out] dest center of bounding aabb
*/
CGLM_INLINE
void
glm_aabb2d_center(vec2 aabb[2], vec2 dest) {
glm_vec2_center(aabb[0], aabb[1], dest);
}
/*!
* @brief check if two AABB intersects
*
* @param[in] aabb bounding aabb
* @param[in] other other bounding aabb
*/
CGLM_INLINE
bool
glm_aabb2d_aabb(vec2 aabb[2], vec2 other[2]) {
return (aabb[0][0] <= other[1][0] && aabb[1][0] >= other[0][0])
&& (aabb[0][1] <= other[1][1] && aabb[1][1] >= other[0][1]);
}
/*!
* @brief check if AABB intersects with a circle
*
* Circle Representation in cglm: [center.x, center.y, radii]
*
* @param[in] aabb solid bounding aabb
* @param[in] c solid circle
*/
CGLM_INLINE
bool
glm_aabb2d_circle(vec2 aabb[2], vec3 c) {
float dmin;
int a, b;
a = (c[0] < aabb[0][0]) + (c[0] > aabb[1][0]);
b = (c[1] < aabb[0][1]) + (c[1] > aabb[1][1]);
dmin = glm_pow2((c[0] - aabb[!(a - 1)][0]) * (a != 0))
+ glm_pow2((c[1] - aabb[!(b - 1)][1]) * (b != 0));
return dmin <= glm_pow2(c[2]);
}
/*!
* @brief check if point is inside of AABB
*
* @param[in] aabb bounding aabb
* @param[in] point point
*/
CGLM_INLINE
bool
glm_aabb2d_point(vec2 aabb[2], vec2 point) {
return (point[0] >= aabb[0][0] && point[0] <= aabb[1][0])
&& (point[1] >= aabb[0][1] && point[1] <= aabb[1][1]);
}
/*!
* @brief check if AABB contains other AABB
*
* @param[in] aabb bounding aabb
* @param[in] other other bounding aabb
*/
CGLM_INLINE
bool
glm_aabb2d_contains(vec2 aabb[2], vec2 other[2]) {
return (aabb[0][0] <= other[0][0] && aabb[1][0] >= other[1][0])
&& (aabb[0][1] <= other[0][1] && aabb[1][1] >= other[1][1]);
}
#endif /* cglm_aabb2d_h */

View File

@@ -19,14 +19,21 @@ extern "C" {
#include "call/ivec3.h"
#include "call/ivec4.h"
#include "call/mat2.h"
#include "call/mat2x3.h"
#include "call/mat2x4.h"
#include "call/mat3.h"
#include "call/mat3x2.h"
#include "call/mat3x4.h"
#include "call/mat4.h"
#include "call/mat4x2.h"
#include "call/mat4x3.h"
#include "call/affine.h"
#include "call/cam.h"
#include "call/quat.h"
#include "call/euler.h"
#include "call/plane.h"
#include "call/frustum.h"
#include "call/aabb2d.h"
#include "call/box.h"
#include "call/io.h"
#include "call/project.h"

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglmc_aabb2d_h
#define cglmc_aabb2d_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../cglm.h"
CGLM_EXPORT
void
glmc_aabb2d_copy(vec2 aabb[2], vec2 dest[2]);
CGLM_EXPORT
void
glmc_aabb2d_transform(vec2 aabb[2], mat3 m, vec2 dest[2]);
CGLM_EXPORT
void
glmc_aabb2d_merge(vec2 aabb1[2], vec2 aabb2[2], vec2 dest[2]);
CGLM_EXPORT
void
glmc_aabb2d_crop(vec2 aabb[2], vec2 cropAabb[2], vec2 dest[2]);
CGLM_EXPORT
void
glmc_aabb2d_crop_until(vec2 aabb[2],
vec2 cropAabb[2],
vec2 clampAabb[2],
vec2 dest[2]);
CGLM_EXPORT
void
glmc_aabb2d_invalidate(vec2 aabb[2]);
CGLM_EXPORT
bool
glmc_aabb2d_isvalid(vec2 aabb[2]);
CGLM_EXPORT
float
glmc_aabb2d_size(vec2 aabb[2]);
CGLM_EXPORT
float
glmc_aabb2d_radius(vec2 aabb[2]);
CGLM_EXPORT
void
glmc_aabb2d_center(vec2 aabb[2], vec2 dest);
CGLM_EXPORT
bool
glmc_aabb2d_aabb(vec2 aabb[2], vec2 other[2]);
CGLM_EXPORT
bool
glmc_aabb2d_point(vec2 aabb[2], vec2 point);
CGLM_EXPORT
bool
glmc_aabb2d_contains(vec2 aabb[2], vec2 other[2]);
CGLM_EXPORT
bool
glmc_aabb2d_circle(vec2 aabb[2], vec3 s);
#ifdef __cplusplus
}
#endif
#endif /* cglmc_aabb2d_h */

View File

@@ -49,6 +49,31 @@ CGLM_EXPORT
void
glmc_euler_by_order(vec3 angles, glm_euler_seq axis, mat4 dest);
CGLM_EXPORT
void
glmc_euler_xyz_quat(vec3 angles, versor dest);
CGLM_EXPORT
void
glmc_euler_xzy_quat(vec3 angles, versor dest);
CGLM_EXPORT
void
glmc_euler_yxz_quat(vec3 angles, versor dest);
CGLM_EXPORT
void
glmc_euler_yzx_quat(vec3 angles, versor dest);
CGLM_EXPORT
void
glmc_euler_zxy_quat(vec3 angles, versor dest);
CGLM_EXPORT
void
glmc_euler_zyx_quat(vec3 angles, versor dest);
#ifdef __cplusplus
}
#endif

View File

@@ -53,6 +53,70 @@ CGLM_EXPORT
void
glmc_ivec2_scale(ivec2 v, int s, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_addadd(ivec2 a, ivec2 b, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_addadds(ivec2 a, int s, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_subadd(ivec2 a, ivec2 b, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_subadds(ivec2 a, int s, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_muladd(ivec2 a, ivec2 b, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_muladds(ivec2 a, int s, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_maxadd(ivec2 a, ivec2 b, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_minadd(ivec2 a, ivec2 b, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_subsub(ivec2 a, ivec2 b, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_subsubs(ivec2 a, int s, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_addsub(ivec2 a, ivec2 b, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_addsubs(ivec2 a, int s, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_mulsub(ivec2 a, ivec2 b, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_mulsubs(ivec2 a, int s, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_maxsub(ivec2 a, ivec2 b, ivec2 dest);
CGLM_EXPORT
void
glmc_ivec2_minsub(ivec2 a, ivec2 b, ivec2 dest);
CGLM_EXPORT
int
glmc_ivec2_distance2(ivec2 a, ivec2 b);
@@ -61,6 +125,18 @@ CGLM_EXPORT
float
glmc_ivec2_distance(ivec2 a, ivec2 b);
CGLM_EXPORT
void
glmc_ivec2_fill(ivec2 v, int val);
CGLM_EXPORT
bool
glmc_ivec2_eq(ivec2 v, int val);
CGLM_EXPORT
bool
glmc_ivec2_eqv(ivec2 a, ivec2 b);
CGLM_EXPORT
void
glmc_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest);

View File

@@ -53,6 +53,70 @@ CGLM_EXPORT
void
glmc_ivec3_scale(ivec3 v, int s, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_addadd(ivec3 a, ivec3 b, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_addadds(ivec3 a, int s, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_subadd(ivec3 a, ivec3 b, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_subadds(ivec3 a, int s, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_muladd(ivec3 a, ivec3 b, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_muladds(ivec3 a, int s, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_maxadd(ivec3 a, ivec3 b, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_minadd(ivec3 a, ivec3 b, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_subsub(ivec3 a, ivec3 b, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_subsubs(ivec3 a, int s, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_addsub(ivec3 a, ivec3 b, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_addsubs(ivec3 a, int s, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_mulsub(ivec3 a, ivec3 b, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_mulsubs(ivec3 a, int s, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_maxsub(ivec3 a, ivec3 b, ivec3 dest);
CGLM_EXPORT
void
glmc_ivec3_minsub(ivec3 a, ivec3 b, ivec3 dest);
CGLM_EXPORT
int
glmc_ivec3_distance2(ivec3 a, ivec3 b);
@@ -61,6 +125,18 @@ CGLM_EXPORT
float
glmc_ivec3_distance(ivec3 a, ivec3 b);
CGLM_EXPORT
void
glmc_ivec3_fill(ivec3 v, int val);
CGLM_EXPORT
bool
glmc_ivec3_eq(ivec3 v, int val);
CGLM_EXPORT
bool
glmc_ivec3_eqv(ivec3 a, ivec3 b);
CGLM_EXPORT
void
glmc_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest);

View File

@@ -53,6 +53,70 @@ CGLM_EXPORT
void
glmc_ivec4_scale(ivec4 v, int s, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_addadd(ivec4 a, ivec4 b, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_addadds(ivec4 a, int s, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_subadd(ivec4 a, ivec4 b, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_subadds(ivec4 a, int s, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_muladd(ivec4 a, ivec4 b, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_muladds(ivec4 a, int s, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_maxadd(ivec4 a, ivec4 b, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_minadd(ivec4 a, ivec4 b, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_subsub(ivec4 a, ivec4 b, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_subsubs(ivec4 a, int s, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_addsub(ivec4 a, ivec4 b, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_addsubs(ivec4 a, int s, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_mulsub(ivec4 a, ivec4 b, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_mulsubs(ivec4 a, int s, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_maxsub(ivec4 a, ivec4 b, ivec4 dest);
CGLM_EXPORT
void
glmc_ivec4_minsub(ivec4 a, ivec4 b, ivec4 dest);
CGLM_EXPORT
int
glmc_ivec4_distance2(ivec4 a, ivec4 b);

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglmc_mat2x3_h
#define cglmc_mat2x3_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../cglm.h"
CGLM_EXPORT
void
glmc_mat2x3_copy(mat2x3 mat, mat2x3 dest);
CGLM_EXPORT
void
glmc_mat2x3_zero(mat2x3 mat);
CGLM_EXPORT
void
glmc_mat2x3_make(float * __restrict src, mat2x3 dest);
CGLM_EXPORT
void
glmc_mat2x3_mul(mat2x3 m1, mat3x2 m2, mat2 dest);
CGLM_EXPORT
void
glmc_mat2x3_mulv(mat2x3 m, vec3 v, vec2 dest);
CGLM_EXPORT
void
glmc_mat2x3_transpose(mat2x3 m, mat3x2 dest);
CGLM_EXPORT
void
glmc_mat2x3_scale(mat2x3 m, float s);
#ifdef __cplusplus
}
#endif
#endif /* cglmc_mat2x3_h */

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglmc_mat2x4_h
#define cglmc_mat2x4_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../cglm.h"
CGLM_EXPORT
void
glmc_mat2x4_copy(mat2x4 mat, mat2x4 dest);
CGLM_EXPORT
void
glmc_mat2x4_zero(mat2x4 mat);
CGLM_EXPORT
void
glmc_mat2x4_make(float * __restrict src, mat2x4 dest);
CGLM_EXPORT
void
glmc_mat2x4_mul(mat2x4 m1, mat4x2 m2, mat2 dest);
CGLM_EXPORT
void
glmc_mat2x4_mulv(mat2x4 m, vec4 v, vec2 dest);
CGLM_EXPORT
void
glmc_mat2x4_transpose(mat2x4 m, mat4x2 dest);
CGLM_EXPORT
void
glmc_mat2x4_scale(mat2x4 m, float s);
#ifdef __cplusplus
}
#endif
#endif /* cglmc_mat2x4_h */

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglmc_mat3x2_h
#define cglmc_mat3x2_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../cglm.h"
CGLM_EXPORT
void
glmc_mat3x2_copy(mat3x2 mat, mat3x2 dest);
CGLM_EXPORT
void
glmc_mat3x2_zero(mat3x2 mat);
CGLM_EXPORT
void
glmc_mat3x2_make(float * __restrict src, mat3x2 dest);
CGLM_EXPORT
void
glmc_mat3x2_mul(mat3x2 m1, mat2x3 m2, mat3 dest);
CGLM_EXPORT
void
glmc_mat3x2_mulv(mat3x2 m, vec2 v, vec3 dest);
CGLM_EXPORT
void
glmc_mat3x2_transpose(mat3x2 m, mat2x3 dest);
CGLM_EXPORT
void
glmc_mat3x2_scale(mat3x2 m, float s);
#ifdef __cplusplus
}
#endif
#endif /* cglmc_mat3x2_h */

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglmc_mat3x4_h
#define cglmc_mat3x4_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../cglm.h"
CGLM_EXPORT
void
glmc_mat3x4_copy(mat3x4 mat, mat3x4 dest);
CGLM_EXPORT
void
glmc_mat3x4_zero(mat3x4 mat);
CGLM_EXPORT
void
glmc_mat3x4_make(float * __restrict src, mat3x4 dest);
CGLM_EXPORT
void
glmc_mat3x4_mul(mat3x4 m1, mat4x3 m2, mat3 dest);
CGLM_EXPORT
void
glmc_mat3x4_mulv(mat3x4 m, vec4 v, vec3 dest);
CGLM_EXPORT
void
glmc_mat3x4_transpose(mat3x4 m, mat4x3 dest);
CGLM_EXPORT
void
glmc_mat3x4_scale(mat3x4 m, float s);
#ifdef __cplusplus
}
#endif
#endif /* cglmc_mat3x4_h */

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglmc_mat4x2_h
#define cglmc_mat4x2_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../cglm.h"
CGLM_EXPORT
void
glmc_mat4x2_copy(mat4x2 mat, mat4x2 dest);
CGLM_EXPORT
void
glmc_mat4x2_zero(mat4x2 mat);
CGLM_EXPORT
void
glmc_mat4x2_make(float * __restrict src, mat4x2 dest);
CGLM_EXPORT
void
glmc_mat4x2_mul(mat4x2 m1, mat2x4 m2, mat4 dest);
CGLM_EXPORT
void
glmc_mat4x2_mulv(mat4x2 m, vec2 v, vec4 dest);
CGLM_EXPORT
void
glmc_mat4x2_transpose(mat4x2 m, mat2x4 dest);
CGLM_EXPORT
void
glmc_mat4x2_scale(mat4x2 m, float s);
#ifdef __cplusplus
}
#endif
#endif /* cglmc_mat4x2_h */

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglmc_mat4x3_h
#define cglmc_mat4x3_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../cglm.h"
CGLM_EXPORT
void
glmc_mat4x3_copy(mat4x3 mat, mat4x3 dest);
CGLM_EXPORT
void
glmc_mat4x3_zero(mat4x3 mat);
CGLM_EXPORT
void
glmc_mat4x3_make(float * __restrict src, mat4x3 dest);
CGLM_EXPORT
void
glmc_mat4x3_mul(mat4x3 m1, mat3x4 m2, mat4 dest);
CGLM_EXPORT
void
glmc_mat4x3_mulv(mat4x3 m, vec3 v, vec4 dest);
CGLM_EXPORT
void
glmc_mat4x3_transpose(mat4x3 m, mat3x4 dest);
CGLM_EXPORT
void
glmc_mat4x3_scale(mat4x3 m, float s);
#ifdef __cplusplus
}
#endif
#endif /* cglmc_mat4x3_h */

View File

@@ -105,6 +105,30 @@ CGLM_EXPORT
void
glmc_vec2_minadd(vec2 a, vec2 b, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_subsub(vec2 a, vec2 b, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_addsub(vec2 a, vec2 b, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_mulsub(vec2 a, vec2 b, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_mulsubs(vec2 a, float s, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_maxsub(vec2 a, vec2 b, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_minsub(vec2 a, vec2 b, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_negate_to(vec2 v, vec2 dest);
@@ -125,6 +149,10 @@ CGLM_EXPORT
void
glmc_vec2_rotate(vec2 v, float angle, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_center(vec2 a, vec2 b, vec2 dest);
CGLM_EXPORT
float
glmc_vec2_distance2(vec2 a, vec2 b);

View File

@@ -132,6 +132,30 @@ CGLM_EXPORT
void
glmc_vec3_minadd(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_subsub(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_addsub(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_mulsub(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_mulsubs(vec3 a, float s, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_maxsub(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_minsub(vec3 a, vec3 b, vec3 dest);
CGLM_EXPORT
void
glmc_vec3_negate(vec3 v);

View File

@@ -133,6 +133,30 @@ CGLM_EXPORT
void
glmc_vec4_minadd(vec4 a, vec4 b, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_subsub(vec4 a, vec4 b, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_addsub(vec4 a, vec4 b, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_mulsub(vec4 a, vec4 b, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_mulsubs(vec4 a, float s, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_maxsub(vec4 a, vec4 b, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_minsub(vec4 a, vec4 b, vec4 dest);
CGLM_EXPORT
void
glmc_vec4_negate(vec4 v);

View File

@@ -16,14 +16,21 @@
#include "ivec3.h"
#include "ivec4.h"
#include "mat4.h"
#include "mat4x2.h"
#include "mat4x3.h"
#include "mat3.h"
#include "mat3x2.h"
#include "mat3x4.h"
#include "mat2.h"
#include "mat2x3.h"
#include "mat2x4.h"
#include "affine.h"
#include "cam.h"
#include "frustum.h"
#include "quat.h"
#include "euler.h"
#include "plane.h"
#include "aabb2d.h"
#include "box.h"
#include "color.h"
#include "util.h"

View File

@@ -30,6 +30,12 @@
CGLM_INLINE void glm_euler_by_order(vec3 angles,
glm_euler_seq ord,
mat4 dest);
CGLM_INLINE void glm_euler_xyz_quat(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_xzy_quat(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_yxz_quat(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_yzx_quat(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_zxy_quat(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_zyx_quat(vec3 angles, versor dest);
*/
#ifndef cglm_euler_h
@@ -37,6 +43,47 @@
#include "common.h"
#ifdef CGLM_FORCE_LEFT_HANDED
# include "handed/euler_to_quat_lh.h"
#else
# include "handed/euler_to_quat_rh.h"
#endif
#ifndef CGLM_CLIPSPACE_INCLUDE_ALL
# if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
# include "clipspace/ortho_lh_zo.h"
# include "clipspace/persp_lh_zo.h"
# include "clipspace/view_lh_zo.h"
# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
# include "clipspace/ortho_lh_no.h"
# include "clipspace/persp_lh_no.h"
# include "clipspace/view_lh_no.h"
# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
# include "clipspace/ortho_rh_zo.h"
# include "clipspace/persp_rh_zo.h"
# include "clipspace/view_rh_zo.h"
# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
# include "clipspace/ortho_rh_no.h"
# include "clipspace/persp_rh_no.h"
# include "clipspace/view_rh_no.h"
# endif
#else
# include "clipspace/ortho_lh_zo.h"
# include "clipspace/persp_lh_zo.h"
# include "clipspace/ortho_lh_no.h"
# include "clipspace/persp_lh_no.h"
# include "clipspace/ortho_rh_zo.h"
# include "clipspace/persp_rh_zo.h"
# include "clipspace/ortho_rh_no.h"
# include "clipspace/persp_rh_no.h"
# include "clipspace/view_lh_zo.h"
# include "clipspace/view_lh_no.h"
# include "clipspace/view_rh_zo.h"
# include "clipspace/view_rh_no.h"
#endif
/*!
* if you have axis order like vec3 orderVec = [0, 1, 2] or [0, 2, 1]...
* vector then you can convert it to this enum by doing this:
@@ -188,7 +235,6 @@ glm_euler_xzy(vec3 angles, mat4 dest) {
dest[3][3] = 1.0f;
}
/*!
* @brief build rotation matrix from euler angles
*
@@ -448,4 +494,108 @@ glm_euler_by_order(vec3 angles, glm_euler_seq ord, mat4 dest) {
dest[3][3] = 1.0f;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x y z order (roll pitch yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_xyz_quat(vec3 angles, versor dest) {
#ifdef CGLM_FORCE_LEFT_HANDED
glm_euler_xyz_quat_lh(angles, dest);
#else
glm_euler_xyz_quat_rh(angles, dest);
#endif
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x z y order (roll yaw pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_xzy_quat(vec3 angles, versor dest) {
#ifdef CGLM_FORCE_LEFT_HANDED
glm_euler_xzy_quat_lh(angles, dest);
#else
glm_euler_xzy_quat_rh(angles, dest);
#endif
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y x z order (pitch roll yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_yxz_quat(vec3 angles, versor dest) {
#ifdef CGLM_FORCE_LEFT_HANDED
glm_euler_yxz_quat_lh(angles, dest);
#else
glm_euler_yxz_quat_rh(angles, dest);
#endif
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y z x order (pitch yaw roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_yzx_quat(vec3 angles, versor dest) {
#ifdef CGLM_FORCE_LEFT_HANDED
glm_euler_yzx_quat_lh(angles, dest);
#else
glm_euler_yzx_quat_rh(angles, dest);
#endif
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z x y order (yaw roll pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_zxy_quat(vec3 angles, versor dest) {
#ifdef CGLM_FORCE_LEFT_HANDED
glm_euler_zxy_quat_lh(angles, dest);
#else
glm_euler_zxy_quat_rh(angles, dest);
#endif
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z y x order (yaw pitch roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_zyx_quat(vec3 angles, versor dest) {
#ifdef CGLM_FORCE_LEFT_HANDED
glm_euler_zyx_quat_lh(angles, dest);
#else
glm_euler_zyx_quat_rh(angles, dest);
#endif
}
#endif /* cglm_euler_h */

View File

@@ -0,0 +1,167 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Functions:
CGLM_INLINE void glm_euler_xyz_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_xzy_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_yxz_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_yzx_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_zxy_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_zyx_quat_lh(vec3 angles, versor dest);
*/
/*
Things to note:
The only difference between euler to quat rh vs lh is that the zsin part is negative
*/
#ifndef cglm_euler_to_quat_lh_h
#define cglm_euler_to_quat_lh_h
#include "../common.h"
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x y z order in left hand (roll pitch yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_xyz_quat_lh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;
xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = -sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);
dest[0] = xc * ys * zs + xs * yc * zc;
dest[1] = xc * ys * zc - xs * yc * zs;
dest[2] = xc * yc * zs + xs * ys * zc;
dest[3] = xc * yc * zc - xs * ys * zs;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x z y order in left hand (roll yaw pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_xzy_quat_lh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;
xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = -sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);
dest[0] = -xc * zs * ys + xs * zc * yc;
dest[1] = xc * zc * ys - xs * zs * yc;
dest[2] = xc * zs * yc + xs * zc * ys;
dest[3] = xc * zc * yc + xs * zs * ys;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y x z order in left hand (pitch roll yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_yxz_quat_lh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;
xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = -sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);
dest[0] = yc * xs * zc + ys * xc * zs;
dest[1] = -yc * xs * zs + ys * xc * zc;
dest[2] = yc * xc * zs - ys * xs * zc;
dest[3] = yc * xc * zc + ys * xs * zs;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y z x order in left hand (pitch yaw roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_yzx_quat_lh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;
xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = -sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);
dest[0] = yc * zc * xs + ys * zs * xc;
dest[1] = yc * zs * xs + ys * zc * xc;
dest[2] = yc * zs * xc - ys * zc * xs;
dest[3] = yc * zc * xc - ys * zs * xs;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z x y order in left hand (yaw roll pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_zxy_quat_lh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;
xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = -sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);
dest[0] = zc * xs * yc - zs * xc * ys;
dest[1] = zc * xc * ys + zs * xs * yc;
dest[2] = zc * xs * ys + zs * xc * yc;
dest[3] = zc * xc * yc - zs * xs * ys;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z y x order in left hand (yaw pitch roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_zyx_quat_lh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;
xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = -sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);
dest[0] = zc * yc * xs - zs * ys * xc;
dest[1] = zc * ys * xc + zs * yc * xs;
dest[2] = -zc * ys * xs + zs * yc * xc;
dest[3] = zc * yc * xc + zs * ys * xs;
}
#endif /*cglm_euler_to_quat_lh_h*/

View File

@@ -0,0 +1,170 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Functions:
CGLM_INLINE void glm_euler_xyz_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_xzy_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_yxz_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_yzx_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_zxy_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glm_euler_zyx_quat_rh(vec3 angles, versor dest);
*/
/*
Things to note:
The only difference between euler to quat rh vs lh is that the zsin part is negative
*/
#ifndef cglm_euler_to_quat_rh_h
#define cglm_euler_to_quat_rh_h
#include "../common.h"
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x y z order in right hand (roll pitch yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_xyz_quat_rh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;
xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);
dest[0] = xc * ys * zs + xs * yc * zc;
dest[1] = xc * ys * zc - xs * yc * zs;
dest[2] = xc * yc * zs + xs * ys * zc;
dest[3] = xc * yc * zc - xs * ys * zs;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x z y order in right hand (roll yaw pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_xzy_quat_rh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;
xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);
dest[0] = -xc * zs * ys + xs * zc * yc;
dest[1] = xc * zc * ys - xs * zs * yc;
dest[2] = xc * zs * yc + xs * zc * ys;
dest[3] = xc * zc * yc + xs * zs * ys;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y x z order in right hand (pitch roll yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_yxz_quat_rh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;
xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);
dest[0] = yc * xs * zc + ys * xc * zs;
dest[1] = -yc * xs * zs + ys * xc * zc;
dest[2] = yc * xc * zs - ys * xs * zc;
dest[3] = yc * xc * zc + ys * xs * zs;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y z x order in right hand (pitch yaw roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_yzx_quat_rh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;
xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);
dest[0] = yc * zc * xs + ys * zs * xc;
dest[1] = yc * zs * xs + ys * zc * xc;
dest[2] = yc * zs * xc - ys * zc * xs;
dest[3] = yc * zc * xc - ys * zs * xs;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z x y order in right hand (yaw roll pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_zxy_quat_rh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;
xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);
dest[0] = zc * xs * yc - zs * xc * ys;
dest[1] = zc * xc * ys + zs * xs * yc;
dest[2] = zc * xs * ys + zs * xc * yc;
dest[3] = zc * xc * yc - zs * xs * ys;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z y x order in right hand (yaw pitch roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
void
glm_euler_zyx_quat_rh(vec3 angles, versor dest) {
float xc, yc, zc,
xs, ys, zs;
xs = sinf(angles[0] * 0.5f); xc = cosf(angles[0] * 0.5f);
ys = sinf(angles[1] * 0.5f); yc = cosf(angles[1] * 0.5f);
zs = sinf(angles[2] * 0.5f); zc = cosf(angles[2] * 0.5f);
dest[0] = zc * yc * xs - zs * ys * xc;
dest[1] = zc * ys * xc + zs * yc * xs;
dest[2] = -zc * ys * xs + zs * yc * xc;
dest[3] = zc * yc * xc + zs * ys * xs;
}
#endif /*cglm_euler_to_quat_rh_h*/

View File

@@ -10,8 +10,11 @@
CGLM_INLINE void glm_mat4_print(mat4 matrix, FILE *ostream);
CGLM_INLINE void glm_mat3_print(mat3 matrix, FILE *ostream);
CGLM_INLINE void glm_vec4_print(vec4 vec, FILE *ostream);
CGLM_INLINE void glm_ivec4_print(ivec4 vec, FILE *ostream);
CGLM_INLINE void glm_vec3_print(vec3 vec, FILE *ostream);
CGLM_INLINE void glm_ivec3_print(ivec3 vec, FILE *ostream);
CGLM_INLINE void glm_vec2_print(vec2 vec, FILE *ostream);
CGLM_INLINE void glm_ivec2_print(ivec2 vec, FILE *ostream);
CGLM_INLINE void glm_versor_print(versor vec, FILE *ostream);
CGLM_INLINE void glm_arch_print(FILE *ostream);
*/
@@ -261,6 +264,24 @@ glm_vec4_print(vec4 vec,
#undef m
}
CGLM_INLINE
void
glm_ivec4_print(ivec4 vec,
FILE * __restrict ostream) {
int i;
#define m 4
fprintf(ostream, "Vector (int%d): " CGLM_PRINT_COLOR "\n (", m);
for (i = 0; i < m; i++)
fprintf(ostream, " % d", vec[i]);
fprintf(ostream, " )" CGLM_PRINT_COLOR_RESET "\n\n");
#undef m
}
CGLM_INLINE
void
glm_vec3_print(vec3 vec,
@@ -323,6 +344,24 @@ glm_vec2_print(vec2 vec,
#undef m
}
CGLM_INLINE
void
glm_ivec2_print(ivec2 vec,
FILE * __restrict ostream) {
int i;
#define m 2
fprintf(ostream, "Vector (int%d): " CGLM_PRINT_COLOR "\n (", m);
for (i = 0; i < m; i++)
fprintf(ostream, " % d", vec[i]);
fprintf(ostream, " )" CGLM_PRINT_COLOR_RESET "\n\n");
#undef m
}
CGLM_INLINE
void
glm_versor_print(versor vec,
@@ -387,9 +426,11 @@ glm_aabb_print(vec3 bbox[2],
#define glm_mat3_print(v, s) (void)v; (void)s;
#define glm_mat2_print(v, s) (void)v; (void)s;
#define glm_vec4_print(v, s) (void)v; (void)s;
#define glm_ivec4_print(v, s) (void)v; (void)s;
#define glm_vec3_print(v, s) (void)v; (void)s;
#define glm_ivec3_print(v, s) (void)v; (void)s;
#define glm_vec2_print(v, s) (void)v; (void)s;
#define glm_ivec2_print(v, s) (void)v; (void)s;
#define glm_versor_print(v, s) (void)v; (void)s;
#define glm_aabb_print(v, t, s) (void)v; (void)t; (void)s;
#define glm_arch_print(s) (void)s;

View File

@@ -23,8 +23,27 @@
CGLM_INLINE void glm_ivec2_subs(ivec2 v, int s, ivec2 dest)
CGLM_INLINE void glm_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE void glm_ivec2_scale(ivec2 v, int s, ivec2 dest)
CGLM_INLINE void glm_ivec2_addadd(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE void glm_ivec2_addadds(ivec2 a, int s, ivec2 dest)
CGLM_INLINE void glm_ivec2_subadd(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE void glm_ivec2_subadds(ivec2 a, int s, ivec2 dest)
CGLM_INLINE void glm_ivec2_muladd(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE void glm_ivec2_muladds(ivec2 a, int s, ivec2 dest)
CGLM_INLINE void glm_ivec2_maxadd(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE void glm_ivec2_minadd(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE void glm_ivec2_subsub(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE void glm_ivec2_subsubs(ivec2 a, int s, ivec2 dest)
CGLM_INLINE void glm_ivec2_addsub(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE void glm_ivec2_addsubs(ivec2 a, int s, ivec2 dest)
CGLM_INLINE void glm_ivec2_mulsub(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE void glm_ivec2_mulsubs(ivec2 a, int s, ivec2 dest)
CGLM_INLINE void glm_ivec2_maxsub(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE void glm_ivec2_minsub(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE int glm_ivec2_distance2(ivec2 a, ivec2 b)
CGLM_INLINE float glm_ivec2_distance(ivec2 a, ivec2 b)
CGLM_INLINE void glm_ivec2_fill(ivec2 v, int val);
CGLM_INLINE bool glm_ivec2_eq(ivec2 v, int val);
CGLM_INLINE bool glm_ivec2_eqv(ivec2 a, ivec2 b);
CGLM_INLINE void glm_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE void glm_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest)
CGLM_INLINE void glm_ivec2_clamp(ivec2 v, int minVal, int maxVal)
@@ -35,6 +54,7 @@
#define cglm_ivec2_h
#include "common.h"
#include "util.h"
#define GLM_IVEC2_ONE_INIT {1, 1}
#define GLM_IVEC2_ZERO_INIT {0, 0}
@@ -174,6 +194,262 @@ glm_ivec2_scale(ivec2 v, int s, ivec2 dest) {
dest[1] = v[1] * s;
}
/*!
* @brief add vector [a] with vector [b] and add result to vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += (a + b)
*/
CGLM_INLINE
void
glm_ivec2_addadd(ivec2 a, ivec2 b, ivec2 dest) {
dest[0] += a[0] + b[0];
dest[1] += a[1] + b[1];
}
/*!
* @brief add scalar [s] onto vector [a] and add result to vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest += (a + s)
*/
CGLM_INLINE
void
glm_ivec2_addadds(ivec2 a, int s, ivec2 dest) {
dest[0] += a[0] + s;
dest[1] += a[1] + s;
}
/*!
* @brief subtract vector [a] from vector [b] and add result to [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += (a - b)
*/
CGLM_INLINE
void
glm_ivec2_subadd(ivec2 a, ivec2 b, ivec2 dest) {
dest[0] += a[0] - b[0];
dest[1] += a[1] - b[1];
}
/*!
* @brief subtract scalar [s] from vector [a] and add result to [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first
* @param[in] s scalar
* @param[out] dest dest += (a - s)
*/
CGLM_INLINE
void
glm_ivec2_subadds(ivec2 a, int s, ivec2 dest) {
dest[0] += a[0] - s;
dest[1] += a[1] - s;
}
/*!
* @brief multiply vector [a] with vector [b] and add result to [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += (a * b)
*/
CGLM_INLINE
void
glm_ivec2_muladd(ivec2 a, ivec2 b, ivec2 dest) {
dest[0] += a[0] * b[0];
dest[1] += a[1] * b[1];
}
/*!
* @brief multiply vector [a] with scalar [s] and add result to [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest += (a * s)
*/
CGLM_INLINE
void
glm_ivec2_muladds(ivec2 a, int s, ivec2 dest) {
dest[0] += a[0] * s;
dest[1] += a[1] * s;
}
/*!
* @brief add maximum of vector [a] and vector [b] to vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += max(a, b)
*/
CGLM_INLINE
void
glm_ivec2_maxadd(ivec2 a, ivec2 b, ivec2 dest) {
dest[0] += glm_imax(a[0], b[0]);
dest[1] += glm_imax(a[1], b[1]);
}
/*!
* @brief add minimum of vector [a] and vector [b] to vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += min(a, b)
*/
CGLM_INLINE
void
glm_ivec2_minadd(ivec2 a, ivec2 b, ivec2 dest) {
dest[0] += glm_imin(a[0], b[0]);
dest[1] += glm_imin(a[1], b[1]);
}
/*!
* @brief subtract vector [a] from vector [b] and subtract result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest -= (a - b)
*/
CGLM_INLINE
void
glm_ivec2_subsub(ivec2 a, ivec2 b, ivec2 dest) {
dest[0] -= a[0] - b[0];
dest[1] -= a[1] - b[1];
}
/*!
* @brief subtract scalar [s] from vector [a] and subtract result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest -= (a - s)
*/
CGLM_INLINE
void
glm_ivec2_subsubs(ivec2 a, int s, ivec2 dest) {
dest[0] -= a[0] - s;
dest[1] -= a[1] - s;
}
/*!
* @brief add vector [a] to vector [b] and subtract the result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] b scalar
* @param[out] dest dest -= (a + b)
*/
CGLM_INLINE
void
glm_ivec2_addsub(ivec2 a, ivec2 b, ivec2 dest) {
dest[0] -= a[0] + b[0];
dest[1] -= a[1] + b[1];
}
/*!
* @brief add scalar [s] to vector [a] and subtract the result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest -= (a + b)
*/
CGLM_INLINE
void
glm_ivec2_addsubs(ivec2 a, int s, ivec2 dest) {
dest[0] -= a[0] + s;
dest[1] -= a[1] + s;
}
/*!
* @brief multiply vector [a] and vector [b] and subtract the result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] b scalar
* @param[out] dest dest -= (a * b)
*/
CGLM_INLINE
void
glm_ivec2_mulsub(ivec2 a, ivec2 b, ivec2 dest) {
dest[0] -= a[0] * b[0];
dest[1] -= a[1] * b[1];
}
/*!
* @brief multiply vector [a] with scalar [s] and subtract the result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest -= (a * s)
*/
CGLM_INLINE
void
glm_ivec2_mulsubs(ivec2 a, int s, ivec2 dest) {
dest[0] -= a[0] * s;
dest[1] -= a[1] * s;
}
/*!
* @brief subtract maximum of vector [a] and vector [b] from vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest -= max(a, b)
*/
CGLM_INLINE
void
glm_ivec2_maxsub(ivec2 a, ivec2 b, ivec2 dest) {
dest[0] -= glm_imax(a[0], b[0]);
dest[1] -= glm_imax(a[1], b[1]);
}
/*!
* @brief subtract minimum of vector [a] and vector [b] from vector [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest -= min(a, b)
*/
CGLM_INLINE
void
glm_ivec2_minsub(ivec2 a, ivec2 b, ivec2 dest) {
dest[0] -= glm_imin(a[0], b[0]);
dest[1] -= glm_imin(a[1], b[1]);
}
/*!
* @brief squared distance between two vectors
*
@@ -203,6 +479,44 @@ glm_ivec2_distance(ivec2 a, ivec2 b) {
return sqrtf((float)glm_ivec2_distance2(a, b));
}
/*!
* @brief fill a vector with specified value
*
* @param[out] v dest
* @param[in] val value
*/
CGLM_INLINE
void
glm_ivec2_fill(ivec2 v, int val) {
v[0] = v[1] = val;
}
/*!
* @brief check if vector is equal to value
*
* @param[in] v vector
* @param[in] val value
*/
CGLM_INLINE
bool
glm_ivec2_eq(ivec2 v, int val) {
return v[0] == val && v[0] == v[1];
}
/*!
* @brief check if vector is equal to another
*
* @param[in] a vector
* @param[in] b vector
*/
CGLM_INLINE
bool
glm_ivec2_eqv(ivec2 a, ivec2 b) {
return a[0] == b[0]
&& a[1] == b[1];
}
/*!
* @brief set each member of dest to greater of vector a and b
*

View File

@@ -23,8 +23,27 @@
CGLM_INLINE void glm_ivec3_subs(ivec3 v, int s, ivec3 dest)
CGLM_INLINE void glm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE void glm_ivec3_scale(ivec3 v, int s, ivec3 dest)
CGLM_INLINE void glm_ivec3_addadd(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE void glm_ivec3_addadds(ivec3 a, int s, ivec3 dest)
CGLM_INLINE void glm_ivec3_subadd(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE void glm_ivec3_subadds(ivec3 a, int s, ivec3 dest)
CGLM_INLINE void glm_ivec3_muladd(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE void glm_ivec3_muladds(ivec3 a, int s, ivec3 dest)
CGLM_INLINE void glm_ivec3_maxadd(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE void glm_ivec3_minadd(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE void glm_ivec3_subsub(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE void glm_ivec3_subsubs(ivec3 a, int s, ivec3 dest)
CGLM_INLINE void glm_ivec3_addsub(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE void glm_ivec3_addsubs(ivec3 a, int s, ivec3 dest)
CGLM_INLINE void glm_ivec3_mulsub(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE void glm_ivec3_mulsubs(ivec3 a, int s, ivec3 dest)
CGLM_INLINE void glm_ivec3_maxsub(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE void glm_ivec3_minsub(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE int glm_ivec3_distance2(ivec3 a, ivec3 b)
CGLM_INLINE float glm_ivec3_distance(ivec3 a, ivec3 b)
CGLM_INLINE void glm_ivec3_fill(ivec3 v, int val);
CGLM_INLINE bool glm_ivec3_eq(ivec3 v, int val);
CGLM_INLINE bool glm_ivec3_eqv(ivec3 a, ivec3 b);
CGLM_INLINE void glm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE void glm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest)
CGLM_INLINE void glm_ivec3_clamp(ivec3 v, int minVal, int maxVal)
@@ -35,6 +54,7 @@
#define cglm_ivec3_h
#include "common.h"
#include "util.h"
#define GLM_IVEC3_ONE_INIT {1, 1, 1}
#define GLM_IVEC3_ZERO_INIT {0, 0, 0}
@@ -182,6 +202,278 @@ glm_ivec3_scale(ivec3 v, int s, ivec3 dest) {
dest[2] = v[2] * s;
}
/*!
* @brief add vector [a] with vector [b] and add result to vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += (a + b)
*/
CGLM_INLINE
void
glm_ivec3_addadd(ivec3 a, ivec3 b, ivec3 dest) {
dest[0] += a[0] + b[0];
dest[1] += a[1] + b[1];
dest[2] += a[2] + b[2];
}
/*!
* @brief add scalar [s] onto vector [a] and add result to vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest += (a + s)
*/
CGLM_INLINE
void
glm_ivec3_addadds(ivec3 a, int s, ivec3 dest) {
dest[0] += a[0] + s;
dest[1] += a[1] + s;
dest[2] += a[2] + s;
}
/*!
* @brief subtract vector [a] from vector [b] and add result to [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += (a - b)
*/
CGLM_INLINE
void
glm_ivec3_subadd(ivec3 a, ivec3 b, ivec3 dest) {
dest[0] += a[0] - b[0];
dest[1] += a[1] - b[1];
dest[2] += a[2] - b[2];
}
/*!
* @brief subtract scalar [s] from vector [a] and add result to [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first
* @param[in] s scalar
* @param[out] dest dest += (a - s)
*/
CGLM_INLINE
void
glm_ivec3_subadds(ivec3 a, int s, ivec3 dest) {
dest[0] += a[0] - s;
dest[1] += a[1] - s;
dest[2] += a[2] - s;
}
/*!
* @brief multiply vector [a] with vector [b] and add result to [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += (a * b)
*/
CGLM_INLINE
void
glm_ivec3_muladd(ivec3 a, ivec3 b, ivec3 dest) {
dest[0] += a[0] * b[0];
dest[1] += a[1] * b[1];
dest[2] += a[2] * b[2];
}
/*!
* @brief multiply vector [a] with scalar [s] and add result to [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest += (a * s)
*/
CGLM_INLINE
void
glm_ivec3_muladds(ivec3 a, int s, ivec3 dest) {
dest[0] += a[0] * s;
dest[1] += a[1] * s;
dest[2] += a[2] * s;
}
/*!
* @brief add maximum of vector [a] and vector [b] to vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += max(a, b)
*/
CGLM_INLINE
void
glm_ivec3_maxadd(ivec3 a, ivec3 b, ivec3 dest) {
dest[0] += glm_imax(a[0], b[0]);
dest[1] += glm_imax(a[1], b[1]);
dest[2] += glm_imax(a[2], b[2]);
}
/*!
* @brief add minimum of vector [a] and vector [b] to vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += min(a, b)
*/
CGLM_INLINE
void
glm_ivec3_minadd(ivec3 a, ivec3 b, ivec3 dest) {
dest[0] += glm_imin(a[0], b[0]);
dest[1] += glm_imin(a[1], b[1]);
dest[2] += glm_imin(a[2], b[2]);
}
/*!
* @brief subtract vector [a] from vector [b] and subtract result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest -= (a - b)
*/
CGLM_INLINE
void
glm_ivec3_subsub(ivec3 a, ivec3 b, ivec3 dest) {
dest[0] -= a[0] - b[0];
dest[1] -= a[1] - b[1];
dest[2] -= a[2] - b[2];
}
/*!
* @brief subtract scalar [s] from vector [a] and subtract result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest -= (a - s)
*/
CGLM_INLINE
void
glm_ivec3_subsubs(ivec3 a, int s, ivec3 dest) {
dest[0] -= a[0] - s;
dest[1] -= a[1] - s;
dest[2] -= a[2] - s;
}
/*!
* @brief add vector [a] to vector [b] and subtract the result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] b scalar
* @param[out] dest dest -= (a + b)
*/
CGLM_INLINE
void
glm_ivec3_addsub(ivec3 a, ivec3 b, ivec3 dest) {
dest[0] -= a[0] + b[0];
dest[1] -= a[1] + b[1];
dest[2] -= a[2] + b[2];
}
/*!
* @brief add scalar [s] to vector [a] and subtract the result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest -= (a + b)
*/
CGLM_INLINE
void
glm_ivec3_addsubs(ivec3 a, int s, ivec3 dest) {
dest[0] -= a[0] + s;
dest[1] -= a[1] + s;
dest[2] -= a[2] + s;
}
/*!
* @brief multiply vector [a] and vector [b] and subtract the result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] b scalar
* @param[out] dest dest -= (a * b)
*/
CGLM_INLINE
void
glm_ivec3_mulsub(ivec3 a, ivec3 b, ivec3 dest) {
dest[0] -= a[0] * b[0];
dest[1] -= a[1] * b[1];
dest[2] -= a[2] * b[2];
}
/*!
* @brief multiply vector [a] with scalar [s] and subtract the result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest -= (a * s)
*/
CGLM_INLINE
void
glm_ivec3_mulsubs(ivec3 a, int s, ivec3 dest) {
dest[0] -= a[0] * s;
dest[1] -= a[1] * s;
dest[2] -= a[2] * s;
}
/*!
* @brief subtract maximum of vector [a] and vector [b] from vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest -= max(a, b)
*/
CGLM_INLINE
void
glm_ivec3_maxsub(ivec3 a, ivec3 b, ivec3 dest) {
dest[0] -= glm_imax(a[0], b[0]);
dest[1] -= glm_imax(a[1], b[1]);
dest[2] -= glm_imax(a[2], b[2]);
}
/*!
* @brief subtract minimum of vector [a] and vector [b] from vector [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest -= min(a, b)
*/
CGLM_INLINE
void
glm_ivec3_minsub(ivec3 a, ivec3 b, ivec3 dest) {
dest[0] -= glm_imin(a[0], b[0]);
dest[1] -= glm_imin(a[1], b[1]);
dest[2] -= glm_imin(a[2], b[2]);
}
/*!
* @brief squared distance between two vectors
*
@@ -212,6 +504,44 @@ glm_ivec3_distance(ivec3 a, ivec3 b) {
return sqrtf((float)glm_ivec3_distance2(a, b));
}
/*!
* @brief fill a vector with specified value
*
* @param[out] v dest
* @param[in] val value
*/
CGLM_INLINE
void
glm_ivec3_fill(ivec3 v, int val) {
v[0] = v[1] = v[2] = val;
}
/*!
* @brief check if vector is equal to value
*
* @param[in] v vector
* @param[in] val value
*/
CGLM_INLINE
bool
glm_ivec3_eq(ivec3 v, int val) {
return v[0] == val && v[0] == v[1] && v[0] == v[2];
}
/*!
* @brief check if vector is equal to another
*
* @param[in] a vector
* @param[in] b vector
*/
CGLM_INLINE
bool
glm_ivec3_eqv(ivec3 a, ivec3 b) {
return a[0] == b[0]
&& a[1] == b[1]
&& a[2] == b[2];
}
/*!
* @brief set each member of dest to greater of vector a and b
*

View File

@@ -23,6 +23,22 @@
CGLM_INLINE void glm_ivec4_subs(ivec4 v, int s, ivec4 dest)
CGLM_INLINE void glm_ivec4_mul(ivec4 a, ivec4 b, ivec4 dest)
CGLM_INLINE void glm_ivec4_scale(ivec4 v, int s, ivec4 dest)
CGLM_INLINE void glm_ivec4_addadd(ivec4 a, ivec4 b, ivec4 dest)
CGLM_INLINE void glm_ivec4_addadds(ivec4 a, int s, ivec4 dest)
CGLM_INLINE void glm_ivec4_subadd(ivec4 a, ivec4 b, ivec4 dest)
CGLM_INLINE void glm_ivec4_subadds(ivec4 a, int s, ivec4 dest)
CGLM_INLINE void glm_ivec4_muladd(ivec4 a, ivec4 b, ivec4 dest)
CGLM_INLINE void glm_ivec4_muladds(ivec4 a, int s, ivec4 dest)
CGLM_INLINE void glm_ivec4_maxadd(ivec4 a, ivec4 b, ivec4 dest)
CGLM_INLINE void glm_ivec4_minadd(ivec4 a, ivec4 b, ivec4 dest)
CGLM_INLINE void glm_ivec4_subsub(ivec4 a, ivec4 b, ivec4 dest)
CGLM_INLINE void glm_ivec4_subsubs(ivec4 a, int s, ivec4 dest)
CGLM_INLINE void glm_ivec4_addsub(ivec4 a, ivec4 b, ivec4 dest)
CGLM_INLINE void glm_ivec4_addsubs(ivec4 a, int s, ivec4 dest)
CGLM_INLINE void glm_ivec4_mulsub(ivec4 a, ivec4 b, ivec4 dest)
CGLM_INLINE void glm_ivec4_mulsubs(ivec4 a, int s, ivec4 dest)
CGLM_INLINE void glm_ivec4_maxsub(ivec4 a, ivec4 b, ivec4 dest)
CGLM_INLINE void glm_ivec4_minsub(ivec4 a, ivec4 b, ivec4 dest)
CGLM_INLINE int glm_ivec4_distance2(ivec4 a, ivec4 b)
CGLM_INLINE float glm_ivec4_distance(ivec4 a, ivec4 b)
CGLM_INLINE void glm_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest)
@@ -35,6 +51,7 @@
#define cglm_ivec4_h
#include "common.h"
#include "util.h"
#define GLM_IVEC4_ONE_INIT {1, 1, 1, 1}
#define GLM_IVEC4_ZERO_INIT {0, 0, 0, 0}
@@ -191,6 +208,294 @@ glm_ivec4_scale(ivec4 v, int s, ivec4 dest) {
dest[3] = v[3] * s;
}
/*!
* @brief add vector [a] with vector [b] and add result to vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += (a + b)
*/
CGLM_INLINE
void
glm_ivec4_addadd(ivec4 a, ivec4 b, ivec4 dest) {
dest[0] += a[0] + b[0];
dest[1] += a[1] + b[1];
dest[2] += a[2] + b[2];
dest[3] += a[3] + b[3];
}
/*!
* @brief add scalar [s] onto vector [a] and add result to vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest += (a + s)
*/
CGLM_INLINE
void
glm_ivec4_addadds(ivec4 a, int s, ivec4 dest) {
dest[0] += a[0] + s;
dest[1] += a[1] + s;
dest[2] += a[2] + s;
dest[3] += a[3] + s;
}
/*!
* @brief subtract vector [a] from vector [b] and add result to [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += (a - b)
*/
CGLM_INLINE
void
glm_ivec4_subadd(ivec4 a, ivec4 b, ivec4 dest) {
dest[0] += a[0] - b[0];
dest[1] += a[1] - b[1];
dest[2] += a[2] - b[2];
dest[3] += a[3] - b[3];
}
/*!
* @brief subtract scalar [s] from vector [a] and add result to [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first
* @param[in] s scalar
* @param[out] dest dest += (a - s)
*/
CGLM_INLINE
void
glm_ivec4_subadds(ivec4 a, int s, ivec4 dest) {
dest[0] += a[0] - s;
dest[1] += a[1] - s;
dest[2] += a[2] - s;
dest[3] += a[3] - s;
}
/*!
* @brief multiply vector [a] with vector [b] and add result to [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += (a * b)
*/
CGLM_INLINE
void
glm_ivec4_muladd(ivec4 a, ivec4 b, ivec4 dest) {
dest[0] += a[0] * b[0];
dest[1] += a[1] * b[1];
dest[2] += a[2] * b[2];
dest[3] += a[3] * b[3];
}
/*!
* @brief multiply vector [a] with scalar [s] and add result to [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest += (a * s)
*/
CGLM_INLINE
void
glm_ivec4_muladds(ivec4 a, int s, ivec4 dest) {
dest[0] += a[0] * s;
dest[1] += a[1] * s;
dest[2] += a[2] * s;
dest[3] += a[3] * s;
}
/*!
* @brief add maximum of vector [a] and vector [b] to vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += max(a, b)
*/
CGLM_INLINE
void
glm_ivec4_maxadd(ivec4 a, ivec4 b, ivec4 dest) {
dest[0] += glm_imax(a[0], b[0]);
dest[1] += glm_imax(a[1], b[1]);
dest[2] += glm_imax(a[2], b[2]);
dest[3] += glm_imax(a[3], b[3]);
}
/*!
* @brief add minimum of vector [a] and vector [b] to vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest += min(a, b)
*/
CGLM_INLINE
void
glm_ivec4_minadd(ivec4 a, ivec4 b, ivec4 dest) {
dest[0] += glm_imin(a[0], b[0]);
dest[1] += glm_imin(a[1], b[1]);
dest[2] += glm_imin(a[2], b[2]);
dest[3] += glm_imin(a[3], b[3]);
}
/*!
* @brief subtract vector [a] from vector [b] and subtract result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest -= (a - b)
*/
CGLM_INLINE
void
glm_ivec4_subsub(ivec4 a, ivec4 b, ivec4 dest) {
dest[0] -= a[0] - b[0];
dest[1] -= a[1] - b[1];
dest[2] -= a[2] - b[2];
dest[3] -= a[3] - b[3];
}
/*!
* @brief subtract scalar [s] from vector [a] and subtract result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest -= (a - s)
*/
CGLM_INLINE
void
glm_ivec4_subsubs(ivec4 a, int s, ivec4 dest) {
dest[0] -= a[0] - s;
dest[1] -= a[1] - s;
dest[2] -= a[2] - s;
dest[3] -= a[3] - s;
}
/*!
* @brief add vector [a] to vector [b] and subtract the result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] b scalar
* @param[out] dest dest -= (a + b)
*/
CGLM_INLINE
void
glm_ivec4_addsub(ivec4 a, ivec4 b, ivec4 dest) {
dest[0] -= a[0] + b[0];
dest[1] -= a[1] + b[1];
dest[2] -= a[2] + b[2];
dest[3] -= a[3] + b[3];
}
/*!
* @brief add scalar [s] to vector [a] and subtract the result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest -= (a + b)
*/
CGLM_INLINE
void
glm_ivec4_addsubs(ivec4 a, int s, ivec4 dest) {
dest[0] -= a[0] + s;
dest[1] -= a[1] + s;
dest[2] -= a[2] + s;
dest[3] -= a[3] + s;
}
/*!
* @brief multiply vector [a] and vector [b] and subtract the result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] b scalar
* @param[out] dest dest -= (a * b)
*/
CGLM_INLINE
void
glm_ivec4_mulsub(ivec4 a, ivec4 b, ivec4 dest) {
dest[0] -= a[0] * b[0];
dest[1] -= a[1] * b[1];
dest[2] -= a[2] * b[2];
dest[3] -= a[3] * b[3];
}
/*!
* @brief multiply vector [a] with scalar [s] and subtract the result from [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest -= (a * s)
*/
CGLM_INLINE
void
glm_ivec4_mulsubs(ivec4 a, int s, ivec4 dest) {
dest[0] -= a[0] * s;
dest[1] -= a[1] * s;
dest[2] -= a[2] * s;
dest[3] -= a[3] * s;
}
/*!
* @brief subtract maximum of vector [a] and vector [b] from vector [dest]
*
* applies += operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest -= max(a, b)
*/
CGLM_INLINE
void
glm_ivec4_maxsub(ivec4 a, ivec4 b, ivec4 dest) {
dest[0] -= glm_imax(a[0], b[0]);
dest[1] -= glm_imax(a[1], b[1]);
dest[2] -= glm_imax(a[2], b[2]);
dest[3] -= glm_imax(a[3], b[3]);
}
/*!
* @brief subtract minimum of vector [a] and vector [b] from vector [dest]
*
* applies -= operator so dest must be initialized
*
* @param[in] a first vector
* @param[in] b second vector
* @param[out] dest dest -= min(a, b)
*/
CGLM_INLINE
void
glm_ivec4_minsub(ivec4 a, ivec4 b, ivec4 dest) {
dest[0] -= glm_imin(a[0], b[0]);
dest[1] -= glm_imin(a[1], b[1]);
dest[2] -= glm_imin(a[2], b[2]);
dest[3] -= glm_imin(a[3], b[3]);
}
/*!
* @brief squared distance between two vectors
*

154
include/cglm/mat2x3.h Normal file
View File

@@ -0,0 +1,154 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLM_MAT2X3_ZERO_INIT
GLM_MAT2X3_ZERO
Functions:
CGLM_INLINE void glm_mat2x3_copy(mat2x3 mat, mat2x3 dest);
CGLM_INLINE void glm_mat2x3_zero(mat2x3 mat);
CGLM_INLINE void glm_mat2x3_make(float * __restrict src, mat2x3 dest);
CGLM_INLINE void glm_mat2x3_mul(mat2x3 m1, mat3x2 m2, mat2 dest);
CGLM_INLINE void glm_mat2x3_mulv(mat2x3 m, vec3 v, vec2 dest);
CGLM_INLINE void glm_mat2x3_transpose(mat2x3 m, mat3x2 dest);
CGLM_INLINE void glm_mat2x3_scale(mat2x3 m, float s);
*/
#ifndef cglm_mat2x3_h
#define cglm_mat2x3_h
#include "common.h"
#define GLM_MAT2X3_ZERO_INIT {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}}
/* for C only */
#define GLM_MAT2X3_ZERO GLM_MAT2X3_ZERO_INIT
/*!
* @brief copy all members of [mat] to [dest]
*
* @param[in] mat source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_mat2x3_copy(mat2x3 mat, mat2x3 dest) {
dest[0][0] = mat[0][0];
dest[0][1] = mat[0][1];
dest[0][2] = mat[0][2];
dest[1][0] = mat[1][0];
dest[1][1] = mat[1][1];
dest[1][2] = mat[1][2];
}
/*!
* @brief make given matrix zero.
*
* @param[in, out] mat matrix
*/
CGLM_INLINE
void
glm_mat2x3_zero(mat2x3 mat) {
CGLM_ALIGN_MAT mat2x3 t = GLM_MAT2X3_ZERO_INIT;
glm_mat2x3_copy(t, mat);
}
/*!
* @brief Create mat2x3 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @param[out] dest matrix
*/
CGLM_INLINE
void
glm_mat2x3_make(float * __restrict src, mat2x3 dest) {
dest[0][0] = src[0];
dest[0][1] = src[1];
dest[0][2] = src[2];
dest[1][0] = src[3];
dest[1][1] = src[4];
dest[1][2] = src[5];
}
/*!
* @brief multiply m1 and m2 to dest
*
* @code
* glm_mat2x3_mul(mat2x3, mat3x2, mat2);
* @endcode
*
* @param[in] m1 left matrix (mat2x3)
* @param[in] m2 right matrix (mat3x2)
* @param[out] dest destination matrix (mat2)
*/
CGLM_INLINE
void
glm_mat2x3_mul(mat2x3 m1, mat3x2 m2, mat2 dest) {
float a00 = m1[0][0], a01 = m1[0][1], a02 = m1[0][2],
a10 = m1[1][0], a11 = m1[1][1], a12 = m1[1][2],
b00 = m2[0][0], b01 = m2[0][1],
b10 = m2[1][0], b11 = m2[1][1],
b20 = m2[2][0], b21 = m2[2][1];
dest[0][0] = a00 * b00 + a01 * b10 + a02 * b20;
dest[0][1] = a00 * b01 + a01 * b11 + a02 * b21;
dest[1][0] = a10 * b00 + a11 * b10 + a12 * b20;
dest[1][1] = a10 * b01 + a11 * b11 + a12 * b21;
}
/*!
* @brief multiply matrix with column vector and store in dest vector
*
* @param[in] m matrix (left)
* @param[in] v vector (right, column vector)
* @param[out] dest result vector
*/
CGLM_INLINE
void
glm_mat2x3_mulv(mat2x3 m, vec3 v, vec2 dest) {
float v0 = v[0], v1 = v[1], v2 = v[2];
dest[0] = m[0][0] * v0 + m[0][1] * v1 + m[0][2] * v2;
dest[1] = m[1][0] * v0 + m[1][1] * v1 + m[1][2] * v2;
}
/*!
* @brief transpose matrix and store in dest
*
* @param[in] m matrix
* @param[out] dest result
*/
CGLM_INLINE
void
glm_mat2x3_transpose(mat2x3 m, mat3x2 dest) {
dest[0][0] = m[0][0]; dest[0][1] = m[1][0];
dest[1][0] = m[0][1]; dest[1][1] = m[1][1];
dest[2][0] = m[0][2]; dest[2][1] = m[1][2];
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in, out] m matrix
* @param[in] s scalar
*/
CGLM_INLINE
void
glm_mat2x3_scale(mat2x3 m, float s) {
m[0][0] *= s; m[0][1] *= s; m[0][2] *= s;
m[1][0] *= s; m[1][1] *= s; m[1][2] *= s;
}
#endif

154
include/cglm/mat2x4.h Normal file
View File

@@ -0,0 +1,154 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLM_MAT2X4_ZERO_INIT
GLM_MAT2X4_ZERO
Functions:
CGLM_INLINE void glm_mat2x4_copy(mat2x4 mat, mat2x4 dest);
CGLM_INLINE void glm_mat2x4_zero(mat2x4 mat);
CGLM_INLINE void glm_mat2x4_make(float * __restrict src, mat2x4 dest);
CGLM_INLINE void glm_mat2x4_mul(mat2x4 m1, mat4x2 m2, mat2 dest);
CGLM_INLINE void glm_mat2x4_mulv(mat2x4 m, vec4 v, vec2 dest);
CGLM_INLINE void glm_mat2x4_transpose(mat2x4 m, mat4x2 dest);
CGLM_INLINE void glm_mat2x4_scale(mat2x4 m, float s);
*/
#ifndef cglm_mat2x4_h
#define cglm_mat2x4_h
#include "common.h"
#include "vec4.h"
#define GLM_MAT2X4_ZERO_INIT {{0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 0.0f}}
/* for C only */
#define GLM_MAT2X4_ZERO GLM_MAT2X4_ZERO_INIT
/*!
* @brief copy all members of [mat] to [dest]
*
* @param[in] mat source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_mat2x4_copy(mat2x4 mat, mat2x4 dest) {
glm_vec4_ucopy(mat[0], dest[0]);
glm_vec4_ucopy(mat[1], dest[1]);
}
/*!
* @brief make given matrix zero.
*
* @param[in, out] mat matrix
*/
CGLM_INLINE
void
glm_mat2x4_zero(mat2x4 mat) {
CGLM_ALIGN_MAT mat2x4 t = GLM_MAT2X4_ZERO_INIT;
glm_mat2x4_copy(t, mat);
}
/*!
* @brief Create mat2x4 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @param[out] dest matrix
*/
CGLM_INLINE
void
glm_mat2x4_make(float * __restrict src, mat2x4 dest) {
dest[0][0] = src[0];
dest[0][1] = src[1];
dest[0][2] = src[2];
dest[0][3] = src[3];
dest[1][0] = src[4];
dest[1][1] = src[5];
dest[1][2] = src[6];
dest[1][3] = src[7];
}
/*!
* @brief multiply m1 and m2 to dest
*
* @code
* glm_mat2x4_mul(mat2x4, mat4x2, mat2);
* @endcode
*
* @param[in] m1 left matrix (mat2x4)
* @param[in] m2 right matrix (mat4x2)
* @param[out] dest destination matrix (mat2)
*/
CGLM_INLINE
void
glm_mat2x4_mul(mat2x4 m1, mat4x2 m2, mat2 dest) {
float a00 = m1[0][0], a01 = m1[0][1], a02 = m1[0][2], a03 = m1[0][3],
a10 = m1[1][0], a11 = m1[1][1], a12 = m1[1][2], a13 = m1[1][3],
b00 = m2[0][0], b01 = m2[0][1],
b10 = m2[1][0], b11 = m2[1][1],
b20 = m2[2][0], b21 = m2[2][1],
b30 = m2[3][0], b31 = m2[3][1];
dest[0][0] = a00 * b00 + a01 * b10 + a02 * b20 + a03 * b30;
dest[0][1] = a00 * b01 + a01 * b11 + a02 * b21 + a03 * b31;
dest[1][0] = a10 * b00 + a11 * b10 + a12 * b20 + a13 * b30;
dest[1][1] = a10 * b01 + a11 * b11 + a12 * b21 + a13 * b31;
}
/*!
* @brief multiply matrix with column vector and store in dest vector
*
* @param[in] m matrix (left)
* @param[in] v vector (right, column vector)
* @param[out] dest result vector
*/
CGLM_INLINE
void
glm_mat2x4_mulv(mat2x4 m, vec4 v, vec2 dest) {
float v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3];
dest[0] = m[0][0] * v0 + m[0][1] * v1 + m[0][2] * v2 + m[0][3] * v3;
dest[1] = m[1][0] * v0 + m[1][1] * v1 + m[1][2] * v2 + m[1][3] * v3;
}
/*!
* @brief transpose matrix and store in dest
*
* @param[in] m matrix
* @param[out] dest result
*/
CGLM_INLINE
void
glm_mat2x4_transpose(mat2x4 m, mat4x2 dest) {
dest[0][0] = m[0][0]; dest[0][1] = m[1][0];
dest[1][0] = m[0][1]; dest[1][1] = m[1][1];
dest[2][0] = m[0][2]; dest[2][1] = m[1][2];
dest[3][0] = m[0][3]; dest[3][1] = m[1][3];
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in, out] m matrix
* @param[in] s scalar
*/
CGLM_INLINE
void
glm_mat2x4_scale(mat2x4 m, float s) {
m[0][0] *= s; m[0][1] *= s; m[0][2] *= s; m[0][3] *= s;
m[1][0] *= s; m[1][1] *= s; m[1][2] *= s; m[1][3] *= s;
}
#endif

162
include/cglm/mat3x2.h Normal file
View File

@@ -0,0 +1,162 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLM_MAT3X2_ZERO_INIT
GLM_MAT3X2_ZERO
Functions:
CGLM_INLINE void glm_mat3x2_copy(mat3x2 mat, mat3x2 dest);
CGLM_INLINE void glm_mat3x2_zero(mat3x2 mat);
CGLM_INLINE void glm_mat3x2_make(float * __restrict src, mat3x2 dest);
CGLM_INLINE void glm_mat3x2_mul(mat3x2 m1, mat2x3 m2, mat3 dest);
CGLM_INLINE void glm_mat3x2_mulv(mat3x2 m, vec2 v, vec3 dest);
CGLM_INLINE void glm_mat3x2_transpose(mat3x2 m, mat2x3 dest);
CGLM_INLINE void glm_mat3x2_scale(mat3x2 m, float s);
*/
#ifndef cglm_mat3x2_h
#define cglm_mat3x2_h
#include "common.h"
#define GLM_MAT3X2_ZERO_INIT {{0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}}
/* for C only */
#define GLM_MAT3X2_ZERO GLM_MAT3X2_ZERO_INIT
/*!
* @brief copy all members of [mat] to [dest]
*
* @param[in] mat source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_mat3x2_copy(mat3x2 mat, mat3x2 dest) {
dest[0][0] = mat[0][0];
dest[0][1] = mat[0][1];
dest[1][0] = mat[1][0];
dest[1][1] = mat[1][1];
dest[2][0] = mat[2][0];
dest[2][1] = mat[2][1];
}
/*!
* @brief make given matrix zero.
*
* @param[in, out] mat matrix
*/
CGLM_INLINE
void
glm_mat3x2_zero(mat3x2 mat) {
CGLM_ALIGN_MAT mat3x2 t = GLM_MAT3X2_ZERO_INIT;
glm_mat3x2_copy(t, mat);
}
/*!
* @brief Create mat3x2 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @param[out] dest matrix
*/
CGLM_INLINE
void
glm_mat3x2_make(float * __restrict src, mat3x2 dest) {
dest[0][0] = src[0];
dest[0][1] = src[1];
dest[1][0] = src[2];
dest[1][1] = src[3];
dest[2][0] = src[4];
dest[2][1] = src[5];
}
/*!
* @brief multiply m1 and m2 to dest
*
* @code
* glm_mat3x2_mul(mat3x2, mat2x3, mat3);
* @endcode
*
* @param[in] m1 left matrix (mat3x2)
* @param[in] m2 right matrix (mat2x3)
* @param[out] dest destination matrix (mat3)
*/
CGLM_INLINE
void
glm_mat3x2_mul(mat3x2 m1, mat2x3 m2, mat3 dest) {
float a00 = m1[0][0], a01 = m1[0][1],
a10 = m1[1][0], a11 = m1[1][1],
a20 = m1[2][0], a21 = m1[2][1],
b00 = m2[0][0], b01 = m2[0][1], b02 = m2[0][2],
b10 = m2[1][0], b11 = m2[1][1], b12 = m2[1][2];
dest[0][0] = a00 * b00 + a01 * b10;
dest[0][1] = a00 * b01 + a01 * b11;
dest[0][2] = a00 * b02 + a01 * b12;
dest[1][0] = a10 * b00 + a11 * b10;
dest[1][1] = a10 * b01 + a11 * b11;
dest[1][2] = a10 * b02 + a11 * b12;
dest[2][0] = a20 * b00 + a21 * b10;
dest[2][1] = a20 * b01 + a21 * b11;
dest[2][2] = a20 * b02 + a21 * b12;
}
/*!
* @brief multiply matrix with column vector and store in dest vector
*
* @param[in] m matrix (left)
* @param[in] v vector (right, column vector)
* @param[out] dest result vector
*/
CGLM_INLINE
void
glm_mat3x2_mulv(mat3x2 m, vec2 v, vec3 dest) {
float v0 = v[0], v1 = v[1];
dest[0] = m[0][0] * v0 + m[0][1] * v1;
dest[1] = m[1][0] * v0 + m[1][1] * v1;
dest[2] = m[2][0] * v0 + m[2][1] * v1;
}
/*!
* @brief transpose matrix and store in dest
*
* @param[in] m matrix
* @param[out] dest result
*/
CGLM_INLINE
void
glm_mat3x2_transpose(mat3x2 m, mat2x3 dest) {
dest[0][0] = m[0][0]; dest[0][1] = m[1][0]; dest[0][2] = m[2][0];
dest[1][0] = m[0][1]; dest[1][1] = m[1][1]; dest[1][2] = m[2][1];
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in, out] m matrix
* @param[in] s scalar
*/
CGLM_INLINE
void
glm_mat3x2_scale(mat3x2 m, float s) {
m[0][0] *= s; m[0][1] *= s; m[1][0] *= s;
m[1][1] *= s; m[2][0] *= s; m[2][1] *= s;
}
#endif

171
include/cglm/mat3x4.h Normal file
View File

@@ -0,0 +1,171 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLM_MAT3X4_ZERO_INIT
GLM_MAT3X4_ZERO
Functions:
CGLM_INLINE void glm_mat3x4_copy(mat3x4 mat, mat3x4 dest);
CGLM_INLINE void glm_mat3x4_zero(mat3x4 mat);
CGLM_INLINE void glm_mat3x4_make(float * __restrict src, mat3x4 dest);
CGLM_INLINE void glm_mat3x4_mul(mat3x4 m1, mat4x3 m2, mat3 dest);
CGLM_INLINE void glm_mat3x4_mulv(mat3x4 m, vec4 v, vec3 dest);
CGLM_INLINE void glm_mat3x4_transpose(mat3x4 m, mat4x3 dest);
CGLM_INLINE void glm_mat3x4_scale(mat3x4 m, float s);
*/
#ifndef cglm_mat3x4_h
#define cglm_mat3x4_h
#include "common.h"
#define GLM_MAT3X4_ZERO_INIT {{0.0f, 0.0f, 0.0f, 0.0f}, \
{0.0f, 0.0f, 0.0f, 0.0f}, \
{0.0f, 0.0f, 0.0f, 0.0f}}
/* for C only */
#define GLM_MAT3X4_ZERO GLM_MAT3X4_ZERO_INIT
/*!
* @brief copy all members of [mat] to [dest]
*
* @param[in] mat source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_mat3x4_copy(mat3x4 mat, mat3x4 dest) {
glm_vec4_ucopy(mat[0], dest[0]);
glm_vec4_ucopy(mat[1], dest[1]);
glm_vec4_ucopy(mat[2], dest[2]);
}
/*!
* @brief make given matrix zero.
*
* @param[in, out] mat matrix
*/
CGLM_INLINE
void
glm_mat3x4_zero(mat3x4 mat) {
CGLM_ALIGN_MAT mat3x4 t = GLM_MAT3X4_ZERO_INIT;
glm_mat3x4_copy(t, mat);
}
/*!
* @brief Create mat3x4 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @param[out] dest matrix
*/
CGLM_INLINE
void
glm_mat3x4_make(float * __restrict src, mat3x4 dest) {
dest[0][0] = src[0];
dest[0][1] = src[1];
dest[0][2] = src[2];
dest[0][3] = src[3];
dest[1][0] = src[4];
dest[1][1] = src[5];
dest[1][2] = src[6];
dest[1][3] = src[7];
dest[2][0] = src[8];
dest[2][1] = src[9];
dest[2][2] = src[10];
dest[2][3] = src[11];
}
/*!
* @brief multiply m1 and m2 to dest
*
* @code
* glm_mat3x4_mul(mat3x4, mat4x3, mat3);
* @endcode
*
* @param[in] m1 left matrix (mat3x4)
* @param[in] m2 right matrix (mat4x3)
* @param[out] dest destination matrix (mat3)
*/
CGLM_INLINE
void
glm_mat3x4_mul(mat3x4 m1, mat4x3 m2, mat3 dest) {
float a00 = m1[0][0], a01 = m1[0][1], a02 = m1[0][2], a03 = m1[0][3],
a10 = m1[1][0], a11 = m1[1][1], a12 = m1[1][2], a13 = m1[1][3],
a20 = m1[2][0], a21 = m1[2][1], a22 = m1[2][2], a23 = m1[2][3],
b00 = m2[0][0], b01 = m2[0][1], b02 = m2[0][2],
b10 = m2[1][0], b11 = m2[1][1], b12 = m2[1][2],
b20 = m2[2][0], b21 = m2[2][1], b22 = m2[2][2],
b30 = m2[3][0], b31 = m2[3][1], b32 = m2[3][2];
dest[0][0] = a00 * b00 + a01 * b10 + a02 * b20 + a03 * b30;
dest[0][1] = a00 * b01 + a01 * b11 + a02 * b21 + a03 * b31;
dest[0][2] = a00 * b02 + a01 * b12 + a02 * b22 + a03 * b32;
dest[1][0] = a10 * b00 + a11 * b10 + a12 * b20 + a13 * b30;
dest[1][1] = a10 * b01 + a11 * b11 + a12 * b21 + a13 * b31;
dest[1][2] = a10 * b02 + a11 * b12 + a12 * b22 + a13 * b32;
dest[2][0] = a20 * b00 + a21 * b10 + a22 * b20 + a23 * b30;
dest[2][1] = a20 * b01 + a21 * b11 + a22 * b21 + a23 * b31;
dest[2][2] = a20 * b02 + a21 * b12 + a22 * b22 + a23 * b32;
}
/*!
* @brief multiply matrix with column vector and store in dest vector
*
* @param[in] m matrix (left)
* @param[in] v vector (right, column vector)
* @param[out] dest result vector
*/
CGLM_INLINE
void
glm_mat3x4_mulv(mat3x4 m, vec4 v, vec3 dest) {
float v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3];
dest[0] = m[0][0] * v0 + m[0][1] * v1 + m[0][2] * v2 + m[0][3] * v3;
dest[1] = m[1][0] * v0 + m[1][1] * v1 + m[1][2] * v2 + m[1][3] * v3;
dest[2] = m[2][0] * v0 + m[2][1] * v1 + m[2][2] * v2 + m[2][3] * v3;
}
/*!
* @brief transpose matrix and store in dest
*
* @param[in] m matrix
* @param[out] dest result
*/
CGLM_INLINE
void
glm_mat3x4_transpose(mat3x4 m, mat4x3 dest) {
dest[0][0] = m[0][0]; dest[0][1] = m[1][0]; dest[0][2] = m[2][0];
dest[1][0] = m[0][1]; dest[1][1] = m[1][1]; dest[1][2] = m[2][1];
dest[2][0] = m[0][2]; dest[2][1] = m[1][2]; dest[2][2] = m[2][2];
dest[3][0] = m[0][3]; dest[3][1] = m[1][3]; dest[3][2] = m[2][3];
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in, out] m matrix
* @param[in] s scalar
*/
CGLM_INLINE
void
glm_mat3x4_scale(mat3x4 m, float s) {
m[0][0] *= s; m[1][0] *= s; m[2][0] *= s;
m[0][1] *= s; m[1][1] *= s; m[2][1] *= s;
m[0][2] *= s; m[1][2] *= s; m[2][2] *= s;
m[0][3] *= s; m[1][3] *= s; m[2][3] *= s;
}
#endif

184
include/cglm/mat4x2.h Normal file
View File

@@ -0,0 +1,184 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLM_MAT4X2_ZERO_INIT
GLM_MAT4X2_ZERO
Functions:
CGLM_INLINE void glm_mat4x2_copy(mat4x2 mat, mat4x2 dest);
CGLM_INLINE void glm_mat4x2_zero(mat4x2 mat);
CGLM_INLINE void glm_mat4x2_make(float * __restrict src, mat4x2 dest);
CGLM_INLINE void glm_mat4x2_mul(mat4x2 m1, mat2x4 m2, mat4 dest);
CGLM_INLINE void glm_mat4x2_mulv(mat4x2 m, vec2 v, vec4 dest);
CGLM_INLINE void glm_mat4x2_transpose(mat4x2 m, mat2x4 dest);
CGLM_INLINE void glm_mat4x2_scale(mat4x2 m, float s);
*/
#ifndef cglm_mat4x2_h
#define cglm_mat4x2_h
#include "common.h"
#define GLM_MAT4X2_ZERO_INIT {{0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f}}
/* for C only */
#define GLM_MAT4X2_ZERO GLM_MAT4X2_ZERO_INIT
/*!
* @brief copy all members of [mat] to [dest]
*
* @param[in] mat source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_mat4x2_copy(mat4x2 mat, mat4x2 dest) {
dest[0][0] = mat[0][0];
dest[0][1] = mat[0][1];
dest[1][0] = mat[1][0];
dest[1][1] = mat[1][1];
dest[2][0] = mat[2][0];
dest[2][1] = mat[2][1];
dest[3][0] = mat[3][0];
dest[3][1] = mat[3][1];
}
/*!
* @brief make given matrix zero.
*
* @param[in, out] mat matrix
*/
CGLM_INLINE
void
glm_mat4x2_zero(mat4x2 mat) {
CGLM_ALIGN_MAT mat4x2 t = GLM_MAT4X2_ZERO_INIT;
glm_mat4x2_copy(t, mat);
}
/*!
* @brief Create mat4x2 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @param[out] dest matrix
*/
CGLM_INLINE
void
glm_mat4x2_make(float * __restrict src, mat4x2 dest) {
dest[0][0] = src[0];
dest[0][1] = src[1];
dest[1][0] = src[2];
dest[1][1] = src[3];
dest[2][0] = src[4];
dest[2][1] = src[5];
dest[3][0] = src[6];
dest[3][1] = src[7];
}
/*!
* @brief multiply m1 and m2 to dest
*
* @code
* glm_mat4x2_mul(mat4x2, mat2x4, mat4);
* @endcode
*
* @param[in] m1 left matrix (mat4x2)
* @param[in] m2 right matrix (mat2x4)
* @param[out] dest destination matrix (mat4)
*/
CGLM_INLINE
void
glm_mat4x2_mul(mat4x2 m1, mat2x4 m2, mat4 dest) {
float a00 = m1[0][0], a01 = m1[0][1],
a10 = m1[1][0], a11 = m1[1][1],
a20 = m1[2][0], a21 = m1[2][1],
a30 = m1[3][0], a31 = m1[3][1],
b00 = m2[0][0], b01 = m2[0][1], b02 = m2[0][2], b03 = m2[0][3],
b10 = m2[1][0], b11 = m2[1][1], b12 = m2[1][2], b13 = m2[1][3];
dest[0][0] = a00 * b00 + a01 * b10;
dest[0][1] = a00 * b01 + a01 * b11;
dest[0][2] = a00 * b02 + a01 * b12;
dest[0][3] = a00 * b03 + a01 * b13;
dest[1][0] = a10 * b00 + a11 * b10;
dest[1][1] = a10 * b01 + a11 * b11;
dest[1][2] = a10 * b02 + a11 * b12;
dest[1][3] = a10 * b03 + a11 * b13;
dest[2][0] = a20 * b00 + a21 * b10;
dest[2][1] = a20 * b01 + a21 * b11;
dest[2][2] = a20 * b02 + a21 * b12;
dest[2][3] = a20 * b03 + a21 * b13;
dest[3][0] = a30 * b00 + a31 * b10;
dest[3][1] = a30 * b01 + a31 * b11;
dest[3][2] = a30 * b02 + a31 * b12;
dest[3][3] = a30 * b03 + a31 * b13;
}
/*!
* @brief multiply matrix with column vector and store in dest vector
*
* @param[in] m matrix (left)
* @param[in] v vector (right, column vector)
* @param[out] dest result vector
*/
CGLM_INLINE
void
glm_mat4x2_mulv(mat4x2 m, vec2 v, vec4 dest) {
float v0 = v[0], v1 = v[1];
dest[0] = m[0][0] * v0 + m[0][1] * v1;
dest[1] = m[1][0] * v0 + m[1][1] * v1;
dest[2] = m[2][0] * v0 + m[2][1] * v1;
dest[3] = m[3][0] * v0 + m[3][1] * v1;
}
/*!
* @brief transpose matrix and store in dest
*
* @param[in] m matrix
* @param[out] dest result
*/
CGLM_INLINE
void
glm_mat4x2_transpose(mat4x2 m, mat2x4 dest) {
dest[0][0] = m[0][0];
dest[0][1] = m[1][0];
dest[0][2] = m[2][0];
dest[0][3] = m[3][0];
dest[1][0] = m[0][1];
dest[1][1] = m[1][1];
dest[1][2] = m[2][1];
dest[1][3] = m[3][1];
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in, out] m matrix
* @param[in] s scalar
*/
CGLM_INLINE
void
glm_mat4x2_scale(mat4x2 m, float s) {
m[0][0] *= s; m[0][1] *= s; m[1][0] *= s; m[1][1] *= s;
m[2][0] *= s; m[2][1] *= s; m[3][0] *= s; m[3][1] *= s;
}
#endif

201
include/cglm/mat4x3.h Normal file
View File

@@ -0,0 +1,201 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLM_MAT4X3_ZERO_INIT
GLM_MAT4X3_ZERO
Functions:
CGLM_INLINE void glm_mat4x3_copy(mat4x3 mat, mat4x3 dest);
CGLM_INLINE void glm_mat4x3_zero(mat4x3 mat);
CGLM_INLINE void glm_mat4x3_make(float * __restrict src, mat4x3 dest);
CGLM_INLINE void glm_mat4x3_mul(mat4x3 m1, mat3x4 m2, mat4 dest);
CGLM_INLINE void glm_mat4x3_mulv(mat4x3 m, vec3 v, vec4 dest);
CGLM_INLINE void glm_mat4x3_transpose(mat4x3 m, mat3x4 dest);
CGLM_INLINE void glm_mat4x3_scale(mat4x3 m, float s);
*/
#ifndef cglm_mat4x3_h
#define cglm_mat4x3_h
#include "common.h"
#define GLM_MAT4X3_ZERO_INIT {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, \
{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}}
/* for C only */
#define GLM_MAT4X3_ZERO GLM_MAT4X3_ZERO_INIT
/*!
* @brief copy all members of [mat] to [dest]
*
* @param[in] mat source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_mat4x3_copy(mat4x3 mat, mat4x3 dest) {
dest[0][0] = mat[0][0];
dest[0][1] = mat[0][1];
dest[0][2] = mat[0][2];
dest[1][0] = mat[1][0];
dest[1][1] = mat[1][1];
dest[1][2] = mat[1][2];
dest[2][0] = mat[2][0];
dest[2][1] = mat[2][1];
dest[2][2] = mat[2][2];
dest[3][0] = mat[3][0];
dest[3][1] = mat[3][1];
dest[3][2] = mat[3][2];
}
/*!
* @brief make given matrix zero.
*
* @param[in, out] mat matrix
*/
CGLM_INLINE
void
glm_mat4x3_zero(mat4x3 mat) {
CGLM_ALIGN_MAT mat4x3 t = GLM_MAT4X3_ZERO_INIT;
glm_mat4x3_copy(t, mat);
}
/*!
* @brief Create mat4x3 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @param[out] dest matrix
*/
CGLM_INLINE
void
glm_mat4x3_make(float * __restrict src, mat4x3 dest) {
dest[0][0] = src[0];
dest[0][1] = src[1];
dest[0][2] = src[2];
dest[1][0] = src[3];
dest[1][1] = src[4];
dest[1][2] = src[5];
dest[2][0] = src[6];
dest[2][1] = src[7];
dest[2][2] = src[8];
dest[3][0] = src[9];
dest[3][1] = src[10];
dest[3][2] = src[11];
}
/*!
* @brief multiply m1 and m2 to dest
*
* @code
* glm_mat4x3_mul(mat4x3, mat3x4, mat4);
* @endcode
*
* @param[in] m1 left matrix (mat4x3)
* @param[in] m2 right matrix (mat3x4)
* @param[out] dest destination matrix (mat4)
*/
CGLM_INLINE
void
glm_mat4x3_mul(mat4x3 m1, mat3x4 m2, mat4 dest) {
float a00 = m1[0][0], a01 = m1[0][1], a02 = m1[0][2],
a10 = m1[1][0], a11 = m1[1][1], a12 = m1[1][2],
a20 = m1[2][0], a21 = m1[2][1], a22 = m1[2][2],
a30 = m1[3][0], a31 = m1[3][1], a32 = m1[3][2],
b00 = m2[0][0], b01 = m2[0][1], b02 = m2[0][2], b03 = m2[0][3],
b10 = m2[1][0], b11 = m2[1][1], b12 = m2[1][2], b13 = m2[1][3],
b20 = m2[2][0], b21 = m2[2][1], b22 = m2[2][2], b23 = m2[2][3];
dest[0][0] = a00 * b00 + a01 * b10 + a02 * b20;
dest[0][1] = a00 * b01 + a01 * b11 + a02 * b21;
dest[0][2] = a00 * b02 + a01 * b12 + a02 * b22;
dest[0][3] = a00 * b03 + a01 * b13 + a02 * b23;
dest[1][0] = a10 * b00 + a11 * b10 + a12 * b20;
dest[1][1] = a10 * b01 + a11 * b11 + a12 * b21;
dest[1][2] = a10 * b02 + a11 * b12 + a12 * b22;
dest[1][3] = a10 * b03 + a11 * b13 + a12 * b23;
dest[2][0] = a20 * b00 + a21 * b10 + a22 * b20;
dest[2][1] = a20 * b01 + a21 * b11 + a22 * b21;
dest[2][2] = a20 * b02 + a21 * b12 + a22 * b22;
dest[2][3] = a20 * b03 + a21 * b13 + a22 * b23;
dest[3][0] = a30 * b00 + a31 * b10 + a32 * b20;
dest[3][1] = a30 * b01 + a31 * b11 + a32 * b21;
dest[3][2] = a30 * b02 + a31 * b12 + a32 * b22;
dest[3][3] = a30 * b03 + a31 * b13 + a32 * b23;
}
/*!
* @brief multiply matrix with column vector and store in dest vector
*
* @param[in] m matrix (left)
* @param[in] v vector (right, column vector)
* @param[out] dest result vector
*/
CGLM_INLINE
void
glm_mat4x3_mulv(mat4x3 m, vec3 v, vec4 dest) {
float v0 = v[0], v1 = v[1], v2 = v[2];
dest[0] = m[0][0] * v0 + m[0][1] * v1 + m[0][2] * v2;
dest[1] = m[1][0] * v0 + m[1][1] * v1 + m[1][2] * v2;
dest[2] = m[2][0] * v0 + m[2][1] * v1 + m[2][2] * v2;
dest[3] = m[3][0] * v0 + m[3][1] * v1 + m[3][2] * v2;
}
/*!
* @brief transpose matrix and store in dest
*
* @param[in] m matrix
* @param[out] dest result
*/
CGLM_INLINE
void
glm_mat4x3_transpose(mat4x3 m, mat3x4 dest) {
dest[0][0] = m[0][0];
dest[0][1] = m[1][0];
dest[0][2] = m[2][0];
dest[0][3] = m[3][0];
dest[1][0] = m[0][1];
dest[1][1] = m[1][1];
dest[1][2] = m[2][1];
dest[1][3] = m[3][1];
dest[2][0] = m[0][2];
dest[2][1] = m[1][2];
dest[2][2] = m[2][2];
dest[2][3] = m[3][2];
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in, out] m matrix
* @param[in] s scalar
*/
CGLM_INLINE
void
glm_mat4x3_scale(mat4x3 m, float s) {
m[0][0] *= s; m[0][1] *= s; m[0][2] *= s; m[1][0] *= s;
m[1][1] *= s; m[1][2] *= s; m[2][0] *= s; m[2][1] *= s;
m[2][2] *= s; m[3][0] *= s; m[3][1] *= s; m[3][2] *= s;
}
#endif

View File

@@ -258,7 +258,7 @@ glm_quat_normalize_to(versor q, versor dest) {
}
glmm_store(dest, wasm_f32x4_div(x0, wasm_f32x4_sqrt(xdot)));
#elif defined( __SSE2__ ) || defined( __SSE2__ )
#elif defined( __SSE__ ) || defined( __SSE2__ )
__m128 xdot, x0;
float dot;

View File

@@ -56,11 +56,9 @@ glmm_float32x4_init(float x, float y, float z, float w) {
#define glmm_float32x4_SIGNMASK_NPNP glmm_float32x4_init(-0.f, 0.f, -0.f, 0.f)
#define glmm_float32x4_SIGNMASK_NPPN glmm_float32x4_init(-0.f, 0.f, 0.f, -0.f)
static inline
float32x4_t
glmm_abs(float32x4_t v) {
return vabsq_f32(v);
}
static inline float32x4_t glmm_abs(float32x4_t v) { return vabsq_f32(v); }
static inline float32x4_t glmm_min(float32x4_t a, float32x4_t b) { return vminq_f32(a, b); }
static inline float32x4_t glmm_max(float32x4_t a, float32x4_t b) { return vmaxq_f32(a, b); }
static inline
float32x4_t
@@ -174,11 +172,7 @@ glmm_fnmadd(float32x4_t a, float32x4_t b, float32x4_t c) {
static inline
float32x4_t
glmm_fmsub(float32x4_t a, float32x4_t b, float32x4_t c) {
#if CGLM_ARM64
return vfmsq_f32(c, a, b);
#else
return vmlsq_f32(c, a, b);
#endif
return glmm_fmadd(a, b, vnegq_f32(c));
}
static inline

View File

@@ -63,7 +63,7 @@
#endif
/* ARM Neon */
#if defined(_WIN32)
#if defined(_WIN32) && defined(_MSC_VER)
/* TODO: non-ARM stuff already inported, will this be better option */
/* # include <intrin.h> */

View File

@@ -36,11 +36,9 @@
#define glmm_float32x4_SIGNMASK_NPPN GLMM__SIGNMASKf(GLMM_NEGZEROf, 0, 0, GLMM_NEGZEROf)
#define glmm_float32x4_SIGNMASK_NEG wasm_i32x4_const_splat(GLMM_NEGZEROf)
static inline
glmm_128
glmm_abs(glmm_128 x) {
return wasm_f32x4_abs(x);
}
static inline glmm_128 glmm_abs(glmm_128 x) { return wasm_f32x4_abs(x); }
static inline glmm_128 glmm_min(glmm_128 a, glmm_128 b) { return wasm_f32x4_pmin(b, a); }
static inline glmm_128 glmm_max(glmm_128 a, glmm_128 b) { return wasm_f32x4_pmax(b, a); }
static inline
glmm_128

View File

@@ -74,6 +74,9 @@ glmm_abs(__m128 x) {
return _mm_andnot_ps(glmm_float32x4_SIGNMASK_NEG, x);
}
static inline __m128 glmm_min(__m128 a, __m128 b) { return _mm_min_ps(a, b); }
static inline __m128 glmm_max(__m128 a, __m128 b) { return _mm_max_ps(a, b); }
static inline
__m128
glmm_vhadd(__m128 v) {

View File

@@ -17,8 +17,14 @@ extern "C" {
#include "struct/vec3.h"
#include "struct/vec4.h"
#include "struct/mat2.h"
#include "struct/mat2x3.h"
#include "struct/mat2x4.h"
#include "struct/mat3.h"
#include "struct/mat3x2.h"
#include "struct/mat3x4.h"
#include "struct/mat4.h"
#include "struct/mat4x2.h"
#include "struct/mat4x3.h"
#include "struct/affine.h"
#include "struct/frustum.h"
#include "struct/plane.h"

View File

@@ -0,0 +1,235 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglms_aabb2ds_h
#define cglms_aabb2ds_h
#include "../common.h"
#include "../types-struct.h"
#include "../aabb2d.h"
#include "vec2.h"
#include "vec4.h"
#include "mat4.h"
/* api definition */
#define glms_aabb2d_(NAME) CGLM_STRUCTAPI(aabb, NAME)
/*!
* @brief apply transform to Axis-Aligned Bounding Box
*
* @param[in] aabb bounding box
* @param[in] m transform matrix
* @param[out] dest transformed bounding box
*/
CGLM_INLINE
void
glms_aabb2d_(transform)(vec2s aabb[2], mat3s m, vec2s dest[2]) {
vec2 rawAabb[2];
vec2 rawDest[2];
glms_vec2_(unpack)(rawAabb, aabb, 2);
glm_aabb2d_transform(rawAabb, m.raw, rawDest);
glms_vec2_(pack)(dest, rawDest, 2);
}
/*!
* @brief merges two AABB bounding box and creates new one
*
* two box must be in same space, if one of box is in different space then
* you should consider to convert it's space by glm_box_space
*
* @param[in] aabb1 bounding box 1
* @param[in] aabb2 bounding box 2
* @param[out] dest merged bounding box
*/
CGLM_INLINE
void
glms_aabb2d_(merge)(vec2s aabb1[2], vec2s aabb2[2], vec2s dest[2]) {
vec2 rawAabb1[2];
vec2 rawAabb2[2];
vec2 rawDest[2];
glms_vec2_(unpack)(rawAabb1, aabb1, 2);
glms_vec2_(unpack)(rawAabb2, aabb2, 2);
glm_aabb2d_merge(rawAabb1, rawAabb2, rawDest);
glms_vec2_(pack)(dest, rawDest, 2);
}
/*!
* @brief crops a bounding box with another one.
*
* this could be useful for gettng a bbox which fits with view frustum and
* object bounding boxes. In this case you crop view frustum box with objects
* box
*
* @param[in] aabb bounding box 1
* @param[in] cropAabb crop box
* @param[out] dest cropped bounding box
*/
CGLM_INLINE
void
glms_aabb2d_(crop)(vec2s aabb[2], vec2s cropAabb[2], vec2s dest[2]) {
vec2 rawAabb[2];
vec2 rawCropAabb[2];
vec2 rawDest[2];
glms_vec2_(unpack)(rawAabb, aabb, 2);
glms_vec2_(unpack)(rawCropAabb, cropAabb, 2);
glm_aabb2d_crop(rawAabb, rawCropAabb, rawDest);
glms_vec2_(pack)(dest, rawDest, 2);
}
/*!
* @brief crops a bounding box with another one.
*
* this could be useful for gettng a bbox which fits with view frustum and
* object bounding boxes. In this case you crop view frustum box with objects
* box
*
* @param[in] aabb bounding box
* @param[in] cropAabb crop box
* @param[in] clampAabb miniumum box
* @param[out] dest cropped bounding box
*/
CGLM_INLINE
void
glms_aabb2d_(crop_until)(vec2s aabb[2],
vec2s cropAabb[2],
vec2s clampAabb[2],
vec2s dest[2]) {
glms_aabb2d_(crop)(aabb, cropAabb, dest);
glms_aabb2d_(merge)(clampAabb, dest, dest);
}
/*!
* @brief invalidate AABB min and max values
*
* @param[in, out] aabb bounding box
*/
CGLM_INLINE
void
glms_aabb2d_(invalidate)(vec2s box[2]) {
box[0] = glms_vec2_(fill)(FLT_MAX);
box[1] = glms_vec2_(fill)(-FLT_MAX);
}
/*!
* @brief check if AABB is valid or not
*
* @param[in] aabb bounding box
*/
CGLM_INLINE
bool
glms_aabb2d_(isvalid)(vec2s aabb[2]) {
vec2 rawAabb[2];
glms_vec2_(unpack)(rawAabb, aabb, 2);
return glm_aabb2d_isvalid(rawAabb);
}
/*!
* @brief distance between of min and max
*
* @param[in] aabb bounding box
*/
CGLM_INLINE
float
glms_aabb2d_(size)(vec2s aabb[2]) {
return glm_vec2_distance(aabb[0].raw, aabb[1].raw);
}
/*!
* @brief radius of sphere which surrounds AABB
*
* @param[in] aabb bounding box
*/
CGLM_INLINE
float
glms_aabb2d_(radius)(vec2s aabb[2]) {
return glms_aabb2d_(size)(aabb) * 0.5f;
}
/*!
* @brief computes center point of AABB
*
* @param[in] aabb bounding box
* @returns center of bounding box
*/
CGLM_INLINE
vec2s
glms_aabb2d_(center)(vec2s aabb[2]) {
return glms_vec2_(center)(aabb[0], aabb[1]);
}
/*!
* @brief check if two AABB intersects
*
* @param[in] aabb bounding box
* @param[in] other other bounding box
*/
CGLM_INLINE
bool
glms_aabb2d_(aabb)(vec2s aabb[2], vec2s other[2]) {
vec2 rawAabb[2];
vec2 rawOther[2];
glms_vec2_(unpack)(rawAabb, aabb, 2);
glms_vec2_(unpack)(rawOther, other, 2);
return glm_aabb2d_aabb(rawAabb, rawOther);
}
/*!
* @brief check if AABB intersects with a circle
*
* https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c
* Solid Box - Solid Sphere test.
*
* @param[in] aabb solid bounding box
* @param[in] s solid sphere
*/
CGLM_INLINE
bool
glms_aabb2d_(circle)(vec2s aabb[2], vec3s c) {
vec2 rawAabb[2];
glms_vec2_(unpack)(rawAabb, aabb, 2);
return glm_aabb2d_circle(rawAabb, c.raw);
}
/*!
* @brief check if point is inside of AABB
*
* @param[in] aabb bounding box
* @param[in] point point
*/
CGLM_INLINE
bool
glms_aabb2d_(point)(vec2s aabb[2], vec2s point) {
vec2 rawAabb[2];
glms_vec2_(unpack)(rawAabb, aabb, 2);
return glm_aabb2d_point(rawAabb, point.raw);
}
/*!
* @brief check if AABB contains other AABB
*
* @param[in] box bounding box
* @param[in] other other bounding box
*/
CGLM_INLINE
bool
glms_aabb2d_(contains)(vec2s aabb[2], vec2s other[2]) {
vec2 rawAabb[2];
vec2 rawOther[2];
glms_vec2_(unpack)(rawAabb, aabb, 2);
glms_vec2_(unpack)(rawOther, other, 2);
return glm_aabb2d_contains(rawAabb, rawOther);
}
#endif /* cglms_aabb2ds_h */

View File

@@ -22,7 +22,7 @@
CGLM_INLINE mat4s glms_rotate_make(float angle, vec3s axis);
CGLM_INLINE mat4s glms_rotate(mat4s m, float angle, vec3s axis);
CGLM_INLINE mat4s glms_rotate_at(mat4s m, vec3s pivot, float angle, vec3s axis);
CGLM_INLINE mat4s glms_rotate_atm(mat4s m, vec3s pivot, float angle, vec3s axis);
CGLM_INLINE mat4s glms_rotate_atm(vec3s pivot, float angle, vec3s axis);
CGLM_INLINE mat4s glms_spin(mat4s m, float angle, vec3s axis);
CGLM_INLINE vec3s glms_decompose_scalev(mat4s m);
CGLM_INLINE bool glms_uniscaled(mat4s m);
@@ -125,7 +125,6 @@ glms_rotate_make(float angle, vec3s axis) {
* this should work faster than glm_rotate_at because it reduces
* one glm_translate.
*
* @param[in] m affine transfrom
* @param[in] pivot rotation center
* @param[in] angle angle (radians)
* @param[in] axis axis
@@ -133,7 +132,8 @@ glms_rotate_make(float angle, vec3s axis) {
*/
CGLM_INLINE
mat4s
glms_rotate_atm(mat4s m, vec3s pivot, float angle, vec3s axis) {
glms_rotate_atm(vec3s pivot, float angle, vec3s axis) {
mat4s m;
glm_rotate_atm(m.raw, pivot.raw, angle, axis.raw);
return m;
}

View File

@@ -24,6 +24,8 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../vec3.h"
#include "../../clipspace/ortho_lh_no.h"
/*!
* @brief set up orthographic projection matrix

View File

@@ -24,6 +24,8 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../vec3.h"
#include "../../clipspace/ortho_lh_zo.h"
/*!
* @brief set up orthographic projection matrix

View File

@@ -24,6 +24,8 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../vec3.h"
#include "../../clipspace/ortho_rh_no.h"
/*!
* @brief set up orthographic projection matrix

View File

@@ -24,6 +24,8 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../vec3.h"
#include "../../clipspace/ortho_rh_zo.h"
/*!
* @brief set up orthographic projection matrix

View File

@@ -39,6 +39,7 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../../clipspace/persp_lh_no.h"
/*!
* @brief set up perspective peprojection matrix

View File

@@ -39,6 +39,7 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../../clipspace/persp_lh_zo.h"
/*!
* @brief set up perspective peprojection matrix

View File

@@ -39,6 +39,7 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../../clipspace/persp_rh_no.h"
/*!
* @brief set up perspective peprojection matrix

View File

@@ -39,6 +39,7 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../../clipspace/persp_rh_zo.h"
/*!
* @brief set up perspective peprojection matrix

View File

@@ -7,8 +7,9 @@
/*
Functions:
CGLM_INLINE vec3s glms_unprojecti_no(vec3s pos, mat4s invMat, vec4s vp, vec3 dest)
CGLM_INLINE vec3s glms_project_no(vec3s pos, mat4s m, vec4s vp, vec3s dest)
CGLM_INLINE vec3s glms_unprojecti_no(vec3s pos, mat4s invMat, vec4s vp)
CGLM_INLINE vec3s glms_project_no(vec3s pos, mat4s m, vec4s vp)
CGLM_INLINE float glms_project_z_no(vec3s v, mat4s m)
*/
#ifndef cglms_project_no_h
@@ -18,6 +19,7 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../../clipspace/project_no.h"
/*!
* @brief maps the specified viewport coordinates into specified space [1]
@@ -48,7 +50,7 @@
*/
CGLM_INLINE
vec3s
glms_unprojecti_no(vec3s pos, mat4s invMat, vec4s vp, vec3 dest) {
glms_unprojecti_no(vec3s pos, mat4s invMat, vec4s vp) {
vec3s dest;
glm_unprojecti_no(pos.raw, invMat.raw, vp.raw, dest.raw);
return dest;
@@ -69,7 +71,7 @@ glms_unprojecti_no(vec3s pos, mat4s invMat, vec4s vp, vec3 dest) {
*/
CGLM_INLINE
vec3s
glms_project_no(vec3s pos, mat4s m, vec4s vp, vec3s dest) {
glms_project_no(vec3s pos, mat4s m, vec4s vp) {
vec3s dest;
glm_project_no(pos.raw, m.raw, vp.raw, dest.raw);
return dest;
@@ -88,7 +90,7 @@ glms_project_no(vec3s pos, mat4s m, vec4s vp, vec3s dest) {
* @returns projected z coordinate
*/
CGLM_INLINE
vec3s
float
glms_project_z_no(vec3s v, mat4s m) {
return glm_project_z_no(v.raw, m.raw);
}

View File

@@ -7,8 +7,9 @@
/*
Functions:
CGLM_INLINE vec3s glms_unprojecti_no(vec3s pos, mat4s invMat, vec4s vp, vec3 dest)
CGLM_INLINE vec3s glms_project_no(vec3s pos, mat4s m, vec4s vp, vec3s dest)
CGLM_INLINE vec3s glms_unprojecti_no(vec3s pos, mat4s invMat, vec4s vp)
CGLM_INLINE vec3s glms_project_no(vec3s pos, mat4s m, vec4s vp)
CGLM_INLINE float glms_project_z_zo(vec3s v, mat4s m)
*/
#ifndef cglms_project_zo_h
@@ -18,6 +19,7 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../../clipspace/project_zo.h"
/*!
* @brief maps the specified viewport coordinates into specified space [1]
@@ -48,7 +50,7 @@
*/
CGLM_INLINE
vec3s
glms_unprojecti_zo(vec3s pos, mat4s invMat, vec4s vp, vec3 dest) {
glms_unprojecti_zo(vec3s pos, mat4s invMat, vec4s vp) {
vec3s dest;
glm_unprojecti_zo(pos.raw, invMat.raw, vp.raw, dest.raw);
return dest;
@@ -69,7 +71,7 @@ glms_unprojecti_zo(vec3s pos, mat4s invMat, vec4s vp, vec3 dest) {
*/
CGLM_INLINE
vec3s
glms_project_zo(vec3s pos, mat4s m, vec4s vp, vec3 dest) {
glms_project_zo(vec3s pos, mat4s m, vec4s vp) {
vec3s dest;
glm_project_zo(pos.raw, m.raw, vp.raw, dest.raw);
return dest;
@@ -88,7 +90,7 @@ glms_project_zo(vec3s pos, mat4s m, vec4s vp, vec3 dest) {
* @returns projected z coordinate
*/
CGLM_INLINE
vec3s
float
glms_project_z_zo(vec3s v, mat4s m) {
return glm_project_z_zo(v.raw, m.raw);
}

View File

@@ -19,6 +19,7 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../../clipspace/view_lh_no.h"
/*!
* @brief set up view matrix

View File

@@ -19,6 +19,7 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../../clipspace/view_lh_zo.h"
/*!
* @brief set up view matrix

View File

@@ -19,6 +19,7 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../../clipspace/view_rh_no.h"
/*!
* @brief set up view matrix

View File

@@ -19,6 +19,7 @@
#include "../../types-struct.h"
#include "../../plane.h"
#include "../../cam.h"
#include "../../clipspace/view_rh_zo.h"
/*!
* @brief set up view matrix

View File

@@ -26,6 +26,12 @@
CGLM_INLINE mat4s glms_euler_zxy(vec3s angles)
CGLM_INLINE mat4s glms_euler_zyx(vec3s angles)
CGLM_INLINE mat4s glms_euler_by_order(vec3s angles, glm_euler_seq ord)
CGLM_INLINE versors glms_euler_xyz_quat(vec3s angles)
CGLM_INLINE versors glms_euler_xzy_quat(vec3s angles)
CGLM_INLINE versors glms_euler_yxz_quat(vec3s angles)
CGLM_INLINE versors glms_euler_yzx_quat(vec3s angles)
CGLM_INLINE versors glms_euler_zxy_quat(vec3s angles)
CGLM_INLINE versors glms_euler_zyx_quat(vec3s angles)
*/
#ifndef cglms_euler_h
@@ -149,4 +155,95 @@ glms_euler_by_order(vec3s angles, glm_euler_seq ord) {
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x y z order (roll pitch yaw)
*
* @param[in] angles angles x y z (radians)
* @returns quaternion
*/
CGLM_INLINE
versors
glms_euler_xyz_quat(vec3s angles) {
versors dest;
glm_euler_xyz_quat(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x z y order (roll yaw pitch)
*
* @param[in] angles angles x y z (radians)
* @returns quaternion
*/
CGLM_INLINE
versors
glms_euler_xzy_quat(vec3s angles) {
versors dest;
glm_euler_xzy_quat(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y x z order (pitch roll yaw)
*
* @param[in] angles angles x y z (radians)
* @returns quaternion
*/
CGLM_INLINE
versors
glms_euler_yxz_quat(vec3s angles) {
versors dest;
glm_euler_yxz_quat(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y z x order (pitch yaw roll)
*
* @param[in] angles angles x y z (radians)
* @returns quaternion
*/
CGLM_INLINE
versors
glms_euler_yzx_quat(vec3s angles) {
versors dest;
glm_euler_yzx_quat(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z x y order (yaw roll pitch)
*
* @param[in] angles angles x y z (radians)
* @returns quaternion
*/
CGLM_INLINE
versors
glms_euler_zxy_quat(vec3s angles) {
versors dest;
glm_euler_zxy_quat(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z y x order (yaw pitch roll)
*
* @param[in] angles angles x y z (radians)
* @returns quaternion
*/
CGLM_INLINE
versors
glms_euler_zyx_quat(vec3s angles) {
versors dest;
glm_euler_zyx_quat(angles.raw, dest.raw);
return dest;
}
#endif /* cglms_euler_h */

View File

@@ -0,0 +1,115 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Functions:
CGLM_INLINE void glms_euler_xyz_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_xzy_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_yxz_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_yzx_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_zxy_quat_lh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_zyx_quat_lh(vec3 angles, versor dest);
*/
#ifndef cglms_euler_to_quat_lh_h
#define cglms_euler_to_quat_lh_h
#include "../common.h"
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x y z order in left hand (roll pitch yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_xyz_quat_lh(vec3s angles) {
versors dest;
glm_euler_xyz_quat_lh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x z y order in left hand (roll yaw pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_xzy_quat_lh(vec3s angles) {
versors dest;
glm_euler_xzy_quat_lh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y x z order in left hand (pitch roll yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_yxz_quat_lh(vec3s angles) {
versors dest;
glm_euler_yxz_quat_lh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y z x order in left hand (pitch yaw roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_yzx_quat_lh(vec3s angles) {
versors dest;
glm_euler_yzx_quat_lh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z x y order in left hand (yaw roll pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_zxy_quat_lh(vec3s angles) {
versors dest;
glm_euler_zxy_quat_lh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z y x order in left hand (yaw pitch roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_zyx_quat_lh(vec3s angles) {
versors dest;
glm_euler_zyx_quat_lh(angles.raw, dest.raw);
return dest;
}
#endif /* cglms_euler_to_quat_lh_h */

View File

@@ -0,0 +1,115 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Functions:
CGLM_INLINE void glms_euler_xyz_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_xzy_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_yxz_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_yzx_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_zxy_quat_rh(vec3 angles, versor dest);
CGLM_INLINE void glms_euler_zyx_quat_rh(vec3 angles, versor dest);
*/
#ifndef cglms_euler_to_quat_rh_h
#define cglms_euler_to_quat_rh_h
#include "../common.h"
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x y z order in right hand (roll pitch yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_xyz_quat_rh(vec3s angles) {
versors dest;
glm_euler_xyz_quat_rh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in x z y order in right hand (roll yaw pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_xzy_quat_rh(vec3s angles) {
versors dest;
glm_euler_xzy_quat_rh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y x z order in right hand (pitch roll yaw)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_yxz_quat_rh(vec3s angles) {
versors dest;
glm_euler_yxz_quat_rh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in y z x order in right hand (pitch yaw roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_yzx_quat_rh(vec3s angles) {
versors dest;
glm_euler_yzx_quat_rh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z x y order in right hand (yaw roll pitch)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_zxy_quat_rh(vec3s angles) {
versors dest;
glm_euler_zxy_quat_rh(angles.raw, dest.raw);
return dest;
}
/*!
* @brief creates NEW quaternion using rotation angles and does
* rotations in z y x order in right hand (yaw pitch roll)
*
* @param[in] angles angles x y z (radians)
* @param[out] dest quaternion
*/
CGLM_INLINE
versors
glms_euler_zyx_quat_rh(vec3s angles) {
versors dest;
glm_euler_zyx_quat_rh(angles.raw, dest.raw);
return dest;
}
#endif /* cglms_euler_to_quat_rh_h */

View File

@@ -12,6 +12,8 @@
CGLM_INLINE void glm_vec4_print(vec4 vec, FILE *ostream);
CGLM_INLINE void glm_vec3_print(vec3 vec, FILE *ostream);
CGLM_INLINE void glm_ivec3_print(ivec3 vec, FILE *ostream);
CGLM_INLINE void glm_ivec3_print(ivec3 vec, FILE *ostream);
CGLM_INLINE void glm_versor_print(versor vec, FILE *ostream);
*/

View File

@@ -27,7 +27,7 @@
CGLM_INLINE void glms_mat2_swap_col(mat2 mat, int col1, int col2)
CGLM_INLINE void glms_mat2_swap_row(mat2 mat, int row1, int row2)
CGLM_INLINE float glms_mat2_rmc(vec2 r, mat2 m, vec2 c)
CGLM_INLINE float glms_mat42_make(float * __restrict src);
CGLM_INLINE mat2s glms_mat2_make(float * __restrict src);
*/
#ifndef cglms_mat2_h
@@ -44,8 +44,8 @@
#define GLMS_MAT2_ZERO_INIT {GLM_MAT2_ZERO_INIT}
/* for C only */
#define GLMS_MAT2_IDENTITY ((mat3s)GLMS_MAT2_IDENTITY_INIT)
#define GLMS_MAT2_ZERO ((mat3s)GLMS_MAT2_ZERO_INIT)
#define GLMS_MAT2_IDENTITY ((mat2s)GLMS_MAT2_IDENTITY_INIT)
#define GLMS_MAT2_ZERO ((mat2s)GLMS_MAT2_ZERO_INIT)
/*!
* @brief make given matrix identity. It is identical with below,
@@ -108,13 +108,13 @@ glms_mat2_(zero)(void) {
*
* @code
* mat2 m = GLM_MAT2_IDENTITY_INIT;
* glm_mat2_mul(m, m, m);
* r = glms_mat2_mul(m, m);
* @endcode
*
* @param[in] m1 left matrix
* @param[in] m2 right matrix
*
* @returns matrix
* @returns destination matrix
*/
CGLM_INLINE
mat2s

View File

@@ -0,0 +1,127 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLMS_MAT2X3_ZERO_INIT
GLMS_MAT2X3_ZERO
Functions:
CGLM_INLINE mat2x3s glms_mat2x3_zero(void);
CGLM_INLINE mat2x3s glms_mat2x3_make(float * __restrict src);
CGLM_INLINE mat2s glms_mat2x3_mul(mat2x3s m1, mat3x2s m2);
CGLM_INLINE vec2s glms_mat2x3_mulv(mat2x3s m, vec3s v);
CGLM_INLINE mat3x2s glms_mat2x3_transpose(mat2x3s m);
CGLM_INLINE mat2x3s glms_mat2x3_scale(mat2x3s m, float s);
*/
#ifndef cglms_mat2x3_h
#define cglms_mat2x3_h
#include "../common.h"
#include "../types-struct.h"
#include "../mat2x3.h"
/* api definition */
#define glms_mat2x3_(NAME) CGLM_STRUCTAPI(mat2x3, NAME)
#define GLMS_MAT2X3_ZERO_INIT {GLM_MAT2X3_ZERO_INIT}
/* for C only */
#define GLMS_MAT2X3_ZERO ((mat2x3s)GLMS_MAT2X3_ZERO_INIT)
/*!
* @brief make given matrix zero.
*
* @param[in, out] mat matrix
*/
CGLM_INLINE
mat2x3s
glms_mat2x3_(zero)(void) {
mat2x3s r;
glm_mat2x3_zero(r.raw);
return r;
}
/*!
* @brief Create mat2x3 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @return constructed matrix from raw pointer
*/
CGLM_INLINE
mat2x3s
glms_mat2x3_(make)(float * __restrict src) {
mat2x3s r;
glm_mat2x3_make(src, r.raw);
return r;
}
/*!
* @brief multiply m1 and m2 to dest
*
* @code
* r = glms_mat2x3_mul(mat2x3s, mat3x2s);
* @endcode
*
* @param[in] m1 left matrix (mat2x3s)
* @param[in] m2 right matrix (mat3x2s)
* @returns destination matrix (mat2s)
*/
CGLM_INLINE
mat2s
glms_mat2x3_(mul)(mat2x3s m1, mat3x2s m2) {
mat2s r;
glm_mat2x3_mul(m1.raw, m2.raw, r.raw);
return r;
}
/*!
* @brief multiply matrix with column vector and store in dest vector
*
* @param[in] m matrix (left)
* @param[in] v vector (right, column vector)
* @param[out] dest result vector
*/
CGLM_INLINE
vec2s
glms_mat2x3_(mulv)(mat2x3s m, vec3s v) {
vec2s r;
glm_mat2x3_mulv(m.raw, v.raw, r.raw);
return r;
}
/*!
* @brief transpose matrix and store in dest
*
* @param[in] m matrix
* @param[out] dest result
*/
CGLM_INLINE
mat3x2s
glms_mat2x3_(transpose)(mat2x3s m) {
mat3x2s r;
glm_mat2x3_transpose(m.raw, r.raw);
return r;
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in, out] m matrix
* @param[in] s scalar
*/
CGLM_INLINE
mat2x3s
glms_mat2x3_(scale)(mat2x3s m, float s) {
glm_mat2x3_scale(m.raw, s);
return m;
}
#endif /* cglms_mat2x3_h */

View File

@@ -0,0 +1,127 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLMS_MAT2X4_ZERO_INIT
GLMS_MAT2X4_ZERO
Functions:
CGLM_INLINE mat2x4s glms_mat2x4_zero(void);
CGLM_INLINE mat2x4s glms_mat2x4_make(float * __restrict src);
CGLM_INLINE mat2s glms_mat2x4_mul(mat2x4s m1, mat4x2s m2);
CGLM_INLINE vec2s glms_mat2x4_mulv(mat2x4s m, vec4s v);
CGLM_INLINE mat4x2s glms_mat2x4_transpose(mat2x4s m);
CGLM_INLINE mat2x4s glms_mat2x4_scale(mat2x4s m, float s);
*/
#ifndef cglms_mat2x4_h
#define cglms_mat2x4_h
#include "../common.h"
#include "../types-struct.h"
#include "../mat2x4.h"
/* api definition */
#define glms_mat2x4_(NAME) CGLM_STRUCTAPI(mat2x4, NAME)
#define GLMS_MAT2X4_ZERO_INIT {GLM_MAT2X4_ZERO_INIT}
/* for C only */
#define GLMS_MAT2X4_ZERO ((mat2x4s)GLMS_MAT2X4_ZERO_INIT)
/*!
* @brief make given matrix zero.
*
* @param[in, out] mat matrix
*/
CGLM_INLINE
mat2x4s
glms_mat2x4_(zero)(void) {
mat2x4s r;
glm_mat2x4_zero(r.raw);
return r;
}
/*!
* @brief Create mat2x4 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @return constructed matrix from raw pointer
*/
CGLM_INLINE
mat2x4s
glms_mat2x4_(make)(float * __restrict src) {
mat2x4s r;
glm_mat2x4_make(src, r.raw);
return r;
}
/*!
* @brief multiply m1 and m2 to dest
*
* @code
* r = glms_mat2x4_mul(mat2x4s, mat4x2s);
* @endcode
*
* @param[in] m1 left matrix (mat2x4s)
* @param[in] m2 right matrix (mat4x2s)
* @returns destination matrix (mat2s)
*/
CGLM_INLINE
mat2s
glms_mat2x4_(mul)(mat2x4s m1, mat4x2s m2) {
mat2s r;
glm_mat2x4_mul(m1.raw, m2.raw, r.raw);
return r;
}
/*!
* @brief multiply matrix with column vector and store in dest vector
*
* @param[in] m matrix (left)
* @param[in] v vector (right, column vector)
* @param[out] dest result vector
*/
CGLM_INLINE
vec2s
glms_mat2x4_(mulv)(mat2x4s m, vec4s v) {
vec2s r;
glm_mat2x4_mulv(m.raw, v.raw, r.raw);
return r;
}
/*!
* @brief transpose matrix and store in dest
*
* @param[in] m matrix
* @param[out] dest result
*/
CGLM_INLINE
mat4x2s
glms_mat2x4_(transpose)(mat2x4s m) {
mat4x2s r;
glm_mat2x4_transpose(m.raw, r.raw);
return r;
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in, out] m matrix
* @param[in] s scalar
*/
CGLM_INLINE
mat2x4s
glms_mat2x4_(scale)(mat2x4s m, float s) {
glm_mat2x4_scale(m.raw, s);
return m;
}
#endif /* cglms_mat2x4_h */

View File

@@ -28,7 +28,7 @@
CGLM_INLINE mat3s glms_mat3_swap_col(mat3s mat, int col1, int col2);
CGLM_INLINE mat3s glms_mat3_swap_row(mat3s mat, int row1, int row2);
CGLM_INLINE float glms_mat3_rmc(vec3s r, mat3s m, vec3s c);
CGLM_INLINE float glms_mat3_make(float * __restrict src);
CGLM_INLINE mat3s glms_mat3_make(float * __restrict src);
*/
#ifndef cglms_mat3s_h
@@ -124,7 +124,7 @@ glms_mat3_(zero)(void) {
*
* @code
* mat3 m = GLM_MAT3_IDENTITY_INIT;
* glm_mat3_mul(m, m, m);
* r = glms_mat3_mul(m, m);
* @endcode
*
* @param[in] m1 left matrix

View File

@@ -0,0 +1,127 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLMS_MAT3X2_ZERO_INIT
GLMS_MAT3X2_ZERO
Functions:
CGLM_INLINE mat3x2s glms_mat3x2_zero(void);
CGLM_INLINE mat3x2s glms_mat3x2_make(float * __restrict src);
CGLM_INLINE mat3s glms_mat3x2_mul(mat3x2s m1, mat2x3s m2);
CGLM_INLINE vec3s glms_mat3x2_mulv(mat3x2s m, vec2s v);
CGLM_INLINE mat2x3s glms_mat3x2_transpose(mat3x2s m);
CGLM_INLINE mat3x2s glms_mat3x2_scale(mat3x2s m, float s);
*/
#ifndef cglms_mat3x2_h
#define cglms_mat3x2_h
#include "../common.h"
#include "../types-struct.h"
#include "../mat3x2.h"
/* api definition */
#define glms_mat3x2_(NAME) CGLM_STRUCTAPI(mat3x2, NAME)
#define GLMS_MAT3X2_ZERO_INIT {GLM_MAT3X2_ZERO_INIT}
/* for C only */
#define GLMS_MAT3X2_ZERO ((mat3x2s)GLMS_MAT3X2_ZERO_INIT)
/*!
* @brief make given matrix zero.
*
* @param[in, out] mat matrix
*/
CGLM_INLINE
mat3x2s
glms_mat3x2_(zero)(void) {
mat3x2s r;
glm_mat3x2_zero(r.raw);
return r;
}
/*!
* @brief Create mat3x2 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @return constructed matrix from raw pointer
*/
CGLM_INLINE
mat3x2s
glms_mat3x2_(make)(float * __restrict src) {
mat3x2s r;
glm_mat3x2_make(src, r.raw);
return r;
}
/*!
* @brief multiply m1 and m2 to dest
*
* @code
* r = glms_mat3x2_mul(mat3x2s, mat2x3s);
* @endcode
*
* @param[in] m1 left matrix (mat3x2s)
* @param[in] m2 right matrix (mat2x3s)
* @returns destination matrix (mat3s)
*/
CGLM_INLINE
mat3s
glms_mat3x2_(mul)(mat3x2s m1, mat2x3s m2) {
mat3s r;
glm_mat3x2_mul(m1.raw, m2.raw, r.raw);
return r;
}
/*!
* @brief multiply matrix with column vector and store in dest vector
*
* @param[in] m matrix (left)
* @param[in] v vector (right, column vector)
* @param[out] dest result vector
*/
CGLM_INLINE
vec3s
glms_mat3x2_(mulv)(mat3x2s m, vec2s v) {
vec3s r;
glm_mat3x2_mulv(m.raw, v.raw, r.raw);
return r;
}
/*!
* @brief transpose matrix and store in dest
*
* @param[in] m matrix
* @param[out] dest result
*/
CGLM_INLINE
mat2x3s
glms_mat3x2_(transpose)(mat3x2s m) {
mat2x3s r;
glm_mat3x2_transpose(m.raw, r.raw);
return r;
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in, out] m matrix
* @param[in] s scalar
*/
CGLM_INLINE
mat3x2s
glms_mat3x2_(scale)(mat3x2s m, float s) {
glm_mat3x2_scale(m.raw, s);
return m;
}
#endif /* cglms_mat3x2_h */

View File

@@ -0,0 +1,127 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLMS_MAT3X4_ZERO_INIT
GLMS_MAT3X4_ZERO
Functions:
CGLM_INLINE mat3x4s glms_mat3x4_zero(void);
CGLM_INLINE mat3x4s glms_mat3x4_make(float * __restrict src);
CGLM_INLINE mat3s glms_mat3x4_mul(mat3x4s m1, mat4x3s m2);
CGLM_INLINE vec3s glms_mat3x4_mulv(mat3x4s m, vec4s v);
CGLM_INLINE mat4x3s glms_mat3x4_transpose(mat3x4s m);
CGLM_INLINE mat3x4s glms_mat3x4_scale(mat3x4s m, float s);
*/
#ifndef cglms_mat3x4_h
#define cglms_mat3x4_h
#include "../common.h"
#include "../types-struct.h"
#include "../mat3x4.h"
/* api definition */
#define glms_mat3x4_(NAME) CGLM_STRUCTAPI(mat3x4, NAME)
#define GLMS_MAT3X4_ZERO_INIT {GLM_MAT3X4_ZERO_INIT}
/* for C only */
#define GLMS_MAT3X4_ZERO ((mat3x4s)GLMS_MAT3X4_ZERO_INIT)
/*!
* @brief make given matrix zero.
*
* @param[in, out] mat matrix
*/
CGLM_INLINE
mat3x4s
glms_mat3x4_(zero)(void) {
mat3x4s r;
glm_mat3x4_zero(r.raw);
return r;
}
/*!
* @brief Create mat3x4 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @return constructed matrix from raw pointer
*/
CGLM_INLINE
mat3x4s
glms_mat3x4_(make)(float * __restrict src) {
mat3x4s r;
glm_mat3x4_make(src, r.raw);
return r;
}
/*!
* @brief multiply m1 and m2 to dest
*
* @code
* r = glms_mat3x4_mul(mat3x4s, mat4x3s);
* @endcode
*
* @param[in] m1 left matrix (mat3x4s)
* @param[in] m2 right matrix (mat4x3s)
* @returns destination matrix (mat3s)
*/
CGLM_INLINE
mat3s
glms_mat3x4_(mul)(mat3x4s m1, mat4x3s m2) {
mat3s r;
glm_mat3x4_mul(m1.raw, m2.raw, r.raw);
return r;
}
/*!
* @brief multiply matrix with column vector and store in dest vector
*
* @param[in] m matrix (left)
* @param[in] v vector (right, column vector)
* @param[out] dest result vector
*/
CGLM_INLINE
vec3s
glms_mat3x4_(mulv)(mat3x4s m, vec4s v) {
vec3s r;
glm_mat3x4_mulv(m.raw, v.raw, r.raw);
return r;
}
/*!
* @brief transpose matrix and store in dest
*
* @param[in] m matrix
* @param[out] dest result
*/
CGLM_INLINE
mat4x3s
glms_mat3x4_(transpose)(mat3x4s m) {
mat4x3s r;
glm_mat3x4_transpose(m.raw, r.raw);
return r;
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in, out] m matrix
* @param[in] s scalar
*/
CGLM_INLINE
mat3x4s
glms_mat3x4_(scale)(mat3x4s m, float s) {
glm_mat3x4_scale(m.raw, s);
return m;
}
#endif /* cglms_mat3x4_h */

View File

@@ -25,7 +25,7 @@
CGLM_INLINE mat4s glms_mat4_zero(void);
CGLM_INLINE mat3s glms_mat4_pick3(mat4s mat);
CGLM_INLINE mat3s glms_mat4_pick3t(mat4s mat);
CGLM_INLINE mat4s glms_mat4_ins3(mat3s mat);
CGLM_INLINE mat4s glms_mat4_ins3(mat3s mat, mat4s dest);
CGLM_INLINE mat4s glms_mat4_mul(mat4s m1, mat4s m2);
CGLM_INLINE mat4s glms_mat4_mulN(mat4s * __restrict matrices[], uint32_t len);
CGLM_INLINE vec4s glms_mat4_mulv(mat4s m, vec4s v);
@@ -42,7 +42,7 @@
CGLM_INLINE mat4s glms_mat4_swap_col(mat4s mat, int col1, int col2);
CGLM_INLINE mat4s glms_mat4_swap_row(mat4s mat, int row1, int row2);
CGLM_INLINE float glms_mat4_rmc(vec4s r, mat4s m, vec4s c);
CGLM_INLINE float glms_mat4_make(float * __restrict src);
CGLM_INLINE mat4s glms_mat4_make(float * __restrict src);
*/
#ifndef cglms_mat4s_h
@@ -183,14 +183,14 @@ glms_mat4_(pick3t)(mat4s mat) {
* @brief copy mat3 to mat4's upper-left
*
* @param[in] mat source
* @param[in] dest destination
* @returns destination
*/
CGLM_INLINE
mat4s
glms_mat4_(ins3)(mat3s mat) {
mat4s r;
glm_mat4_ins3(mat.raw, r.raw);
return r;
glms_mat4_(ins3)(mat3s mat, mat4s dest) {
glm_mat4_ins3(mat.raw, dest.raw);
return dest;
}
/*!
@@ -200,7 +200,7 @@ glms_mat4_(ins3)(mat3s mat) {
*
* @code
* mat4 m = GLM_MAT4_IDENTITY_INIT;
* glm_mat4_mul(m, m, m);
* r = glms_mat4_mul(m, m);
* @endcode
*
* @param[in] m1 left matrix

View File

@@ -0,0 +1,128 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLMS_MAT4X2_ZERO_INIT
GLMS_MAT4X2_ZERO
Functions:
CGLM_INLINE mat4x2s glms_mat4x2_zero(void);
CGLM_INLINE mat4x2s glms_mat4x2_make(float * __restrict src);
CGLM_INLINE mat4s glms_mat4x2_mul(mat4x2s m1, mat2x4s m2);
CGLM_INLINE vec4s glms_mat4x2_mulv(mat4x2s m, vec2s v);
CGLM_INLINE mat2x4s glms_mat4x2_transpose(mat4x2s m);
CGLM_INLINE mat4x2s glms_mat4x2_scale(mat4x2s m, float s);
*/
#ifndef cglms_mat4x2_h
#define cglms_mat4x2_h
#include "../common.h"
#include "../types-struct.h"
#include "../mat4x2.h"
/* api definition */
#define glms_mat4x2_(NAME) CGLM_STRUCTAPI(mat4x2, NAME)
#define GLMS_MAT4X2_ZERO_INIT {GLM_MAT4X2_ZERO_INIT}
/* for C only */
#define GLMS_MAT4X2_ZERO ((mat4x2s)GLMS_MAT4X2_ZERO_INIT)
/*!
* @brief make given matrix zero.
*
* @param[in, out] mat matrix
*/
CGLM_INLINE
mat4x2s
glms_mat4x2_(zero)(void) {
mat4x2s r;
glm_mat4x2_zero(r.raw);
return r;
}
/*!
* @brief Create mat4x2 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @return constructed matrix from raw pointer
*/
CGLM_INLINE
mat4x2s
glms_mat4x2_(make)(float * __restrict src) {
mat4x2s r;
glm_mat4x2_make(src, r.raw);
return r;
}
/*!
* @brief multiply m1 and m2 to dest
*
* @code
* r = glms_mat4x2_mul(mat4x2s, mat2x4s);
* @endcode
*
* @param[in] m1 left matrix (mat4x2s)
* @param[in] m2 right matrix (mat2x4s)
* @returns destination matrix (mat4s)
*/
CGLM_INLINE
mat4s
glms_mat4x2_(mul)(mat4x2s m1, mat2x4s m2) {
mat4s r;
glm_mat4x2_mul(m1.raw, m2.raw, r.raw);
return r;
}
/*!
* @brief multiply matrix with column vector and store in dest vector
*
* @param[in] m matrix (left)
* @param[in] v vector (right, column vector)
* @param[out] dest result vector
*/
CGLM_INLINE
vec4s
glms_mat4x2_(mulv)(mat4x2s m, vec2s v) {
vec4s r;
glm_mat4x2_mulv(m.raw, v.raw, r.raw);
return r;
}
/*!
* @brief transpose matrix and store in dest
*
* @param[in] m matrix
* @param[out] dest result
*/
CGLM_INLINE
mat2x4s
glms_mat4x2_(transpose)(mat4x2s m) {
mat2x4s r;
glm_mat4x2_transpose(m.raw, r.raw);
return r;
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in, out] m matrix
* @param[in] s scalar
*/
CGLM_INLINE
mat4x2s
glms_mat4x2_(scale)(mat4x2s m, float s) {
glm_mat4x2_scale(m.raw, s);
return m;
}
#endif /* cglms_mat4x2_h */

View File

@@ -0,0 +1,127 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
/*
Macros:
GLMS_MAT4X3_ZERO_INIT
GLMS_MAT4X3_ZERO
Functions:
CGLM_INLINE mat4x3s glms_mat4x3_zero(void);
CGLM_INLINE mat4x3s glms_mat4x3_make(float * __restrict src);
CGLM_INLINE mat4s glms_mat4x3_mul(mat4x3s m1, mat3x4s m2);
CGLM_INLINE vec4s glms_mat4x3_mulv(mat4x3s m, vec3s v);
CGLM_INLINE mat3x4s glms_mat4x3_transpose(mat4x3s m);
CGLM_INLINE mat4x3s glms_mat4x3_scale(mat4x3s m, float s);
*/
#ifndef cglms_mat4x3_h
#define cglms_mat4x3_h
#include "../common.h"
#include "../types-struct.h"
#include "../mat4x3.h"
/* api definition */
#define glms_mat4x3_(NAME) CGLM_STRUCTAPI(mat4x3, NAME)
#define GLMS_MAT4X3_ZERO_INIT {GLM_MAT4X3_ZERO_INIT}
/* for C only */
#define GLMS_MAT4X3_ZERO ((mat4x3s)GLMS_MAT4X3_ZERO_INIT)
/*!
* @brief make given matrix zero.
*
* @param[in, out] mat matrix
*/
CGLM_INLINE
mat4x3s
glms_mat4x3_(zero)(void) {
mat4x3s r;
glm_mat4x3_zero(r.raw);
return r;
}
/*!
* @brief Create mat4x3 matrix from pointer
*
* @param[in] src pointer to an array of floats
* @return constructed matrix from raw pointer
*/
CGLM_INLINE
mat4x3s
glms_mat4x3_(make)(float * __restrict src) {
mat4x3s r;
glm_mat4x3_make(src, r.raw);
return r;
}
/*!
* @brief multiply m1 and m2 to dest
*
* @code
* r = glms_mat4x3_mul(mat4x3s, mat3x4s);
* @endcode
*
* @param[in] m1 left matrix (mat4x3s)
* @param[in] m2 right matrix (mat3x4s)
* @returns destination matrix (mat4s)
*/
CGLM_INLINE
mat4s
glms_mat4x3_(mul)(mat4x3s m1, mat3x4s m2) {
mat4s r;
glm_mat4x3_mul(m1.raw, m2.raw, r.raw);
return r;
}
/*!
* @brief multiply matrix with column vector and store in dest vector
*
* @param[in] m matrix (left)
* @param[in] v vector (right, column vector)
* @param[out] dest result vector
*/
CGLM_INLINE
vec4s
glms_mat4x3_(mulv)(mat4x3s m, vec3s v) {
vec4s r;
glm_mat4x3_mulv(m.raw, v.raw, r.raw);
return r;
}
/*!
* @brief transpose matrix and store in dest
*
* @param[in] m matrix
* @param[out] dest result
*/
CGLM_INLINE
mat3x4s
glms_mat4x3_(transpose)(mat4x3s m) {
mat3x4s r;
glm_mat4x3_transpose(m.raw, r.raw);
return r;
}
/*!
* @brief scale (multiply with scalar) matrix
*
* multiply matrix with scalar
*
* @param[in, out] m matrix
* @param[in] s scalar
*/
CGLM_INLINE
mat4x3s
glms_mat4x3_(scale)(mat4x3s m, float s) {
glm_mat4x3_scale(m.raw, s);
return m;
}
#endif /* cglms_mat4x3_h */

View File

@@ -15,6 +15,17 @@
#include "vec4.h"
#include "mat4.h"
#ifndef CGLM_CLIPSPACE_INCLUDE_ALL
# if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_ZO_BIT
# include "clipspace/project_zo.h"
# elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_NO_BIT
# include "clipspace/project_no.h"
# endif
#else
# include "clipspace/project_zo.h"
# include "clipspace/project_no.h"
#endif
/*!
* @brief maps the specified viewport coordinates into specified space [1]
* the matrix should contain projection matrix.
@@ -68,6 +79,9 @@ glms_unprojecti(vec3s pos, mat4s invMat, vec4s vp) {
* glm_mat4_mul(proj, view, viewProj);
* glm_mat4_mul(viewProj, model, MVP);
*
* or in struct api:
* MVP = mat4_mul(mat4_mul(proj, view), model)
*
* @param[in] pos point/position in viewport coordinates
* @param[in] m matrix (see brief)
* @param[in] vp viewport as [x, y, width, height]
@@ -88,6 +102,9 @@ glms_unproject(vec3s pos, mat4s m, vec4s vp) {
* glm_mat4_mul(proj, view, viewProj);
* glm_mat4_mul(viewProj, model, MVP);
*
* or in struct api:
* MVP = mat4_mul(mat4_mul(proj, view), model)
*
* @param[in] pos object coordinates
* @param[in] m MVP matrix
* @param[in] vp viewport as [x, y, width, height]
@@ -101,6 +118,31 @@ glms_project(vec3s pos, mat4s m, vec4s vp) {
return r;
}
/*!
* @brief map object's z coordinate to window coordinates
*
* Computing MVP:
* glm_mat4_mul(proj, view, viewProj);
* glm_mat4_mul(viewProj, model, MVP);
*
* or in struct api:
* MVP = mat4_mul(mat4_mul(proj, view), model)
*
* @param[in] v object coordinates
* @param[in] m MVP matrix
*
* @returns projected z coordinate
*/
CGLM_INLINE
float
glms_project_z(vec3s v, mat4s m) {
#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_ZO_BIT
return glms_project_z_zo(v, m);
#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_NO_BIT
return glms_project_z_no(v, m);
#endif
}
/*!
* @brief define a picking region
*

View File

@@ -37,9 +37,16 @@
CGLM_INLINE vec2s glms_vec2_muladds(vec2s a, float s, vec2s dest)
CGLM_INLINE vec2s glms_vec2_maxadd(vec2s a, vec2s b, vec2s dest)
CGLM_INLINE vec2s glms_vec2_minadd(vec2s a, vec2s b, vec2s dest)
CGLM_INLINE vec2s glms_vec2_subsub(vec2s a, vec2s b, vec2s dest)
CGLM_INLINE vec2s glms_vec2_addsub(vec2s a, vec2s b, vec2s dest)
CGLM_INLINE vec2s glms_vec2_mulsub(vec2s a, vec2s b, vec2s dest)
CGLM_INLINE vec2s glms_vec2_mulsubs(vec2s a, float s, vec2s dest)
CGLM_INLINE vec2s glms_vec2_maxsub(vec2s a, vec2s b, vec2s dest)
CGLM_INLINE vec2s glms_vec2_minsub(vec2s a, vec2s b, vec2s dest)
CGLM_INLINE vec2s glms_vec2_negate(vec2s v)
CGLM_INLINE vec2s glms_vec2_normalize(vec2s v)
CGLM_INLINE vec2s glms_vec2_rotate(vec2s v, float angle, vec2s axis)
CGLM_INLINE vec2s glms_vec2_center(vec2s a, vec2s b)
CGLM_INLINE float glms_vec2_distance(vec2s a, vec2s b)
CGLM_INLINE float glms_vec2_distance2(vec2s a, vec2s b)
CGLM_INLINE vec2s glms_vec2_maxv(vec2s a, vec2s b)
@@ -429,6 +436,102 @@ glms_vec2_(minadd)(vec2s a, vec2s b, vec2s dest) {
return dest;
}
/*!
* @brief sub two vectors and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= (a - b)
*/
CGLM_INLINE
vec2s
glms_vec2_(subsub)(vec2s a, vec2s b, vec2s dest) {
glm_vec2_subsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief add two vectors and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= (a + b)
*/
CGLM_INLINE
vec2s
glms_vec2_(addsub)(vec2s a, vec2s b, vec2s dest) {
glm_vec2_addsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief mul two vectors and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= (a * b)
*/
CGLM_INLINE
vec2s
glms_vec2_(mulsub)(vec2s a, vec2s b, vec2s dest) {
glm_vec2_mulsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief mul vector with scalar and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @returns dest -= (a * b)
*/
CGLM_INLINE
vec2s
glms_vec2_(mulsubs)(vec2s a, float s, vec2s dest) {
glm_vec2_mulsubs(a.raw, s, dest.raw);
return dest;
}
/*!
* @brief sub max of two vectors to dest
*
* it applies += operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= max(a, b)
*/
CGLM_INLINE
vec2s
glms_vec2_(maxsub)(vec2s a, vec2s b, vec2s dest) {
glm_vec2_maxsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief sub min of two vectors to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= min(a, b)
*/
CGLM_INLINE
vec2s
glms_vec2_(minsub)(vec2s a, vec2s b, vec2s dest) {
glm_vec2_minsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief negate vector components
*
@@ -470,6 +573,21 @@ glms_vec2_(rotate)(vec2s v, float angle) {
return r;
}
/**
* @brief find center point of two vector
*
* @param[in] a vector1
* @param[in] b vector2
* @returns center point
*/
CGLM_INLINE
vec2s
glms_vec2_(center)(vec2s a, vec2s b) {
vec2s r;
glm_vec2_center(a.raw, b.raw, r.raw);
return r;
}
/**
* @brief distance between two vectors
*

View File

@@ -41,9 +41,14 @@
CGLM_INLINE vec3s glms_vec3_muladds(vec3s a, float s, vec3s dest);
CGLM_INLINE vec3s glms_vec3_maxadd(vec3s a, vec3s b, vec3s dest);
CGLM_INLINE vec3s glms_vec3_minadd(vec3s a, vec3s b, vec3s dest);
CGLM_INLINE vec3s glms_vec3_subsub(vec3s a, vec3s b, vec3s dest);
CGLM_INLINE vec3s glms_vec3_addsub(vec3s a, vec3s b, vec3s dest);
CGLM_INLINE vec3s glms_vec3_mulsub(vec3s a, vec3s b, vec3s dest);
CGLM_INLINE vec3s glms_vec3_mulsubs(vec3s a, float s, vec3s dest);
CGLM_INLINE vec3s glms_vec3_maxsub(vec3s a, vec3s b, vec3s dest);
CGLM_INLINE vec3s glms_vec3_minsub(vec3s a, vec3s b, vec3s dest);
CGLM_INLINE vec3s glms_vec3_flipsign(vec3s v);
CGLM_INLINE vec3s glms_vec3_negate(vec3s v);
CGLM_INLINE vec3s glms_vec3_inv(vec3s v);
CGLM_INLINE vec3s glms_vec3_normalize(vec3s v);
CGLM_INLINE vec3s glms_vec3_cross(vec3s a, vec3s b);
CGLM_INLINE vec3s glms_vec3_crossn(vec3s a, vec3s b);
@@ -485,6 +490,102 @@ glms_vec3_(minadd)(vec3s a, vec3s b, vec3s dest) {
return dest;
}
/*!
* @brief sub two vectors and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= (a - b)
*/
CGLM_INLINE
vec3s
glms_vec3_(subsub)(vec3s a, vec3s b, vec3s dest) {
glm_vec3_subsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief add two vectors and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= (a + b)
*/
CGLM_INLINE
vec3s
glms_vec3_(addsub)(vec3s a, vec3s b, vec3s dest) {
glm_vec3_addsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief mul two vectors and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= (a * b)
*/
CGLM_INLINE
vec3s
glms_vec3_(mulsub)(vec3s a, vec3s b, vec3s dest) {
glm_vec3_mulsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief mul vector with scalar and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @returns dest -= (a * b)
*/
CGLM_INLINE
vec3s
glms_vec3_(mulsubs)(vec3s a, float s, vec3s dest) {
glm_vec3_mulsubs(a.raw, s, dest.raw);
return dest;
}
/*!
* @brief sub max of two vectors to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= max(a, b)
*/
CGLM_INLINE
vec3s
glms_vec3_(maxsub)(vec3s a, vec3s b, vec3s dest) {
glm_vec3_maxsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief sub min of two vectors to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= min(a, b)
*/
CGLM_INLINE
vec3s
glms_vec3_(minsub)(vec3s a, vec3s b, vec3s dest) {
glm_vec3_minsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief negate vector components and store result in dest
*

View File

@@ -41,8 +41,13 @@
CGLM_INLINE vec4s glms_vec4_muladds(vec4s a, float s, vec4s dest);
CGLM_INLINE vec4s glms_vec4_maxadd(vec4s a, vec4s b, vec4s dest);
CGLM_INLINE vec4s glms_vec4_minadd(vec4s a, vec4s b, vec4s dest);
CGLM_INLINE vec4s glms_vec4_subsub(vec4s a, vec4s b, vec4s dest);
CGLM_INLINE vec4s glms_vec4_addsub(vec4s a, vec4s b, vec4s dest);
CGLM_INLINE vec4s glms_vec4_mulsub(vec4s a, vec4s b, vec4s dest);
CGLM_INLINE vec4s glms_vec4_mulsubs(vec4s a, float s, vec4s dest);
CGLM_INLINE vec4s glms_vec4_maxsub(vec4s a, vec4s b, vec4s dest);
CGLM_INLINE vec4s glms_vec4_minsub(vec4s a, vec4s b, vec4s dest);
CGLM_INLINE vec4s glms_vec4_negate(vec4s v);
CGLM_INLINE vec4s glms_vec4_inv(vec4s v);
CGLM_INLINE vec4s glms_vec4_normalize(vec4s v);
CGLM_INLINE float glms_vec4_distance(vec4s a, vec4s b);
CGLM_INLINE float glms_vec4_distance2(vec4s a, vec4s b);
@@ -514,6 +519,102 @@ glms_vec4_(minadd)(vec4s a, vec4s b, vec4s dest) {
return dest;
}
/*!
* @brief sub two vectors and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= (a + b)
*/
CGLM_INLINE
vec4s
glms_vec4_(subsub)(vec4s a, vec4s b, vec4s dest) {
glm_vec4_subsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief add two vectors and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= (a + b)
*/
CGLM_INLINE
vec4s
glms_vec4_(addsub)(vec4s a, vec4s b, vec4s dest) {
glm_vec4_addsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief mul two vectors and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= (a * b)
*/
CGLM_INLINE
vec4s
glms_vec4_(mulsub)(vec4s a, vec4s b, vec4s dest) {
glm_vec4_mulsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief mul vector with scalar and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @returns dest -= (a * b)
*/
CGLM_INLINE
vec4s
glms_vec4_(mulsubs)(vec4s a, float s, vec4s dest) {
glm_vec4_mulsubs(a.raw, s, dest.raw);
return dest;
}
/*!
* @brief sub max of two vectors to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= max(a, b)
*/
CGLM_INLINE
vec4s
glms_vec4_(maxsub)(vec4s a, vec4s b, vec4s dest) {
glm_vec4_maxsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief sub min of two vectors to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @returns dest -= min(a, b)
*/
CGLM_INLINE
vec4s
glms_vec4_(minsub)(vec4s a, vec4s b, vec4s dest) {
glm_vec4_minsub(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief negate vector components and store result in dest
*

View File

@@ -197,6 +197,28 @@ typedef union mat2s {
#endif
} mat2s;
typedef union mat2x3s {
mat2x3 raw;
vec3s col[2]; /* [col (2), row (3)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02;
float m10, m11, m12;
};
#endif
} mat2x3s;
typedef union mat2x4s {
mat2x4 raw;
vec4s col[2]; /* [col (2), row (4)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
};
#endif
} mat2x4s;
typedef union mat3s {
mat3 raw;
vec3s col[3];
@@ -209,6 +231,30 @@ typedef union mat3s {
#endif
} mat3s;
typedef union mat3x2s {
mat3x2 raw;
vec2s col[3]; /* [col (3), row (2)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01;
float m10, m11;
float m20, m21;
};
#endif
} mat3x2s;
typedef union mat3x4s {
mat3x4 raw;
vec4s col[3]; /* [col (3), row (4)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02, m03;
float m10, m11, m12, m13;
float m20, m21, m22, m23;
};
#endif
} mat3x4s;
typedef union CGLM_ALIGN_MAT mat4s {
mat4 raw;
vec4s col[4];
@@ -222,4 +268,30 @@ typedef union CGLM_ALIGN_MAT mat4s {
#endif
} mat4s;
typedef union mat4x2s {
mat4x2 raw;
vec2s col[4]; /* [col (4), row (2)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01;
float m10, m11;
float m20, m21;
float m30, m31;
};
#endif
} mat4x2s;
typedef union mat4x3s {
mat4x3 raw;
vec3s col[4]; /* [col (4), row (3)] */
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
float m00, m01, m02;
float m10, m11, m12;
float m20, m21, m22;
float m30, m31, m32;
};
#endif
} mat4x3s;
#endif /* cglm_types_struct_h */

View File

@@ -8,6 +8,10 @@
#ifndef cglm_types_h
#define cglm_types_h
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
# include <stdalign.h>
#endif
#if defined(_MSC_VER)
/* do not use alignment for older visual studio versions */
# if _MSC_VER < 1913 /* Visual Studio 2017 version 15.6 */
@@ -32,19 +36,41 @@
# define CGLM_ALIGN_MAT CGLM_ALIGN(16)
#endif
#ifndef CGLM_HAVE_BUILTIN_ASSUME_ALIGNED
# if defined(__has_builtin)
# if __has_builtin(__builtin_assume_aligned)
# define CGLM_HAVE_BUILTIN_ASSUME_ALIGNED 1
# endif
# elif defined(__GNUC__) && defined(__GNUC_MINOR__)
# if __GNUC__ >= 4 && __GNUC_MINOR__ >= 7
# define CGLM_HAVE_BUILTIN_ASSUME_ALIGNED 1
# endif
# endif
# ifndef CGLM_HAVE_BUILTIN_ASSUME_ALIGNED
# define CGLM_HAVE_BUILTIN_ASSUME_ALIGNED 0
# endif
#endif
#if CGLM_HAVE_BUILTIN_ASSUME_ALIGNED
# define CGLM_ASSUME_ALIGNED(expr, alignment) \
__builtin_assume_aligned((expr), (alignment))
#else
# define CGLM_ASSUME_ALIGNED(expr, alignment) (expr)
#endif
#else
# define CGLM_ASSUME_ALIGNED(expr, alignment) (expr)
#endif
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
# define CGLM_CASTPTR_ASSUME_ALIGNED(expr, type) \
((type*)CGLM_ASSUME_ALIGNED((expr), alignof(type)))
#elif defined(_MSC_VER)
# define CGLM_CASTPTR_ASSUME_ALIGNED(expr, type) \
((type*)CGLM_ASSUME_ALIGNED((expr), __alignof(type)))
#else
# define CGLM_CASTPTR_ASSUME_ALIGNED(expr, type) \
((type*)CGLM_ASSUME_ALIGNED((expr), __alignof__(type)))
#endif
typedef int ivec2[2];
typedef int ivec3[3];
@@ -55,8 +81,14 @@ typedef float vec3[3];
typedef CGLM_ALIGN_IF(16) float vec4[4];
typedef vec4 versor; /* |x, y, z, w| -> w is the last */
typedef vec3 mat3[3];
typedef vec2 mat3x2[3]; /* [col (3), row (2)] */
typedef vec4 mat3x4[3]; /* [col (3), row (4)] */
typedef CGLM_ALIGN_IF(16) vec2 mat2[2];
typedef vec3 mat2x3[2]; /* [col (2), row (3)] */
typedef vec4 mat2x4[2]; /* [col (2), row (4)] */
typedef CGLM_ALIGN_MAT vec4 mat4[4];
typedef vec2 mat4x2[4]; /* [col (4), row (2)] */
typedef vec3 mat4x3[4]; /* [col (4), row (3)] */
/*
Important: cglm stores quaternion as [x, y, z, w] in memory since v0.4.0

View File

@@ -147,6 +147,38 @@ glm_max(float a, float b) {
return b;
}
/*!
* @brief find minimum of given two values
*
* @param[in] a number 1
* @param[in] b number 2
*
* @return smallest of the two values
*/
CGLM_INLINE
int
glm_imin(int a, int b) {
if (a < b)
return a;
return b;
}
/*!
* @brief find maximum of given two values
*
* @param[in] a number 1
* @param[in] b number 2
*
* @return largest of the two values
*/
CGLM_INLINE
int
glm_imax(int a, int b) {
if (a > b)
return a;
return b;
}
/*!
* @brief clamp a number between min and max
*

View File

@@ -36,11 +36,18 @@
CGLM_INLINE void glm_vec2_muladds(vec2 a, float s, vec2 dest)
CGLM_INLINE void glm_vec2_maxadd(vec2 a, vec2 b, vec2 dest)
CGLM_INLINE void glm_vec2_minadd(vec2 a, vec2 b, vec2 dest)
CGLM_INLINE void glm_vec2_subsub(vec2 a, vec2 b, vec2 dest)
CGLM_INLINE void glm_vec2_addsub(vec2 a, vec2 b, vec2 dest)
CGLM_INLINE void glm_vec2_mulsub(vec2 a, vec2 b, vec2 dest)
CGLM_INLINE void glm_vec2_mulsubs(vec2 a, float s, vec2 dest)
CGLM_INLINE void glm_vec2_maxsub(vec2 a, vec2 b, vec2 dest)
CGLM_INLINE void glm_vec2_minsub(vec2 a, vec2 b, vec2 dest)
CGLM_INLINE void glm_vec2_negate_to(vec2 v, vec2 dest)
CGLM_INLINE void glm_vec2_negate(vec2 v)
CGLM_INLINE void glm_vec2_normalize(vec2 v)
CGLM_INLINE void glm_vec2_normalize_to(vec2 vec, vec2 dest)
CGLM_INLINE void glm_vec2_rotate(vec2 v, float angle, vec2 dest)
CGLM_INLINE void glm_vec2_center(vec2 a, vec2 b, vec2 dest)
CGLM_INLINE float glm_vec2_distance2(vec2 a, vec2 b)
CGLM_INLINE float glm_vec2_distance(vec2 a, vec2 b)
CGLM_INLINE void glm_vec2_maxv(vec2 v1, vec2 v2, vec2 dest)
@@ -402,6 +409,102 @@ glm_vec2_minadd(vec2 a, vec2 b, vec2 dest) {
dest[1] += glm_min(a[1], b[1]);
}
/*!
* @brief sub two vectors and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @param[out] dest dest -= (a - b)
*/
CGLM_INLINE
void
glm_vec2_subsub(vec2 a, vec2 b, vec2 dest) {
dest[0] -= a[0] - b[0];
dest[1] -= a[1] - b[1];
}
/*!
* @brief add two vectors and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @param[out] dest dest -= (a + b)
*/
CGLM_INLINE
void
glm_vec2_addsub(vec2 a, vec2 b, vec2 dest) {
dest[0] -= a[0] + b[0];
dest[1] -= a[1] + b[1];
}
/*!
* @brief mul two vectors and sub result to dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @param[out] dest dest -= (a * b)
*/
CGLM_INLINE
void
glm_vec2_mulsub(vec2 a, vec2 b, vec2 dest) {
dest[0] -= a[0] * b[0];
dest[1] -= a[1] * b[1];
}
/*!
* @brief mul vector with scalar and sub result to sum
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector
* @param[in] s scalar
* @param[out] dest dest -= (a * b)
*/
CGLM_INLINE
void
glm_vec2_mulsubs(vec2 a, float s, vec2 dest) {
dest[0] -= a[0] * s;
dest[1] -= a[1] * s;
}
/*!
* @brief sub max of two vectors to result/dest
*
* 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
void
glm_vec2_maxsub(vec2 a, vec2 b, vec2 dest) {
dest[0] -= glm_max(a[0], b[0]);
dest[1] -= glm_max(a[1], b[1]);
}
/*!
* @brief sub min of two vectors to result/dest
*
* it applies -= operator so dest must be initialized
*
* @param[in] a vector 1
* @param[in] b vector 2
* @param[out] dest dest -= min(a, b)
*/
CGLM_INLINE
void
glm_vec2_minsub(vec2 a, vec2 b, vec2 dest) {
dest[0] -= glm_min(a[0], b[0]);
dest[1] -= glm_min(a[1], b[1]);
}
/*!
* @brief negate vector components and store result in dest
*
@@ -493,6 +596,20 @@ glm_vec2_rotate(vec2 v, float angle, vec2 dest) {
dest[1] = s * x1 + c * y1;
}
/**
* @brief find center point of two vector
*
* @param[in] a vector1
* @param[in] b vector2
* @param[out] dest center point
*/
CGLM_INLINE
void
glm_vec2_center(vec2 a, vec2 b, vec2 dest) {
glm_vec2_add(a, b, dest);
glm_vec2_scale(dest, 0.5f, dest);
}
/**
* @brief squared distance between two vectors
*

Some files were not shown because too many files have changed in this diff Show More