From 3882b72f7ff4f847e3697af1b3330940445e593a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 5 Feb 2018 17:46:28 +0300 Subject: [PATCH 001/292] vec: helper macro for zero vectors --- include/cglm/vec3.h | 7 ++++++- include/cglm/vec4.h | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index ebcedcf..06c7147 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -14,7 +14,9 @@ Macros: glm_vec_dup(v, dest) GLM_VEC3_ONE_INIT + GLM_VEC3_ZERO_INIT GLM_VEC3_ONE + GLM_VEC3_ZERO GLM_YUP GLM_ZUP GLM_XUP @@ -62,8 +64,11 @@ /* DEPRECATED! use _copy, _ucopy versions */ #define glm_vec_dup(v, dest) glm_vec_copy(v, dest) -#define GLM_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f} +#define GLM_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f} +#define GLM_VEC3_ZERO_INIT {0.0f, 0.0f, 0.0f} + #define GLM_VEC3_ONE (vec3)GLM_VEC3_ONE_INIT +#define GLM_VEC3_ZERO (vec3)GLM_VEC3_ZERO_INIT #define GLM_YUP (vec3){0.0f, 1.0f, 0.0f} #define GLM_ZUP (vec3){0.0f, 0.0f, 1.0f} diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index e76bfac..91b1059 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -16,8 +16,10 @@ glm_vec4_dup(v, dest) GLM_VEC4_ONE_INIT GLM_VEC4_BLACK_INIT + GLM_VEC4_ZERO_INIT GLM_VEC4_ONE GLM_VEC4_BLACK + GLM_VEC4_ZERO Functions: CGLM_INLINE void glm_vec4(vec3 v3, float last, vec4 dest); @@ -53,9 +55,11 @@ #define GLM_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f} #define GLM_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f} +#define GLM_VEC4_ZERO_INIT {0.0f, 0.0f, 0.0f, 0.0f} #define GLM_VEC4_ONE (vec4)GLM_VEC4_ONE_INIT #define GLM_VEC4_BLACK (vec4)GLM_VEC4_BLACK_INIT +#define GLM_VEC4_ZERO (vec4)GLM_VEC4_ZERO_INIT /*! * @brief init vec4 using vec3 From 5ccf80cd0ef7f8f52fcc89b1ada98f24b3ead19e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 5 Feb 2018 18:13:40 +0300 Subject: [PATCH 002/292] Update README.md --- README.md | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 250d434..b185646 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,14 @@ https://github.com/g-truc/glm #### Note for experienced developers: - Since I'm testing this library in my projects, sometimes bugs occurs; finding that bug[s] and making improvements would be more easy with multiple developer/contributor and their projects or knowledge. Consider to make some tests if you suspect something is wrong and any feedbacks, contributions and bug reports are always welcome. -#### Note for floating point errors: -I realized that floating point errors may occur is some operaitons especially decomposing matrices. cglm will support double later but I will try yo fix these errors by learning floating points standarts in more details. Currently it is just in my TODOs. +#### Allocations? +`cglm` doesn't alloc any memory on heap. So it doesn't provide any allocator. You should alloc memory for **out** parameters too if you pass pointer of memory location. Don't forget that **vec4** (also quat/**versor**) and **mat4** must be aligned (16-bytes), because *cglm* uses SIMD instructions to optimize most operations if available. + +#### Returning vector or matrix... ? +Since almost all types are arrays and **C** doesn't allow returning arrays, so **cglm** doesn't support this feature. In the future *cglm* may use **struct** for some types for this purpose. + +#### Other APIs like Vulkan, Metal, Dx? +Currently *cglm* uses default clip space configuration (-1, 1) for camera functions (perspective, extract corners...), in the future other clip space configurations will be supported
@@ -167,7 +173,34 @@ this header will include all heaers with c postfix. You need to call functions w glmc_vec_normalize(vec); ``` -Function usage and parameters are documented inside related headers. +Function usage and parameters are documented inside related headers. You may see same parameter passed twice in some examples like this: +```C +glm_mat4_mul(m1, m2, m1); + +/* or */ +glm_mat4_mul(m1, m1, m1); +``` +the first two parameter are **[in]** and the last one is **[out]** parameter. After multiplied *m1* and *m2* the result is stored in *m1*. This is why we send *m1* twice. You may store result in different matrix, this just an example. + +## How to send matrix to OpenGL + +mat4 is array of vec4 and vec4 is array of floats. `glUniformMatrix4fv` functions accecpts `float*` as `value` (last param), so you can cast mat4 to float* or you can pass first column of matrix as beginning of memory of matrix: + +Option 1: Send first column +```C +glUniformMatrix4fv(location, 1, GL_FALSE, matrix[0]); + +/* array of matrices */ +glUniformMatrix4fv(location, 1, GL_FALSE, matrix[0][0]); +``` + +Option 2: Cast matrix to pointer type (also valid for multiple dimensional arrays) +```C +glUniformMatrix4fv(location, 1, GL_FALSE, (float *)matrix); +``` + +You can pass same way to another APIs e.g. Vulkan, DX... + ## Notes - This library uses float types only, does not support Integers, Double... yet From 681a74b39c5ad8cd2120819dbcfbc84074bd5425 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 18 Feb 2018 10:46:17 +0300 Subject: [PATCH 003/292] move credits to its own file to keep LICENSE more clear --- CREDITS | 45 +++++++++++++++++++++++++++++++++++++++++++++ LICENSE | 48 ------------------------------------------------ 2 files changed, 45 insertions(+), 48 deletions(-) create mode 100644 CREDITS diff --git a/CREDITS b/CREDITS new file mode 100644 index 0000000..810f0b4 --- /dev/null +++ b/CREDITS @@ -0,0 +1,45 @@ +This library [initially] used some [piece of] implementations +(may include codes) from these open source projects/resources: + +1. Affine Transforms +The original glm repo (g-truc), url: https://github.com/g-truc/glm + +LICENSE[S]: + The Happy Bunny License (Modified MIT License) + The MIT License + Copyright (c) 2005 - 2016 G-Truc Creation + +FULL LICENSE: https://github.com/g-truc/glm/blob/master/copying.txt + +2. Quaternions +Anton's OpenGL 4 Tutorials book source code: + +LICENSE: + OpenGL 4 Example Code. + Accompanies written series "Anton's OpenGL 4 Tutorials" + Email: anton at antongerdelan dot net + First version 27 Jan 2014 + Copyright Dr Anton Gerdelan, Trinity College Dublin, Ireland. + +3. Euler Angles + David Eberly + Geometric Tools, LLC http://www.geometrictools.com/ + Copyright (c) 1998-2016. All Rights Reserved. + + Computing Euler angles from a rotation matrix (euler.pdf) + Gregory G. Slabaugh + +4. Extracting Planes +Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix +Authors: + Gil Gribb (ggribb@ravensoft.com) + Klaus Hartmann (k_hartmann@osnabrueck.netsurf.de) + +5. Transform AABB +Transform Axis Aligned Bounding Boxes: +http://dev.theomader.com/transform-bounding-boxes/ +https://github.com/erich666/GraphicsGems/blob/master/gems/TransBox.c + +6. Cull frustum +http://www.txutxi.com/?p=584 +http://old.cescg.org/CESCG-2002/DSykoraJJelinek/ diff --git a/LICENSE b/LICENSE index df5aeb1..c92e559 100644 --- a/LICENSE +++ b/LICENSE @@ -19,51 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -- - -This library [initially] used some [piece of] implementations -(may include codes) from these open source projects/resources: - -1. Affine Transforms -The original glm repo (g-truc), url: https://github.com/g-truc/glm - -LICENSE[S]: - The Happy Bunny License (Modified MIT License) - The MIT License - Copyright (c) 2005 - 2016 G-Truc Creation - -FULL LICENSE: https://github.com/g-truc/glm/blob/master/copying.txt - -2. Quaternions -Anton's OpenGL 4 Tutorials book source code: - -LICENSE: - OpenGL 4 Example Code. - Accompanies written series "Anton's OpenGL 4 Tutorials" - Email: anton at antongerdelan dot net - First version 27 Jan 2014 - Copyright Dr Anton Gerdelan, Trinity College Dublin, Ireland. - -3. Euler Angles - David Eberly - Geometric Tools, LLC http://www.geometrictools.com/ - Copyright (c) 1998-2016. All Rights Reserved. - - Computing Euler angles from a rotation matrix (euler.pdf) - Gregory G. Slabaugh - -4. Extracting Planes -Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix -Authors: - Gil Gribb (ggribb@ravensoft.com) - Klaus Hartmann (k_hartmann@osnabrueck.netsurf.de) - -5. Transform AABB -Transform Axis Aligned Bounding Boxes: -http://dev.theomader.com/transform-bounding-boxes/ -https://github.com/erich666/GraphicsGems/blob/master/gems/TransBox.c - -6. Cull frustum -http://www.txutxi.com/?p=584 -http://old.cescg.org/CESCG-2002/DSykoraJJelinek/ From c1c659489aee7533d3cd10a33ddb2a6898c72bb0 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 18 Feb 2018 11:16:03 +0300 Subject: [PATCH 004/292] surround macro values with parentheses --- include/cglm/mat3.h | 4 ++-- include/cglm/mat4.h | 4 ++-- include/cglm/quat.h | 2 +- include/cglm/vec3.h | 10 +++++----- include/cglm/vec4.h | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 9b454ce..61c4f3d 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -45,8 +45,8 @@ /* for C only */ -#define GLM_MAT3_IDENTITY (mat3)GLM_MAT3_IDENTITY_INIT -#define GLM_MAT3_ZERO (mat3)GLM_MAT3_ZERO_INIT +#define GLM_MAT3_IDENTITY ((mat3)GLM_MAT3_IDENTITY_INIT) +#define GLM_MAT3_ZERO ((mat3)GLM_MAT3_ZERO_INIT) /* DEPRECATED! use _copy, _ucopy versions */ #define glm_mat3_dup(mat, dest) glm_mat3_copy(mat, dest) diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 4da3fc7..45f54b4 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -71,8 +71,8 @@ {0.0f, 0.0f, 0.0f, 0.0f}} /* for C only */ -#define GLM_MAT4_IDENTITY (mat4)GLM_MAT4_IDENTITY_INIT -#define GLM_MAT4_ZERO (mat4)GLM_MAT4_ZERO_INIT +#define GLM_MAT4_IDENTITY ((mat4)GLM_MAT4_IDENTITY_INIT) +#define GLM_MAT4_ZERO ((mat4)GLM_MAT4_ZERO_INIT) /* DEPRECATED! use _copy, _ucopy versions */ #define glm_mat4_udup(mat, dest) glm_mat4_ucopy(mat, dest) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index e47559b..63236b1 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -46,7 +46,7 @@ */ #define GLM_QUAT_IDENTITY_INIT {1.0f, 0.0f, 0.0f, 0.0f} -#define GLM_QUAT_IDENTITY (versor)GLM_QUAT_IDENTITY_INIT +#define GLM_QUAT_IDENTITY ((versor)GLM_QUAT_IDENTITY_INIT) /*! * @brief makes given quat to identity diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 06c7147..8600711 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -67,12 +67,12 @@ #define GLM_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f} #define GLM_VEC3_ZERO_INIT {0.0f, 0.0f, 0.0f} -#define GLM_VEC3_ONE (vec3)GLM_VEC3_ONE_INIT -#define GLM_VEC3_ZERO (vec3)GLM_VEC3_ZERO_INIT +#define GLM_VEC3_ONE ((vec3)GLM_VEC3_ONE_INIT) +#define GLM_VEC3_ZERO ((vec3)GLM_VEC3_ZERO_INIT) -#define GLM_YUP (vec3){0.0f, 1.0f, 0.0f} -#define GLM_ZUP (vec3){0.0f, 0.0f, 1.0f} -#define GLM_XUP (vec3){1.0f, 0.0f, 0.0f} +#define GLM_YUP ((vec3){0.0f, 1.0f, 0.0f}) +#define GLM_ZUP ((vec3){0.0f, 0.0f, 1.0f}) +#define GLM_XUP ((vec3){1.0f, 0.0f, 0.0f}) /*! * @brief init vec3 using vec4 diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 91b1059..e0dfae8 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -57,9 +57,9 @@ #define GLM_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f} #define GLM_VEC4_ZERO_INIT {0.0f, 0.0f, 0.0f, 0.0f} -#define GLM_VEC4_ONE (vec4)GLM_VEC4_ONE_INIT -#define GLM_VEC4_BLACK (vec4)GLM_VEC4_BLACK_INIT -#define GLM_VEC4_ZERO (vec4)GLM_VEC4_ZERO_INIT +#define GLM_VEC4_ONE ((vec4)GLM_VEC4_ONE_INIT) +#define GLM_VEC4_BLACK ((vec4)GLM_VEC4_BLACK_INIT) +#define GLM_VEC4_ZERO ((vec4)GLM_VEC4_ZERO_INIT) /*! * @brief init vec4 using vec3 From 43d083730333959e5be902600a4535b7739d64b9 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 21 Feb 2018 11:53:31 +0300 Subject: [PATCH 005/292] Update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b185646..8c63fb0 100644 --- a/README.md +++ b/README.md @@ -120,13 +120,15 @@ MIT. check the LICENSE file ### Unix (Autotools) -```text -$ sh ./build-deps.sh # run only once (dependencies) +```bash +$ sh ./build-deps.sh # run only once (dependencies) [Optional]. +$ # You can pass this step if you don't want to run `make check` for tests. +$ # cglm uses cmocka for tests and it may reqiure cmake for building it $ $ sh autogen.sh $ ./configure $ make -$ make install +$ make check # [Optional] (if you run `sh ./build-deps.sh`) $ [sudo] make install ``` From 8a16f358a36e4c38eb815900e8e34833fff654c8 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 22 Feb 2018 19:55:16 +0300 Subject: [PATCH 006/292] build: fix C flags for older compiler[s] --- makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile.am b/makefile.am index 4226f4b..f5a78ab 100644 --- a/makefile.am +++ b/makefile.am @@ -13,7 +13,7 @@ AM_CFLAGS = -Wall \ -O3 \ -Wstrict-aliasing=2 \ -fstrict-aliasing \ - -Wpedantic + -pedantic lib_LTLIBRARIES = libcglm.la libcglm_la_LDFLAGS = -no-undefined -version-info 0:1:0 From 4ce2e86d9fc114c83ad288941637a2e60aedb0a8 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 23 Feb 2018 11:12:55 +0300 Subject: [PATCH 007/292] color: add luminance function --- include/cglm/cglm.h | 1 + include/cglm/color.h | 26 ++++++++++++++++++++++++++ makefile.am | 3 ++- win/cglm.vcxproj | 1 + win/cglm.vcxproj.filters | 3 +++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 include/cglm/color.h diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index 3b0611c..e99bb09 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -20,6 +20,7 @@ #include "euler.h" #include "plane.h" #include "box.h" +#include "color.h" #include "util.h" #include "io.h" diff --git a/include/cglm/color.h b/include/cglm/color.h new file mode 100644 index 0000000..69566ad --- /dev/null +++ b/include/cglm/color.h @@ -0,0 +1,26 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_color_h +#define cglm_color_h + +#include "common.h" +#include "vec3.h" + +/*! + * @brief averages the color channels into one value + * + * @param[in] rgb RGB color + */ +CGLM_INLINE +float +glm_luminance(vec3 rgb) { + vec3 l = {0.212671f, 0.715160f, 0.072169f}; + return glm_dot(rgb, l); +} + +#endif /* cglm_color_h */ diff --git a/makefile.am b/makefile.am index f5a78ab..f6d1471 100644 --- a/makefile.am +++ b/makefile.am @@ -53,7 +53,8 @@ cglm_HEADERS = include/cglm/version.h \ include/cglm/affine-mat.h \ include/cglm/plane.h \ include/cglm/frustum.h \ - include/cglm/box.h + include/cglm/box.h \ + include/cglm/color.h cglm_calldir=$(includedir)/cglm/call cglm_call_HEADERS = include/cglm/call/mat4.h \ diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj index 36000c0..4a0463d 100644 --- a/win/cglm.vcxproj +++ b/win/cglm.vcxproj @@ -52,6 +52,7 @@ + diff --git a/win/cglm.vcxproj.filters b/win/cglm.vcxproj.filters index 559f2f7..506f3d8 100644 --- a/win/cglm.vcxproj.filters +++ b/win/cglm.vcxproj.filters @@ -203,5 +203,8 @@ include\cglm + + include\cglm + \ No newline at end of file From d95bf60b0272ac16d1293481a3ddf0ac9cfef88f Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 24 Feb 2018 00:54:59 +0300 Subject: [PATCH 008/292] docs: update docs --- docs/source/cglm-intro.png | Bin 0 -> 74053 bytes docs/source/getting_started.rst | 4 ++++ docs/source/index.rst | 6 ++++-- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 docs/source/cglm-intro.png diff --git a/docs/source/cglm-intro.png b/docs/source/cglm-intro.png new file mode 100644 index 0000000000000000000000000000000000000000..74ac74ec4a588606b06cc65f5ffc8dbed3d319c8 GIT binary patch literal 74053 zcmeFZWmH^C*Di_$3mOOncMC2-8cnd^&;<7Yjk`Mp*C36%ySuvv3GVLh+Q=pQ{mysx ze%~|BuRF&5alallMpxIWRkLc&xk~2qtPYl!6-PzJM}~reLY4R`0)&Esor8jc0V2Y` zmT)^-xV?Ts+X2PDK$VRW?!V^MOunhwtI9|N^sOwI^bD-N8!|atSijbSg5q-qyk;#7 z?e$2VEzB+L0M7j6f7JlI=KmBklau~c#ommcTvbM%RM^Vakn|H12NMgq05T~lDW9zY z2mllj`>)$yfANzW+uK_Mn32Q11! zhNcfgt^2oReTVt=;6OC#li7@dp`jtWt(_hH!_9GWyUXQHQJ+B?r^UkE#>U3xM|%3= zpMuYKu=L6$#vJDQCWNvlKtiLjv{c8V%6{sOtZsM$b)fjj`r`jh($Rq^vj3NUB_$=T zn3NPg9(sCuwF}dL%Qy|oeUGQ>*;@l;Uh5b)2Z!r#T{@wOePh^-M4c)H;y;OF@KU&A zpaT`G4=Osr0S5()OT5j*iyF^$;AI<`4mjz*rHyzYKH51C1#dAbYU&$l85z{A(t?5y zuot{QAh2w{$>ER%WD2_-W!-8$_T}?owb#otlTKZPIp^(?og9F0)O*mMcCP#OWO*?P z*|8O1Dm4#iCLS!;+P0FKCz}0-C}~npq@LV&AsgHua`&7o#ta;rbv?d$!@eHrjd72On85U~*;CinV=$#$x$<^0}eLh)2Hp@#d{#1v=!orlw{Hf!H|% zg_g+CTg46bH0+Ao#sl%!o)H^VRH#~Ndb*CTSnB5$mw%g?2?yaefSn*t&YZ~}HF&L3 zH);Mi$*^r-0HSUk-q3}jqN0OGt7SWW=OJNXVO0SF>z|B9Qw)f*#2SV&g#(q#)N4P6 z=k6A|Ulb?#c1dcx?&sR#OV*;PcFT71C-Sca4`-;@G`Z|Q-LC2cuxUs|^i6#8)rW7p zSnKqi4j;^Bi6+7OCcce2Si*v;Nd~&hr}*^&R3_M2B6v`c{V}rLC*wL*HxY618>mfD z)ia&a65Ni>X~=?fj#q=tYU;y>BpJiMMmG@qV}#6F0(cvyP&_t0gxc$n5tXJB1_U`91S>4-0-bDcl~BUUVX$uSkF?@ zm+E<&*YW6U7Ha+k=!&k%w3fFKtL!78<7%6SNd;=5M`sgl=*LBx$8?0^dfDaH0*s~YEGiSo zXxw4fE%bu^=$BJg{v^DP=5+UFwc@2lYR_$d_iO14Iv66yGbKelu34{#tNnZoM{?v% zWWcW3-O@Ln)HQ*I5d-*UD_PmmPOJ7OR9?%o4G^+Dg7 zfGPJpCr0)o9>1&o{lRoGMXE7)Jt{{~QIZrH2tPCt+`~`MyJ>v#HgXe+8tWzd>t;_* zPEO3=p~2%dUgec&D9(Ej2oxuI9?#H(FNNh2@kK(x6Due3Os%M;y#2W;ZbO_#M{<$F zAVC&r7_Vt7Auyyzc}(gH|Ga15Fwu%!?lTvfFrt0U{BpqzgiCJ8`5hk@hvqw3`CZI! zeoj#$9~apWFQgVND%r;i-XRjbU1%rZfHoy@f`OLyg9u=9%^vxNu7Vfdjn;%ZBPCWk ziKCFbiD^OpCz))#oKc@A-2Ir}s>Dawi_tFPnP#Wc5G+~l%t+2}p$-i9-P=KR`Ld}1 zXeuYb1x?m(kbIiHo;|f5cvWOUYiKx;{cT@3feMZmlPcx;eS`L^C(vfL8k?~zJO%{4 z-yQ%qcUz#{%j8=atU1YBsD<70!`|{#C@m7n2p~mo7MHgbsk}HGCUMh5p1>WnBMiCW zU2FU}inhOUT-R%F#tfUsan7YbdaF|(9=+`UM zl_IhLu$J4UmhLzSZ;1thg0Wg1GL^1r%8b%nKJ`VAM|V|ZS$lUEox zlbDuqo>m{B>l_<*TNrs_lfYHIz+)tQ{qhE90?!1WLrxzUi8L ziu)_8C>|g#ohx!ybWS{`kLBomfHYS^NLcIQ^0rOE&l0@wkESKY^D! zrv|C+J{6-X#0wWd4iU@8#tK_UK0ljmv8JsS?dqS;ehi}YOb>+IH^_7p9EWx*G;F84 zUkvibGiu-{RGqd#PB^-x`pnK%lGFU~A{Hsb7OJ*}vr{15u!8!1VR&*bmZXnVet4mS zlTJAPNO=o?E{Zx{9;#V&#ly-;ok=w5|4HRxgQ7Vq!qDR)|J%6RS zn$fUA70yI&h^~Wg6N~zp=2V#^OQdvrG;cTSkE>nK^fiM)IP&((V|k~syvVV-%~gwB zFLMv+Vp=G38#mDD4#M`2m4+G#?w3(A%5*PG#y5lCcyV1(Uw3&J)%gGeg?A&}j6WgM zbD?*s-5x;@2EdbDWw{EzeU46^Vmp?vtU|0r1M8gx-J;ChDI$dE#u4;omhJ6q3}ie3 z*6$v%-D1hi`-=_J_A~y*@dp9-J91Bi5Tgif-hZI2S3r*s3#r zTh2pl>k-N5U8I31i59EG@x@-?_5cH=C8{=9kd>F$4L^-bF`{rzC#r8Zfp9{qZ${{c zEaj~E8TS%r)^Ey7jq0NCyhf8rYPvefOJf+1aJ9bH8~@^E6KX}|P4@$NsUV$xD`v~i zHMm>GGVwThGo*{J6EnzxhB?>#`^GOWg2Veu>E5Y<@7iFM3G}db!tE}ZC&s1Q76uK> zYb%)>UZ9;Sk5?ekkkEQND2Z$5!*YO{3dZ>4mvjTXen zZh@-h9jEy4VWT-q2#q>F=Dj$`b50fi7c66G|{i9S*ToP`udC{xD zl(CLuRd`qBm}k#8f2ZtY(~8}91}nZ#02?kl9nprU52eoI-txV1j2bJwI@>4^KpRWfH~doZM) z*uTeWN8X^Es62^i2WQd9yS@mu^o|KYj%4FTPkNrvX`9;(Zy>jFeCIvnvdmuW{QOUN zU2Q+{zAgpl%!fmS4#Q%pks;}Wr}SNDqIyYP9zU)5zyT*qW&uFS7fEn3C>3UuVfky9 zl){Qw(kewe_7in1?1!LukkF^%dsbV)F5rAT-DWfRMaEMweD#-K)Q_pR&4Z46JsbL$!2(c&kRlGpC4E^WDd5phVJ>ELnY*fN|f>3{a>V_H_!V? zypmheyJR$|YEWD`G;n`hR1G(yTL@ogsaewv$wkhXNyY%Yd^w0awIr_w6VzxE@dlP- zuBfq;eHo>URZb5QvrrFR9=L`H?oRcj{0vZax*Nv52j8MFFbI`#ff2?w%?2(>On1NauE$u?Yw=t{5Q@>>4m5V+w zOdfzQS(=d`C_8Wbb4%N^&%iG(6AG!RJ~}wCDEM1vhJQPh=)#PU|IW#pD*4tVPYRd{ zwoi+nDD)(Hql;P%#-xgoz54tp*!{vUaw3DEK4i>1a8$1vhu*7F3rVY%aXp}V8d z>vqz(d$AwnB~0T^;UFl3~?P*mEW7v-jE6=LZqJ3|jh-c*Ogj z`9Kfs8${473{?K^eOj`3Ip0$vi?>Z>RVH9QH z!;u6og$z?0VZFt`=#L-mE3l6qoBr(avM6nt^t#N4Vq!ygKf%fP5WGk z#4Pmrccd0h+VFX5aMgX0k_M+sYQP6V3OQO~-CDoq>am{f9xt#1>SjZg;1ci5w)?sK z#-*=BPTVGmzj5-v<-g zOhY-OhePQ7=0!eO_y&v~~0ig*5LQ^5O5pwm5oP!ApnUEod^nlLVN$t%xQ zkEbb3Y9#Hp-(5m&c3if|>v5Ch_S^k>D%@slPX4YeJ$9cT0yX04uYVl3k|;4~?PUT& zvZ3rlK2ba{rtXHL(j^RM#a67|xpf`&8{agLK-g|Gpd`;@=7Z+T=H-tDdXF?O#=M>{ zwP}46#}jLQehVpy3pdMC`sIwE&(8sqYhPOf0$hoxXh(2rt?Br=Zlh2BSFK9Mg9AJ_mo9EK{ zm8OU_o&Q+^OSm!8TLDvkf;PO_D@R2y(5fK9QeGs1T`Niq*-mcryn zZ{KO5&SJ5uU{*hYhe#Okq>xfmB*Z?-&Z@qU_Ja)%<;PTPVPm_5IPw(;B;r&&deAe8 z2PJx!Pwtz>x~;T4!6`x%5HrnonEHqYKCGZ{A?(0jt4CdFOv*%sNJROU!rN?78uBzC z3Pux5I|Om(pQr3e|7bd<47FD0XT@mdItEG=#_QFrKA0~A-RPF<>+ZM>wZEfsqhAWm zieJLA!~!vTMrT?+AknrFs3BGP)KFtuT5D^kamPl>ioHE3$F&Lgei2Jj2j6JAO_j*P z%|21>P@FcqzGPZEV6YGbKXV|U0h7mp@crRkAN!p5Kc4m9d@zBjKV$+M!Ln`wlD^`!*eVQJ(JdK1KBG}lv+?4mf>PbKdERGF z&a_jHIH1xEI&6r%fMJS!evo5#Z8RC8BY*{Ospe|u{GPHceq4#fp)4U|msfHiW&1!K z)15?+r)72`f!S=#ZTL-j*d+^Of6si@%>Jrqa+=F;tXzi@jO zJ)Rl_^=mdLH#Q4VO>90}Oy>7oBi^SymC>ab?`wXc4@fE=*u6*B@Wsv7x1t`_uzraI zjOz8pr*~$^5bsaL@SJU-+s3g%WxS^XJ~u1uk`cA_t$(jh*6)DVpW@ zxhrvcj?d}=*?YkiP-T`u7JeZPPu10VPTy~=Bt+~haQ)c5Zl3)25U!BcU*>|&CA<<@ z|2=UGAFuq2M9`t8_Np#u{=gLE-H3|qYYLdI1su?#J(OLTw=nmcXI(x~-@rfYxB$)N z5pzh*l;x_EYB%07B@C7&=Pf1bF&lAu@YEYoOe)YO=u1dR8P;+*p&}3AdklTm)7N6K z8qxI@lG6FKcta#9Vjy8z;;bil5d-s4w1K%gwlzU?cyd^0PN(ieM*)`}M|I)$`1lIy zvXslmJQU>B@H>};rl_2&H^?M}g<%JYuaAyDx{?i0X`FP83N_eZc6W z#K*;I1CU*_O`BdmvlT3~36uC{<%? z>E-Cw7Z9)KJ~i~~+9N;wI%?IDb4}`%X*jN1?D^))v{1j8F_CXg$ zK8D-qP<3mi$&U1rA(~o9FTLprYk-gG!>~jj>tLDyE~xvAAH9Z0=zsD#z1ua|h}aQo zl%AkpcQPRT64CK&VArR^iB2-i;WvsmQOQ}lLgSSXk$mIYAi%DtwQ~8KL03;_p=Si4F6lRw5x!4DX4qSx*>q*^vn3`f zH@dm}0&_yun>QBqQ1?Z*$BX@&33-Z}#g3;dt(LztJ|iIJ%N3>id3*#>SOC{QCFD?D z)A8+MvF2leU}e5lFD)RyQF#pfk8pTx zMx3^|l64^WTttcU*=SdyhTQG(B~DKp;FTvhoePO8T0UR@wohA@=%_8a`A z;&OS%S~CFBr=j^11=bb@t%Rv4vdE$yD(ti=fUR$9RS7 zAHYULF~Go)w5qX22ip<9!3?eja-lLzNjAUnZz`WoAL)h8%B6$IhEw?>6%296n0S}+ zkOkBBue>Kw=K2*$fchtEim@Jp8}afirYTNH^a{g<#Ne{G3+}dSU>#+}P)6^yc-yam zTZ^rx1P-fCX`z!-mz`qgoBpo?kB%1*eQ^dS6-dZw zy&hXJEHQYI(wu0^?|t;eN6`(JBd7b6Nv08PdZy>xhGPnMGUU&tRGY)#_p3JjL{^&u zLDoPH%RXbTdQeENwWoB8Dc}&m%@{SAg~gr72TJM*)g&aZjiKtH59STL^35$ysaQ(s z9s&0`Ul0kkY|kCmV&fQ6MLXJA$=hg7{xiY&#ZO+?)^yuU=iuI+Vypu2FP>Z&gyP7Kx*T`1Qr zBWFfcE+7OJOlwb3qeb3GKayL(drd0}U;HZWl)8wDLzAQ55NdIyK+VCep(4j+d5d3@ zJ5xh;(^BlQpJVM)=C)7^7Cc6u3Eo~1)alhWu~6&SXO7sWntJaZO`i^!Fh9{94)#kNtj=IFMX%jx{URX6 z)7!#fDlas2X*-PAl_IH*FOBJhTCkVmW7y;7`#GiDzDn>!9e-luLBB(nB;>w$z%G(w zSFh&#_p*u23G;@u+vx;C4?HLV1lqB~7OtzuG+&h6?>pAzSiO_9P6D@9QKK|dr6-5e z%$ENa(fkafrQMlF@kmT`p=9sL1%#o)ZmRitrC>gSe=3%V0!9GLq;Hn-Cu#)IQ0=jY z-Tb)eFTiRKJWDds5PXf5Kk03&BTbCY1~1=Y%2wAo82J>dp*6pvYAfv&WuQAT3{jV& z%V*dN6J_P<-_tqSR^JgWIHIUKpKZy+-&D6gSXQ*LmgY{cO8Fo``l}S|>oISXhMLg~ z%VxA^RnHF|OyDu=!)XhF1NL{5LPHCv8X;5K3Fc(wlaY*3tJ@VJw1s{q1rhIZxGOpC z=)ui|282>g-Gjo_IUkeb_N*vR`T|Kjxziy*q)1k~biK}bpcwPYALbd(GP@R*uZycAGgy|w zACrfto11qKBnl)nQ$Y0c9W-=QrCFGbj(1Mqs6%}j8Q;z=a{xZZqa19lvq&To^oLPcC>o0Iu=~D&_OH~)j%gTY1b)xtU=fKU&}U*lqtu%z zAZrU%x(3+SihRnl7YqE^rlJ|w4#H?B^cV6)l<5nOAZb$pG?gcAzr~KKNH;&e7E?B&>_QUY1mr-6<{oBten~eZe0yg;#;JlMY*NU!(W2tsx z61|gK;9(Hw6g-|VZLbLme6ER?yJATXCk>6b+p^-CMv>a#o-1W3gF$1wV@b?_SLj8N z4~-UniG&Celjp@C%_rkYV_plXr^3_=bH{9k%%ok#F}G}&{l%^B0Mx@i+Y3{8X~~66 z7c|L3!M|%qoYJRTt1}{0(s1wq4jlCoF_G1sPAtT8S1~#`N~DfPN43TCK9?r^k*nHX zn|(dXCkTJrmG;Xckr+*d;6T_mIW|4x_KhJ7CJZXwoU%HFv-{rxW$Og2y$h)xbd~3% zk!iYq+L`^~l+@mdsmi7H{--2BpoarD3@8s0{W5Qm(^{KeW$(;NBYFx7s7l$cdbmos z(MqTB0w3o3J*DC8agHrHId`V`{5x`PPYz8#mx{;>ppSEqGo-s?z@8bWEdkW3rAs~p z<<9b?wx-}wsna{nviUN(*f(8B&^|0i83|VHFODx{C;O{)pU$euw)hJ#)fg@QbFKe_ zhzgURL_<7eId@b9Ss?o`7DBtk2MOK2HkZYFnRrtIgD zj23y(J|BoY^Dl{(ls7Ub7_$GSC!uD{Gcu#&fC;2TZ=}cN)h8{dQ5W*_kK8 zv_HlF8~*KBm+nBmS=Vf4N=C95@WIF*MbMDrHq=fRJGdf7s~g=!uKVOS|2%bR9`U zC6dwiJ5~SC{a<#lmw`#T4_}n3o<;O>H8k9QzrVllt5CPu#Al;{iL>+{$|oh`NyC#) zWXmPF&ki3x+5@_Q{$kXtvL z=F5c$yMJt@{sMb~$T8}X9i4BIU`GRhX+1?nMQ;;&1(MW`>^=LRRxSzv7o~r5o_{%# z5Ftj8)Ei#co210U6YDN%U=2Mk&NUY9W756_^C*NvzQckFwh#2n|}A*R3b zd*(1U`MO*jZbSh)YDX+ci+`WM{*_OaAw9u9>I0Q`uknQvQR^-Khmtbbk$Pf(5SiTo zP)4ff^xoC|8%yNXTLCdbnsjqABiezTE;zi>U3LH7*90LW%pig{%{dUoTn`WL512*PI{=*~wznH3;_u;k52!xW9rk?#O5TzWIme#f(B~DCtnv&A&$pk!uM<-5c zF`F$5iPv^5tjeZpdww`{%gf0L+lX=Srx1@=`a)Cl#f5WcW&DD0=t?g=DJqKf12KP0 zbab7-<5~B;dt3Q0`uW$T9wi7xc*meD+%pZ$kls{r1%FLq9V>dUx3`yUA!|XK=ep3S zD$}vxEO@BW|1@OJ`GLbw*o1!GRfS+tJ(77_YN_4J3$fXC?{{Wwi(S$KUmm1dL9w@sEGMwGj+)QLt$1031n=_3wf9;cI~9B5ehZ!u1G4G7yS zmHOhQ4g4K4FSu7PY@pQI%Cs&+3ua!R*GN=rE1Lu0k8&`^UYBB`vD#UrDk(j_-4wft zpS&jxIk{5t@I-Vc;u*iS0x#I`bJrH%(<_4=f6!_PysgYqZ}M`hC+W;)r?3G@2y<(y$9z=O;Z%fx9x7OQdU`4!*cgz~pzIt@+Fh}4OSkB`Sg z!q|j23^Xn@rRR#7+!u9-W=1pxF5#wMz^5i4 z1{9jU&ROyH{CV$fb9L0Z(bfyaGYMKAvHnnLC&ETpo@PA8sq(NO*~|1R%WqjfR>`xp zFh6g?yj0MaEOF|RFkv-9bF;8q{kXAqACUHEkt7_2`~K{^H}qy!(C}Gr zs25_0W9ZAi<2DCb9v^W$6Di38Zu#MM%@pi+Q(fU{J4^#ZQsSDl5k+_QTgp7s zvP;ti`@~9yzK!u|OHvGRh*gkdT*%<&y_b*EZuYPvlW-!Max5)sYyPJJ-)KkH^=J4? z_7vv1dMlk6NnAZ)hEK#HS$0%5OuJ5ACsKu%3BST)tq98Gm6esf(vqbpnfFut_eVXT zK`giNig7xmvqvN^cl~(l?vZqO@cMTi^gC9Fc7%0zN8PRHxAFR`u-T2n5vJaS!ps*I zpLkKRNncRlrq;Ty=WshcGWrygF`B~K2J8LqQFq=9Lrb&yPFz3BZLSzH56Mg1f9ha` zCL3E@iUpyDQ+lQ9!dJ84Z-(81Zsv} zD(HZuNvT(=lh|N!J~zkqD$0Y)qpueHVQqqN6GsWr&_viq9TTFYh7N!U z(rH_AC7Isywt3Y8{q%hqo*zNzYHb1m(kw#Em`C-(rbYd7T<~`%@~V`G`#9%vi@6H2 zbO@SaMHCMvl{2D?3{ATEa684NSNF5VkQ4JQvz;I|L=t?~iNCh))HPG8;r7l5Z3pJj zQTJqb9^!T&E%_j*tKEgt_hJf9EgmTsh!#;FmpUYTAE-Ynw4x2x=XI=pMlV_+aXYG9 z{zDt6m?nEVQGn?6S4kKW_`N-gqA+e1tPt0 z;`)vbVmz-ee>K{b1c@DlGjMH_NI~87DOJqM5H)(8thT@C+hcRUcny@*fpaPR%l7@k zDSu+^dz*JL?6fsdT=Ef4oRr*%(r^VjKJx9Xa?9x=5v>k{edn_cQ%Wm)2(yRVRV4(F zx7X#(7ppK^kTrUDuKoH-pL~08%6jOc!@+}*Z@55flJvPH=qw5EiDKvgo?qA^mR{LC zRZYm#E%N^T#UtuP+f5IaocWelC-KqP{S*0ldmnN5;CBtN*GSUmmdv{+Z;0K%^HBCr zfu;!9RWuBzPy38LR(K%4q3Nh%$%U?nd399ml(6xt$KHYFGM;PEhVFx`VGY*PZe1t` zu0Wp_Y86dFWhl)Le>~2Z%;!w78%NCU42=>)VEbFXLSOhy4fQh?DHa6K6CJV?cA zSBe$We>TSa)5~*T{l@@O>9oClQLSGotJelXV2N>J*+h1>a^XC3s&^^hev8t8v({1oANj;!|pCL(+8B`HlJV@dr+Fk?NYpLT7xgDs3B6toR za`IySNIJ;BY=0SmeBL3T;$t(=pv)rZk#C~}ol3+=pJFQ3rEkT$k=$|JCmOLB&+4?n zCPHkvQ(UwaQ+vF!m7l0nW`VO*AqF2$}hnX(& zVFW&2B7qr6+oQjn_NJi3bGhi? zOg#xYiF~%v`*S!Vg@>k}V_mbaiw6t>XXGgnF3>%oLQK&CdUVT84)i%#)!|;oz$HmU z+%JtMzqHGu?#zDLGaJbC%w+0A@En-GbMmIkO1}g=a#<{V>&WDoe~c-~($D7iAQL#O zNzUDQl4lVgkNPUCFeiqfpNgjS9eo{ff<9}rDOJ|dpwG{`323j2?h?M%mYzUn1x<9w zU%%pdC_6zP@=Q~LWj!CyjbhjmeO3QkqNH|77P35GhbXD_(e0&5PhM6H!l684tw!vA z*7;={HJK7TxdOKMU^pA5@KFN+xx#M1Eg#_O7fh?hGCjBo$S{I)xz0zC*kW|#<-s=E zg+=Gfm>-3Y72eJdl^ffGO3`mn%C|upQnoi@lgExM#5D=2jq}gL$_sM0z4N?A6DU_w zrHBFC(^*dfdop1W(7v@g3g3JjN_U%-;WDhAWo1svzpxq$1<0oHx!9sNpyiH2$n4-9 zR3+OW##qgfa`(lf6Ng0=nSMto1j=jbk!3Ki&jVq^ zIFuOMbz-@qUt#+4NFm9DRKU7W+~iHmdH_L9&t=9I`mPK=xXT@VxK>5um^;QdXo&8T zcmtFjNfc(u9-X=xoRiO=4~taZT98;n!cPFPURCQZ6b20)#s#(@^IqU#(j0uJ9FxVP z(b+wFyz!ZoUl3zn5JMV+D5otRw>W)7oQ(0w%)CQz=(S4|f3p0%;}Kp9oiN=*EBBXY zf88RrnZ#2ilx$n58ec-4E!O)*iT)%79yvJUUp z-v&2_U&Up$FlA#kz+%zv(2DuW<2bOSPPpLPL1B4F6avMoNKz~MD{uQhnl&(3&kqZ_ z(?PP4yh4V2mecP{H{T3Y`L_sWD>f6V-Fz>a`Ya+qw{aPH>)iE5655cF^4Szn=|w*L z5ql^PJ9njrNG3&dVj+wi6a1blRW~()aKXvtomkj|UjFxZ(n;l`vArd)0KP_A+Cs1q z;d3=>e`MUmv226=5mCi+q+#A^6sQ%?_HofYvm!5(C0ry*Ah_kHC_LTIq2@5QBhk83 z-ABBk!G#LjENLESwR}jQxj0<$r^qblCV7Lv81d2@QH|jY0a?-!EZR%9p;ceVz8^t| zraGhiR|5552)V&4H%G&wdHii7`+mn5btzqs7t)Lw%loa;`2sUmAX-~j+UJF&%6GRI zAR3p)M9xd-bze?j4VYW?%JKLcj+k^BED%Z^n&-#xu04=2AhGzMV=Z8dPJWgT&i(N@f?+7BpR^l#WW#AI zL!-vKhyI!SP#mf*lGH!fyUtJH6e%ksE0k+^)@HdX#VB}L0%uIRalvvNmdv;JffY=I~wJ%C!)HWdXwODsz=}U@cHI(S|N!81I#+a+wWZk zlOGlR+%lI~aue3t$^`X7Sd|Vk-ie1y(=y~5)9i8dp_ooy^IZPB7;{3*138nOO6Kb#x_XoDfyRvNU>pxh3pN| zigp%mZ;czPoxdH*%02EO5YFENZLD}hpf2VHo@~t>jPo}gX>M9bJnuelqh&If`gic1 zoOYn}d41ATa*RFZyJy|R_UkPjf7>eqxdN{`N@GI%s!;*j>1ca4B~)t(y9~1vuz*dzGfb&^)zDOS#CWe zhhaaJvzqERwWH0K87W(5045$Sud+1vd(!=)*jT)e(LOsLa2bb+v>-cev!_Ci2Pplm z3EGV!U&ih{qTvNi*$|IcTAOiQ#(Ga>yHY~h(U^hFYN5-pxAcwi=K4{k%LuHm6Sxo8 zNS(s~dlp+Dj{;}xA^tGslD&0onnUev=)DK7blDd))EWcbwtkQI?lncC$NS_T4%9+i zYPS+geto_k^3F)(M`gnymzpz%5|zvZpG;N;UJ$-fU&}1}mB4bg)fzeI_Sx6Y_2gR9 zSoxZI$x~X*DvR*)E}iAuX;R*VDZ1Bz5!Ai5cOx;+NtdQYp&cCdsIvSD%mWnev4CSU!{u@Omt)$J z3*P`hr*#2eFY_d#g_0PF``vbMZfTOtgVECMCHiT*O{6s1?K_O!gLwV>>Jqzm>mQK> zgGLKLcEq``*U#S2us7Ksj6p@?YB&?hi-TPS><|XY4FZPTXsoz0(H<=OE}d_XFToSaYJ*VDs$8hd6U+b<2P;> z;HeY!U1@-)a}T~w2wa(vqfRYFBnIAtt*Kmz3$wEuUogdph696ciD{0By+woSSbkLC z+XLb`Zc8-kWyhvHr31BwpJQ2l=gG!`7K*s_C|`7ka@byYuP+&ot3#k^OLgzZ8qx#Z zaCXrBp7`B3?Y#cHKv!k{{LT5%=~1r#5lKvafv`mbQR8&u-guH-g5MbDsnEJBr57VQ z%b##Td=bHk2;-(|MZ#37<+SOWR={=~YJLx+MqOAyy1-NZ{N&TzW+gfh2labOKsvmd z&bHPin}wYj&9H&lTYvbtnh7yj>iNfKEIuw9l9v7of|f|RMF$RfXH=VA-8dkw)mhk{ z)=ZfS!Q7kGmOQ?Pb{6jryqTv>XZ2)*ko&5m_3$dEKeGp)$CkzM7zt|hyvy# zDx?4VUohZRZ)i)hiEmn|{t)VubmC8@Q<8KHlDmmUX>=k!Pl)v|{kntVz=IF+bZgJT z2QO;i_)<72!xtN_4XHu3(7`?#Nh2LVaVbdRu}LMUjy=gehth&3oo4-->iRux>49ce zLrJFL9aQv{-*q*b9*id>-+_%J*+za4 z9GxkNJDx$Z3$v|e@|K)r*CEjWIlU~k#;6+R5$~eQQngd8S9bL?&4e>aZi_1WLk$;W z@^Uz2kp=ju7*#rm=Qv>+AL_2(imrYg_O$|E_IobXrI!Kd*{xQe&hC@Ng}(Xnp~o4u zg=@J1rc^^IMVj*ZRgYB=SUq=sZkl*3=K_sj8foZSVZh^!i(~(jlEFRrMsp(e5a=#n zcC9@wNy?bJ61Mc#8RwbC^2Pg}YDZzI*7ZyA&(S<0$Gh8{K{MPPs^OTe7vvj(?Ql(_ zYI{vd6~tTDc(B<@xc+%VTvJ1&b#V{`<;Bi(FKGU7rfL$8bbxxrj&+sd5aNJtT&&VS zF#yfET_cWKWF)_Pd@s0%n6;Oc^cuTEg8T017y$>RRTu^onh#v|otN}*Qv4O{rf-(_ zMRJMTKxS9_m*S$~R)YJxJt#9rQ!b+5T*9L1=%;T$N-m1k<`i;GEBG&|hl`fY7DW4H z)Jx76A3pE8@`gCY3?MD)(v(&P*{=ZC*uc)+74=w_*hCH^LSk98GE8)nK-GS|9PqZD z@&+do&!MuuLKq!(Iz)wB>{!2T|g;4N#=pmS=`8KDC-EqzU=(^s^V}XzHoMkLXN}IT?ReG zq!rIHt-Bx{=FGgs6MI5EWbhR3u|2eHH#n*-8W*rs_Y33Oh*4y=jxYN%W z=OOYIZ_ACo-D)efG4^()e`(e=B2v+}2S6ZPEKtMYj=E#B&=q~=jdODBS{p!goEv1M zJ$A%X6MIsVe9L;z*KTsRKQEh2xDe7~k%hJ?oo$YU!nxl{JSEYLll7Jwe)i*#HgvlE z=e-}~>Xd&)FWMqQ&H{H7G0Z-QRfB-UcV0LQR#R+SICSYf78m60 zz-KGdbXySx%Z@hItnFh##^uNB3krV=#L47R5kQJ@X; z9e|ggoz38l$j{5EJsAy^6>KK8^#%#=#y>9zdwKyimufUMq)0wp-obkQ+LLA!UDv`Y z#u`{T{fN!r;GJ8TTh*eiMwMY-R0g)h+ds+E*O5yj)tw?KRTWB13!5a|kbdQQRs2x< zZUEHy;1AJ05vKJW*};kx^{w9s41|mCYA9w^!{ejPQ!K$Np&W+lns)VCo7r%j$`JY# zk(2L}e9ThVE1T~B1&vV&9Q{oyAgN%aPPYVJWq`q*$rrg6o}s{NyZEUYK*yu@D_k$# zCpk^AmWweSeXAfQ6W%JP#pDH~t|)1k+CX$sT|4$w^}`Su=NsB#NOro@a<=h4h8Ud^ zf^(W_tMHz$N*C>i28wV4c(Lzwi#N{HW(G5OZ%rrFV{PCs82eiqT(1u_w-CXZW!mwy zQ;BDUK98)OVgKhB7RefMq1vmI4vi+7`vXOZ5V!7bDq2TjctUf0uGqrH$&+ z)Q5pCdQm;i)|#2uBX)_(FL5{(`bcWBC=l%vUZQ|9_n!vjW#`TK4+CAswfO!DK4SWC zI>>5(V_^F!Gsf)B+Yhmyjh_6x55S&%r>88JuK<>J4Cw9c#(2*wT+S^qCh5YG1}GQ{c31T_qkBU2K<3u z&#Sul$>Ayr^^tPH0MTLT5(AU%_IJ13!{a@Z!K+wEb}+Z66MB!R)n7ESjJ6T~AL_n4 zDyn69R{;r15Kuuf0)morPND?Kpaem3&Pa{}f)XWX7(fs~0m(TGaY#dyoO8}$2s1Em zbI!f@=sEZO)?4ene;$iJw$i)z-rZHz)n8S8O;U3v=3Mht{q^&fQv)bVRBEYZSM@!f zc+QYMt%g!*qVt|l36=!y(+c&m4i`j6obODIyu|Cvk!oHf9Z#z@jJxe3nPHLM&Kn3Q zUiWuxr{$kq7AtSRxeuPx=~z#xI&(#P#W3fl-|no^kcrsS)+`&-X55fzsa%k@mClVB zQ(KIu^1ynrs7&v{OErC8qZ{=mJRu6jD?x9PiCp{4VQ1pu)li=O-lf~NI-;xKMZavE z!&50jbi$MFEJtioj2%kU8y1!A{D(B(RvyHgHB2Rl!~#?lMI;cYB(tRF{&srzo;;^; zUfEn3g@@1ayJdkq`34~ z-C+FuI!VR9H9}%J!%!q4oTNU%@Bv+&kdNbKX)d>bUth;YoK%qhB{^j*f3m7NqnIS+ z{kRaI_-Iu{2~Q92Nx|UF)Wb;psc^4e1q;C$EqI|NyeQ$BybMS5Ll2)IFN%d@%1zd7 z)*tiF9eYW?|0sW@!=3w7Wxz5&Bs(B@IAk#9r*zSJDUi@m;(ok7I4NAP5<8JJ$6c3| ze6-$YP>dw|z)1M8JKgufvg_`5ZL5Z$h)e1&l#7`qf`iWKspDGg?6=NK!j%CUnZm;Z z;p$-Z_67bAfg_)FFI&rM<0_KeVmUUEO-2@`+DR_b|H9Fl|C-XXD3OS7 zKmR-<=RW@%MQ1=bY7*aFS~4|nzG>nla#DJ%OH&@_|!{4Hdt~Eij=BH)irBm&`)D$ zSMNG~xMTB2a*)vb>+lcLtrX7lw8VNboSZ=fMX!|$#+N=>;#&%gs*ztP)V_~x8L(Xq zZlq?1z<%IC_ehb$$=`XU{8PINe1;X?eaU$mu{^Tzv#q(t5hNt}2L5%vu)%pCwlSn8 z)w}FG_idlJ+oihlvzl%B8Hz~#2ZoIXX2!y(0cOGSdhQ0y>}Xm|FZ~d5qYZog z>92oyQs7yxYrT#We(i1D%4~R z(ZJ(~;{3Qz8@K!^kQvGv=?%%u=EbQgf+~9n@RF;^hb+1syF^i^bWupZ{bu}CeVmyo z-=rJrLv-FJ@wKH`;k)MHHaI?hgy8gT;7?lBH=YHR^&gNGr|djI{pKY+Ja{P8&POYJ z$>ozSA=PFlDyvn|rvzV$-t{kP#}r_-E4#EdI=Ey-N`9Oee^Yut|$4HVV&4`dJFf~$ZI~_F)NMAG8$TS>ufvXP1*?+g}(>3=}}LgcjXq&s}9NOva&KnY3S$Ew{A1>!WIKGJ`)mq z0rQJu(QEQ+G{=m(R12ps>`!T;fKVkhSMaG1;er!KwCCs9L4bxq~yFo`rpJ?hHE*if=74bT(7U zF^-kM+N1%;=$*-J3=^3>F|4>}GyUbvQbRHWDnt$3s3g3`m7JAhQMXJ)1 zXW%oc6@-gu9_2axlI+@pf$6P}; zIvX^uz2{Hl=+fd6oE#HJ`)wQg{dnFy5W<_1-Qr!GmJ=F_g-B0~tp}RhunJ}b`aGr_ zLK6Z_Fco>6S?ZsyB;8D^iZ&!JU0*i#LHES9J5SnC>{W@*L6wl}xJ5bOv2pR-v#a>!Y;DBt7R6@Jg9X0D2)9LtmfmJ%FSL`H zJy($3w?x)2h}-ALB#|HOyO{lZT__qbYww$I=%omZ26=U(Bi^|$Lf}@aXYZPmXGV*3 zfK09m|D^flb?VML3-QU+Jf9TCR{0$S!EpBE3v<`!Qzs84;eGYbV19gvj5080?n%jAB)v-uo+mL# zJcu|W6VA{!1`Bhhd&To6yPn;=?XaKRmKn8k93=8ZV9Upe<=o=Fl6@bz6I$cvCT+h> z>?nK(glA`EP#V}=>ue(KKgU0x`&!f5Xf?n&h721H{E?T z*^o?h>i$etSY|J%8&!SUsm+XhA9h+zb)zDuCMo_n`3k-62C=SM=7zjt&JVU`!y|y& z2B@m#5J|$xO}|jlk3C?|-W@v-&*Yx7_7A`MBa{2!S>}xJCRp3S44Ze#OH0@JhSR!V zy}TjM5`yl^LvfXQMQry(Ssjr+x|GW>^4fWqE|e3s4L59Td&_NBHPAfqe7b=t)ZT$9 zHsP3ev!7_lYG|ai%gD^*5#0^TL190#5~?Vg6JNdMN9j{3$0%=|T$#X& zzffgX#cQxn?Tmbs+kQykO&z*pG(BP{jORtOGQ4d`1{ta8Yt18m_^i>SckxiTdf&dB z1txpx_x_01@Phb6_Yi`9gic7X$cJ4;J1uYM8-|#H9lzoZEy90Bc$HGoyXXr@mEJsinp??9_4UhT;PV+~tZjg>R5-e^|=IoFa5usc(R@Xg(Ju1oz4|ZqerhG%{b96Hl z>QLm{w)Kq1PxvU0b8j*<VY#!*}E*&8m%b z`6jyAaMz=f{LVDtwm~NH1f_@~U_Q?vE@S0?tm8DT^G5k4ak8hOrNf@W?n!|UY%loz zr@DLF4@sX4_^7nZK_i&PMT9-|9xu2)Jb)MrqI6&e*1QP`v5Z_yIjF5k&ypaAEsxRE z@9Z&$f5Z@F9{bmpeU^FrflXy|E!~SP1N0pv9XDr~V8|n!*;jid$=0&xxUG49$xucT ztt4D_%WDG(`7oDCN*TfTp5q%6Q#@1dNC|R-WrJHbTow&yres;G;3h@Q6Ji&2HDfZI5^?-R@@SS1B4p!TFAe7 zNYLlq$G$D~v#^~v;bygE94YbMN-#lLOJ;DG#9&iHb69O`={c|ER;*x$;YX{QbTrhi z8)Qn!gF0a8@=Hw|#~Ug^qU^pCucWyFRS$iy@q@YNZ^Z)Vc{Iey6xaBGWsyPTuMR zw%t0d7Ag)a7??xt)i9gb3&UU$b;E}T>Xa-CRhV*zBZF}no1r(ObCyp)I7cGVjQs@A zQQUsd_bi#Z1SLq&eMhUVA7^;FRvF|Wb@)F`aw|#>nP%YL(z0w!?4|9?&joBBo)N=e z;)NT?{77*dA)}c6*!939vOHBb6Egd%YB|{^7`=2;8;N%GRC-SpPwl&pG_K3*;BT34 zH^76lE^-OIb#3ucdq%S|>6r0LYZ)ND0JoynU45KWGHJ(hyc~=poZZs{HupHU$sb>5 z)dR;yvML{cNM4zrYf;_{lnE|clPtC3jhN*GH6h6lQ6a^W53zGa%F8cJcjub*8H4OC zI`7(-3G5@=y*r2!P2M+;y$+mfMbK&ptBnW3%{shvZP(QgL5Y=#`6xk2Y09JA7boms0}SDkM5lR9yJ3`ygk_| ztvBXvbur4CH*>;vOcB#5>JOe&^UAOCq$YKIHosM}?Cw3_O8CcR4NMeJno? zPW~!3Ji@!|$ZOZ1ZNV~}DF-kFm>9`RDaQ>f2tC14ZTeC^vZYn3tA@qB@sodJ*p$la z-WHX>1F%idbUtONOa)dcJWKJugDUWZ%XQHbszt`f-L2AehN#XQk}#{ zc;b~DD!Swsg<_ym?*&b4J?XrxIK^s3J_;w;X%&gE?52GV{GbiEQ9mSwgTyi4IJ>4TkD7OjY-gP44|u6sHvx3CjiuFeT$LvCWY!+Db)6ugm) z1_I|(rZ8Qq-h#5mXY*UwbeWzq%~U}~7j&Uwk$lazF23qL3w30VCmkQ7`Y~z8$Y9pE zr0Z$-n8)50X0b#9(U`Splo`^=C>EDZK`~?8d zbQ-$y;TgEikXGDWe}Lt7RLfP=|l4lo!))uGlpEXIDiq|_BJN0jr6aS^~Vlvt9{GtiP1v>wq+$Ql(ICpHKD_&DmGZCPi)!5kFhJpXkt^Z8+pBI5RZH4cB zfHZZh+a*u$-Db!#VKm;O7I4Un-*)Jo{QKMilK%?rvr=y%CAZW!{08J<53y>27e@eP zHw>mLY(HD??JIu(lww|QApZ}42h7l}t56aewra-ONKje`00Z z)J4=vG-zS`UA!zpC8pCK&Aw`0907I5J-Lj!(lM&tFpl(g%=f=j$N@6B z{vAU^c=ChQV-c@UvfP}pf`pg=mzm~FP zS`!EB+^Pd;l4;FKlyB^LBpuaIa~QP+SFaecT62v0=V--6) zJ7w=+mHx9@&tV;hp4yWzLIFo528)~S?fVua14hf-9=@YEIv}x#Jq`rt;7d0&$BVoC zcy*+8WT4+`%m2``prk)u;burkNDWg5r1{Io7xQ8@rKN{e$b^`}T95Y*J;gm7(P0i) z@a+k@6`{q|KYgQLWz=6v9w@q{T?CzsXztNkCwEqOpC873BIl=SqfLsJ_MaUn)Tt`! z|KF9&4Sc|9t9$wEJZ78lcgnxIom7k}(j3{bZ4{TQI(RAOai-I1&>KR!Nwy3N(C z_dJcLWw=MmG7YHzvJAk)>sApn3iXapYKf+kc>rZnUe6W3v^)(B4RuzqQcQ~h>U!lH zKlb5cx6sLBuE^%-bvJ8p`6AEWlX}RC{4U7@D}c)G9=lhR87(ILD2{icNJEwfskPal13P(CWET`T_|@WTXfRO*=GN!4jE?>%Z4X0OBj)HjblS9u69}p> z@K}yFN32OpzfpZP{77idZ>l3dF~`ErK9|{ibDEsuM$^pi)B(wWmWZR*d{_`9=0WV zga1i8Kc{is2M+5HVx~5Lx?6yZVP9W`gBRV4!Hnv(ef(R}5~p|z2=DeX{WOXM(qRNQ z#x(w7lm6k{V!GPVOS4FiQuRSH&YsK}DsWCb8fCKWZPV*4A7LGxOHj6-&(?4}^d9gO znf2BKiIu9;1t2TF_skf-60GtpzWqp4w_UvyG4*l!b#bypwSKHLPG#Id9fz8MQ^|>- z7~WkA2P2BI199DVT?{qLgs@V8hBS-Z7ZrT&)grf1M4#6E198Vt2=CU}&mOkAZHZ61 z&EXzqW~;h~br~EagpKS6@rk6c=F4}B1z=GxSNKqlJhSSL*u2Dvz;jSi81~Nq0WS`z zb05Bi{u~jVT*cG`;4}bznK)3(AHl!>SWf?H+9*=~7(SXjvso>oGAcX!DW^ijd?YoEjC-s{|4)q|mEVRS5e zV#JVq9PY$oHJD5$hhEUL3A(heX736Qn1X7ECNsB-|e^DVaNR}l^*fzeil092>2Jv*KD?SCOdXKvVGR=Og$AI z9&Yln70dq6>XT6&^Uvj%Se9Q6*q+NFxI8BgS*w6GX;8+JJhIdqF~%||cDGM|CxDIID9g*U zz)^LwNE{PKY?r0D0D0t=o%>{~bc;w^XNvRuS$_LjBt;b?9l`_H6KMw!iA3|vO5VIA zS~=Rib?1RiySN3xcF*nyU98r3A55VT0*|@A*+Wz&3t3d2OK*la3iPOzUG@l6{OYm` z2)q_c+%(!3j5yZwM|8BED>Jow-Ah2Gw>6SN>WcNHN=7rEFB1g;E6IbAPLfA+a|<3~ zmeVbz7m?A0qm6DusftwWQL|`62+g6MF#5kO{lUa&Z-mGaNhqBu)m(5wJ1m5Da{%+{VP41xV4r)$Nx6Zy8T9yPQ*g+`@XfYG30=%_s1?aH}z^ zDagf0(X(yP?x#mHc(EV35(B{sh>7QET=ymnafiGWJqIm+(C8{@g?#F^W<516uX76~ z)(&L@Jt<(CR|^cvPLnaAi7ev~joyj;lB|@}e4Dya!kNU%IRqN3L!6a{)1@UkZ@`bY4;*9`xgJF#f?_)g3*xglCBq(CA zA;|F)h&+g8srn&DXtg=40@WIII3X})mL1`AoLNCe z1@=vMFDVR*+V<=@o}mISPlx*V=EK&jREkV9&SB<8(+Omgr>*Af0acwLJer)TNS3J% zwX4dGb-B8QtT48ewx!jgfH}c4>W(Wqtq2qSYK1J^ezmWaCI;_tr#yHrIg|EA@NNBH z`pPbm@)?(}4W2`2cJ&lEn~3QwsWeCr4+i9}2gvWwvC2%qj^lo6^$qFrdUTp6^I47M ze#g49QIdhextLY122|DyAKjC^)fIVmaKOyVH)V9VewxZ*1-aFKx>ypi!b|F*X%wv2 z;wnayK#;Suf?ZXsE4G|b++{8tX}K3qZMnB1Gp?2Ep(M(G!^i;2F(Y-x{$dW=>GM>d z$sBc;D*lQqENl>>n*L&)VI8IR(f%Osgq*XOG!~Zc1!Mv+fKL4uf0JY4c(vCflXMjG49RbK?|B%eeK*5ADp1QNXC?*!>j zT(}Wx*#9Z(e@-Q?09u~`LG|MjiFo=ZL?gHC9w}~{FelULnf)f|+;$I&GqOnq3BIM> zg@$A+ByAyg|8haeLh!T^wPt)_z798QI#x;5`L%i5(rfij85-k@7JQWT4*j5xuk z%V1BTR!&(u*m93~L~TKL70cm;gNU$R8&8lqkP?MfA^3HDPDZwHP#i+&4aK@=ci8J4 zSRD15yjHX2j0yN&q_8pkTb+SV>LD!x+^2NAqoH4%iuD$!(xy*7+`bh#zfIC3sz7J-= z$rZ3vU*X{tE;Ss`;h?HSZeP*0pwiw|`kdX7Ix`q`+P0I{;rObPJYm-(?DCl^W1h}3 zWBKh?Jsr5C`Dpe`b`!*vuUXodvZ8sOT5Oaci~@sYI`lDOb4ZU<-3xq~9J!}130tV1 zr(sqK^&=$LejFVTutbpNy3f982MF)4d#gkny9L6jk}&o+@O0$2wi2D zdrJKPAsjwNZ8&VVAV1P!Sl>v9(iyym+cbFQ0>jXx*%FQEB%80lE6Ve4Y%BGq0V+*08$g!=&xRHi(_6A zUdUIP6RvU|-^88XdjKkF&z>hJ-s3t}Z)r%o1a%!24TLQFh;9Id8lNc9>xM<2kx|q1 zu?B{HMt}xTW(Yi+HSy{-3MUxn9Q&c{^KKXBFb-{nB)4qu{cU3lbP5z>&(yw7*uivj z+VPtw`gZq_HxUWZ9eddj$qBK*OHhYq2MR8JwIts1y_fJRL%S>dY$?#ox`h~yzODkW zPjk;{swCvzZbem{Qr_Ff)WYv47U?)8Gz;I>xxO}wN922p2+ahRfFnPBT8%zo$hbPr zJz_f5gLwLU^L|$qtDOCEscFyG=)Qd^0#WCKtL|51$%mher9Fjg#?&k0zf|v-xz&qbQW$*Ctg+oofJB+0M+n`dA8dkw`nY zDbBivgeKK03TemmyYBTm{=&DiywCUcu!KF_Y9^?z{Mpc}rGD*_SGGx}&ANDyrS#X; z0n+ znkebSERSr@=6@WQKWAo`)IY@sOBiK}yOo+;?Hf+OzDKS*4}0-#isA`o1TqRp26 zH0cSSFkjmX*=*0TMds&t0(CRA|MC(4HPoX1DZIr;5C~(s`=ZU8_2ALbQRwRGYHCVK zibh{DcWzCBPGO%t+3>rcTCRVaQw04$b$MmbCVCBaH%E)~Cf(hwXZD#AwXYw@)Q$zp)q_3CKJiqASpO?qN*KdOW>)yYu0!-F- zzb^V;7r|?3lSLyNM=#Z8iTi!JZ{iG--Nf5|W6jya{M!ctvWFhyhY9zyd2r`-gv6|B zKi1B;W*PMwvnKoHZ*u25k$;z<>hfx99=hn!*0)S2Ak{@_Wv0mis$o)D1 z!}!4SCN1+N-wwg_(C1mMB6cVN0xFUBMfp>1ST2#phrdn|sXK<%g?%9=m6H4`RXCSX+u3BRo)*=m%7xj_2Z6thL5Wv`FM?` z-$GI<=GHomVji0v8HI&8JGkLvj~;)(qtjP)5HC+MXcMC?!OJH#0%^*|GZFx z0^LW`Jfzy5KWX@ho+f(ke2JT|#@((`UxY|?|EoUIB zY*utf_rE<*uF0(!5!>jo_rhQmmb|p@eJ3T@_4AAcB!ayN^5fgL4J<%Vy+1acXH_fx zZpb7u0B34fecG&29F4R~hJ&twGT>aSCE@a&yQbw`b2LYp;%R7UMZUwu@6tz{?rXAGd$TG;r!u6HnRWQ z^!QjPd?p6j1^&&JB5cN7B-ecrIG)U5xm<+v1R zqMjIT^Y^?uqfYDBM5Satk)05bj!~OH4_R42f|f&H?q8>v9!WekSMH8U#SEf!9e>yw zL?G@6P?52_1J4_!1R)QmR(n(V^Qhet1l5qkhTknuW%WtSf~bfG@)wt*U!yk zMY~cQyJ1x{&C^s3NU=h;1uy7lCXxG!8cyif->vkkR6k7D3Y^r&-(=?69Nq@ZVL(=L z;g`SvY_z+fE{I@B6&-`Pt2gQ#Ipk{=auJRp9n!gxcOuU=s+L(&! zI;ub?{1_Ysky2~XP*~qaTc$7IHj_{STyv)Yf9T3YA7UoqFJnPUfsxisMX_VU%0T0< zN7M=WSyf(6(e_TO=8IkR!bh`Lc8R{fd|5ysun5ptTI4_Re@R%q93u}sB0Ub{BAE5hyVY%~5>{O%OcN=U$4M5d41Ru9l!r!8rdF46yvijsNB1-W1jfx2 zQ$X6va@yz;h`fNGpCuCQ<-i_AGWK!X%#{HYbU}>=pX_Z|T1-8fZ;>pcmimKf6{@iY zqYEGrE6%QSBg4baM-^jwbrGHv&44d0?C&E}0yCZ=$eMD;@D}WeDAxkZ%@)zZXbT`8 z4^7;r?PIV`W|chIAMb1gdhDlI|Ij|1nt>oL2ZF?$DJ<(LD3y~4SrSW-ycc-XFQ$&` zqNF~017{RvRJ&}A4!cbOi!YUl;D?TWedVO&z_}K<_b5oIG5_UK4clK@PQnIzu_&DfNEh`a#-qQKVL}!Pl*cQq$I3|C^_v|oA3%3DAF*xl&7YE0 zqWt!YXtvFeM&VSj!^4HvAQWjU+zPk1BUFHNKN}n2%HzMUyaeJij5MuDEoGepPCHZ? z5+Q&@mZI(q^ zSL_hDk~vmdgoM2%nRmkziaqJ!C;!A-1qKub-oi{Hw?@bv&7TWu4$={%8%`EeuC}Q;BaXwv1G%wIg z{ZVb%)FgPHw0pir&yMW)yX5i^v-kawG;J-L#yhes((`LTdbk_q$4%&>^#p|%GjLwl zJWK?2YhktuI1C!LIqN@3;Ug$*PTW(p-+44PR-j#0;!c6=wf8;h1`dMrW88tP=p0pmI_!oUnk1|lm2bB{xw$+E-%$jz9!sAYHKHJM?=~1H!hntyw z(~-5mjc9x?CPn>5)>l|NvPS{Q&!L41JHdlh+8a;2q)bo`f^|cJftitR9&FQw!np~d zS5J{{QM=!_fHP-Rk+n;D%4u$Q*TfP~&o53v@Uo0vb$%(eSs>&k{zA~TbgyAu756YV zDcU#P>5U!Hb1dRh=Ha!;ji0$i3YSc4KffF)!h7kHV-3L_$0YQM;J?hj1d1qc;-L*D zxNr}k!OM_1?M>!3zuKNCs z$B#19*HpVn|AR9Jcs3ygdakL)gX}|k*No8JN3(^bW2xHq!ceDzT->ucsWj3~MuP$+ z13?U_`sB+eQ@7zWH6~p#j4#8tFf4n8$4N)~GYcmo%)6aCX@lAv^a2lmxC}3Ndiwe+ z)8Uf8qWw1)fTLc-;rh99rOm`UeM4Qw!F|N!SYu_v$X@0$;`ZhdT0+jQ<#>OFpp#ju zBbah$`+-VT?s(esv`WuJ>36^EmNP-v!`ry7sQK@9KX%a1V6z)9u{(1xq{R!3V3dl& z3TA@#!+EO7BQrhi?#qxYpim3bRcYmNh1A!hUno-99DX(k5TkzISu#9eb|FozOQ!XG zf1J^ZS_iTtRJxOh~Ikl>A9-;6pBP`{+1^QKXGmk5CiOt;?_SF9J?lM6*$5uBcATRjcfOWPA z+W`5gHH!R0bL~cPD}GOby><|1_03iu>PO^32f`^5wwQc9^?PYD-92P=a^dCtMCRNJ z&{DC-mh{S%1g66J7fQvV6jzGNRiynZ^~^Jz*|Stkk$P)0m!cHPA8?Ibk*C3@jzfK) z0=#KfVVF%$cE%ts^|S()gva6YWAyduACjD6QdVDU#z zT8&{zkTIV(Kf;wb*Pk-_7Z=sw#$5pGyYb0@@EQ;`=xkT%3*T@z^DxGMTCl7gYPpEj zRy;7SY2~25(!y;yARU*g<0|E(Kk_eb>$TZEvLW%f3Or#yv~!`lHP>TkLeOk5`_X@< zMxk(fs^{riQA0#4>TTQ;eGC+2nKyEWb*jpKt{3KTM}I$E@^J%Sv79-pwCmMJ8?ucY zJ=2-)c;=%Q$KD@&L{}^j25$)Oq7w4P*%E+cMa#Ff&Xy$`zl^?t-}Q^r;2Cn#b41}7 zAX!@nydHqNm!{6EHLij@2ol-N%1|aPN+vb$Pru9K&BAyfai^d4WxvS4gF7*$-RR1y zbBXpy7w2FKXI3p$D_y(U6I9J0dGQHBy@PZ&gjW~XEpY}KEc(G)$z<)+L!@p8y#I)% zZ0h{IhaDy^qr!rZM9)%$upPQfx7WP=BY%=Zz4Q7Zx8ktpHH6WpuvVVPesP_%x?eV9 zd7@~%i0HCODccYRl{$gREv?I zlM>P}>Sf2xB@QbP?7|4QRb-Z;)tRpwF*fH7_?*Hh+gG!NeROk>AVM!9YL>c?9nx4V z!mAO|6?Mfg|fOn3AJ z_ONvd43Pb6>@AI5aB9^K<%82V;(<%x zvvAALbaGL%BOZ36bo)`8nvgfhH6A@%HtOXIWwTsO!&iFm`}Iq};^lq%+7$-6v!CW% z)=73i;P%ZZT5lI*muXLe&-;-(IH@B2k9}w5`@+wUSWvMm{O;mjjxBB-gp4RTA6`RL z)QU_n=*iakv-8_AS6n^b%}C1a9tD>my2!c-5c3tu!uhR)^MUa(cay89mBvwfD~GZI zm?wB`Jzgu+1|B&6Vojdu;<=Nb4p73gBUe;=l|_@xH${JO$*e+~e5su%@+u4+rkcDG zJGc#cNrK4T(~bv$Ksks0lRiI)8JHihn;)#(?X+R7A5jGLjtlDm6D%YNzhAQF`ndMk z%v_V>XZ^?I9Y6{w@0ayaueg7rMQFEp$3C13fr(MKI;KJ{yEQv9zEb7aXje8)3wL+L z5_ql%hzAzSWO={##)DpPpGT2e+Ohx;=GsRBpLMAq)vpUc2B5yWorXXpK+;Rc^pi6X z2oCi}o0&n6cKPM_KS}i)ZzuZZ6)qh1uxH5DGG?|CCkQB00DGT)Rp^Y!t|;N-^NaIZ zcF=iG^2V-1JxKI@@;1&F4<juCWub@|gbj6n zHhSD%lWZ1sb-E_qBs-lllu86{srd!383@9#8f}VbKACpvzobN;CVrTSZ(4j2f=A9L z(saYU2(q#vmEO=D>N&ik7@#LfTdM0RUo3QRBzCYqm>tB4m<;z%e7KE|Uc%GS(zL2| z$&cG_UB-^N3?NlU7>Y;JHBN5vWQjSB!bQfN`0e9V-B`niZ7&l+=Oco8BvW{C#!UJ& z_M38^PrMeli)L3274*}&&HIY!A_TGwN4~$Vlefo>yHk|$i;H7Rm^UHQc4Tn|B;o3J z`<+zKP(xt@5GAmXOA!I_h?)~DmA@$DLRaDKq#fD5?>ZxJ>U>(H{K#>ExBZj^TLXg@ z_-qGiNL9F7(n{0+skk!LkaTP&V$SZ>>1Z+AVUO1=Aa}ej*`pG5u}V zUxrL&2>`=r3LW8I_r>|~9DuknrfVZ-WbEjLVnD-Fj~i6)1aDYKNB^~3y$1BsfK7Y` z9lz9H8|XiGUwJaXCjMmn`>5Ps%k`fK(*JbJwQ=^e!QGu45$r6}+A&BodWS0II1S=VLc_15&!b(pn9x~lsZi}S~&iU;r!@#a>cfBypqHqP(`-C}R~gx#>8 z^~1m&^Z4Iz6<`d2M_*(0z*f7EbVOc9M~A?FMP-zKX>&nT*`6#;Twqx(J*@G!j+<`K zs+3{EDczp^U3GJpyD+n{g8Zda%mypsn&aCU(Z4;@U+mGq zfXsQ4B0u(i&Wf}hS=!9d&^s-JVt~gqj~4GZH7HS@Uno-Y*OB}s82f*5nW>MnJmW6L zH7-kwOpt<91}6UkqyeZYemK@kc`bY#AOr$zc$I)GP_h!oB`7a&+`$HZs6GKGR@1o9 z!10%_!6fpBiEUiJ>2a`xSy70ChLh8guyh242L`lqEryDar}!7m5d}5}sAeVO<%3~z zyXw!j53b(dVY67+D@c>f@6fXXV^a7ND+w4r`rt_}1VG3ChNqV~u`zzxV>HdvtCW=~ zk&fY!j>TG58fTH)*E_yKS~Wa$`sp{(^fixaQ~et}NpZCk62s^eRu#R?LdR%Kr|BlfnQ@7|Ur( z#|`J$PXb_Dc|r7dv=>+78vms|`m3yZFMVFa3#UN^DwnwXrNbht*;oHlY2^*n$)mJI!=ijw31 zD0HShwuQkdp1D)Bgd$NAaB7Ia?W+eoggeiKCr4UJ9dfR05uAN`V*qM4ou`^Dea~Na z^npL*Y71gF2@r4JvFs6F`PwB6fX`E}ba;!)|LS)S2X_a-!kl8v{LM6Tu7!qUO9|1c5?s|Z!fxg8qNvtwTExo1sZBR52I1owr{R&?KRmKf6i`@Wf5>B(gFOpbrs{Vw{Zrs znli9&g#S$Cvz_d^pyF4-e8~%c9ptYj-SclexoQ5|ZUWkN2mLhF;`=QY@`u~vy|_Jo z6gOO}ghvh(19l%Vkt?y8mK=wy0Z|x@Sk>W$#{CcMxJzd`P)E1tc6KGYO)Tq|fita5 zyTS9_eheHoqNAS5;fN0M4ity1thbR17&;6UFGR^R8Fpqk9e!83t zzdCUTknSD2#Fr`sx@0HgRM)6h5GON8ASIchJSoZE8A`+b7Rb+AM9yT_pg=&l6PEDCIT781>5F6OTY;u z)R%xeUbX|Iol?l_u~Ue7p9yuBGa=+>GOji znc%y^tl!0QNfp6I`a;`$z%|=#XR;z#X3=tVwu1Q~kIGm{dGEm&5Bd|bkh!v9Cmd5P zg}0~c@?Q5k@&4_4Sf%^*+l_h?zX4X?YtWsg!`J{EaP#;9ZoMTZJceq^@f=Z~mo5k5B;P)R=IIH%~yx%P`EEXE2eQuZMbB8U!Wv2S?vl@0Rt*wyTQ>Ug?h zQdgj@>B9gg=GsVP{#cjH|EMk*Ky8FPILd(0rCC? zH`4dTbbhHg8f|6aO0b;WsjBZ)p1J5ovv(C ze}LY#Cz(20IKgx8?I@BT0}DmA*WWI?(V3nbtzpP9y2xI-=JpL+zOtXJxcu66 zFuVf(^1rBi>!`SwrEPQ*0)!wzlHeX-kl^kFhu|`}ySr;}hu|)Q1`8G(65QQ_1{qv} zhrzxd+s;1ctoyBRt-J1h@BMF9!gTj^byZi@^HjALkF;MuTC(YFHdzkI$y!H-;KTJ; z=-=6i0G>Ar-gPDDWu{4wckw~SSFhEZm0`XPG>U@_T)|Kb7zb)zi@IOjMKnF@&<#&A z8l&$?B#HNr0Ho9Y^EhRB{tNR~flSrpv;ZHteL?D@tn$@9N3_Mh&-YZb5|~$H>%Cz_ zSR3iL4En2~3KTHB6}MV%LUv5w*FzS?S*{C^t5rWg0b6LV>!1()jiC7aMdAbXfn5fi9`JxrY|9G6*z0ps*t+n zlCO4*efNnzIWDA!p#zMZqzv-uRo+lKJGrcgZpWz)R}FeSuC|GMvUs-oYCbIcNYj-wM&#iK($*IH4Q-5f{7~E(CVw$t^n=gVhw7e$Y`73tT7KO}`LezRx69)V zU+;Ipnp*_D^_4^)kMq>N4tX=bsFuk24%Fi+lMw6;SWmg$u;Z)R@`u>8-D^Ja?AS1N z2A$?}rcPbSOqp?(+k4D<>+dy%2o#<;C#NO=*3%O5>w(<|c5YTf@(}XE`v-g)^TTsZ zK9{}e)gK)#Z84074rGB(2yYNH0*HkAHd#pVKmVD3fVRLY~3OiCu)%1s@rvc zNN*?A(nZnYxl|e6jq1K|#9!W?YGQiRF;wocxN&sIdX!et@!^&sUq`7ZhWe%Y++X2> z0`=1c;^6XxX7%6A&N9{4nmjqK$EpV=RFeO+(UCZuL3@&(y`WaNPZ~R6s zuO?7WvsDkA{t7sSd@zA1u6Vi%hPM9J zQMdz8@_Ks|yk4V`d9T>$hJ5pIYHDQ8WNbO85yS0zfpzhTLg&s{@{9 zDX|GAuP;7d_O<6^u$V~iKbDcU%WhsM2$;`uD}71B;}7HV@V;@M%;|I_L_D&0m6hm{ zbfO=EcjZ&#&rDk_eG~V6^`SFNTbF^^bPybW{C4w-=Oz5jEIHu`N6mf4FfNX-hSJg7 zpBf<(IT8zJ1~s}Z03>0%1@C+nzx90ZL`mQ!XS8Ta>%-kK(CI4SCvWEIk|;k*;A%3- zBEK!Tk#BHSG(;xb+}%F|VSDn6&F(9~X~wcCDZiK3+3NqwS?0C_UgR9uOOpV&(=wi> ziV=#94+Fg-%f1uUMrT2cg6z8VwF4doa4RG}TeE&<{^)8{P+`*RuCvY6PstTmF};8eTpPvb2y$#&-AT;!C{qe4&S} zNLg+b*uK<@QpIT(h{;F?shGr4njZ2VNJGUf(qRNo7Ckm^@H#j550s_5)*6zU8R;&p z^z1^;UN2DAZW75qPeh)xVKgn*TDfY!dQ07u^YOUFJhnEx^-Zi(!WegX@uBZ~AD)E( z`^TN2C(Giy6!`F~ue#O$u#NEEBJ{lQOY!T==eePOMLg{CxwB{oliv*cekUj>F z7*%S2X8b@~I&t}fCfr5dL6bqqh%9q2bEaW#@@O;1Iw$!tcS8quE7&<|=t~_oj!n;3 zD^_yk#+W+a{u;Knm|q73@0R!k+CFzByqfIysC1`qHNqj0Bj`G?YY(~?=EK2y*r&(A z=F<~cjS;@Vn&icM(9NRuDED=X(w`)f*7U-CAPT-dlonW-?Tu=^DxtVM(vJ1L(0M{TUf;|Dxt(IA5Y};@I;m_XkPE-<92NtwO(5o(vH6!?rEeyDJU5l=~RfxXv0D_0zd)I;tFs1NzqA>@HJwhj0eLV zRO{?8V67F|Xj>{O3v9d8$Q&E7x`JoA^1Ww=7d3F#{j!2o&Xfct<4^UFWG zZ(kaPz!J}-PTvz`HQFvWgQw6vM0sOJAIjZdWL|V$H0pTpwML^LZ~ENWXeaoN_sFKe zTP)^l|IHOIfqT+}q-U91;`N#tUe9~ffa%&6vGLeI-0(S~n;0?O5^Hh$@}Mj{+vQ`D zq;b)%qpir!U*%(_Hmy|cmBoyR*U!|Sno)VYdCXXlD;-<|kK2}M_MfA+D@Fo2_7LVl z--YWogWKXfnbe+9qg5}iTPhY_dF-k!;*-%;bd+CD2~#b&WZp_O6OkJIb2{uBLljsBF&dF2~J8#7DL=_}TC=Ju=k zzDr#OaX}CMo|xOVS-hQ#^I-nb7Ut#wYCQ!%l$)F%Mcq2|Wn0b4NU2pH#$?UOp&enJ znX=c(8-7|%AFA!}_gq^-P@wAKncnk9>`N-#4R`o6@wdSHWL&Q~ey51_cx&);lK#!Q znvYARZ2}eHpP{BvKiL>)w44K)TVvbgu%13Vi*p* zGg7SELy)&x+_B_(rvE6Jw}8ql)N3tkkU6NvhAO)7SI)rc9gdFkg#1R|<;zc}dx`NE ztu0wsEi%ilmr$9VDFcVs*9;;QVP|Z$`$T$TjL~r#-h;o`Z|^@g`Z=DBaLR8P*`A$v zWwVfcIGxk8lYmI>J0(!d>#E>)Jm0^mfOq*mj24MhGRL}^!!ZImTU|RIPEMg23#i-2 z$X0X5?}B+w-aoat_iGLGePfgHqTJ@2AMMc8i66yb?bEy5_wAm4I|WFOx#mjvOE1+t zVmtf;)dBdQaYJxIWrm5Kma({zxPoA#TkGCm>A?=}Jgo6nOdmDX$A;}pjqD7$Q@-z; z6smvEA<#on_YH+=Nl}DcYJPDu6oOWtGXF9YKhv7ib{e7ZMy+@YTd21JpQc{SSZ^+G zIt_5LezOY8kVsD0Ry)m<;r1QzY#>Cual*ZDLiT2B&b+woa9T+k^_skn1Do2d4xZ{y zuk{s5P))KnEQZT%(Q zG+U*gch^Jve&1YV#y|D%RNdVpom1~5qv`3J@tmhj5v~Tt{56iy!7=?Gy|}(`h?8%U zWpVY-H1xWMPnU7~(}d-(e1pCv&1E$8QT( zYfoZ^CwX(<4boNJa>TX?_HGS@r!Ypw8u^e76@T{)qmI~mBt0DdvL_6=b;W)7;G^~I z%-zCMqnJoD4cYI*?S0H0bVc@#I}X+K4EF%+H9>KaGzwj*Fyd3xV>MZ+)ka5FFA&kTGnI`Y9)R!e~9Ht-;}8!miT z2F%o-)88#$Vzx@puU{C6i0vu7l}}Tw-(ix1S1Zsc%a?GMeGGVO z)Tc>f#_?qES}{9hh_S=_<#lW!dP{SL?%*i>FS3HBNS=a~w4TFcNNY47IzK+VFDl|e zvYqz^LE6BP6TG9JOYTT-*Dod9J2L2v*TS|;7M=QlD;iF=8g8w{R8ip98n~iGp6%_w z*`yZ|j|@I5Wve%E$b_T;!{*rR$8WCY>&Irdh*pW4F5Sm2KuS0P%%n#1TN7s`i$_93 z*{BP4&$>$(ZX`V#P$q`_Z_41Ui}bZS0<4oASbvx;kJ$R{x+cl-rbHja{%tQ&v7UI) zD^UN5U}!zL{=kWNX;t#0n%<6ouLN>R>HM#JaS0ck*=M?#>8HP^t#dn&e`eqO1fGu` z+q^piDY-135vwy2+J8!E_m7F50~3{fm=XPBB0=Pzug+K(_j}uybWW8#wY*7I;ayU4Fj~A%1gnq~yBQMm^#xJcOxW3zgbf@2%wYZ`r z1pI{w%p<{(V6Gw&x;>gUkc9t3kMGeAB=#P7<$20a!M4Mfa^V0lbXZx5$U zJ@V}zH~|jqm%b%{bXA`q>=$*E?sDNdmD_+up0a{fZtcAYso|5A{YP5f_Zi!?yy_l= z3ZP2s%5$R8&d@$m*#--Yyi`IU|ICE{BPsrW_EAU-`6v5N@%u5JRmY!6X%QdUng5dc z8>U~+xN-@-ZET|fS|`?%R(XMNKQi2ZVIZ#c$p@~g|5_&y5K)a^A{^Oxi_=jveTLL>LGV7)*VK_F7Nf0k+AiHu!3vp7yOY{-ZQJW6Xh z+dyts9gzE%^#BCCgBOsVT`{1C0JP9`p@3YvfxOhbL;&n2FjWCk&aIUz!Np9EKl=T06)oaQsx@P*V5En>7>6L0SKl#2$W{kbW^JD zfvm=#3~^N2$7%RIPK|pzWx?Z`4-o==JR4AK%gYd9Pn`kTK+Y&U)~#p&=6Kn0Krk!^ zfG8LHdHf5pWwoSU_`MhA$@KU|HQou22ugp_p!xv-c}4)kvKPQp zEt7u-LV`2@qjX@02B^l!#$s&+;FQ{@m+W3TDuWsaAA)55{vD(N*^gRI!`uZ(ja^3n z5eez}uVIiMhZ$!n|9zNdR$!RX{~88Z%@Ok3E&x1bm&tvELJDjYS?u3b^$_S9TE`;0tbmum5a6hm8p9AoHPz`zj^FHSI-mgMm5l zU;Ld)dIVf^`yMS}HoKMD84xMAF*3okr)v}=62s}-uD$Sc2WX>uD@M=YDc=#TvhBPw z1VCTC9*Q{`uW1>6+Lf&J6#yM_LQsJOR-K9djONrYXSYk8B z=XTuGd!NmB4fn5pJIoS?$9IF`+xb>+<;}R54|b>B~l?F_(j{tQ~7U|K3FBc0eb&jhzpC8ezZ~kjm$=oLZB24$&#GC(=v=A`P<$o0)b)?{CNO2v@G0B&P6r{Azqql-&!tvOyzo` z3>NaG+@DsYT$ZGGo`VIM^#1kZfD0NZ^I8R-xqJKAA;?cDMT@zTK%Jre#|M-J(^{E5 zuyUD;_f#(UkTgYit;~J%51r~EnE%5S{9{MZQy*u~x!t5bll*mvq9sl$4`+xagb61{iK0vHy>%V;ASh4RyvvK($_*v^0@4;+( zMHIq+9+!Z0DuvpIz-Wi%pIOJ=X41gr37WPCS_V~pwX>=q07_s%etZM}n_cEd27u&| zVRl!SjYT|ClEtN^B{tWC`LVGK&ST_H4PIlkv!kzFN{0Zpiw#`Ud9uFA#-E07vAGEF zY5&@taf07#a8sEf4kzn9c7>-^VqK493&(;w!f*^>J1 zA1)~@8=yd~vT{oNYq&pFS0Vx&;J;k`zmMgkD*S)=D?$|n^A)64;hGLUv15e)_?drd zX9wjYMd|kXEL2~)st|vSjg76`*ryLDG28#v57@11h%!*gcAjGQhu!Lc1zi7wkd=sm zt68I~Tn2Cl%)foUR|I%2UGxMKr+~>f=4dh1vBi%f5%hiQ0(f?L(-pthNXY(PBN403 zc&NyDQQ{7tk^2uz4zzpxqaJ!>8fNwX6D4Dtb`Qqa)Y4k~^z}jf!L_iL&iLd%_c@mX zdAcs(?(W#{;RkRbeR(+5tv2l0dW^NfHXL2Vg_lL&h`D$;HYWoNh06c1C5WQMpE3Tn zx%!_Ux8^1x=hk>biaN_#fOTFuwar#k(Aw74*AqzdjnprdxB$V@oGf{YE=9TdlZ#2> z3#Hfyj>_=A@>;-MK*;nMZyf_&1PlOrLVH?z$7{5%ui5+n^txy|mfg1DZ*lI_?b&8A zu2t^1`}W&lZ`JQMRppDzzXe{L0BlxuB>SYdf-vB0l(#B80}&jzZk3icCL1Vb)ElMI z<0?Bgc$FOYNW-i-`9n#QY;=_W8LprO^sb0h-6M7UL?9F*AZBLlU`0n)BZ8 zmNdyiRr%jJq5pl4|9vX|+gtc=8T_{t|1$OeBY#_>_XI7eTywviOeEAApT)a>i%eD| zJ@lOZu!yX}#$?x`bwwqY)5Dgi#;d<9^uW9^ApLUuu&30C`?6s zcMd}B(DGc1&O$9Oy7`^bp5NC)b+pPt1UenT@m9~Tbu#Gu11)8r`9TsE^*aB!Z%h21 z@Uwon>VjM#h{SZ33%E#b#C0*J5L{um&bn3o;OK-GAtpMd$I$XrN_%e4^8=XE3}J9u zbuw_KW8G$&D9&XiX4zEJ1bvx7!fj!g=^xU#5YaamE1P69W(&Ds8y>O1T}YB`$w#P= zG>jH;Me{K1N0>ejAugKpl0(XN1B)H{q%})>e1?JBqnkx)+83*D-j@yK-9UHbGVuP) z?fj3(=>Pd6qe?xla6t%T2%I)?Z%OAdSsc8St0OYep$?G7mVAhu>^Lw&lAGK3_4PYi zQ7W-rU}^n+ZRO<}%zEydQkmvn2hF|$TfWctrfAm<%o|dftf#c^NQo+mwb8SsfHqlT zJNnaM&v7^9L+7OW3uB|E_VhWq&EWy^nN;kQ|hp%>U%#kPi5kFL3J>Bd1N(>*-kSi#{>?r+$ zm}3!jk5_|1;swPEQqt+B$Z8I(Xpt_3sFfw{@4>V-Kjp|qWG1{6Pkr$DgM7n|-Zim) zS`-WbDk;y5Wf^{QGZwy>-AG^~wqq-o12Fp^?2wFHR1Q+)X{Cn|m#bGh5BYeYjc=p2 zG{ks}y0IJ(Py3l>s_m^ob7zdfMjmXb5y`o5p*Gxkyw`c0PZXm@wue2~Y5B+5Wvf16AeInh!(>agcE~Hq4}2xOG8dlUp^$O3k^= zsHv5Rm8g4yyWjYOX}K$@nikwH4E61DX|hEx$3ICmEDsJdLZ5^g`?M7hJ{A>t34}e89L*>va?O^6jxb5s6~aCGf^g5m}MqZGU2h3G);6^h*im z1Qj(@)s}<}WwnAKPKq!MIfg=NYYrEFQU&=w2bjpHpkJ6H=Abev^JfyV3wO*@cZh)t z*8B^&D!d!G%_BJ3+}AgDD5A&0ei5g{uDu^5@@vQ6s~p8Uv|6pG?x$yl$K6b9fHqbe zAWZGgO|XW*_5m1RMnu<@Qk}pfAvcJKBJr3H_vBZ^PEzM4ku+>G2QbTG5}R*=uH3AL z3YFXQxxD%vb(N~xM3st9mAWw-=d~&Mu@KxjkMu3wbCEjY!t9GJzLmWSu?qP@WcQI0 zHpQuZnJ4v2ew=W$Ri;oXw>^jF=^spUHCaEi79Eb_<^v+cokCIQWu?x2Z{7|Mh3|NX zP|FR%JFo0OJ#gL`rZ@e8XY_`MjBy~vH=ya6GM`}v;t;(;XQEZBb7R(_bUN~4mYn2g z^pw_9b&tWMi*9*e#oON80-}fEFVNf(&%KX6G)`X-hA|%96L#BPx7HL>!cbRHHdT)+G`d}X=GJk;HrA(A^QW5?FE0( zM>{j{h$~$RcyH%qHtqdb!%fYyr*3n5Y<&A_N}sla0Il2MunYNIRAxrA(-KyBS0VaL zBh`y;D{Cuk1UaXp7_t+-M zH$wAR6~5Z|pBQy`yt9|bbYfX2PIhn;CGaKb7YP2mc7mP_4XQ8si$Jl{ncXM}9z?Gj z#DXD+9^8WoB0A$fe=3b13sIgRe7OPJ-{DAv6D`!ybC49^J|PNMYQX(Ooj(B5X8DRd zbRMa?cekrb++wU6)Y`?-HyNw2P{*5z?D~}< zXV(?HUXyUurXyi@ri@Ff~#=W_#L>dtuds`p)3B^lHDy+q-k- z#CENtd~97GhZQLSi&~0_(*6y!XKnUAGq!CY!yJjjG9!lV>rEGWPww>aqC9P0$4oQt zpDza;yf`%@97h=3M!vRmQ7&8RBsd+Q)me!vp0rywkaq+$AJCy+uI^p>YmYe*jdB_D zqz4#EluJa8CxH4qcDdq4?wT#@v_!EdP2X7E;?@YreFK>!g^-tX>Md`5-ohO+#W-Do97a71KD?$Hrd!C`vKRKQ5^4mF~j$iKuYQDUmVhXAQy^xF2vv- z1mMO9BtMy|URPQL=QrflgRVnXV=fP!e{AYl%z+6zNs+doAnNGP5qf(hmx}6g65JD+ z!G?9(tCdUx_nnk0Y>6D1;ih$rDA~JKRYHCd(oK|ysylP$0t*q+QzlL?Qrc6$WJG_I zhgn2bX(_<${F*EqwC0N{CJ`;l?8Al-NI4-asj{o6+fL)u3aEW`Mx7zMj1wC>0*ML6 z?8_)pw|=?jp@9mDx@wD~>@-)}=P%5$U`#L{6-`c##ZG~dQ=W6NL~L&`g9|?~W!3;_ zaV(#(tkeyrX$G7*y3?U*=!x3+&RtE_Ld6y3VarR{da8_|0Dc?ti12{Zo56Y~Py{am z^!B6EwcR-9g!}|+$r5vz+hRTS_JyT(g42=I0{mgRaQuQc?&U>O4gWq|{SFE`MM?Et z1J6kI2K`2C-A0Q-3^W|Hy%z<~TC@^EEX=I_Laa&LtxpxQtW<=P8>!fPEs>i!w62#} z7JQMCn|Zvh)Dczq8Z!SnLtzce4u3GUINj(6dB@xGAgIU=Q({dAZrdyV5H(0*eKEsD zSVe-v^z{y?4)5-X4~ofcsw?5o%0^PvmR#T|E=dyMV@>8Wop}s(kV{#mR~lNxjyix;>(H{WPAZ>?-5d2bTl%heQ-RX<&T*^ zaPP@~M$lo|wCRIN3wyWi-APA%Lf@C)oV*YIs~3QyOIOPX(STj&YoFbQcCQDjEW*Vm zyp;Ro_WGyG;T-jLwewx7Ez1!CyC+|eE_LnBRa-8abA3{U>SLR zOT^IiXU5*IHfbjb-YI!{d0kR>u+NYmzm*R=NV?tG!g${<26&B#%in1P(~A)_qg8D?!rEZ3=*i}74+KJfw`6=eZ$pq&ok^joo+lA z*58~{B{GGB8_&}|#~P$y+nC|#T2z%}%5>1nIqKle8~8o(q?7)29-2r&{V@~cW(p8T zHpKBN4<~QBtxmq?`&#FlzFqQ{x=k3y-{%;7cIQBMWZOx&tv$>Mz6q!N{+)*!Y$Sy? zM(>Mb-&iBAf6qy{76JABY+pik&5l;u?w0?R$@x0Ba#Ul+wjqDG3l!K#fI+(n`?O4} zvLql?l-{R3O4j7s{=$Sl-pVXytbRu-(Ls3DNtXvP>w}|!e9oB5ns=hpe9E|`3aWIZ zGh;X7T)MPgLc+aJo2fz_$D_w^S`uu+&i(Rk_+Be3J8pjwZztjsDoh_~<=$)Bw6&c& zc1_BI>(ZxMw*2wx{rPLa?Dw9xDE8v%iJeVQv7u!}ulN^1qMSAykLX4XY>01-^+sJn z^BpfxVxw&G9T_&7Gg+0Bb)ZiYPqYG819vnM9pu-GbZO3fN^t!?FW7J<#Z`%gLh{R{ zICpcRbU(0EKCgm1gmr$EBZgx^LQv+NiIPcvXBZA1C)ATu!vq4RzD`(mAGa zng(g`I1hKcRF73N+*Z_S0_&wfxEl`-NgHCc2=eN6Zf9A3B_mhC*HWhi=Qq;JM-qVV zyAq`oV~-MhF!qDmpzB=n<^8?_Oja8xu0qbiRzv-iY3$@5qSXm~(^Bt~B^DZaa)zrJ zcIjd$l`;IT>Ydb;?m2wj>x+gm*OrRh58ylrMcBiTBCfNmfd|1L@|EGaZz9LO)zurk zd;VsWLc%KXUF=;X=5i;#2SO-$a)#DJOt!dRlx~>gZRI=8I=XHD^Q=m3*xtmBN}~7r zY%YR1g{2r&yMD2v--(ir*bX6jh4JRovZvl;yG&ks-;(I36LA%7UMIe{Vsj9{r7Pdk zOn34by(xyg$gfo#6;z(kn!w%>SBWC~4K!!GtT&sU@TIt8{{6Bbjdmsz&QjTq6 z&eACkDvlOL73UYE31o3KIqudR2@5kh z^UjkJ#@{4vRD#@K!Z7*7`vjgC3GN5uJI)=!aS_mViBD7a5I4in`uu1QrHQ2GjpK}U z1NrK-3-PHtUD&zrcbvo78>LH~=QDg;j)#0CujWRVT49(l+QIso^VY15BQsE+OU!jj zzBatBzizOtSQBwK<#Og!r1J*2)aq1W5`SkdYPuo)F!|i7M>PSs7d+cYH#(yvR-&G7 z(DmIzc4!mNL`RVwIDru!Fifmdjhyu=H4l@$CGs*;o*Ox^?f2y+(iw$C-AqwCRW>8N z60SYJ|HhJI+O(!!nIAw2(}$h|#6?mi0(W2hekT-%=4aIHJIqcX&J9lE_u4`dyrh zJyKyaU)oiIXkempB^DV-6BOo@o_L;^&yVZmqjrw-3BMLHScpnN=u!kSv45Q$!V&9h zWHu_NI5JQVWU?uzWEv~w_&~oM>9zoxwudJt_OJprz@{>2F|4g>Oj^L1pTg zM&~*C7N856rAqDkQC=FEUI_P!(r7ryqeso1fAHE;swKIBF-QNJe()EEOTRkH+?i5J zdkY-pd-mS1g&s+jDFoXuH}azLnpu5mW$kDP1cmVAOvP5j8z7PT)W z9E=pWULv~PvV{3!@kbj*B{~f}=$=1}S1F(#EGnKJ$bf0k#nOzz2qRg33wI=q7UiDU ze1m7Z_C1P)DW^|nJP@f4eemmL#26{Z-ocDa?}+FwRsB5Z9gRmYz^x0Ivw1T zB<|aRx2LozusHjiwMPe-Yn(DGg}6=2Tx2VIti%f!(OTJeX-B@@FJ3TfhNFKp;@S92 z=oCD3;`3tgsqF4G+5T9r*Mt*jqp1=I#w;762$W-r#~Bq5GN;LmRx-JkPh46PUDU5mOb0`S@T;M(a}z0v?EM^`DJcTNp;5ujj1mYjh2ZjWb8r2ImayI( zCy?+N4>#$OgyUwK=)EoL#2Sb?3U!=83@11LP`SO%K`zljLwSkGjK`{I$1Hz-lSHAmt@U}0d#A46YBWrTs2k38y!A-Srk09sam-Kt!z7qTx&xd z0WQ)MCqNwJRl()nL?*X4(rj=&x`XpHLnZdyda~ku5YGH#NZEvvN@a}uRoajT`}TCy zqVi~B$CCTAW80>J`06R|ml@QD>1W=Pt8-|ot}p1p3uI-gHR~T#7mz0%jLP3UjP{Bn zmM|+t^iio-prk~4^T_hZuMIAHgDzckLzKkd71=jQe2*%?D&&h=A+pTf-nq%0xZz1D zeLYyHRchr}q0379-IjEvn4sUM@gw2j1?$bRK#O>+YY_>QPkpaOCu&amF7o2;P`=T! zUQ02gz>jlqBolYU?j2r^@o?&yLY^VvD=(TG)7%Eg@a8=)ZFZ-TOGjm++5xBjizmkA z*j=2LvZFm~D;|77;8>l}?|7`m6%mfq%K?tj5YUaQkAZ&iNsf3S&K-?)PQcMSyr9>C z^Fn;6SrLZ*$NRq-xXCsxt!V@}D!gJq8d6E*wO>=Q*LPt|`9h2Mb5Xs@#E93$mwj;9 zV1W;()@wpAcd4EhT}5rtwzGSj8|R|?EBer602qBZ9)x7Yo#OcNuA;7r%36+?I}IwT zzTj)^+Som&(^6+~DtW)VSSqt{NtXDl)aq>ulk6%T%(AhU>2R3cCW!z8L0Ro)20DL3 znI1hU-sIkf(S{%^)R#YPf(B#v#J$+WmC4!lW{~k5p!R|M=&{Vr637YOTl63LJFiR3`__cI{?v z&Q15-L-wX*Ko2ZAnOt`*^Im`>M4Eg}9}a7*&fO)LwX&@2d-WZf!hM01)v5=O3l|xG zQ&)8&Rlg8zy|~2W>y$lkz0)UN=W#X9n@8q4|E(9p6ZtKi?K68R z#|~}7$>TO;44%AH(`QA&#L8&6%Cb)15Eg5+?He5IKDKXn9DFZVYnimHr#q~?Kf7t; z0Vss9_daH(v32@PNY{k%AFxM+vJ~)?v?v5EH-**r++W#Q8N1Bux+t#62&;rHzEb2K zkx-!y9F-!Pm+7CA{0#bPLkVdm49kou$)=M(Ca0Yf>t_=+*lLc)!W$94P&{B;(+dtu z+xvp(--g*Xh6owGm)YbmK+5+V$Kl3~S0qqgP<=7euCgV(y!J&L@)Js3!g`tuCvjnd zoZmc;(R)}yR$|5>cVQwy*72^HVz19w<)N3tPna#4txgJ@p`1g=>+0GiXSDrP^v|qr}%w|JOZAvIR=Rdc*X}w-Rd&-oRXKjWZ{BtP zyEmQ!<=1@%{cj3hBKMkHAm7D_U|yhj${Dk$+6sH`B`}DEkfod;nMW$EzYlrC>UU zR0XY`^M<0>VGPKcT~w7vC#hY(PsLy$rxS%XqI0_T0Ln01LM~~bRu~;4f7A_rCBGZr zS&!jCvKv?@^0JSiA0Z6??2RZ2rX_9!*kI^Ta+AxLG@lJLj38M=rI@yv>y4Nt@m1Yq z4qH*8205Mps%J7w!u`g3jM6w!fEg!LHO##SKdGYgIS)<`H}18->FfMch1R>cu6PQJ z6P<_>2tjBGz42hYSij?&=BOm`LNRE0jgosYDa)rZl(@M#ldwTq*EF^?dd?FiSdTLr z78A~kr1)Q@%1JF*@f-1hm`Miu-I7GDd%n)No>g_lWkhtX?nO^!lJ2fB&=8eAUA;3_ z30Wo0AG+*$WuG2N(Yp?qB~-^n$H!%y(QWPiH&LH>_wdN2l@BEq zeJBkWH#%`B7{MufshM;}h#FB=(w{4=ntIT_z%OZA*RU8r~ly#xx zBcQ`@eEx}~5msPP6cl0K7n|)k`QdjdVLYhpu4v~sK%#-Zc;%lbqKoGmf z#s;UPA$2KHDYhb>Oinw*A9qatiL)a9YuJ!#*vnIicri(95jCVjsgyxk@oW4KQNr!- zILIP8kjQ6g?UE{Zp3f8(V+3R326s@p|MJ%dy~gOc3|m(fm_bxg^AyCzM5&&>`C6i@6N)ONVmpN4AZx~}E8!kK zEUx=rOhA~2f|fNYA!?yyuV+7O&n#a!66_GYV2zA5&B?8l^$LFGShPrBQ1)6Qps|gT zHh5uiPNJ!_t!JOnwO98}ZhQ`OVd=JKv?9Xx#Uv82I2jTlhJB;i^Ey$4A3&>=VW%sY z6RCO3g(Ug+I_2GxMy0UpuiYr%yLUXjo7N<(PY_QkcWE2k4Tc!Nd-ly--DPH#9pS(k zI^f*6rP!q0v=()89if3yfXUNS-iu79ShoBAHu)-?IE9^r3(X>u??VY=(vyr*M=SC9 zEQ|})W^hMA-Id6F0O(#e42E$bk=|l?|8f}2hI5Cn5!_8c@fm$YFU1~h>kWSG9t)CM z>PghrX!Tj9`&pj5FZOq+^g|qw7QERBDAEjd@h%9wcq7k~Xcr zsSBTfph|;BjAlm4f_06n5#b%i7gq9aFY7e7^-|Lt0#UuT~$UT+HfqoHfSeUfaLfRD@w|cVWKgw@ugag(Wz}? z8zNqeaaXD^3s$;wl2+?8$5Qm-NRfQcEf_&n$n>b32^)zAB3=|>RGskjWntr|JK}); zr-xu@-j_1h5?Bdy^9x79{1YW7!lnV0CQN6L?g+MVBI1RW1VuV0gUD-&^s#fH=~Wlu z>EjYcB|kyri5pRI19O3dQf_+;J1yI8?j0-k`>?#Nt#zwBO^ys90DmMNi)AS4DiX$HHrSL0h}juXkR1V99a{ zakl&%W2RDFP=H|ZF=L*q{o9d;DB1@7=5L}A5%`T%s2|NCOoh|^Iru|u{fqr-1$pmv zxXts=o=%cXbW5VCm=xEGpmsae3FT!Fe7cltWL_& zHypGnDeqQ_+NO{vKcxsRSFH7MkW0hsVob;zmxx+aPJ-LRyN`OjF_Nq6|7kvdbD zg|a3E97Q~r_~eCxk|+&Q88(gdVy0v|n8Ax^ig&i5@PXa z_+V^_Uhd9*HOXhj`6d+{IcIH*hqW2ISRh+@@dBB(=v^5jwhFpz^ESm5x#e$damoF( z#xylp6PD3bMFEOEkzfUUkf2z$F#5ZEY9c;0E0t^MIGlLOFvPVnOw|Q=3>Wur-8!$f zTtt)V(N2-`ZzU}hC?=j>s*0|ee|W2?xhWp~i(M4klP0`ISvNa-PJ(TvnB!VfE7>h`thnsH~CMG?0(X-orV&jrP%y=YeEo>82gEWRo@TWm$dlN^Wi zhGLHiOp1+>)GIZW5#xDxkv7FT+WS{~#m|BHWwyG;9djzwXwf-&J7)gqZ zq6WRJv}I{wlg;P@P)FsvB#l76V33^|1v~~C>R`s8+Qo&UF*kWH3oUE45`iC{;&;Tg zQsNTA9NHmlsmap8S3=WZOMyI(d|2#Ud>`h>;<@hJJ7XdiytFXUF?be5+dT<3!Sv7) zUyISwU+n00@7Quw(vuiw5SmglV&ly)M_Ad46&60Rre(s@=@zOw5r$8epASo{h^Y{l zrfTn#U~MS|&&3rX$CoL5kS>TQcmiWMUHqwvJ)_aD7vF~=`vVgFa`HBfjBDuGAx$^d#m=+QY2}~ikr;gBlC##V2^=_XIP;k zYt+~rqe?7*eHZSWMpuz(UgqI>`K@73N!eH zZSX8lcOy%P-%F?*8!m#>qzGohDdJYiSB0nDXog$j|5tl&9TZphwTT8of(32dwSk}s z5Zv9}Em(jM+&x%ucXtU60U8U9ySqEVT^eUP$?tu?nLGd8x^rv(__|J=I^Cyw%i4Rb zZEHP`4u;&&X38Dy@A>T3!6yyUZJe|Yk?Nb5xq-CP%yLa6V%|~aWql^k!l!g;j-W%)Rs%5tf>5N+Vd144x6~zK^k$^9%i>%c3o zxf7wJr`TBfCBbD|2QVwUrDI3;rJK56l^1T=T$XL}*Oswk zq4%j3rbvU-Qw@Z!#UjOPHS1~Yv1;JPBaKA}K%j5=2A~F)j{AyWpdJCCT2lT;nc9ok zBcO^ElZvrfVaM>beW;uP_aI}^fh{+eDC>wS-=J#4xW(u%j|7eE8&ir5r)~P@g^%O_bUUn&Gm7D`NlFMb3+U?q~25?-rHlK<(S4NQb==>;%+cEL-9T zgo(mD{Vd9YV1lp+#N@AtCiE~U(JC=P(V2aU`Do`aMPEkUy@wbJR()rOVU$G^ujMT7 zpJ&)I2*$}~x2t*Q`-NtWJN<}y>oP@f7_L^Nym2^2(w6PP>6lbRo&0;Ggxjqr$DrP9r;t3*xHF-ty=SfA0; zoMU-tQtEn<``BKFdGZUgTq$TD)I*`oMig)uQG7x#w3GzXUN{5C_UVHd8`D0>`h=X6 zQaii;ov$t#v{1+eTWqOCBjZ#+T#T~`xTP&&mafT=0%Z*i$)6NR~1YSQC87l9Mz|IaQA!PV<0E# zxTkzFHeXQlL{%d7pnLy<3oGTTB$s_Nte;#t!chB_o+M(f`xVn(o zG*fUJm}8MwPkrRUAJ$idtVJfO=hFU`MLFI^7>DvMB6nmF-ePQAnr=n8%#6H}LOaL6 zS8~1nyR4wZeqCt(s+;t@e9>({+mw0jiyFQR7@o2*1#(^MTLTQoa}h5nL^!oQ4n?zk z@FF()m(Oy7MWK%GH&jHM5f=KLpWncxrISM?!z#8NkSeGPt6Wv!z#v*k7DaxirOW*! zBd>pj=4+3f=Kd}fy(L1@SB1O|*}$pGjSuti&|FP)px(KKovtoKLGa7_Go^sFIqwHe zD;*73CQuXR5X$psi3LMXn3V8c*UES+W<1#6O*3U<{w01cS&#|SmUyIF*&$VKZ556! z$PLa7RVxh6oe<>o0op;PKz@v_sk+i^XK%b+hOKr%bE(k_R1$)vV%qHP1X5RVHz7va zZDG{G@h)kXn6`}tNoMsyh5QPp71vaGW`qEif0*U_*kLD-^GyzFtDWjUODiB%$XR2K zRe&QyWG3_??}%ICVTlE5gE;_E*c_ zMKVgAl5Yz3KOG%7+O<0`49o`pKvoB$F4+7|kqnH0wWHyj{y%jl7GG(&8QfZCS|(0H zY&TWv`z=ysl`4A0GJ2$AU}{lZ)Buwl85b-&gEJ6U(opyriN7D8NF(6VcZ zwLKTomxgwRy!)eOeH^e*es;S3sqd2^TL-k;C}JKPP?X)%0_&?U#;{t_*;P=UAz~=m z${l<`lzX%LMpp=~Z8N3JScTbP%d>Sh1+RA2pYacH`>(2 zEo4Ed7+)Vv6#b7(1hHX7f>0CeC$KC?aH4*y(auvWA}DGg4-5|K#8wzn^ZNL7hhkSW z&#NoSE7Swls+8ARw!l=i-;JXvvbp`jJ@^z?+}bWBh`7APs-c0}AahYT4w zs0`^PPZF!X3>Vb$l>e5_m?B)+M-D8vUdumSc8nGQ3kOF%oPhnab{tS{B_`eTyuXxC ztS6&C9hmLD2<487Ffr2A%sieb2*dqm-=vyxa|dLB2KFH>Oh|7$>MAQKRh!?Ou4^~c z^c%x=yQOoO4gcwmZE!VyF8~bmKrJOqc~PrBP$SB3m`Wl@o7tfOnWEW#0NFUspN@53 z8Vx$SH-)H0z5i#4|6lmr2Ll_(6)jFP{-65UCkl#*iN!%t{G^{>Ix(C2J%@N*&=sYh z)6Isa561(n|1k>aNrHB|Iy$NUn1TGjws<;~P-x=>0p^sD(7W9qeybNgNWJP+7tj)s z_xa(X914~F@RB;(z1b8Bs{`l>$5+X$Lv-$tB|}D(O=iit;#l>Z6q2%BsNL&5!EFG{{hU+~c@{`KHd$+|a4@nnaiFALIrLKQx*ZpKBH!Me z^~mBR#Kgru!f8go6>cPvmp+M(Pe{mM_kM7VfdAko+eU0kf?M(9(?6B@2>Trq%E=_w zetoo9$3g|r1$&(v09bqp5UXelvNo?J> z_M^UHAKn=sCI9=&zYpih&{w=ny8rg2f8WSLQEN2YD+FdD`~TAn|MiM23Q@Ctoc%6tDA_DXE+xcS6-0ZL2%Q|rNkq^sX3=1Ieb;}Ev=(-P58$Jlk7u*QlFltf^4 z2Z}XVYC?L{1No!Q$xvxn%N889{Ow&Pscmm4lKl=N9A(k9MCT*j1@g+u4qrM~&Wg_8 z&OqT(1P^A)b#iI5dOJqjg#rw_wWXatF4$dYEQw~dj0ullLfHZy;5F#yVCW18iG88v zsW+dm*^Xg|kIX$1_4bo-7)P33dx0?8`I{R$F|g#kE%M+kj)nm@6eY(XtmeWB6;S1u z(HXdt|99Xs!G*!vsxixS`!#;F2qKjqFmkB|022}Cja$-(*|puIc2}5X$ui)ID;HDQ zEw2%;PB5{)_Axoj63Mxd5LgA>U-1gK9XIY+hu1@XBC>seP2ZTShC-|Sstxfs7im_D zd)9LW%M9IvLc_wcLaQ%~Q31haRa>?s>5l(tkUj!fTKcS*WKfKWOP*Pk$Js9^cZjj{tIA}t;nZy1{Uv3x_J zcyx4<&HgA}v;#CWEbM6cAf0~sLDrVhrTV8wM%Hv&W64WjENAE!J@}RR!)YYv z4@r@ee|0rF4lZ`N`%_V8^DLKEhg-^S{+~Z3ZJ)>%_zM0_;q|Y1ya4ROFAUg4f7OX> z2a)P;KFr$>1A?*5b1OebDveyMCnU3Ret(gtgnU6BfEFzwc+&W9(Qu)JFx}V3PWo65 zt){s>dS6cTcXVQS1onW@TTJyXm6Is^VI4pGGQc z#pYQzm5C9_LWIA$%eIfk+LnJblM>>@|102I39|9uiCt8dUC>G({;7&Y!C{$6ydcV- zLef5dLt8>}?o9Gk`8ykn?uFYpH1dFOM-B3j)+B!Xoyo0Y!-&XF^x{vyzg#K9q7a5) zAAZ|DnUni7>pV{vJp7YMOWOsdhuWValD<07og(#x`<+Pzn8Lg&89ILAxl4TcQ~5DX z1kocSu#Ud|)1PkjA+d!gt5J&VPX>)z;qp!|F@t~nZn)PBQFq}BNX}jp&boiA6cH;p z#dLi#kC+~z$|j9I;>d&%d}tK6%RV)4H?`T_7!Ol44M&hFIP|+ngiV6`bl&uHS8xmC ze}%|q4ZG0&spcvb`qG83uVBd%*P}O*m^tp38FczbGWci2k4Ay>)B7@UjMHjDKPF>}c{JL^dj4=os_E6^gL$#r109 zAwNz&bv)X_Zs~97|Cf98B;4;2s*4Uii)ds|*>U5qJpaoy|DDwTe{okPU#ko*5+3&c zoj6$(!fB;z(`lv19j;-=y!Jw+0a%%TKsmGG%hOG-0Ew!;ek*{~4Kad;QKvrLX(z*_ zg4*+0VAoN|ne*QYpvY%8w5zPa{YR{{FqivzN}kUhV00}p;di& zPw1>yyA?Y9-BaK_6V)m~6l-in2TM>Kg_!O9&VtYL=F~?nozqUD#Bd=C(ImDFio5E{ zVzsWlF-Jo*x>%b)c+z~*YN1WrG392r3x!_NXl{tEY6{%E;dyqs^9>^Pc6Ga%#|89h z!$K(*q;`HAO)*$BL>l{7vxrdmvq!QtOgSBrHaxaa=NXB;+{cma+mIjMGP5$-^NceK~ROa-uV2C11os1kJq`%g#pSbjveo=F3ctI%dr;|Z>U%?QW*jNJA*A>I z1pGX#3J~SF!2&~A=U3xy<#7*p9)^&kFvMOj$OP&7-GxoKBlN6&!#7C@#f{~_?5FOhjE^L`G`i~ zR!Ty5`nxQkH6Y-6Cc7(YitJkJpK8;9JG>pe(bc=W;IU+_u9!AU3)?E^hM&Bki~~3p@7_)y2KYED ziSsPV6FKqQXMW};Xa;9JT^21Xc8ug%m2IfDUoaprSsu!Mj`Jxw1}^k_F7!Pt+{l0y z9Y*;;G^WKW%JiI1#9Ug!Jd3ir1?k*Mgp*9oaxc*(Rryh(1&+Y{YlZ7XM{3wV{~b(-lE$ z^oHHsFy~)*AGvy)HDWiSW6O2AMLh!<-uCO4qdF8u*(35OLI6oO%g&>A!-@i(o>hC0E!Ugmqc*e(+d zQq0?8o4p^}V#<2sBy80lChw+Pe2Er#`7RZ}q2w_V_l3Rb%NPwu(a93N*2M1nte5!K zvfIY5c;MgW$NkY36tS=Uzr?zJB8owrBj>GDxS_zTVB~?-sFY~_k>1P?xwXV$SFMsX z$FsSfvOQ1p{9bqQQ`hl<4k50Sux1fE0jyUl-c7Nsa{13*Si5F-*GD|8+z}70&~t>k*=}3|Ps%u$ zTb@^Yfmw9a)YQ*`8}pvf#X|FiCz~DQ*FuWz;`WhherWQz}Speym2Xgo9UWCuf> zCw_kM=I7CRmlv70ORpRNYr}<$F z@U+CP=%@(6m#^>B5Dc4#<9h3S29$3~Q z3{stN#{y&-c0NtQ&y)U_#L}GbYZZLTep#U49afyp52r-$2XL*gX_yK`43e$=n=f_= z)ng;KyKW;VPRlL%A(bq?x4DaQ6bUGm1PR*WA(=ZBuQu4m&9Mx@Q zpF)nH^rr(mLD{B1CagNByyk{(u9>RLLC2BNTLr9F4Bnr2++7Z@DdJHjNtcN8(Dz6+ zYRtKhp!CQS@6NPSc59=9Ql>Vor*?ASCJ5;$`KKeeE>|5o1R%v&{7#_Yvs~oI_RM?{ zw-dqE`sf*E9>?8N3&+%(N`meI_+$5)T`mcj^oR4r;t&%l1F2y(PU_IYei}ab4elK&Pb?tuhYA+~$;LEPe zQ*J=!!VJ+}eoDB%wh1%BIW!kll)bfzkeym$QKhhBfs zfD5YeGSexEIHxw*b9n2XSH+ce=mDR&#D4}YRye$Td75fVD4VM*$85CUu#?##v(eaM z`-=vFm-;f9;I$GMdFk$xhE*FV6^THc0hOu9%`z5ljhKJ&Yx9o84bCLNG(#}QY#g30 z&AXUeQXpv-Mb2thF0Uo%2DgPYgrQv_q#~f25Tdc^!s*S_CLfnSmL0L|;>Ll*G1vem z@;I_TfF#o=i%Q`?qF!^5-wDVOT*_b^y&>&$g7Q*e(-K6zZ=4%(=sT4M@X6s7yh#uB z3}oo=CbMT>KkN_keezrOxo825{%EXN<4$&5>NnYrlBKZzl#8yUnsRfszU*|vrEf^? zaGJ-Ader_HBAc5Dg^j;>3i6;^w= z%he5S0axF=i3-|j*VTvxMf*kg;eE!POJM2e@rOv*R{~IU8m_l)dFj&P2eUTmQ0ok9 zosYETzWT^Ege60XMy`V5J6{}LR(~JvD&TfugghJ7+~MMM^P^zBkjtmLn6&kwK6dVo zIIqIklPBg2JD`g1JV+Vx>GSFvyGCt$r0#RjJnX%qt=LCf>Gh$<@pUdbE|nt=%HVge zOZK4S)+-LfJzsnlKtB~F*8ucIw}_AE(2oDk;I46x@*InWB=k@U4)7H`=XNy=?gAgdfz22+y0xz?zHGU~FMj?0E+(~R$cN1POvNC)T{X=QUy zTtW4Q6KHigkHk`V@aQM>RdaD35jl5XEzFK*F^^f3^ql8a8hFsT;CUFs*~L;PN#kQH zdles^@xx2!2C+7Z;P?0fZKHlQQm%imRC$>Tbxp@G?l-h>JN%NV zFZ?ylb33kJUyo>{NIu0bD<7e&u^8^RU-7SGj6^PII*YHO0uUW-&UZAdoF)02%E!xZip77@O zD^BPWsXfu5K<*bAz)|b#bv2iQA*Xz;D^(}KxP@5+h<*G+%9IBqTwM-Hri51M@&n2C zntKI#;O&|}8q+=Wc6ZJTs00Jc=$0%o7hjGW%~;$BU{ib8Re6N{#4)Okb`E(^iYoX5 z9)7%oE~l(W*v!ZHYr%;DF7Q^Ld3j71x@TdNou_<;uaGK!*b2ZP;vcG>nY zeJ`OCvbyzKf(>4O7LQHwxGgaHj!eV6aBJ;ig}30qSDdL#6yP)Mrt+3Iqd<$seWoa< zPVqsx)F@ZY<}wa&A5=wHj{rhz`(?MWoNzC2=8a*uBux00Jd^m6P}`MOl6=W8HJNV7 z^MhHIm$S>c%LgL)pxfChui$&rDz$p})3R5IS(834g;`BHkMa6#V3g}-2SN?mcrxKg%K9M5cvo5c5^nvBnmWo-b|-ZieoAGpOquDj9o>6{Vy9y#Wi^lT!=>Z z!|I|J!*IjNx@!bl=%=-|M4moqBbnhH$ zI~3vC$;!ZRn}(Hd1_?2D>961AXs?jH<5B*zCFiS4ttj4szxnpVd%Ig|z%(Wm+nfal zBK0K`v`$0;%`O;?m2u<@JxQmI1%OVgSCqEjK*5;?Q4lu}daXh7b+iy(WH=GkkAbCe`sL~+@Ht}l%7Auxk(0k?3Y;O*s) zIP|TF1~@3!G%Y`>!K9}9QR5OePE%2y&w(KW$;n@gEc?5VQ{D`DJ8S;{j z^L`K`40PbJN47H7R|L802Tj;h&O%T3`8Z>Cl#iy5%r8#j(_eBpggDMOYg-P<#4xryH7(nVPAj}zwBerjt0HKx5q~o=Xw1GuPUOd zE9dJ0{d!X|aepf>he$rlAgxtuko?9n<)P#7TE;_p(Mr^2lRz$U%fa``(RO=wh!GcY z;^>+g%cy^&O|KK9+kPZwxpR)KPnbQg(&LNK_Xk?ZP3$cfK1AJ@B~yXmDbl_ z`{uxgnX#xqXYB2F-L`doN&wbZSxMiT3O{56NX*DD)*mIjD=x&Kf%^uaz|l7Yd+)bo zj|y_evo#D#^#{ZoKNUOMD3`0a{iCtD6`hiQV;ojZZ-m*~#!H06i5H zTp#xLGFWE(^D2os-N@%`xYsIN--whe5+oAnrMn$N?eSaku|Nr41Vd~co~=I5PY%ZW z@`1o3qD{|$J6GC0u5|7@inH%Oao~`I9Usm|;k;i17L^ZOdZVyr+X8T=CGWw>**=B+ zj;F#J-tf&Y=h3ZjTW6Il0E1ncn1c&vNypN+s3) zYFt;Y3Qo=kN&G<>s#dB;8hdd}WElhx2IT&d(iq$6NJ)r9xWj_mi~?q4p@6s0fMY|1 z7YVWX+{x?xoP~1vXvZ8rr=H>50+}TBDg^RZ9<0|Y#V(_rQUW%?$qV14cqZJe82#R+ zN4cTW%_1p=RoCXFbb*2)cPW#W@hXyyGxz#G-OE2R+=lDW%{`jZbateBci3@)xT{6f zNu$q+-mianVBg#%JgoIW8x-lA712$ioK8?6zY;4#Lj_hOX?3|`%)~qexL2pV@{N*w zwrl~1-k?#m1p7q@U^n2r%$liotU$4b?vJ}-aKilAOM;To*~)H%nsZWQ9Z{Q{kD5Mj z4>#FqEi7(3waCGdkz|aYAbHZB0k{i@y*?Lh0EmC}jo~*c3k@!kuVGlfHkfTf{2y&RRgBXO$B8I;B)5^ zM2vgG8P2L)r$JAwV+zIE!*<-p)#F`=&8XK>OP|%peF7#sY7?BU7#odbDGMUM-OC}9 zeC1m@urdzUXWp=ycx8^S*W?1+?QvFx>F?8nS_qj*!vTxMmJU+2k(3ZrnOz#;yEa^b ztX(<11Yypv_1PJ=#1`s0L;*uZe03YzZLptT9d}9bEE_};a#Y0HGjhDIL%h%-&2g`c zqxoS-@^d%;Iy>VATX%8d0~l%PpoBk=a^*m(a>=~x4gQj|kZS!x|4LNL0hJWB2zUZJ zYz8Tba@mOD6;DpiiFrsCKN6vY-YILUZD~VL+J==xixI9>mlfR;J)^lOPw~lpt>fuc zhI#MbRY0o|zk)Z!{F9et#bv3B@G@Sa@^wP%cxwX`? zAtd>c=bN}g5!#d*UDC4iqSfzha?-c5`yu<5+(QKWwei;t;#UD7``iPC)TmV4*57@+ zT=;vHD%X^da^v&W9lyTp9FN3b3ui0r3#-`VI|K%wy04HsOV8HMt^QDj!qq}6IGFYuV z$9f+w7Dp|1f3^gLp)rYjuU5MGI3zu2F=B#0npdiE%Fg=HvJWF1SD?d3VS>ohR>8|3 z%hoFb%u@0+kQUzhi1H<1XU6fc{aCcm`@9Kiz~h8xO|RR>+!M3Q>89v9X;Q+1v8^ zA1lp0!W66(o}M)+*50w;ON_9;?oq4SERf@Iq@~ulkoUiz_tbK7z8oR%eL_`tO?~dZ z$YSC-XN#z+rGI9Ln?=i=MDOy|Q{uf}^J=jy?1;eC;9qR7_Tx?-=SDxJEFqD+R61T$ z+bwZ#qeFePY;uw`PfFe_yC2KET&E+}0H=!8pjnVE-bjhMx#Avq1k6)A8x|?Iy+hlA zyy+nD1*ak08}i%Ni-YN=t2Jm7v65fc(_{k)2^IMHIyJr&RIzV@r6lJg2MOx6(Z`R?*D@EQ z$9o&6RyE$uS(>RjHHCI)cH0p!1WRm+(%(H7R`awewI6H+o#zCuMduEL7_yTq*Lt!F1Hf zo?+0neJU&i`_R4pQ1b8j;lA)!Ar~rA#f2!Tk^Aa6BIhl~mP6eoHdBhT*ZyUZ83RO- zdKje(n0E40y46E~Ea0Zo_aQq$-oWz9T8@mNP^TyP%SokU*fHXW3^`tfy((wS)<&JK;Fm3b}Pvx(p{o zjugj5xjRI~NO(nSf4Ymk>LcN5yHI01z!J<-qN0zQLVo!6I-kGBeHD^Av2%9%53mbmzkcRK-FLUjT&91w1#~B&T~EDx)Gh*Dqhw@@a5TqCZGj{5j71 z2ulw8ri|O#`DI*s=Un-5!K&~Dvl93F#*@xAPol^Q!B#<%Pl{;7blpF_2i3b!mxVlY zYI))aXGVN;_&b!x2o-Hy^ z8=D(`pW5Gd&~@>id34QKz9=qIXsa^L)piw)dJ_R?16ltC`-J97Ef&JIZ>+RHJTFK3 zYy4Ra8<2^7fXVb^Mey~7X;~bhK!F}nhpbxWnP4 z=~m+5dx;O)u1uo%+=w(Dl-x~kci0Iw6g9aq7ruG8h0@N}LeY}gG52(g1)UrPbzGxd zfiaOMalL?PV6MOF{SL>vv8HEJm$D;o09TSkV@!8k`P#s%kl&_DADMbtt9FTUBZTm7Vdb(;VnbixC2hXE z1bF6WB(G)J*s(1)uHz+&zk_O)F=hVqp~?8^8%yDckJd}1f$`^0vxl;kYy52OJ6hlROw8kBM8iX;r*;gm2(~6_tm+!lHNhl|t++|)Z z)a>^x_8?*V2uG4yd|X;Jo z)T`V8mRr6Nu>I_UBdh;W_#Sw`la`!)EZz7N?4nH7YXk{x%`MNjdw%C+LJrdS0(GS$ z4!t?x<>;)$O5#JLzcl1Kj7_DSV8R(^`m}!H`S1{H+oJ@zB;0wL%LpmvV`{75x?=p! zk}$GBKxa-X2-&cCagMw}Dz2SLqp+|y6$DdfA%|-8~7+t!yn6EkFdRK8fpN}Vhq?pAK2C$5Pr5lHN|nS z{fPJeq2(ju(iL;=C3v!OOGGECCXX&qPe6y0gvTpGS6ZLEDD~|$&B_5}xYQMld`2wg z8HP}r+-fhB8}%(PulzXIN2Hk918w_`aN+`~D3>j9mu-wmciI|t)BC;C4jon}@dKO% zD{|sO%=Gw~ad8mx={@#DDjIQ#4}YwS_94SY>jVX@vmHvP=|X2Xp%O~sTb((1s$~&7 zcV1JKp&w7pUwc&R@FOM%3<#H07tSgxJWqL&-p}IQW$9Mt@uB9U?v)_q4d`*r{4t|ilB|^`O*8aoot!O%z*6ir@U=cOBcRWwBUyA8x%I^EF*U@Z#aG^X zwRctHPR}eAliy!z*y>F!F5tL5z>QXeF6!>*Vq72NLs-nKe2!R>%+-%Z4tys}T~Crr zQCs>0o%gaxPr<_OjB!sw89XkL^2UhPKvu1}p1N4WjeH+tM`Az;c7PK?+*f3~>k68(f)<`=mxaB^4|hJ5I#+2^=7VdQE+-BGJS({K>t(AW`#v_zo2y7-=RJ{qOV9(w zecmUzB=5~4#2xbvbHBy9J{{iGp=a!hOG3NuqRm9vZ#`?`amlRJ3!#e;#S!7=S9ITW zggNa}3~l1HU|Hz~eJCi^;G@GVC_|N;OquLa&Uu{-v1g;#z0aZCE6<^%kE=IX>rZAa zV_={ASne~k3gv;iADR|499vu?q;y!a0ngtIygc{WOgOL9tv(Zg)V)&Vnj%N48k$mUB6p zKiU{+X;HE+PGRoJf$fRk8t=2`2+vz^D!mRxVsD7_RyL@dIj-=wxhFek5Lge1hv%uY zJf#WLp^0eiy(f>~;ovQen)sfd)Nnjnhxc7IE7+2JGj=~sp6wCU$MRGltQCTjsYa^u zj=TQh9SIE?jYH)-!Ocki+M+YQj>WThl(Y>Z}uw3t_PgXKVFG>bZJF``{AG!6@xT%Eh89erJPwgwD9Oj21WA zATH~)?Z3f)63#l}>R%IU&5hI;?`?wB(go%l-JfHt!~;QDO2T~93F+sw^mygdf4j7^ zF~G!6T^Om@j`Bfdd*z#Z>>_}rEn~9*lUBdpBN%kPYtP`UpAUoa$^+UhxT%Rg;FL*w z=08hKTy$)7huxq0CIdbDJu-oB4TGME4}4EgI^;2DS$ywOaW(StokgThdQ7Yl<2w5) zxK2uJ$@ReDgqm})&q?Xg*xu|y-!ThYRy;3;EgK(vmv;ny983n)vh8TDJQP3lYhjBd zGv~;*jEaKL07<3~GE|S&EV(VSAC^*+)uaSTG!?J88I^`QM9nocwT#R@GsTUlqL#Jal_cm!DwLf zVU5g|tJP`d<&fVdUA18>2VKuylGn2Yf%T3TbEbstjbBZQ@6Do%%4yk+s9n?dIx)MMwkYtGWF625b?K_It@-ADgLSRkHI1XXT8Qam z;!C%|*-zL(RvcG~MH+oW`pkWSOSNITC<4(%Q zJN=G~2D-$>IY_>ox3`2l1u~g^UQGdW+UuxAR}RFzFh?M7L^*QfECjtvlm>~Su<+dN zu)0^>9!ob2`|f#(TYQyx^v?bU%7s_`9Q!I9Gn4Wt$(}ZFZ@7W6lb;QDZD9@g-PjH# zQ<~;K-c81EiuFt;Uz;*u_B~&BqbW_yoIg7hw1~Z~ZW6DEqOnU?Fi@EW*W3~MZ{R~o zWxNcb5hB_N^5&eVOOEB^~Oiw2S&IhrtTIXl9I@@Z76H>F4S*uf7~isRzVsSK`P^7T}; zzJ%bWJjuX4Ev%anB6AYv*A5cXq`JqAlr|EFD!Wk+Jno!5z&l^U1jT`#w{HRQ-C6dG zREM9C(pq!U^G@z?9j4zpZT(1Qz6BXRyakdTSZcpO*{C>94Phw_tNi9d4h%mj*Xmkn z_nUh?QB(o2N9K`bb1&*S8yS!z`$2h_{lmw~1&Km%kIpqSk9m@ArznL-uX4;8~l2^0B2omiqqWjLj65f!s+a z;PG60i@Bq!sY(R_)U9k#qzmjMN zn0~lSD-~t7via*3_zXAZB$MpQDSt8QGJ8kGuqvCioiRl)Q?L2)i|Tl_V%q&jHC8UV;pi&st(S zn8-K%(*v@jq$*5El1?%&trL^aN)TiUi%%}-rPn`lWlUQh7XxcTi7e{y9#e}LcDe(5 zB};5YnT2+?^ycx@Xn8SN5D0bqAAwT~`e%6sgnHn1^p=-;-q2*ExZiFkIhEB+j7vvm z7qKG!PMY%cv=i-sQvD7+kIHh`3$k1kr$WBXZ3);5*v5vkIggfZIDY!$Q42<>qO2jg zjn-w9J7sP^r|%s36EytWIaW{}0Ijw>ZWiEAbKF8*GoD$YfX$>)_T@ge8>@xCTs5rFuS@0mnEIZEGLsw|ux>lis;lMa20zSp8>p_}3RV z!v8D3X!1-H#s}0dBL#?55-+x!q63$W9tVrJJm(Vr2^jk)jOMSu?tkC^TLS+-NkEVr b@xkYHVUN{BW{=ei=toLSUbI5^qu>7kL1S6y literal 0 HcmV?d00001 diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 1b3d3f8..d16f326 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -1,5 +1,9 @@ Getting Started ================================ +.. image:: cglm-intro.png + :width: 492px  + :height: 297px + :align: center **cglm** uses **glm** prefix for all functions e.g. glm_lookat. You can see supported types in common header file: diff --git a/docs/source/index.rst b/docs/source/index.rst index 8af7247..ae51468 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -9,7 +9,7 @@ Welcome to cglm's documentation! **cglm** is optimized 3D math library written in C99 (compatible with C89). It is similar to original **glm** library except this is mainly for **C** -This library stores matrices as row-major order but in the future column-major +This library stores matrices as column-major order but in the future row-major is considered to be supported as optional. Also currently only **float** type is supported for most operations. @@ -28,7 +28,9 @@ Also currently only **float** type is supported for most operations. * euler angles / yaw-pitch-roll to matrix * extract euler angles * inline or pre-compiled function call -* more features (todo) +* frustum (extract view frustum planes, corners...) +* bounding box (AABB in Frustum (culling), crop, merge...) + .. toctree:: :maxdepth: 2 From 6d5734fe7e41a373935f160d7d98cba0778546f4 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 24 Feb 2018 13:18:13 +0300 Subject: [PATCH 009/292] docs: update sphinx conf --- docs/source/conf.py | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 4157b5e..e02fea3 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -30,7 +30,15 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = [] +extensions = [ + 'sphinx.ext.doctest', + 'sphinx.ext.todo', + 'sphinx.ext.coverage', + 'sphinx.ext.mathjax', + 'sphinx.ext.ifconfig', + 'sphinx.ext.viewcode', + 'sphinx.ext.githubpages' +] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -54,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.2.1' +version = u'0.3.3' # The full version, including alpha/beta/rc tags. -release = u'0.2.1' +release = u'0.3.3' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -161,3 +169,31 @@ texinfo_documents = [ author, 'cglm', 'One line description of project.', 'Miscellaneous'), ] + +# -- Options for Epub output ------------------------------------------------- + +# Bibliographic Dublin Core info. +epub_title = project +epub_author = author +epub_publisher = author +epub_copyright = copyright + +# The unique identifier of the text. This can be a ISBN number +# or the project homepage. +# +# epub_identifier = '' + +# A unique identification for the text. +# +# epub_uid = '' + +# A list of files that should not be packed into the epub file. +epub_exclude_files = ['search.html'] + + +# -- Extension configuration ------------------------------------------------- + +# -- Options for todo extension ---------------------------------------------- + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True From fc424631a4560b66a7b250310877b4fc378ede74 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 24 Feb 2018 13:18:28 +0300 Subject: [PATCH 010/292] docs: add docs for api, mat4 --- docs/source/api.rst | 29 ++++++ docs/source/index.rst | 1 + docs/source/mat4.rst | 231 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 docs/source/api.rst create mode 100644 docs/source/mat4.rst diff --git a/docs/source/api.rst b/docs/source/api.rst new file mode 100644 index 0000000..5c54521 --- /dev/null +++ b/docs/source/api.rst @@ -0,0 +1,29 @@ +API documentation +================================ + +Some functions may exist twice, +once for their namespace and once for global namespace +to make easier to write very common functions + +For instance, in general we use :code:`glm_vec_dot` to get dot product +of two **vec3**. Now we can also do this with :code:`glm_dot`, +same for *_cross* and so on... + +The original function stays where it is, the function in global namespace +of same name is just an alias, so there is no call version of those functions. +e.g there is no func like :code:`glmc_dot` because *glm_dot* is just alias for +:code:`glm_vec_dot` + +By including **cglm/cglm.h** header you will include all inline version +of functions. Since functions in this header[s] are inline you don't need to +build or link *cglm* against your project. + +But by including **cglm/call.h** header you will include all *non-inline* +version of functions. You need to build *cglm* and link it. +Follow the :doc:`build` documentation for this + +.. toctree:: + :maxdepth: 2 + :caption: API categories: + + mat4 diff --git a/docs/source/index.rst b/docs/source/index.rst index ae51468..3241872 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -38,6 +38,7 @@ Also currently only **float** type is supported for most operations. build getting_started + api Indices and tables ================== diff --git a/docs/source/mat4.rst b/docs/source/mat4.rst new file mode 100644 index 0000000..dffe18a --- /dev/null +++ b/docs/source/mat4.rst @@ -0,0 +1,231 @@ +.. default-domain:: C + +mat4 +==== + +Header: cglm/mat4.h + +Important: :c:func:`glm_mat4_scale` multiplies mat4 with scalar, if you need to +apply scale transform use :c:func:`glm_scale` functions. + +Table of contents (clik func/macro to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Macros: + +1. GLM_MAT4_IDENTITY_INIT +#. GLM_MAT4_ZERO_INIT +#. GLM_MAT4_IDENTITY +#. GLM_MAT4_ZERO +#. glm_mat4_udup(mat, dest) +#. glm_mat4_dup(mat, dest) + +Functions: + +1. :c:func:`glm_mat4_ucopy` +#. :c:func:`glm_mat4_copy` +#. :c:func:`glm_mat4_identity` +#. :c:func:`glm_mat4_pick3` +#. :c:func:`glm_mat4_pick3t` +#. :c:func:`glm_mat4_ins3` +#. :c:func:`glm_mat4_mul` +#. :c:func:`glm_mat4_mulN` +#. :c:func:`glm_mat4_mulv` +#. :c:func:`glm_mat4_mulv3` +#. :c:func:`glm_mat4_transpose_to` +#. :c:func:`glm_mat4_transpose` +#. :c:func:`glm_mat4_scale_p` +#. :c:func:`glm_mat4_scale` +#. :c:func:`glm_mat4_det` +#. :c:func:`glm_mat4_inv` +#. :c:func:`glm_mat4_inv_fast` +#. :c:func:`glm_mat4_swap_col` +#. :c:func:`glm_mat4_swap_row` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_mat4_ucopy(mat4 mat, mat4 dest) + + copy mat4 to another one (dest). u means align is not required for dest + + Parameters: + | *[in]* **mat** source + | *[out]* **dest** destination + +.. c:function:: void glm_mat4_copy(mat4 mat, mat4 dest) + + copy mat4 to another one (dest). + + Parameters: + | *[in]* **mat** source + | *[out]* **dest** destination + +.. c:function:: void glm_mat4_identity(mat4 mat) + + copy identity mat4 to mat, or makes mat to identiy + + Parameters: + | *[out]* **mat** matrix + +.. c:function:: void glm_mat4_pick3(mat4 mat, mat3 dest) + + copy upper-left of mat4 to mat3 + + Parameters: + | *[in]* **mat** source + | *[out]* **dest** destination + +.. c:function:: void glm_mat4_pick3t(mat4 mat, mat4 dest) + + copy upper-left of mat4 to mat3 (transposed) + the postfix t stands for transpose + + Parameters: + | *[in]* **mat** source + | *[out]* **dest** destination + +.. c:function:: void glm_mat4_ins3(mat3 mat, mat4 dest) + + copy mat3 to mat4's upper-left. this function does not fill mat4's other + elements. To do that use glm_mat4. + + Parameters: + | *[in]* **mat** source + | *[out]* **dest** destination + +.. 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 + + mat4 m = GLM_MAT4_IDENTITY_INIT; + glm_mat4_mul(m, m, m); + + Parameters: + | *[in]* **m1** left matrix + | *[in]* **m2** right matrix + | *[out]* **dest** destination matrix + +.. c:function:: glm_mat4_mulN(mat4 * __restrict matrices[], int len, mat4 dest) + + mupliply N mat4 matrices and store result in dest + | this function lets you multiply multiple (more than two or more...) + | matrices + + | multiplication will be done in loop, this may reduce instructions + | size but if **len** is too small then compiler may unroll whole loop + + .. code-block:: c + + mat m1, m2, m3, m4, res; + glm_mat4_mulN((mat4 *[]){&m1, &m2, &m3, &m4}, 4, res); + + Parameters: + | *[in]* **matrices** array of mat4 + | *[in]* **len** matrices count + | *[out]* **dest** destination matrix + +.. c:function:: void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) + + multiply mat4 with vec4 (column vector) and store in dest vector + + Parameters: + | *[in]* **m** mat4 (left) + | *[in]* **v** vec4 (right, column vector) + | *[out]* **dest** vec4 (result, column vector) + +.. c:function:: void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest) + + multiply vector with mat4's mat3 part(rotation) + + Parameters: + | *[in]* **m** mat4 (left) + | *[in]* **v** vec3 (right, column vector) + | *[out]* **dest** vec3 (result, column vector) + +.. c:function:: void glm_mat4_transpose_to(mat4 m, mat4 dest) + + transpose mat4 and store in dest + source matrix will not be transposed unless dest is m + + Parameters: + | *[in]* **m** matrix + | *[out]* **dest** destination matrix + +.. c:function:: void glm_mat4_transpose(mat4 m) + + tranpose mat4 and store result in same matrix + + Parameters: + | *[in]* **m** source + | *[out]* **dest** destination matrix + +.. c:function:: void glm_mat4_scale_p(mat4 m, float s) + + scale (multiply with scalar) matrix without simd optimization + + Parameters: + | *[in, out]* **m** matrix + | *[in]* **s** scalar + +.. c:function:: void glm_mat4_scale(mat4 m, float s) + + scale (multiply with scalar) matrix + THIS IS NOT SCALE TRANSFORM, use glm_scale for that. + + Parameters: + | *[in, out]* **m** matrix + | *[in]* **s** scalar + +.. c:function:: float glm_mat4_det(mat4 mat) + + mat4 determinant + + Parameters: + | *[in]* **mat** matrix + + Return: + | determinant + +.. c:function:: void glm_mat4_inv(mat4 mat, mat4 dest) + + inverse mat4 and store in dest + + Parameters: + | *[in]* **mat** source + | *[out]* **dest** destination matrix (inverse matrix) + +.. c:function:: void glm_mat4_inv_fast(mat4 mat, mat4 dest) + + inverse mat4 and store in dest + + | this func uses reciprocal approximation without extra corrections + | e.g Newton-Raphson. this should work faster than normal, + | to get more precise use glm_mat4_inv version. + + | NOTE: You will lose precision, glm_mat4_inv is more accurate + + Parameters: + | *[in]* **mat** source + | *[out]* **dest** destination + +.. c:function:: void glm_mat4_swap_col(mat4 mat, int col1, int col2) + + swap two matrix columns + + Parameters: + | *[in, out]* **mat** matrix + | *[in]* **col1** col1 + | *[in]* **col2** col2 + +.. c:function:: void glm_mat4_swap_row(mat4 mat, int row1, int row2) + + swap two matrix rows + + Parameters: + | *[in, out]* **mat** matrix + | *[in]* **row1** row1 + | *[in]* **row2** row2 From 02ab66a8b356b8ee62dead42846545ce0fe6c2ce Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 24 Feb 2018 20:12:05 +0300 Subject: [PATCH 011/292] docs: add docs for transforms --- docs/source/affine.rst | 242 +++++++++++++++++++++++++++++++++++++++++ docs/source/api.rst | 1 + include/cglm/affine.h | 2 +- 3 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 docs/source/affine.rst diff --git a/docs/source/affine.rst b/docs/source/affine.rst new file mode 100644 index 0000000..ee6c2ed --- /dev/null +++ b/docs/source/affine.rst @@ -0,0 +1,242 @@ +.. default-domain:: C + +Affine Transforms +================================================================================ + +Header: cglm/affine.h + +Functions with **_make** prefix expect you don't have a matrix and they create +a matrix for you. You don't need to pass identity matrix. + +But other functions expect you have a matrix and you want to transform them. If +you didn't have any existing matrix you have to initialize matrix to identity +before sending to transfrom functions. + +There are also functions to decompose transform matrix. These functions can't +decompose matrix after projected. + +Table of contents (clik func/macro to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_translate_to` +#. :c:func:`glm_translate` +#. :c:func:`glm_translate_x` +#. :c:func:`glm_translate_y` +#. :c:func:`glm_translate_z` +#. :c:func:`glm_translate_make` +#. :c:func:`glm_scale_to` +#. :c:func:`glm_scale_make` +#. :c:func:`glm_scale` +#. :c:func:`glm_scale1` +#. :c:func:`glm_scale_uni` +#. :c:func:`glm_rotate_x` +#. :c:func:`glm_rotate_y` +#. :c:func:`glm_rotate_z` +#. :c:func:`glm_rotate_ndc_make` +#. :c:func:`glm_rotate_make` +#. :c:func:`glm_rotate_ndc` +#. :c:func:`glm_rotate` +#. :c:func:`glm_decompose_scalev` +#. :c:func:`glm_uniscaled` +#. :c:func:`glm_decompose_rs` +#. :c:func:`glm_decompose` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_translate_to(mat4 m, vec3 v, mat4 dest) + + translate existing transform matrix by *v* vector and store result in dest + + Parameters: + | *[in]* **m** affine transfrom + | *[in]* **v** translate vector [x, y, z] + | *[out]* **dest** translated matrix + +.. c:function:: void glm_translate(mat4 m, vec3 v) + + translate existing transform matrix by v vector + and stores result in same matrix + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **v** translate vector [x, y, z] + +.. c:function:: void glm_translate_x(mat4 m, float x) + + translate existing transform matrix by x factor + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **v** x factor + +.. c:function:: void glm_translate_y(mat4 m, float y) + + translate existing transform matrix by y factor + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **v** y factor + +.. c:function:: void glm_translate_z(mat4 m, float z) + + translate existing transform matrix by z factor + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **v** z factor + +.. c:function:: void glm_translate_make(mat4 m, vec3 v) + + creates NEW translate transform matrix by v vector + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **v** translate vector [x, y, z] + +.. c:function:: void glm_scale_to(mat4 m, vec3 v, mat4 dest) + + scale existing transform matrix by v vector and store result in dest + + Parameters: + | *[in]* **m** affine transfrom + | *[in]* **v** scale vector [x, y, z] + | *[out]* **dest** scaled matrix + +.. c:function:: void glm_scale_make(mat4 m, vec3 v) + + creates NEW scale matrix by v vector + + Parameters: + | *[out]* **m** affine transfrom + | *[in]* **v** scale vector [x, y, z] + +.. c:function:: void glm_scale(mat4 m, vec3 v) + + scales existing transform matrix by v vector + and stores result in same matrix + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **v** scale vector [x, y, z] + +.. c:function:: void glm_scale1(mat4 m, float s) + + DEPRECATED! Use glm_scale_uni + +.. c:function:: void glm_scale_uni(mat4 m, float s) + + applies uniform scale to existing transform matrix v = [s, s, s] + and stores result in same matrix + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **v** scale factor + +.. c:function:: void glm_rotate_x(mat4 m, float angle, mat4 dest) + + rotate existing transform matrix around X axis by angle + and store result in dest + + Parameters: + | *[in]* **m** affine transfrom + | *[in]* **angle** angle (radians) + | *[out]* **dest** rotated matrix + +.. c:function:: void glm_rotate_y(mat4 m, float angle, mat4 dest) + + rotate existing transform matrix around Y axis by angle + and store result in dest + + Parameters: + | *[in]* **m** affine transfrom + | *[in]* **angle** angle (radians) + | *[out]* **dest** rotated matrix + +.. c:function:: void glm_rotate_z(mat4 m, float angle, mat4 dest) + + rotate existing transform matrix around Z axis by angle + and store result in dest + + Parameters: + | *[in]* **m** affine transfrom + | *[in]* **angle** angle (radians) + | *[out]* **dest** rotated matrix + +.. c:function:: void glm_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc) + + creates NEW rotation matrix by angle and axis + this name may change in the future. axis must be is normalized + + Parameters: + | *[out]* **m** affine transfrom + | *[in]* **angle** angle (radians) + | *[in]* **axis_ndc** normalized axis + +.. c:function:: void glm_rotate_make(mat4 m, float angle, vec3 axis) + + creates NEW rotation matrix by angle and axis, + axis will be normalized so you don't need to normalize it + + Parameters: + | *[out]* **m** affine transfrom + | *[in]* **axis** angle (radians) + | *[in]* **axis** axis + +.. c:function:: void glm_rotate_ndc(mat4 m, float angle, vec3 axis_ndc) + + rotate existing transform matrix around Z axis by angle and axis + this name may change in the future, axis must be normalized. + + Parameters: + | *[out]* **m** affine transfrom + | *[in]* **angle** angle (radians) + | *[in]* **axis_ndc** normalized axis + +.. c:function:: void glm_rotate(mat4 m, float angle, vec3 axis) + + rotate existing transform matrix around Z axis by angle and axis + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **angle** angle (radians) + | *[in]* **axis** axis + +.. c:function:: void glm_decompose_scalev(mat4 m, vec3 s) + + decompose scale vector + + Parameters: + | *[in]* **m** affine transform + | *[out]* **s** scale vector (Sx, Sy, Sz) + +.. c:function:: bool glm_uniscaled(mat4 m) + + returns true if matrix is uniform scaled. + This is helpful for creating normal matrix. + + Parameters: + | *[in]* **m** matrix + +.. c:function:: void glm_decompose_rs(mat4 m, mat4 r, vec3 s) + + decompose rotation matrix (mat4) and scale vector [Sx, Sy, Sz] + DON'T pass projected matrix here + + Parameters: + | *[in]* **m** affine transform + | *[out]* **r** rotation matrix + | *[out]* **s** scale matrix + +.. c:function:: void glm_decompose(mat4 m, vec4 t, mat4 r, vec3 s) + + decompose affine transform, TODO: extract shear factors. + DON'T pass projected matrix here + + Parameters: + | *[in]* **m** affine transfrom + | *[out]* **t** translation vector + | *[out]* **r** rotation matrix (mat4) + | *[out]* **s** scaling vector [X, Y, Z] diff --git a/docs/source/api.rst b/docs/source/api.rst index 5c54521..151238c 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -27,3 +27,4 @@ Follow the :doc:`build` documentation for this :caption: API categories: mat4 + affine diff --git a/include/cglm/affine.h b/include/cglm/affine.h index bc96510..10f190f 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -384,7 +384,7 @@ glm_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc) { /*! * @brief creates NEW rotation matrix by angle and axis * - * this name may change in the future. axis must be is normalized + * axis will be normalized so you don't need to normalize it * * @param[out] m affine transfrom * @param[in] angle angle (radians) From 96f773417a7de5e18f2bad94fbe2062f318b74e9 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 26 Feb 2018 12:16:09 +0300 Subject: [PATCH 012/292] docs: add docs for mat3 --- docs/source/api.rst | 3 +- docs/source/mat3.rst | 134 +++++++++++++++++++++++++++++++++++++++++++ docs/source/mat4.rst | 2 +- 3 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 docs/source/mat3.rst diff --git a/docs/source/api.rst b/docs/source/api.rst index 151238c..164dec4 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -26,5 +26,6 @@ Follow the :doc:`build` documentation for this :maxdepth: 2 :caption: API categories: - mat4 affine + mat4 + mat3 diff --git a/docs/source/mat3.rst b/docs/source/mat3.rst new file mode 100644 index 0000000..60e548c --- /dev/null +++ b/docs/source/mat3.rst @@ -0,0 +1,134 @@ +.. default-domain:: C + +mat3 +==== + +Header: cglm/mat3.h + +Table of contents (clik func/macro to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Macros: + +1. GLM_MAT3_IDENTITY_INIT +#. GLM_MAT3_ZERO_INIT +#. GLM_MAT3_IDENTITY +#. GLM_MAT3_ZERO +#. glm_mat3_dup(mat, dest) + +Functions: + +1. :c:func:`glm_mat3_copy` +#. :c:func:`glm_mat3_identity` +#. :c:func:`glm_mat3_mul` +#. :c:func:`glm_mat3_transpose_to` +#. :c:func:`glm_mat3_transpose` +#. :c:func:`glm_mat3_mulv` +#. :c:func:`glm_mat3_scale` +#. :c:func:`glm_mat3_det` +#. :c:func:`glm_mat3_inv` +#. :c:func:`glm_mat3_swap_col` +#. :c:func:`glm_mat3_swap_row` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_mat3_copy(mat3 mat, mat3 dest) + + copy mat3 to another one (dest). + + Parameters: + | *[in]* **mat** source + | *[out]* **dest** destination + +.. c:function:: void glm_mat3_identity(mat3 mat) + + copy identity mat3 to mat, or makes mat to identiy + + Parameters: + | *[out]* **mat** matrix + +.. 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 + + mat3 m = GLM_MAT3_IDENTITY_INIT; + glm_mat3_mul(m, m, m); + + Parameters: + | *[in]* **m1** left matrix + | *[in]* **m2** right matrix + | *[out]* **dest** destination matrix + +.. c:function:: void glm_mat3_transpose_to(mat3 m, mat3 dest) + + transpose mat4 and store in dest + source matrix will not be transposed unless dest is m + + Parameters: + | *[in]* **mat** source + | *[out]* **dest** destination + +.. c:function:: void glm_mat3_transpose(mat3 m) + + tranpose mat3 and store result in same matrix + + Parameters: + | *[in]* **mat** source + | *[out]* **dest** destination + +.. c:function:: void glm_mat3_mulv(mat3 m, vec3 v, vec3 dest) + + multiply mat4 with vec4 (column vector) and store in dest vector + + Parameters: + | *[in]* **mat** mat3 (left) + | *[in]* **v** vec3 (right, column vector) + | *[out]* **dest** destination (result, column vector) + +.. c:function:: void glm_mat3_scale(mat3 m, float s) + + multiply matrix with scalar + + Parameters: + | *[in, out]* **mat** matrix + | *[in]* **dest** scalar + +.. c:function:: float glm_mat3_det(mat3 mat) + + returns mat3 determinant + + Parameters: + | *[in]* **mat** matrix + + Returns: + mat3 determinant + +.. c:function:: void glm_mat3_inv(mat3 mat, mat3 dest) + + inverse mat3 and store in dest + + Parameters: + | *[in]* **mat** matrix + | *[out]* **dest** destination (inverse matrix) + +.. c:function:: void glm_mat3_swap_col(mat3 mat, int col1, int col2) + + swap two matrix columns + + Parameters: + | *[in, out]* **mat** matrix + | *[in]* **col1** col1 + | *[in]* **col2** col2 + +.. c:function:: void glm_mat3_swap_row(mat3 mat, int row1, int row2) + + swap two matrix rows + + Parameters: + | *[in, out]* **mat** matrix + | *[in]* **row1** row1 + | *[in]* **row2** row2 diff --git a/docs/source/mat4.rst b/docs/source/mat4.rst index dffe18a..27d9225 100644 --- a/docs/source/mat4.rst +++ b/docs/source/mat4.rst @@ -109,7 +109,7 @@ Functions documentation | *[in]* **m2** right matrix | *[out]* **dest** destination matrix -.. c:function:: glm_mat4_mulN(mat4 * __restrict matrices[], int len, mat4 dest) +.. c:function:: void glm_mat4_mulN(mat4 * __restrict matrices[], int len, mat4 dest) mupliply N mat4 matrices and store result in dest | this function lets you multiply multiple (more than two or more...) From 77e62163ea3b9403485e0538283f30fb2508a873 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 26 Feb 2018 16:21:04 +0300 Subject: [PATCH 013/292] docs: add docs for vec3 --- docs/source/affine.rst | 10 +- docs/source/api.rst | 1 + docs/source/vec3.rst | 273 +++++++++++++++++++++++++++++++++++++++++ include/cglm/vec3.h | 9 +- 4 files changed, 285 insertions(+), 8 deletions(-) create mode 100644 docs/source/vec3.rst diff --git a/docs/source/affine.rst b/docs/source/affine.rst index ee6c2ed..fdb2ef3 100644 --- a/docs/source/affine.rst +++ b/docs/source/affine.rst @@ -57,7 +57,7 @@ Functions documentation .. c:function:: void glm_translate(mat4 m, vec3 v) - translate existing transform matrix by v vector + translate existing transform matrix by *v* vector and stores result in same matrix Parameters: @@ -74,7 +74,7 @@ Functions documentation .. c:function:: void glm_translate_y(mat4 m, float y) - translate existing transform matrix by y factor + translate existing transform matrix by *y* factor Parameters: | *[in, out]* **m** affine transfrom @@ -82,7 +82,7 @@ Functions documentation .. c:function:: void glm_translate_z(mat4 m, float z) - translate existing transform matrix by z factor + translate existing transform matrix by *z* factor Parameters: | *[in, out]* **m** affine transfrom @@ -90,7 +90,7 @@ Functions documentation .. c:function:: void glm_translate_make(mat4 m, vec3 v) - creates NEW translate transform matrix by v vector + creates NEW translate transform matrix by *v* vector. Parameters: | *[in, out]* **m** affine transfrom @@ -98,7 +98,7 @@ Functions documentation .. c:function:: void glm_scale_to(mat4 m, vec3 v, mat4 dest) - scale existing transform matrix by v vector and store result in dest + scale existing transform matrix by *v* vector and store result in dest Parameters: | *[in]* **m** affine transfrom diff --git a/docs/source/api.rst b/docs/source/api.rst index 164dec4..57fe2b3 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -29,3 +29,4 @@ Follow the :doc:`build` documentation for this affine mat4 mat3 + vec3 diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst new file mode 100644 index 0000000..55a1dc8 --- /dev/null +++ b/docs/source/vec3.rst @@ -0,0 +1,273 @@ +.. default-domain:: C + +vec3 +==== + +Header: cglm/vec3.h + +We mostly use vectors in graphics math, to make writing code faster +and easy to read, some *vec3* functions are aliased in global namespace. +For instance :c:func:`glm_dot` is alias of :c:func:`glm_vec_dot`, +alias means inline wrapper here. There is no call verison of alias functions + +There are also functions for rotating *vec3* vector. **_m4**, **_m3** prefixes +rotate *vec3* with matrix. + +Table of contents (clik func/macro to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Macros: + +1. glm_vec_dup(v, dest) +#. GLM_VEC3_ONE_INIT +#. GLM_VEC3_ZERO_INIT +#. GLM_VEC3_ONE +#. GLM_VEC3_ZERO +#. GLM_YUP +#. GLM_ZUP +#. GLM_XUP + +Functions: + +1. :c:func:`glm_vec3` +#. :c:func:`glm_vec_copy` +#. :c:func:`glm_vec_dot` +#. :c:func:`glm_vec_cross` +#. :c:func:`glm_vec_norm2` +#. :c:func:`glm_vec_norm` +#. :c:func:`glm_vec_add` +#. :c:func:`glm_vec_sub` +#. :c:func:`glm_vec_scale` +#. :c:func:`glm_vec_scale_as` +#. :c:func:`glm_vec_flipsign` +#. :c:func:`glm_vec_inv` +#. :c:func:`glm_vec_inv_to` +#. :c:func:`glm_vec_normalize` +#. :c:func:`glm_vec_normalize_to` +#. :c:func:`glm_vec_distance` +#. :c:func:`glm_vec_angle` +#. :c:func:`glm_vec_rotate` +#. :c:func:`glm_vec_rotate_m4` +#. :c:func:`glm_vec_proj` +#. :c:func:`glm_vec_center` +#. :c:func:`glm_vec_maxv` +#. :c:func:`glm_vec_minv` +#. :c:func:`glm_vec_ortho` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_vec3(vec4 v4, vec3 dest) + + init vec3 using vec4 + + Parameters: + | *[in]* **v4** vector4 + | *[out]* **dest** destination + +.. c:function:: void glm_vec_copy(vec3 a, vec3 dest) + + copy all members of [a] to [dest] + + Parameters: + | *[in]* **a** source + | *[out]* **dest** destination + +.. c:function:: float glm_vec_dot(vec3 a, vec3 b) + + dot product of vec3 + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + + Returns: + dot product + +.. c:function:: void glm_vec_cross(vec3 a, vec3 b, vec3 d) + + cross product + + Parameters: + | *[in]* **a** source 1 + | *[in]* **b** source 2 + | *[out]* **d** destination + +.. c:function:: float glm_vec_norm2(vec3 v) + + norm * norm (magnitude) of vector + + we can use this func instead of calling norm * norm, because it would call + sqrtf fuction twice but with this func we can avoid func call, maybe this is + not good name for this func + + Parameters: + | *[in]* **v** vector + + Returns: + square of norm / magnitude + +.. c:function:: float glm_vec_norm(vec3 vec) + + norm (magnitude) of vec3 + + Parameters: + | *[in]* **vec** vector + +.. c:function:: void glm_vec_add(vec3 v1, vec3 v2, vec3 dest) + + add v2 vector to v1 vector store result in dest + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec_sub(vec3 v1, vec3 v2, vec3 dest) + + subtract v2 vector from v1 vector store result in dest + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec_scale(vec3 v, float s, vec3 dest) + + multiply/scale vec3 vector with scalar: result = v * s + + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec_scale_as(vec3 v, float s, vec3 dest) + + make vec3 vector scale as specified: result = unit(v) * s + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec_flipsign(vec3 v) + + flip sign of all vec3 members + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec_inv(vec3 v) + + make vector as inverse/opposite of itself + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec_inv_to(vec3 v, vec3 dest) + + inverse/opposite vector + + Parameters: + | *[in]* **v** source + | *[out]* **dest** destination + +.. c:function:: void glm_vec_normalize(vec3 v) + + normalize vec3 and store result in same vec + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec_normalize_to(vec3 vec, vec3 dest) + + normalize vec3 to dest + + Parameters: + | *[in]* **vec** source + | *[out]* **dest** destination + +.. c:function:: float glm_vec_angle(vec3 v1, vec3 v2) + + angle betwen two vector + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + + Return: + | angle as radians + +.. c:function:: void glm_vec_rotate(vec3 v, float angle, vec3 axis) + + rotate vec3 around axis by angle using Rodrigues' rotation formula + + Parameters: + | *[in, out]* **v** vector + | *[in]* **axis** axis vector (must be unit vector) + | *[out]* **angle** angle (radians) + +.. c:function:: void glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) + + apply rotation matrix to vector + + Parameters: + | *[in]* **m** affine matrix or rot matrix + | *[in]* **v** vector + | *[out]* **dest** rotated vector + +.. c:function:: void glm_vec_proj(vec3 a, vec3 b, vec3 dest) + + project a vector onto b vector + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + | *[out]* **dest** projected vector + +.. c:function:: void glm_vec_center(vec3 v1, vec3 v2, vec3 dest) + + find center point of two vector + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + | *[out]* **dest** center point + +.. c:function:: float glm_vec_distance(vec3 v1, vec3 v2) + + distance between two vectors + + Parameters: + | *[in]* **mat** vector1 + | *[in]* **row1** vector2 + + Returns: + | distance + +.. c:function:: void glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest) + + max values of vectors + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + | *[out]* **dest** destination + +.. c:function:: void glm_vec_minv(vec3 v1, vec3 v2, vec3 dest) + + min values of vectors + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + | *[out]* **dest** destination + +.. c:function:: void glm_vec_ortho(vec3 v, vec3 dest) + + possible orthogonal/perpendicular vector + + Parameters: + | *[in]* **mat** vector + | *[out]* **dest** orthogonal/perpendicular vector diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 8600711..26adf7d 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -135,8 +135,8 @@ glm_vec_cross(vec3 a, vec3 b, vec3 d) { /*! * @brief norm * norm (magnitude) of vec * - * we can use this func instead of calling norm * norm, because it would call - * sqrtf fuction twice but with this func we can avoid func call, maybe this is + * we can use this func instead of calling norm * norm, because it would call + * sqrtf fuction twice but with this func we can avoid func call, maybe this is * not good name for this func * * @param[in] v vector @@ -309,13 +309,16 @@ glm_vec_normalize_to(vec3 vec, vec3 dest) { /*! * @brief angle betwen two vector * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * * @return angle as radians */ CGLM_INLINE float glm_vec_angle(vec3 v1, vec3 v2) { float norm; - + /* maybe compiler generate approximation instruction (rcp) */ norm = 1.0f / (glm_vec_norm(v1) * glm_vec_norm(v2)); return acosf(glm_vec_dot(v1, v2) * norm); From be3f117374305453fe0c32f52ff6849a109f4f36 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 26 Feb 2018 17:10:33 +0300 Subject: [PATCH 014/292] docs: add docs for vec3-ext --- docs/source/api.rst | 1 + docs/source/vec3-ext.rst | 98 ++++++++++++++++++++++++++++++++++++++++ include/cglm/vec3-ext.h | 32 ++++++------- 3 files changed, 115 insertions(+), 16 deletions(-) create mode 100644 docs/source/vec3-ext.rst diff --git a/docs/source/api.rst b/docs/source/api.rst index 57fe2b3..40a30d5 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -30,3 +30,4 @@ Follow the :doc:`build` documentation for this mat4 mat3 vec3 + vec3-ext diff --git a/docs/source/vec3-ext.rst b/docs/source/vec3-ext.rst new file mode 100644 index 0000000..f93ff82 --- /dev/null +++ b/docs/source/vec3-ext.rst @@ -0,0 +1,98 @@ +.. default-domain:: C + +vec3 extra +========== + +Header: cglm/vec3-ext.h + +There are some functions are in called in extra header. These are called extra +because they are not used like other functions in vec3.h in the future some of +these functions ma be moved to vec3 header. + +Table of contents (clik func/macro to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_vec_mulv` +#. :c:func:`glm_vec_broadcast` +#. :c:func:`glm_vec_eq` +#. :c:func:`glm_vec_eq_eps` +#. :c:func:`glm_vec_eq_all` +#. :c:func:`glm_vec_eqv` +#. :c:func:`glm_vec_eqv_eps` +#. :c:func:`glm_vec_max` +#. :c:func:`glm_vec_min` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_vec_mulv(vec3 a, vec3 b, vec3 d) + + multiplies individual items + + Parameters: + | *[in]* **a** vec1 + | *[in]* **b** vec2 + | *[out]* **d** destination (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]) + +.. c:function:: void glm_vec_broadcast(float val, vec3 d) + + fill a vector with specified value + + Parameters: + | *[in]* **val** value + | *[out]* **dest** destination + +.. c:function:: bool glm_vec_eq(vec3 v, float val) + + check if vector is equal to value (without epsilon) + + Parameters: + | *[in]* **v** vector + | *[in]* **val** value + +.. c:function:: bool glm_vec_eq_eps(vec4 v, float val) + + check if vector is equal to value (with epsilon) + + Parameters: + | *[in]* **v** vector + | *[in]* **val** value + +.. c:function:: bool glm_vec_eq_all(vec3 v) + + check if vectors members are equal (without epsilon) + + Parameters: + | *[in]* **v** vector + +.. c:function:: bool glm_vec_eqv(vec3 v1, vec3 v2) + + check if vector is equal to another (without epsilon) vector + + Parameters: + | *[in]* **vec** vector 1 + | *[in]* **vec** vector 2 + +.. c:function:: bool glm_vec_eqv_eps(vec3 v1, vec3 v2) + + check if vector is equal to another (with epsilon) + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + +.. c:function:: float glm_vec_max(vec3 v) + + max value of vector + + Parameters: + | *[in]* **v** vector + +.. c:function:: float glm_vec_min(vec3 v) + + min value of vector + + Parameters: + | *[in]* **v** vector diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index 41c1749..c9bffe3 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -33,9 +33,9 @@ /*! * @brief multiplies individual items, just for convenient like SIMD * - * @param a vec1 - * @param b vec2 - * @param d vec3 = (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]) + * @param[in] a vec1 + * @param[in] b vec2 + * @param[out] d vec3 = (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]) */ CGLM_INLINE void @@ -48,8 +48,8 @@ glm_vec_mulv(vec3 a, vec3 b, vec3 d) { /*! * @brief fill a vector with specified value * - * @param val value - * @param d dest + * @param[in] val value + * @param[out] d dest */ CGLM_INLINE void @@ -60,8 +60,8 @@ glm_vec_broadcast(float val, vec3 d) { /*! * @brief check if vector is equal to value (without epsilon) * - * @param v vector - * @param val value + * @param[in] v vector + * @param[in] val value */ CGLM_INLINE bool @@ -72,8 +72,8 @@ glm_vec_eq(vec3 v, float val) { /*! * @brief check if vector is equal to value (with epsilon) * - * @param v vector - * @param val value + * @param[in] v vector + * @param[in] val value */ CGLM_INLINE bool @@ -86,7 +86,7 @@ glm_vec_eq_eps(vec4 v, float val) { /*! * @brief check if vectors members are equal (without epsilon) * - * @param v vector + * @param[in] v vector */ CGLM_INLINE bool @@ -97,8 +97,8 @@ glm_vec_eq_all(vec3 v) { /*! * @brief check if vector is equal to another (without epsilon) * - * @param v1 vector - * @param v2 vector + * @param[in] v1 vector + * @param[in] v2 vector */ CGLM_INLINE bool @@ -111,8 +111,8 @@ glm_vec_eqv(vec3 v1, vec3 v2) { /*! * @brief check if vector is equal to another (with epsilon) * - * @param v1 vector - * @param v2 vector + * @param[in] v1 vector + * @param[in] v2 vector */ CGLM_INLINE bool @@ -125,7 +125,7 @@ glm_vec_eqv_eps(vec3 v1, vec3 v2) { /*! * @brief max value of vector * - * @param v vector + * @param[in] v vector */ CGLM_INLINE float @@ -144,7 +144,7 @@ glm_vec_max(vec3 v) { /*! * @brief min value of vector * - * @param v vector + * @param[in] v vector */ CGLM_INLINE float From 23698b7e48645592a98140da0f6fd4c740251ea5 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 26 Feb 2018 22:08:04 +0300 Subject: [PATCH 015/292] docs: add docs for vec4 --- docs/source/api.rst | 2 + docs/source/vec3-ext.rst | 2 +- docs/source/vec4-ext.rst | 98 +++++++++++++++++++ docs/source/vec4.rst | 205 +++++++++++++++++++++++++++++++++++++++ include/cglm/vec4.h | 2 +- 5 files changed, 307 insertions(+), 2 deletions(-) create mode 100644 docs/source/vec4-ext.rst create mode 100644 docs/source/vec4.rst diff --git a/docs/source/api.rst b/docs/source/api.rst index 40a30d5..2caa11e 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -31,3 +31,5 @@ Follow the :doc:`build` documentation for this mat3 vec3 vec3-ext + vec4 + vec4-ext diff --git a/docs/source/vec3-ext.rst b/docs/source/vec3-ext.rst index f93ff82..112e2a3 100644 --- a/docs/source/vec3-ext.rst +++ b/docs/source/vec3-ext.rst @@ -52,7 +52,7 @@ Functions documentation | *[in]* **v** vector | *[in]* **val** value -.. c:function:: bool glm_vec_eq_eps(vec4 v, float val) +.. c:function:: bool glm_vec_eq_eps(vec3 v, float val) check if vector is equal to value (with epsilon) diff --git a/docs/source/vec4-ext.rst b/docs/source/vec4-ext.rst new file mode 100644 index 0000000..d9c6e0b --- /dev/null +++ b/docs/source/vec4-ext.rst @@ -0,0 +1,98 @@ +.. default-domain:: C + +vec4 extra +========== + +Header: cglm/vec4-ext.h + +There are some functions are in called in extra header. These are called extra +because they are not used like other functions in vec4.h in the future some of +these functions ma be moved to vec4 header. + +Table of contents (clik func/macro to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_vec4_mulv` +#. :c:func:`glm_vec4_broadcast` +#. :c:func:`glm_vec4_eq` +#. :c:func:`glm_vec4_eq_eps` +#. :c:func:`glm_vec4_eq_all` +#. :c:func:`glm_vec4_eqv` +#. :c:func:`glm_vec4_eqv_eps` +#. :c:func:`glm_vec4_max` +#. :c:func:`glm_vec4_min` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_vec4_mulv(vec4 a, vec4 b, vec4 d) + + multiplies individual items + + Parameters: + | *[in]* **a** vec1 + | *[in]* **b** vec2 + | *[out]* **d** destination + +.. c:function:: void glm_vec4_broadcast(float val, vec4 d) + + fill a vector with specified value + + Parameters: + | *[in]* **val** value + | *[out]* **dest** destination + +.. c:function:: bool glm_vec4_eq(vec4 v, float val) + + check if vector is equal to value (without epsilon) + + Parameters: + | *[in]* **v** vector + | *[in]* **val** value + +.. c:function:: bool glm_vec4_eq_eps(vec4 v, float val) + + check if vector is equal to value (with epsilon) + + Parameters: + | *[in]* **v** vector + | *[in]* **val** value + +.. c:function:: bool glm_vec4_eq_all(vec4 v) + + check if vectors members are equal (without epsilon) + + Parameters: + | *[in]* **v** vector + +.. c:function:: bool glm_vec4_eqv(vec4 v1, vec4 v2) + + check if vector is equal to another (without epsilon) vector + + Parameters: + | *[in]* **vec** vector 1 + | *[in]* **vec** vector 2 + +.. c:function:: bool glm_vec4_eqv_eps(vec4 v1, vec4 v2) + + check if vector is equal to another (with epsilon) + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + +.. c:function:: float glm_vec4_max(vec4 v) + + max value of vector + + Parameters: + | *[in]* **v** vector + +.. c:function:: float glm_vec4_min(vec4 v) + + min value of vector + + Parameters: + | *[in]* **v** vector diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst new file mode 100644 index 0000000..5409c1e --- /dev/null +++ b/docs/source/vec4.rst @@ -0,0 +1,205 @@ +.. default-domain:: C + +vec4 +==== + +Header: cglm/vec4.h + +Table of contents (clik func/macro to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Macros: + +1. glm_vec4_dup3(v, dest) +#. glm_vec4_dup(v, dest) +#. GLM_VEC4_ONE_INIT +#. GLM_VEC4_BLACK_INIT +#. GLM_VEC4_ZERO_INIT +#. GLM_VEC4_ONE +#. GLM_VEC4_BLACK +#. GLM_VEC4_ZERO + +Functions: + +1. :c:func:`glm_vec4` +#. :c:func:`glm_vec4_copy3` +#. :c:func:`glm_vec4_copy` +#. :c:func:`glm_vec4_dot` +#. :c:func:`glm_vec4_norm2` +#. :c:func:`glm_vec4_norm` +#. :c:func:`glm_vec4_add` +#. :c:func:`glm_vec4_sub` +#. :c:func:`glm_vec4_scale` +#. :c:func:`glm_vec4_scale_as` +#. :c:func:`glm_vec4_flipsign` +#. :c:func:`glm_vec4_inv` +#. :c:func:`glm_vec4_inv_to` +#. :c:func:`glm_vec4_normalize` +#. :c:func:`glm_vec4_normalize_to` +#. :c:func:`glm_vec4_distance` +#. :c:func:`glm_vec4_maxv` +#. :c:func:`glm_vec4_minv` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_vec4(vec3 v3, float last, vec4 dest) + + init vec4 using vec3, since you are initializing vec4 with vec3 + you need to set last item. cglm could set it zero but making it parameter + gives more control + + Parameters: + | *[in]* **v3** vector4 + | *[in]* **last** last item of vec4 + | *[out]* **dest** destination + +.. c:function:: void glm_vec4_copy3(vec4 a, vec3 dest) + + copy first 3 members of [a] to [dest] + + Parameters: + | *[in]* **a** source + | *[out]* **dest** destination + +.. c:function:: void glm_vec4_copy(vec4 v, vec4 dest) + + copy all members of [a] to [dest] + + Parameters: + | *[in]* **v** source + | *[in]* **dest** destination + +.. c:function:: float glm_vec4_dot(vec4 a, vec4 b) + + dot product of vec4 + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + + Returns: + dot product + +.. c:function:: float glm_vec4_norm2(vec4 v) + + norm * norm (magnitude) of vector + + we can use this func instead of calling norm * norm, because it would call + sqrtf fuction twice but with this func we can avoid func call, maybe this is + not good name for this func + + Parameters: + | *[in]* **v** vector + + Returns: + square of norm / magnitude + +.. c:function:: float glm_vec4_norm(vec4 vec) + + norm (magnitude) of vec4 + + Parameters: + | *[in]* **vec** vector + +.. c:function:: void glm_vec4_add(vec4 v1, vec4 v2, vec4 dest) + + add v2 vector to v1 vector store result in dest + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec4_sub(vec4 v1, vec4 v2, vec4 dest) + + subtract v2 vector from v1 vector store result in dest + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec4_scale(vec4 v, float s, vec4 dest) + + multiply/scale vec4 vector with scalar: result = v * s + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec4_scale_as(vec4 v, float s, vec4 dest) + + make vec4 vector scale as specified: result = unit(v) * s + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec4_flipsign(vec4 v) + + flip sign of all vec4 members + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec4_inv(vec4 v) + + make vector as inverse/opposite of itself + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec4_inv_to(vec4 v, vec4 dest) + + inverse/opposite vector + + Parameters: + | *[in]* **v** source + | *[out]* **dest** destination + +.. c:function:: void glm_vec4_normalize(vec4 v) + + normalize vec4 and store result in same vec + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec4_normalize_to(vec4 vec, vec4 dest) + + normalize vec4 to dest + + Parameters: + | *[in]* **vec** source + | *[out]* **dest** destination + +.. c:function:: float glm_vec4_distance(vec4 v1, vec4 v2) + + distance between two vectors + + Parameters: + | *[in]* **mat** vector1 + | *[in]* **row1** vector2 + + Returns: + | distance + +.. c:function:: void glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest) + + max values of vectors + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + | *[out]* **dest** destination + +.. c:function:: void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest) + + min values of vectors + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + | *[out]* **dest** destination diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index e0dfae8..a656166 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -20,7 +20,7 @@ GLM_VEC4_ONE GLM_VEC4_BLACK GLM_VEC4_ZERO - + Functions: CGLM_INLINE void glm_vec4(vec3 v3, float last, vec4 dest); CGLM_INLINE void glm_vec4_copy3(vec4 a, vec3 dest); From 425bf87c1fef7487cc897038ae6eb75e6a4895db Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 26 Feb 2018 23:23:31 +0300 Subject: [PATCH 016/292] docs: add docs for camera --- docs/source/api.rst | 1 + docs/source/cam.rst | 298 ++++++++++++++++++++++++++++++++++++++++++++ include/cglm/cam.h | 104 ++++++++-------- 3 files changed, 349 insertions(+), 54 deletions(-) create mode 100644 docs/source/cam.rst diff --git a/docs/source/api.rst b/docs/source/api.rst index 2caa11e..94164b1 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -27,6 +27,7 @@ Follow the :doc:`build` documentation for this :caption: API categories: affine + cam mat4 mat3 vec3 diff --git a/docs/source/cam.rst b/docs/source/cam.rst new file mode 100644 index 0000000..2725334 --- /dev/null +++ b/docs/source/cam.rst @@ -0,0 +1,298 @@ +.. default-domain:: C + +Camera +====== + +Header: cglm/cam.h + +There are many convenient functions for camera. For instance :c:func:`glm_look` +is just wrapper for :c:func:`glm_lookat`. Sometimes you only have direction +instead of target, so that makes easy to build view matrix using direction. +There is also :c:func:`glm_look_anyup` function which can help build view matrix +without providing UP axis. It uses :c:func:`glm_vec_ortho` to get a UP axis and +builds view matrix. + +You can also *_default* versions of ortho and perspective to build projection +fast if you don't care specific projection values. + +*_decomp* means decompose; these function can help to decompose projection +matrices. + + **NOTE**: Be careful when working with high range (very small near, very large + far) projection matrices. You may not get exact value you gave. + **float** type cannot store very high precision so you will lose precision. + Also your projection matrix will be inaccurate due to losing precision + +Table of contents (clik func/macro to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_frustum` +#. :c:func:`glm_ortho` +#. :c:func:`glm_ortho_aabb` +#. :c:func:`glm_ortho_aabb_p` +#. :c:func:`glm_ortho_aabb_pz` +#. :c:func:`glm_ortho_default` +#. :c:func:`glm_ortho_default_s` +#. :c:func:`glm_perspective` +#. :c:func:`glm_perspective_default` +#. :c:func:`glm_perspective_resize` +#. :c:func:`glm_lookat` +#. :c:func:`glm_look` +#. :c:func:`glm_look_anyup` +#. :c:func:`glm_persp_decomp` +#. :c:func:`glm_persp_decompv` +#. :c:func:`glm_persp_decomp_x` +#. :c:func:`glm_persp_decomp_y` +#. :c:func:`glm_persp_decomp_z` +#. :c:func:`glm_persp_decomp_far` +#. :c:func:`glm_persp_decomp_near` +#. :c:func:`glm_persp_fovy` +#. :c:func:`glm_persp_aspect` +#. :c:func:`glm_persp_sizes` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_frustum(float left, float right, float bottom, float top, float nearVal, float farVal, mat4 dest) + + | set up perspective peprojection matrix + + Parameters: + | *[in]* **left** viewport.left + | *[in]* **right** viewport.right + | *[in]* **bottom** viewport.bottom + | *[in]* **top** viewport.top + | *[in]* **nearVal** near clipping plane + | *[in]* **farVal** far clipping plane + | *[out]* **dest** result matrix + +.. c:function:: void glm_ortho(float left, float right, float bottom, float top, float nearVal, float farVal, mat4 dest) + + | set up orthographic projection matrix + + Parameters: + | *[in]* **left** viewport.left + | *[in]* **right** viewport.right + | *[in]* **bottom** viewport.bottom + | *[in]* **top** viewport.top + | *[in]* **nearVal** near clipping plane + | *[in]* **farVal** far clipping plane + | *[out]* **dest** result matrix + +.. c:function:: void glm_ortho_aabb(vec3 box[2], mat4 dest) + + | set up orthographic projection matrix using bounding box + | bounding box (AABB) must be in view space + + Parameters: + | *[in]* **box** AABB + | *[in]* **dest** result matrix + +.. c:function:: void glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) + + | set up orthographic projection matrix using bounding box + | bounding box (AABB) must be in view space + + this version adds padding to box + + Parameters: + | *[in]* **box** AABB + | *[in]* **padding** padding + | *[out]* **d** result matrix + +.. c:function:: void glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) + + | set up orthographic projection matrix using bounding box + | bounding box (AABB) must be in view space + + this version adds Z padding to box + + Parameters: + | *[in]* **box** AABB + | *[in]* **padding** padding for near and far + | *[out]* **d** result matrix + + Returns: + square of norm / magnitude + +.. c:function:: void glm_ortho_default(float aspect, mat4 dest) + + | set up unit orthographic projection matrix + + Parameters: + | *[in]* **aspect** aspect ration ( width / height ) + | *[out]* **dest** result matrix + +.. c:function:: void glm_ortho_default_s(float aspect, float size, mat4 dest) + + | set up orthographic projection matrix with given CUBE size + + Parameters: + | *[in]* **aspect** aspect ration ( width / height ) + | *[in]* **size** cube size + | *[out]* **dest** result matrix + +.. c:function:: void glm_perspective(float fovy, float aspect, float nearVal, float farVal, mat4 dest) + + | set up perspective projection matrix + + Parameters: + | *[in]* **fovy** field of view angle + | *[in]* **aspect** aspect ratio ( width / height ) + | *[in]* **nearVal** near clipping plane + | *[in]* **farVal** far clipping planes + | *[out]* **dest** result matrix + +.. c:function:: void glm_perspective_default(float aspect, mat4 dest) + + | set up perspective projection matrix with default near/far + and angle values + + Parameters: + | *[in]* **aspect** aspect aspect ratio ( width / height ) + | *[out]* **dest** result matrix + +.. c:function:: void glm_perspective_resize(float aspect, mat4 proj) + + | resize perspective matrix by aspect ratio ( width / height ) + this makes very easy to resize proj matrix when window / viewport reized + + Parameters: + | *[in]* **aspect** aspect ratio ( width / height ) + | *[in, out]* **proj** perspective projection matrix + +.. c:function:: void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) + + | set up view matrix + + Parameters: + | *[in]* **eye** eye vector + | *[in]* **center** center vector + | *[in]* **up** up vector + | *[out]* **dest** result matrix + +.. c:function:: void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) + + | set up view matrix + + convenient wrapper for :c:func:`glm_lookat`: if you only have direction not + target self then this might be useful. Because you need to get target + from direction. + + Parameters: + | *[in]* **eye** eye vector + | *[in]* **center** direction vector + | *[in]* **up** up vector + | *[out]* **dest** result matrix + +.. c:function:: void glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) + + | set up view matrix + + convenient wrapper for :c:func:`glm_look` if you only have direction + and if you don't care what UP vector is then this might be useful + to create view matrix + + Parameters: + | *[in]* **eye** eye vector + | *[in]* **center** direction vector + | *[out]* **dest** result matrix + +.. c:function:: void glm_persp_decomp(mat4 proj, float *nearVal, float *farVal, float *top, float *bottom, float *left, float *right) + + | decomposes frustum values of perspective projection. + + Parameters: + | *[in]* **eye** perspective projection matrix + | *[out]* **nearVal** near + | *[out]* **farVal** far + | *[out]* **top** top + | *[out]* **bottom** bottom + | *[out]* **left** left + | *[out]* **right** right + +.. c:function:: void glm_persp_decompv(mat4 proj, float dest[6]) + + | decomposes frustum values of perspective projection. + | this makes easy to get all values at once + + Parameters: + | *[in]* **proj** perspective projection matrix + | *[out]* **dest** array + +.. c:function:: void glm_persp_decomp_x(mat4 proj, float *left, float *right) + + | decomposes left and right values of perspective projection. + | x stands for x axis (left / right axis) + + Parameters: + | *[in]* **proj** perspective projection matrix + | *[out]* **left** left + | *[out]* **right** right + +.. c:function:: void glm_persp_decomp_y(mat4 proj, float *top, float *bottom) + + | decomposes top and bottom values of perspective projection. + | y stands for y axis (top / botom axis) + + Parameters: + | *[in]* **proj** perspective projection matrix + | *[out]* **top** top + | *[out]* **bottom** bottom + +.. c:function:: void glm_persp_decomp_z(mat4 proj, float *nearVal, float *farVal) + + | decomposes near and far values of perspective projection. + | z stands for z axis (near / far axis) + + Parameters: + | *[in]* **proj** perspective projection matrix + | *[out]* **nearVal** near + | *[out]* **farVal** far + +.. c:function:: void glm_persp_decomp_far(mat4 proj, float * __restrict farVal) + + | decomposes far value of perspective projection. + + Parameters: + | *[in]* **proj** perspective projection matrix + | *[out]* **farVal** far + +.. c:function:: void glm_persp_decomp_near(mat4 proj, float * __restrict nearVal) + + | decomposes near value of perspective projection. + + Parameters: + | *[in]* **proj** perspective projection matrix + | *[out]* **nearVal** near + +.. c:function:: float glm_persp_fovy(mat4 proj) + + | returns field of view angle along the Y-axis (in radians) + + if you need to degrees, use glm_deg to convert it or use this: + fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) + + Parameters: + | *[in]* **proj** perspective projection matrix + + Returns: + | fovy in radians + +.. c:function:: float glm_persp_aspect(mat4 proj) + + | returns aspect ratio of perspective projection + + Parameters: + | *[in]* **proj** perspective projection matrix + +.. c:function:: void glm_persp_sizes(mat4 proj, float fovy, vec4 dest) + + | returns sizes of near and far planes of perspective projection + + Parameters: + | *[in]* **proj** perspective projection matrix + | *[in]* **fovy** fovy (see brief) + | *[out]* **dest** sizes order: [Wnear, Hnear, Wfar, Hfar] diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 9290ffa..acd573c 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -7,54 +7,53 @@ /* Functions: - CGLM_INLINE void glm_frustum(float left, - float right, - float bottom, - float top, - float nearVal, - float farVal, - mat4 dest); - CGLM_INLINE void glm_ortho(float left, - float right, - float bottom, - float top, - float nearVal, - float farVal, - mat4 dest); - CGLM_INLINE void glm_ortho_default(float aspect, mat4 dest); - CGLM_INLINE void glm_ortho_default_s(float aspect, float size, mat4 dest); - CGLM_INLINE void glm_perspective(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest); - CGLM_INLINE void glm_perspective_default(float aspect, mat4 dest); - CGLM_INLINE void glm_perspective_resize(float aspect, mat4 proj); - CGLM_INLINE void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest); - CGLM_INLINE void glm_persp_decomp(mat4 proj, - float * __restrict nearVal, - float * __restrict farVal, - float * __restrict top, - float * __restrict bottom, - float * __restrict left, - float * __restrict right); - CGLM_INLINE void glm_persp_decompv(mat4 proj, float dest[6]); - CGLM_INLINE void glm_persp_decomp_x(mat4 proj, - float * __restrict left, - float * __restrict right); - CGLM_INLINE void glm_persp_decomp_y(mat4 proj, - float * __restrict top, - float * __restrict bottom); - CGLM_INLINE void glm_persp_decomp_z(mat4 proj, - float * __restrict nearVal, - float * __restrict farVal); - CGLM_INLINE void glm_persp_decomp_far(mat4 proj, float * __restrict farVal); - CGLM_INLINE void glm_persp_decomp_near(mat4 proj, float *__restrict nearVal); - CGLM_INLINE void glm_frustum_planes(mat4 m, vec4 dest[6]); - CGLM_INLINE void glm_frustum_corners(mat4 invMat, vec4 dest[8]); - CGLM_INLINE glm_ortho_box(vec3 box[2], mat4 dest); - CGLM_INLINE void glm_ortho_boxp(vec3 box[2], float padding, mat4 dest); - CGLM_INLINE void glm_ortho_boxp(vec3 box[2], float padding, mat4 dest); + CGLM_INLINE void glm_frustum(float left, + float right, + float bottom, + float top, + float nearVal, + float farVal, + mat4 dest) + CGLM_INLINE void glm_ortho(float left, + float right, + float bottom, + float top, + float nearVal, + float farVal, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb(vec3 box[2], mat4 dest) + CGLM_INLINE void glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) + CGLM_INLINE void glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) + CGLM_INLINE void glm_ortho_default(float aspect, mat4 dest) + CGLM_INLINE void glm_ortho_default_s(float aspect, float size, mat4 dest) + CGLM_INLINE void glm_perspective(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) + CGLM_INLINE void glm_perspective_default(float aspect, mat4 dest) + CGLM_INLINE void glm_perspective_resize(float aspect, mat4 proj) + CGLM_INLINE void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) + CGLM_INLINE void glm_persp_decomp(mat4 proj, + float *nearVal, + float *farVal, + float *top, + float *bottom, + float *left, + float *right) + CGLM_INLINE void glm_persp_decompv(mat4 proj, float dest[6]) + CGLM_INLINE void glm_persp_decomp_x(mat4 proj, float *left, float *right) + CGLM_INLINE void glm_persp_decomp_y(mat4 proj, float *top, float *bottom) + CGLM_INLINE void glm_persp_decomp_z(mat4 proj, + float *nearVal, + float *farVal) + CGLM_INLINE void glm_persp_decomp_far(mat4 proj, float *farVal) + CGLM_INLINE void glm_persp_decomp_near(mat4 proj, float *nearVal) + CGLM_INLINE float glm_persp_fovy(mat4 proj) + CGLM_INLINE float glm_persp_aspect(mat4 proj) + CGLM_INLINE void glm_persp_sizes(mat4 proj, float fovy, vec4 dest) */ #ifndef cglm_vcam_h @@ -303,7 +302,7 @@ glm_perspective_default(float aspect, /*! * @brief resize perspective matrix by aspect ratio ( width / height ) - * this very make easy to resize proj matrix when window, viewport + * this makes very easy to resize proj matrix when window /viewport * reized * * @param[in] aspect aspect ratio ( width / height ) @@ -458,7 +457,7 @@ glm_persp_decompv(mat4 proj, float dest[6]) { * @brief decomposes left and right values of perspective projection. * x stands for x axis (left / right axis) * - * @param[in] proj perspective projection matrix + * @param[in] proj perspective projection matrix * @param[out] left left * @param[out] right right */ @@ -572,10 +571,7 @@ glm_persp_aspect(mat4 proj) { } /*! - * @brief returns aspect ratio of perspective projection - * - * if you don't have fovy then use glm_persp_fovy(proj) to get it - * or pass directly: glm_persp_sizes(proj, glm_persp_fovy(proj), sizes); + * @brief returns sizes of near and far planes of perspective projection * * @param[in] proj perspective projection matrix * @param[in] fovy fovy (see brief) From a610626693468d6f056e1a3aa873f8602a40a526 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 26 Feb 2018 23:24:43 +0300 Subject: [PATCH 017/292] fix vec4 parameter type --- include/cglm/vec3-ext.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index c9bffe3..99e778a 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -14,7 +14,7 @@ CGLM_INLINE void glm_vec_mulv(vec3 a, vec3 b, vec3 d); CGLM_INLINE void glm_vec_broadcast(float val, vec3 d); CGLM_INLINE bool glm_vec_eq(vec3 v, float val); - CGLM_INLINE bool glm_vec_eq_eps(vec4 v, float val); + CGLM_INLINE bool glm_vec_eq_eps(vec3 v, float val); CGLM_INLINE bool glm_vec_eq_all(vec3 v); CGLM_INLINE bool glm_vec_eqv(vec3 v1, vec3 v2); CGLM_INLINE bool glm_vec_eqv_eps(vec3 v1, vec3 v2); @@ -77,7 +77,7 @@ glm_vec_eq(vec3 v, float val) { */ CGLM_INLINE bool -glm_vec_eq_eps(vec4 v, float val) { +glm_vec_eq_eps(vec3 v, float val) { return fabsf(v[0] - val) <= FLT_EPSILON && fabsf(v[1] - val) <= FLT_EPSILON && fabsf(v[2] - val) <= FLT_EPSILON; From b737bb2ddefdc0a93a1b4b279931b3b7ad5715f9 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 27 Feb 2018 10:53:45 +0300 Subject: [PATCH 018/292] docs: add docs for affine matrix --- docs/source/affine-mat.rst | 77 ++++++++++++++++++++++++++++++++++++++ docs/source/api.rst | 1 + 2 files changed, 78 insertions(+) create mode 100644 docs/source/affine-mat.rst diff --git a/docs/source/affine-mat.rst b/docs/source/affine-mat.rst new file mode 100644 index 0000000..0d09e12 --- /dev/null +++ b/docs/source/affine-mat.rst @@ -0,0 +1,77 @@ +.. default-domain:: C + +Affine Transform Matrix (Specialized Functions) +================================================================================ + +Header: cglm/affine-mat.h + +We mostly use glm_mat4_* for 4x4 general and transform matrices. **cglm** +provides optimized version of some functions. Because affine transform matrix is +a known format, for instance all last item of first three columns is zero. + +You should be careful when using these functions. For instance :c:func:`glm_mul` +assumes matrix will be this format: + +.. code-block:: text + + R R R X + R R R Y + R R R Z + 0 0 0 W + +if you override zero values here then use :c:func:`glm_mat4_mul` version. +You cannot use :c:func:`glm_mul` anymore. + +Same is also true for :c:func:`glm_inv_tr` if you only have rotation and +translation then it will work as expected, otherwise you cannot use that. + +In the future it may accept scale factors too but currectly it does not. + +Table of contents (click func go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_mul` +#. :c:func:`glm_inv_tr` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_mul(mat4 m1, mat4 m2, mat4 dest) + + | this is similar to glm_mat4_mul but specialized to affine transform + + Matrix format should be: + + .. code-block:: text + + R R R X + R R R Y + R R R Z + 0 0 0 W + + this reduces some multiplications. It should be faster than mat4_mul. + if you are not sure about matrix format then DON'T use this! use mat4_mul + + Parameters: + | *[in]* **m1** affine matrix 1 + | *[in]* **m2** affine matrix 2 + | *[out]* **dest** result matrix + +.. c:function:: void glm_inv_tr(mat4 mat) + + | inverse orthonormal rotation + translation matrix (ridig-body) + + .. code-block:: text + + X = | R T | X' = | R' -R'T | + | 0 1 | | 0 1 | + + use this if you only have rotation + translation, this should work faster + than :c:func:`glm_mat4_inv` + + Don't use this if your matrix includes other things e.g. scale, shear... + + Parameters: + | *[in,out]* **mat** affine matrix diff --git a/docs/source/api.rst b/docs/source/api.rst index 94164b1..01515cf 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -27,6 +27,7 @@ Follow the :doc:`build` documentation for this :caption: API categories: affine + affine-mat cam mat4 mat3 From b3a39aa13c1a8f70e0fc4699abce425cc2708484 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 27 Feb 2018 11:14:03 +0300 Subject: [PATCH 019/292] docs: add docs for quaternions --- docs/source/api.rst | 1 + docs/source/quat.rst | 124 +++++++++++++++++++++++++++++++++++++++++++ docs/source/vec3.rst | 2 +- 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 docs/source/quat.rst diff --git a/docs/source/api.rst b/docs/source/api.rst index 01515cf..496b9ca 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -29,6 +29,7 @@ Follow the :doc:`build` documentation for this affine affine-mat cam + quat mat4 mat3 vec3 diff --git a/docs/source/quat.rst b/docs/source/quat.rst new file mode 100644 index 0000000..064aa19 --- /dev/null +++ b/docs/source/quat.rst @@ -0,0 +1,124 @@ +.. default-domain:: C + +Quaternions +=========== + +Header: cglm/quat.h + + **Important:** *cglm* stores quaternion as [w, x, y, z] in memory, don't + forget that when changing quaternion items manually. For instance *quat[3]* + is *quat.z* and *quat[0*] is *quat.w*. This may change in the future if *cglm* + will got enough request to do that. Probably it will not be changed in near + future + +There are some TODOs for quaternions check TODO list to see them. + +Also **versor** is identity quaternion so the type may change to **vec4** or +something else. This will not affect existing functions for your engine because +*versor* is alias of *vec4* + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Macros: + +1. GLM_QUAT_IDENTITY_INIT +#. GLM_QUAT_IDENTITY + +Functions: + +1. :c:func:`glm_quat_identity` +#. :c:func:`glm_quat` +#. :c:func:`glm_quatv` +#. :c:func:`glm_quat_norm` +#. :c:func:`glm_quat_normalize` +#. :c:func:`glm_quat_dot` +#. :c:func:`glm_quat_mulv` +#. :c:func:`glm_quat_mat4` +#. :c:func:`glm_quat_slerp` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_quat_identity(versor q) + + | makes given quat to identity + + Parameters: + | *[in, out]* **q** quaternion + +.. c:function:: void glm_quat(versor q, float angle, float x, float y, float z) + + | creates NEW quaternion with individual axis components + + Parameters: + | *[out]* **q** quaternion + | *[in]* **angle** angle (radians) + | *[in]* **x** axis.x + | *[in]* **y** axis.y + | *[in]* **z** axis.z + +.. c:function:: void glm_quatv(versor q, float angle, vec3 v) + + | creates NEW quaternion with axis vector + + Parameters: + | *[out]* **q** quaternion + | *[in]* **angle** angle (radians) + | *[in]* **v** axis + +.. c:function:: float glm_quat_norm(versor q) + + | returns norm (magnitude) of quaternion + + Parameters: + | *[in]* **a** quaternion + + Returns: + norm (magnitude) + +.. c:function:: void glm_quat_normalize(versor q) + + | normalize quaternion + + Parameters: + | *[in, out]* **q** quaternion + +.. c:function:: float glm_quat_dot(versor q, versor r) + + dot product of two quaternion + + Parameters: + | *[in]* **q1** quaternion 1 + | *[in]* **q2** quaternion 2 + + Returns: + dot product + +.. c:function:: void glm_quat_mulv(versor q1, versor q2, versor dest) + + | multiplies two quaternion and stores result in dest + + Parameters: + | *[in]* **q1** quaternion 1 + | *[in]* **q2** quaternion 2 + | *[out]* **dest** result quaternion + +.. c:function:: void glm_quat_mat4(versor q, mat4 dest) + + | convert quaternion to mat4 + + Parameters: + | *[in]* **q** quaternion + | *[out]* **dest** result matrix + +.. c:function:: void glm_quat_slerp(versor q, versor r, float t, versor dest) + + | interpolates between two quaternions + | using spherical linear interpolation (SLERP) + + Parameters: + | *[in]* **q** from + | *[in]* **r** to + | *[in]* **t** amout + | *[out]* **dest** result quaternion diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index 55a1dc8..4458362 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -67,7 +67,7 @@ Functions documentation .. c:function:: void glm_vec_copy(vec3 a, vec3 dest) - copy all members of [a] to [dest] + copy all members of [a] to [dest] Parameters: | *[in]* **a** source From 1fd0a744786a8ef74e11c024a4fc39f4caabef97 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 1 Mar 2018 18:27:56 +0300 Subject: [PATCH 020/292] docs: euler angles documentation --- docs/source/api.rst | 1 + docs/source/euler.rst | 171 ++++++++++++++++++++++++++++++++++++++++++ include/cglm/euler.h | 54 ++++++++++--- 3 files changed, 216 insertions(+), 10 deletions(-) create mode 100644 docs/source/euler.rst diff --git a/docs/source/api.rst b/docs/source/api.rst index 496b9ca..7db4f83 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -30,6 +30,7 @@ Follow the :doc:`build` documentation for this affine-mat cam quat + euler mat4 mat3 vec3 diff --git a/docs/source/euler.rst b/docs/source/euler.rst new file mode 100644 index 0000000..1cf64ed --- /dev/null +++ b/docs/source/euler.rst @@ -0,0 +1,171 @@ +.. default-domain:: C + +Euler Angles +============ + +Header: cglm/euler.h + +You may wonder what **glm_euler_sq** type ( **_sq** stands for sequence ) and +:c:func:`glm_euler_by_order` do. +I used them to convert euler angles in one coordinate system to another. For +instance if you have **Z_UP** euler angles and if you want to convert it +to **Y_UP** axis then :c:func:`glm_euler_by_order` is your friend. For more +information check :c:func:`glm_euler_order` documentation + +You must pass arrays as array, if you use C compiler then you can use something +like this: + +.. code-block:: c + + float pitch, yaw, roll; + mat4 rot; + + /* pitch = ...; yaw = ...; roll = ... */ + glm_euler((vec3){pitch, yaw, roll}, rot); + +Rotation Conveniention +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Current *cglm*'s euler functions uses these convention: + +* Tait–Bryan angles (x-y-z convention) +* Intrinsic rotations (pitch, yaw and roll). + This is reserve order of extrinsic (elevation, heading and bank) rotation +* Right hand rule (actually all rotations in *cglm* use **RH**) +* All angles used in *cglm* are **RADIANS** not degrees + + +**NOTE**: The default :c:func:`glm_euler` function is the short name of +:c:func:`glm_euler_xyz` this is why you can't see :c:func:`glm_euler_xyz`. +When you see an euler function which doesn't have any X, Y, Z suffix then +assume that uses **_xyz** (or instead it accept order as parameter). + +If rotation doesn't work properly, your options: + +1. If you use (or paste) degrees convert it to radians before calling an euler function + +.. code-block:: c + + float pitch, yaw, roll; + mat4 rot; + + /* pitch = degrees; yaw = degrees; roll = degrees */ + glm_euler((vec3){glm_rad(pitch), glm_rad(yaw), glm_rad(roll)}, rot); + +2. Convention mismatch. You may have extrinsic angles, + if you do (if you must) then consider to use reverse order e.g if you have + **xyz** extrinsic then use **zyx** + +3. *cglm* may implemented it wrong, consider to create an issue to report it + or pull request to fix it + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Types: + +1. glm_euler_sq + +Functions: + +1. :c:func:`glm_euler_order` +#. :c:func:`glm_euler_angles` +#. :c:func:`glm_euler` +#. :c:func:`glm_euler_zyx` +#. :c:func:`glm_euler_zxy` +#. :c:func:`glm_euler_xzy` +#. :c:func:`glm_euler_yzx` +#. :c:func:`glm_euler_yxz` +#. :c:func:`glm_euler_by_order` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: glm_euler_sq glm_euler_order(int ord[3]) + + | packs euler angles order to glm_euler_sq enum. + + To use :c:func:`glm_euler_by_order` function you need *glm_euler_sq*. You + can get it with this function. + + You can build param like this: + + | X = 0, Y = 1, Z = 2 + + if you have ZYX order then you pass this: [2, 1, 0] = ZYX. + if you have YXZ order then you pass this: [1, 0, 2] = YXZ + + As you can see first item specifies which axis will be first then the + second one specifies which one will be next an so on. + + Parameters: + | *[in]* **ord** euler angles order [Angle1, Angle2, Angle2] + + Returns: + packed euler order + +.. c:function:: void glm_euler_angles(mat4 m, vec3 dest) + + | extract euler angles (in radians) using xyz order + + Parameters: + | *[in]* **m** affine transform + | *[out]* **dest** angles vector [x, y, z] + +.. c:function:: void glm_euler(vec3 angles, mat4 dest) + + | build rotation matrix from euler angles + + Parameters: + | *[in]* **angles** angles as vector [Ex, Ey, Ez] + | *[in]* **dest** rotation matrix + +.. c:function:: void glm_euler_zyx(vec3 angles, mat4 dest) + + | build rotation matrix from euler angles + + Parameters: + | *[in]* **angles** angles as vector [Ez, Ey, Ex] + | *[in]* **dest** rotation matrix + +.. c:function:: void glm_euler_zxy(vec3 angles, mat4 dest) + + | build rotation matrix from euler angles + + Parameters: + | *[in]* **angles** angles as vector [Ez, Ex, Ey] + | *[in]* **dest** rotation matrix + +.. c:function:: void glm_euler_xzy(vec3 angles, mat4 dest) + + | build rotation matrix from euler angles + + Parameters: + | *[in]* **angles** angles as vector [Ex, Ez, Ey] + | *[in]* **dest** rotation matrix + +.. c:function:: void glm_euler_yzx(vec3 angles, mat4 dest) + + build rotation matrix from euler angles + + Parameters: + | *[in]* **angles** angles as vector [Ey, Ez, Ex] + | *[in]* **dest** rotation matrix + +.. c:function:: void glm_euler_yxz(vec3 angles, mat4 dest) + + | build rotation matrix from euler angles + + Parameters: + | *[in]* **angles** angles as vector [Ey, Ex, Ez] + | *[in]* **dest** rotation matrix + +.. c:function:: void glm_euler_by_order(vec3 angles, glm_euler_sq ord, mat4 dest) + + | build rotation matrix from euler angles with given euler order. + + Use :c:func:`glm_euler_order` function to build *ord* parameter + + Parameters: + | *[in]* **angles** angles as vector (ord parameter spceifies angles order) + | *[in]* **ord** euler order + | *[in]* **dest** rotation matrix diff --git a/include/cglm/euler.h b/include/cglm/euler.h index bf62bb7..2289b04 100644 --- a/include/cglm/euler.h +++ b/include/cglm/euler.h @@ -8,7 +8,7 @@ /* Types: enum glm_euler_sq - + Functions: CGLM_INLINE glm_euler_sq glm_euler_order(int newOrder[3]); CGLM_INLINE void glm_euler_angles(mat4 m, vec3 dest); @@ -19,7 +19,7 @@ CGLM_INLINE void glm_euler_yzx(vec3 angles, mat4 dest); CGLM_INLINE void glm_euler_yxz(vec3 angles, mat4 dest); CGLM_INLINE void glm_euler_by_order(vec3 angles, - glm_euler_sq axis, + glm_euler_sq ord, mat4 dest); */ @@ -48,12 +48,12 @@ typedef enum glm_euler_sq { CGLM_INLINE glm_euler_sq -glm_euler_order(int newOrder[3]) { - return (glm_euler_sq)(newOrder[0] | newOrder[1] << 2 | newOrder[2] << 4); +glm_euler_order(int ord[3]) { + return (glm_euler_sq)(ord[0] << 0 | ord[1] << 2 | ord[2] << 4); } /*! - * @brief euler angles (in radian) using xyz sequence + * @brief extract euler angles (in radians) using xyz order * * @param[in] m affine transform * @param[out] dest angles vector [x, y, z] @@ -66,7 +66,7 @@ glm_euler_angles(mat4 m, vec3 dest) { vec3 a[2]; float cy1, cy2; int path; - + a[0][1] = asinf(-m[0][2]); a[1][1] = CGLM_PI - a[0][1]; @@ -96,7 +96,7 @@ glm_euler_angles(mat4 m, vec3 dest) { } /*! - * @brief build rotation matrix from euler angles(ExEyEz/RzRyRx) + * @brief build rotation matrix from euler angles * * @param[in] angles angles as vector [Ex, Ey, Ez] * @param[out] dest rotation matrix @@ -130,7 +130,10 @@ glm_euler(vec3 angles, mat4 dest) { } /*! - * @brief build rotation matrix from euler angles (EzEyEx/RxRyRz) + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Ez, Ey, Ex] + * @param[out] dest rotation matrix */ CGLM_INLINE void @@ -161,6 +164,12 @@ glm_euler_zyx(vec3 angles, dest[3][3] = 1.0f; } +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Ez, Ex, Ey] + * @param[out] dest rotation matrix + */ CGLM_INLINE void glm_euler_zxy(vec3 angles, @@ -190,6 +199,12 @@ glm_euler_zxy(vec3 angles, dest[3][3] = 1.0f; } +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Ex, Ez, Ey] + * @param[out] dest rotation matrix + */ CGLM_INLINE void glm_euler_xzy(vec3 angles, @@ -219,6 +234,12 @@ glm_euler_xzy(vec3 angles, dest[3][3] = 1.0f; } +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Ey, Ez, Ex] + * @param[out] dest rotation matrix + */ CGLM_INLINE void glm_euler_yzx(vec3 angles, @@ -248,6 +269,12 @@ glm_euler_yzx(vec3 angles, dest[3][3] = 1.0f; } +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Ey, Ex, Ez] + * @param[out] dest rotation matrix + */ CGLM_INLINE void glm_euler_yxz(vec3 angles, @@ -277,9 +304,16 @@ glm_euler_yxz(vec3 angles, dest[3][3] = 1.0f; } +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector (ord parameter spceifies angles order) + * @param[in] ord euler order + * @param[out] dest rotation matrix + */ CGLM_INLINE void -glm_euler_by_order(vec3 angles, glm_euler_sq axis, mat4 dest) { +glm_euler_by_order(vec3 angles, glm_euler_sq ord, mat4 dest) { float cx, cy, cz, sx, sy, sz; @@ -297,7 +331,7 @@ glm_euler_by_order(vec3 angles, glm_euler_sq axis, mat4 dest) { czsx = cz * sx; cxsz = cx * sz; sysz = sy * sz; - switch (axis) { + switch (ord) { case GLM_EULER_XYZ: dest[0][0] = cycz; dest[0][1] = cysz; From 0e964a1a626f08c49c18c3be3b44088445eed931 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 3 Mar 2018 17:59:50 +0300 Subject: [PATCH 021/292] complete documentation --- README.md | 30 ++++-- configure.ac | 2 +- docs/source/affine-mat.rst | 2 +- docs/source/affine.rst | 4 +- docs/source/api.rst | 9 +- docs/source/box.rst | 92 +++++++++++++++++ docs/source/call.rst | 19 ++++ docs/source/cam.rst | 4 +- docs/source/color.rst | 34 +++++++ docs/source/conf.py | 4 +- docs/source/euler.rst | 2 +- docs/source/frustum.rst | 168 ++++++++++++++++++++++++++++++++ docs/source/getting_started.rst | 46 +++++++-- docs/source/index.rst | 3 +- docs/source/io.rst | 92 +++++++++++++++++ docs/source/mat3.rst | 2 +- docs/source/mat4.rst | 2 +- docs/source/opengl.rst | 61 ++++++++++++ docs/source/plane.rst | 33 +++++++ docs/source/quat.rst | 2 +- docs/source/util.rst | 93 ++++++++++++++++++ docs/source/vec3-ext.rst | 2 +- docs/source/vec3.rst | 2 +- docs/source/vec4-ext.rst | 2 +- docs/source/vec4.rst | 2 +- include/cglm/version.h | 2 +- 26 files changed, 675 insertions(+), 39 deletions(-) create mode 100644 docs/source/box.rst create mode 100644 docs/source/call.rst create mode 100644 docs/source/color.rst create mode 100644 docs/source/frustum.rst create mode 100644 docs/source/io.rst create mode 100644 docs/source/opengl.rst create mode 100644 docs/source/plane.rst create mode 100644 docs/source/util.rst diff --git a/README.md b/README.md index 8c63fb0..84b321e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # 🎥 OpenGL Mathematics (glm) for `C` [![Build Status](https://travis-ci.org/recp/cglm.svg?branch=master)](https://travis-ci.org/recp/cglm) [![Build status](https://ci.appveyor.com/api/projects/status/av7l3gc0yhfex8y4/branch/master?svg=true)](https://ci.appveyor.com/project/recp/cglm/branch/master) +[![Documentation Status](https://readthedocs.org/projects/cglm/badge/?version=latest)](http://cglm.readthedocs.io/en/latest/?badge=latest) [![Coverage Status](https://coveralls.io/repos/github/recp/cglm/badge.svg?branch=master)](https://coveralls.io/github/recp/cglm?branch=master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/6a62b37d5f214f178ebef269dc4a6bf1)](https://www.codacy.com/app/recp/cglm?utm_source=github.com&utm_medium=referral&utm_content=recp/cglm&utm_campaign=Badge_Grade) @@ -9,7 +10,7 @@ The original glm library is for C++ only (templates, namespaces, classes...), th #### Documentation Almost all functions (inline versions) and parameters are documented inside related headers.
-Complete documentation is in progress: http://cglm.readthedocs.io +Complete documentation: http://cglm.readthedocs.io #### Note for previous versions: @@ -29,15 +30,15 @@ https://github.com/g-truc/glm - Welcome! #### Note for experienced developers: -- Since I'm testing this library in my projects, sometimes bugs occurs; finding that bug[s] and making improvements would be more easy with multiple developer/contributor and their projects or knowledge. Consider to make some tests if you suspect something is wrong and any feedbacks, contributions and bug reports are always welcome. +- Since I'm testing this library in my projects, sometimes bugs occurs; finding that bug[s] and making improvements would be more easy with multiple developer/contributor and their projects or knowledge. Consider to make some tests if you suspect something is wrong and any feedbacks, contributions and bug reports are always welcome. -#### Allocations? -`cglm` doesn't alloc any memory on heap. So it doesn't provide any allocator. You should alloc memory for **out** parameters too if you pass pointer of memory location. Don't forget that **vec4** (also quat/**versor**) and **mat4** must be aligned (16-bytes), because *cglm* uses SIMD instructions to optimize most operations if available. +#### Allocations? +`cglm` doesn't alloc any memory on heap. So it doesn't provide any allocator. You should alloc memory for **out** parameters too if you pass pointer of memory location. Don't forget that **vec4** (also quat/**versor**) and **mat4** must be aligned (16-bytes), because *cglm* uses SIMD instructions to optimize most operations if available. #### Returning vector or matrix... ? -Since almost all types are arrays and **C** doesn't allow returning arrays, so **cglm** doesn't support this feature. In the future *cglm* may use **struct** for some types for this purpose. +Since almost all types are arrays and **C** doesn't allow returning arrays, so **cglm** doesn't support this feature. In the future *cglm* may use **struct** for some types for this purpose. -#### Other APIs like Vulkan, Metal, Dx? +#### Other APIs like Vulkan, Metal, Dx? Currently *cglm* uses default clip space configuration (-1, 1) for camera functions (perspective, extract corners...), in the future other clip space configurations will be supported
@@ -121,8 +122,8 @@ MIT. check the LICENSE file ### Unix (Autotools) ```bash -$ sh ./build-deps.sh # run only once (dependencies) [Optional]. -$ # You can pass this step if you don't want to run `make check` for tests. +$ sh ./build-deps.sh # run only once (dependencies) [Optional]. +$ # You can pass this step if you don't want to run `make check` for tests. $ # cglm uses cmocka for tests and it may reqiure cmake for building it $ $ sh autogen.sh @@ -146,6 +147,15 @@ if `msbuild` won't work (because of multi version VS) then try to build with `de $ devenv cglm.sln /Build Release ``` +### Building Docs +First you need install Sphinx: http://www.sphinx-doc.org/en/master/usage/installation.html +then: +```bash +$ cd docs +$ sphinx-build source build +``` +it will compile docs into build folder, you can run index.html inside that function. + ## How to use If you want to use inline versions of funcstions then; include main header ```C @@ -201,7 +211,7 @@ Option 2: Cast matrix to pointer type (also valid for multiple dimensional array glUniformMatrix4fv(location, 1, GL_FALSE, (float *)matrix); ``` -You can pass same way to another APIs e.g. Vulkan, DX... +You can pass same way to another APIs e.g. Vulkan, DX... ## Notes @@ -213,5 +223,5 @@ You can pass same way to another APIs e.g. Vulkan, DX... - [ ] Unit tests for comparing cglm with glm results - [x] Add version info - [ ] Unaligned operations (e.g. `glm_umat4_mul`) -- [ ] Extra documentation +- [x] Extra documentation - [ ] ARM Neon Arch (In Progress) diff --git a/configure.ac b/configure.ac index 1fea297..a77cd68 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.2.1], [info@recp.me]) +AC_INIT([cglm], [0.3.4], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/affine-mat.rst b/docs/source/affine-mat.rst index 0d09e12..0c0fcaa 100644 --- a/docs/source/affine-mat.rst +++ b/docs/source/affine-mat.rst @@ -1,6 +1,6 @@ .. default-domain:: C -Affine Transform Matrix (Specialized Functions) +affine transform matrix (specialized functions) ================================================================================ Header: cglm/affine-mat.h diff --git a/docs/source/affine.rst b/docs/source/affine.rst index fdb2ef3..c34921f 100644 --- a/docs/source/affine.rst +++ b/docs/source/affine.rst @@ -1,6 +1,6 @@ .. default-domain:: C -Affine Transforms +affine transforms ================================================================================ Header: cglm/affine.h @@ -15,7 +15,7 @@ before sending to transfrom functions. There are also functions to decompose transform matrix. These functions can't decompose matrix after projected. -Table of contents (clik func/macro to go): +Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Functions: diff --git a/docs/source/api.rst b/docs/source/api.rst index 7db4f83..e2c03d4 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -23,12 +23,14 @@ version of functions. You need to build *cglm* and link it. Follow the :doc:`build` documentation for this .. toctree:: - :maxdepth: 2 + :maxdepth: 1 :caption: API categories: affine affine-mat cam + frustum + box quat euler mat4 @@ -37,3 +39,8 @@ Follow the :doc:`build` documentation for this vec3-ext vec4 vec4-ext + color + plane + util + io + call diff --git a/docs/source/box.rst b/docs/source/box.rst new file mode 100644 index 0000000..b753b3f --- /dev/null +++ b/docs/source/box.rst @@ -0,0 +1,92 @@ +.. default-domain:: C + +axis aligned bounding box (AABB) +================================================================================ + +Header: cglm/box.h + +Some convenient functions provided for AABB. + +**Definition of box:** + +cglm defines box as two dimensional array of vec3. +The first element is **min** point and the second one is **max** point. +If you have another type e.g. struct or even another representation then you must +convert it before and after call cglm box function. + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_aabb_transform` +#. :c:func:`glm_aabb_merge` +#. :c:func:`glm_aabb_crop` +#. :c:func:`glm_aabb_crop_until` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]) + + | apply transform to Axis-Aligned Bounding Box + + Parameters: + | *[in]* **box** bounding box + | *[in]* **m** transform matrix + | *[out]* **dest** transformed bounding box + +.. c:function:: void glm_aabb_merge(vec3 box1[2], vec3 box2[2], vec3 dest[2]) + + | 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 + + Parameters: + | *[in]* **box1** bounding box 1 + | *[in]* **box2** bounding box 2 + | *[out]* **dest** merged bounding box + +.. c:function:: void glm_aabb_crop(vec3 box[2], vec3 cropBox[2], vec3 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]* **box** bounding box 1 + | *[in]* **cropBox** crop box + | *[out]* **dest** cropped bounding box + +.. c:function:: void glm_frustum_box(vec4 corners[8], mat4 m, vec3 box[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]* **box** bounding box + | *[in]* **cropBox** crop box + | *[in]* **clampBox** miniumum box + | *[out]* **dest** cropped bounding box + +.. c:function:: bool glm_aabb_frustum(vec3 box[2], vec4 planes[6]) + + | check if AABB intersects with frustum planes + + this could be useful for frustum culling using AABB. + + OPTIMIZATION HINT: + if planes order is similar to LEFT, RIGHT, BOTTOM, TOP, NEAR, FAR + then this method should run even faster because it would only use two + planes if object is not inside the two planes + fortunately cglm extracts planes as this order! just pass what you got! + + Parameters: + | *[in]* **box** bounding box + | *[out]* **planes** frustum planes diff --git a/docs/source/call.rst b/docs/source/call.rst new file mode 100644 index 0000000..f7765a7 --- /dev/null +++ b/docs/source/call.rst @@ -0,0 +1,19 @@ +.. default-domain:: C + +precompiled functions (call) +================================================================================ + +All funcitons in **glm_** namespace are forced to **inline**. +Most functions also have pre-compiled version. + +Precompiled versions are in **glmc_** namespace. *c* in the namespace stands for +"call". + +Since precompiled functions are just wrapper for inline verisons, +these functions are not documented individually. +It would be duplicate documentation also it +would be hard to sync documentation between inline and call verison for me. + +By including **clgm/cglm.h** you include all inline verisons. To get precompiled +versions you need to include **cglm/call.h** header it also includes all +call versions plus *clgm/cglm.h* (inline verisons) diff --git a/docs/source/cam.rst b/docs/source/cam.rst index 2725334..a9f1ce7 100644 --- a/docs/source/cam.rst +++ b/docs/source/cam.rst @@ -1,6 +1,6 @@ .. default-domain:: C -Camera +camera ====== Header: cglm/cam.h @@ -23,7 +23,7 @@ matrices. **float** type cannot store very high precision so you will lose precision. Also your projection matrix will be inaccurate due to losing precision -Table of contents (clik func/macro to go): +Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Functions: diff --git a/docs/source/color.rst b/docs/source/color.rst new file mode 100644 index 0000000..62a4dc1 --- /dev/null +++ b/docs/source/color.rst @@ -0,0 +1,34 @@ +.. default-domain:: C + +color +================================================================================ + +Header: cglm/color.h + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_luminance` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: float glm_luminance(vec3 rgb) + + | averages the color channels into one value + + This function uses formula in COLLADA 1.5 spec which is + + .. code-block:: text + + luminance = (color.r * 0.212671) + + (color.g * 0.715160) + + (color.b * 0.072169) + + It is based on the ISO/CIE color standards (see ITU-R Recommendation BT.709-4), + that averages the color channels into one value + + Parameters: + | *[in]* **rgb** RGB color diff --git a/docs/source/conf.py b/docs/source/conf.py index e02fea3..7ad96a1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.3.3' +version = u'0.3.4' # The full version, including alpha/beta/rc tags. -release = u'0.3.3' +release = u'0.3.4' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/source/euler.rst b/docs/source/euler.rst index 1cf64ed..260aec7 100644 --- a/docs/source/euler.rst +++ b/docs/source/euler.rst @@ -1,6 +1,6 @@ .. default-domain:: C -Euler Angles +euler angles ============ Header: cglm/euler.h diff --git a/docs/source/frustum.rst b/docs/source/frustum.rst new file mode 100644 index 0000000..0ace87d --- /dev/null +++ b/docs/source/frustum.rst @@ -0,0 +1,168 @@ +.. default-domain:: C + +frustum +============= + +Header: cglm/frustum.h + +cglm provides convenient functions to extract frustum planes, corners... +All extracted corners are **vec4** so you must create array of **vec4** +not **vec3**. If you want to store them to save space you msut convert them +yourself. + +**vec4** is used to speed up functions need to corners. This is why frustum +fucntions use *vec4* instead of *vec3* + +Currenty related-functions use [-1, 1] clip space configuration to extract +corners but you can override it by prodiving **GLM_CUSTOM_CLIPSPACE** macro. +If you provide it then you have to all bottom macros as *vec4* + +Current configuration: + +.. code-block:: c + + /* near */ + GLM_CSCOORD_LBN {-1.0f, -1.0f, -1.0f, 1.0f} + GLM_CSCOORD_LTN {-1.0f, 1.0f, -1.0f, 1.0f} + GLM_CSCOORD_RTN { 1.0f, 1.0f, -1.0f, 1.0f} + GLM_CSCOORD_RBN { 1.0f, -1.0f, -1.0f, 1.0f} + + /* far */ + GLM_CSCOORD_LBF {-1.0f, -1.0f, 1.0f, 1.0f} + GLM_CSCOORD_LTF {-1.0f, 1.0f, 1.0f, 1.0f} + GLM_CSCOORD_RTF { 1.0f, 1.0f, 1.0f, 1.0f} + GLM_CSCOORD_RBF { 1.0f, -1.0f, 1.0f, 1.0f} + + +Explain of short names: + * **LBN**: left bottom near + * **LTN**: left top near + * **RTN**: right top near + * **RBN**: right bottom near + * **LBF**: left bottom far + * **LTF**: left top far + * **RTF**: right top far + * **RBF**: right bottom far + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Macros: + +.. code-block:: c + + GLM_LBN 0 /* left bottom near */ + GLM_LTN 1 /* left top near */ + GLM_RTN 2 /* right top near */ + GLM_RBN 3 /* right bottom near */ + + GLM_LBF 4 /* left bottom far */ + GLM_LTF 5 /* left top far */ + GLM_RTF 6 /* right top far */ + GLM_RBF 7 /* right bottom far */ + + GLM_LEFT 0 + GLM_RIGHT 1 + GLM_BOTTOM 2 + GLM_TOP 3 + GLM_NEAR 4 + GLM_FAR 5 + +Functions: + +1. :c:func:`glm_frustum_planes` +#. :c:func:`glm_frustum_corners` +#. :c:func:`glm_frustum_center` +#. :c:func:`glm_frustum_box` +#. :c:func:`glm_frustum_corners_at` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_frustum_planes(mat4 m, vec4 dest[6]) + + | extracts view frustum planes + + planes' space: + - if m = proj: View Space + - if m = viewProj: World Space + - if m = MVP: Object Space + + You probably want to extract planes in world space so use viewProj as m + Computing viewProj: + + .. code-block:: c + + glm_mat4_mul(proj, view, viewProj); + + Exracted planes order: [left, right, bottom, top, near, far] + + Parameters: + | *[in]* **m** matrix + | *[out]* **dest** exracted view frustum planes + +.. c:function:: void glm_frustum_corners(mat4 invMat, vec4 dest[8]) + + | extracts view frustum corners using clip-space coordinates + + corners' space: + - if m = invViewProj: World Space + - if m = invMVP: Object Space + + You probably want to extract corners in world space so use **invViewProj** + Computing invViewProj: + + .. code-block:: c + + glm_mat4_mul(proj, view, viewProj); + ... + glm_mat4_inv(viewProj, invViewProj); + + if you have a near coord at **i** index, + you can get it's far coord by i + 4; + follow example below to understand that + + For instance to find center coordinates between a near and its far coord: + + .. code-block:: c + + for (j = 0; j < 4; j++) { + glm_vec_center(corners[i], corners[i + 4], centerCorners[i]); + } + + corners[i + 4] is far of corners[i] point. + + Parameters: + | *[in]* **invMat** matrix + | *[out]* **dest** exracted view frustum corners + +.. c:function:: void glm_frustum_center(vec4 corners[8], vec4 dest) + + | finds center of view frustum + + Parameters: + | *[in]* **corners** view frustum corners + | *[out]* **dest** view frustum center + +.. c:function:: void glm_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) + + | finds bounding box of frustum relative to given matrix e.g. view mat + + Parameters: + | *[in]* **corners** view frustum corners + | *[in]* **m** matrix to convert existing conners + | *[out]* **box** bounding box as array [min, max] + +.. c:function:: void glm_frustum_corners_at(vec4 corners[8], float splitDist, float farDist, vec4 planeCorners[4]) + + | finds planes corners which is between near and far planes (parallel) + + this will be helpful if you want to split a frustum e.g. CSM/PSSM. This will + find planes' corners but you will need to one more plane. + Actually you have it, it is near, far or created previously with this func ;) + + Parameters: + | *[in]* **corners** frustum corners + | *[in]* **splitDist** split distance + | *[in]* **farDist** far distance (zFar) + | *[out]* **planeCorners** plane corners [LB, LT, RT, RB] diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index d16f326..89c231c 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -1,9 +1,8 @@ Getting Started ================================ -.. image:: cglm-intro.png - :width: 492px  - :height: 297px - :align: center + +Types: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ **cglm** uses **glm** prefix for all functions e.g. glm_lookat. You can see supported types in common header file: @@ -22,23 +21,50 @@ Getting Started As you can see types don't store extra informations in favor of space. You can send these values e.g. matrix to OpenGL directly without casting or calling a function like *value_ptr* -*vec4* and *mat4* requires 16 byte aligment because vec4 and mat4 operations are +Aligment is Required: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**vec4** and **mat4** requires 16 byte aligment because vec4 and mat4 operations are vectorized by SIMD instructions (SSE/AVX). +Allocations: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*cglm* doesn't alloc any memory on heap. So it doesn't provide any allocator. +You must allocate memory yourself. You should alloc memory for out parameters too if you pass pointer of memory location. +When allocating memory don't forget that **vec4** and **mat4** requires aligment. + **NOTE:** Unaligned vec4 and unaligned mat4 operations will be supported in the future. Check todo list. Because you may want to multiply a CGLM matrix with external matrix. There is no guarantee that non-CGLM matrix is aligned. Unaligned types will have *u* prefix e.g. **umat4** +Array vs Struct: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*cglm* uses arrays for vector and matrix types. So you can't access individual +elements like vec.x, vec.y, vec.z... You must use subscript to access vector elements +e.g. vec[0], vec[1], vec[2]. + +Also I think it is more meaningful to access matrix elements with subscript +e.g **matrix[2][3]** instead of **matrix._23**. Since matrix is array of vectors, +vectors are also defined as array. This makes types homogeneous. + +**Return arrays?** + +Since C doesn't support return arrays, cglm also doesn't support this feature. + +Function design: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. image:: cglm-intro.png + :width: 492px  + :height: 297px + :align: center + cglm provides a few way to call a function to do same operation. * Inline - *glm_, glm_u* - * aligned - * unaligned (todo) * Pre-compiled - *glmc_, glmc_u* - * aligned - * unaligned (todo) -For instance **glm_mat4_mul** is inline (all *glm_* functions are inline), to make it non-inline (pre-compiled) +For instance **glm_mat4_mul** is inline (all *glm_* functions are inline), to make it non-inline (pre-compiled), call it as **glmc_mat4_mul** from library, to use unaligned version use **glm_umat4_mul** (todo). Most functions have **dest** parameter for output. For instance mat4_mul func looks like this: diff --git a/docs/source/index.rst b/docs/source/index.rst index 3241872..25e7cb3 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -33,11 +33,12 @@ Also currently only **float** type is supported for most operations. .. toctree:: - :maxdepth: 2 + :maxdepth: 1 :caption: Table Of Contents: build getting_started + opengl api Indices and tables diff --git a/docs/source/io.rst b/docs/source/io.rst new file mode 100644 index 0000000..9cf8900 --- /dev/null +++ b/docs/source/io.rst @@ -0,0 +1,92 @@ +.. default-domain:: C + +io (input / output e.g. print) +================================================================================ + +Header: cglm/io.h + +There are some built-in print functions which may save your time, +especially for debugging. + +All functions accept **FILE** parameter which makes very flexible. +You can even print it to file on disk. + +In general you will want to print them to console to see results. +You can use **stdout** and **stderr** to write results to console. +Some programs may occupy **stdout** but you can still use **stderr**. +Using **stderr** is suggested. + +Example to print mat4 matrix: + +.. code-block:: c + + mat4 transform; + /* ... */ + glm_mat4_print(transform, stderr); + +**NOTE:** print functions use **%0.4f** precision if you need more +(you probably will in some cases), you can change it temporary. +cglm may provide precision parameter in the future + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_mat4_print` +#. :c:func:`glm_mat3_print` +#. :c:func:`glm_vec4_print` +#. :c:func:`glm_vec3_print` +#. :c:func:`glm_ivec3_print` +#. :c:func:`glm_versor_print` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_mat4_print(mat4 matrix, FILE * __restrict ostream) + + | print mat4 to given stream + + Parameters: + | *[in]* **matrix** matrix + | *[in]* **ostream** FILE to write + +.. c:function:: void glm_mat3_print(mat3 matrix, FILE * __restrict ostream) + + | print mat3 to given stream + + Parameters: + | *[in]* **matrix** matrix + | *[in]* **ostream** FILE to write + +.. c:function:: void glm_vec4_print(vec4 vec, FILE * __restrict ostream) + + | print vec4 to given stream + + Parameters: + | *[in]* **vec** vector + | *[in]* **ostream** FILE to write + +.. c:function:: void glm_vec3_print(vec3 vec, FILE * __restrict ostream) + + | print vec3 to given stream + + Parameters: + | *[in]* **vec** vector + | *[in]* **ostream** FILE to write + +.. c:function:: void glm_ivec3_print(ivec3 vec, FILE * __restrict ostream) + + | print ivec3 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 + + Parameters: + | *[in]* **vec** quaternion + | *[in]* **ostream** FILE to write diff --git a/docs/source/mat3.rst b/docs/source/mat3.rst index 60e548c..9b00417 100644 --- a/docs/source/mat3.rst +++ b/docs/source/mat3.rst @@ -5,7 +5,7 @@ mat3 Header: cglm/mat3.h -Table of contents (clik func/macro to go): +Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Macros: diff --git a/docs/source/mat4.rst b/docs/source/mat4.rst index 27d9225..1a391cb 100644 --- a/docs/source/mat4.rst +++ b/docs/source/mat4.rst @@ -8,7 +8,7 @@ Header: cglm/mat4.h Important: :c:func:`glm_mat4_scale` multiplies mat4 with scalar, if you need to apply scale transform use :c:func:`glm_scale` functions. -Table of contents (clik func/macro to go): +Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Macros: diff --git a/docs/source/opengl.rst b/docs/source/opengl.rst new file mode 100644 index 0000000..e6b37e0 --- /dev/null +++ b/docs/source/opengl.rst @@ -0,0 +1,61 @@ +How to send vector or matrix to OpenGL like API +================================================== + +*cglm*'s vector and matrix types are arrays. So you can send them directly to a +function which accecpts pointer. But you may got warnings for matrix because it is +two dimensional array. + +Passing / Uniforming Matrix to OpenGL: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +**glUniformMatrix4fv** accepts float pointer, you can pass matrix to that parameter +and it should work but with warnings. "You can pass" doesn't mean that you must pass like that. + +**Correct options:** + +Correct doesn't mean correct way to use OpenGL it is just shows correct way to pass cglm type to it. + +1. Pass first column +--------------------- + +The goal is that pass address of matrix, first element of matrix is also address of matrix, +because it is array of vectors and vector is array of floats. + +.. code-block:: c + + mat4 matrix; + /* ... */ + glUniformMatrix4fv(location, 1, GL_FALSE, matrix[0]); + +array of matrices: + +.. code-block:: c + + mat4 matrix; + /* ... */ + glUniformMatrix4fv(location, count, GL_FALSE, matrix[0][0]); + +1. Cast matrix to pointer +-------------------------- + +.. code-block:: c + + mat4 matrix; + /* ... */ + glUniformMatrix4fv(location, count, GL_FALSE, (float *)matrix); + +in this way, passing aray of matrices is same + +Passing / Uniforming Vectors to OpenGL:¶ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You don't need to do extra thing when passing cglm vectors to OpengL or other APIs. +Because a function like **glUniform4fv** accepts vector as pointer. cglm's vectors +are array of floats. So you can pass it directly ot those functions: + +.. code-block:: c + + vec4 vec; + /* ... */ + glUniform4fv(location, 1, vec); + +this show how to pass **vec4** others are same. diff --git a/docs/source/plane.rst b/docs/source/plane.rst new file mode 100644 index 0000000..b9afbed --- /dev/null +++ b/docs/source/plane.rst @@ -0,0 +1,33 @@ +.. default-domain:: C + +plane +================================================================================ + +Header: cglm/plane.h + +Plane extract functions are in frustum header and documented +in :doc:`frustum` page. + +**Definition of plane:** + +Plane equation: **Ax + By + Cz + D = 0** + +Plan is stored in **vec4** as **[A, B, C, D]**. (A, B, C) is normal and D is distance + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_plane_normalize` + + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_plane_normalize(vec4 plane) + + | normalizes a plane + + Parameters: + | *[in, out]* **plane** pnale to normalize diff --git a/docs/source/quat.rst b/docs/source/quat.rst index 064aa19..863eed5 100644 --- a/docs/source/quat.rst +++ b/docs/source/quat.rst @@ -1,6 +1,6 @@ .. default-domain:: C -Quaternions +quaternions =========== Header: cglm/quat.h diff --git a/docs/source/util.rst b/docs/source/util.rst new file mode 100644 index 0000000..048be70 --- /dev/null +++ b/docs/source/util.rst @@ -0,0 +1,93 @@ +.. default-domain:: C + +utils / helpers +================================================================================ + +Header: cglm/util.h + + + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_sign` +#. :c:func:`glm_rad` +#. :c:func:`glm_deg` +#. :c:func:`glm_make_rad` +#. :c:func:`glm_make_deg` +#. :c:func:`glm_pow2` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: int glm_sign(int val) + + | returns sign of 32 bit integer as +1 or -1 + + Parameters: + | *[in]* **val** an integer + + Returns: + sign of given number + +.. c:function:: float glm_rad(float deg) + + | convert degree to radians + + Parameters: + | *[in]* **deg** angle in degrees + +.. c:function:: float glm_deg(float rad) + + | convert radians to degree + + Parameters: + | *[in]* **rad** angle in radians + +.. c:function:: void glm_make_rad(float *degm) + + | convert exsisting degree to radians. this will override degrees value + + Parameters: + | *[in, out]* **deg** pointer to angle in degrees + +.. c:function:: void glm_make_deg(float *rad) + + | convert exsisting radians to degree. this will override radians value + + Parameters: + | *[in, out]* **rad** pointer to angle in radians + +.. c:function:: float glm_pow2(float x) + + | multiplies given parameter with itself = x * x or powf(x, 2) + + Parameters: + | *[in]* **x** value + + Returns: + square of a given number + +.. c:function:: float glm_min(float a, float b) + + | returns minimum of given two values + + Parameters: + | *[in]* **a** number 1 + | *[in]* **b** number 2 + + Returns: + minimum value + +.. c:function:: float glm_max(float a, float b) + + | returns maximum of given two values + + Parameters: + | *[in]* **a** number 1 + | *[in]* **b** number 2 + + Returns: + maximum value diff --git a/docs/source/vec3-ext.rst b/docs/source/vec3-ext.rst index 112e2a3..e632de9 100644 --- a/docs/source/vec3-ext.rst +++ b/docs/source/vec3-ext.rst @@ -9,7 +9,7 @@ There are some functions are in called in extra header. These are called extra because they are not used like other functions in vec3.h in the future some of these functions ma be moved to vec3 header. -Table of contents (clik func/macro to go): +Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Functions: diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index 4458362..2ae95f0 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -13,7 +13,7 @@ alias means inline wrapper here. There is no call verison of alias functions There are also functions for rotating *vec3* vector. **_m4**, **_m3** prefixes rotate *vec3* with matrix. -Table of contents (clik func/macro to go): +Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Macros: diff --git a/docs/source/vec4-ext.rst b/docs/source/vec4-ext.rst index d9c6e0b..11613ad 100644 --- a/docs/source/vec4-ext.rst +++ b/docs/source/vec4-ext.rst @@ -9,7 +9,7 @@ There are some functions are in called in extra header. These are called extra because they are not used like other functions in vec4.h in the future some of these functions ma be moved to vec4 header. -Table of contents (clik func/macro to go): +Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Functions: diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index 5409c1e..60be7fa 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -5,7 +5,7 @@ vec4 Header: cglm/vec4.h -Table of contents (clik func/macro to go): +Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Macros: diff --git a/include/cglm/version.h b/include/cglm/version.h index ce2f784..e654df6 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 3 -#define CGLM_VERSION_PATCH 3 +#define CGLM_VERSION_PATCH 4 #endif /* cglm_version_h */ From da2f3aaafd36632b91e17ffdb4e68e42e31abb0b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 3 Mar 2018 18:17:58 +0300 Subject: [PATCH 022/292] docs: fix aabb docs --- docs/source/box.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/box.rst b/docs/source/box.rst index b753b3f..84ba145 100644 --- a/docs/source/box.rst +++ b/docs/source/box.rst @@ -23,6 +23,7 @@ Functions: #. :c:func:`glm_aabb_merge` #. :c:func:`glm_aabb_crop` #. :c:func:`glm_aabb_crop_until` +#. :c:func:`glm_aabb_frustum` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -61,7 +62,7 @@ Functions documentation | *[in]* **cropBox** crop box | *[out]* **dest** cropped bounding box -.. c:function:: void glm_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) +.. c:function:: void glm_aabb_crop_until(vec3 box[2], vec3 cropBox[2], vec3 clampBox[2], vec3 dest[2]) | crops a bounding box with another one. From cfab79e5460406d8e08d27a0f95d743e02fd31aa Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 8 Mar 2018 12:18:07 +0300 Subject: [PATCH 023/292] now working on v0.3.5 --- configure.ac | 2 +- include/cglm/version.h | 2 +- makefile.am | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index a77cd68..23e8a15 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.3.4], [info@recp.me]) +AC_INIT([cglm], [0.3.5], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/include/cglm/version.h b/include/cglm/version.h index e654df6..a025ccb 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 3 -#define CGLM_VERSION_PATCH 4 +#define CGLM_VERSION_PATCH 5 #endif /* cglm_version_h */ diff --git a/makefile.am b/makefile.am index f6d1471..ff951c8 100644 --- a/makefile.am +++ b/makefile.am @@ -16,7 +16,7 @@ AM_CFLAGS = -Wall \ -pedantic lib_LTLIBRARIES = libcglm.la -libcglm_la_LDFLAGS = -no-undefined -version-info 0:1:0 +libcglm_la_LDFLAGS = -no-undefined -version-info 0:3:5 checkLDFLAGS = -L./.libs \ -L./test/lib/cmocka/build/src \ From 29996d0bddea84c6ba80b5e5e0ce9f6b2e75af02 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 8 Mar 2018 13:02:33 +0300 Subject: [PATCH 024/292] add unproject function --- include/cglm/call.h | 1 + include/cglm/call/project.h | 29 +++++++++++++ include/cglm/cglm.h | 1 + include/cglm/project.h | 84 +++++++++++++++++++++++++++++++++++++ src/project.c | 21 ++++++++++ win/cglm.vcxproj | 3 ++ win/cglm.vcxproj.filters | 9 ++++ 7 files changed, 148 insertions(+) create mode 100644 include/cglm/call/project.h create mode 100644 include/cglm/project.h create mode 100644 src/project.c diff --git a/include/cglm/call.h b/include/cglm/call.h index 3f7bf14..ce08b78 100644 --- a/include/cglm/call.h +++ b/include/cglm/call.h @@ -24,6 +24,7 @@ extern "C" { #include "call/frustum.h" #include "call/box.h" #include "call/io.h" +#include "call/project.h" #ifdef __cplusplus } diff --git a/include/cglm/call/project.h b/include/cglm/call/project.h new file mode 100644 index 0000000..1120b21 --- /dev/null +++ b/include/cglm/call/project.h @@ -0,0 +1,29 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_project_h +#define cglmc_project_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_unprojecti(mat4 invMat, vec4 vp, vec3 coord, vec3 dest); + +CGLM_EXPORT +void +glmc_unproject(mat4 m, vec2 vp, vec3 coord, vec3 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_project_h */ + + diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index e99bb09..52c7e97 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -23,5 +23,6 @@ #include "color.h" #include "util.h" #include "io.h" +#include "project.h" #endif /* cglm_h */ diff --git a/include/cglm/project.h b/include/cglm/project.h new file mode 100644 index 0000000..27cb42a --- /dev/null +++ b/include/cglm/project.h @@ -0,0 +1,84 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_project_h +#define cglm_project_h + +#include "mat4.h" + +/*! + * @brief maps the specified viewport coordinates into specified space [1] + * the matrix should contain projection matrix. + * + * if you don't have ( and don't want to have ) an inverse matrix then use + * glm_unproject version. You may use existing inverse of matrix in somewhere + * else, this is why glm_unprojecti exists to save save inversion cost + * + * [1] space: + * 1- if m = invProj: View Space + * 2- if m = invViewProj: World Space + * 3- if m = invMVP: Object Space + * + * You probably want to map the coordinates into object space + * so use invMVP as m + * + * Computing viewProj: + * glm_mat4_mul(proj, view, viewProj); + * glm_mat4_mul(viewProj, model, MVP); + * glm_mat4_inv(viewProj, invMVP); + * + * @param[in] invMat matrix (see brief) + * @param[in] vp viewport as [x, y, width, height] + * @param[in] coord viewport coordinates + * @param[out] dest unprojected coordinates + */ +CGLM_INLINE +void +glm_unprojecti(mat4 invMat, vec4 vp, vec3 coord, vec4 dest) { + vec4 v; + + v[0] = 2.0f * (coord[0] - vp[0]) / vp[2] - 1.0f; + v[1] = 2.0f * (coord[1] - vp[1]) / vp[3] - 1.0f; + v[2] = 2.0f * coord[2] - 1.0f; + v[3] = 1.0f; + + glm_mat4_mulv(invMat, v, dest); +} + +/*! + * @brief maps the specified viewport coordinates into specified space [1] + * the matrix should contain projection matrix. + * + * this is same as glm_unprojecti except this function get inverse matrix for + * you. + * + * [1] space: + * 1- if m = proj: View Space + * 2- if m = viewProj: World Space + * 3- if m = MVP: Object Space + * + * You probably want to map the coordinates into object space + * so use MVP as m + * + * Computing viewProj: + * glm_mat4_mul(proj, view, viewProj); + * glm_mat4_mul(viewProj, model, MVP); + * + * @param[in] m matrix (see brief) + * @param[in] vp viewport as [x, y, width, height] + * @param[in] coord viewport coordinates + * @param[out] dest unprojected coordinates + */ +CGLM_INLINE +void +glm_unproject(mat4 m, vec2 vp, vec3 coord, vec3 dest) { + mat4 inv; + glm_mat4_inv(m, inv); + glm_unprojecti(inv, vp, coord, dest); +} + +#endif /* cglm_project_h */ diff --git a/src/project.c b/src/project.c new file mode 100644 index 0000000..80e0b44 --- /dev/null +++ b/src/project.c @@ -0,0 +1,21 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +void +glmc_unprojecti(mat4 invMat, vec4 vp, vec3 coord, vec3 dest) { + glm_unprojecti(invMat, vp, coord, dest); +} + +CGLM_EXPORT +void +glmc_unproject(mat4 m, vec2 vp, vec3 coord, vec3 dest) { + glm_unproject(m, vp, coord, dest); +} diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj index 4a0463d..415a87d 100644 --- a/win/cglm.vcxproj +++ b/win/cglm.vcxproj @@ -29,6 +29,7 @@ + @@ -47,6 +48,7 @@ + @@ -60,6 +62,7 @@ + diff --git a/win/cglm.vcxproj.filters b/win/cglm.vcxproj.filters index 506f3d8..3090d72 100644 --- a/win/cglm.vcxproj.filters +++ b/win/cglm.vcxproj.filters @@ -75,6 +75,9 @@ src + + src + @@ -206,5 +209,11 @@ include\cglm + + include\cglm + + + include\cglm\call + \ No newline at end of file From fadde1e26a403c73db2ca9210aabc5766bf15cbe Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 8 Mar 2018 13:04:29 +0300 Subject: [PATCH 025/292] fix libtool version number --- makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile.am b/makefile.am index ff951c8..f6d1471 100644 --- a/makefile.am +++ b/makefile.am @@ -16,7 +16,7 @@ AM_CFLAGS = -Wall \ -pedantic lib_LTLIBRARIES = libcglm.la -libcglm_la_LDFLAGS = -no-undefined -version-info 0:3:5 +libcglm_la_LDFLAGS = -no-undefined -version-info 0:1:0 checkLDFLAGS = -L./.libs \ -L./test/lib/cmocka/build/src \ From c148eacdc25a82c0fdca3552fe3115856c88486c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 8 Mar 2018 13:12:08 +0300 Subject: [PATCH 026/292] fix unproject's parameters --- include/cglm/project.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/project.h b/include/cglm/project.h index 27cb42a..911a69b 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -75,7 +75,7 @@ glm_unprojecti(mat4 invMat, vec4 vp, vec3 coord, vec4 dest) { */ CGLM_INLINE void -glm_unproject(mat4 m, vec2 vp, vec3 coord, vec3 dest) { +glm_unproject(mat4 m, vec4 vp, vec3 coord, vec4 dest) { mat4 inv; glm_mat4_inv(m, inv); glm_unprojecti(inv, vp, coord, dest); From 780179ff0d5796690a3ae84c2160e4cd5e4de22c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 8 Mar 2018 22:29:10 +0300 Subject: [PATCH 027/292] fix unproject --- include/cglm/call/project.h | 2 +- include/cglm/project.h | 5 ++++- src/project.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/cglm/call/project.h b/include/cglm/call/project.h index 1120b21..c60b9b3 100644 --- a/include/cglm/call/project.h +++ b/include/cglm/call/project.h @@ -19,7 +19,7 @@ glmc_unprojecti(mat4 invMat, vec4 vp, vec3 coord, vec3 dest); CGLM_EXPORT void -glmc_unproject(mat4 m, vec2 vp, vec3 coord, vec3 dest); +glmc_unproject(mat4 m, vec4 vp, vec3 coord, vec3 dest); #ifdef __cplusplus } diff --git a/include/cglm/project.h b/include/cglm/project.h index 911a69b..8a53577 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -9,6 +9,8 @@ #define cglm_project_h #include "mat4.h" +#include "vec3.h" +#include "vec4.h" /*! * @brief maps the specified viewport coordinates into specified space [1] @@ -46,7 +48,8 @@ glm_unprojecti(mat4 invMat, vec4 vp, vec3 coord, vec4 dest) { v[2] = 2.0f * coord[2] - 1.0f; v[3] = 1.0f; - glm_mat4_mulv(invMat, v, dest); + glm_mat4_mulv(invMat, v, v); + glm_vec4_scale(v, 1.0f / v[3], dest); } /*! diff --git a/src/project.c b/src/project.c index 80e0b44..16209e7 100644 --- a/src/project.c +++ b/src/project.c @@ -16,6 +16,6 @@ glmc_unprojecti(mat4 invMat, vec4 vp, vec3 coord, vec3 dest) { CGLM_EXPORT void -glmc_unproject(mat4 m, vec2 vp, vec3 coord, vec3 dest) { +glmc_unproject(mat4 m, vec4 vp, vec3 coord, vec3 dest) { glm_unproject(m, vp, coord, dest); } From 91b2a989e2ca50ccfe75aa70ee05b242cd94311d Mon Sep 17 00:00:00 2001 From: mcsquizzy123 Date: Mon, 19 Mar 2018 18:37:49 -0700 Subject: [PATCH 028/292] typo fixes - heaer and haeder --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 84b321e..e10597f 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ If you want to use inline versions of funcstions then; include main header ```C #include ``` -the haeder will include all headers. Then call func you want e.g. rotate vector by axis: +the header will include all headers. Then call func you want e.g. rotate vector by axis: ```C glm_vec_rotate(v1, glm_rad(45), (vec3){1.0f, 0.0f, 0.0f}); ``` @@ -180,7 +180,7 @@ to call pre-compiled versions include header with `c` postfix, c means call. Pre ```C #include ``` -this header will include all heaers with c postfix. You need to call functions with c posfix: +this header will include all headers with c postfix. You need to call functions with c posfix: ```C glmc_vec_normalize(vec); ``` From 86055097e1e8325abbe7624c5f97b18c1b209220 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 22 Mar 2018 18:10:10 +0300 Subject: [PATCH 029/292] clamp functions --- include/cglm/util.h | 13 +++++++++++++ include/cglm/vec3.h | 15 +++++++++++++++ include/cglm/vec4.h | 16 ++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/include/cglm/util.h b/include/cglm/util.h index 12db1a2..20b4c67 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -115,4 +115,17 @@ glm_max(float a, float b) { return b; } +/*! + * @brief clamp a number between min and max + * + * @param[in] val value to clamp + * @param[in] minVal minimum value + * @param[in] maxVal maximum value + */ +CGLM_INLINE +float +glm_clamp(float val, float minVal, float maxVal) { + return glm_min(glm_max(val, minVal), maxVal); +} + #endif /* cglm_util_h */ diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 26adf7d..82c729a 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -478,6 +478,21 @@ glm_vec_ortho(vec3 v, vec3 dest) { dest[2] = v[0] - v[1]; } +/*! + * @brief clamp vector's individual members between min and max values + * + * @param[in, out] v vector + * @param[in] minVal minimum value + * @param[in] maxVal maximum value + */ +CGLM_INLINE +void +glm_vec_clamp(vec3 v, float minVal, float maxVal) { + v[0] = glm_clamp(v[0], minVal, maxVal); + v[1] = glm_clamp(v[1], minVal, maxVal); + v[2] = glm_clamp(v[2], minVal, maxVal); +} + /*! * @brief vec3 cross product * diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index a656166..0e6659e 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -373,4 +373,20 @@ glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { dest[3] = glm_min(v1[3], v2[3]); } +/*! + * @brief clamp vector's individual members between min and max values + * + * @param[in, out] v vector + * @param[in] minVal minimum value + * @param[in] maxVal maximum value + */ +CGLM_INLINE +void +glm_vec4_clamp(vec4 v, float minVal, float maxVal) { + v[0] = glm_clamp(v[0], minVal, maxVal); + v[1] = glm_clamp(v[1], minVal, maxVal); + v[2] = glm_clamp(v[2], minVal, maxVal); + v[3] = glm_clamp(v[3], minVal, maxVal); +} + #endif /* cglm_vec4_h */ From 48b7b30e4261d03d385aa263022bf756908d47ad Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 22 Mar 2018 21:18:08 +0300 Subject: [PATCH 030/292] add call version for clamp --- include/cglm/call/vec3.h | 4 ++++ include/cglm/call/vec4.h | 4 ++++ include/cglm/vec3.h | 1 + include/cglm/vec4.h | 1 + src/vec3.c | 6 ++++++ src/vec4.c | 6 ++++++ 6 files changed, 22 insertions(+) diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index a637d7e..461de0b 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -104,6 +104,10 @@ CGLM_EXPORT void glmc_vec_minv(vec3 v1, vec3 v2, vec3 dest); +CGLM_EXPORT +void +glmc_vec_clamp(vec3 v, float minVal, float maxVal); + #ifdef __cplusplus } #endif diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index 084fce2..b63af80 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -85,6 +85,10 @@ CGLM_EXPORT void glmc_vec4_minv(vec4 v1, vec4 v2, vec4 dest); +CGLM_EXPORT +void +glmc_vec4_clamp(vec4 v, float minVal, float maxVal); + #ifdef __cplusplus } #endif diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 82c729a..e2108f3 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -46,6 +46,7 @@ CGLM_INLINE void glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest); CGLM_INLINE void glm_vec_minv(vec3 v1, vec3 v2, vec3 dest); CGLM_INLINE void glm_vec_ortho(vec3 v, vec3 dest); + CGLM_INLINE void glm_vec_clamp(vec3 v, float minVal, float maxVal); Convenient: CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d); diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 0e6659e..95bab09 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -40,6 +40,7 @@ CGLM_INLINE float glm_vec4_distance(vec4 v1, vec4 v2); CGLM_INLINE void glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest); CGLM_INLINE void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest); + CGLM_INLINE void glm_vec4_clamp(vec4 v, float minVal, float maxVal); */ #ifndef cglm_vec4_h diff --git a/src/vec3.c b/src/vec3.c index f377d88..ebc677d 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -139,3 +139,9 @@ void glmc_vec_minv(vec3 v1, vec3 v2, vec3 dest) { glm_vec_maxv(v1, v2, dest); } + +CGLM_EXPORT +void +glmc_vec_clamp(vec3 v, float minVal, float maxVal) { + glm_vec_clamp(v, minVal, maxVal); +} diff --git a/src/vec4.c b/src/vec4.c index 279652d..f5f6a06 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -109,3 +109,9 @@ void glmc_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { glm_vec4_maxv(v1, v2, dest); } + +CGLM_EXPORT +void +glmc_vec4_clamp(vec4 v, float minVal, float maxVal) { + glm_vec4_clamp(v, minVal, maxVal); +} From 71b48b530ebd73a33a8f72cb92092db5b6caf9de Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 22 Mar 2018 21:24:26 +0300 Subject: [PATCH 031/292] add documentation for clamp --- docs/source/util.rst | 15 +++++++++++++++ docs/source/vec3.rst | 10 ++++++++++ docs/source/vec4.rst | 10 ++++++++++ 3 files changed, 35 insertions(+) diff --git a/docs/source/util.rst b/docs/source/util.rst index 048be70..43a9d49 100644 --- a/docs/source/util.rst +++ b/docs/source/util.rst @@ -18,6 +18,9 @@ Functions: #. :c:func:`glm_make_rad` #. :c:func:`glm_make_deg` #. :c:func:`glm_pow2` +#. :c:func:`glm_min` +#. :c:func:`glm_max` +#. :c:func:`glm_clamp` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -91,3 +94,15 @@ Functions documentation Returns: maximum value + +.. c:function:: void glm_clamp(float val, float minVal, float maxVal) + + constrain a value to lie between two further values + + Parameters: + | *[in]* **val** input value + | *[in]* **minVal** minimum value + | *[in]* **maxVal** maximum value + + Returns: + clamped value diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index 2ae95f0..355178d 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -53,6 +53,7 @@ Functions: #. :c:func:`glm_vec_maxv` #. :c:func:`glm_vec_minv` #. :c:func:`glm_vec_ortho` +#. :c:func:`glm_vec_clamp` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -271,3 +272,12 @@ Functions documentation Parameters: | *[in]* **mat** vector | *[out]* **dest** orthogonal/perpendicular vector + +.. c:function:: void glm_vec_clamp(vec3 v, float minVal, float maxVal) + + constrain a value to lie between two further values + + Parameters: + | *[in, out]* **v** vector + | *[in]* **minVal** minimum value + | *[in]* **maxVal** maximum value diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index 60be7fa..ac1b9c5 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -39,6 +39,7 @@ Functions: #. :c:func:`glm_vec4_distance` #. :c:func:`glm_vec4_maxv` #. :c:func:`glm_vec4_minv` +#. :c:func:`glm_vec4_clamp` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -203,3 +204,12 @@ Functions documentation | *[in]* **v1** vector1 | *[in]* **v2** vector2 | *[out]* **dest** destination + +.. c:function:: void glm_vec4_clamp(vec4 v, float minVal, float maxVal) + + constrain a value to lie between two further values + + Parameters: + | *[in, out]* **v** vector + | *[in]* **minVal** minimum value + | *[in]* **maxVal** maximum value From 21ec45b2af4d664b62477235ec290f3b262764be Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 22 Mar 2018 21:24:41 +0300 Subject: [PATCH 032/292] add tests for clamp --- makefile.am | 3 ++- test/src/test_clamp.c | 30 ++++++++++++++++++++++++++++++ test/src/test_main.c | 5 ++++- test/src/test_tests.h | 3 +++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 test/src/test_clamp.c diff --git a/makefile.am b/makefile.am index f6d1471..0767008 100644 --- a/makefile.am +++ b/makefile.am @@ -104,7 +104,8 @@ test_tests_SOURCES=\ test/src/test_common.c \ test/src/test_main.c \ test/src/test_mat4.c \ - test/src/test_cam.c + test/src/test_cam.c \ + test/src/test_clamp.c all-local: sh ./post-build.sh diff --git a/test/src/test_clamp.c b/test/src/test_clamp.c new file mode 100644 index 0000000..ee98958 --- /dev/null +++ b/test/src/test_clamp.c @@ -0,0 +1,30 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +void +test_clamp(void **state) { + vec3 v3 = {15.07, 0.4, 17.3}; + vec4 v4 = {5.07, 2.3, 1.3, 1.4}; + + assert_true(glm_clamp(1.6f, 0.0f, 1.0f) == 1.0f); + assert_true(glm_clamp(-1.6f, 0.0f, 1.0f) == 0.0f); + assert_true(glm_clamp(0.6f, 0.0f, 1.0f) == 0.6f); + + glm_vec_clamp(v3, 0.0, 1.0); + glm_vec4_clamp(v4, 1.5, 3.0); + + assert_true(v3[0] == 1.0f); + assert_true(v3[1] == 0.4f); + assert_true(v3[2] == 1.0f); + + assert_true(v4[0] == 3.0f); + assert_true(v4[1] == 2.3f); + assert_true(v4[2] == 1.5f); + assert_true(v4[3] == 1.5f); +} diff --git a/test/src/test_main.c b/test/src/test_main.c index 5d59cfd..4de5184 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -14,7 +14,10 @@ main(int argc, const char * argv[]) { /* camera */ cmocka_unit_test(test_camera_lookat), - cmocka_unit_test(test_camera_decomp) + cmocka_unit_test(test_camera_decomp), + + /* vector */ + cmocka_unit_test(test_clamp) }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/test/src/test_tests.h b/test/src/test_tests.h index a4e5adb..fb9771e 100644 --- a/test/src/test_tests.h +++ b/test/src/test_tests.h @@ -16,4 +16,7 @@ test_camera_lookat(void **state); void test_camera_decomp(void **state); +void +test_clamp(void **state); + #endif /* test_tests_h */ From 205d13aa93484b83cca2b83e7b592f18a09ba890 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 26 Mar 2018 23:00:38 +0300 Subject: [PATCH 033/292] fix euler angles (extrinsic -> intrinsic) because cglm uses intrinsics for these rotations --- include/cglm/euler.h | 442 ++++++++++++++++++++++++------------------- 1 file changed, 243 insertions(+), 199 deletions(-) diff --git a/include/cglm/euler.h b/include/cglm/euler.h index 2289b04..66e0f77 100644 --- a/include/cglm/euler.h +++ b/include/cglm/euler.h @@ -5,6 +5,14 @@ * Full license can be found in the LICENSE file */ +/* + NOTE: + angles must be passed as [X-Angle, Y-Angle, Z-angle] order + For instance you don't pass angles as [Z-Angle, X-Angle, Y-angle] to + glm_euler_zxy funciton, All RELATED functions accept angles same order + which is [X, Y, Z]. + */ + /* Types: enum glm_euler_sq @@ -95,219 +103,255 @@ glm_euler_angles(mat4 m, vec3 dest) { } } + /*! * @brief build rotation matrix from euler angles * - * @param[in] angles angles as vector [Ex, Ey, Ez] + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] + * @param[out] dest rotation matrix + */ +CGLM_INLINE +void +glm_euler_xyz(vec3 angles, mat4 dest) { + float cx, cy, cz, + sx, sy, sz, czsx, cxcz, sysz; + + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); + + czsx = cz * sx; + cxcz = cx * cz; + sysz = sy * sz; + + dest[0][0] = cy * cz; + dest[0][1] = czsx * sy + cx * sz; + dest[0][2] = -cxcz * sy + sx * sz; + dest[1][0] = -cy * sz; + dest[1][1] = cxcz - sx * sysz; + dest[1][2] = czsx + cx * sysz; + dest[2][0] = sy; + dest[2][1] = -cy * sx; + dest[2][2] = cx * cy; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; +} + +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] * @param[out] dest rotation matrix */ CGLM_INLINE void glm_euler(vec3 angles, mat4 dest) { - float cx, cy, cz, - sx, sy, sz; - - sx = sinf(angles[0]); cx = cosf(angles[0]); - sy = sinf(angles[1]); cy = cosf(angles[1]); - sz = sinf(angles[2]); cz = cosf(angles[2]); - - dest[0][0] = cy * cz; - dest[0][1] = cy * sz; - dest[0][2] =-sy; - dest[1][0] = cz * sx * sy - cx * sz; - dest[1][1] = cx * cz + sx * sy * sz; - dest[1][2] = cy * sx; - dest[2][0] = cx * cz * sy + sx * sz; - dest[2][1] =-cz * sx + cx * sy * sz; - dest[2][2] = cx * cy; - dest[0][3] = 0.0f; - dest[1][3] = 0.0f; - dest[2][3] = 0.0f; - dest[3][0] = 0.0f; - dest[3][1] = 0.0f; - dest[3][2] = 0.0f; - dest[3][3] = 1.0f; + glm_euler_xyz(angles, dest); } /*! * @brief build rotation matrix from euler angles * - * @param[in] angles angles as vector [Ez, Ey, Ex] + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] * @param[out] dest rotation matrix */ CGLM_INLINE void -glm_euler_zyx(vec3 angles, - mat4 dest) { +glm_euler_xzy(vec3 angles, mat4 dest) { float cx, cy, cz, - sx, sy, sz; + sx, sy, sz, sxsy, cysx, cxsy, cxcy; - sx = sinf(angles[0]); cx = cosf(angles[0]); - sy = sinf(angles[1]); cy = cosf(angles[1]); - sz = sinf(angles[2]); cz = cosf(angles[2]); + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); - dest[0][0] = cy * cz; - dest[0][1] = cz * sx * sy + cx * sz; - dest[0][2] =-cx * cz * sy + sx * sz; - dest[1][0] =-cy * sz; - dest[1][1] = cx * cz - sx * sy * sz; - dest[1][2] = cz * sx + cx * sy * sz; - dest[2][0] = sy; - dest[2][1] =-cy * sx; - dest[2][2] = cx * cy; - dest[0][3] = 0.0f; - dest[1][3] = 0.0f; - dest[2][3] = 0.0f; - dest[3][0] = 0.0f; - dest[3][1] = 0.0f; - dest[3][2] = 0.0f; - dest[3][3] = 1.0f; + sxsy = sx * sy; + cysx = cy * sx; + cxsy = cx * sy; + cxcy = cx * cy; + + dest[0][0] = cy * cz; + dest[0][1] = sxsy + cxcy * sz; + dest[0][2] = -cxsy + cysx * sz; + dest[1][0] = -sz; + dest[1][1] = cx * cz; + dest[1][2] = cz * sx; + dest[2][0] = cz * sy; + dest[2][1] = -cysx + cxsy * sz; + dest[2][2] = cxcy + sxsy * sz; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; } + /*! * @brief build rotation matrix from euler angles * - * @param[in] angles angles as vector [Ez, Ex, Ey] + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] * @param[out] dest rotation matrix */ CGLM_INLINE void -glm_euler_zxy(vec3 angles, - mat4 dest) { +glm_euler_yxz(vec3 angles, mat4 dest) { float cx, cy, cz, - sx, sy, sz; + sx, sy, sz, cycz, sysz, czsy, cysz; - sx = sinf(angles[0]); cx = cosf(angles[0]); - sy = sinf(angles[1]); cy = cosf(angles[1]); - sz = sinf(angles[2]); cz = cosf(angles[2]); + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); - dest[0][0] = cy * cz + sx * sy * sz; - dest[0][1] = cx * sz; - dest[0][2] =-cz * sy + cy * sx * sz; - dest[1][0] = cz * sx * sy - cy * sz; - dest[1][1] = cx * cz; - dest[1][2] = cy * cz * sx + sy * sz; - dest[2][0] = cx * sy; - dest[2][1] =-sx; - dest[2][2] = cx * cy; - dest[0][3] = 0.0f; - dest[1][3] = 0.0f; - dest[2][3] = 0.0f; - dest[3][0] = 0.0f; - dest[3][1] = 0.0f; - dest[3][2] = 0.0f; - dest[3][3] = 1.0f; + cycz = cy * cz; + sysz = sy * sz; + czsy = cz * sy; + cysz = cy * sz; + + dest[0][0] = cycz + sx * sysz; + dest[0][1] = cx * sz; + dest[0][2] = -czsy + cysz * sx; + dest[1][0] = -cysz + czsy * sx; + dest[1][1] = cx * cz; + dest[1][2] = cycz * sx + sysz; + dest[2][0] = cx * sy; + dest[2][1] = -sx; + dest[2][2] = cx * cy; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; } /*! * @brief build rotation matrix from euler angles * - * @param[in] angles angles as vector [Ex, Ez, Ey] + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] * @param[out] dest rotation matrix */ CGLM_INLINE void -glm_euler_xzy(vec3 angles, - mat4 dest) { +glm_euler_yzx(vec3 angles, mat4 dest) { float cx, cy, cz, - sx, sy, sz; + sx, sy, sz, sxsy, cxcy, cysx, cxsy; - sx = sinf(angles[0]); cx = cosf(angles[0]); - sy = sinf(angles[1]); cy = cosf(angles[1]); - sz = sinf(angles[2]); cz = cosf(angles[2]); + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); - dest[0][0] = cy * cz; - dest[0][1] = sz; - dest[0][2] =-cz * sy; - dest[1][0] = sx * sy - cx * cy * sz; - dest[1][1] = cx * cz; - dest[1][2] = cy * sx + cx * sy * sz; - dest[2][0] = cx * sy + cy * sx * sz; - dest[2][1] =-cz * sx; - dest[2][2] = cx * cy - sx * sy * sz; - dest[0][3] = 0.0f; - dest[1][3] = 0.0f; - dest[2][3] = 0.0f; - dest[3][0] = 0.0f; - dest[3][1] = 0.0f; - dest[3][2] = 0.0f; - dest[3][3] = 1.0f; + sxsy = sx * sy; + cxcy = cx * cy; + cysx = cy * sx; + cxsy = cx * sy; + + dest[0][0] = cy * cz; + dest[0][1] = sz; + dest[0][2] = -cz * sy; + dest[1][0] = sxsy - cxcy * sz; + dest[1][1] = cx * cz; + dest[1][2] = cysx + cxsy * sz; + dest[2][0] = cxsy + cysx * sz; + dest[2][1] = -cz * sx; + dest[2][2] = cxcy - sxsy * sz; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; } /*! * @brief build rotation matrix from euler angles * - * @param[in] angles angles as vector [Ey, Ez, Ex] + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] * @param[out] dest rotation matrix */ CGLM_INLINE void -glm_euler_yzx(vec3 angles, - mat4 dest) { +glm_euler_zxy(vec3 angles, mat4 dest) { float cx, cy, cz, - sx, sy, sz; + sx, sy, sz, cycz, sxsy, cysz; - sx = sinf(angles[0]); cx = cosf(angles[0]); - sy = sinf(angles[1]); cy = cosf(angles[1]); - sz = sinf(angles[2]); cz = cosf(angles[2]); + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); - dest[0][0] = cy * cz; - dest[0][1] = sx * sy + cx * cy * sz; - dest[0][2] =-cx * sy + cy * sx * sz; - dest[1][0] =-sz; - dest[1][1] = cx * cz; - dest[1][2] = cz * sx; - dest[2][0] = cz * sy; - dest[2][1] =-cy * sx + cx * sy * sz; - dest[2][2] = cx * cy + sx * sy * sz; - dest[0][3] = 0.0f; - dest[1][3] = 0.0f; - dest[2][3] = 0.0f; - dest[3][0] = 0.0f; - dest[3][1] = 0.0f; - dest[3][2] = 0.0f; - dest[3][3] = 1.0f; + cycz = cy * cz; + sxsy = sx * sy; + cysz = cy * sz; + + dest[0][0] = cycz - sxsy * sz; + dest[0][1] = cz * sxsy + cysz; + dest[0][2] = -cx * sy; + dest[1][0] = -cx * sz; + dest[1][1] = cx * cz; + dest[1][2] = sx; + dest[2][0] = cz * sy + cysz * sx; + dest[2][1] = -cycz * sx + sy * sz; + dest[2][2] = cx * cy; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; } /*! * @brief build rotation matrix from euler angles * - * @param[in] angles angles as vector [Ey, Ex, Ez] + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] * @param[out] dest rotation matrix */ CGLM_INLINE void -glm_euler_yxz(vec3 angles, - mat4 dest) { +glm_euler_zyx(vec3 angles, mat4 dest) { float cx, cy, cz, - sx, sy, sz; + sx, sy, sz, czsx, cxcz, sysz; - sx = sinf(angles[0]); cx = cosf(angles[0]); - sy = sinf(angles[1]); cy = cosf(angles[1]); - sz = sinf(angles[2]); cz = cosf(angles[2]); + sx = sinf(angles[0]); cx = cosf(angles[0]); + sy = sinf(angles[1]); cy = cosf(angles[1]); + sz = sinf(angles[2]); cz = cosf(angles[2]); - dest[0][0] = cy * cz - sx * sy * sz; - dest[0][1] = cz * sx * sy + cy * sz; - dest[0][2] =-cx * sy; - dest[1][0] =-cx * sz; - dest[1][1] = cx * cz; - dest[1][2] = sx; - dest[2][0] = cz * sy + cy * sx * sz; - dest[2][1] =-cy * cz * sx + sy * sz; - dest[2][2] = cx * cy; - dest[0][3] = 0.0f; - dest[1][3] = 0.0f; - dest[2][3] = 0.0f; - dest[3][0] = 0.0f; - dest[3][1] = 0.0f; - dest[3][2] = 0.0f; - dest[3][3] = 1.0f; + czsx = cz * sx; + cxcz = cx * cz; + sysz = sy * sz; + + dest[0][0] = cy * cz; + dest[0][1] = cy * sz; + dest[0][2] = -sy; + dest[1][0] = czsx * sy - cx * sz; + dest[1][1] = cxcz + sx * sysz; + dest[1][2] = cy * sx; + dest[2][0] = cxcz * sy + sx * sz; + dest[2][1] = -czsx + cx * sysz; + dest[2][2] = cx * cy; + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; } /*! * @brief build rotation matrix from euler angles * - * @param[in] angles angles as vector (ord parameter spceifies angles order) + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] * @param[in] ord euler order * @param[out] dest rotation matrix */ @@ -332,71 +376,71 @@ glm_euler_by_order(vec3 angles, glm_euler_sq ord, mat4 dest) { sysz = sy * sz; switch (ord) { - case GLM_EULER_XYZ: - dest[0][0] = cycz; - dest[0][1] = cysz; - dest[0][2] =-sy; - dest[1][0] = czsx * sy - cxsz; - dest[1][1] = cxcz + sx * sysz; - dest[1][2] = cysx; - dest[2][0] = cx * czsy + sx * sz; - dest[2][1] =-czsx + cx * sysz; - dest[2][2] = cxcy; - break; case GLM_EULER_XZY: - dest[0][0] = cycz; - dest[0][1] = sz; - dest[0][2] =-czsy; - dest[1][0] = sx * sy - cx * cysz; - dest[1][1] = cxcz; - dest[1][2] = cysx + cx * sysz; - dest[2][0] = cx * sy + cysx * sz; - dest[2][1] =-czsx; - dest[2][2] = cxcy - sx * sysz; + dest[0][0] = cycz; + dest[0][1] = sx * sy + cx * cysz; + dest[0][2] = -cx * sy + cysx * sz; + dest[1][0] = -sz; + dest[1][1] = cxcz; + dest[1][2] = czsx; + dest[2][0] = czsy; + dest[2][1] = -cysx + cx * sysz; + dest[2][2] = cxcy + sx * sysz; break; - case GLM_EULER_ZXY: - dest[0][0] = cycz + sx * sysz; - dest[0][1] = cxsz; - dest[0][2] =-czsy + cysx * sz; - dest[1][0] = czsx * sy - cysz; - dest[1][1] = cxcz; - dest[1][2] = cycz * sx + sysz; - dest[2][0] = cx * sy; - dest[2][1] =-sx; - dest[2][2] = cxcy; - break; - case GLM_EULER_ZYX: - dest[0][0] = cycz; - dest[0][1] = czsx * sy + cxsz; - dest[0][2] =-cx * czsy + sx * sz; - dest[1][0] =-cysz; - dest[1][1] = cxcz - sx * sysz; - dest[1][2] = czsx + cx * sysz; - dest[2][0] = sy; - dest[2][1] =-cysx; - dest[2][2] = cxcy; + case GLM_EULER_XYZ: + dest[0][0] = cycz; + dest[0][1] = czsx * sy + cxsz; + dest[0][2] = -cx * czsy + sx * sz; + dest[1][0] = -cysz; + dest[1][1] = cxcz - sx * sysz; + dest[1][2] = czsx + cx * sysz; + dest[2][0] = sy; + dest[2][1] = -cysx; + dest[2][2] = cxcy; break; case GLM_EULER_YXZ: - dest[0][0] = cycz - sx * sysz; - dest[0][1] = czsx * sy + cysz; - dest[0][2] =-cx * sy; - dest[1][0] =-cxsz; - dest[1][1] = cxcz; - dest[1][2] = sx; - dest[2][0] = czsy + cysx * sz; - dest[2][1] =-cycz * sx + sysz; - dest[2][2] = cxcy; + dest[0][0] = cycz + sx * sysz; + dest[0][1] = cxsz; + dest[0][2] = -czsy + cysx * sz; + dest[1][0] = czsx * sy - cysz; + dest[1][1] = cxcz; + dest[1][2] = cycz * sx + sysz; + dest[2][0] = cx * sy; + dest[2][1] = -sx; + dest[2][2] = cxcy; break; case GLM_EULER_YZX: - dest[0][0] = cycz; - dest[0][1] = sx * sy + cx * cysz; - dest[0][2] =-cx * sy + cysx * sz; - dest[1][0] =-sz; - dest[1][1] = cxcz; - dest[1][2] = czsx; - dest[2][0] = czsy; - dest[2][1] =-cysx + cx * sysz; - dest[2][2] = cxcy + sx * sysz; + dest[0][0] = cycz; + dest[0][1] = sz; + dest[0][2] = -czsy; + dest[1][0] = sx * sy - cx * cysz; + dest[1][1] = cxcz; + dest[1][2] = cysx + cx * sysz; + dest[2][0] = cx * sy + cysx * sz; + dest[2][1] = -czsx; + dest[2][2] = cxcy - sx * sysz; + break; + case GLM_EULER_ZXY: + dest[0][0] = cycz - sx * sysz; + dest[0][1] = czsx * sy + cysz; + dest[0][2] = -cx * sy; + dest[1][0] = -cxsz; + dest[1][1] = cxcz; + dest[1][2] = sx; + dest[2][0] = czsy + cysx * sz; + dest[2][1] = -cycz * sx + sysz; + dest[2][2] = cxcy; + break; + case GLM_EULER_ZYX: + dest[0][0] = cycz; + dest[0][1] = cysz; + dest[0][2] = -sy; + dest[1][0] = czsx * sy - cxsz; + dest[1][1] = cxcz + sx * sysz; + dest[1][2] = cysx; + dest[2][0] = cx * czsy + sx * sz; + dest[2][1] = -czsx + cx * sysz; + dest[2][2] = cxcy; break; } From c244b68e73e079dfa387437b683e596ee8db9cad Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 27 Mar 2018 11:22:05 +0300 Subject: [PATCH 034/292] build: improve build-deps --- build-deps.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/build-deps.sh b/build-deps.sh index 23bb9e9..74b1cfa 100644 --- a/build-deps.sh +++ b/build-deps.sh @@ -16,14 +16,18 @@ cd $(dirname "$0") if [ "$(uname)" = "Darwin" ]; then libtoolBin=$(which glibtoolize) libtoolBinDir=$(dirname "${libtoolBin}") - ln -s $libtoolBin "${libtoolBinDir}/libtoolize" + + if [ ! -f "${libtoolBinDir}/libtoolize" ]; then + ln -s $libtoolBin "${libtoolBinDir}/libtoolize" + fi fi # general deps: gcc make autoconf automake libtool cmake # test - cmocka cd ./test/lib/cmocka -mkdir build +rm -rf build +mkdir -p build cd build cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug .. make -j8 From 429821179559511aff831e42677664bd1d71b45a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 27 Mar 2018 12:14:12 +0300 Subject: [PATCH 035/292] euler: fix extracting XYZ angles --- include/cglm/call/euler.h | 4 +++ include/cglm/euler.h | 51 ++++++++++++++++++--------------------- src/euler.c | 6 +++++ 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/include/cglm/call/euler.h b/include/cglm/call/euler.h index 8cbea2b..9b85485 100644 --- a/include/cglm/call/euler.h +++ b/include/cglm/call/euler.h @@ -21,6 +21,10 @@ CGLM_EXPORT void glmc_euler(vec3 angles, mat4 dest); +CGLM_EXPORT +void +glmc_euler_xyz(vec3 angles, mat4 dest); + CGLM_EXPORT void glmc_euler_zyx(vec3 angles, mat4 dest); diff --git a/include/cglm/euler.h b/include/cglm/euler.h index 66e0f77..7417bde 100644 --- a/include/cglm/euler.h +++ b/include/cglm/euler.h @@ -69,38 +69,33 @@ glm_euler_order(int ord[3]) { CGLM_INLINE void glm_euler_angles(mat4 m, vec3 dest) { - if (m[0][2] < 1.0f) { - if (m[0][2] > -1.0f) { - vec3 a[2]; - float cy1, cy2; - int path; + float m00, m01, m10, m11, m20, m21, m22; + float thetaX, thetaY, thetaZ; - a[0][1] = asinf(-m[0][2]); - a[1][1] = CGLM_PI - a[0][1]; + m00 = m[0][0]; m10 = m[1][0]; m20 = m[2][0]; + m01 = m[0][1]; m11 = m[1][1]; m21 = m[2][1]; + m22 = m[2][2]; - cy1 = cosf(a[0][1]); - cy2 = cosf(a[1][1]); - - a[0][0] = atan2f(m[1][2] / cy1, m[2][2] / cy1); - a[1][0] = atan2f(m[1][2] / cy2, m[2][2] / cy2); - - a[0][2] = atan2f(m[0][1] / cy1, m[0][0] / cy1); - a[1][2] = atan2f(m[0][1] / cy2, m[0][0] / cy2); - - path = (fabsf(a[0][0]) + fabsf(a[0][1]) + fabsf(a[0][2])) >= - (fabsf(a[1][0]) + fabsf(a[1][1]) + fabsf(a[1][2])); - - glm_vec_copy(a[path], dest); - } else { - dest[0] = atan2f(m[1][0], m[2][0]); - dest[1] = CGLM_PI_2; - dest[2] = 0.0f; + thetaY = 0.0f; + if (m20 < 1.0f) { + if (m20 > -1.0f) { + thetaY = asinf(m20); + thetaX = atan2f(-m21, m22); + thetaZ = atan2f(-m10, m00); + } else { /* m20 == -1 */ + /* Not a unique solution */ + thetaX = -atan2f(m01, m11); + thetaZ = 0.0f; } - } else { - dest[0] = atan2f(-m[1][0], -m[2][0]); - dest[1] =-CGLM_PI_2; - dest[2] = 0.0f; + } else {/* m20 == +1 */ + thetaY = CGLM_PI_2; + thetaX = atan2f(m01, m11); + thetaZ = 0.0f; } + + dest[0] = thetaX; + dest[1] = thetaY; + dest[2] = thetaZ; } diff --git a/src/euler.c b/src/euler.c index 5c945e2..44d6edb 100644 --- a/src/euler.c +++ b/src/euler.c @@ -20,6 +20,12 @@ glmc_euler(vec3 angles, mat4 dest) { glm_euler(angles, dest); } +CGLM_EXPORT +void +glmc_euler_xyz(vec3 angles, mat4 dest) { + glm_euler_xyz(angles, dest); +} + CGLM_EXPORT void glmc_euler_zyx(vec3 angles, mat4 dest) { From d1f3feeb6e2bbbf76a0524e098a6ca913665bd2f Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 27 Mar 2018 12:14:46 +0300 Subject: [PATCH 036/292] test: add tests for euler XYZ --- makefile.am | 3 ++- test/src/test_common.c | 7 +++++++ test/src/test_common.h | 3 +++ test/src/test_euler.c | 44 ++++++++++++++++++++++++++++++++++++++++++ test/src/test_main.c | 5 ++++- test/src/test_tests.h | 3 +++ 6 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 test/src/test_euler.c diff --git a/makefile.am b/makefile.am index 0767008..a81bdd5 100644 --- a/makefile.am +++ b/makefile.am @@ -105,7 +105,8 @@ test_tests_SOURCES=\ test/src/test_main.c \ test/src/test_mat4.c \ test/src/test_cam.c \ - test/src/test_clamp.c + test/src/test_clamp.c \ + test/src/test_euler.c all-local: sh ./post-build.sh diff --git a/test/src/test_common.c b/test/src/test_common.c index e6f36ab..23f2b50 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -50,3 +50,10 @@ test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps) { } } } + +void +test_assert_vec3_eq(vec3 v1, vec3 v2) { + assert_true(fabsf(v1[0] - v2[0]) <= 0.0000009); + assert_true(fabsf(v1[1] - v2[1]) <= 0.0000009); + assert_true(fabsf(v1[2] - v2[2]) <= 0.0000009); +} diff --git a/test/src/test_common.h b/test/src/test_common.h index 5fff3d7..aeea4d6 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -31,4 +31,7 @@ test_assert_mat4_eq(mat4 m1, mat4 m2); void test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps); +void +test_assert_vec3_eq(vec3 v1, vec3 v2); + #endif /* test_common_h */ diff --git a/test/src/test_euler.c b/test/src/test_euler.c new file mode 100644 index 0000000..b71c4cb --- /dev/null +++ b/test/src/test_euler.c @@ -0,0 +1,44 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +void +test_euler(void **state) { + mat4 rot1, rot2; + vec3 inAngles, outAngles; + + inAngles[0] = glm_rad(-45.0f); /* X angle */ + inAngles[1] = glm_rad(88.0f); /* Y angle */ + inAngles[2] = glm_rad(18.0f); /* Z angle */ + + glm_euler_xyz(inAngles, rot1); + + /* extract angles */ + glmc_euler_angles(rot1, outAngles); + + /* angles must be equal in that range */ + test_assert_vec3_eq(inAngles, outAngles); + + /* matrices must be equal */ + glmc_euler_xyz(outAngles, rot2); + test_assert_mat4_eq(rot1, rot2); + + /* change range */ + inAngles[0] = glm_rad(-145.0f); /* X angle */ + inAngles[1] = glm_rad(818.0f); /* Y angle */ + inAngles[2] = glm_rad(181.0f); /* Z angle */ + + glm_euler_xyz(inAngles, rot1); + glmc_euler_angles(rot1, outAngles); + + /* angles may not be equal but matrices MUST! */ + + /* matrices must be equal */ + glmc_euler_xyz(outAngles, rot2); + test_assert_mat4_eq(rot1, rot2); +} diff --git a/test/src/test_main.c b/test/src/test_main.c index 4de5184..38eb4c2 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -17,7 +17,10 @@ main(int argc, const char * argv[]) { cmocka_unit_test(test_camera_decomp), /* vector */ - cmocka_unit_test(test_clamp) + cmocka_unit_test(test_clamp), + + /* euler */ + cmocka_unit_test(test_euler) }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/test/src/test_tests.h b/test/src/test_tests.h index fb9771e..b1288f7 100644 --- a/test/src/test_tests.h +++ b/test/src/test_tests.h @@ -19,4 +19,7 @@ test_camera_decomp(void **state); void test_clamp(void **state); +void +test_euler(void **state); + #endif /* test_tests_h */ From 26110f83d112357d1e900edfbe17f9e0eacd283e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 27 Mar 2018 12:35:19 +0300 Subject: [PATCH 037/292] euler: fix thetaY in extracting angles --- include/cglm/euler.h | 5 ++--- test/src/test_main.c | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/cglm/euler.h b/include/cglm/euler.h index 7417bde..5db7e66 100644 --- a/include/cglm/euler.h +++ b/include/cglm/euler.h @@ -76,7 +76,6 @@ glm_euler_angles(mat4 m, vec3 dest) { m01 = m[0][1]; m11 = m[1][1]; m21 = m[2][1]; m22 = m[2][2]; - thetaY = 0.0f; if (m20 < 1.0f) { if (m20 > -1.0f) { thetaY = asinf(m20); @@ -84,10 +83,11 @@ glm_euler_angles(mat4 m, vec3 dest) { thetaZ = atan2f(-m10, m00); } else { /* m20 == -1 */ /* Not a unique solution */ + thetaY = -CGLM_PI_2; thetaX = -atan2f(m01, m11); thetaZ = 0.0f; } - } else {/* m20 == +1 */ + } else { /* m20 == +1 */ thetaY = CGLM_PI_2; thetaX = atan2f(m01, m11); thetaZ = 0.0f; @@ -98,7 +98,6 @@ glm_euler_angles(mat4 m, vec3 dest) { dest[2] = thetaZ; } - /*! * @brief build rotation matrix from euler angles * diff --git a/test/src/test_main.c b/test/src/test_main.c index 38eb4c2..38d2fe4 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -20,7 +20,7 @@ main(int argc, const char * argv[]) { cmocka_unit_test(test_clamp), /* euler */ - cmocka_unit_test(test_euler) + cmocka_unit_test(test_euler) }; return cmocka_run_group_tests(tests, NULL, NULL); From 5a7b9caf166a1606965763d0d7ed0213fba414d9 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 29 Mar 2018 00:02:37 +0300 Subject: [PATCH 038/292] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e10597f..6d047e8 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Complete documentation: http://cglm.readthedocs.io - _dup (duplicate) is changed to _copy. For instance `glm_vec_dup -> glm_vec_copy` - OpenGL related functions are dropped to make this lib platform/third-party independent - make sure you have latest version and feel free to report bugs, troubles +- **[bugfix]** euler angles was implemented in reverse order (extrinsic) it was fixed, now they are intrinsic. Make sure that you have the latest version #### Note for C++ developers: If you don't aware about original GLM library yet, you may also want to look at: From ca504f70583d2e890dcc6d4e1d1368ab30898119 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 29 Mar 2018 00:12:16 +0300 Subject: [PATCH 039/292] now working on v0.3.6 --- configure.ac | 2 +- include/cglm/version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 23e8a15..afb694b 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.3.5], [info@recp.me]) +AC_INIT([cglm], [0.3.6], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/include/cglm/version.h b/include/cglm/version.h index a025ccb..c27a26e 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 3 -#define CGLM_VERSION_PATCH 5 +#define CGLM_VERSION_PATCH 6 #endif /* cglm_version_h */ From db4761b4371c4c7175aaba201be78c9df656b49b Mon Sep 17 00:00:00 2001 From: Jess Date: Sun, 1 Apr 2018 18:12:46 +0900 Subject: [PATCH 040/292] Added backers and sponsors on the README --- README.md | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d047e8..4e7c4ef 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ # 🎥 OpenGL Mathematics (glm) for `C` [![Build Status](https://travis-ci.org/recp/cglm.svg?branch=master)](https://travis-ci.org/recp/cglm) -[![Build status](https://ci.appveyor.com/api/projects/status/av7l3gc0yhfex8y4/branch/master?svg=true)](https://ci.appveyor.com/project/recp/cglm/branch/master) + [![Build status](https://ci.appveyor.com/api/projects/status/av7l3gc0yhfex8y4/branch/master?svg=true)](https://ci.appveyor.com/project/recp/cglm/branch/master) [![Documentation Status](https://readthedocs.org/projects/cglm/badge/?version=latest)](http://cglm.readthedocs.io/en/latest/?badge=latest) [![Coverage Status](https://coveralls.io/repos/github/recp/cglm/badge.svg?branch=master)](https://coveralls.io/github/recp/cglm?branch=master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/6a62b37d5f214f178ebef269dc4a6bf1)](https://www.codacy.com/app/recp/cglm?utm_source=github.com&utm_medium=referral&utm_content=recp/cglm&utm_campaign=Badge_Grade) +[![Backers on Open Collective](https://opencollective.com/cglm/backers/badge.svg)](#backers) +[![Sponsors on Open Collective](https://opencollective.com/cglm/sponsors/badge.svg)](#sponsors) The original glm library is for C++ only (templates, namespaces, classes...), this library targeted to C99 but currently you can use it for C89 safely by language extensions e.g `__restrict` @@ -115,6 +117,36 @@ glm_mul(T, R, modelMat); glm_inv_tr(modelMat); ``` +## Contributors + +This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. + + + +## Backers + +Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/cglm#backer)] + + + + +## Sponsors + +Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/cglm#sponsor)] + + + + + + + + + + + + + + ## License MIT. check the LICENSE file From 984916d52065c3f4f3e262ed3ed3966892ff182c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 2 Apr 2018 11:50:53 +0300 Subject: [PATCH 041/292] invalidate axis-aligned boundng box util --- include/cglm/box.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/cglm/box.h b/include/cglm/box.h index d7184c5..c8115a6 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -153,4 +153,16 @@ glm_aabb_frustum(vec3 box[2], vec4 planes[6]) { return true; } +/*! + * @brief invalidate AABB min and max values + * + * @param[in, out] box bounding box + */ +CGLM_INLINE +void +glm_aabb_invalidate(vec3 box[2]) { + glm_vec_broadcast(FLT_MAX, box[0]); + glm_vec_broadcast(-FLT_MAX, box[1]); +} + #endif /* cglm_box_h */ From b0991342a65ce15f7e67e667ec2214837b64509a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 2 Apr 2018 12:08:08 +0300 Subject: [PATCH 042/292] aabb printer function --- include/cglm/io.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/cglm/io.h b/include/cglm/io.h index 2ee8ee8..f38fad7 100644 --- a/include/cglm/io.h +++ b/include/cglm/io.h @@ -171,4 +171,33 @@ glm_versor_print(versor vec, #undef m } +CGLM_INLINE +void +glm_aabb_print(vec3 bbox[2], + const char * __restrict tag, + FILE * __restrict ostream) { + int i, j; + +#define m 3 + + fprintf(ostream, "AABB (%s):\n", tag ? tag: "float"); + + for (i = 0; i < 2; i++) { + fprintf(ostream, "\t|"); + + for (j = 0; j < m; j++) { + fprintf(ostream, "%0.4f", bbox[i][j]); + + if (j != m - 1) + fprintf(ostream, "\t"); + } + + fprintf(ostream, "|\n"); + } + + fprintf(ostream, "\n"); + +#undef m +} + #endif /* cglm_io_h */ From 86efe64b8ee3093f111b706ca17fba3a09e8a419 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 2 Apr 2018 12:35:22 +0300 Subject: [PATCH 043/292] helper for check aabb is valid or not --- include/cglm/box.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/cglm/box.h b/include/cglm/box.h index c8115a6..89ef5a9 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -165,4 +165,16 @@ glm_aabb_invalidate(vec3 box[2]) { glm_vec_broadcast(-FLT_MAX, box[1]); } +/*! + * @brief check if AABB is valid or not + * + * @param[in] box bounding box + */ +CGLM_INLINE +bool +glm_aabb_isvalid(vec3 box[2]) { + return glm_vec_max(box[0]) != FLT_MAX + && glm_vec_min(box[1]) != -FLT_MAX; +} + #endif /* cglm_box_h */ From acda316c12f36991f9044ed94ee70c59d23efa7c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 2 Apr 2018 16:18:50 +0300 Subject: [PATCH 044/292] get sign of float helper as -1, +1 and 0 * add clarification for zero input --- docs/source/util.rst | 17 ++++++++++++++++- include/cglm/util.h | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/docs/source/util.rst b/docs/source/util.rst index 43a9d49..a9f4066 100644 --- a/docs/source/util.rst +++ b/docs/source/util.rst @@ -13,6 +13,7 @@ Table of contents (click to go): Functions: 1. :c:func:`glm_sign` +#. :c:func:`glm_signf` #. :c:func:`glm_rad` #. :c:func:`glm_deg` #. :c:func:`glm_make_rad` @@ -27,7 +28,9 @@ Functions documentation .. c:function:: int glm_sign(int val) - | returns sign of 32 bit integer as +1 or -1 + | returns sign of 32 bit integer as +1, -1, 0 + + | **Important**: It returns 0 for zero input Parameters: | *[in]* **val** an integer @@ -35,6 +38,18 @@ Functions documentation Returns: sign of given number +.. c:function:: float glm_signf(float val) + + | returns sign of 32 bit integer as +1.0, -1.0, 0.0 + + | **Important**: It returns 0.0f for zero input + + Parameters: + | *[in]* **val** a float + + Returns: + sign of given number + .. c:function:: float glm_rad(float deg) | convert degree to radians diff --git a/include/cglm/util.h b/include/cglm/util.h index 20b4c67..2a9ece7 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -21,7 +21,9 @@ #include "common.h" /*! - * @brief get sign of 32 bit integer as +1 or -1 + * @brief get sign of 32 bit integer as +1, -1, 0 + * + * Important: It returns 0 for zero input * * @param val integer value */ @@ -31,6 +33,19 @@ glm_sign(int val) { return ((val >> 31) - (-val >> 31)); } +/*! + * @brief get sign of 32 bit float as +1, -1, 0 + * + * Important: It returns 0 for zero/NaN input + * + * @param val float value + */ +CGLM_INLINE +float +glm_signf(float val) { + return (val > 0.0f) - (val < 0.0f); +} + /*! * @brief convert degree to radians * From dbd1e334ea3bfa9c15afe002990605b3656dffe0 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 2 Apr 2018 16:26:14 +0300 Subject: [PATCH 045/292] aabb box size and radius --- include/cglm/box.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/cglm/box.h b/include/cglm/box.h index 89ef5a9..7032339 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -177,4 +177,26 @@ glm_aabb_isvalid(vec3 box[2]) { && glm_vec_min(box[1]) != -FLT_MAX; } +/*! + * @brief distance between of min and max + * + * @param[in] box bounding box + */ +CGLM_INLINE +float +glm_aabb_size(vec3 box[2]) { + return glm_vec_distance(box[0], box[1]); +} + +/*! + * @brief radius of sphere which surrounds AABB + * + * @param[in] box bounding box + */ +CGLM_INLINE +float +glm_aabb_radius(vec3 box[2]) { + return glm_aabb_size(box) * 0.5f; +} + #endif /* cglm_box_h */ From 74f9865884ef17fc2dd72482a42aa2204ab9d4e3 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 2 Apr 2018 16:36:55 +0300 Subject: [PATCH 046/292] add docs for new aabb functions --- docs/source/box.rst | 40 ++++++++++++++++++++++++++++++++++++++++ docs/source/io.rst | 10 ++++++++++ 2 files changed, 50 insertions(+) diff --git a/docs/source/box.rst b/docs/source/box.rst index 84ba145..e6082e8 100644 --- a/docs/source/box.rst +++ b/docs/source/box.rst @@ -24,6 +24,10 @@ Functions: #. :c:func:`glm_aabb_crop` #. :c:func:`glm_aabb_crop_until` #. :c:func:`glm_aabb_frustum` +#. :c:func:`glm_aabb_invalidate` +#. :c:func:`glm_aabb_isvalid` +#. :c:func:`glm_aabb_size` +#. :c:func:`glm_aabb_radius` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -91,3 +95,39 @@ Functions documentation Parameters: | *[in]* **box** bounding box | *[out]* **planes** frustum planes + +.. c:function:: void glm_aabb_invalidate(vec3 box[2]) + + | invalidate AABB min and max values + + | It fills *max* values with -FLT_MAX and *min* values with +FLT_MAX + + Parameters: + | *[in, out]* **box** bounding box + +.. c:function:: bool check if AABB is valid or not + + | check if AABB intersects with frustum planes + + Parameters: + | *[in]* **box** bounding box + + Returns: + returns true if aabb is valid otherwise false + +.. c:function:: float glm_aabb_size(vec3 box[2]) + + | distance between of min and max + + Parameters: + | *[in]* **box** bounding box + + Returns: + distance between min - max + +.. c:function:: float glm_aabb_radius(vec3 box[2]) + + | radius of sphere which surrounds AABB + + Parameters: + | *[in]* **box** bounding box diff --git a/docs/source/io.rst b/docs/source/io.rst index 9cf8900..34fe696 100644 --- a/docs/source/io.rst +++ b/docs/source/io.rst @@ -39,6 +39,7 @@ Functions: #. :c:func:`glm_vec3_print` #. :c:func:`glm_ivec3_print` #. :c:func:`glm_versor_print` +#. :c:func:`glm_aabb_print` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -90,3 +91,12 @@ Functions documentation Parameters: | *[in]* **vec** quaternion | *[in]* **ostream** FILE to write + +.. c:function:: void glm_aabb_print(versor vec, const char * __restrict tag, FILE * __restrict ostream) + + | print aabb to given stream + + Parameters: + | *[in]* **vec** aabb (axis-aligned bounding box) + | *[in]* **tag** tag to find it more easly in logs + | *[in]* **ostream** FILE to write From c298f4a4d761e8e7fc51715eaca07d8010886d25 Mon Sep 17 00:00:00 2001 From: Matt Reyer Date: Mon, 2 Apr 2018 11:33:58 -0400 Subject: [PATCH 047/292] Fix small typo. --- docs/source/box.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/box.rst b/docs/source/box.rst index e6082e8..6aa4d62 100644 --- a/docs/source/box.rst +++ b/docs/source/box.rst @@ -105,9 +105,9 @@ Functions documentation Parameters: | *[in, out]* **box** bounding box -.. c:function:: bool check if AABB is valid or not +.. c:function:: bool glm_aabb_isvalid(vec3 box[2]) - | check if AABB intersects with frustum planes + | check if AABB is valid or not Parameters: | *[in]* **box** bounding box From 3399595dc261c937f883b982d4eb8dd792077e46 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 3 Apr 2018 10:46:46 +0300 Subject: [PATCH 048/292] add vec2 type --- include/cglm/types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/cglm/types.h b/include/cglm/types.h index a4170c4..c411d8b 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -14,6 +14,7 @@ # define CGLM_ALIGN(X) __attribute((aligned(X))) #endif +typedef float vec2[2]; typedef float vec3[3]; typedef int ivec3[3]; typedef CGLM_ALIGN(16) float vec4[4]; From 9f389ab8ec6ef846801f202c3b3faedeaf2629d5 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 3 Apr 2018 11:09:13 +0300 Subject: [PATCH 049/292] project function --- include/cglm/project.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/cglm/project.h b/include/cglm/project.h index 8a53577..fec21b0 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -84,4 +84,27 @@ glm_unproject(mat4 m, vec4 vp, vec3 coord, vec4 dest) { glm_unprojecti(inv, vp, coord, dest); } +/*! + * @brief map object coordinates to window coordinates + * + * @param[in] pos object coordinates + * @param[in] m MVP matrix + * @param[in] vp viewport as [x, y, width, height] + * @param[out] dest projected coordinates + */ +CGLM_INLINE +void +glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { + vec4 pos4; + + glm_vec4(pos, 1.0f, pos4); + + glm_mat4_mulv(m, pos4, pos4); + glm_vec4_scale(pos4, 1.0f / pos4[3], pos4); /* pos = pos / pos.w */ + + dest[0] = (pos4[0] + 1.0f) * 0.5f * vp[2] + vp[0]; + dest[1] = (pos4[1] + 1.0f) * 0.5f * vp[3] + vp[1]; + dest[2] = (pos4[2] + 1.0f) * 0.5f; +} + #endif /* cglm_project_h */ From eb527e39b45d6f29322c34cff830a4d90244651e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 3 Apr 2018 11:25:33 +0300 Subject: [PATCH 050/292] optimize project --- include/cglm/project.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/cglm/project.h b/include/cglm/project.h index fec21b0..fdb0cf9 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -67,7 +67,7 @@ glm_unprojecti(mat4 invMat, vec4 vp, vec3 coord, vec4 dest) { * You probably want to map the coordinates into object space * so use MVP as m * - * Computing viewProj: + * Computing viewProj and MVP: * glm_mat4_mul(proj, view, viewProj); * glm_mat4_mul(viewProj, model, MVP); * @@ -87,6 +87,10 @@ glm_unproject(mat4 m, vec4 vp, vec3 coord, vec4 dest) { /*! * @brief map object coordinates to window coordinates * + * Computing MVP: + * glm_mat4_mul(proj, view, viewProj); + * glm_mat4_mul(viewProj, model, MVP); + * * @param[in] pos object coordinates * @param[in] m MVP matrix * @param[in] vp viewport as [x, y, width, height] @@ -95,16 +99,18 @@ glm_unproject(mat4 m, vec4 vp, vec3 coord, vec4 dest) { CGLM_INLINE void glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { - vec4 pos4; + vec4 pos4, vone = GLM_VEC4_ONE_INIT; glm_vec4(pos, 1.0f, pos4); glm_mat4_mulv(m, pos4, pos4); glm_vec4_scale(pos4, 1.0f / pos4[3], pos4); /* pos = pos / pos.w */ + glm_vec4_add(pos4, vone, pos4); + glm_vec4_scale(pos4, 0.5f, pos4); - dest[0] = (pos4[0] + 1.0f) * 0.5f * vp[2] + vp[0]; - dest[1] = (pos4[1] + 1.0f) * 0.5f * vp[3] + vp[1]; - dest[2] = (pos4[2] + 1.0f) * 0.5f; + dest[0] = pos4[0] * vp[2] + vp[0]; + dest[1] = pos4[1] * vp[3] + vp[1]; + dest[2] = pos4[2]; } #endif /* cglm_project_h */ From 63acfd681e815dc0a4937d0786e2eeded845c24c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 3 Apr 2018 12:27:20 +0300 Subject: [PATCH 051/292] fix unproject, add tests to project/unproject --- include/cglm/call/project.h | 8 ++++++-- include/cglm/project.h | 19 ++++++++++--------- src/project.c | 14 ++++++++++---- test/src/test_main.c | 3 +++ test/src/test_project.c | 31 +++++++++++++++++++++++++++++++ test/src/test_tests.h | 3 +++ 6 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 test/src/test_project.c diff --git a/include/cglm/call/project.h b/include/cglm/call/project.h index c60b9b3..35ac087 100644 --- a/include/cglm/call/project.h +++ b/include/cglm/call/project.h @@ -15,11 +15,15 @@ extern "C" { CGLM_EXPORT void -glmc_unprojecti(mat4 invMat, vec4 vp, vec3 coord, vec3 dest); +glmc_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest); CGLM_EXPORT void -glmc_unproject(mat4 m, vec4 vp, vec3 coord, vec3 dest); +glmc_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest); + +CGLM_EXPORT +void +glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest); #ifdef __cplusplus } diff --git a/include/cglm/project.h b/include/cglm/project.h index fdb0cf9..a0b306b 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -33,23 +33,24 @@ * glm_mat4_mul(viewProj, model, MVP); * glm_mat4_inv(viewProj, invMVP); * + * @param[in] pos viewport coordinates * @param[in] invMat matrix (see brief) * @param[in] vp viewport as [x, y, width, height] - * @param[in] coord viewport coordinates * @param[out] dest unprojected coordinates */ CGLM_INLINE void -glm_unprojecti(mat4 invMat, vec4 vp, vec3 coord, vec4 dest) { +glm_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { vec4 v; - v[0] = 2.0f * (coord[0] - vp[0]) / vp[2] - 1.0f; - v[1] = 2.0f * (coord[1] - vp[1]) / vp[3] - 1.0f; - v[2] = 2.0f * coord[2] - 1.0f; + v[0] = 2.0f * (pos[0] - vp[0]) / vp[2] - 1.0f; + v[1] = 2.0f * (pos[1] - vp[1]) / vp[3] - 1.0f; + v[2] = 2.0f * pos[2] - 1.0f; v[3] = 1.0f; glm_mat4_mulv(invMat, v, v); - glm_vec4_scale(v, 1.0f / v[3], dest); + glm_vec4_scale(v, 1.0f / v[3], v); + glm_vec3(v, dest); } /*! @@ -71,17 +72,17 @@ glm_unprojecti(mat4 invMat, vec4 vp, vec3 coord, vec4 dest) { * glm_mat4_mul(proj, view, viewProj); * glm_mat4_mul(viewProj, model, MVP); * + * @param[in] pos viewport coordinates * @param[in] m matrix (see brief) * @param[in] vp viewport as [x, y, width, height] - * @param[in] coord viewport coordinates * @param[out] dest unprojected coordinates */ CGLM_INLINE void -glm_unproject(mat4 m, vec4 vp, vec3 coord, vec4 dest) { +glm_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) { mat4 inv; glm_mat4_inv(m, inv); - glm_unprojecti(inv, vp, coord, dest); + glm_unprojecti(pos, inv, vp, dest); } /*! diff --git a/src/project.c b/src/project.c index 16209e7..91c7128 100644 --- a/src/project.c +++ b/src/project.c @@ -10,12 +10,18 @@ CGLM_EXPORT void -glmc_unprojecti(mat4 invMat, vec4 vp, vec3 coord, vec3 dest) { - glm_unprojecti(invMat, vp, coord, dest); +glmc_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { + glm_unprojecti(pos, invMat, vp, dest); } CGLM_EXPORT void -glmc_unproject(mat4 m, vec4 vp, vec3 coord, vec3 dest) { - glm_unproject(m, vp, coord, dest); +glmc_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) { + glm_unproject(pos, m, vp, dest); +} + +CGLM_EXPORT +void +glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { + glm_project(pos, m, vp, dest); } diff --git a/test/src/test_main.c b/test/src/test_main.c index 5d59cfd..61fa7d5 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -15,6 +15,9 @@ main(int argc, const char * argv[]) { /* camera */ cmocka_unit_test(test_camera_lookat), cmocka_unit_test(test_camera_decomp) + + /* project */ + cmocka_unit_test(test_project) }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/test/src/test_project.c b/test/src/test_project.c new file mode 100644 index 0000000..4cdac9e --- /dev/null +++ b/test/src/test_project.c @@ -0,0 +1,31 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +void +test_project(void **state) { + mat4 model, view, proj, mvp; + vec4 viewport = {0.0f, 0.0f, 800.0f, 600.0f}; + vec3 pos = {13.0f, 45.0f, 0.74f}; + vec3 projected, unprojected; + + glm_translate_make(model, (vec3){0.0f, 0.0f, -10.0f}); + glm_lookat((vec3){0.0f, 0.0f, 0.0f}, pos, GLM_YUP, view); + + glm_perspective_default(0.5f, proj); + glm_mat4_mulN((mat4 *[]){&proj, &view, &model}, 3, mvp); + + glmc_project(pos, mvp, viewport, projected); + glmc_unproject(projected, mvp, viewport, unprojected); + + /* unprojected of projected vector must be same as original one */ + /* we used 0.01 because of projection floating point errors */ + assert_true(fabsf(pos[0] - unprojected[0]) < 0.01); + assert_true(fabsf(pos[1] - unprojected[1]) < 0.01); + assert_true(fabsf(pos[2] - unprojected[2]) < 0.01); +} diff --git a/test/src/test_tests.h b/test/src/test_tests.h index a4e5adb..26eb91d 100644 --- a/test/src/test_tests.h +++ b/test/src/test_tests.h @@ -16,4 +16,7 @@ test_camera_lookat(void **state); void test_camera_decomp(void **state); +void +test_project(void **state); + #endif /* test_tests_h */ From be81d738950979ec5856f2cc4ca43966660a8b3e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 3 Apr 2018 12:32:21 +0300 Subject: [PATCH 052/292] Update test_main.c --- test/src/test_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/test_main.c b/test/src/test_main.c index dad20f9..f1dfc9b 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -17,7 +17,7 @@ main(int argc, const char * argv[]) { cmocka_unit_test(test_camera_decomp) /* project */ - cmocka_unit_test(test_project) + cmocka_unit_test(test_project), /* vector */ cmocka_unit_test(test_clamp), From e8615ea14c1fa11e3dafcd07fb9fa071401289bd Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 3 Apr 2018 12:35:30 +0300 Subject: [PATCH 053/292] fix tests list --- test/src/test_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/test_main.c b/test/src/test_main.c index f1dfc9b..5c1a647 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -14,7 +14,7 @@ main(int argc, const char * argv[]) { /* camera */ cmocka_unit_test(test_camera_lookat), - cmocka_unit_test(test_camera_decomp) + cmocka_unit_test(test_camera_decomp), /* project */ cmocka_unit_test(test_project), From 024412f00ec05e1c931f604ce5261d2b30c32108 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 3 Apr 2018 16:41:13 +0300 Subject: [PATCH 054/292] add docs for project/unproject --- docs/source/api.rst | 1 + docs/source/project.rst | 102 ++++++++++++++++++++++++++++++++++++++++ include/cglm/project.h | 4 +- 3 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 docs/source/project.rst diff --git a/docs/source/api.rst b/docs/source/api.rst index e2c03d4..c61365b 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -41,6 +41,7 @@ Follow the :doc:`build` documentation for this vec4-ext color plane + project util io call diff --git a/docs/source/project.rst b/docs/source/project.rst new file mode 100644 index 0000000..b31a86a --- /dev/null +++ b/docs/source/project.rst @@ -0,0 +1,102 @@ +.. default-domain:: C + +Project / UnProject +================================================================================ + +Header: cglm/project.h + +Viewport is required as *vec4* **[X, Y, Width, Height]** but this doesn't mean +that you should store it as **vec4**. You can convert your data representation +to vec4 before passing it to related functions. + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_unprojecti` +#. :c:func:`glm_unproject` +#. :c:func:`glm_project` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) + + | maps the specified viewport coordinates into specified space [1] + the matrix should contain projection matrix. + + if you don't have ( and don't want to have ) an inverse matrix then use + glm_unproject version. You may use existing inverse of matrix in somewhere + else, this is why glm_unprojecti exists to save save inversion cost + + [1] space: + - if m = invProj: View Space + - if m = invViewProj: World Space + - if m = invMVP: Object Space + + You probably want to map the coordinates into object space + so use invMVP as m + + Computing viewProj: + + .. code-block:: c + + glm_mat4_mul(proj, view, viewProj); + glm_mat4_mul(viewProj, model, MVP); + glm_mat4_inv(viewProj, invMVP); + + Parameters: + | *[in]* **pos** point/position in viewport coordinates + | *[in]* **invMat** matrix (see brief) + | *[in]* **vp** viewport as [x, y, width, height] + | *[out]* **dest** unprojected coordinates + +.. c:function:: void glm_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) + + | maps the specified viewport coordinates into specified space [1] + the matrix should contain projection matrix. + + this is same as glm_unprojecti except this function get inverse matrix for + you. + + [1] space: + - if m = proj: View Space + - if m = viewProj: World Space + - if m = MVP: Object Space + + You probably want to map the coordinates into object space so use MVP as m + + Computing viewProj and MVP: + + .. code-block:: c + + glm_mat4_mul(proj, view, viewProj); + glm_mat4_mul(viewProj, model, MVP); + + Parameters: + | *[in]* **pos** point/position in viewport coordinates + | *[in]* **m** matrix (see brief) + | *[in]* **vp** viewport as [x, y, width, height] + | *[out]* **dest** unprojected coordinates + +.. c:function:: void glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) + + | map object coordinates to window coordinates + + Computing MVP: + + .. code-block:: c + + glm_mat4_mul(proj, view, viewProj); + glm_mat4_mul(viewProj, model, MVP); + + 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]* **pos** object coordinates + | *[in]* **m** MVP matrix + | *[in]* **vp** viewport as [x, y, width, height] + | *[out]* **dest** projected coordinates diff --git a/include/cglm/project.h b/include/cglm/project.h index a0b306b..fea44b0 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -33,7 +33,7 @@ * glm_mat4_mul(viewProj, model, MVP); * glm_mat4_inv(viewProj, invMVP); * - * @param[in] pos viewport coordinates + * @param[in] pos point/position in viewport coordinates * @param[in] invMat matrix (see brief) * @param[in] vp viewport as [x, y, width, height] * @param[out] dest unprojected coordinates @@ -72,7 +72,7 @@ glm_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { * glm_mat4_mul(proj, view, viewProj); * glm_mat4_mul(viewProj, model, MVP); * - * @param[in] pos viewport coordinates + * @param[in] pos point/position in viewport coordinates * @param[in] m matrix (see brief) * @param[in] vp viewport as [x, y, width, height] * @param[out] dest unprojected coordinates From 429fdfd5c53442c37e9264465fb071c3d728890e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 3 Apr 2018 16:47:51 +0300 Subject: [PATCH 055/292] update build scripts --- makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/makefile.am b/makefile.am index a81bdd5..217fff3 100644 --- a/makefile.am +++ b/makefile.am @@ -98,13 +98,15 @@ libcglm_la_SOURCES=\ src/mat4.c \ src/plane.c \ src/frustum.c \ - src/box.c + src/box.c \ + src/project.c test_tests_SOURCES=\ test/src/test_common.c \ test/src/test_main.c \ test/src/test_mat4.c \ test/src/test_cam.c \ + test/src/test_project.c \ test/src/test_clamp.c \ test/src/test_euler.c From ea0a10ade9a76830c71ea3a2b528dcce7849f34a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 3 Apr 2018 16:47:59 +0300 Subject: [PATCH 056/292] suppress warnings --- include/cglm/util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/util.h b/include/cglm/util.h index 2a9ece7..85fc789 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -43,7 +43,7 @@ glm_sign(int val) { CGLM_INLINE float glm_signf(float val) { - return (val > 0.0f) - (val < 0.0f); + return (float)((val > 0.0f) - (val < 0.0f)); } /*! From 7411ac36c182495a597aff9cd0dcc604114ade8c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 3 Apr 2018 17:05:45 +0300 Subject: [PATCH 057/292] update docs for euler angles --- docs/source/euler.rst | 25 ++++++++++++++++++------- include/cglm/euler.h | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/docs/source/euler.rst b/docs/source/euler.rst index 260aec7..74ba4c2 100644 --- a/docs/source/euler.rst +++ b/docs/source/euler.rst @@ -70,6 +70,7 @@ Functions: 1. :c:func:`glm_euler_order` #. :c:func:`glm_euler_angles` #. :c:func:`glm_euler` +#. :c:func:`glm_euler_xyz` #. :c:func:`glm_euler_zyx` #. :c:func:`glm_euler_zxy` #. :c:func:`glm_euler_xzy` @@ -115,8 +116,18 @@ Functions documentation | build rotation matrix from euler angles + this is alias of glm_euler_xyz function + Parameters: - | *[in]* **angles** angles as vector [Ex, Ey, Ez] + | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle] + | *[in]* **dest** rotation matrix + +.. c:function:: void glm_euler_xyz(vec3 angles, mat4 dest) + + | build rotation matrix from euler angles + + Parameters: + | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle] | *[in]* **dest** rotation matrix .. c:function:: void glm_euler_zyx(vec3 angles, mat4 dest) @@ -124,7 +135,7 @@ Functions documentation | build rotation matrix from euler angles Parameters: - | *[in]* **angles** angles as vector [Ez, Ey, Ex] + | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle] | *[in]* **dest** rotation matrix .. c:function:: void glm_euler_zxy(vec3 angles, mat4 dest) @@ -132,7 +143,7 @@ Functions documentation | build rotation matrix from euler angles Parameters: - | *[in]* **angles** angles as vector [Ez, Ex, Ey] + | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle] | *[in]* **dest** rotation matrix .. c:function:: void glm_euler_xzy(vec3 angles, mat4 dest) @@ -140,7 +151,7 @@ Functions documentation | build rotation matrix from euler angles Parameters: - | *[in]* **angles** angles as vector [Ex, Ez, Ey] + | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle] | *[in]* **dest** rotation matrix .. c:function:: void glm_euler_yzx(vec3 angles, mat4 dest) @@ -148,7 +159,7 @@ Functions documentation build rotation matrix from euler angles Parameters: - | *[in]* **angles** angles as vector [Ey, Ez, Ex] + | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle] | *[in]* **dest** rotation matrix .. c:function:: void glm_euler_yxz(vec3 angles, mat4 dest) @@ -156,7 +167,7 @@ Functions documentation | build rotation matrix from euler angles Parameters: - | *[in]* **angles** angles as vector [Ey, Ex, Ez] + | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle] | *[in]* **dest** rotation matrix .. c:function:: void glm_euler_by_order(vec3 angles, glm_euler_sq ord, mat4 dest) @@ -166,6 +177,6 @@ Functions documentation Use :c:func:`glm_euler_order` function to build *ord* parameter Parameters: - | *[in]* **angles** angles as vector (ord parameter spceifies angles order) + | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle] | *[in]* **ord** euler order | *[in]* **dest** rotation matrix diff --git a/include/cglm/euler.h b/include/cglm/euler.h index 5db7e66..bb455a8 100644 --- a/include/cglm/euler.h +++ b/include/cglm/euler.h @@ -21,6 +21,7 @@ CGLM_INLINE glm_euler_sq glm_euler_order(int newOrder[3]); CGLM_INLINE void glm_euler_angles(mat4 m, vec3 dest); CGLM_INLINE void glm_euler(vec3 angles, mat4 dest); + CGLM_INLINE void glm_euler_xyz(vec3 angles, mat4 dest); CGLM_INLINE void glm_euler_zyx(vec3 angles, mat4 dest); CGLM_INLINE void glm_euler_zxy(vec3 angles, mat4 dest); CGLM_INLINE void glm_euler_xzy(vec3 angles, mat4 dest); From 967fb1afad7edea14a7b29eeeb22c80ec7497f93 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 3 Apr 2018 17:32:10 +0300 Subject: [PATCH 058/292] Update README.md --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 4e7c4ef..dc9f736 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ Currently *cglm* uses default clip space configuration (-1, 1) for camera functi - inline or pre-compiled function call - frustum (extract view frustum planes, corners...) - bounding box (AABB in Frustum (culling), crop, merge...) +- project, unproject
@@ -227,6 +228,27 @@ glm_mat4_mul(m1, m1, m1); ``` the first two parameter are **[in]** and the last one is **[out]** parameter. After multiplied *m1* and *m2* the result is stored in *m1*. This is why we send *m1* twice. You may store result in different matrix, this just an example. +### Example: Computing MVP matrix + +#### Option 1 +```C +mat4 proj, view, model, mvp; + +/* init proj, view and model ... */ + +glm_mat4_mul(proj, view, viewProj); +glm_mat4_mul(viewProj, model, mvp); +``` + +#### Option 2 +```C +mat4 proj, view, model, mvp; + +/* init proj, view and model ... */ + +glm_mat4_mulN((mat4 *[]){&proj, &view, &model}, 3, mvp); +``` + ## How to send matrix to OpenGL mat4 is array of vec4 and vec4 is array of floats. `glUniformMatrix4fv` functions accecpts `float*` as `value` (last param), so you can cast mat4 to float* or you can pass first column of matrix as beginning of memory of matrix: From cfd360010717a8040ee586d59f61ed1b76fe0174 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 4 Apr 2018 22:42:21 +0300 Subject: [PATCH 059/292] simd: optional shuffle configuration to save move instructions --- include/cglm/simd/intrin.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index c0f2e53..2507291 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -20,15 +20,21 @@ # include # include -/* float */ -# define _mm_shuffle1_ps(a, z, y, x, w) \ - _mm_shuffle_ps(a, a, _MM_SHUFFLE(z, y, x, w)) +/* OPTIONAL: You may save some instructions but latency (not sure) */ +#ifdef CGLM_USE_INT_DOM_FOR_SHUFF +# define _mm_shuffle1_ps(xmm, z, y, x, w) \ + _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(xmm), \ + _MM_SHUFFLE(z, y, x, w))) +#else +# define _mm_shuffle1_ps(xmm, z, y, x, w) \ + _mm_shuffle_ps(xmm, xmm, _MM_SHUFFLE(z, y, x, w)) +#endif -# define _mm_shuffle1_ps1(a, x) \ - _mm_shuffle_ps(a, a, _MM_SHUFFLE(x, x, x, x)) +# define _mm_shuffle1_ps1(xmm, x) \ + _mm_shuffle1_ps(xmm, x, x, x, x) -# define _mm_shuffle2_ps(a, b, z0, y0, x0, w0, z1, y1, x1, w1) \ - _mm_shuffle1_ps(_mm_shuffle_ps(a, b, _MM_SHUFFLE(z0, y0, x0, w0)), \ +# define _mm_shuffle2_ps(a, b, z0, y0, x0, w0, z1, y1, x1, w1) \ + _mm_shuffle1_ps(_mm_shuffle_ps(a, b, _MM_SHUFFLE(z0, y0, x0, w0)), \ z1, y1, x1, w1) #endif From 58f004341706867d1c7af1ed1cbd8aea1cd7ac1f Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 6 Apr 2018 22:57:24 +0300 Subject: [PATCH 060/292] vector utils: isnan and isinf * a vector which has least one NaN or INF member, is assumed not valid vector. --- include/cglm/vec3-ext.h | 36 ++++++++++++++++++++++++++++++++++++ include/cglm/vec4-ext.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index 99e778a..7890c33 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -160,4 +160,40 @@ glm_vec_min(vec3 v) { return min; } +/*! + * @brief check if all items are NaN (not a number) + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec_isnan(vec3 v) { + return !(isnan(v[0]) || isnan(v[1]) || isnan(v[2])); +} + +/*! + * @brief check if all items are INFINITY + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec_isinf(vec3 v) { + return !(isinf(v[0]) || isinf(v[1]) || isinf(v[2])); +} + +/*! + * @brief check if all items are valid number + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec_isvalid(vec3 v) { + return !glm_vec_isnan(v) && !glm_vec_isinf(v); +} + #endif /* cglm_vec3_ext_h */ diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index ca697af..c290477 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -174,5 +174,41 @@ glm_vec4_min(vec4 v) { return min; } +/*! + * @brief check if all items are NaN (not a number) + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec4_isnan(vec4 v) { + return !(isnan(v[0]) || isnan(v[1]) || isnan(v[2]) || isnan(v[3])); +} + +/*! + * @brief check if all items are INFINITY + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec4_isinf(vec4 v) { + return !(isinf(v[0]) || isinf(v[1]) || isinf(v[2]) || isinf(v[3])); +} + +/*! + * @brief check if all items are valid number + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec4_isvalid(vec4 v) { + return !glm_vec4_isnan(v) && !glm_vec4_isinf(v); +} + #endif /* cglm_vec4_ext_h */ From 11430559b45b773e8b3a7868bc88a053010740e8 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 7 Apr 2018 08:28:37 +0300 Subject: [PATCH 061/292] fix isnan and isinf --- include/cglm/vec3-ext.h | 4 ++-- include/cglm/vec4-ext.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index 7890c33..8a9226f 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -169,7 +169,7 @@ glm_vec_min(vec3 v) { CGLM_INLINE bool glm_vec_isnan(vec3 v) { - return !(isnan(v[0]) || isnan(v[1]) || isnan(v[2])); + return isnan(v[0]) || isnan(v[1]) || isnan(v[2]); } /*! @@ -181,7 +181,7 @@ glm_vec_isnan(vec3 v) { CGLM_INLINE bool glm_vec_isinf(vec3 v) { - return !(isinf(v[0]) || isinf(v[1]) || isinf(v[2])); + return isinf(v[0]) || isinf(v[1]) || isinf(v[2]); } /*! diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index c290477..2859588 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -183,7 +183,7 @@ glm_vec4_min(vec4 v) { CGLM_INLINE bool glm_vec4_isnan(vec4 v) { - return !(isnan(v[0]) || isnan(v[1]) || isnan(v[2]) || isnan(v[3])); + return isnan(v[0]) || isnan(v[1]) || isnan(v[2]) || isnan(v[3]); } /*! @@ -195,7 +195,7 @@ glm_vec4_isnan(vec4 v) { CGLM_INLINE bool glm_vec4_isinf(vec4 v) { - return !(isinf(v[0]) || isinf(v[1]) || isinf(v[2]) || isinf(v[3])); + return isinf(v[0]) || isinf(v[1]) || isinf(v[2]) || isinf(v[3]); } /*! From ae06c51746e3a00f89205a5a57ee286befc9eb4e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 7 Apr 2018 13:22:44 +0300 Subject: [PATCH 062/292] improve glm_mat4_mulN for non-DEBUG environment --- include/cglm/call/mat4.h | 2 +- include/cglm/mat4.h | 18 +++++++++--------- src/mat4.c | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/cglm/call/mat4.h b/include/cglm/call/mat4.h index 6ea81e4..5c8ff38 100644 --- a/include/cglm/call/mat4.h +++ b/include/cglm/call/mat4.h @@ -47,7 +47,7 @@ glmc_mat4_mul(mat4 m1, mat4 m2, mat4 dest); CGLM_EXPORT void -glmc_mat4_mulN(mat4 * __restrict matrices[], int len, mat4 dest); +glmc_mat4_mulN(mat4 * __restrict matrices[], uint32_t len, mat4 dest); CGLM_EXPORT void diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 45f54b4..02fde18 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -58,7 +58,9 @@ # include "simd/neon/mat4.h" #endif -#include +#ifdef DEBUG +# include +#endif #define GLM_MAT4_IDENTITY_INIT {{1.0f, 0.0f, 0.0f, 0.0f}, \ {0.0f, 1.0f, 0.0f, 0.0f}, \ @@ -281,19 +283,17 @@ glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest) { */ CGLM_INLINE void -glm_mat4_mulN(mat4 * __restrict matrices[], int len, mat4 dest) { - int i; +glm_mat4_mulN(mat4 * __restrict matrices[], uint32_t len, mat4 dest) { + uint32_t i; +#ifdef DEBUG assert(len > 1 && "there must be least 2 matrices to go!"); +#endif - glm_mat4_mul(*matrices[0], - *matrices[1], - dest); + glm_mat4_mul(*matrices[0], *matrices[1], dest); for (i = 2; i < len; i++) - glm_mat4_mul(dest, - *matrices[i], - dest); + glm_mat4_mul(dest, *matrices[i], dest); } /*! diff --git a/src/mat4.c b/src/mat4.c index 838b52d..0b1ccee 100644 --- a/src/mat4.c +++ b/src/mat4.c @@ -52,7 +52,7 @@ glmc_mat4_mul(mat4 m1, mat4 m2, mat4 dest) { CGLM_EXPORT void -glmc_mat4_mulN(mat4 * __restrict matrices[], int len, mat4 dest) { +glmc_mat4_mulN(mat4 * __restrict matrices[], uint32_t len, mat4 dest) { glm_mat4_mulN(matrices, len, dest); } From 9b8748acc459fb6d8252e0454c088aa3174c2017 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 7 Apr 2018 13:27:40 +0300 Subject: [PATCH 063/292] quat: quaternion to mat3 --- include/cglm/call/quat.h | 4 ++++ include/cglm/quat.h | 36 ++++++++++++++++++++++++++++++++++++ src/quat.c | 6 ++++++ 3 files changed, 46 insertions(+) diff --git a/include/cglm/call/quat.h b/include/cglm/call/quat.h index 0dff506..e40bcdf 100644 --- a/include/cglm/call/quat.h +++ b/include/cglm/call/quat.h @@ -51,6 +51,10 @@ CGLM_EXPORT void glmc_quat_mat4(versor q, mat4 dest); +CGLM_EXPORT +void +glmc_quat_mat3(versor q, mat3 dest); + CGLM_EXPORT void glmc_quat_slerp(versor q, diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 63236b1..1a2cfe3 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -216,6 +216,42 @@ glm_quat_mat4(versor q, mat4 dest) { dest[3][3] = 1.0f; } +/*! + * @brief convert quaternion to mat3 + * + * @param[in] q quaternion + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_quat_mat3(versor q, mat3 dest) { + float w, x, y, z; + float xx, yy, zz; + float xy, yz, xz; + float wx, wy, wz; + + w = q[0]; + x = q[1]; + y = q[2]; + z = q[3]; + + xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x; + yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y; + zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z; + + dest[0][0] = 1.0f - yy - zz; + dest[1][1] = 1.0f - xx - zz; + dest[2][2] = 1.0f - xx - yy; + + dest[0][1] = xy + wz; + dest[1][2] = yz + wx; + dest[2][0] = xz + wy; + + dest[1][0] = xy - wz; + dest[2][1] = yz - wx; + dest[0][2] = xz - wy; +} + /*! * @brief interpolates between two quaternions * using spherical linear interpolation (SLERP) diff --git a/src/quat.c b/src/quat.c index b26d112..9955ce1 100644 --- a/src/quat.c +++ b/src/quat.c @@ -62,6 +62,12 @@ glmc_quat_mat4(versor q, mat4 dest) { glm_quat_mat4(q, dest); } +CGLM_EXPORT +void +glmc_quat_mat3(versor q, mat3 dest) { + glm_quat_mat3(q, dest); +} + CGLM_EXPORT void glmc_quat_slerp(versor q, From 619ecdc5a4652598fa9034a39eb770b23a425c1a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 7 Apr 2018 13:46:46 +0300 Subject: [PATCH 064/292] quat: improve normalize --- include/cglm/quat.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 1a2cfe3..a9a3649 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -133,11 +133,12 @@ void glm_quat_normalize(versor q) { float sum; - sum = q[0] * q[0] + q[1] * q[1] - + q[2] * q[2] + q[3] * q[3]; + sum = glm_vec4_norm2(q); - if (fabs(1.0f - sum) < 0.0001f) + if (sum <= 0.0f) { + glm_quat_identity(q); return; + } glm_vec4_scale(q, 1.0f / sqrtf(sum), q); } From f5140ea00504bc388f61965bc9f9676047cbae20 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 7 Apr 2018 13:47:20 +0300 Subject: [PATCH 065/292] quat: mat4_mul_quat helper * the quaternion is used as right matrix --- include/cglm/mat4.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 02fde18..eddfe6b 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -45,6 +45,7 @@ #define cglm_mat_h #include "common.h" +#include "quat.h" #ifdef CGLM_SSE_FP # include "simd/sse2/mat4.h" @@ -318,6 +319,21 @@ glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) { #endif } +/*! + * @brief multiply mat4 with quaternion and store in dest vector + * + * @param[in] m left matrix + * @param[in] q quaternion as right matrix + * @param[out] dest destination matrix + */ +CGLM_INLINE +void +glm_mat4_mulq(mat4 m, versor q, mat4 dest) { + mat4 rot; + glm_quat_mat4(q, rot); + glm_mat4_mul(m, rot, dest); +} + /*! * @brief multiply vector with mat4's mat3 part(rotation) * From 257c57d41ff56905b25b0fcc5449f1319843cb85 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 7 Apr 2018 19:46:46 +0300 Subject: [PATCH 066/292] mat4 to quaternion --- .gitignore | 3 ++- include/cglm/call/mat4.h | 8 ++++++++ include/cglm/mat4.h | 30 ++++++++++++++++++++++++++++++ makefile.am | 4 ++-- src/mat4.c | 12 ++++++++++++ test/src/test_common.c | 38 +++++++++++++++++++++++++++++++++++++- test/src/test_common.h | 12 ++++++++++++ test/src/test_main.c | 5 ++++- test/src/test_quat.c | 22 ++++++++++++++++++++++ test/src/test_tests.h | 3 +++ 10 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 test/src/test_quat.c diff --git a/.gitignore b/.gitignore index 180c5d9..37f68c8 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,5 @@ cglm_test_ios/* cglm_test_iosTests/* docs/build/* win/cglm_test_* -* copy.* +* copy.* +*.o diff --git a/include/cglm/call/mat4.h b/include/cglm/call/mat4.h index 5c8ff38..35b9f66 100644 --- a/include/cglm/call/mat4.h +++ b/include/cglm/call/mat4.h @@ -53,6 +53,14 @@ CGLM_EXPORT void glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest); +CGLM_EXPORT +void +glmc_mat4_mulq(mat4 m, versor q, mat4 dest); + +CGLM_EXPORT +void +glmc_mat4_quat(mat4 m, versor dest); + CGLM_EXPORT void glmc_mat4_transpose_to(mat4 m, mat4 dest); diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index eddfe6b..ec7ac39 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -334,6 +334,36 @@ glm_mat4_mulq(mat4 m, versor q, mat4 dest) { glm_mat4_mul(m, rot, dest); } +/*! + * @brief convert mat4's rotation part to quaternion + * + * @param[in] m left matrix + * @param[out] dest destination quaternion + */ +CGLM_INLINE +void +glm_mat4_quat(mat4 m, versor dest) { + versor q; + float m00, m10, m20, + m01, m11, m21, + m02, m12, m22; + + m00 = m[0][0]; m10 = m[1][0]; m20 = m[2][0]; + m01 = m[0][1]; m11 = m[1][1]; m21 = m[2][1]; + m02 = m[0][2]; m12 = m[1][2]; m22 = m[2][2]; + + q[0] = sqrtf(glm_max(0.0f, 1.0f + m00 + m11 + m22)) * 0.5f; /* w */ + q[1] = sqrtf(glm_max(0.0f, 1.0f + m00 - m11 - m22)) * 0.5f; /* x */ + q[2] = sqrtf(glm_max(0.0f, 1.0f - m00 + m11 - m22)) * 0.5f; /* y */ + q[3] = sqrtf(glm_max(0.0f, 1.0f - m00 - m11 + m22)) * 0.5f; /* z */ + + q[1] *= glm_signf(m12 - m21); + q[2] *= glm_signf(m20 - m02); + q[3] *= glm_signf(m01 - m10); + + glm_vec4_copy(q, dest); +} + /*! * @brief multiply vector with mat4's mat3 part(rotation) * diff --git a/makefile.am b/makefile.am index 217fff3..436973c 100644 --- a/makefile.am +++ b/makefile.am @@ -108,7 +108,7 @@ test_tests_SOURCES=\ test/src/test_cam.c \ test/src/test_project.c \ test/src/test_clamp.c \ - test/src/test_euler.c - + test/src/test_euler.c \ + test/src/test_quat.c all-local: sh ./post-build.sh diff --git a/src/mat4.c b/src/mat4.c index 0b1ccee..8b2a2d0 100644 --- a/src/mat4.c +++ b/src/mat4.c @@ -62,6 +62,18 @@ glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest) { glm_mat4_mulv(m, v, dest); } +CGLM_EXPORT +void +glmc_mat4_mulq(mat4 m, versor q, mat4 dest) { + glm_mat4_mulq(m, q, dest); +} + +CGLM_EXPORT +void +glmc_mat4_quat(mat4 m, versor dest) { + glm_mat4_quat(m, dest); +} + CGLM_EXPORT void glmc_mat4_transpose_to(mat4 m, mat4 dest) { diff --git a/test/src/test_common.c b/test/src/test_common.c index 23f2b50..c38c474 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -27,6 +27,33 @@ test_rand_mat4(mat4 dest) { /* glm_scale(dest, (vec3){drand48(), drand48(), drand48()}); */ } +void +test_rand_vec3(vec3 dest) { + srand((unsigned int)time(NULL)); + + dest[0] = drand48(); + dest[1] = drand48(); + dest[2] = drand48(); +} + +float +test_rand_angle(void) { + srand((unsigned int)time(NULL)); + return drand48(); +} + +void +test_rand_quat(versor q) { + srand((unsigned int)time(NULL)); + + q[0] = drand48(); + q[1] = drand48(); + q[2] = drand48(); + q[3] = drand48(); + + glm_quat_normalize(q); +} + void test_assert_mat4_eq(mat4 m1, mat4 m2) { int i, j, k; @@ -53,7 +80,16 @@ test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps) { void test_assert_vec3_eq(vec3 v1, vec3 v2) { - assert_true(fabsf(v1[0] - v2[0]) <= 0.0000009); + assert_true(fabsf(v1[0] - v2[0]) <= 0.0000009); /* rounding errors */ assert_true(fabsf(v1[1] - v2[1]) <= 0.0000009); assert_true(fabsf(v1[2] - v2[2]) <= 0.0000009); } + +void +test_assert_quat_eq(versor v1, versor v2) { + assert_true(fabsf(v1[0] - v2[0]) <= 0.0009); /* rounding errors */ + assert_true(fabsf(v1[1] - v2[1]) <= 0.0009); + assert_true(fabsf(v1[2] - v2[2]) <= 0.0009); + assert_true(fabsf(v1[3] - v2[3]) <= 0.0009); +} + diff --git a/test/src/test_common.h b/test/src/test_common.h index aeea4d6..f692483 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -34,4 +34,16 @@ test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps); void test_assert_vec3_eq(vec3 v1, vec3 v2); +void +test_assert_quat_eq(versor v1, versor v2); + +void +test_rand_vec3(vec3 dest); + +float +test_rand_angle(void); + +void +test_rand_quat(versor q); + #endif /* test_common_h */ diff --git a/test/src/test_main.c b/test/src/test_main.c index 5c1a647..384250f 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -23,7 +23,10 @@ main(int argc, const char * argv[]) { cmocka_unit_test(test_clamp), /* euler */ - cmocka_unit_test(test_euler) + cmocka_unit_test(test_euler), + + /* quaternion */ + cmocka_unit_test(test_quat) }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/test/src/test_quat.c b/test/src/test_quat.c new file mode 100644 index 0000000..1a328de --- /dev/null +++ b/test/src/test_quat.c @@ -0,0 +1,22 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +void +test_quat(void **state) { + mat4 rot; + versor inQuat, outQuat; + int i; + + for (i = 0; i < 10000; i++) { + test_rand_quat(inQuat); + glmc_quat_mat4(inQuat, rot); + glm_mat4_quat(rot, outQuat); + test_assert_quat_eq(inQuat, outQuat); + } +} diff --git a/test/src/test_tests.h b/test/src/test_tests.h index 7234782..398caa3 100644 --- a/test/src/test_tests.h +++ b/test/src/test_tests.h @@ -25,4 +25,7 @@ test_clamp(void **state); void test_euler(void **state); +void +test_quat(void **state); + #endif /* test_tests_h */ From 12c53074473f50a2a7fc4eea660a661d911fda6c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 7 Apr 2018 21:53:22 +0300 Subject: [PATCH 067/292] vec3 and vec4 sign helper --- include/cglm/vec3-ext.h | 16 ++++++++++++++++ include/cglm/vec4-ext.h | 30 +++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index 8a9226f..e119900 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -26,6 +26,7 @@ #define cglm_vec3_ext_h #include "common.h" +#include "util.h" #include #include #include @@ -196,4 +197,19 @@ glm_vec_isvalid(vec3 v) { return !glm_vec_isnan(v) && !glm_vec_isinf(v); } +/*! + * @brief get sign of 32 bit float as +1, -1, 0 + * + * Important: It returns 0 for zero/NaN input + * + * @param v vector + */ +CGLM_INLINE +void +glm_vec_sign(vec3 v, vec3 dest) { + dest[0] = glm_signf(v[0]); + dest[1] = glm_signf(v[1]); + dest[2] = glm_signf(v[2]); +} + #endif /* cglm_vec3_ext_h */ diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index 2859588..f6cbe04 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -210,5 +210,33 @@ glm_vec4_isvalid(vec4 v) { return !glm_vec4_isnan(v) && !glm_vec4_isinf(v); } -#endif /* cglm_vec4_ext_h */ +/*! + * @brief get sign of 32 bit float as +1, -1, 0 + * + * Important: It returns 0 for zero/NaN input + * + * @param v vector + */ +CGLM_INLINE +void +glm_vec4_sign(vec4 v, vec4 dest) { +#if defined( __SSE2__ ) || defined( __SSE2__ ) + __m128 x0, x1, x2, x3, x4; + x0 = _mm_load_ps(v); + x1 = _mm_set_ps(0.0f, 0.0f, 1.0f, -1.0f); + x2 = _mm_shuffle1_ps1(x1, 2); + + x3 = _mm_and_ps(_mm_cmpgt_ps(x0, x2), _mm_shuffle1_ps1(x1, 1)); + x4 = _mm_and_ps(_mm_cmplt_ps(x0, x2), _mm_shuffle1_ps1(x1, 0)); + + _mm_store_ps(dest, _mm_or_ps(x3, x4)); +#else + dest[0] = glm_signf(v[0]); + dest[1] = glm_signf(v[1]); + dest[2] = glm_signf(v[2]); + dest[3] = glm_signf(v[3]); +#endif +} + +#endif /* cglm_vec4_ext_h */ From b27603c26839ba0e40ce657c38e6007a7087653f Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 8 Apr 2018 00:09:40 +0300 Subject: [PATCH 068/292] normalize quaternion before converting to matrix * because it must be unit quaternion and didn't specified this in docs. * we must provide alternative func for unit quat --- include/cglm/quat.h | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index a9a3649..e9e986e 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -182,15 +182,17 @@ glm_quat_mulv(versor q1, versor q2, versor dest) { CGLM_INLINE void glm_quat_mat4(versor q, mat4 dest) { - float w, x, y, z; - float xx, yy, zz; - float xy, yz, xz; - float wx, wy, wz; + float w, x, y, z, + xx, yy, zz, + xy, yz, xz, + wx, wy, wz, norm; - w = q[0]; - x = q[1]; - y = q[2]; - z = q[3]; + norm = 1.0f / glm_quat_norm(q); + + w = q[0] * norm; + x = q[1] * norm; + y = q[2] * norm; + z = q[3] * norm; xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x; yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y; @@ -226,15 +228,17 @@ glm_quat_mat4(versor q, mat4 dest) { CGLM_INLINE void glm_quat_mat3(versor q, mat3 dest) { - float w, x, y, z; - float xx, yy, zz; - float xy, yz, xz; - float wx, wy, wz; + float w, x, y, z, + xx, yy, zz, + xy, yz, xz, + wx, wy, wz, norm; - w = q[0]; - x = q[1]; - y = q[2]; - z = q[3]; + norm = 1.0f / glm_quat_norm(q); + + w = q[0] * norm; + x = q[1] * norm; + y = q[2] * norm; + z = q[3] * norm; xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x; yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y; From 81bda7439dd89eef31cf0d65e4ac90c70562e9a5 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 8 Apr 2018 12:30:15 +0300 Subject: [PATCH 069/292] vector square root --- include/cglm/vec3-ext.h | 14 ++++++++++++++ include/cglm/vec4-ext.h | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index e119900..afc853e 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -212,4 +212,18 @@ glm_vec_sign(vec3 v, vec3 dest) { dest[2] = glm_signf(v[2]); } +/*! + * @brief square root of each vector item + * + * @param[in] v vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec_sqrt(vec4 v, vec4 dest) { + dest[0] = sqrtf(v[0]); + dest[1] = sqrtf(v[1]); + dest[2] = sqrtf(v[2]); +} + #endif /* cglm_vec3_ext_h */ diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index f6cbe04..77ba1fa 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -239,4 +239,23 @@ glm_vec4_sign(vec4 v, vec4 dest) { #endif } +/*! + * @brief square root of each vector item + * + * @param[in] v vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_sqrt(vec4 v, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_sqrt_ps(_mm_load_ps(v))); +#else + dest[0] = sqrtf(v[0]); + dest[1] = sqrtf(v[1]); + dest[2] = sqrtf(v[2]); + dest[3] = sqrtf(v[3]); +#endif +} + #endif /* cglm_vec4_ext_h */ From 932f638d5a6b3bcb0897b059b74ddace2a204308 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 8 Apr 2018 12:31:32 +0300 Subject: [PATCH 070/292] optimize mat4 to quaternion * add SSE2 version and optimize scalar version --- include/cglm/mat4.h | 34 +++++++++++++++-------- include/cglm/simd/sse2/mat4.h | 51 +++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index ec7ac39..782a24b 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -343,25 +343,38 @@ glm_mat4_mulq(mat4 m, versor q, mat4 dest) { CGLM_INLINE void glm_mat4_quat(mat4 m, versor dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_quat_sse2(m, dest); +#else + vec4 vsgn, vzero = GLM_VEC4_ZERO_INIT; versor q; float m00, m10, m20, m01, m11, m21, m02, m12, m22; - m00 = m[0][0]; m10 = m[1][0]; m20 = m[2][0]; - m01 = m[0][1]; m11 = m[1][1]; m21 = m[2][1]; - m02 = m[0][2]; m12 = m[1][2]; m22 = m[2][2]; + m00 = m[0][0]; m01 = m[0][1]; m02 = m[0][2]; + m10 = m[1][0]; m11 = m[1][1]; m12 = m[1][2]; + m20 = m[2][0]; m21 = m[2][1]; m22 = m[2][2]; - q[0] = sqrtf(glm_max(0.0f, 1.0f + m00 + m11 + m22)) * 0.5f; /* w */ - q[1] = sqrtf(glm_max(0.0f, 1.0f + m00 - m11 - m22)) * 0.5f; /* x */ - q[2] = sqrtf(glm_max(0.0f, 1.0f - m00 + m11 - m22)) * 0.5f; /* y */ - q[3] = sqrtf(glm_max(0.0f, 1.0f - m00 - m11 + m22)) * 0.5f; /* z */ + q[0] = 1.0f + m00 + m11 + m22; /* w */ + q[1] = 1.0f + m00 - m11 - m22; /* x */ + q[2] = 1.0f - m00 + m11 - m22; /* y */ + q[3] = 1.0f - m00 - m11 + m22; /* z */ - q[1] *= glm_signf(m12 - m21); - q[2] *= glm_signf(m20 - m02); - q[3] *= glm_signf(m01 - m10); + glm_vec4_maxv(q, vzero, q); + glm_vec4_sqrt(q, q); + glm_vec4_scale(q, 0.5f, q); + + vsgn[0] = 1.0f; + vsgn[1] = m12 - m21; + vsgn[2] = m20 - m02; + vsgn[3] = m01 - m10; + + glm_vec4_sign(vsgn, vsgn); + glm_vec4_mulv(q, vsgn, q); glm_vec4_copy(q, dest); +#endif } /*! @@ -614,5 +627,4 @@ glm_mat4_swap_row(mat4 mat, int row1, int row2) { mat[3][row2] = tmp[3]; } -#else #endif /* cglm_mat_h */ diff --git a/include/cglm/simd/sse2/mat4.h b/include/cglm/simd/sse2/mat4.h index 77874a8..0476176 100644 --- a/include/cglm/simd/sse2/mat4.h +++ b/include/cglm/simd/sse2/mat4.h @@ -102,6 +102,57 @@ glm_mat4_mulv_sse2(mat4 m, vec4 v, vec4 dest) { _mm_store_ps(dest, _mm_add_ps(x1, x2)); } +CGLM_INLINE +void +glm_mat4_quat_sse2(mat4 m, versor dest) { + __m128 c0, c1, c2, x0, x1, x2, x3, m00, m11, m22, r; + __m128 zero, one, half, ngone; + + c0 = _mm_load_ps(m[0]); + c1 = _mm_load_ps(m[1]); + c2 = _mm_load_ps(m[2]); + + m00 = _mm_xor_ps(_mm_shuffle1_ps1(c0, 0), _mm_set_ps(-0.f, -0.f, 0.f, 0.f)); + m11 = _mm_xor_ps(_mm_shuffle1_ps1(c1, 1), _mm_set_ps(-0.f, 0.f, -0.f, 0.f)); + m22 = _mm_xor_ps(_mm_shuffle1_ps1(c2, 2), _mm_set_ps( 0.f, -0.f, -0.f, 0.f)); + + x0 = _mm_set_ps(-1.0f, 0.0f, 0.5, 1.0f); + one = _mm_shuffle1_ps1(x0, 0); + half = _mm_shuffle1_ps1(x0, 1); + zero = _mm_shuffle1_ps1(x0, 2); + ngone = _mm_shuffle1_ps1(x0, 3); + + /* + q[0] = sqrtf(glm_max(0.0f, 1.0f + m00 + m11 + m22)) * 0.5f; + q[1] = sqrtf(glm_max(0.0f, 1.0f + m00 - m11 - m22)) * 0.5f; + q[2] = sqrtf(glm_max(0.0f, 1.0f - m00 + m11 - m22)) * 0.5f; + q[3] = sqrtf(glm_max(0.0f, 1.0f - m00 - m11 + m22)) * 0.5f; + */ + x0 = _mm_add_ps(one, _mm_add_ps(_mm_add_ps(m00, m11), m22)); + r = _mm_mul_ps(_mm_sqrt_ps(_mm_max_ps(zero, x0)), half); + + /* + q[1] *= glm_signf(m12 - m21); + q[2] *= glm_signf(m20 - m02); + q[3] *= glm_signf(m01 - m10); + */ + x1 = _mm_shuffle_ps(c1, c2, _MM_SHUFFLE(0, 0, 2, 2)); /* m20 m20 m12 m12 */ + x1 = _mm_shuffle_ps(x1, c0, _MM_SHUFFLE(1, 1, 2, 0)); /* m01 m01 m20 m12 */ + + x2 = _mm_shuffle_ps(c2, c0, _MM_SHUFFLE(2, 2, 1, 1)); /* m02 m02 m21 m21 */ + x2 = _mm_shuffle_ps(x2, c1, _MM_SHUFFLE(0, 0, 2, 0)); /* m10 m10 m02 m21 */ + + x1 = _mm_sub_ps(x1, x2); + x2 = _mm_or_ps(_mm_and_ps(_mm_cmpgt_ps(x1, zero), one), + _mm_and_ps(_mm_cmplt_ps(x1, zero), ngone)); + x2 = _mm_shuffle1_ps(x2, 2, 1, 0, 0); + + x3 = _mm_shuffle_ps(one, x2, _MM_SHUFFLE(0, 0, 0, 0)); /* q1 q1 1 1 */ + x3 = _mm_shuffle_ps(x3, x2, _MM_SHUFFLE(3, 2, 2, 0)); /* q3 q2 q1 1 */ + + _mm_store_ps(dest, _mm_mul_ps(r, x3)); +} + CGLM_INLINE float glm_mat4_det_sse2(mat4 mat) { From e4e0fa623c78e93bb9b141d9f890308eb056aa60 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 8 Apr 2018 18:27:54 +0300 Subject: [PATCH 071/292] sse2 version of vec4 dot product * use this for normalizing vector --- include/cglm/vec4.h | 9 ++++++++- makefile.am | 4 +++- test/src/test_common.c | 10 ++++++++++ test/src/test_common.h | 3 +++ test/src/test_main.c | 5 ++++- test/src/test_tests.h | 3 +++ test/src/test_vec4.c | 30 ++++++++++++++++++++++++++++++ 7 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 test/src/test_vec4.c diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 95bab09..97df6d4 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -122,7 +122,14 @@ glm_vec4_copy(vec4 v, vec4 dest) { CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + __m128 x0; + x0 = _mm_mul_ps(_mm_load_ps(a), _mm_load_ps(b)); + x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 3, 2)); + return _mm_cvtss_f32(_mm_add_ss(x0, _mm_shuffle1_ps(x0, 0, 1, 0, 1))); +#else return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; +#endif } /*! @@ -139,7 +146,7 @@ glm_vec4_dot(vec4 a, vec4 b) { CGLM_INLINE float glm_vec4_norm2(vec4 v) { - return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]; + return glm_vec_dot(v, v); } /*! diff --git a/makefile.am b/makefile.am index 436973c..2922373 100644 --- a/makefile.am +++ b/makefile.am @@ -109,6 +109,8 @@ test_tests_SOURCES=\ test/src/test_project.c \ test/src/test_clamp.c \ test/src/test_euler.c \ - test/src/test_quat.c + test/src/test_quat.c \ + test/src/test_vec4.c + all-local: sh ./post-build.sh diff --git a/test/src/test_common.c b/test/src/test_common.c index c38c474..c13ac0e 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -36,6 +36,16 @@ test_rand_vec3(vec3 dest) { dest[2] = drand48(); } +void +test_rand_vec4(vec4 dest) { + srand((unsigned int)time(NULL)); + + dest[0] = drand48(); + dest[1] = drand48(); + dest[2] = drand48(); + dest[3] = drand48(); +} + float test_rand_angle(void) { srand((unsigned int)time(NULL)); diff --git a/test/src/test_common.h b/test/src/test_common.h index f692483..477e59d 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -40,6 +40,9 @@ test_assert_quat_eq(versor v1, versor v2); void test_rand_vec3(vec3 dest); +void +test_rand_vec4(vec4 dest) ; + float test_rand_angle(void); diff --git a/test/src/test_main.c b/test/src/test_main.c index 384250f..7995a5a 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -26,7 +26,10 @@ main(int argc, const char * argv[]) { cmocka_unit_test(test_euler), /* quaternion */ - cmocka_unit_test(test_quat) + cmocka_unit_test(test_quat), + + /* vec4 */ + cmocka_unit_test(test_vec4) }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/test/src/test_tests.h b/test/src/test_tests.h index 398caa3..1dfbb5f 100644 --- a/test/src/test_tests.h +++ b/test/src/test_tests.h @@ -28,4 +28,7 @@ test_euler(void **state); void test_quat(void **state); +void +test_vec4(void **state); + #endif /* test_tests_h */ diff --git a/test/src/test_vec4.c b/test/src/test_vec4.c new file mode 100644 index 0000000..a45a700 --- /dev/null +++ b/test/src/test_vec4.c @@ -0,0 +1,30 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +CGLM_INLINE +float +test_vec4_dot(vec4 a, vec4 b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; +} + +void +test_vec4(void **state) { + vec4 v; + int i; + float d1, d2; + + /* test SSE/SIMD dot product */ + for (i = 0; i < 100; i++) { + test_rand_vec4(v); + d1 = glm_vec4_dot(v, v); + d2 = test_vec4_dot(v, v); + + assert_true(fabsf(d1 - d2) <= 0.000009); + } +} From 381b2fdcc0afdde2d8fe9f7abab62e1e7581000e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 9 Apr 2018 00:01:56 +0300 Subject: [PATCH 072/292] fix vec4_norm2, use dot for vec3_norm2 --- include/cglm/vec3.h | 2 +- include/cglm/vec4.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index e2108f3..873c172 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -147,7 +147,7 @@ glm_vec_cross(vec3 a, vec3 b, vec3 d) { CGLM_INLINE float glm_vec_norm2(vec3 v) { - return v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; + return glm_vec_dot(v, v); } /*! diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 97df6d4..adf5fb9 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -146,7 +146,7 @@ glm_vec4_dot(vec4 a, vec4 b) { CGLM_INLINE float glm_vec4_norm2(vec4 v) { - return glm_vec_dot(v, v); + return glm_vec4_dot(v, v); } /*! From f0daaca58b57bb290ac52de927d626adef967a83 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 9 Apr 2018 00:46:00 +0300 Subject: [PATCH 073/292] improve matrix to quaternion --- include/cglm/mat3.h | 48 +++++++++++++++++++++++++++++ include/cglm/mat4.h | 58 +++++++++++++++++++---------------- include/cglm/simd/sse2/mat4.h | 51 ------------------------------ test/src/test_common.c | 6 +--- test/src/test_quat.c | 10 +++--- 5 files changed, 86 insertions(+), 87 deletions(-) diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 61c4f3d..e7f8bcc 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -186,6 +186,54 @@ glm_mat3_mulv(mat3 m, vec3 v, vec3 dest) { dest[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2]; } + +/*! + * @brief convert mat4's rotation part to quaternion + * + * @param[in] m left matrix + * @param[out] dest destination quaternion + */ +CGLM_INLINE +void +glm_mat3_quat(mat3 m, versor dest) { + float trace, r, rinv; + + trace = m[0][0] + m[1][1] + m[2][2]; + if (trace >= 0.0f) { + r = 2.0f * sqrtf(1 + trace); + rinv = 1.0f / r; + + dest[1] = rinv * (m[1][2] - m[2][1]); + dest[2] = rinv * (m[2][0] - m[0][2]); + dest[3] = rinv * (m[0][1] - m[1][0]); + dest[0] = r * 0.25f; + } else if (m[0][0] >= m[1][1] && m[0][0] >= m[2][2]) { + r = 2.0f * sqrtf(1 - m[1][1] - m[2][2] + m[0][0]); + rinv = 1.0f / r; + + dest[1] = r * 0.25f; + dest[2] = rinv * (m[0][1] + m[1][0]); + dest[3] = rinv * (m[0][2] + m[2][0]); + dest[0] = rinv * (m[1][2] - m[2][1]); + } else if (m[1][1] >= m[2][2]) { + r = 2.0f * sqrtf(1 - m[0][0] - m[2][2] + m[1][1]); + rinv = 1.0f / r; + + dest[1] = rinv * (m[0][1] + m[1][0]); + dest[2] = r * 0.25f; + dest[3] = rinv * (m[1][2] + m[2][1]); + dest[0] = rinv * (m[2][0] - m[0][2]); + } else { + r = 2.0f * sqrtf(1 - m[0][0] - m[1][1] + m[2][2]); + rinv = 1.0f / r; + + dest[1] = rinv * (m[0][2] + m[2][0]); + dest[2] = rinv * (m[1][2] + m[2][1]); + dest[3] = r * 0.25f; + dest[0] = rinv * (m[0][1] - m[1][0]); + } +} + /*! * @brief scale (multiply with scalar) matrix * diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 782a24b..05aac60 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -343,38 +343,42 @@ glm_mat4_mulq(mat4 m, versor q, mat4 dest) { CGLM_INLINE void glm_mat4_quat(mat4 m, versor dest) { -#if defined( __SSE__ ) || defined( __SSE2__ ) - glm_mat4_quat_sse2(m, dest); -#else - vec4 vsgn, vzero = GLM_VEC4_ZERO_INIT; - versor q; - float m00, m10, m20, - m01, m11, m21, - m02, m12, m22; + float trace, r, rinv; - m00 = m[0][0]; m01 = m[0][1]; m02 = m[0][2]; - m10 = m[1][0]; m11 = m[1][1]; m12 = m[1][2]; - m20 = m[2][0]; m21 = m[2][1]; m22 = m[2][2]; + trace = m[0][0] + m[1][1] + m[2][2]; + if (trace >= 0.0f) { + r = 2.0f * sqrtf(1 + trace); + rinv = 1.0f / r; - q[0] = 1.0f + m00 + m11 + m22; /* w */ - q[1] = 1.0f + m00 - m11 - m22; /* x */ - q[2] = 1.0f - m00 + m11 - m22; /* y */ - q[3] = 1.0f - m00 - m11 + m22; /* z */ + dest[1] = rinv * (m[1][2] - m[2][1]); + dest[2] = rinv * (m[2][0] - m[0][2]); + dest[3] = rinv * (m[0][1] - m[1][0]); + dest[0] = r * 0.25f; + } else if (m[0][0] >= m[1][1] && m[0][0] >= m[2][2]) { + r = 2.0f * sqrtf(1 - m[1][1] - m[2][2] + m[0][0]); + rinv = 1.0f / r; - glm_vec4_maxv(q, vzero, q); - glm_vec4_sqrt(q, q); - glm_vec4_scale(q, 0.5f, q); + dest[1] = r * 0.25f; + dest[2] = rinv * (m[0][1] + m[1][0]); + dest[3] = rinv * (m[0][2] + m[2][0]); + dest[0] = rinv * (m[1][2] - m[2][1]); + } else if (m[1][1] >= m[2][2]) { + r = 2.0f * sqrtf(1 - m[0][0] - m[2][2] + m[1][1]); + rinv = 1.0f / r; - vsgn[0] = 1.0f; - vsgn[1] = m12 - m21; - vsgn[2] = m20 - m02; - vsgn[3] = m01 - m10; + dest[1] = rinv * (m[0][1] + m[1][0]); + dest[2] = r * 0.25f; + dest[3] = rinv * (m[1][2] + m[2][1]); + dest[0] = rinv * (m[2][0] - m[0][2]); + } else { + r = 2.0f * sqrtf(1 - m[0][0] - m[1][1] + m[2][2]); + rinv = 1.0f / r; - glm_vec4_sign(vsgn, vsgn); - glm_vec4_mulv(q, vsgn, q); - - glm_vec4_copy(q, dest); -#endif + dest[1] = rinv * (m[0][2] + m[2][0]); + dest[2] = rinv * (m[1][2] + m[2][1]); + dest[3] = r * 0.25f; + dest[0] = rinv * (m[0][1] - m[1][0]); + } } /*! diff --git a/include/cglm/simd/sse2/mat4.h b/include/cglm/simd/sse2/mat4.h index 0476176..77874a8 100644 --- a/include/cglm/simd/sse2/mat4.h +++ b/include/cglm/simd/sse2/mat4.h @@ -102,57 +102,6 @@ glm_mat4_mulv_sse2(mat4 m, vec4 v, vec4 dest) { _mm_store_ps(dest, _mm_add_ps(x1, x2)); } -CGLM_INLINE -void -glm_mat4_quat_sse2(mat4 m, versor dest) { - __m128 c0, c1, c2, x0, x1, x2, x3, m00, m11, m22, r; - __m128 zero, one, half, ngone; - - c0 = _mm_load_ps(m[0]); - c1 = _mm_load_ps(m[1]); - c2 = _mm_load_ps(m[2]); - - m00 = _mm_xor_ps(_mm_shuffle1_ps1(c0, 0), _mm_set_ps(-0.f, -0.f, 0.f, 0.f)); - m11 = _mm_xor_ps(_mm_shuffle1_ps1(c1, 1), _mm_set_ps(-0.f, 0.f, -0.f, 0.f)); - m22 = _mm_xor_ps(_mm_shuffle1_ps1(c2, 2), _mm_set_ps( 0.f, -0.f, -0.f, 0.f)); - - x0 = _mm_set_ps(-1.0f, 0.0f, 0.5, 1.0f); - one = _mm_shuffle1_ps1(x0, 0); - half = _mm_shuffle1_ps1(x0, 1); - zero = _mm_shuffle1_ps1(x0, 2); - ngone = _mm_shuffle1_ps1(x0, 3); - - /* - q[0] = sqrtf(glm_max(0.0f, 1.0f + m00 + m11 + m22)) * 0.5f; - q[1] = sqrtf(glm_max(0.0f, 1.0f + m00 - m11 - m22)) * 0.5f; - q[2] = sqrtf(glm_max(0.0f, 1.0f - m00 + m11 - m22)) * 0.5f; - q[3] = sqrtf(glm_max(0.0f, 1.0f - m00 - m11 + m22)) * 0.5f; - */ - x0 = _mm_add_ps(one, _mm_add_ps(_mm_add_ps(m00, m11), m22)); - r = _mm_mul_ps(_mm_sqrt_ps(_mm_max_ps(zero, x0)), half); - - /* - q[1] *= glm_signf(m12 - m21); - q[2] *= glm_signf(m20 - m02); - q[3] *= glm_signf(m01 - m10); - */ - x1 = _mm_shuffle_ps(c1, c2, _MM_SHUFFLE(0, 0, 2, 2)); /* m20 m20 m12 m12 */ - x1 = _mm_shuffle_ps(x1, c0, _MM_SHUFFLE(1, 1, 2, 0)); /* m01 m01 m20 m12 */ - - x2 = _mm_shuffle_ps(c2, c0, _MM_SHUFFLE(2, 2, 1, 1)); /* m02 m02 m21 m21 */ - x2 = _mm_shuffle_ps(x2, c1, _MM_SHUFFLE(0, 0, 2, 0)); /* m10 m10 m02 m21 */ - - x1 = _mm_sub_ps(x1, x2); - x2 = _mm_or_ps(_mm_and_ps(_mm_cmpgt_ps(x1, zero), one), - _mm_and_ps(_mm_cmplt_ps(x1, zero), ngone)); - x2 = _mm_shuffle1_ps(x2, 2, 1, 0, 0); - - x3 = _mm_shuffle_ps(one, x2, _MM_SHUFFLE(0, 0, 0, 0)); /* q1 q1 1 1 */ - x3 = _mm_shuffle_ps(x3, x2, _MM_SHUFFLE(3, 2, 2, 0)); /* q3 q2 q1 1 */ - - _mm_store_ps(dest, _mm_mul_ps(r, x3)); -} - CGLM_INLINE float glm_mat4_det_sse2(mat4 mat) { diff --git a/test/src/test_common.c b/test/src/test_common.c index c13ac0e..b824b37 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -55,12 +55,8 @@ test_rand_angle(void) { void test_rand_quat(versor q) { srand((unsigned int)time(NULL)); - - q[0] = drand48(); - q[1] = drand48(); - q[2] = drand48(); - q[3] = drand48(); + glm_quat(q, drand48(), drand48(), drand48(), drand48()); glm_quat_normalize(q); } diff --git a/test/src/test_quat.c b/test/src/test_quat.c index 1a328de..36d2ef5 100644 --- a/test/src/test_quat.c +++ b/test/src/test_quat.c @@ -9,14 +9,16 @@ void test_quat(void **state) { - mat4 rot; + mat4 inRot, outRot; versor inQuat, outQuat; int i; - for (i = 0; i < 10000; i++) { + for (i = 0; i < 1000; i++) { test_rand_quat(inQuat); - glmc_quat_mat4(inQuat, rot); - glm_mat4_quat(rot, outQuat); + glmc_quat_mat4(inQuat, inRot); + glmc_mat4_quat(inRot, outQuat); + glmc_quat_mat4(outQuat, outRot); test_assert_quat_eq(inQuat, outQuat); + test_assert_mat4_eq2(inRot, outRot, 0.000009); /* almost equal */ } } From 7615f785acc2759b1a27e88ecf9ad6dffd4e9b8c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 9 Apr 2018 00:53:14 +0300 Subject: [PATCH 074/292] improve quaternion to matrix --- include/cglm/quat.h | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index e9e986e..bbad5f2 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -185,18 +185,19 @@ glm_quat_mat4(versor q, mat4 dest) { float w, x, y, z, xx, yy, zz, xy, yz, xz, - wx, wy, wz, norm; + wx, wy, wz, norm, s; - norm = 1.0f / glm_quat_norm(q); + norm = glm_quat_norm(q); + s = norm > 0.0f ? 2.0f / norm : 0.0f; - w = q[0] * norm; - x = q[1] * norm; - y = q[2] * norm; - z = q[3] * norm; + w = q[0]; + x = q[1]; + y = q[2]; + z = q[3]; - xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x; - yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y; - zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z; + xx = s * x * x; xy = s * x * y; wx = s * w * x; + yy = s * y * y; yz = s * y * z; wy = s * w * y; + zz = s * z * z; xz = s * x * z; wz = s * w * z; dest[0][0] = 1.0f - yy - zz; dest[1][1] = 1.0f - xx - zz; @@ -210,8 +211,8 @@ glm_quat_mat4(versor q, mat4 dest) { dest[2][1] = yz - wx; dest[0][2] = xz - wy; - dest[1][3] = 0.0f; dest[0][3] = 0.0f; + dest[1][3] = 0.0f; dest[2][3] = 0.0f; dest[3][0] = 0.0f; dest[3][1] = 0.0f; @@ -231,18 +232,19 @@ glm_quat_mat3(versor q, mat3 dest) { float w, x, y, z, xx, yy, zz, xy, yz, xz, - wx, wy, wz, norm; + wx, wy, wz, norm, s; - norm = 1.0f / glm_quat_norm(q); + norm = glm_quat_norm(q); + s = norm > 0.0f ? 2.0f / norm : 0.0f; - w = q[0] * norm; - x = q[1] * norm; - y = q[2] * norm; - z = q[3] * norm; + w = q[0]; + x = q[1]; + y = q[2]; + z = q[3]; - xx = 2.0f * x * x; xy = 2.0f * x * y; wx = 2.0f * w * x; - yy = 2.0f * y * y; yz = 2.0f * y * z; wy = 2.0f * w * y; - zz = 2.0f * z * z; xz = 2.0f * x * z; wz = 2.0f * w * z; + xx = s * x * x; xy = s * x * y; wx = s * w * x; + yy = s * y * y; yz = s * y * z; wy = s * w * y; + zz = s * z * z; xz = s * x * z; wz = s * w * z; dest[0][0] = 1.0f - yy - zz; dest[1][1] = 1.0f - xx - zz; From 3dc93c56e8696a25e1e5d21fba5cdeefc8f9ab42 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 9 Apr 2018 18:49:12 +0300 Subject: [PATCH 075/292] convert quaterinon to xyzw order (part 1) --- include/cglm/call/quat.h | 15 ++----- include/cglm/mat3.h | 52 +++++++++++----------- include/cglm/mat4.h | 52 +++++++++++----------- include/cglm/quat.h | 95 +++++++++++++++++++++------------------- include/cglm/vec3.h | 4 +- src/quat.c | 12 ++--- 6 files changed, 112 insertions(+), 118 deletions(-) diff --git a/include/cglm/call/quat.h b/include/cglm/call/quat.h index e40bcdf..576f43b 100644 --- a/include/cglm/call/quat.h +++ b/include/cglm/call/quat.h @@ -19,17 +19,11 @@ glmc_quat_identity(versor q); CGLM_EXPORT void -glmc_quat(versor q, - float angle, - float x, - float y, - float z); +glmc_quat(versor q, float angle, float x, float y, float z); CGLM_EXPORT void -glmc_quatv(versor q, - float angle, - vec3 v); +glmc_quatv(versor q, float angle, vec3 v); CGLM_EXPORT float @@ -57,10 +51,7 @@ glmc_quat_mat3(versor q, mat3 dest); CGLM_EXPORT void -glmc_quat_slerp(versor q, - versor r, - float t, - versor dest); +glmc_quat_slerp(versor q, versor r, float t, versor dest); #ifdef __cplusplus } diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index e7f8bcc..9512aef 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -198,39 +198,41 @@ void glm_mat3_quat(mat3 m, versor dest) { float trace, r, rinv; + /* it seems using like m12 instead of m[1][2] causes extra instructions */ + trace = m[0][0] + m[1][1] + m[2][2]; if (trace >= 0.0f) { - r = 2.0f * sqrtf(1 + trace); - rinv = 1.0f / r; + r = sqrtf(1.0f + trace); + rinv = 0.5f / r; - dest[1] = rinv * (m[1][2] - m[2][1]); - dest[2] = rinv * (m[2][0] - m[0][2]); - dest[3] = rinv * (m[0][1] - m[1][0]); - dest[0] = r * 0.25f; - } else if (m[0][0] >= m[1][1] && m[0][0] >= m[2][2]) { - r = 2.0f * sqrtf(1 - m[1][1] - m[2][2] + m[0][0]); - rinv = 1.0f / r; - - dest[1] = r * 0.25f; - dest[2] = rinv * (m[0][1] + m[1][0]); - dest[3] = rinv * (m[0][2] + m[2][0]); dest[0] = rinv * (m[1][2] - m[2][1]); - } else if (m[1][1] >= m[2][2]) { - r = 2.0f * sqrtf(1 - m[0][0] - m[2][2] + m[1][1]); - rinv = 1.0f / r; + dest[1] = rinv * (m[2][0] - m[0][2]); + dest[2] = rinv * (m[0][1] - m[1][0]); + dest[3] = r * 0.5f; + } else if (m[0][0] >= m[1][1] && m[0][0] >= m[2][2]) { + r = sqrtf(1.0f - m[1][1] - m[2][2] + m[0][0]); + rinv = 0.5f / r; + dest[0] = r * 0.5f; dest[1] = rinv * (m[0][1] + m[1][0]); - dest[2] = r * 0.25f; - dest[3] = rinv * (m[1][2] + m[2][1]); - dest[0] = rinv * (m[2][0] - m[0][2]); - } else { - r = 2.0f * sqrtf(1 - m[0][0] - m[1][1] + m[2][2]); - rinv = 1.0f / r; + dest[2] = rinv * (m[0][2] + m[2][0]); + dest[3] = rinv * (m[1][2] - m[2][1]); + } else if (m[1][1] >= m[2][2]) { + r = sqrtf(1.0f - m[0][0] - m[2][2] + m[1][1]); + rinv = 0.5f / r; - dest[1] = rinv * (m[0][2] + m[2][0]); + dest[0] = rinv * (m[0][1] + m[1][0]); + dest[1] = r * 0.5f; dest[2] = rinv * (m[1][2] + m[2][1]); - dest[3] = r * 0.25f; - dest[0] = rinv * (m[0][1] - m[1][0]); + dest[3] = rinv * (m[2][0] - m[0][2]); + } else { + r = sqrtf(1.0f - m[0][0] - m[1][1] + m[2][2]); + rinv = 0.5f / r; + + dest[0] = rinv * (m[0][2] + m[2][0]); + dest[1] = rinv * (m[1][2] + m[2][1]); + dest[2] = r * 0.5f; + dest[3] = rinv * (m[0][1] - m[1][0]); } } diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 05aac60..fd7a340 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -345,39 +345,41 @@ void glm_mat4_quat(mat4 m, versor dest) { float trace, r, rinv; + /* it seems using like m12 instead of m[1][2] causes extra instructions */ + trace = m[0][0] + m[1][1] + m[2][2]; if (trace >= 0.0f) { - r = 2.0f * sqrtf(1 + trace); - rinv = 1.0f / r; + r = sqrtf(1.0f + trace); + rinv = 0.5f / r; - dest[1] = rinv * (m[1][2] - m[2][1]); - dest[2] = rinv * (m[2][0] - m[0][2]); - dest[3] = rinv * (m[0][1] - m[1][0]); - dest[0] = r * 0.25f; - } else if (m[0][0] >= m[1][1] && m[0][0] >= m[2][2]) { - r = 2.0f * sqrtf(1 - m[1][1] - m[2][2] + m[0][0]); - rinv = 1.0f / r; - - dest[1] = r * 0.25f; - dest[2] = rinv * (m[0][1] + m[1][0]); - dest[3] = rinv * (m[0][2] + m[2][0]); dest[0] = rinv * (m[1][2] - m[2][1]); - } else if (m[1][1] >= m[2][2]) { - r = 2.0f * sqrtf(1 - m[0][0] - m[2][2] + m[1][1]); - rinv = 1.0f / r; + dest[1] = rinv * (m[2][0] - m[0][2]); + dest[2] = rinv * (m[0][1] - m[1][0]); + dest[3] = r * 0.5f; + } else if (m[0][0] >= m[1][1] && m[0][0] >= m[2][2]) { + r = sqrtf(1.0f - m[1][1] - m[2][2] + m[0][0]); + rinv = 0.5f / r; + dest[0] = r * 0.5f; dest[1] = rinv * (m[0][1] + m[1][0]); - dest[2] = r * 0.25f; - dest[3] = rinv * (m[1][2] + m[2][1]); - dest[0] = rinv * (m[2][0] - m[0][2]); - } else { - r = 2.0f * sqrtf(1 - m[0][0] - m[1][1] + m[2][2]); - rinv = 1.0f / r; + dest[2] = rinv * (m[0][2] + m[2][0]); + dest[3] = rinv * (m[1][2] - m[2][1]); + } else if (m[1][1] >= m[2][2]) { + r = sqrtf(1.0f - m[0][0] - m[2][2] + m[1][1]); + rinv = 0.5f / r; - dest[1] = rinv * (m[0][2] + m[2][0]); + dest[0] = rinv * (m[0][1] + m[1][0]); + dest[1] = r * 0.5f; dest[2] = rinv * (m[1][2] + m[2][1]); - dest[3] = r * 0.25f; - dest[0] = rinv * (m[0][1] - m[1][0]); + dest[3] = rinv * (m[2][0] - m[0][2]); + } else { + r = sqrtf(1.0f - m[0][0] - m[1][1] + m[2][2]); + rinv = 0.5f / r; + + dest[0] = rinv * (m[0][2] + m[2][0]); + dest[1] = rinv * (m[1][2] + m[2][1]); + dest[2] = r * 0.5f; + dest[3] = rinv * (m[0][1] - m[1][0]); } } diff --git a/include/cglm/quat.h b/include/cglm/quat.h index bbad5f2..4d6ee5d 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -13,7 +13,7 @@ Functions: CGLM_INLINE void glm_quat_identity(versor q); CGLM_INLINE void glm_quat(versor q, float angle, float x, float y, float z); - CGLM_INLINE void glm_quatv(versor q, float angle, vec3 v); + CGLM_INLINE void glm_quatv(versor q, float angle, vec3 axis); CGLM_INLINE float glm_quat_norm(versor q); CGLM_INLINE void glm_quat_normalize(versor q); CGLM_INLINE float glm_quat_dot(versor q, versor r); @@ -33,19 +33,16 @@ #endif /* - * IMPORTANT! cglm stores quat as [w, x, y, z] + * IMPORTANT: + * ---------------------------------------------------------------------------- + * cglm stores quat as [x, y, z, w] since v0.3.6 * - * Possible changes (these may be changed in the future): - * - versor is identity quat, we can define new type for quat. - * it can't be quat or quaternion becuase someone can use that name for - * variable name. maybe just vec4. - * - it stores [w, x, y, z] but it may change to [x, y, z, w] if we get enough - * feedback to change it. - * - in general we use last param as dest, but this header used first param - * as dest this may be changed but decided yet + * it was [w, x, y, z] before v0.3.6 it has been changed to [x, y, z, w] + * with v0.3.6 version. + * ---------------------------------------------------------------------------- */ -#define GLM_QUAT_IDENTITY_INIT {1.0f, 0.0f, 0.0f, 0.0f} +#define GLM_QUAT_IDENTITY_INIT {0.0f, 0.0f, 0.0f, 1.0f} #define GLM_QUAT_IDENTITY ((versor)GLM_QUAT_IDENTITY_INIT) /*! @@ -60,6 +57,24 @@ glm_quat_identity(versor q) { glm_vec4_copy(v, q); } +/*! + * @brief inits quaterion with raw values + * + * @param[out] q quaternion + * @param[in] x x + * @param[in] y y + * @param[in] z z + * @param[in] w w (real part) + */ +CGLM_INLINE +void +glm_quat_init(versor q, float x, float y, float z, float w) { + q[0] = x; + q[1] = y; + q[2] = z; + q[3] = w; +} + /*! * @brief creates NEW quaternion with individual axis components * @@ -71,21 +86,17 @@ glm_quat_identity(versor q) { */ CGLM_INLINE void -glm_quat(versor q, - float angle, - float x, - float y, - float z) { +glm_quat(versor q, float angle, float x, float y, float z) { float a, c, s; a = angle * 0.5f; c = cosf(a); s = sinf(a); - q[0] = c; - q[1] = s * x; - q[2] = s * y; - q[3] = s * z; + q[0] = s * x; + q[1] = s * y; + q[2] = s * z; + q[3] = c; } /*! @@ -93,23 +104,21 @@ glm_quat(versor q, * * @param[out] q quaternion * @param[in] angle angle (radians) - * @param[in] v axis + * @param[in] axis axis */ CGLM_INLINE void -glm_quatv(versor q, - float angle, - vec3 v) { +glm_quatv(versor q, float angle, vec3 axis) { float a, c, s; a = angle * 0.5f; c = cosf(a); s = sinf(a); - q[0] = c; - q[1] = s * v[0]; - q[2] = s * v[1]; - q[3] = s * v[2]; + q[0] = s * axis[0]; + q[1] = s * axis[1]; + q[2] = s * axis[2]; + q[3] = c; } /*! @@ -146,13 +155,13 @@ glm_quat_normalize(versor q) { /*! * @brief dot product of two quaternion * - * @param[in] q quaternion 1 - * @param[in] r quaternion 2 + * @param[in] q1 quaternion 1 + * @param[in] q2 quaternion 2 */ CGLM_INLINE float -glm_quat_dot(versor q, versor r) { - return glm_vec4_dot(q, r); +glm_quat_dot(versor q1, versor q2) { + return glm_vec4_dot(q1, q2); } /*! @@ -190,10 +199,10 @@ glm_quat_mat4(versor q, mat4 dest) { norm = glm_quat_norm(q); s = norm > 0.0f ? 2.0f / norm : 0.0f; - w = q[0]; - x = q[1]; - y = q[2]; - z = q[3]; + x = q[0]; + y = q[1]; + z = q[2]; + w = q[3]; xx = s * x * x; xy = s * x * y; wx = s * w * x; yy = s * y * y; yz = s * y * z; wy = s * w * y; @@ -237,10 +246,10 @@ glm_quat_mat3(versor q, mat3 dest) { norm = glm_quat_norm(q); s = norm > 0.0f ? 2.0f / norm : 0.0f; - w = q[0]; - x = q[1]; - y = q[2]; - z = q[3]; + x = q[0]; + y = q[1]; + z = q[2]; + w = q[3]; xx = s * x * x; xy = s * x * y; wx = s * w * x; yy = s * y * y; yz = s * y * z; wy = s * w * y; @@ -270,10 +279,8 @@ glm_quat_mat3(versor q, mat3 dest) { */ CGLM_INLINE void -glm_quat_slerp(versor q, - versor r, - float t, - versor dest) { +glm_quat_slerp(versor q, versor r, float t, versor dest) { + /* https://en.wikipedia.org/wiki/Slerp */ #if defined( __SSE__ ) || defined( __SSE2__ ) glm_quat_slerp_sse2(q, r, t, dest); diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 873c172..65fe0ba 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -327,9 +327,7 @@ glm_vec_angle(vec3 v1, vec3 v2) { CGLM_INLINE void -glm_quatv(versor q, - float angle, - vec3 v); +glm_quatv(versor q, float angle, vec3 axis); /*! * @brief rotate vec3 around axis by angle using Rodrigues' rotation formula diff --git a/src/quat.c b/src/quat.c index 9955ce1..35ec890 100644 --- a/src/quat.c +++ b/src/quat.c @@ -16,19 +16,13 @@ glmc_quat_identity(versor q) { CGLM_EXPORT void -glmc_quat(versor q, - float angle, - float x, - float y, - float z) { +glmc_quat(versor q, float angle, float x, float y, float z) { glm_quat(q, angle, x, y, z); } CGLM_EXPORT void -glmc_quatv(versor q, - float angle, - vec3 v) { +glmc_quatv(versor q, float angle, vec3 v) { glm_quatv(q, angle, v); } @@ -53,7 +47,7 @@ glmc_quat_dot(versor q, versor r) { CGLM_EXPORT void glmc_quat_mulv(versor q1, versor q2, versor dest) { - glm_quat_mulv(q1, q2, dest); + glm_quat_mul(q1, q2, dest); } CGLM_EXPORT From d79e58486d21f5c2406e6fa7fbc55d73b03ecab7 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 9 Apr 2018 21:54:35 +0300 Subject: [PATCH 076/292] update credits file --- CREDITS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CREDITS b/CREDITS index 810f0b4..66604eb 100644 --- a/CREDITS +++ b/CREDITS @@ -43,3 +43,6 @@ https://github.com/erich666/GraphicsGems/blob/master/gems/TransBox.c 6. Cull frustum http://www.txutxi.com/?p=584 http://old.cescg.org/CESCG-2002/DSykoraJJelinek/ + +7. Quaternions +Initial mat4_quat is borrowed from Apple's simd library From 76e9f740208305fffd4f027c0bed186a12857027 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 9 Apr 2018 21:54:53 +0300 Subject: [PATCH 077/292] conjugate of quaternion --- include/cglm/quat.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 4d6ee5d..f824010 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -182,6 +182,20 @@ glm_quat_mulv(versor q1, versor q2, versor dest) { glm_quat_normalize(dest); } +/*! + * @brief conjugate of quaternion + * + * @param[in] q quaternion + * @param[out] dest conjugate + */ +CGLM_INLINE +void +glm_quat_conjugate(versor q, versor dest) { + glm_vec4_copy(q, dest); + glm_vec4_flipsign(dest); + dest[3] = -dest[3]; +} + /*! * @brief convert quaternion to mat4 * From b21df8fc37ce40cb43c88615ef7471075b61a968 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 9 Apr 2018 22:26:23 +0300 Subject: [PATCH 078/292] inverse of quaternion --- include/cglm/quat.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index f824010..a2556dd 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -196,6 +196,20 @@ glm_quat_conjugate(versor q, versor dest) { dest[3] = -dest[3]; } +/*! + * @brief inverse of non-zero quaternion + * + * @param[in] q quaternion + * @param[out] dest inverse quaternion + */ +CGLM_INLINE +void +glm_quat_inv(versor q, versor dest) { + versor conj; + glm_quat_conjugate(q, conj); + glm_vec_scale(conj, glm_vec4_norm2(q), dest); +} + /*! * @brief convert quaternion to mat4 * From cc1d3b53ea4a09ae8ef285c22100dc2353da784d Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 9 Apr 2018 22:32:55 +0300 Subject: [PATCH 079/292] quat: implement add, sub, real and imag helpers --- include/cglm/quat.h | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index a2556dd..efea541 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -210,6 +210,56 @@ glm_quat_inv(versor q, versor dest) { glm_vec_scale(conj, glm_vec4_norm2(q), dest); } +/*! + * @brief add (componentwise) two quaternions and store result in dest + * + * @param[in] p quaternion 1 + * @param[in] q quaternion 2 + * @param[out] dest result quaternion + */ +CGLM_INLINE +void +glm_quat_add(versor p, versor q, versor dest) { + glm_vec4_add(p, q, dest); +} + +/*! + * @brief subtract (componentwise) two quaternions and store result in dest + * + * @param[in] p quaternion 1 + * @param[in] q quaternion 2 + * @param[out] dest result quaternion + */ +CGLM_INLINE +void +glm_quat_sub(versor p, versor q, versor dest) { + glm_vec4_sub(p, q, dest); +} + +/*! + * @brief returns real part of quaternion + * + * @param[in] q quaternion + */ +CGLM_INLINE +float +glm_quat_real(versor q) { + return q[3]; +} + +/*! + * @brief returns imaginary part of quaternion + * + * @param[in] q quaternion + */ +CGLM_INLINE +void +glm_quat_imag(versor q, vec3 dest) { + dest[0] = q[0]; + dest[1] = q[1]; + dest[2] = q[2]; +} + /*! * @brief convert quaternion to mat4 * From 93a08fce17155addc14fc526644d9e24320d1a67 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 9 Apr 2018 23:12:44 +0300 Subject: [PATCH 080/292] quat: axis angle of quaternion --- include/cglm/quat.h | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index efea541..e73bf8b 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -260,6 +260,56 @@ glm_quat_imag(versor q, vec3 dest) { dest[2] = q[2]; } +/*! + * @brief returns normalized imaginary part of quaternion + * + * @param[in] q quaternion + */ +CGLM_INLINE +void +glm_quat_imagn(versor q, vec3 dest) { + glm_normalize_to(q, dest); +} + +/*! + * @brief returns length of imaginary part of quaternion + * + * @param[in] q quaternion + */ +CGLM_INLINE +float +glm_quat_imaglen(versor q) { + return glm_vec_norm(q); +} + +/*! + * @brief returns angle of quaternion + * + * @param[in] q quaternion + */ +CGLM_INLINE +float +glm_quat_angle(versor q) { + /* + sin(theta / 2) = length(x*x + y*y + z*z) + cos(theta / 2) = w + theta = 2 * atan(sin(theta / 2) / cos(theta / 2)) + */ + return 2.0f * atan2f(glm_quat_imaglen(q), glm_quat_real(q)); +} + +/*! + * @brief axis of quaternion + * + * @param[in] q quaternion + * @param[out] dest axis of quaternion + */ +CGLM_INLINE +void +glm_quat_axis(versor q, versor dest) { + glm_quat_imagn(q, dest); +} + /*! * @brief convert quaternion to mat4 * From 6f69da361b91d27d5784abc2c2f799536efd309b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 9 Apr 2018 23:56:09 +0300 Subject: [PATCH 081/292] quaternion multiplication * convert quaternion multiplication to xyzw * previous implementation may be wrong, wikipedia version implemented * implement SSE version --- include/cglm/call/quat.h | 2 +- include/cglm/quat.h | 77 +++++++++++++++++++++++------------ include/cglm/simd/sse2/quat.h | 29 +++++++++++++ src/quat.c | 9 ++-- test/src/test_common.c | 18 +++++--- test/src/test_common.h | 3 ++ test/src/test_quat.c | 18 +++++++- 7 files changed, 116 insertions(+), 40 deletions(-) diff --git a/include/cglm/call/quat.h b/include/cglm/call/quat.h index 576f43b..ee45f0c 100644 --- a/include/cglm/call/quat.h +++ b/include/cglm/call/quat.h @@ -39,7 +39,7 @@ glmc_quat_dot(versor q, versor r); CGLM_EXPORT void -glmc_quat_mulv(versor q1, versor q2, versor dest); +glmc_quat_mul(versor p, versor q, versor dest); CGLM_EXPORT void diff --git a/include/cglm/quat.h b/include/cglm/quat.h index e73bf8b..e1112d5 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -11,15 +11,27 @@ GLM_QUAT_IDENTITY Functions: - CGLM_INLINE void glm_quat_identity(versor q); - CGLM_INLINE void glm_quat(versor q, float angle, float x, float y, float z); - CGLM_INLINE void glm_quatv(versor q, float angle, vec3 axis); + CGLM_INLINE void glm_quat_identity(versor q); + CGLM_INLINE void glm_quat_init(versor q, float x, float y, float z, float w); + CGLM_INLINE void glm_quat(versor q, float angle, float x, float y, float z); + CGLM_INLINE void glm_quatv(versor q, float angle, vec3 axis); CGLM_INLINE float glm_quat_norm(versor q); - CGLM_INLINE void glm_quat_normalize(versor q); - CGLM_INLINE float glm_quat_dot(versor q, versor r); - CGLM_INLINE void glm_quat_mulv(versor q1, versor q2, versor dest); - CGLM_INLINE void glm_quat_mat4(versor q, mat4 dest); - CGLM_INLINE void glm_quat_slerp(versor q, versor r, float t, versor dest); + CGLM_INLINE void glm_quat_normalize(versor q); + CGLM_INLINE float glm_quat_dot(versor q1, versor q2); + CGLM_INLINE void glm_quat_conjugate(versor q, versor dest); + CGLM_INLINE void glm_quat_inv(versor q, versor dest); + CGLM_INLINE void glm_quat_add(versor p, versor q, versor dest); + CGLM_INLINE void glm_quat_sub(versor p, versor q, versor dest); + CGLM_INLINE float glm_quat_real(versor q); + CGLM_INLINE void glm_quat_imag(versor q, vec3 dest); + CGLM_INLINE void glm_quat_imagn(versor q, vec3 dest); + CGLM_INLINE float glm_quat_imaglen(versor q); + CGLM_INLINE float glm_quat_angle(versor q); + CGLM_INLINE void glm_quat_axis(versor q, versor dest); + CGLM_INLINE void glm_quat_mul(versor p, versor q, versor dest); + CGLM_INLINE void glm_quat_mat4(versor q, mat4 dest); + CGLM_INLINE void glm_quat_mat3(versor q, mat3 dest) + CGLM_INLINE void glm_quat_slerp(versor q, versor r, float t, versor dest); */ #ifndef cglm_quat_h @@ -164,24 +176,6 @@ glm_quat_dot(versor q1, versor q2) { return glm_vec4_dot(q1, q2); } -/*! - * @brief multiplies two quaternion and stores result in dest - * - * @param[in] q1 quaternion 1 - * @param[in] q2 quaternion 2 - * @param[out] dest result quaternion - */ -CGLM_INLINE -void -glm_quat_mulv(versor q1, versor q2, versor dest) { - dest[0] = q2[0] * q1[0] - q2[1] * q1[1] - q2[2] * q1[2] - q2[3] * q1[3]; - dest[1] = q2[0] * q1[1] + q2[1] * q1[0] - q2[2] * q1[3] + q2[3] * q1[2]; - dest[2] = q2[0] * q1[2] + q2[1] * q1[3] + q2[2] * q1[0] - q2[3] * q1[1]; - dest[3] = q2[0] * q1[3] - q2[1] * q1[2] + q2[2] * q1[1] + q2[3] * q1[0]; - - glm_quat_normalize(dest); -} - /*! * @brief conjugate of quaternion * @@ -310,6 +304,37 @@ glm_quat_axis(versor q, versor dest) { glm_quat_imagn(q, dest); } +/*! + * @brief multiplies two quaternion and stores result in dest + * this is also called Hamilton Product + * + * According to WikiPedia: + * The product of two rotation quaternions [clarification needed] will be + * equivalent to the rotation q followed by the rotation p + * + * @param[in] p quaternion 1 + * @param[in] q quaternion 2 + * @param[out] dest result quaternion + */ +CGLM_INLINE +void +glm_quat_mul(versor p, versor q, versor dest) { + /* + + (a1 b2 + b1 a2 + c1 d2 − d1 c2)i + + (a1 c2 − b1 d2 + c1 a2 + d1 b2)j + + (a1 d2 + b1 c2 − c1 b2 + d1 a2)k + a1 a2 − b1 b2 − c1 c2 − d1 d2 + */ +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_quat_mul_sse2(p, q, dest); +#else + dest[0] = p[3] * q[0] + p[0] * q[3] + p[1] * q[2] - p[2] * q[1]; + dest[1] = p[3] * q[1] - p[0] * q[2] + p[1] * q[3] + p[2] * q[0]; + dest[2] = p[3] * q[2] + p[0] * q[1] - p[1] * q[0] + p[2] * q[3]; + dest[3] = p[3] * q[3] - p[0] * q[0] - p[1] * q[1] - p[2] * q[2]; +#endif +} + /*! * @brief convert quaternion to mat4 * diff --git a/include/cglm/simd/sse2/quat.h b/include/cglm/simd/sse2/quat.h index b3420a7..59438f4 100644 --- a/include/cglm/simd/sse2/quat.h +++ b/include/cglm/simd/sse2/quat.h @@ -12,6 +12,35 @@ #include "../../common.h" #include "../intrin.h" +CGLM_INLINE +void +glm_quat_mul_sse2(versor p, versor q, versor dest) { + /* + + (a1 b2 + b1 a2 + c1 d2 − d1 c2)i + + (a1 c2 − b1 d2 + c1 a2 + d1 b2)j + + (a1 d2 + b1 c2 − c1 b2 + d1 a2)k + a1 a2 − b1 b2 − c1 c2 − d1 d2 + */ + + __m128 xp, xq, x0, r; + + xp = _mm_load_ps(p); /* 3 2 1 0 */ + xq = _mm_load_ps(q); + + r = _mm_mul_ps(_mm_shuffle1_ps1(xp, 3), xq); + + x0 = _mm_xor_ps(_mm_shuffle1_ps1(xp, 0), _mm_set_ps(-0.f, 0.f, -0.f, 0.f)); + r = _mm_add_ps(r, _mm_mul_ps(x0, _mm_shuffle1_ps(xq, 0, 1, 2, 3))); + + x0 = _mm_xor_ps(_mm_shuffle1_ps1(xp, 1), _mm_set_ps(-0.f, -0.f, 0.f, 0.f)); + r = _mm_add_ps(r, _mm_mul_ps(x0, _mm_shuffle1_ps(xq, 1, 0, 3, 2))); + + x0 = _mm_xor_ps(_mm_shuffle1_ps1(xp, 2), _mm_set_ps(-0.f, 0.f, 0.f, -0.f)); + r = _mm_add_ps(r, _mm_mul_ps(x0, _mm_shuffle1_ps(xq, 2, 3, 0, 1))); + + _mm_store_ps(dest, r); +} + CGLM_INLINE void glm_quat_slerp_sse2(versor q, diff --git a/src/quat.c b/src/quat.c index 35ec890..b1cfe90 100644 --- a/src/quat.c +++ b/src/quat.c @@ -46,8 +46,8 @@ glmc_quat_dot(versor q, versor r) { CGLM_EXPORT void -glmc_quat_mulv(versor q1, versor q2, versor dest) { - glm_quat_mul(q1, q2, dest); +glmc_quat_mul(versor p, versor q, versor dest) { + glm_quat_mul(p, q, dest); } CGLM_EXPORT @@ -64,9 +64,6 @@ glmc_quat_mat3(versor q, mat3 dest) { CGLM_EXPORT void -glmc_quat_slerp(versor q, - versor r, - float t, - versor dest) { +glmc_quat_slerp(versor q, versor r, float t, versor dest) { glm_quat_slerp(q, r, t, dest); } diff --git a/test/src/test_common.c b/test/src/test_common.c index b824b37..bd6deaf 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -92,10 +92,18 @@ test_assert_vec3_eq(vec3 v1, vec3 v2) { } void -test_assert_quat_eq(versor v1, versor v2) { - assert_true(fabsf(v1[0] - v2[0]) <= 0.0009); /* rounding errors */ - assert_true(fabsf(v1[1] - v2[1]) <= 0.0009); - assert_true(fabsf(v1[2] - v2[2]) <= 0.0009); - assert_true(fabsf(v1[3] - v2[3]) <= 0.0009); +test_assert_quat_eq_abs(versor v1, versor v2) { + assert_true(fabsf(fabsf(v1[0]) - fabsf(v2[0])) <= 0.0009); /* rounding errors */ + assert_true(fabsf(fabsf(v1[1]) - fabsf(v2[1])) <= 0.0009); + assert_true(fabsf(fabsf(v1[2]) - fabsf(v2[2])) <= 0.0009); + assert_true(fabsf(fabsf(v1[3]) - fabsf(v2[3])) <= 0.0009); +} + +void +test_assert_quat_eq(versor v1, versor v2) { + assert_true(fabsf(v1[0] - v2[0]) <= 0.0000009); /* rounding errors */ + assert_true(fabsf(v1[1] - v2[1]) <= 0.0000009); + assert_true(fabsf(v1[2] - v2[2]) <= 0.0000009); + assert_true(fabsf(v1[3] - v2[3]) <= 0.0000009); } diff --git a/test/src/test_common.h b/test/src/test_common.h index 477e59d..c95405e 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -37,6 +37,9 @@ test_assert_vec3_eq(vec3 v1, vec3 v2); void test_assert_quat_eq(versor v1, versor v2); +void +test_assert_quat_eq_abs(versor v1, versor v2); + void test_rand_vec3(vec3 dest); diff --git a/test/src/test_quat.c b/test/src/test_quat.c index 36d2ef5..723dea1 100644 --- a/test/src/test_quat.c +++ b/test/src/test_quat.c @@ -7,10 +7,19 @@ #include "test_common.h" +CGLM_INLINE +void +test_quat_mul_raw(versor p, versor q, versor dest) { + dest[0] = p[3] * q[0] + p[0] * q[3] + p[1] * q[2] - p[2] * q[1]; + dest[1] = p[3] * q[1] - p[0] * q[2] + p[1] * q[3] + p[2] * q[0]; + dest[2] = p[3] * q[2] + p[0] * q[1] - p[1] * q[0] + p[2] * q[3]; + dest[3] = p[3] * q[3] - p[0] * q[0] - p[1] * q[1] - p[2] * q[2]; +} + void test_quat(void **state) { mat4 inRot, outRot; - versor inQuat, outQuat; + versor inQuat, outQuat, q3, q4; int i; for (i = 0; i < 1000; i++) { @@ -18,7 +27,12 @@ test_quat(void **state) { glmc_quat_mat4(inQuat, inRot); glmc_mat4_quat(inRot, outQuat); glmc_quat_mat4(outQuat, outRot); - test_assert_quat_eq(inQuat, outQuat); + test_assert_quat_eq_abs(inQuat, outQuat); test_assert_mat4_eq2(inRot, outRot, 0.000009); /* almost equal */ + + test_quat_mul_raw(inQuat, outQuat, q3); + glm_quat_mul_sse2(inQuat, outQuat, q4); + + test_assert_quat_eq(q3, q4); } } From 591c881376f5e4c99b459d5c17014b61ed1d79ca Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 10 Apr 2018 10:46:45 +0300 Subject: [PATCH 082/292] vec: extend flip sign to store result in another vector --- include/cglm/vec3.h | 14 ++++++++++++++ include/cglm/vec4.h | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 65fe0ba..13b4920 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -242,6 +242,20 @@ glm_vec_flipsign(vec3 v) { v[2] = -v[2]; } +/*! + * @brief flip sign of all vec3 members and store result in dest + * + * @param[in] v vector + * @param[out] dest vector + */ +CGLM_INLINE +void +glm_vec_flipsign_to(vec3 v, vec3 dest) { + dest[0] = -v[0]; + dest[1] = -v[1]; + dest[2] = -v[2]; +} + /*! * @brief make vector as inverse/opposite of itself * diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index adf5fb9..1c4ce13 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -268,6 +268,26 @@ glm_vec4_flipsign(vec4 v) { #endif } +/*! + * @brief flip sign of all vec4 members and store result in dest + * + * @param[in] v vector + * @param[out] dest vector + */ +CGLM_INLINE +void +glm_vec4_flipsign_to(vec4 v, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_xor_ps(_mm_load_ps(v), + _mm_set1_ps(-0.0f))); +#else + dest[0] = -v[0]; + dest[1] = -v[1]; + dest[2] = -v[2]; + dest[3] = -v[3]; +#endif +} + /*! * @brief make vector as inverse/opposite of itself * From 1fb82a1922b4ac8f6c0207d9a45b0a9d3de460df Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 10 Apr 2018 10:47:55 +0300 Subject: [PATCH 083/292] quat: use vector functions for available operations * provide quat_copy function --- include/cglm/quat.h | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index e1112d5..32367ac 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -133,6 +133,18 @@ glm_quatv(versor q, float angle, vec3 axis) { q[3] = c; } +/*! + * @brief copy quaternion to another one + * + * @param[in] q quaternion + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_quat_copy(versor q, versor dest) { + glm_vec4_copy(q, dest); +} + /*! * @brief returns norm (magnitude) of quaternion * @@ -185,8 +197,7 @@ glm_quat_dot(versor q1, versor q2) { CGLM_INLINE void glm_quat_conjugate(versor q, versor dest) { - glm_vec4_copy(q, dest); - glm_vec4_flipsign(dest); + glm_vec4_flipsign_to(q, dest); dest[3] = -dest[3]; } @@ -442,23 +453,16 @@ glm_quat_slerp(versor q, versor r, float t, versor dest) { cosTheta = glm_quat_dot(q, r); if (cosTheta < 0.0f) { - q[0] *= -1.0f; - q[1] *= -1.0f; - q[2] *= -1.0f; - q[3] *= -1.0f; - + glm_vec4_flipsign(q); cosTheta = -cosTheta; } if (fabs(cosTheta) >= 1.0f) { - dest[0] = q[0]; - dest[1] = q[1]; - dest[2] = q[2]; - dest[3] = q[3]; + glm_quat_copy(q, dest); return; } - sinTheta = sqrt(1.0f - cosTheta * cosTheta); + sinTheta = sqrtf(1.0f - cosTheta * cosTheta); c = 1.0f - t; From 416e2f4452f8d7245ca9ec98d8417ede35fdd965 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 10 Apr 2018 11:44:16 +0300 Subject: [PATCH 084/292] vec: lerp for vec3 and vec4 --- include/cglm/util.h | 15 +++++++++++++++ include/cglm/vec3.h | 22 ++++++++++++++++++++++ include/cglm/vec4.h | 22 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/include/cglm/util.h b/include/cglm/util.h index 85fc789..b272d44 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -143,4 +143,19 @@ glm_clamp(float val, float minVal, float maxVal) { return glm_min(glm_max(val, minVal), maxVal); } +/*! + * @brief linear interpolation between two number + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) clamped between 0 and 1 + */ +CGLM_INLINE +float +glm_lerp(float from, float to, float t) { + return from + glm_clamp(t, 0.0f, 1.0f) * (to - from); +} + #endif /* cglm_util_h */ diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 13b4920..cb94909 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -506,6 +506,28 @@ glm_vec_clamp(vec3 v, float minVal, float maxVal) { v[2] = glm_clamp(v[2], minVal, maxVal); } +/*! + * @brief linear interpolation between two vector + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) clamped between 0 and 1 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) { + vec3 s, v; + + /* from + s * (to - from) */ + glm_vec_broadcast(glm_clamp(t, 0.0f, 1.0f), s); + glm_vec_sub(to, from, v); + glm_vec_mulv(s, v, v); + glm_vec_add(from, v, dest); +} + /*! * @brief vec3 cross product * diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 1c4ce13..eaa4eaf 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -417,4 +417,26 @@ glm_vec4_clamp(vec4 v, float minVal, float maxVal) { v[3] = glm_clamp(v[3], minVal, maxVal); } +/*! + * @brief linear interpolation between two vector + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) clamped between 0 and 1 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) { + vec4 s, v; + + /* from + s * (to - from) */ + glm_vec4_broadcast(glm_clamp(t, 0.0f, 1.0f), s); + glm_vec4_sub(to, from, v); + glm_vec4_mulv(s, v, v); + glm_vec4_add(from, v, dest); +} + #endif /* cglm_vec4_h */ From 290bcf134c661df5d8409f49756dda1e3bad534c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 10 Apr 2018 12:38:54 +0300 Subject: [PATCH 085/292] quat: add lerp and improve slerp --- include/cglm/quat.h | 66 +++++++++++++++++++---------------- include/cglm/simd/sse2/quat.h | 52 --------------------------- 2 files changed, 35 insertions(+), 83 deletions(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 32367ac..f48d3b0 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -432,60 +432,64 @@ glm_quat_mat3(versor q, mat3 dest) { dest[0][2] = xz - wy; } +/*! + * @brief interpolates between two quaternions + * using linear interpolation (LERP) + * + * @param[in] from from + * @param[in] to to + * @param[in] t interpolant (amount) clamped between 0 and 1 + * @param[out] dest result quaternion + */ +CGLM_INLINE +void +glm_quat_lerp(versor from, versor to, float t, versor dest) { + glm_vec4_lerp(from, to, t, dest); +} + /*! * @brief interpolates between two quaternions * using spherical linear interpolation (SLERP) * - * @param[in] q from - * @param[in] r to + * @param[in] from from + * @param[in] to to * @param[in] t amout * @param[out] dest result quaternion */ CGLM_INLINE void -glm_quat_slerp(versor q, versor r, float t, versor dest) { +glm_quat_slerp(versor from, versor to, float t, versor dest) { + vec4 q1, q2; + float cosTheta, sinTheta, angle; - /* https://en.wikipedia.org/wiki/Slerp */ -#if defined( __SSE__ ) || defined( __SSE2__ ) - glm_quat_slerp_sse2(q, r, t, dest); -#else - float cosTheta, sinTheta, angle, a, b, c; + cosTheta = glm_quat_dot(from, to); + glm_quat_copy(from, q1); - cosTheta = glm_quat_dot(q, r); - if (cosTheta < 0.0f) { - glm_vec4_flipsign(q); - cosTheta = -cosTheta; + if (fabsf(cosTheta) >= 1.0f) { + glm_quat_copy(q1, dest); + return; } - if (fabs(cosTheta) >= 1.0f) { - glm_quat_copy(q, dest); - return; + if (cosTheta < 0.0f) { + glm_vec4_flipsign(q1); + cosTheta = -cosTheta; } sinTheta = sqrtf(1.0f - cosTheta * cosTheta); - c = 1.0f - t; - - /* LERP */ - /* TODO: FLT_EPSILON vs 0.001? */ - if (sinTheta < 0.001f) { - dest[0] = c * q[0] + t * r[0]; - dest[1] = c * q[1] + t * r[1]; - dest[2] = c * q[2] + t * r[2]; - dest[3] = c * q[3] + t * r[3]; + /* LERP to avoid zero division */ + if (fabsf(sinTheta) < 0.001f) { + glm_quat_lerp(from, to, t, dest); return; } /* SLERP */ angle = acosf(cosTheta); - a = sinf(c * angle); - b = sinf(t * angle); + glm_vec4_scale(q1, sinf((1.0f - t) * angle), q1); + glm_vec4_scale(to, sinf(t * angle), q2); - dest[0] = (q[0] * a + r[0] * b) / sinTheta; - dest[1] = (q[1] * a + r[1] * b) / sinTheta; - dest[2] = (q[2] * a + r[2] * b) / sinTheta; - dest[3] = (q[3] * a + r[3] * b) / sinTheta; -#endif + glm_vec4_add(q1, q2, q1); + glm_vec4_scale(q1, 1.0f / sinTheta, dest); } #endif /* cglm_quat_h */ diff --git a/include/cglm/simd/sse2/quat.h b/include/cglm/simd/sse2/quat.h index 59438f4..5dbf759 100644 --- a/include/cglm/simd/sse2/quat.h +++ b/include/cglm/simd/sse2/quat.h @@ -41,58 +41,6 @@ glm_quat_mul_sse2(versor p, versor q, versor dest) { _mm_store_ps(dest, r); } -CGLM_INLINE -void -glm_quat_slerp_sse2(versor q, - versor r, - float t, - versor dest) { - /* https://en.wikipedia.org/wiki/Slerp */ - float cosTheta, sinTheta, angle, a, b, c; - - __m128 xmm_q; - - xmm_q = _mm_load_ps(q); - - cosTheta = glm_vec4_dot(q, r); - if (cosTheta < 0.0f) { - _mm_store_ps(q, - _mm_xor_ps(xmm_q, - _mm_set1_ps(-0.f))) ; - - cosTheta = -cosTheta; - } - - if (cosTheta >= 1.0f) { - _mm_store_ps(dest, xmm_q); - return; - } - - sinTheta = sqrtf(1.0f - cosTheta * cosTheta); - - c = 1.0f - t; - - /* LERP */ - if (sinTheta < 0.001f) { - _mm_store_ps(dest, _mm_add_ps(_mm_mul_ps(_mm_set1_ps(c), - xmm_q), - _mm_mul_ps(_mm_set1_ps(t), - _mm_load_ps(r)))); - return; - } - - /* SLERP */ - angle = acosf(cosTheta); - a = sinf(c * angle); - b = sinf(t * angle); - - _mm_store_ps(dest, - _mm_div_ps(_mm_add_ps(_mm_mul_ps(_mm_set1_ps(a), - xmm_q), - _mm_mul_ps(_mm_set1_ps(b), - _mm_load_ps(r))), - _mm_set1_ps(sinTheta))); -} #endif #endif /* cglm_quat_simd_h */ From f0a51b35ad8d37d0c8aeccc4b1e6ed8b6008ab33 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 10 Apr 2018 15:41:09 +0300 Subject: [PATCH 086/292] quat: transposed/inverted version of quat2mat --- include/cglm/quat.h | 86 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index f48d3b0..ff3c38c 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -393,6 +393,53 @@ glm_quat_mat4(versor q, mat4 dest) { dest[3][3] = 1.0f; } +/*! + * @brief convert quaternion to mat4 (transposed) + * + * @param[in] q quaternion + * @param[out] dest result matrix as transposed + */ +CGLM_INLINE +void +glm_quat_mat4t(versor q, mat4 dest) { + float w, x, y, z, + xx, yy, zz, + xy, yz, xz, + wx, wy, wz, norm, s; + + norm = glm_quat_norm(q); + s = norm > 0.0f ? 2.0f / norm : 0.0f; + + x = q[0]; + y = q[1]; + z = q[2]; + w = q[3]; + + xx = s * x * x; xy = s * x * y; wx = s * w * x; + yy = s * y * y; yz = s * y * z; wy = s * w * y; + zz = s * z * z; xz = s * x * z; wz = s * w * z; + + dest[0][0] = 1.0f - yy - zz; + dest[1][1] = 1.0f - xx - zz; + dest[2][2] = 1.0f - xx - yy; + + dest[1][0] = xy + wz; + dest[2][1] = yz + wx; + dest[0][2] = xz + wy; + + dest[0][1] = xy - wz; + dest[1][2] = yz - wx; + dest[2][0] = xz - wy; + + dest[0][3] = 0.0f; + dest[1][3] = 0.0f; + dest[2][3] = 0.0f; + dest[3][0] = 0.0f; + dest[3][1] = 0.0f; + dest[3][2] = 0.0f; + dest[3][3] = 1.0f; +} + /*! * @brief convert quaternion to mat3 * @@ -432,6 +479,45 @@ glm_quat_mat3(versor q, mat3 dest) { dest[0][2] = xz - wy; } +/*! + * @brief convert quaternion to mat3 (transposed) + * + * @param[in] q quaternion + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_quat_mat3t(versor q, mat3 dest) { + float w, x, y, z, + xx, yy, zz, + xy, yz, xz, + wx, wy, wz, norm, s; + + norm = glm_quat_norm(q); + s = norm > 0.0f ? 2.0f / norm : 0.0f; + + x = q[0]; + y = q[1]; + z = q[2]; + w = q[3]; + + xx = s * x * x; xy = s * x * y; wx = s * w * x; + yy = s * y * y; yz = s * y * z; wy = s * w * y; + zz = s * z * z; xz = s * x * z; wz = s * w * z; + + dest[0][0] = 1.0f - yy - zz; + dest[1][1] = 1.0f - xx - zz; + dest[2][2] = 1.0f - xx - yy; + + dest[1][0] = xy + wz; + dest[2][1] = yz + wx; + dest[0][2] = xz + wy; + + dest[0][1] = xy - wz; + dest[1][2] = yz - wx; + dest[2][0] = xz - wy; +} + /*! * @brief interpolates between two quaternions * using linear interpolation (LERP) From 9466182c10f31882168240879a2c160913e86e54 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 10 Apr 2018 16:01:23 +0300 Subject: [PATCH 087/292] quat: create view wmatrix with quaternion helper --- include/cglm/quat.h | 27 +++++++++++++++++++++++++++ test/src/test_quat.c | 15 ++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index ff3c38c..fa760b7 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -39,6 +39,8 @@ #include "common.h" #include "vec4.h" +#include "mat4.h" +#include "mat3.h" #ifdef CGLM_SSE_FP # include "simd/sse2/quat.h" @@ -578,4 +580,29 @@ glm_quat_slerp(versor from, versor to, float t, versor dest) { glm_vec4_scale(q1, 1.0f / sinTheta, dest); } +CGLM_INLINE +void +glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); + +/*! + * @brief creates view matrix using quaternion as camera orientation + * + * @param[in] eye eye + * @param[in] ori orientation in world space as quaternion + * @param[out] dest view matrix + */ +CGLM_INLINE +void +glm_quat_look(vec3 eye, versor ori, mat4 dest) { + vec4 t; + + /* orientation */ + glm_quat_mat4t(ori, dest); + + /* translate */ + glm_vec4(eye, 1.0f, t); + glm_mat4_mulv(dest, t, t); + glm_vec_flipsign_to(t, dest[3]); +} + #endif /* cglm_quat_h */ diff --git a/test/src/test_quat.c b/test/src/test_quat.c index 723dea1..b5db10f 100644 --- a/test/src/test_quat.c +++ b/test/src/test_quat.c @@ -18,8 +18,9 @@ test_quat_mul_raw(versor p, versor q, versor dest) { void test_quat(void **state) { - mat4 inRot, outRot; + mat4 inRot, outRot, view1, view2; versor inQuat, outQuat, q3, q4; + vec3 eye; int i; for (i = 0; i < 1000; i++) { @@ -35,4 +36,16 @@ test_quat(void **state) { test_assert_quat_eq(q3, q4); } + + /* test lookat */ + test_rand_vec3(eye); + glm_quatv(q3, glm_rad(-90.0f), GLM_YUP); + + /* now X axis must be forward axis, Z must be right axis */ + glm_look(eye, GLM_XUP, GLM_YUP, view1); + + /* create view matrix with quaternion */ + glm_quat_look(eye, q3, view2); + + test_assert_mat4_eq2(view1, view2, 0.000009); } From 18ef0d7af187552eec187c5dfd38c74d5ebd1558 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 10 Apr 2018 16:52:52 +0300 Subject: [PATCH 088/292] quat: quaternion for look rotation ( from source point to dest point ) --- include/cglm/quat.h | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index fa760b7..fabce2d 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -605,4 +605,52 @@ glm_quat_look(vec3 eye, versor ori, mat4 dest) { glm_vec_flipsign_to(t, dest[3]); } +/*! + * @brief creates look rotation quaternion + * + * @param[in] fwd forward vector + * @param[in] up up vector + * @param[out] dest destination quaternion + */ +CGLM_INLINE +void +glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) { + vec3 axis; + float dot, angle; + + dot = glm_vec_dot(dir, fwd); + if (fabsf(dot + 1.0f) < 0.000001f) { + glm_quat_init(dest, up[0], up[1], up[2], CGLM_PI); + return; + } + + if (fabsf(dot - 1.0f) < 0.000001f) { + glm_quat_identity(dest); + return; + } + + angle = acosf(dot); + glm_cross(fwd, dir, axis); + glm_normalize(axis); + + glm_quatv(dest, angle, axis); +} + +/*! + * @brief creates look rotation quaternion using source and + * destination positions p suffix stands for position + * + * @param[in] from source point + * @param[in] to destination point + * @param[in] up up vector + * @param[out] dest destination quaternion + */ +CGLM_INLINE +void +glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { + vec3 dir; + glm_vec_sub(to, from, dir); + glm_quat_for(dir, fwd, up, dest); +} + #endif /* cglm_quat_h */ From 4c79fee5d354ca12e18f2c31c6c2afaca20c7cb8 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 10 Apr 2018 17:16:31 +0300 Subject: [PATCH 089/292] quat: additional tests for angle, axis, mul (hamilton product) --- test/src/test_quat.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/test/src/test_quat.c b/test/src/test_quat.c index b5db10f..8f3909c 100644 --- a/test/src/test_quat.c +++ b/test/src/test_quat.c @@ -18,11 +18,12 @@ test_quat_mul_raw(versor p, versor q, versor dest) { void test_quat(void **state) { - mat4 inRot, outRot, view1, view2; - versor inQuat, outQuat, q3, q4; - vec3 eye; + mat4 inRot, outRot, view1, view2, rot1, rot2; + versor inQuat, outQuat, q3, q4, q5; + vec3 eye, axis; int i; + /* 1. test quat to mat and mat to quat */ for (i = 0; i < 1000; i++) { test_rand_quat(inQuat); glmc_quat_mat4(inQuat, inRot); @@ -37,7 +38,7 @@ test_quat(void **state) { test_assert_quat_eq(q3, q4); } - /* test lookat */ + /* 2. test lookat */ test_rand_vec3(eye); glm_quatv(q3, glm_rad(-90.0f), GLM_YUP); @@ -48,4 +49,32 @@ test_quat(void **state) { glm_quat_look(eye, q3, view2); test_assert_mat4_eq2(view1, view2, 0.000009); + + /* 5. test quaternion rotation matrix result */ + test_rand_quat(q3); + glm_quat_mat4(q3, rot1); + + /* 5.1 test axis and angle of quat */ + glm_quat_axis(q3, axis); + glm_rotate_make(rot2, glm_quat_angle(q3), axis); + + test_assert_mat4_eq2(rot1, rot2, 0.000009); + + /* 6. test quaternion multiplication, first rotation + second = final */ + test_rand_quat(q3); + test_rand_quat(q4); + + glm_quat_mul(q3, q4, q5); + + glm_quat_axis(q3, axis); + glm_rotate_make(rot1, glm_quat_angle(q3), axis); + + glm_quat_axis(q4, axis); + glm_rotate(rot1, glm_quat_angle(q4), axis); + + /* rot2 is combine of two rotation now test with quaternion result */ + glm_quat_mat4(q5, rot2); + + /* result must be same (almost) */ + test_assert_mat4_eq2(rot1, rot2, 0.000009); } From 5dec68823c850e59b4261d03ff7433045d4458f7 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 10 Apr 2018 17:41:25 +0300 Subject: [PATCH 090/292] add additional tests and comments to quat tests --- test/src/test_quat.c | 72 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/test/src/test_quat.c b/test/src/test_quat.c index 8f3909c..1c1502d 100644 --- a/test/src/test_quat.c +++ b/test/src/test_quat.c @@ -20,25 +20,34 @@ void test_quat(void **state) { mat4 inRot, outRot, view1, view2, rot1, rot2; versor inQuat, outQuat, q3, q4, q5; - vec3 eye, axis; + vec3 eye, axis, imag; int i; + /* 0. test identiy quat */ + glm_quat_identity(q4); + assert_true(glm_quat_real(q4) == cosf(glm_rad(0.0f) * 0.5f)); + /* 1. test quat to mat and mat to quat */ for (i = 0; i < 1000; i++) { test_rand_quat(inQuat); + glmc_quat_mat4(inQuat, inRot); glmc_mat4_quat(inRot, outQuat); glmc_quat_mat4(outQuat, outRot); + + /* 2. test first quat and generated one equality */ test_assert_quat_eq_abs(inQuat, outQuat); + + /* 3. test first rot and second rotation */ test_assert_mat4_eq2(inRot, outRot, 0.000009); /* almost equal */ + /* 4. test SSE mul and raw mul */ test_quat_mul_raw(inQuat, outQuat, q3); glm_quat_mul_sse2(inQuat, outQuat, q4); - test_assert_quat_eq(q3, q4); } - /* 2. test lookat */ + /* 5. test lookat */ test_rand_vec3(eye); glm_quatv(q3, glm_rad(-90.0f), GLM_YUP); @@ -50,17 +59,19 @@ test_quat(void **state) { test_assert_mat4_eq2(view1, view2, 0.000009); - /* 5. test quaternion rotation matrix result */ + /* 6. test quaternion rotation matrix result */ test_rand_quat(q3); glm_quat_mat4(q3, rot1); - /* 5.1 test axis and angle of quat */ + /* 6.1 test axis and angle of quat */ glm_quat_axis(q3, axis); glm_rotate_make(rot2, glm_quat_angle(q3), axis); test_assert_mat4_eq2(rot1, rot2, 0.000009); - /* 6. test quaternion multiplication, first rotation + second = final */ + /* 7. test quaternion multiplication (hamilton product), + final rotation = first rotation + second = quat1 * quat2 + */ test_rand_quat(q3); test_rand_quat(q4); @@ -77,4 +88,53 @@ test_quat(void **state) { /* result must be same (almost) */ test_assert_mat4_eq2(rot1, rot2, 0.000009); + + /* 8. test quaternion for look rotation */ + + /* 8.1 same direction */ + /* look at from 0, 0, 1 to zero, direction = 0, 0, -1 */ + glm_quat_for((vec3){0, 0, -1}, (vec3){0, 0, -1}, GLM_YUP, q3); + + /* result must be identity */ + glm_quat_identity(q4); + test_assert_quat_eq(q3, q4); + + /* look at from 0, 0, 1 to zero, direction = 0, 0, -1 */ + glm_quat_forp(GLM_ZUP, GLM_VEC3_ZERO, (vec3){0, 0, -1}, GLM_YUP, q3); + + /* result must be identity */ + glm_quat_identity(q4); + test_assert_quat_eq(q3, q4); + + /* 8.2 perpendicular */ + glm_quat_for(GLM_XUP, (vec3){0, 0, -1}, GLM_YUP, q3); + + /* result must be -90 */ + glm_quatv(q4, glm_rad(-90.0f), GLM_YUP); + test_assert_quat_eq(q3, q4); + + /* 9. test imag, real */ + + /* 9.1 real */ + assert_true(glm_quat_real(q4) == cosf(glm_rad(-90.0f) * 0.5f)); + + /* 9.1 imag */ + glm_quat_imag(q4, imag); + + /* axis = Y_UP * sinf(angle * 0.5), YUP = 0, 1, 0 */ + axis[0] = 0.0f; + axis[1] = sinf(glm_rad(-90.0f) * 0.5f) * 1.0f; + axis[2] = 0.0f; + + assert_true(glm_vec_eqv_eps(imag, axis)); + + /* 9.2 axis */ + glm_quat_axis(q4, axis); + imag[0] = 0.0f; + imag[1] = -1.0f; + imag[2] = 0.0f; + + assert_true(glm_vec_eqv_eps(imag, axis)); + + /* TODO: add tests for slerp, lerp */ } From 010dcc9837b2ebf5a9b0c4272ac87e5c307bd610 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 11 Apr 2018 00:17:41 +0300 Subject: [PATCH 091/292] optimize normalize quaternion with SIMD * provide _to version for storing into another quat --- include/cglm/quat.h | 48 ++++++++++++++++++++++++++++++-------- include/cglm/simd/intrin.h | 10 ++++++++ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index fabce2d..970b7f6 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -158,6 +158,43 @@ glm_quat_norm(versor q) { return glm_vec4_norm(q); } +/*! + * @brief normalize quaternion and store result in dest + * + * @param[in] q quaternion to normalze + * @param[out] dest destination quaternion + */ +CGLM_INLINE +void +glm_quat_normalize_to(versor q, versor dest) { +#if defined( __SSE2__ ) || defined( __SSE2__ ) + __m128 xdot, x0; + float dot; + + x0 = _mm_load_ps(q); + xdot = glm_simd_dot(x0, x0); + dot = _mm_cvtss_f32(xdot); + + if (dot <= 0.0f) { + glm_quat_identity(dest); + return; + } + + _mm_store_ps(dest, _mm_div_ps(x0, _mm_sqrt_ps(xdot))); +#else + float dot; + + dot = glm_vec4_norm2(q); + + if (dot <= 0.0f) { + glm_quat_identity(q); + return; + } + + glm_vec4_scale(q, 1.0f / sqrtf(dot), dest); +#endif +} + /*! * @brief normalize quaternion * @@ -166,16 +203,7 @@ glm_quat_norm(versor q) { CGLM_INLINE void glm_quat_normalize(versor q) { - float sum; - - sum = glm_vec4_norm2(q); - - if (sum <= 0.0f) { - glm_quat_identity(q); - return; - } - - glm_vec4_scale(q, 1.0f / sqrtf(sum), q); + glm_quat_normalize_to(q, q); } /*! diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index c0f2e53..4c27d90 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -30,6 +30,16 @@ # define _mm_shuffle2_ps(a, b, z0, y0, x0, w0, z1, y1, x1, w1) \ _mm_shuffle1_ps(_mm_shuffle_ps(a, b, _MM_SHUFFLE(z0, y0, x0, w0)), \ z1, y1, x1, w1) + +CGLM_INLINE +__m128 +glm_simd_dot(__m128 a, __m128 b) { + __m128 x0; + x0 = _mm_mul_ps(a, b); + x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 3, 2)); + return _mm_add_ps(x0, _mm_shuffle1_ps(x0, 0, 1, 0, 1)); +} + #endif /* x86, x64 */ From b1fa7ff597e8610d4b6e400dac0dfc28193bb021 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 11 Apr 2018 00:36:39 +0300 Subject: [PATCH 092/292] normalize axis quaternion axis-angle constructor --- include/cglm/quat.h | 59 +++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 970b7f6..effebae 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -89,6 +89,31 @@ glm_quat_init(versor q, float x, float y, float z, float w) { q[3] = w; } +/*! + * @brief creates NEW quaternion with axis vector + * + * @param[out] q quaternion + * @param[in] angle angle (radians) + * @param[in] axis axis + */ +CGLM_INLINE +void +glm_quatv(versor q, float angle, vec3 axis) { + vec3 k; + float a, c, s; + + a = angle * 0.5f; + c = cosf(a); + s = sinf(a); + + glm_normalize_to(axis, k); + + q[0] = s * k[0]; + q[1] = s * k[1]; + q[2] = s * k[2]; + q[3] = c; +} + /*! * @brief creates NEW quaternion with individual axis components * @@ -101,38 +126,8 @@ glm_quat_init(versor q, float x, float y, float z, float w) { CGLM_INLINE void glm_quat(versor q, float angle, float x, float y, float z) { - float a, c, s; - - a = angle * 0.5f; - c = cosf(a); - s = sinf(a); - - q[0] = s * x; - q[1] = s * y; - q[2] = s * z; - q[3] = c; -} - -/*! - * @brief creates NEW quaternion with axis vector - * - * @param[out] q quaternion - * @param[in] angle angle (radians) - * @param[in] axis axis - */ -CGLM_INLINE -void -glm_quatv(versor q, float angle, vec3 axis) { - float a, c, s; - - a = angle * 0.5f; - c = cosf(a); - s = sinf(a); - - q[0] = s * axis[0]; - q[1] = s * axis[1]; - q[2] = s * axis[2]; - q[3] = c; + vec3 axis = {x, y, z}; + glm_quatv(q, angle, axis); } /*! From d447876c70cc0cc4b9ab54595332a0e42d1a887a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 11 Apr 2018 00:46:23 +0300 Subject: [PATCH 093/292] improve glm_vec_rotate --- include/cglm/vec3.h | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index cb94909..1cbf508 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -339,10 +339,6 @@ glm_vec_angle(vec3 v1, vec3 v2) { return acosf(glm_vec_dot(v1, v2) * norm); } -CGLM_INLINE -void -glm_quatv(versor q, float angle, vec3 axis); - /*! * @brief rotate vec3 around axis by angle using Rodrigues' rotation formula * @@ -353,31 +349,26 @@ glm_quatv(versor q, float angle, vec3 axis); CGLM_INLINE void glm_vec_rotate(vec3 v, float angle, vec3 axis) { - versor q; - vec3 v1, v2, v3; + vec3 v1, v2, k; float c, s; c = cosf(angle); s = sinf(angle); + glm_vec_normalize_to(axis, k); + /* Right Hand, Rodrigues' rotation formula: v = v*cos(t) + (kxv)sin(t) + k*(k.v)(1 - cos(t)) */ - - /* quaternion */ - glm_quatv(q, angle, v); - glm_vec_scale(v, c, v1); - glm_vec_cross(axis, v, v2); + glm_vec_cross(k, v, v2); glm_vec_scale(v2, s, v2); - glm_vec_scale(axis, - glm_vec_dot(axis, v) * (1.0f - c), - v3); - glm_vec_add(v1, v2, v1); - glm_vec_add(v1, v3, v); + + glm_vec_scale(k, glm_vec_dot(k, v) * (1.0f - c), v2); + glm_vec_add(v1, v2, v); } /*! From 80d255e6d9cce5b472b2b2f95ed4ef3be594e8c0 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 11 Apr 2018 00:47:11 +0300 Subject: [PATCH 094/292] rotate vector using quaternion --- CREDITS | 4 ++++ include/cglm/quat.h | 30 +++++++++++++++++++++++++++++- test/src/test_common.c | 14 +++++++------- test/src/test_quat.c | 22 ++++++++++++++++++++-- 4 files changed, 60 insertions(+), 10 deletions(-) diff --git a/CREDITS b/CREDITS index 66604eb..44e55a8 100644 --- a/CREDITS +++ b/CREDITS @@ -46,3 +46,7 @@ http://old.cescg.org/CESCG-2002/DSykoraJJelinek/ 7. Quaternions Initial mat4_quat is borrowed from Apple's simd library + + +8. Vector Rotation using Quaternion +https://gamedev.stackexchange.com/questions/28395/rotating-vector3-by-a-quaternion diff --git a/include/cglm/quat.h b/include/cglm/quat.h index effebae..664a069 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -168,7 +168,7 @@ glm_quat_normalize_to(versor q, versor dest) { x0 = _mm_load_ps(q); xdot = glm_simd_dot(x0, x0); - dot = _mm_cvtss_f32(xdot); + dot = _mm_cvtss_f32(xdot); if (dot <= 0.0f) { glm_quat_identity(dest); @@ -676,4 +676,32 @@ glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { glm_quat_for(dir, fwd, up, dest); } +/*! + * @brief rotate existing transform matrix using quaternion + * + * @param[in] q quaternion + * @param[in] v vector to rotate + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_quat_rotatev(versor q, vec3 v, vec3 dest) { + versor p; + vec3 u, v1, v2; + float s; + + glm_quat_normalize_to(q, p); + glm_quat_imag(p, u); + s = glm_quat_real(p); + + glm_vec_scale(u, 2.0f * glm_vec_dot(u, v), v1); + glm_vec_scale(v, s * s - glm_vec_dot(u, u), v2); + glm_vec_add(v1, v2, v1); + + glm_vec_cross(u, v, v2); + glm_vec_scale(v2, 2.0f * s, v2); + + glm_vec_add(v1, v2, dest); +} + #endif /* cglm_quat_h */ diff --git a/test/src/test_common.c b/test/src/test_common.c index bd6deaf..514c006 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -86,9 +86,9 @@ test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps) { void test_assert_vec3_eq(vec3 v1, vec3 v2) { - assert_true(fabsf(v1[0] - v2[0]) <= 0.0000009); /* rounding errors */ - assert_true(fabsf(v1[1] - v2[1]) <= 0.0000009); - assert_true(fabsf(v1[2] - v2[2]) <= 0.0000009); + assert_true(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ + assert_true(fabsf(v1[1] - v2[1]) <= 0.000009); + assert_true(fabsf(v1[2] - v2[2]) <= 0.000009); } void @@ -101,9 +101,9 @@ test_assert_quat_eq_abs(versor v1, versor v2) { void test_assert_quat_eq(versor v1, versor v2) { - assert_true(fabsf(v1[0] - v2[0]) <= 0.0000009); /* rounding errors */ - assert_true(fabsf(v1[1] - v2[1]) <= 0.0000009); - assert_true(fabsf(v1[2] - v2[2]) <= 0.0000009); - assert_true(fabsf(v1[3] - v2[3]) <= 0.0000009); + assert_true(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ + assert_true(fabsf(v1[1] - v2[1]) <= 0.000009); + assert_true(fabsf(v1[2] - v2[2]) <= 0.000009); + assert_true(fabsf(v1[3] - v2[3]) <= 0.000009); } diff --git a/test/src/test_quat.c b/test/src/test_quat.c index 1c1502d..43dbdb2 100644 --- a/test/src/test_quat.c +++ b/test/src/test_quat.c @@ -20,7 +20,7 @@ void test_quat(void **state) { mat4 inRot, outRot, view1, view2, rot1, rot2; versor inQuat, outQuat, q3, q4, q5; - vec3 eye, axis, imag; + vec3 eye, axis, imag, v1, v2; int i; /* 0. test identiy quat */ @@ -134,7 +134,25 @@ test_quat(void **state) { imag[1] = -1.0f; imag[2] = 0.0f; - assert_true(glm_vec_eqv_eps(imag, axis)); + test_assert_vec3_eq(imag, axis); + + /* 10. test rotate vector using quat */ + /* (0,0,-1) around (1,0,0) must give (0,1,0) */ + v1[0] = 0.0f; v1[1] = 0.0f; v1[2] = -1.0f; + v2[0] = 0.0f; v2[1] = 0.0f; v2[2] = -1.0f; + + glm_vec_rotate(v1, glm_rad(90.0f), (vec3){1.0f, 0.0f, 0.0f}); + glm_quatv(q3, glm_rad(90.0f), (vec3){1.0f, 0.0f, 0.0f}); + + glm_vec4_scale(q3, 1.5, q3); + glm_quat_rotatev(q3, v2, v2); + + /* result must be : (0,1,0) */ + assert_true(fabsf(v1[0]) <= 0.00009f + && fabsf(v1[1] - 1.0f) <= 0.00009f + && fabsf(v1[2]) <= 0.00009f); + + test_assert_vec3_eq(v1, v2); /* TODO: add tests for slerp, lerp */ } From fdea13507bbf63dd24d93294aee7a1dc21b9249e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 11 Apr 2018 10:49:53 +0300 Subject: [PATCH 095/292] replace mat4_mulq with glm_quat_rotate * glm_quat_rotate is better name to rotate transform matrix using quaternion. * we may use mat4_mulq in the future for another purpose e.g. left multiplication quat with matrix --- include/cglm/call/mat4.h | 4 ---- include/cglm/mat4.h | 15 -------------- include/cglm/quat.h | 45 ++++++++++++++++++++++++++++++++++------ src/mat4.c | 6 ------ test/src/test_quat.c | 30 +++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 31 deletions(-) diff --git a/include/cglm/call/mat4.h b/include/cglm/call/mat4.h index 35b9f66..c9ad796 100644 --- a/include/cglm/call/mat4.h +++ b/include/cglm/call/mat4.h @@ -53,10 +53,6 @@ CGLM_EXPORT void glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest); -CGLM_EXPORT -void -glmc_mat4_mulq(mat4 m, versor q, mat4 dest); - CGLM_EXPORT void glmc_mat4_quat(mat4 m, versor dest); diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index fd7a340..27ebe05 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -319,21 +319,6 @@ glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) { #endif } -/*! - * @brief multiply mat4 with quaternion and store in dest vector - * - * @param[in] m left matrix - * @param[in] q quaternion as right matrix - * @param[out] dest destination matrix - */ -CGLM_INLINE -void -glm_mat4_mulq(mat4 m, versor q, mat4 dest) { - mat4 rot; - glm_quat_mat4(q, rot); - glm_mat4_mul(m, rot, dest); -} - /*! * @brief convert mat4's rotation part to quaternion * diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 664a069..95a768e 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -15,8 +15,10 @@ CGLM_INLINE void glm_quat_init(versor q, float x, float y, float z, float w); CGLM_INLINE void glm_quat(versor q, float angle, float x, float y, float z); CGLM_INLINE void glm_quatv(versor q, float angle, vec3 axis); + CGLM_INLINE void glm_quat_copy(versor q, versor dest); CGLM_INLINE float glm_quat_norm(versor q); CGLM_INLINE void glm_quat_normalize(versor q); + CGLM_INLINE void glm_quat_normalize_to(versor q, versor dest); CGLM_INLINE float glm_quat_dot(versor q1, versor q2); CGLM_INLINE void glm_quat_conjugate(versor q, versor dest); CGLM_INLINE void glm_quat_inv(versor q, versor dest); @@ -30,8 +32,20 @@ CGLM_INLINE void glm_quat_axis(versor q, versor dest); CGLM_INLINE void glm_quat_mul(versor p, versor q, versor dest); CGLM_INLINE void glm_quat_mat4(versor q, mat4 dest); - CGLM_INLINE void glm_quat_mat3(versor q, mat3 dest) + CGLM_INLINE void glm_quat_mat4t(versor q, mat4 dest); + CGLM_INLINE void glm_quat_mat3(versor q, mat3 dest); + CGLM_INLINE void glm_quat_mat3t(versor q, mat3 dest); + CGLM_INLINE void glm_quat_lerp(versor from, versor to, float t, versor dest); CGLM_INLINE void glm_quat_slerp(versor q, versor r, float t, versor dest); + CGLM_INLINE void glm_quat_look(vec3 eye, versor ori, mat4 dest); + CGLM_INLINE void glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest); + CGLM_INLINE void glm_quat_forp(vec3 from, + vec3 to, + vec3 fwd, + vec3 up, + versor dest); + CGLM_INLINE void glm_quat_rotatev(versor q, vec3 v, vec3 dest); + CGLM_INLINE void glm_quat_rotate(mat4 m, versor q, mat4 dest); */ #ifndef cglm_quat_h @@ -46,6 +60,14 @@ # include "simd/sse2/quat.h" #endif +CGLM_INLINE +void +glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); + +CGLM_INLINE +void +glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest); + /* * IMPORTANT: * ---------------------------------------------------------------------------- @@ -603,10 +625,6 @@ glm_quat_slerp(versor from, versor to, float t, versor dest) { glm_vec4_scale(q1, 1.0f / sinTheta, dest); } -CGLM_INLINE -void -glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); - /*! * @brief creates view matrix using quaternion as camera orientation * @@ -677,7 +695,7 @@ glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { } /*! - * @brief rotate existing transform matrix using quaternion + * @brief rotate vector using using quaternion * * @param[in] q quaternion * @param[in] v vector to rotate @@ -704,4 +722,19 @@ glm_quat_rotatev(versor q, vec3 v, vec3 dest) { glm_vec_add(v1, v2, dest); } +/*! + * @brief rotate existing transform matrix using quaternion + * + * @param[in] m existing transform matrix + * @param[in] q quaternion + * @param[out] dest destination matrix + */ +CGLM_INLINE +void +glm_quat_rotate(mat4 m, versor q, mat4 dest) { + mat4 rot; + glm_quat_mat4(q, rot); + glm_mat4_mul(m, rot, dest); +} + #endif /* cglm_quat_h */ diff --git a/src/mat4.c b/src/mat4.c index 8b2a2d0..9407684 100644 --- a/src/mat4.c +++ b/src/mat4.c @@ -62,12 +62,6 @@ glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest) { glm_mat4_mulv(m, v, dest); } -CGLM_EXPORT -void -glmc_mat4_mulq(mat4 m, versor q, mat4 dest) { - glm_mat4_mulq(m, q, dest); -} - CGLM_EXPORT void glmc_mat4_quat(mat4 m, versor dest) { diff --git a/test/src/test_quat.c b/test/src/test_quat.c index 43dbdb2..fec8dae 100644 --- a/test/src/test_quat.c +++ b/test/src/test_quat.c @@ -154,5 +154,35 @@ test_quat(void **state) { test_assert_vec3_eq(v1, v2); + /* 11. test rotate transform */ + glm_translate_make(rot1, (vec3){-10.0, 45.0f, 8.0f}); + glm_rotate(rot1, glm_rad(-90), GLM_ZUP); + + glm_quatv(q3, glm_rad(-90.0f), GLM_ZUP); + glm_translate_make(rot2, (vec3){-10.0, 45.0f, 8.0f}); + glm_quat_rotate(rot2, q3, rot2); + + /* result must be same (almost) */ + test_assert_mat4_eq2(rot1, rot2, 0.000009); + + glm_rotate_make(rot1, glm_rad(-90), GLM_ZUP); + glm_translate(rot1, (vec3){-10.0, 45.0f, 8.0f}); + + glm_quatv(q3, glm_rad(-90.0f), GLM_ZUP); + glm_mat4_identity(rot2); + glm_quat_rotate(rot2, q3, rot2); + glm_translate(rot2, (vec3){-10.0, 45.0f, 8.0f}); + + /* result must be same (almost) */ + test_assert_mat4_eq2(rot1, rot2, 0.000009); + + /* reverse */ + glm_rotate_make(rot1, glm_rad(-90), GLM_ZUP); + glm_quatv(q3, glm_rad(90.0f), GLM_ZUP); + glm_quat_rotate(rot1, q3, rot1); + + /* result must be identity */ + test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009); + /* TODO: add tests for slerp, lerp */ } From 51278b26b4ea5c9c8734777c7709da5b9bc65ef8 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 11 Apr 2018 11:19:13 +0300 Subject: [PATCH 096/292] quat: update call versions of quaternion --- include/cglm/call/quat.h | 88 +++++++++++++++++++++++- include/cglm/quat.h | 4 +- src/quat.c | 141 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 222 insertions(+), 11 deletions(-) diff --git a/include/cglm/call/quat.h b/include/cglm/call/quat.h index ee45f0c..d250f52 100644 --- a/include/cglm/call/quat.h +++ b/include/cglm/call/quat.h @@ -17,25 +17,77 @@ CGLM_EXPORT void glmc_quat_identity(versor q); +CGLM_EXPORT +void +glmc_quat_init(versor q, float x, float y, float z, float w); + CGLM_EXPORT void glmc_quat(versor q, float angle, float x, float y, float z); CGLM_EXPORT void -glmc_quatv(versor q, float angle, vec3 v); +glmc_quatv(versor q, float angle, vec3 axis); + +CGLM_EXPORT +void +glmc_quat_copy(versor q, versor dest); CGLM_EXPORT float glmc_quat_norm(versor q); +CGLM_EXPORT +void +glmc_quat_normalize_to(versor q, versor dest); + CGLM_EXPORT void glmc_quat_normalize(versor q); CGLM_EXPORT float -glmc_quat_dot(versor q, versor r); +glmc_quat_dot(versor p, versor q); + +CGLM_EXPORT +void +glmc_quat_conjugate(versor q, versor dest); + +CGLM_EXPORT +void +glmc_quat_inv(versor q, versor dest); + +CGLM_EXPORT +void +glmc_quat_add(versor p, versor q, versor dest); + +CGLM_EXPORT +void +glmc_quat_sub(versor p, versor q, versor dest); + +CGLM_EXPORT +float +glmc_quat_real(versor q); + +CGLM_EXPORT +void +glmc_quat_imag(versor q, vec3 dest); + +CGLM_EXPORT +void +glmc_quat_imagn(versor q, vec3 dest); + +CGLM_EXPORT +float +glmc_quat_imaglen(versor q); + +CGLM_EXPORT +float +glmc_quat_angle(versor q); + +CGLM_EXPORT +void +glmc_quat_axis(versor q, versor dest); CGLM_EXPORT void @@ -45,14 +97,46 @@ CGLM_EXPORT void glmc_quat_mat4(versor q, mat4 dest); +CGLM_EXPORT +void +glmc_quat_mat4t(versor q, mat4 dest); + CGLM_EXPORT void glmc_quat_mat3(versor q, mat3 dest); +CGLM_EXPORT +void +glmc_quat_mat3t(versor q, mat3 dest); + +CGLM_EXPORT +void +glmc_quat_lerp(versor from, versor to, float t, versor dest); + CGLM_EXPORT void glmc_quat_slerp(versor q, versor r, float t, versor dest); +CGLM_EXPORT +void +glmc_quat_look(vec3 eye, versor ori, mat4 dest); + +CGLM_EXPORT +void +glmc_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest); + +CGLM_EXPORT +void +glmc_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest); + +CGLM_EXPORT +void +glmc_quat_rotatev(versor from, vec3 to, vec3 dest); + +CGLM_EXPORT +void +glmc_quat_rotate(mat4 m, versor q, mat4 dest); + #ifdef __cplusplus } #endif diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 95a768e..c9927bb 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -231,8 +231,8 @@ glm_quat_normalize(versor q) { */ CGLM_INLINE float -glm_quat_dot(versor q1, versor q2) { - return glm_vec4_dot(q1, q2); +glm_quat_dot(versor p, versor q) { + return glm_vec4_dot(p, q); } /*! diff --git a/src/quat.c b/src/quat.c index b1cfe90..8a9a463 100644 --- a/src/quat.c +++ b/src/quat.c @@ -8,12 +8,19 @@ #include "../include/cglm/cglm.h" #include "../include/cglm/call.h" + CGLM_EXPORT void glmc_quat_identity(versor q) { glm_quat_identity(q); } +CGLM_EXPORT +void +glmc_quat_init(versor q, float x, float y, float z, float w) { + glm_quat_init(q, x, y, z, w); +} + CGLM_EXPORT void glmc_quat(versor q, float angle, float x, float y, float z) { @@ -22,8 +29,14 @@ glmc_quat(versor q, float angle, float x, float y, float z) { CGLM_EXPORT void -glmc_quatv(versor q, float angle, vec3 v) { - glm_quatv(q, angle, v); +glmc_quatv(versor q, float angle, vec3 axis) { + glm_quatv(q, angle, axis); +} + +CGLM_EXPORT +void +glmc_quat_copy(versor q, versor dest) { + glm_quat_copy(q, dest); } CGLM_EXPORT @@ -32,16 +45,82 @@ glmc_quat_norm(versor q) { return glm_quat_norm(q); } +CGLM_EXPORT +void +glmc_quat_normalize_to(versor q, versor dest) { + glm_quat_normalize_to(q, dest); +} + CGLM_EXPORT void glmc_quat_normalize(versor q) { - glm_quat_normalize(q); + glm_quat_norm(q); } CGLM_EXPORT float -glmc_quat_dot(versor q, versor r) { - return glm_quat_dot(q, r); +glmc_quat_dot(versor p, versor q) { + return glm_quat_dot(p, q); +} + +CGLM_EXPORT +void +glmc_quat_conjugate(versor q, versor dest) { + glm_quat_conjugate(q, dest); +} + +CGLM_EXPORT +void +glmc_quat_inv(versor q, versor dest) { + glm_quat_inv(q, dest); +} + +CGLM_EXPORT +void +glmc_quat_add(versor p, versor q, versor dest) { + glm_quat_add(p, q, dest); +} + +CGLM_EXPORT +void +glmc_quat_sub(versor p, versor q, versor dest) { + glm_quat_sub(p, q, dest); +} + +CGLM_EXPORT +float +glmc_quat_real(versor q) { + return glm_quat_real(q); +} + +CGLM_EXPORT +void +glmc_quat_imag(versor q, vec3 dest) { + glm_quat_imag(q, dest); +} + +CGLM_EXPORT +void +glmc_quat_imagn(versor q, vec3 dest) { + glm_quat_imagn(q, dest); +} + +CGLM_EXPORT +float +glmc_quat_imaglen(versor q) { + return glm_quat_imaglen(q); +} + +CGLM_EXPORT +float +glmc_quat_angle(versor q) { + return glm_quat_angle(q); +} + +CGLM_EXPORT +void +glmc_quat_axis(versor q, versor dest) { + glm_quat_axis(q, dest); } CGLM_EXPORT @@ -56,6 +135,12 @@ glmc_quat_mat4(versor q, mat4 dest) { glm_quat_mat4(q, dest); } +CGLM_EXPORT +void +glmc_quat_mat4t(versor q, mat4 dest) { + glm_quat_mat4t(q, dest); +} + CGLM_EXPORT void glmc_quat_mat3(versor q, mat3 dest) { @@ -64,6 +149,48 @@ glmc_quat_mat3(versor q, mat3 dest) { CGLM_EXPORT void -glmc_quat_slerp(versor q, versor r, float t, versor dest) { - glm_quat_slerp(q, r, t, dest); +glmc_quat_mat3t(versor q, mat3 dest) { + glm_quat_mat3t(q, dest); +} + +CGLM_EXPORT +void +glmc_quat_lerp(versor from, versor to, float t, versor dest) { + glm_quat_lerp(from, to, t, dest); +} + +CGLM_EXPORT +void +glmc_quat_slerp(versor from, versor to, float t, versor dest) { + glm_quat_slerp(from, to, t, dest); +} + +CGLM_EXPORT +void +glmc_quat_look(vec3 eye, versor ori, mat4 dest) { + glm_quat_look(eye, ori, dest); +} + +CGLM_EXPORT +void +glmc_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) { + glm_quat_for(dir, fwd, up, dest); +} + +CGLM_EXPORT +void +glmc_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { + glm_quat_forp(from, to, fwd, up, dest); +} + +CGLM_EXPORT +void +glmc_quat_rotatev(versor q, vec3 v, vec3 dest) { + glm_quat_rotatev(q, v, dest); +} + +CGLM_EXPORT +void +glmc_quat_rotate(mat4 m, versor q, mat4 dest) { + glm_quat_rotate(m, q, dest); } From de5585013657d91b4268a362eade2c73f7b9d298 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 11 Apr 2018 12:31:29 +0300 Subject: [PATCH 097/292] add call version of vector extensions --- include/cglm/call/vec3.h | 74 ++++++++++++++++++++++++++ include/cglm/call/vec4.h | 70 +++++++++++++++++++++++++ include/cglm/vec3-ext.h | 2 +- src/vec3.c | 110 +++++++++++++++++++++++++++++++++++++++ src/vec4.c | 104 ++++++++++++++++++++++++++++++++++++ 5 files changed, 359 insertions(+), 1 deletion(-) diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 461de0b..e79ec8f 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -16,6 +16,10 @@ extern "C" { /* DEPRECATED! use _copy, _ucopy versions */ #define glmc_vec_dup(v, dest) glmc_vec_copy(v, dest) +CGLM_EXPORT +void +glmc_vec3(vec4 v4, vec3 dest); + CGLM_EXPORT void glmc_vec_copy(vec3 a, vec3 dest); @@ -64,6 +68,10 @@ CGLM_EXPORT void glmc_vec_flipsign(vec3 v); +CGLM_EXPORT +void +glmc_vec_flipsign_to(vec3 v, vec3 dest); + CGLM_EXPORT void glmc_vec_inv(vec3 v); @@ -108,6 +116,72 @@ CGLM_EXPORT void glmc_vec_clamp(vec3 v, float minVal, float maxVal); +CGLM_EXPORT +void +glmc_vec_ortho(vec3 v, vec3 dest); + +CGLM_EXPORT +void +glmc_vec_lerp(vec3 from, vec3 to, float t, vec3 dest); + +/* ext */ + +CGLM_EXPORT +void +glmc_vec_mulv(vec3 a, vec3 b, vec3 d); + +CGLM_EXPORT +void +glmc_vec_broadcast(float val, vec3 d); + +CGLM_EXPORT +bool +glmc_vec_eq(vec3 v, float val); + +CGLM_EXPORT +bool +glmc_vec_eq_eps(vec3 v, float val); + +CGLM_EXPORT +bool +glmc_vec_eq_all(vec3 v); + +CGLM_EXPORT +bool +glmc_vec_eqv(vec3 v1, vec3 v2); + +CGLM_EXPORT +bool +glmc_vec_eqv_eps(vec3 v1, vec3 v2); + +CGLM_EXPORT +float +glmc_vec_max(vec3 v); + +CGLM_EXPORT +float +glmc_vec_min(vec3 v); + +CGLM_EXPORT +bool +glmc_vec_isnan(vec3 v); + +CGLM_EXPORT +bool +glmc_vec_isinf(vec3 v); + +CGLM_EXPORT +bool +glmc_vec_isvalid(vec3 v); + +CGLM_EXPORT +void +glmc_vec_sign(vec3 v, vec3 dest); + +CGLM_EXPORT +void +glmc_vec_sqrt(vec3 v, vec3 dest); + #ifdef __cplusplus } #endif diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index b63af80..ad915e6 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -17,6 +17,10 @@ extern "C" { #define glmc_vec4_dup3(v, dest) glmc_vec4_copy3(v, dest) #define glmc_vec4_dup(v, dest) glmc_vec4_copy(v, dest) +CGLM_EXPORT +void +glmc_vec4(vec3 v3, float last, vec4 dest); + CGLM_EXPORT void glmc_vec4_copy3(vec4 a, vec3 dest); @@ -65,6 +69,10 @@ CGLM_EXPORT void glmc_vec4_flipsign(vec4 v); +CGLM_EXPORT +void +glmc_vec4_flipsign_to(vec4 v, vec4 dest); + CGLM_EXPORT void glmc_vec4_inv(vec4 v); @@ -89,6 +97,68 @@ CGLM_EXPORT void glmc_vec4_clamp(vec4 v, float minVal, float maxVal); +CGLM_EXPORT +void +glmc_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest); + +/* ext */ + +CGLM_EXPORT +void +glmc_vec4_mulv(vec4 a, vec4 b, vec4 d); + +CGLM_EXPORT +void +glmc_vec4_broadcast(float val, vec4 d); + +CGLM_EXPORT +bool +glmc_vec4_eq(vec4 v, float val); + +CGLM_EXPORT +bool +glmc_vec4_eq_eps(vec4 v, float val); + +CGLM_EXPORT +bool +glmc_vec4_eq_all(vec4 v); + +CGLM_EXPORT +bool +glmc_vec4_eqv(vec4 v1, vec4 v2); + +CGLM_EXPORT +bool +glmc_vec4_eqv_eps(vec4 v1, vec4 v2); + +CGLM_EXPORT +float +glmc_vec4_max(vec4 v); + +CGLM_EXPORT +float +glmc_vec4_min(vec4 v); + +CGLM_EXPORT +bool +glmc_vec4_isnan(vec4 v); + +CGLM_EXPORT +bool +glmc_vec4_isinf(vec4 v); + +CGLM_EXPORT +bool +glmc_vec4_isvalid(vec4 v); + +CGLM_EXPORT +void +glmc_vec4_sign(vec4 v, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_sqrt(vec4 v, vec4 dest); + #ifdef __cplusplus } #endif diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index afc853e..fb2a687 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -220,7 +220,7 @@ glm_vec_sign(vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec_sqrt(vec4 v, vec4 dest) { +glm_vec_sqrt(vec3 v, vec3 dest) { dest[0] = sqrtf(v[0]); dest[1] = sqrtf(v[1]); dest[2] = sqrtf(v[2]); diff --git a/src/vec3.c b/src/vec3.c index ebc677d..f7e2692 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -8,6 +8,12 @@ #include "../include/cglm/cglm.h" #include "../include/cglm/call.h" +CGLM_EXPORT +void +glmc_vec3(vec4 v4, vec3 dest) { + glm_vec3(v4, dest); +} + CGLM_EXPORT void glmc_vec_copy(vec3 a, vec3 dest) { @@ -80,6 +86,12 @@ glmc_vec_flipsign(vec3 v) { glm_vec_flipsign(v); } +CGLM_EXPORT +void +glmc_vec_flipsign_to(vec3 v, vec3 dest) { + glm_vec_flipsign_to(v, dest); +} + CGLM_EXPORT void glmc_vec_inv(vec3 v) { @@ -145,3 +157,101 @@ void glmc_vec_clamp(vec3 v, float minVal, float maxVal) { glm_vec_clamp(v, minVal, maxVal); } + +CGLM_EXPORT +void +glmc_vec_ortho(vec3 v, vec3 dest) { + glm_vec_ortho(v, dest); +} + +CGLM_EXPORT +void +glmc_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) { + glm_vec_lerp(from, to, t, dest); +} + +/* ext */ + +CGLM_EXPORT +void +glmc_vec_mulv(vec3 a, vec3 b, vec3 d) { + glm_vec_mulv(a, b, d); +} + +CGLM_EXPORT +void +glmc_vec_broadcast(float val, vec3 d) { + glm_vec_broadcast(val, d); +} + +CGLM_EXPORT +bool +glmc_vec_eq(vec3 v, float val) { + return glm_vec_eq(v, val); +} + +CGLM_EXPORT +bool +glmc_vec_eq_eps(vec3 v, float val) { + return glm_vec_eq_eps(v, val); +} + +CGLM_EXPORT +bool +glmc_vec_eq_all(vec3 v) { + return glm_vec_eq_all(v); +} + +CGLM_EXPORT +bool +glmc_vec_eqv(vec3 v1, vec3 v2) { + return glm_vec_eqv(v1, v2); +} + +CGLM_EXPORT +bool +glmc_vec_eqv_eps(vec3 v1, vec3 v2) { + return glm_vec_eqv_eps(v1, v2); +} + +CGLM_EXPORT +float +glmc_vec_max(vec3 v) { + return glm_vec_max(v); +} + +CGLM_EXPORT +float +glmc_vec_min(vec3 v) { + return glm_vec_min(v); +} + +CGLM_EXPORT +bool +glmc_vec_isnan(vec3 v) { + return glm_vec_isnan(v); +} + +CGLM_EXPORT +bool +glmc_vec_isinf(vec3 v) { + return glm_vec_isinf(v); +} + +CGLM_EXPORT +bool +glmc_vec_isvalid(vec3 v) { + return glm_vec_isvalid(v); +} + +CGLM_EXPORT +void +glmc_vec_sign(vec3 v, vec3 dest) { + glm_vec_sign(v, dest); +} + +CGLM_EXPORT +void +glmc_vec_sqrt(vec3 v, vec3 dest) { + glm_vec_sqrt(v, dest); +} diff --git a/src/vec4.c b/src/vec4.c index f5f6a06..7228070 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -8,6 +8,12 @@ #include "../include/cglm/cglm.h" #include "../include/cglm/call.h" +CGLM_EXPORT +void +glmc_vec4(vec3 v3, float last, vec4 dest) { + glm_vec4(v3, last, dest); +} + CGLM_EXPORT void glmc_vec4_copy3(vec4 a, vec3 dest) { @@ -80,6 +86,12 @@ glmc_vec4_flipsign(vec4 v) { glm_vec4_flipsign(v); } +CGLM_EXPORT +void +glmc_vec4_flipsign_to(vec4 v, vec4 dest) { + glm_vec4_flipsign_to(v, dest); +} + CGLM_EXPORT void glmc_vec4_inv(vec4 v) { @@ -115,3 +127,95 @@ void glmc_vec4_clamp(vec4 v, float minVal, float maxVal) { glm_vec4_clamp(v, minVal, maxVal); } + +CGLM_EXPORT +void +glmc_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) { + glm_vec4_lerp(from, to, t, dest); +} + +/* ext */ + +CGLM_EXPORT +void +glmc_vec4_mulv(vec4 a, vec4 b, vec4 d) { + glm_vec4_mulv(a, b, d); +} + +CGLM_EXPORT +void +glmc_vec4_broadcast(float val, vec4 d) { + glm_vec4_broadcast(val, d); +} + +CGLM_EXPORT +bool +glmc_vec4_eq(vec4 v, float val) { + return glm_vec4_eq(v, val); +} + +CGLM_EXPORT +bool +glmc_vec4_eq_eps(vec4 v, float val) { + return glm_vec4_eq_eps(v, val); +} + +CGLM_EXPORT +bool +glmc_vec4_eq_all(vec4 v) { + return glm_vec4_eq_all(v); +} + +CGLM_EXPORT +bool +glmc_vec4_eqv(vec4 v1, vec4 v2) { + return glm_vec4_eqv(v1, v2); +} + +CGLM_EXPORT +bool +glmc_vec4_eqv_eps(vec4 v1, vec4 v2) { + return glm_vec4_eqv_eps(v1, v2); +} + +CGLM_EXPORT +float +glmc_vec4_max(vec4 v) { + return glm_vec4_max(v); +} + +CGLM_EXPORT +float +glmc_vec4_min(vec4 v) { + return glm_vec4_min(v); +} + +CGLM_EXPORT +bool +glmc_vec4_isnan(vec4 v) { + return glm_vec4_isnan(v); +} + +CGLM_EXPORT +bool +glmc_vec4_isinf(vec4 v) { + return glm_vec4_isinf(v); +} + +CGLM_EXPORT +bool +glmc_vec4_isvalid(vec4 v) { + return glm_vec4_isvalid(v); +} + +CGLM_EXPORT +void +glmc_vec4_sign(vec4 v, vec4 dest) { + glm_vec4_sign(v, dest); +} + +CGLM_EXPORT +void +glmc_vec4_sqrt(vec4 v, vec4 dest) { + glm_vec4_sqrt(v, dest); +} From 0e63c245d437a8d192d7892e60a3405fcef4a020 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 11 Apr 2018 12:34:20 +0300 Subject: [PATCH 098/292] update docs --- docs/source/quat.rst | 274 ++++++++++++++++++++++++++++++++++++--- docs/source/util.rst | 15 +++ docs/source/vec3-ext.rst | 45 +++++++ docs/source/vec3.rst | 26 +++- docs/source/vec4-ext.rst | 40 ++++++ docs/source/vec4.rst | 27 ++++ include/cglm/quat.h | 11 +- include/cglm/vec3.h | 2 +- include/cglm/vec4-ext.h | 4 +- 9 files changed, 414 insertions(+), 30 deletions(-) diff --git a/docs/source/quat.rst b/docs/source/quat.rst index 863eed5..ab99838 100644 --- a/docs/source/quat.rst +++ b/docs/source/quat.rst @@ -5,17 +5,16 @@ quaternions Header: cglm/quat.h - **Important:** *cglm* stores quaternion as [w, x, y, z] in memory, don't - forget that when changing quaternion items manually. For instance *quat[3]* - is *quat.z* and *quat[0*] is *quat.w*. This may change in the future if *cglm* - will got enough request to do that. Probably it will not be changed in near - future + **Important:** *cglm* stores quaternion as **[x, y, z, w]** in memory + since **v0.4.0** it was **[w, x, y, z]** + before v0.4.0 ( **v0.3.5 and earlier** ). w is real part. -There are some TODOs for quaternions check TODO list to see them. +What you can do with quaternions with existing functions is (Some of them): -Also **versor** is identity quaternion so the type may change to **vec4** or -something else. This will not affect existing functions for your engine because -*versor* is alias of *vec4* +- You can rotate transform matrix using quaterion +- You can rotate vector using quaterion +- You can create view matrix using quaterion +- You can create a lookrotation (from source point to dest) Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -28,14 +27,35 @@ Macros: Functions: 1. :c:func:`glm_quat_identity` +#. :c:func:`glm_quat_init` #. :c:func:`glm_quat` #. :c:func:`glm_quatv` +#. :c:func:`glm_quat_copy` #. :c:func:`glm_quat_norm` #. :c:func:`glm_quat_normalize` +#. :c:func:`glm_quat_normalize_to` #. :c:func:`glm_quat_dot` -#. :c:func:`glm_quat_mulv` +#. :c:func:`glm_quat_conjugate` +#. :c:func:`glm_quat_inv` +#. :c:func:`glm_quat_add` +#. :c:func:`glm_quat_sub` +#. :c:func:`glm_quat_real` +#. :c:func:`glm_quat_imag` +#. :c:func:`glm_quat_imagn` +#. :c:func:`glm_quat_imaglen` +#. :c:func:`glm_quat_angle` +#. :c:func:`glm_quat_axis` +#. :c:func:`glm_quat_mul` #. :c:func:`glm_quat_mat4` +#. :c:func:`glm_quat_mat4t` +#. :c:func:`glm_quat_mat3` +#. :c:func:`glm_quat_mat3t` +#. :c:func:`glm_quat_lerp` #. :c:func:`glm_quat_slerp` +#. :c:func:`glm_quat_look` +#. :c:func:`glm_quat_for` +#. :c:func:`glm_quat_forp` +#. :c:func:`glm_quat_rotatev` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -47,10 +67,23 @@ Functions documentation Parameters: | *[in, out]* **q** quaternion +.. c:function:: void glm_quat_init(versor q, float x, float y, float z, float w) + + | inits quaternion with given values + + Parameters: + | *[out]* **q** quaternion + | *[in]* **x** imag.x + | *[in]* **y** imag.y + | *[in]* **z** imag.z + | *[in]* **w** w (real part) + .. c:function:: void glm_quat(versor q, float angle, float x, float y, float z) | creates NEW quaternion with individual axis components + | given axis will be normalized + Parameters: | *[out]* **q** quaternion | *[in]* **angle** angle (radians) @@ -58,14 +91,24 @@ Functions documentation | *[in]* **y** axis.y | *[in]* **z** axis.z -.. c:function:: void glm_quatv(versor q, float angle, vec3 v) +.. c:function:: void glm_quatv(versor q, float angle, vec3 axis) | creates NEW quaternion with axis vector + | given axis will be normalized + Parameters: | *[out]* **q** quaternion | *[in]* **angle** angle (radians) - | *[in]* **v** axis + | *[in]* **axis** axis (will be normalized) + +.. c:function:: void glm_quat_copy(versor q, versor dest) + + | copy quaternion to another one + + Parameters: + | *[in]* **q** source quaternion + | *[out]* **dest** destination quaternion .. c:function:: float glm_quat_norm(versor q) @@ -77,6 +120,14 @@ Functions documentation Returns: norm (magnitude) +.. c:function:: void glm_quat_normalize_to(versor q, versor dest) + + | normalize quaternion and store result in dest, original one will not be normalized + + Parameters: + | *[in]* **q** quaternion to normalize into + | *[out]* **dest** destination quaternion + .. c:function:: void glm_quat_normalize(versor q) | normalize quaternion @@ -84,24 +135,118 @@ Functions documentation Parameters: | *[in, out]* **q** quaternion -.. c:function:: float glm_quat_dot(versor q, versor r) +.. c:function:: float glm_quat_dot(versor p, versor q) dot product of two quaternion Parameters: - | *[in]* **q1** quaternion 1 - | *[in]* **q2** quaternion 2 + | *[in]* **p** quaternion 1 + | *[in]* **q** quaternion 2 Returns: dot product -.. c:function:: void glm_quat_mulv(versor q1, versor q2, versor dest) +.. c:function:: void glm_quat_conjugate(versor q, versor dest) + + conjugate of quaternion + + Parameters: + | *[in]* **q** quaternion + | *[in]* **dest** conjugate + +.. c:function:: void glm_quat_inv(versor q, versor dest) + + inverse of non-zero quaternion + + Parameters: + | *[in]* **q** quaternion + | *[in]* **dest** inverse quaternion + +.. c:function:: void glm_quat_add(versor p, versor q, versor dest) + + add (componentwise) two quaternions and store result in dest + + Parameters: + | *[in]* **p** quaternion 1 + | *[in]* **q** quaternion 2 + | *[in]* **dest** result quaternion + +.. c:function:: void glm_quat_sub(versor p, versor q, versor dest) + + subtract (componentwise) two quaternions and store result in dest + + Parameters: + | *[in]* **p** quaternion 1 + | *[in]* **q** quaternion 2 + | *[in]* **dest** result quaternion + +.. c:function:: float glm_quat_real(versor q) + + returns real part of quaternion + + Parameters: + | *[in]* **q** quaternion + + Returns: + real part (quat.w) + +.. c:function:: void glm_quat_imag(versor q, vec3 dest) + + returns imaginary part of quaternion + + Parameters: + | *[in]* **q** quaternion + | *[out]* **dest** imag + +.. c:function:: void glm_quat_imagn(versor q, vec3 dest) + + returns normalized imaginary part of quaternion + + Parameters: + | *[in]* **q** quaternion + | *[out]* **dest** imag + +.. c:function:: float glm_quat_imaglen(versor q) + + returns length of imaginary part of quaternion + + Parameters: + | *[in]* **q** quaternion + + Returns: + norm of imaginary part + +.. c:function:: float glm_quat_angle(versor q) + + returns angle of quaternion + + Parameters: + | *[in]* **q** quaternion + + Returns: + angles of quat (radians) + +.. c:function:: void glm_quat_axis(versor q, versor dest) + + axis of quaternion + + Parameters: + | *[in]* **p** quaternion + | *[out]* **dest** axis of quaternion + +.. c:function:: void glm_quat_mul(versor p, versor q, versor dest) | multiplies two quaternion and stores result in dest + | this is also called Hamilton Product + + | According to WikiPedia: + | The product of two rotation quaternions [clarification needed] will be + equivalent to the rotation q followed by the rotation p + Parameters: - | *[in]* **q1** quaternion 1 - | *[in]* **q2** quaternion 2 + | *[in]* **p** quaternion 1 (first rotation) + | *[in]* **q** quaternion 2 (second rotation) | *[out]* **dest** result quaternion .. c:function:: void glm_quat_mat4(versor q, mat4 dest) @@ -112,13 +257,100 @@ Functions documentation | *[in]* **q** quaternion | *[out]* **dest** result matrix +.. c:function:: void glm_quat_mat4t(versor q, mat4 dest) + + | convert quaternion to mat4 (transposed). This is transposed version of glm_quat_mat4 + + Parameters: + | *[in]* **q** quaternion + | *[out]* **dest** result matrix + +.. c:function:: void glm_quat_mat3(versor q, mat3 dest) + + | convert quaternion to mat3 + + Parameters: + | *[in]* **q** quaternion + | *[out]* **dest** result matrix + +.. c:function:: void glm_quat_mat3t(versor q, mat3 dest) + + | convert quaternion to mat3 (transposed). This is transposed version of glm_quat_mat3 + + Parameters: + | *[in]* **q** quaternion + | *[out]* **dest** result matrix + +.. c:function:: void glm_quat_lerp(versor from, versor to, float t, versor dest) + + | interpolates between two quaternions + | using spherical linear interpolation (LERP) + + Parameters: + | *[in]* **from** from + | *[in]* **to** to + | *[in]* **t** interpolant (amount) clamped between 0 and 1 + | *[out]* **dest** result quaternion + .. c:function:: void glm_quat_slerp(versor q, versor r, float t, versor dest) | interpolates between two quaternions | using spherical linear interpolation (SLERP) Parameters: - | *[in]* **q** from - | *[in]* **r** to - | *[in]* **t** amout + | *[in]* **from** from + | *[in]* **to** to + | *[in]* **t** interpolant (amount) clamped between 0 and 1 | *[out]* **dest** result quaternion + +.. c:function:: void glm_quat_look(vec3 eye, versor ori, mat4 dest) + + | creates view matrix using quaternion as camera orientation + + Parameters: + | *[in]* **eye** eye + | *[in]* **ori** orientation in world space as quaternion + | *[out]* **dest** result matrix + +.. c:function:: void glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) + + | creates look rotation quaternion + + Parameters: + | *[in]* **dir** direction to look + | *[in]* **fwd** forward vector + | *[in]* **up** up vector + | *[out]* **dest** result matrix + +.. c:function:: void glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) + + | creates look rotation quaternion using source and destination positions p suffix stands for position + + | this is similar to glm_quat_for except this computes direction for glm_quat_for for you. + + Parameters: + | *[in]* **from** source point + | *[in]* **to** destination point + | *[in]* **fwd** forward vector + | *[in]* **up** up vector + | *[out]* **dest** result matrix + +.. c:function:: void glm_quat_rotatev(versor q, vec3 v, vec3 dest) + + | crotate vector using using quaternion + + Parameters: + | *[in]* **q** quaternion + | *[in]* **v** vector to rotate + | *[out]* **dest** rotated vector + +.. c:function:: void glm_quat_rotate(mat4 m, versor q, mat4 dest) + + | rotate existing transform matrix using quaternion + + instead of passing identity matrix, consider to use quat_mat4 functions + + Parameters: + | *[in]* **m** existing transform matrix to rotate + | *[in]* **q** quaternion + | *[out]* **dest** rotated matrix/transform diff --git a/docs/source/util.rst b/docs/source/util.rst index a9f4066..f8dbac4 100644 --- a/docs/source/util.rst +++ b/docs/source/util.rst @@ -22,6 +22,7 @@ Functions: #. :c:func:`glm_min` #. :c:func:`glm_max` #. :c:func:`glm_clamp` +#. :c:func:`glm_lerp` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -121,3 +122,17 @@ Functions documentation Returns: clamped value + +.. c:function:: float glm_lerp(float from, float to, float t) + + linear interpolation between two number + + | formula: from + s * (to - from) + + Parameters: + | *[in]* **from** from value + | *[in]* **to** to value + | *[in]* **t** interpolant (amount) clamped between 0 and 1 + + Returns: + interpolated value diff --git a/docs/source/vec3-ext.rst b/docs/source/vec3-ext.rst index e632de9..c2c0bfc 100644 --- a/docs/source/vec3-ext.rst +++ b/docs/source/vec3-ext.rst @@ -23,6 +23,11 @@ Functions: #. :c:func:`glm_vec_eqv_eps` #. :c:func:`glm_vec_max` #. :c:func:`glm_vec_min` +#. :c:func:`glm_vec_isnan` +#. :c:func:`glm_vec_isinf` +#. :c:func:`glm_vec_isvalid` +#. :c:func:`glm_vec_sign` +#. :c:func:`glm_vec_sqrt` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -96,3 +101,43 @@ Functions documentation Parameters: | *[in]* **v** vector + +.. c:function:: bool glm_vec_isnan(vec3 v) + + | check if one of items is NaN (not a number) + | you should only use this in DEBUG mode or very critical asserts + + Parameters: + | *[in]* **v** vector + +.. c:function:: bool glm_vec_isinf(vec3 v) + + | check if one of items is INFINITY + | you should only use this in DEBUG mode or very critical asserts + + Parameters: + | *[in]* **v** vector + +.. c:function:: bool glm_vec_isvalid(vec3 v) + + | check if all items are valid number + | you should only use this in DEBUG mode or very critical asserts + + Parameters: + | *[in]* **v** vector + +.. c:function:: void glm_vec_sign(vec3 v, vec3 dest) + + get sign of 32 bit float as +1, -1, 0 + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** sign vector (only keeps signs as -1, 0, -1) + +.. c:function:: void glm_vec_sqrt(vec3 v, vec3 dest) + + square root of each vector item + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** destination vector (sqrt(v)) diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index 355178d..8529333 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -40,6 +40,7 @@ Functions: #. :c:func:`glm_vec_scale` #. :c:func:`glm_vec_scale_as` #. :c:func:`glm_vec_flipsign` +#. :c:func:`glm_vec_flipsign_to` #. :c:func:`glm_vec_inv` #. :c:func:`glm_vec_inv_to` #. :c:func:`glm_vec_normalize` @@ -54,6 +55,7 @@ Functions: #. :c:func:`glm_vec_minv` #. :c:func:`glm_vec_ortho` #. :c:func:`glm_vec_clamp` +#. :c:func:`glm_vec_lerp` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -157,7 +159,15 @@ Functions documentation flip sign of all vec3 members Parameters: - | *[in, out]* **v** vector + | *[in, out]* **v** vector + +.. c:function:: void glm_vec_flipsign_to(vec3 v, vec3 dest) + + flip sign of all vec3 members and store result in dest + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** negated vector .. c:function:: void glm_vec_inv(vec3 v) @@ -206,7 +216,7 @@ Functions documentation Parameters: | *[in, out]* **v** vector - | *[in]* **axis** axis vector (must be unit vector) + | *[in]* **axis** axis vector (will be normalized) | *[out]* **angle** angle (radians) .. c:function:: void glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) @@ -281,3 +291,15 @@ Functions documentation | *[in, out]* **v** vector | *[in]* **minVal** minimum value | *[in]* **maxVal** maximum value + +.. c:function:: void glm_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) + + linear interpolation between two vector + + | formula: from + s * (to - from) + + Parameters: + | *[in]* **from** from value + | *[in]* **to** to value + | *[in]* **t** interpolant (amount) clamped between 0 and 1 + | *[out]* **dest** destination diff --git a/docs/source/vec4-ext.rst b/docs/source/vec4-ext.rst index 11613ad..722424e 100644 --- a/docs/source/vec4-ext.rst +++ b/docs/source/vec4-ext.rst @@ -96,3 +96,43 @@ Functions documentation Parameters: | *[in]* **v** vector + +.. c:function:: bool glm_vec4_isnan(vec4 v) + + | check if one of items is NaN (not a number) + | you should only use this in DEBUG mode or very critical asserts + + Parameters: + | *[in]* **v** vector + +.. c:function:: bool glm_vec4_isinf(vec4 v) + + | check if one of items is INFINITY + | you should only use this in DEBUG mode or very critical asserts + + Parameters: + | *[in]* **v** vector + +.. c:function:: bool glm_vec4_isvalid(vec4 v) + + | check if all items are valid number + | you should only use this in DEBUG mode or very critical asserts + + Parameters: + | *[in]* **v** vector + +.. c:function:: void glm_vec4_sign(vec4 v, vec4 dest) + + get sign of 32 bit float as +1, -1, 0 + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** sign vector (only keeps signs as -1, 0, -1) + +.. c:function:: void glm_vec4_sqrt(vec4 v, vec4 dest) + + square root of each vector item + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** destination vector (sqrt(v)) diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index ac1b9c5..6955246 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -32,6 +32,7 @@ Functions: #. :c:func:`glm_vec4_scale` #. :c:func:`glm_vec4_scale_as` #. :c:func:`glm_vec4_flipsign` +#. :c:func:`glm_vec_flipsign_to` #. :c:func:`glm_vec4_inv` #. :c:func:`glm_vec4_inv_to` #. :c:func:`glm_vec4_normalize` @@ -40,6 +41,12 @@ Functions: #. :c:func:`glm_vec4_maxv` #. :c:func:`glm_vec4_minv` #. :c:func:`glm_vec4_clamp` +#. :c:func:`glm_vec4_lerp` +#. :c:func:`glm_vec4_isnan` +#. :c:func:`glm_vec4_isinf` +#. :c:func:`glm_vec4_isvalid` +#. :c:func:`glm_vec4_sign` +#. :c:func:`glm_vec4_sqrt` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -146,6 +153,14 @@ Functions documentation Parameters: | *[in, out]* **v** vector +.. c:function:: void glm_vec4_flipsign_to(vec4 v, vec4 dest) + + flip sign of all vec4 members and store result in dest + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** negated vector + .. c:function:: void glm_vec4_inv(vec4 v) make vector as inverse/opposite of itself @@ -213,3 +228,15 @@ Functions documentation | *[in, out]* **v** vector | *[in]* **minVal** minimum value | *[in]* **maxVal** maximum value + +.. c:function:: void glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) + + linear interpolation between two vector + + | formula: from + s * (to - from) + + Parameters: + | *[in]* **from** from value + | *[in]* **to** to value + | *[in]* **t** interpolant (amount) clamped between 0 and 1 + | *[out]* **dest** destination diff --git a/include/cglm/quat.h b/include/cglm/quat.h index c9927bb..d82a301 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -226,8 +226,8 @@ glm_quat_normalize(versor q) { /*! * @brief dot product of two quaternion * - * @param[in] q1 quaternion 1 - * @param[in] q2 quaternion 2 + * @param[in] p quaternion 1 + * @param[in] q quaternion 2 */ CGLM_INLINE float @@ -303,6 +303,7 @@ glm_quat_real(versor q) { * @brief returns imaginary part of quaternion * * @param[in] q quaternion + * @param[out] dest imag */ CGLM_INLINE void @@ -649,6 +650,7 @@ glm_quat_look(vec3 eye, versor ori, mat4 dest) { /*! * @brief creates look rotation quaternion * + * @param[in] dir direction to look * @param[in] fwd forward vector * @param[in] up up vector * @param[out] dest destination quaternion @@ -683,6 +685,7 @@ glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) { * * @param[in] from source point * @param[in] to destination point + * @param[in] fwd forward vector * @param[in] up up vector * @param[out] dest destination quaternion */ @@ -699,7 +702,7 @@ glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { * * @param[in] q quaternion * @param[in] v vector to rotate - * @param[out] dest destination vector + * @param[out] dest rotated vector */ CGLM_INLINE void @@ -727,7 +730,7 @@ glm_quat_rotatev(versor q, vec3 v, vec3 dest) { * * @param[in] m existing transform matrix * @param[in] q quaternion - * @param[out] dest destination matrix + * @param[out] dest rotated matrix/transform */ CGLM_INLINE void diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 1cbf508..714165b 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -246,7 +246,7 @@ glm_vec_flipsign(vec3 v) { * @brief flip sign of all vec3 members and store result in dest * * @param[in] v vector - * @param[out] dest vector + * @param[out] dest result vector */ CGLM_INLINE void diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index 77ba1fa..53b02a8 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -175,7 +175,7 @@ glm_vec4_min(vec4 v) { } /*! - * @brief check if all items are NaN (not a number) + * @brief check if one of items is NaN (not a number) * you should only use this in DEBUG mode or very critical asserts * * @param[in] v vector @@ -187,7 +187,7 @@ glm_vec4_isnan(vec4 v) { } /*! - * @brief check if all items are INFINITY + * @brief check if one of items is INFINITY * you should only use this in DEBUG mode or very critical asserts * * @param[in] v vector From 9ae8da3e0aa8bcee6faaa397313f2f332a172596 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 11 Apr 2018 12:36:39 +0300 Subject: [PATCH 099/292] update version to v0.4.0 --- configure.ac | 2 +- include/cglm/version.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index afb694b..6e22248 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.3.6], [info@recp.me]) +AC_INIT([cglm], [0.4.0], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/include/cglm/version.h b/include/cglm/version.h index c27a26e..9a54b03 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -9,7 +9,7 @@ #define cglm_version_h #define CGLM_VERSION_MAJOR 0 -#define CGLM_VERSION_MINOR 3 -#define CGLM_VERSION_PATCH 6 +#define CGLM_VERSION_MINOR 4 +#define CGLM_VERSION_PATCH 0 #endif /* cglm_version_h */ From 2d77123999be1ee902bed2f02c88aa29e4875bfe Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 11 Apr 2018 16:50:37 +0300 Subject: [PATCH 100/292] quat: fix quaternion inverse and tests about it * multiplication quaternion and its inverse must be identity --- include/cglm/quat.h | 2 +- test/src/test_quat.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index d82a301..fa356d4 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -259,7 +259,7 @@ void glm_quat_inv(versor q, versor dest) { versor conj; glm_quat_conjugate(q, conj); - glm_vec_scale(conj, glm_vec4_norm2(q), dest); + glm_vec4_scale(conj, 1.0f / glm_vec4_norm2(q), dest); } /*! diff --git a/test/src/test_quat.c b/test/src/test_quat.c index fec8dae..74d12b5 100644 --- a/test/src/test_quat.c +++ b/test/src/test_quat.c @@ -26,6 +26,8 @@ test_quat(void **state) { /* 0. test identiy quat */ glm_quat_identity(q4); assert_true(glm_quat_real(q4) == cosf(glm_rad(0.0f) * 0.5f)); + glm_quat_mat4(q4, rot1); + test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009); /* 1. test quat to mat and mat to quat */ for (i = 0; i < 1000; i++) { @@ -184,5 +186,14 @@ test_quat(void **state) { /* result must be identity */ test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009); + test_rand_quat(q3); + + /* 12. inverse of quat, multiplication must be IDENTITY */ + glm_quat_inv(q3, q4); + glm_quat_mul(q3, q4, q5); + + glm_quat_identity(q3); + test_assert_quat_eq(q3, q5); + /* TODO: add tests for slerp, lerp */ } From c8ed8acbed9c43245a08e74de0fdb922fd1eed0a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 12 Apr 2018 14:47:14 +0300 Subject: [PATCH 101/292] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dc9f736..15f434c 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,9 @@ Complete documentation: http://cglm.readthedocs.io - _dup (duplicate) is changed to _copy. For instance `glm_vec_dup -> glm_vec_copy` - OpenGL related functions are dropped to make this lib platform/third-party independent - make sure you have latest version and feel free to report bugs, troubles -- **[bugfix]** euler angles was implemented in reverse order (extrinsic) it was fixed, now they are intrinsic. Make sure that you have the latest version +- **[bugfix]** euler angles was implemented in reverse order (extrinsic) it was fixed, now they are intrinsic. Make sure that +you have the latest version +- **[major change]** by starting v0.4.0, quaternions are stored as [x, y, z, w], it was [w, x, y, z] in v0.3.5 and earlier versions #### Note for C++ developers: If you don't aware about original GLM library yet, you may also want to look at: From 44728c536b6245c5c7ddd22f579cdb061d424392 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 12 Apr 2018 15:52:06 +0300 Subject: [PATCH 102/292] ci: update travis ci --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index af4e37f..c2c0c84 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,7 @@ script: after_success: - if [[ "$CC" == "gcc" && "$CODE_COVERAGE" == "ON" ]]; then - pip install --user cpp-coveralls + pip install --user cpp-coveralls && coveralls --build-root . --exclude lib From 0eb37da8bbcefc722ad4098b47b742d615c85fb1 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 13 Apr 2018 11:01:07 +0300 Subject: [PATCH 103/292] vec4: optimize vec4 normalize with SIMD --- include/cglm/vec4.h | 48 ++++++++++++++++++++++++------------------ test/src/test_common.c | 8 +++++++ test/src/test_common.h | 3 +++ test/src/test_vec4.c | 29 +++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 22 deletions(-) diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index eaa4eaf..0ef6bff 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -312,26 +312,6 @@ glm_vec4_inv_to(vec4 v, vec4 dest) { glm_vec4_flipsign(dest); } -/*! - * @brief normalize vec4 and store result in same vec - * - * @param[in, out] v vector - */ -CGLM_INLINE -void -glm_vec4_normalize(vec4 v) { - float norm; - - norm = glm_vec4_norm(v); - - if (norm == 0.0f) { - v[0] = v[1] = v[2] = v[3] = 0.0f; - return; - } - - glm_vec4_scale(v, 1.0f / norm, v); -} - /*! * @brief normalize vec4 to dest * @@ -341,16 +321,44 @@ glm_vec4_normalize(vec4 v) { CGLM_INLINE void glm_vec4_normalize_to(vec4 vec, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + __m128 xdot, x0; + float dot; + + x0 = _mm_load_ps(vec); + xdot = glm_simd_dot(x0, x0); + dot = _mm_cvtss_f32(xdot); + + if (dot == 0.0f) { + _mm_store_ps(dest, _mm_setzero_ps()); + return; + } + + _mm_store_ps(dest, _mm_div_ps(x0, _mm_sqrt_ps(xdot))); +#else float norm; norm = glm_vec4_norm(vec); if (norm == 0.0f) { dest[0] = dest[1] = dest[2] = dest[3] = 0.0f; + glm_vec4_broadcast(0.0f, dest); return; } glm_vec4_scale(vec, 1.0f / norm, dest); +#endif +} + +/*! + * @brief normalize vec4 and store result in same vec + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec4_normalize(vec4 v) { + glm_vec4_normalize_to(v, v); } /** diff --git a/test/src/test_common.c b/test/src/test_common.c index 514c006..a559087 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -91,6 +91,14 @@ test_assert_vec3_eq(vec3 v1, vec3 v2) { assert_true(fabsf(v1[2] - v2[2]) <= 0.000009); } +void +test_assert_vec4_eq(vec4 v1, vec4 v2) { + assert_true(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ + assert_true(fabsf(v1[1] - v2[1]) <= 0.000009); + assert_true(fabsf(v1[2] - v2[2]) <= 0.000009); + assert_true(fabsf(v1[3] - v2[3]) <= 0.000009); +} + void test_assert_quat_eq_abs(versor v1, versor v2) { assert_true(fabsf(fabsf(v1[0]) - fabsf(v2[0])) <= 0.0009); /* rounding errors */ diff --git a/test/src/test_common.h b/test/src/test_common.h index c95405e..50e84d6 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -34,6 +34,9 @@ test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps); void test_assert_vec3_eq(vec3 v1, vec3 v2); +void +test_assert_vec4_eq(vec4 v1, vec4 v2); + void test_assert_quat_eq(versor v1, versor v2); diff --git a/test/src/test_vec4.c b/test/src/test_vec4.c index a45a700..994bab7 100644 --- a/test/src/test_vec4.c +++ b/test/src/test_vec4.c @@ -13,18 +13,43 @@ test_vec4_dot(vec4 a, vec4 b) { return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; } +CGLM_INLINE +void +test_vec4_normalize_to(vec4 vec, vec4 dest) { + float norm; + + norm = glm_vec4_norm(vec); + + if (norm == 0.0f) { + dest[0] = dest[1] = dest[2] = dest[3] = 0.0f; + return; + } + + glm_vec4_scale(vec, 1.0f / norm, dest); +} + void test_vec4(void **state) { - vec4 v; + vec4 v, v1, v2; int i; float d1, d2; - /* test SSE/SIMD dot product */ + for (i = 0; i < 100; i++) { + /* 1. test SSE/SIMD dot product */ test_rand_vec4(v); d1 = glm_vec4_dot(v, v); d2 = test_vec4_dot(v, v); assert_true(fabsf(d1 - d2) <= 0.000009); + + /* 2. test SIMD normalize */ + test_vec4_normalize_to(v, v1); + glm_vec4_normalize_to(v, v2); + glm_vec4_normalize(v); + + /* all must be same */ + test_assert_vec4_eq(v1, v2); + test_assert_vec4_eq(v, v2); } } From 79f8b1ebf85040e19a0a2eeb4b750dc57e948db5 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 13 Apr 2018 11:18:42 +0300 Subject: [PATCH 104/292] vec4: optimize vec4 norm and norm2 --- include/cglm/vec4.h | 16 +++++++++++++++- test/src/test_common.c | 5 +++++ test/src/test_common.h | 3 +++ test/src/test_vec4.c | 20 +++++++++++++++++++- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 0ef6bff..c50b4f9 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -146,7 +146,15 @@ glm_vec4_dot(vec4 a, vec4 b) { CGLM_INLINE float glm_vec4_norm2(vec4 v) { - return glm_vec4_dot(v, v); +#if defined( __SSE__ ) || defined( __SSE2__ ) + __m128 x0; + x0 = _mm_load_ps(v); + x0 = _mm_mul_ps(x0, x0); + x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 3, 2)); + return _mm_cvtss_f32(_mm_add_ss(x0, _mm_shuffle1_ps(x0, 0, 1, 0, 1))); +#else + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; +#endif } /*! @@ -159,7 +167,13 @@ glm_vec4_norm2(vec4 v) { CGLM_INLINE float glm_vec4_norm(vec4 vec) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + __m128 x0; + x0 = _mm_load_ps(vec); + return _mm_cvtss_f32(_mm_sqrt_ss(glm_simd_dot(x0, x0))); +#else return sqrtf(glm_vec4_norm2(vec)); +#endif } /*! diff --git a/test/src/test_common.c b/test/src/test_common.c index a559087..60baac3 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -84,6 +84,11 @@ test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps) { } } +void +test_assert_eqf(float a, float b) { + assert_true(fabsf(a - b) <= 0.000009); /* rounding errors */ +} + void test_assert_vec3_eq(vec3 v1, vec3 v2) { assert_true(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ diff --git a/test/src/test_common.h b/test/src/test_common.h index 50e84d6..db113a4 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -25,6 +25,9 @@ void test_rand_mat4(mat4 dest); +void +test_assert_eqf(float a, float b); + void test_assert_mat4_eq(mat4 m1, mat4 m2); diff --git a/test/src/test_vec4.c b/test/src/test_vec4.c index 994bab7..51986f1 100644 --- a/test/src/test_vec4.c +++ b/test/src/test_vec4.c @@ -28,6 +28,16 @@ test_vec4_normalize_to(vec4 vec, vec4 dest) { glm_vec4_scale(vec, 1.0f / norm, dest); } +float +test_vec4_norm2(vec4 vec) { + return test_vec4_dot(vec, vec); +} + +float +test_vec4_norm(vec4 vec) { + return sqrtf(test_vec4_dot(vec, vec)); +} + void test_vec4(void **state) { vec4 v, v1, v2; @@ -35,7 +45,7 @@ test_vec4(void **state) { float d1, d2; - for (i = 0; i < 100; i++) { + for (i = 0; i < 1000; i++) { /* 1. test SSE/SIMD dot product */ test_rand_vec4(v); d1 = glm_vec4_dot(v, v); @@ -51,5 +61,13 @@ test_vec4(void **state) { /* all must be same */ test_assert_vec4_eq(v1, v2); test_assert_vec4_eq(v, v2); + + /* 3. test SIMD norm */ + test_rand_vec4(v); + test_assert_eqf(test_vec4_norm(v), glm_vec4_norm(v)); + + /* 3. test SIMD norm2 */ + test_rand_vec4(v); + test_assert_eqf(test_vec4_norm2(v), glm_vec4_norm2(v)); } } From c489955b0079d4c8c9a599fb14d9a2ca15a9363e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 13 Apr 2018 11:39:14 +0300 Subject: [PATCH 105/292] add simd norm helper --- include/cglm/simd/intrin.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index 4c27d90..c396686 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -40,6 +40,12 @@ glm_simd_dot(__m128 a, __m128 b) { return _mm_add_ps(x0, _mm_shuffle1_ps(x0, 0, 1, 0, 1)); } +CGLM_INLINE +__m128 +glm_simd_norm(__m128 a) { + return _mm_sqrt_ps(glm_simd_dot(a, a)); +} + #endif /* x86, x64 */ From 25fc3d028486c000f242588f735885cb9afad2bd Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 13 Apr 2018 11:57:14 +0300 Subject: [PATCH 106/292] vec: add one and zero helpers for vectors --- docs/source/vec3.rst | 16 ++++++++++++++++ docs/source/vec4.rst | 9 +++++++++ include/cglm/call/vec3.h | 8 ++++++++ include/cglm/call/vec4.h | 8 ++++++++ include/cglm/vec3.h | 26 ++++++++++++++++++++++++++ include/cglm/vec4.h | 36 ++++++++++++++++++++++++++++++++++++ makefile.am | 3 ++- src/vec3.c | 12 ++++++++++++ src/vec4.c | 12 ++++++++++++ test/src/test_main.c | 5 ++++- test/src/test_tests.h | 3 +++ test/src/test_vec3.c | 21 +++++++++++++++++++++ test/src/test_vec4.c | 8 ++++++++ 13 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 test/src/test_vec3.c diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index 8529333..0c5d590 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -31,6 +31,8 @@ Functions: 1. :c:func:`glm_vec3` #. :c:func:`glm_vec_copy` +#. :c:func:`glm_vec_zero` +#. :c:func:`glm_vec_one` #. :c:func:`glm_vec_dot` #. :c:func:`glm_vec_cross` #. :c:func:`glm_vec_norm2` @@ -76,6 +78,20 @@ Functions documentation | *[in]* **a** source | *[out]* **dest** destination +.. c:function:: void glm_vec_zero(vec3 v) + + makes all members 0.0f (zero) + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec_one(vec3 v) + + makes all members 1.0f (one) + + Parameters: + | *[in, out]* **v** vector + .. c:function:: float glm_vec_dot(vec3 a, vec3 b) dot product of vec3 diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index 6955246..8deed35 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -24,6 +24,8 @@ Functions: 1. :c:func:`glm_vec4` #. :c:func:`glm_vec4_copy3` #. :c:func:`glm_vec4_copy` +#. :c:func:`glm_vec4_zero` +#. :c:func:`glm_vec4_one` #. :c:func:`glm_vec4_dot` #. :c:func:`glm_vec4_norm2` #. :c:func:`glm_vec4_norm` @@ -78,6 +80,13 @@ Functions documentation | *[in]* **v** source | *[in]* **dest** destination +.. c:function:: void glm_vec4_zero(vec4 v) + + makes all members zero + + Parameters: + | *[in, out]* **v** vector + .. c:function:: float glm_vec4_dot(vec4 a, vec4 b) dot product of vec4 diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index e79ec8f..396972f 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -24,6 +24,14 @@ CGLM_EXPORT void glmc_vec_copy(vec3 a, vec3 dest); +CGLM_EXPORT +void +glmc_vec_zero(vec3 v); + +CGLM_EXPORT +void +glmc_vec_one(vec3 v); + CGLM_EXPORT float glmc_vec_dot(vec3 a, vec3 b); diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index ad915e6..95f91e2 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -21,6 +21,14 @@ CGLM_EXPORT void glmc_vec4(vec3 v3, float last, vec4 dest); +CGLM_EXPORT +void +glmc_vec4_zero(vec4 v); + +CGLM_EXPORT +void +glmc_vec4_one(vec4 v); + CGLM_EXPORT void glmc_vec4_copy3(vec4 a, vec3 dest); diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 714165b..6f42855 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -103,6 +103,32 @@ glm_vec_copy(vec3 a, vec3 dest) { dest[2] = a[2]; } +/*! + * @brief make vector zero + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec_zero(vec4 v) { + v[0] = 0.0f; + v[1] = 0.0f; + v[2] = 0.0f; +} + +/*! + * @brief make vector one + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec_one(vec4 v) { + v[0] = 1.0f; + v[1] = 1.0f; + v[2] = 1.0f; +} + /*! * @brief vec3 dot product * diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index c50b4f9..44c6a31 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -111,6 +111,42 @@ glm_vec4_copy(vec4 v, vec4 dest) { #endif } +/*! + * @brief make vector zero + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec4_zero(vec4 v) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(v, _mm_setzero_ps()); +#else + v[0] = 0.0f; + v[1] = 0.0f; + v[2] = 0.0f; + v[3] = 0.0f; +#endif +} + +/*! + * @brief make vector one + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec4_one(vec4 v) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(v, _mm_set1_ps(1.0f)); +#else + v[0] = 1.0f; + v[1] = 1.0f; + v[2] = 1.0f; + v[3] = 1.0f; +#endif +} + /*! * @brief vec4 dot product * diff --git a/makefile.am b/makefile.am index 2922373..00800c0 100644 --- a/makefile.am +++ b/makefile.am @@ -110,7 +110,8 @@ test_tests_SOURCES=\ test/src/test_clamp.c \ test/src/test_euler.c \ test/src/test_quat.c \ - test/src/test_vec4.c + test/src/test_vec4.c \ + test/src/test_vec3.c all-local: sh ./post-build.sh diff --git a/src/vec3.c b/src/vec3.c index f7e2692..f7c890e 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -20,6 +20,18 @@ glmc_vec_copy(vec3 a, vec3 dest) { glm_vec_copy(a, dest); } +CGLM_EXPORT +void +glmc_vec_zero(vec3 v) { + glm_vec_zero(v); +} + +CGLM_EXPORT +void +glmc_vec_one(vec3 v) { + glm_vec_one(v); +} + CGLM_EXPORT float glmc_vec_dot(vec3 a, vec3 b) { diff --git a/src/vec4.c b/src/vec4.c index 7228070..df93556 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -14,6 +14,18 @@ glmc_vec4(vec3 v3, float last, vec4 dest) { glm_vec4(v3, last, dest); } +CGLM_EXPORT +void +glmc_vec4_zero(vec4 v) { + glm_vec4_zero(v); +} + +CGLM_EXPORT +void +glmc_vec4_one(vec4 v) { + glm_vec4_one(v); +} + CGLM_EXPORT void glmc_vec4_copy3(vec4 a, vec3 dest) { diff --git a/test/src/test_main.c b/test/src/test_main.c index 7995a5a..b0649cd 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -29,7 +29,10 @@ main(int argc, const char * argv[]) { cmocka_unit_test(test_quat), /* vec4 */ - cmocka_unit_test(test_vec4) + cmocka_unit_test(test_vec4), + + /* vec3 */ + cmocka_unit_test(test_vec3) }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/test/src/test_tests.h b/test/src/test_tests.h index 1dfbb5f..224d943 100644 --- a/test/src/test_tests.h +++ b/test/src/test_tests.h @@ -31,4 +31,7 @@ test_quat(void **state); void test_vec4(void **state); +void +test_vec3(void **state); + #endif /* test_tests_h */ diff --git a/test/src/test_vec3.c b/test/src/test_vec3.c new file mode 100644 index 0000000..5a3a4c8 --- /dev/null +++ b/test/src/test_vec3.c @@ -0,0 +1,21 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +void +test_vec3(void **state) { + vec3 v; + + /* test zero */ + glm_vec_zero(v); + test_assert_vec3_eq(GLM_VEC3_ZERO, v); + + /* test one */ + glm_vec_one(v); + test_assert_vec3_eq(GLM_VEC3_ONE, v); +} diff --git a/test/src/test_vec4.c b/test/src/test_vec4.c index 51986f1..a80d9c7 100644 --- a/test/src/test_vec4.c +++ b/test/src/test_vec4.c @@ -70,4 +70,12 @@ test_vec4(void **state) { test_rand_vec4(v); test_assert_eqf(test_vec4_norm2(v), glm_vec4_norm2(v)); } + + /* test zero */ + glm_vec4_zero(v); + test_assert_vec4_eq(GLM_VEC4_ZERO, v); + + /* test one */ + glm_vec4_one(v); + test_assert_vec4_eq(GLM_VEC4_ONE, v); } From af5a2627b4566eabd44058d219f31dd8debb1e58 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 13 Apr 2018 11:57:34 +0300 Subject: [PATCH 107/292] fix scale_as for zero length vector * return zero if vector length is zero --- include/cglm/vec3.h | 4 ++-- include/cglm/vec4.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 6f42855..2be7173 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -247,8 +247,8 @@ glm_vec_scale_as(vec3 v, float s, vec3 dest) { float norm; norm = glm_vec_norm(v); - if (norm == 0) { - glm_vec_copy(v, dest); + if (norm == 0.0f) { + glm_vec_zero(dest); return; } diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 44c6a31..b28d9fd 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -291,8 +291,8 @@ glm_vec4_scale_as(vec4 v, float s, vec4 dest) { float norm; norm = glm_vec4_norm(v); - if (norm == 0) { - glm_vec4_copy(v, dest); + if (norm == 0.0f) { + glm_vec4_zero(dest); return; } From d841f8809d7da5f1e4afe6d06b67cb0ba4397b6b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 13 Apr 2018 15:12:56 +0300 Subject: [PATCH 108/292] vec: add some new functions for vector * _mul: multiply two vector (replacement for _mulv) * _div: div two vector * _divs: div vector with scalar * adds: add scalar to each components of vec * subs: sub scalar from each components of vec --- docs/source/vec3.rst | 64 +++++++++++++++-- docs/source/vec4.rst | 66 ++++++++++++++--- include/cglm/call/vec3.h | 22 +++++- include/cglm/call/vec4.h | 24 ++++++- include/cglm/vec3-ext.h | 2 +- include/cglm/vec3.h | 114 ++++++++++++++++++++++++----- include/cglm/vec4-ext.h | 2 +- include/cglm/vec4.h | 152 +++++++++++++++++++++++++++++++-------- src/vec3.c | 34 ++++++++- src/vec4.c | 38 ++++++++-- test/src/test_vec3.c | 33 ++++++++- test/src/test_vec4.c | 31 ++++++++ 12 files changed, 510 insertions(+), 72 deletions(-) diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index 0c5d590..86f17e4 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -38,9 +38,14 @@ Functions: #. :c:func:`glm_vec_norm2` #. :c:func:`glm_vec_norm` #. :c:func:`glm_vec_add` +#. :c:func:`glm_vec_adds` #. :c:func:`glm_vec_sub` +#. :c:func:`glm_vec_subs` +#. :c:func:`glm_vec_mul` #. :c:func:`glm_vec_scale` #. :c:func:`glm_vec_scale_as` +#. :c:func:`glm_vec_div` +#. :c:func:`glm_vec_divs` #. :c:func:`glm_vec_flipsign` #. :c:func:`glm_vec_flipsign_to` #. :c:func:`glm_vec_inv` @@ -133,24 +138,51 @@ Functions documentation Parameters: | *[in]* **vec** vector -.. c:function:: void glm_vec_add(vec3 v1, vec3 v2, vec3 dest) +.. c:function:: void glm_vec_add(vec3 a, vec3 b, vec3 dest) - add v2 vector to v1 vector store result in dest + add a vector to b vector store result in dest Parameters: - | *[in]* **v1** vector1 - | *[in]* **v2** vector2 + | *[in]* **a** vector1 + | *[in]* **b** vector2 + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec_adds(vec3 a, float s, vec3 dest) + + add scalar to v vector store result in dest (d = v + vec(s)) + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar | *[out]* **dest** destination vector .. c:function:: void glm_vec_sub(vec3 v1, vec3 v2, vec3 dest) - subtract v2 vector from v1 vector store result in dest + subtract b vector from a vector store result in dest (d = v1 - v2) Parameters: - | *[in]* **v1** vector1 - | *[in]* **v2** vector2 + | *[in]* **a** vector1 + | *[in]* **b** vector2 | *[out]* **dest** destination vector +.. c:function:: void glm_vec_subs(vec3 v, float s, vec3 dest) + + subtract scalar from v vector store result in dest (d = v - vec(s)) + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec_mul(vec3 a, vec3 b, vec3 d) + + multiply two vector (component-wise multiplication) + + Parameters: + | *[in]* **a** vector + | *[in]* **b** scalar + | *[out]* **d** result = (a[0] * b[0], a[1] * b[1], a[2] * b[2]) + .. c:function:: void glm_vec_scale(vec3 v, float s, vec3 dest) multiply/scale vec3 vector with scalar: result = v * s @@ -170,6 +202,24 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** destination vector +.. c:function:: void glm_vec_div(vec3 a, vec3 b, vec3 dest) + + div vector with another component-wise division: d = a / b + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** result = (a[0] / b[0], a[1] / b[1], a[2] / b[2]) + +.. c:function:: void glm_vec_divs(vec3 v, float s, vec3 dest) + + div vector with scalar: d = v / s + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s]) + .. c:function:: void glm_vec_flipsign(vec3 v) flip sign of all vec3 members diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index 8deed35..89ac5c2 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -30,9 +30,14 @@ Functions: #. :c:func:`glm_vec4_norm2` #. :c:func:`glm_vec4_norm` #. :c:func:`glm_vec4_add` +#. :c:func:`glm_vec4_adds` #. :c:func:`glm_vec4_sub` +#. :c:func:`glm_vec4_subs` +#. :c:func:`glm_vec4_mul` #. :c:func:`glm_vec4_scale` #. :c:func:`glm_vec4_scale_as` +#. :c:func:`glm_vec4_div` +#. :c:func:`glm_vec4_divs` #. :c:func:`glm_vec4_flipsign` #. :c:func:`glm_vec_flipsign_to` #. :c:func:`glm_vec4_inv` @@ -119,24 +124,51 @@ Functions documentation Parameters: | *[in]* **vec** vector -.. c:function:: void glm_vec4_add(vec4 v1, vec4 v2, vec4 dest) +.. c:function:: void glm_vec4_add(vec4 a, vec4 b, vec4 dest) - add v2 vector to v1 vector store result in dest + add a vector to b vector store result in dest Parameters: - | *[in]* **v1** vector1 - | *[in]* **v2** vector2 + | *[in]* **a** vector1 + | *[in]* **b** vector2 | *[out]* **dest** destination vector -.. c:function:: void glm_vec4_sub(vec4 v1, vec4 v2, vec4 dest) +.. c:function:: void glm_vec4_adds(vec4 v, float s, vec4 dest) - subtract v2 vector from v1 vector store result in dest + add scalar to v vector store result in dest (d = v + vec(s)) Parameters: - | *[in]* **v1** vector1 - | *[in]* **v2** vector2 + | *[in]* **v** vector + | *[in]* **s** scalar | *[out]* **dest** destination vector +.. c:function:: void glm_vec4_sub(vec4 a, vec4 b, vec4 dest) + + subtract b vector from a vector store result in dest (d = v1 - v2) + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec4_subs(vec4 v, float s, vec4 dest) + + subtract scalar from v vector store result in dest (d = v - vec(s)) + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec4_mul(vec4 a, vec4 b, vec4 d) + + multiply two vector (component-wise multiplication) + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + | *[out]* **dest** result = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]) + .. c:function:: void glm_vec4_scale(vec4 v, float s, vec4 dest) multiply/scale vec4 vector with scalar: result = v * s @@ -155,6 +187,24 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** destination vector +.. c:function:: void glm_vec4_div(vec4 a, vec4 b, vec4 dest) + + div vector with another component-wise division: d = v1 / v2 + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + | *[out]* **dest** result = (a[0] / b[0], a[1] / b[1], a[2] / b[2], a[3] / b[3]) + +.. c:function:: void glm_vec4_divs(vec4 v, float s, vec4 dest) + + div vector with scalar: d = v / s + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s, a[3] / s) + .. c:function:: void glm_vec4_flipsign(vec4 v) flip sign of all vec4 members diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 396972f..b2374e6 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -62,7 +62,19 @@ glmc_vec_add(vec3 v1, vec3 v2, vec3 dest); CGLM_EXPORT void -glmc_vec_sub(vec3 v1, vec3 v2, vec3 dest); +glmc_vec_adds(vec3 v, float s, vec3 dest); + +CGLM_EXPORT +void +glmc_vec_sub(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec_subs(vec3 v, float s, vec3 dest); + +CGLM_EXPORT +void +glmc_vec_mul(vec3 a, vec3 b, vec3 d); CGLM_EXPORT void @@ -72,6 +84,14 @@ CGLM_EXPORT void glmc_vec_scale_as(vec3 v, float s, vec3 dest); +CGLM_EXPORT +void +glmc_vec_div(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec_divs(vec3 a, float s, vec3 dest); + CGLM_EXPORT void glmc_vec_flipsign(vec3 v); diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index 95f91e2..b460962 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -59,11 +59,23 @@ glmc_vec4_normalize(vec4 v); CGLM_EXPORT void -glmc_vec4_add(vec4 v1, vec4 v2, vec4 dest); +glmc_vec4_add(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_sub(vec4 v1, vec4 v2, vec4 dest); +glmc_vec4_adds(vec4 v, float s, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_sub(vec4 a, vec4 b, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_subs(vec4 v, float s, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_mul(vec4 a, vec4 b, vec4 d); CGLM_EXPORT void @@ -73,6 +85,14 @@ CGLM_EXPORT void glmc_vec4_scale_as(vec3 v, float s, vec3 dest); +CGLM_EXPORT +void +glmc_vec4_div(vec4 a, vec4 b, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_divs(vec4 v, float s, vec4 dest); + CGLM_EXPORT void glmc_vec4_flipsign(vec4 v); diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index fb2a687..e12c133 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -32,7 +32,7 @@ #include /*! - * @brief multiplies individual items, just for convenient like SIMD + * @brief DEPRECATED! use glm_vec_mul * * @param[in] a vec1 * @param[in] b vec2 diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 2be7173..b3012b6 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -28,10 +28,15 @@ CGLM_INLINE void glm_vec_cross(vec3 a, vec3 b, vec3 d); CGLM_INLINE float glm_vec_norm2(vec3 v); CGLM_INLINE float glm_vec_norm(vec3 vec); - CGLM_INLINE void glm_vec_add(vec3 v1, vec3 v2, vec3 dest); - CGLM_INLINE void glm_vec_sub(vec3 v1, vec3 v2, vec3 dest); + CGLM_INLINE void glm_vec_add(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec_adds(vec3 a, float s, vec3 dest); + CGLM_INLINE void glm_vec_sub(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec_subs(vec3 a, float s, vec3 dest); + CGLM_INLINE void glm_vec_mul(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec_scale(vec3 v, float s, vec3 dest); CGLM_INLINE void glm_vec_scale_as(vec3 v, float s, vec3 dest); + CGLM_INLINE void glm_vec_div(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec_divs(vec3 a, float s, vec3 dest); CGLM_INLINE void glm_vec_flipsign(vec3 v); CGLM_INLINE void glm_vec_inv(vec3 v); CGLM_INLINE void glm_vec_inv_to(vec3 v, vec3 dest); @@ -110,7 +115,7 @@ glm_vec_copy(vec3 a, vec3 dest) { */ CGLM_INLINE void -glm_vec_zero(vec4 v) { +glm_vec_zero(vec3 v) { v[0] = 0.0f; v[1] = 0.0f; v[2] = 0.0f; @@ -123,7 +128,7 @@ glm_vec_zero(vec4 v) { */ CGLM_INLINE void -glm_vec_one(vec4 v) { +glm_vec_one(vec3 v) { v[0] = 1.0f; v[1] = 1.0f; v[2] = 1.0f; @@ -190,33 +195,78 @@ glm_vec_norm(vec3 vec) { } /*! - * @brief add v2 vector to v1 vector store result in dest + * @brief add a vector to b vector store result in dest * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] a vector1 + * @param[in] b vector2 * @param[out] dest destination vector */ CGLM_INLINE void -glm_vec_add(vec3 v1, vec3 v2, vec3 dest) { - dest[0] = v1[0] + v2[0]; - dest[1] = v1[1] + v2[1]; - dest[2] = v1[2] + v2[2]; +glm_vec_add(vec3 a, vec3 b, vec3 dest) { + dest[0] = a[0] + b[0]; + dest[1] = a[1] + b[1]; + dest[2] = a[2] + b[2]; +} + +/*! + * @brief add scalar to v vector store result in dest (d = v + s) + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec_adds(vec3 v, float s, vec3 dest) { + dest[0] = v[0] + s; + dest[1] = v[1] + s; + dest[2] = v[2] + s; } /*! * @brief subtract v2 vector from v1 vector store result in dest * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] a vector1 + * @param[in] b vector2 * @param[out] dest destination vector */ CGLM_INLINE void -glm_vec_sub(vec3 v1, vec3 v2, vec3 dest) { - dest[0] = v1[0] - v2[0]; - dest[1] = v1[1] - v2[1]; - dest[2] = v1[2] - v2[2]; +glm_vec_sub(vec3 a, vec3 b, vec3 dest) { + dest[0] = a[0] - b[0]; + dest[1] = a[1] - b[1]; + dest[2] = a[2] - b[2]; +} + +/*! + * @brief subtract scalar from v vector store result in dest (d = v - s) + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec_subs(vec3 v, float s, vec3 dest) { + dest[0] = v[0] - s; + dest[1] = v[1] - s; + dest[2] = v[2] - s; +} + +/*! + * @brief multiply two vector (component-wise multiplication) + * + * @param a v1 + * @param b v2 + * @param d v3 = (a[0] * b[0], a[1] * b[1], a[2] * b[2]) + */ +CGLM_INLINE +void +glm_vec_mul(vec3 a, vec3 b, vec3 d) { + d[0] = a[0] * b[0]; + d[1] = a[1] * b[1]; + d[2] = a[2] * b[2]; } /*! @@ -255,6 +305,36 @@ glm_vec_scale_as(vec3 v, float s, vec3 dest) { glm_vec_scale(v, s / norm, dest); } +/*! + * @brief div vector with another component-wise division: d = a / b + * + * @param[in] a vector 1 + * @param[in] b vector 2 + * @param[out] dest result = (a[0]/b[0], a[1]/b[1], a[2]/b[2]) + */ +CGLM_INLINE +void +glm_vec_div(vec3 a, vec3 b, vec3 dest) { + dest[0] = a[0] / b[0]; + dest[1] = a[1] / b[1]; + dest[2] = a[2] / b[2]; +} + +/*! + * @brief div vector with scalar: d = v / s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest result = (a[0]/s, a[1]/s, a[2]/s) + */ +CGLM_INLINE +void +glm_vec_divs(vec3 v, float s, vec3 dest) { + dest[0] = v[0] / s; + dest[1] = v[1] / s; + dest[2] = v[2] / s; +} + /*! * @brief flip sign of all vec3 members * diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index 53b02a8..7a6cb3d 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -32,7 +32,7 @@ #include /*! - * @brief multiplies individual items, just for convenient like SIMD + * @brief DEPRECATED! use glm_vec4_mul * * @param a v1 * @param b v2 diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index b28d9fd..e1319b9 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -28,10 +28,15 @@ CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b); CGLM_INLINE float glm_vec4_norm2(vec4 v); CGLM_INLINE float glm_vec4_norm(vec4 vec); - CGLM_INLINE void glm_vec4_add(vec4 v1, vec4 v2, vec4 dest); - CGLM_INLINE void glm_vec4_sub(vec4 v1, vec4 v2, vec4 dest); + CGLM_INLINE void glm_vec4_add(vec4 a, vec4 b, vec4 dest); + CGLM_INLINE void glm_vec4_adds(vec4 v, float s, vec4 dest); + CGLM_INLINE void glm_vec4_sub(vec4 a, vec4 b, vec4 dest); + CGLM_INLINE void glm_vec4_subs(vec4 v, float s, vec4 dest); + CGLM_INLINE void glm_vec4_mul(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_scale(vec4 v, float s, vec4 dest); CGLM_INLINE void glm_vec4_scale_as(vec4 v, float s, vec4 dest); + CGLM_INLINE void glm_vec4_div(vec4 a, vec4 b, vec4 dest); + CGLM_INLINE void glm_vec4_divs(vec4 v, float s, vec4 dest); CGLM_INLINE void glm_vec4_flipsign(vec4 v); CGLM_INLINE void glm_vec4_inv(vec4 v); CGLM_INLINE void glm_vec4_inv_to(vec4 v, vec4 dest); @@ -41,6 +46,7 @@ CGLM_INLINE void glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest); CGLM_INLINE void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest); CGLM_INLINE void glm_vec4_clamp(vec4 v, float minVal, float maxVal); + CGLM_INLINE void glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) */ #ifndef cglm_vec4_h @@ -215,44 +221,100 @@ glm_vec4_norm(vec4 vec) { /*! * @brief add v2 vector to v1 vector store result in dest * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] a vector1 + * @param[in] b vector2 * @param[out] dest destination vector */ CGLM_INLINE void -glm_vec4_add(vec4 v1, vec4 v2, vec4 dest) { +glm_vec4_add(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, - _mm_add_ps(_mm_load_ps(v1), - _mm_load_ps(v2))); + _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(a), _mm_load_ps(b))); #else - dest[0] = v1[0] + v2[0]; - dest[1] = v1[1] + v2[1]; - dest[2] = v1[2] + v2[2]; - dest[3] = v1[3] + v2[3]; + dest[0] = a[0] + b[0]; + dest[1] = a[1] + b[1]; + dest[2] = a[2] + b[2]; + dest[3] = a[3] + b[3]; #endif } /*! - * @brief subtract v2 vector from v1 vector store result in dest + * @brief add scalar to v vector store result in dest (d = v + vec(s)) * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] v vector + * @param[in] s scalar * @param[out] dest destination vector */ CGLM_INLINE void -glm_vec4_sub(vec4 v1, vec4 v2, vec4 dest) { +glm_vec4_adds(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, - _mm_sub_ps(_mm_load_ps(v1), - _mm_load_ps(v2))); + _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(v), _mm_set1_ps(s))); #else - dest[0] = v1[0] - v2[0]; - dest[1] = v1[1] - v2[1]; - dest[2] = v1[2] - v2[2]; - dest[3] = v1[3] - v2[3]; + dest[0] = v1[0] + s; + dest[1] = v1[1] + s; + dest[2] = v1[2] + s; + dest[3] = v1[3] + s; +#endif +} + +/*! + * @brief subtract b vector from a vector store result in dest (d = v1 - v2) + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_sub(vec4 a, vec4 b, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_sub_ps(_mm_load_ps(a), _mm_load_ps(b))); +#else + dest[0] = a[0] - b[0]; + dest[1] = a[1] - b[1]; + dest[2] = a[2] - b[2]; + dest[3] = a[3] - b[3]; +#endif +} + +/*! + * @brief subtract scalar from v vector store result in dest (d = v - vec(s)) + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_subs(vec4 v, float s, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_sub_ps(_mm_load_ps(v), _mm_set1_ps(s))); +#else + dest[0] = v1[0] - s; + dest[1] = v1[1] - s; + dest[2] = v1[2] - s; + dest[3] = v1[3] - s; +#endif +} + +/*! + * @brief multiply two vector (component-wise multiplication) + * + * @param a v1 + * @param b v2 + * @param d v3 = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]) + */ +CGLM_INLINE +void +glm_vec4_mul(vec4 a, vec4 b, vec4 d) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(d, _mm_mul_ps(_mm_load_ps(a), _mm_load_ps(b))); +#else + d[0] = a[0] * b[0]; + d[1] = a[1] * b[1]; + d[2] = a[2] * b[2]; + d[3] = a[3] * b[3]; #endif } @@ -267,9 +329,7 @@ CGLM_INLINE void glm_vec4_scale(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, - _mm_mul_ps(_mm_load_ps(v), - _mm_set1_ps(s))); + _mm_store_ps(dest, _mm_mul_ps(_mm_load_ps(v), _mm_set1_ps(s))); #else dest[0] = v[0] * s; dest[1] = v[1] * s; @@ -299,6 +359,43 @@ glm_vec4_scale_as(vec4 v, float s, vec4 dest) { glm_vec4_scale(v, s / norm, dest); } +/*! + * @brief div vector with another component-wise division: d = v1 / v2 + * + * @param[in] a vector 1 + * @param[in] b vector 2 + * @param[out] dest result = (a[0]/b[0], a[1]/b[1], a[2]/b[2], a[3]/b[3]) + */ +CGLM_INLINE +void +glm_vec4_div(vec4 a, vec4 b, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_div_ps(_mm_load_ps(a), _mm_load_ps(b))); +#else + dest[0] = a[0] / b[0]; + dest[1] = a[1] / b[1]; + dest[2] = a[2] / b[2]; + dest[3] = a[3] / b[3]; +#endif +} + +/*! + * @brief div vec4 vector with scalar: d = v / s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_divs(vec4 v, float s, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_div_ps(_mm_load_ps(v), _mm_set1_ps(s))); +#else + glm_vec4_scale(v, 1.0f / s, dest); +#endif +} + /*! * @brief flip sign of all vec4 members * @@ -308,8 +405,7 @@ CGLM_INLINE void glm_vec4_flipsign(vec4 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(v, _mm_xor_ps(_mm_load_ps(v), - _mm_set1_ps(-0.0f))); + _mm_store_ps(v, _mm_xor_ps(_mm_load_ps(v), _mm_set1_ps(-0.0f))); #else v[0] = -v[0]; v[1] = -v[1]; diff --git a/src/vec3.c b/src/vec3.c index f7c890e..b8553ec 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -76,8 +76,26 @@ glmc_vec_add(vec3 v1, vec3 v2, vec3 dest) { CGLM_EXPORT void -glmc_vec_sub(vec3 v1, vec3 v2, vec3 dest) { - glm_vec_sub(v1, v2, dest); +glmc_vec_adds(vec3 v, float s, vec3 dest) { + glm_vec_adds(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec_sub(vec3 a, vec3 b, vec3 dest) { + glm_vec_sub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec_subs(vec3 v, float s, vec3 dest) { + glm_vec_subs(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec_mul(vec3 a, vec3 b, vec3 d) { + glm_vec_mul(a, b, d); } CGLM_EXPORT @@ -92,6 +110,18 @@ glmc_vec_scale_as(vec3 v, float s, vec3 dest) { glm_vec_scale_as(v, s, dest); } +CGLM_EXPORT +void +glmc_vec_div(vec3 a, vec3 b, vec3 dest) { + glm_vec_div(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec_divs(vec3 a, float s, vec3 dest) { + glm_vec_divs(a, s, dest); +} + CGLM_EXPORT void glmc_vec_flipsign(vec3 v) { diff --git a/src/vec4.c b/src/vec4.c index df93556..282712c 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -70,14 +70,32 @@ glmc_vec4_norm2(vec4 vec) { CGLM_EXPORT void -glmc_vec4_add(vec4 v1, vec4 v2, vec4 dest) { - glm_vec4_add(v1, v2, dest); +glmc_vec4_add(vec4 a, vec4 b, vec4 dest) { + glm_vec4_add(a, b, dest); } CGLM_EXPORT void -glmc_vec4_sub(vec4 v1, vec4 v2, vec4 dest) { - glm_vec4_sub(v1, v2, dest); +glmc_vec4_adds(vec4 v, float s, vec4 dest) { + glm_vec4_adds(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec4_sub(vec4 a, vec4 b, vec4 dest) { + glm_vec4_sub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec4_subs(vec4 v, float s, vec4 dest) { + glm_vec4_subs(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec4_mul(vec4 a, vec4 b, vec4 d) { + glm_vec4_mul(a, b, d); } CGLM_EXPORT @@ -92,6 +110,18 @@ glmc_vec4_scale_as(vec3 v, float s, vec3 dest) { glm_vec4_scale_as(v, s, dest); } +CGLM_EXPORT +void +glmc_vec4_div(vec4 a, vec4 b, vec4 dest) { + glm_vec4_div(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec4_divs(vec4 v, float s, vec4 dest) { + glm_vec4_divs(v, s, dest); +} + CGLM_EXPORT void glmc_vec4_flipsign(vec4 v) { diff --git a/test/src/test_vec3.c b/test/src/test_vec3.c index 5a3a4c8..c33e5ec 100644 --- a/test/src/test_vec3.c +++ b/test/src/test_vec3.c @@ -9,7 +9,7 @@ void test_vec3(void **state) { - vec3 v; + vec3 v, v1; /* test zero */ glm_vec_zero(v); @@ -18,4 +18,35 @@ test_vec3(void **state) { /* test one */ glm_vec_one(v); test_assert_vec3_eq(GLM_VEC3_ONE, v); + + /* adds, subs, div, divs, mul */ + glm_vec_add(v, GLM_VEC3_ONE, v); + assert_true(glmc_vec_eq_eps(v, 2)); + + glm_vec_adds(v, 10, v); + assert_true(glmc_vec_eq_eps(v, 12)); + + glm_vec_sub(v, GLM_VEC3_ONE, v); + assert_true(glmc_vec_eq_eps(v, 11)); + + glm_vec_subs(v, 1, v); + assert_true(glmc_vec_eq_eps(v, 10)); + + glm_vec_broadcast(2, v1); + glm_vec_div(v, v1, v); + assert_true(glmc_vec_eq_eps(v, 5)); + + glm_vec_divs(v, 0.5, v); + assert_true(glmc_vec_eq_eps(v, 10)); + + glm_vec_mul(v, v1, v); + assert_true(glmc_vec_eq_eps(v, 20)); + + glm_vec_scale(v, 0.5, v); + assert_true(glmc_vec_eq_eps(v, 10)); + + glm_vec_normalize_to(v, v1); + glm_vec_scale(v1, 0.8, v1); + glm_vec_scale_as(v, 0.8, v); + test_assert_vec3_eq(v1, v); } diff --git a/test/src/test_vec4.c b/test/src/test_vec4.c index a80d9c7..60772a9 100644 --- a/test/src/test_vec4.c +++ b/test/src/test_vec4.c @@ -78,4 +78,35 @@ test_vec4(void **state) { /* test one */ glm_vec4_one(v); test_assert_vec4_eq(GLM_VEC4_ONE, v); + + /* adds, subs, div, divs, mul */ + glm_vec4_add(v, GLM_VEC4_ONE, v); + assert_true(glmc_vec4_eq_eps(v, 2)); + + glm_vec4_adds(v, 10, v); + assert_true(glmc_vec4_eq_eps(v, 12)); + + glm_vec4_sub(v, GLM_VEC4_ONE, v); + assert_true(glmc_vec4_eq_eps(v, 11)); + + glm_vec4_subs(v, 1, v); + assert_true(glmc_vec4_eq_eps(v, 10)); + + glm_vec4_broadcast(2, v1); + glm_vec4_div(v, v1, v); + assert_true(glmc_vec4_eq_eps(v, 5)); + + glm_vec4_divs(v, 0.5, v); + assert_true(glmc_vec4_eq_eps(v, 10)); + + glm_vec4_mul(v, v1, v); + assert_true(glmc_vec4_eq_eps(v, 20)); + + glm_vec4_scale(v, 0.5, v); + assert_true(glmc_vec4_eq_eps(v, 10)); + + glm_vec4_normalize_to(v, v1); + glm_vec4_scale(v1, 0.8, v1); + glm_vec4_scale_as(v, 0.8, v); + test_assert_vec4_eq(v1, v); } From c05f58a1699307c4ace5733dad8f6fa93f3801c2 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 13 Apr 2018 15:46:43 +0300 Subject: [PATCH 109/292] vec: add addadd, subadd and muladd helpers --- docs/source/vec3.rst | 33 +++++++++++++++++ docs/source/vec4.rst | 33 +++++++++++++++++ include/cglm/call/vec3.h | 12 +++++++ include/cglm/call/vec4.h | 12 +++++++ include/cglm/vec3.h | 54 ++++++++++++++++++++++++++++ include/cglm/vec4.h | 76 ++++++++++++++++++++++++++++++++++++++++ src/vec3.c | 18 ++++++++++ src/vec4.c | 20 ++++++++++- test/src/test_vec3.c | 16 ++++++++- test/src/test_vec4.c | 14 ++++++++ 10 files changed, 286 insertions(+), 2 deletions(-) diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index 86f17e4..1397700 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -46,6 +46,9 @@ Functions: #. :c:func:`glm_vec_scale_as` #. :c:func:`glm_vec_div` #. :c:func:`glm_vec_divs` +#. :c:func:`glm_vec_addadd` +#. :c:func:`glm_vec_subadd` +#. :c:func:`glm_vec_muladd` #. :c:func:`glm_vec_flipsign` #. :c:func:`glm_vec_flipsign_to` #. :c:func:`glm_vec_inv` @@ -220,6 +223,36 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s]) +.. c:function:: void glm_vec_addadd(vec3 a, vec3 b, vec3 dest) + + | add two vectors and add result to sum + | it applies += operator so dest must be initialized + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** dest += (a + b) + +.. c:function:: void glm_vec_subadd(vec3 a, vec3 b, vec3 dest) + + | sub two vectors and add result to sum + | it applies += operator so dest must be initialized + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** dest += (a - b) + +.. c:function:: void glm_vec_muladd(vec3 a, vec3 b, vec3 dest) + + | mul two vectors and add result to sum + | it applies += operator so dest must be initialized + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** dest += (a * b) + .. c:function:: void glm_vec_flipsign(vec3 v) flip sign of all vec3 members diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index 89ac5c2..bd27978 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -38,6 +38,9 @@ Functions: #. :c:func:`glm_vec4_scale_as` #. :c:func:`glm_vec4_div` #. :c:func:`glm_vec4_divs` +#. :c:func:`glm_vec4_addadd` +#. :c:func:`glm_vec4_subadd` +#. :c:func:`glm_vec4_muladd` #. :c:func:`glm_vec4_flipsign` #. :c:func:`glm_vec_flipsign_to` #. :c:func:`glm_vec4_inv` @@ -205,6 +208,36 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s, a[3] / s) +.. c:function:: void glm_vec4_addadd(vec4 a, vec4 b, vec4 dest) + + | add two vectors and add result to sum + | it applies += operator so dest must be initialized + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** dest += (a + b) + +.. c:function:: void glm_vec4_subadd(vec4 a, vec4 b, vec4 dest) + + | sub two vectors and add result to sum + | it applies += operator so dest must be initialized + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** dest += (a - b) + +.. c:function:: void glm_vec4_muladd(vec4 a, vec4 b, vec4 dest) + + | mul two vectors and add result to sum + | it applies += operator so dest must be initialized + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** dest += (a * b) + .. c:function:: void glm_vec4_flipsign(vec4 v) flip sign of all vec4 members diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index b2374e6..495ad0b 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -92,6 +92,18 @@ CGLM_EXPORT void glmc_vec_divs(vec3 a, float s, vec3 dest); +CGLM_EXPORT +void +glmc_vec_addadd(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec_subadd(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec_muladd(vec3 a, vec3 b, vec3 dest); + CGLM_EXPORT void glmc_vec_flipsign(vec3 v); diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index b460962..0fea5bf 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -93,6 +93,18 @@ CGLM_EXPORT void glmc_vec4_divs(vec4 v, float s, vec4 dest); +CGLM_EXPORT +void +glmc_vec4_addadd(vec4 a, vec4 b, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_subadd(vec4 a, vec4 b, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_muladd(vec4 a, vec4 b, vec4 dest); + CGLM_EXPORT void glmc_vec4_flipsign(vec4 v); diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index b3012b6..f803af6 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -37,6 +37,9 @@ CGLM_INLINE void glm_vec_scale_as(vec3 v, float s, vec3 dest); CGLM_INLINE void glm_vec_div(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec_divs(vec3 a, float s, vec3 dest); + CGLM_INLINE void glm_vec_addadd(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec_subadd(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec_muladd(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec_flipsign(vec3 v); CGLM_INLINE void glm_vec_inv(vec3 v); CGLM_INLINE void glm_vec_inv_to(vec3 v, vec3 dest); @@ -335,6 +338,57 @@ glm_vec_divs(vec3 v, float s, vec3 dest) { dest[2] = v[2] / s; } +/*! + * @brief add two vectors and add result to sum + * + * 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_vec_addadd(vec3 a, vec3 b, vec3 dest) { + dest[0] += a[0] + b[0]; + dest[1] += a[1] + b[1]; + dest[2] += a[2] + b[2]; +} + +/*! + * @brief sub two vectors and add 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_vec_subadd(vec3 a, vec3 b, vec3 dest) { + dest[0] += a[0] - b[0]; + dest[1] += a[1] - b[1]; + dest[2] += a[2] - b[2]; +} + +/*! + * @brief mul two vectors and add 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_vec_muladd(vec3 a, vec3 b, vec3 dest) { + dest[0] += a[0] * b[0]; + dest[1] += a[1] * b[1]; + dest[2] += a[2] * b[2]; +} + /*! * @brief flip sign of all vec3 members * diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index e1319b9..c07a45e 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -37,6 +37,9 @@ CGLM_INLINE void glm_vec4_scale_as(vec4 v, float s, vec4 dest); CGLM_INLINE void glm_vec4_div(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_divs(vec4 v, float s, vec4 dest); + CGLM_INLINE void glm_vec4_addadd(vec4 a, vec4 b, vec4 dest); + CGLM_INLINE void glm_vec4_subadd(vec4 a, vec4 b, vec4 dest); + CGLM_INLINE void glm_vec4_muladd(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_flipsign(vec4 v); CGLM_INLINE void glm_vec4_inv(vec4 v); CGLM_INLINE void glm_vec4_inv_to(vec4 v, vec4 dest); @@ -396,6 +399,79 @@ glm_vec4_divs(vec4 v, float s, vec4 dest) { #endif } + +/*! + * @brief add two vectors and add result to sum + * + * 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_vec4_addadd(vec4 a, vec4 b, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(dest), + _mm_add_ps(_mm_load_ps(a), + _mm_load_ps(b)))); +#else + dest[0] += a[0] + b[0]; + dest[1] += a[1] + b[1]; + dest[2] += a[2] + b[2]; + dest[3] += a[3] + b[3]; +#endif +} + +/*! + * @brief sub two vectors and add 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_vec4_subadd(vec4 a, vec4 b, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(dest), + _mm_sub_ps(_mm_load_ps(a), + _mm_load_ps(b)))); +#else + dest[0] += a[0] - b[0]; + dest[1] += a[1] - b[1]; + dest[2] += a[2] - b[2]; + dest[3] += a[3] - b[3]; +#endif +} + +/*! + * @brief mul two vectors and add 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_vec4_muladd(vec4 a, vec4 b, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(dest), + _mm_mul_ps(_mm_load_ps(a), + _mm_load_ps(b)))); +#else + dest[0] += a[0] * b[0]; + dest[1] += a[1] * b[1]; + dest[2] += a[2] * b[2]; + dest[3] += a[3] * b[3]; +#endif +} + /*! * @brief flip sign of all vec4 members * diff --git a/src/vec3.c b/src/vec3.c index b8553ec..d484446 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -122,6 +122,24 @@ glmc_vec_divs(vec3 a, float s, vec3 dest) { glm_vec_divs(a, s, dest); } +CGLM_EXPORT +void +glmc_vec_addadd(vec3 a, vec3 b, vec3 dest) { + glm_vec_addadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec_subadd(vec3 a, vec3 b, vec3 dest) { + glm_vec_subadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec_muladd(vec3 a, vec3 b, vec3 dest) { + glm_vec_muladd(a, b, dest); +} + CGLM_EXPORT void glmc_vec_flipsign(vec3 v) { diff --git a/src/vec4.c b/src/vec4.c index 282712c..c3df5d2 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -106,7 +106,7 @@ glmc_vec4_scale(vec4 v, float s, vec4 dest) { CGLM_EXPORT void -glmc_vec4_scale_as(vec3 v, float s, vec3 dest) { +glmc_vec4_scale_as(vec4 v, float s, vec4 dest) { glm_vec4_scale_as(v, s, dest); } @@ -122,6 +122,24 @@ glmc_vec4_divs(vec4 v, float s, vec4 dest) { glm_vec4_divs(v, s, dest); } +CGLM_EXPORT +void +glmc_vec4_addadd(vec4 a, vec4 b, vec4 dest) { + glm_vec4_addadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec4_subadd(vec4 a, vec4 b, vec4 dest) { + glm_vec4_subadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec4_muladd(vec4 a, vec4 b, vec4 dest) { + glm_vec4_muladd(a, b, dest); +} + CGLM_EXPORT void glmc_vec4_flipsign(vec4 v) { diff --git a/test/src/test_vec3.c b/test/src/test_vec3.c index c33e5ec..7c85d1f 100644 --- a/test/src/test_vec3.c +++ b/test/src/test_vec3.c @@ -9,7 +9,7 @@ void test_vec3(void **state) { - vec3 v, v1; + vec3 v, v1, v2; /* test zero */ glm_vec_zero(v); @@ -49,4 +49,18 @@ test_vec3(void **state) { glm_vec_scale(v1, 0.8, v1); glm_vec_scale_as(v, 0.8, v); test_assert_vec3_eq(v1, v); + + /* addadd, subadd, muladd */ + glm_vec_one(v); + + glm_vec_addadd(GLM_VEC3_ONE, GLM_VEC3_ONE, v); + assert_true(glmc_vec_eq_eps(v, 3)); + + glm_vec_subadd(GLM_VEC3_ONE, GLM_VEC3_ZERO, v); + assert_true(glmc_vec_eq_eps(v, 4)); + + glm_vec_broadcast(2, v1); + glm_vec_broadcast(3, v2); + glm_vec_muladd(v1, v2, v); + assert_true(glmc_vec_eq_eps(v, 10)); } diff --git a/test/src/test_vec4.c b/test/src/test_vec4.c index 60772a9..93ce9f7 100644 --- a/test/src/test_vec4.c +++ b/test/src/test_vec4.c @@ -109,4 +109,18 @@ test_vec4(void **state) { glm_vec4_scale(v1, 0.8, v1); glm_vec4_scale_as(v, 0.8, v); test_assert_vec4_eq(v1, v); + + /* addadd, subadd, muladd */ + glm_vec4_one(v); + + glm_vec4_addadd(GLM_VEC4_ONE, GLM_VEC4_ONE, v); + assert_true(glmc_vec4_eq_eps(v, 3)); + + glm_vec4_subadd(GLM_VEC4_ONE, GLM_VEC4_ZERO, v); + assert_true(glmc_vec4_eq_eps(v, 4)); + + glm_vec4_broadcast(2, v1); + glm_vec4_broadcast(3, v2); + glm_vec4_muladd(v1, v2, v); + assert_true(glmc_vec4_eq_eps(v, 10)); } From 725fac75d03863904c4295bbd638aa38dc7c0317 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 13 Apr 2018 15:47:45 +0300 Subject: [PATCH 110/292] now working on v0.4.1 --- configure.ac | 2 +- include/cglm/version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 6e22248..814f776 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.4.0], [info@recp.me]) +AC_INIT([cglm], [0.4.1], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/include/cglm/version.h b/include/cglm/version.h index 9a54b03..94fed8a 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 4 -#define CGLM_VERSION_PATCH 0 +#define CGLM_VERSION_PATCH 1 #endif /* cglm_version_h */ From 13345f06c131572d8bdc265a33b8993e916ca238 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 13 Apr 2018 15:50:05 +0300 Subject: [PATCH 111/292] fix vec4 scalar ops --- include/cglm/vec4.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index c07a45e..26247c7 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -198,7 +198,7 @@ glm_vec4_norm2(vec4 v) { x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 3, 2)); return _mm_cvtss_f32(_mm_add_ss(x0, _mm_shuffle1_ps(x0, 0, 1, 0, 1))); #else - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; + return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]; #endif } @@ -254,10 +254,10 @@ glm_vec4_adds(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(v), _mm_set1_ps(s))); #else - dest[0] = v1[0] + s; - dest[1] = v1[1] + s; - dest[2] = v1[2] + s; - dest[3] = v1[3] + s; + dest[0] = v[0] + s; + dest[1] = v[1] + s; + dest[2] = v[2] + s; + dest[3] = v[3] + s; #endif } @@ -294,10 +294,10 @@ glm_vec4_subs(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) _mm_store_ps(dest, _mm_sub_ps(_mm_load_ps(v), _mm_set1_ps(s))); #else - dest[0] = v1[0] - s; - dest[1] = v1[1] - s; - dest[2] = v1[2] - s; - dest[3] = v1[3] - s; + dest[0] = v[0] - s; + dest[1] = v[1] - s; + dest[2] = v[2] - s; + dest[3] = v[3] - s; #endif } From 7f7007574b11c9fc4d03f138d2fd16555c24e4bc Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 13 Apr 2018 22:30:44 +0300 Subject: [PATCH 112/292] vec: implement muladd's scalar version --- docs/source/vec3.rst | 11 +++++++++++ docs/source/vec4.rst | 11 +++++++++++ include/cglm/call/vec3.h | 4 ++++ include/cglm/call/vec4.h | 4 ++++ include/cglm/vec3.h | 17 +++++++++++++++++ include/cglm/vec4.h | 24 ++++++++++++++++++++++++ src/vec3.c | 6 ++++++ src/vec4.c | 6 ++++++ 8 files changed, 83 insertions(+) diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index 1397700..77aebb6 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -49,6 +49,7 @@ Functions: #. :c:func:`glm_vec_addadd` #. :c:func:`glm_vec_subadd` #. :c:func:`glm_vec_muladd` +#. :c:func:`glm_vec_muladds` #. :c:func:`glm_vec_flipsign` #. :c:func:`glm_vec_flipsign_to` #. :c:func:`glm_vec_inv` @@ -253,6 +254,16 @@ Functions documentation | *[in]* **b** vector 2 | *[out]* **dest** dest += (a * b) +.. c:function:: void glm_vec_muladds(vec3 a, float s, vec3 dest) + + | mul vector with scalar and add result to sum + | it applies += operator so dest must be initialized + + Parameters: + | *[in]* **a** vector + | *[in]* **s** scalar + | *[out]* **dest** dest += (a * b) + .. c:function:: void glm_vec_flipsign(vec3 v) flip sign of all vec3 members diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index bd27978..a1b7250 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -41,6 +41,7 @@ Functions: #. :c:func:`glm_vec4_addadd` #. :c:func:`glm_vec4_subadd` #. :c:func:`glm_vec4_muladd` +#. :c:func:`glm_vec4_muladds` #. :c:func:`glm_vec4_flipsign` #. :c:func:`glm_vec_flipsign_to` #. :c:func:`glm_vec4_inv` @@ -238,6 +239,16 @@ Functions documentation | *[in]* **b** vector 2 | *[out]* **dest** dest += (a * b) +.. c:function:: void glm_vec4_muladds(vec4 a, float s, vec4 dest) + + | mul vector with scalar and add result to sum + | it applies += operator so dest must be initialized + + Parameters: + | *[in]* **a** vector + | *[in]* **s** scalar + | *[out]* **dest** dest += (a * b) + .. c:function:: void glm_vec4_flipsign(vec4 v) flip sign of all vec4 members diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 495ad0b..8fcee4f 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -104,6 +104,10 @@ CGLM_EXPORT void glmc_vec_muladd(vec3 a, vec3 b, vec3 dest); +CGLM_EXPORT +void +glmc_vec_muladds(vec3 a, float s, vec3 dest); + CGLM_EXPORT void glmc_vec_flipsign(vec3 v); diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index 0fea5bf..adcfc94 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -105,6 +105,10 @@ CGLM_EXPORT void glmc_vec4_muladd(vec4 a, vec4 b, vec4 dest); +CGLM_EXPORT +void +glmc_vec4_muladds(vec4 a, float s, vec4 dest); + CGLM_EXPORT void glmc_vec4_flipsign(vec4 v); diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index f803af6..9add4c3 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -389,6 +389,23 @@ glm_vec_muladd(vec3 a, vec3 b, vec3 dest) { dest[2] += a[2] * b[2]; } +/*! + * @brief mul vector with scalar and add 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_vec_muladds(vec3 a, float s, vec3 dest) { + dest[0] += a[0] * s; + dest[1] += a[1] * s; + dest[2] += a[2] * s; +} + /*! * @brief flip sign of all vec3 members * diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 26247c7..1824357 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -472,6 +472,30 @@ glm_vec4_muladd(vec4 a, vec4 b, vec4 dest) { #endif } +/*! + * @brief mul vector with scalar and add 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_vec4_muladds(vec4 a, float s, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(dest), + _mm_mul_ps(_mm_load_ps(a), + _mm_set1_ps(s)))); +#else + dest[0] += a[0] * s; + dest[1] += a[1] * s; + dest[2] += a[2] * s; + dest[3] += a[3] * s; +#endif +} + /*! * @brief flip sign of all vec4 members * diff --git a/src/vec3.c b/src/vec3.c index d484446..28fda51 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -140,6 +140,12 @@ glmc_vec_muladd(vec3 a, vec3 b, vec3 dest) { glm_vec_muladd(a, b, dest); } +CGLM_EXPORT +void +glmc_vec_muladds(vec3 a, float s, vec3 dest) { + glm_vec_muladds(a, s, dest); +} + CGLM_EXPORT void glmc_vec_flipsign(vec3 v) { diff --git a/src/vec4.c b/src/vec4.c index c3df5d2..fb22796 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -140,6 +140,12 @@ glmc_vec4_muladd(vec4 a, vec4 b, vec4 dest) { glm_vec4_muladd(a, b, dest); } +CGLM_EXPORT +void +glmc_vec4_muladds(vec4 a, float s, vec4 dest) { + glm_vec4_muladds(a, s, dest); +} + CGLM_EXPORT void glmc_vec4_flipsign(vec4 v) { From d6395d4fb8dbfb90864ab8a6fd3456165236a956 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 13 Apr 2018 22:33:32 +0300 Subject: [PATCH 113/292] vec: optimize rotate vector using matrix * add mat3 version --- docs/source/vec3.rst | 10 +++++++++ include/cglm/vec3.h | 50 +++++++++++++++++++++++++++++++++++++------- test/src/test_vec3.c | 12 +++++++++++ 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index 77aebb6..fcbfbfb 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -60,6 +60,7 @@ Functions: #. :c:func:`glm_vec_angle` #. :c:func:`glm_vec_rotate` #. :c:func:`glm_vec_rotate_m4` +#. :c:func:`glm_vec_rotate_m3` #. :c:func:`glm_vec_proj` #. :c:func:`glm_vec_center` #. :c:func:`glm_vec_maxv` @@ -338,6 +339,15 @@ Functions documentation | *[in]* **v** vector | *[out]* **dest** rotated vector +.. c:function:: void glm_vec_rotate_m3(mat3 m, vec3 v, vec3 dest) + + apply rotation matrix to vector + + Parameters: + | *[in]* **m** affine matrix or rot matrix + | *[in]* **v** vector + | *[out]* **dest** rotated vector + .. c:function:: void glm_vec_proj(vec3 a, vec3 b, vec3 dest) project a vector onto b vector diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 9add4c3..9976ad9 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -67,6 +67,7 @@ #define cglm_vec3_h #include "common.h" +#include "vec4.h" #include "vec3-ext.h" #include "util.h" @@ -551,6 +552,12 @@ glm_vec_rotate(vec3 v, float angle, vec3 axis) { /*! * @brief apply rotation matrix to vector * + * matrix format should be (no perspective): + * a b c x + * e f g y + * i j k z + * 0 0 0 w + * * @param[in] m affine matrix or rot matrix * @param[in] v vector * @param[out] dest rotated vector @@ -558,17 +565,44 @@ glm_vec_rotate(vec3 v, float angle, vec3 axis) { CGLM_INLINE void glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) { - vec3 res, x, y, z; + vec4 x, y, z, res; - glm_vec_normalize_to(m[0], x); - glm_vec_normalize_to(m[1], y); - glm_vec_normalize_to(m[2], z); + glm_vec4_normalize_to(m[0], x); + glm_vec4_normalize_to(m[1], y); + glm_vec4_normalize_to(m[2], z); - res[0] = x[0] * v[0] + y[0] * v[1] + z[0] * v[2]; - res[1] = x[1] * v[0] + y[1] * v[1] + z[1] * v[2]; - res[2] = x[2] * v[0] + y[2] * v[1] + z[2] * v[2]; + glm_vec4_scale(x, v[0], res); + glm_vec4_muladds(y, v[1], res); + glm_vec4_muladds(y, v[2], res); - glm_vec_copy(res, dest); + glm_vec3(res, dest); +} + +/*! + * @brief apply rotation matrix to vector + * + * @param[in] m affine matrix or rot matrix + * @param[in] v vector + * @param[out] dest rotated vector + */ +CGLM_INLINE +void +glm_vec_rotate_m3(mat3 m, vec3 v, vec3 dest) { + vec4 res, x, y, z; + + glm_vec4(m[0], 0.0f, x); + glm_vec4(m[1], 0.0f, y); + glm_vec4(m[2], 0.0f, z); + + glm_vec4_normalize(x); + glm_vec4_normalize(y); + glm_vec4_normalize(z); + + glm_vec4_scale(x, v[0], res); + glm_vec4_muladds(y, v[1], res); + glm_vec4_muladds(y, v[2], res); + + glm_vec3(res, dest); } /*! diff --git a/test/src/test_vec3.c b/test/src/test_vec3.c index 7c85d1f..dd0c55d 100644 --- a/test/src/test_vec3.c +++ b/test/src/test_vec3.c @@ -9,6 +9,8 @@ void test_vec3(void **state) { + mat3 rot1m3; + mat4 rot1; vec3 v, v1, v2; /* test zero */ @@ -63,4 +65,14 @@ test_vec3(void **state) { glm_vec_broadcast(3, v2); glm_vec_muladd(v1, v2, v); assert_true(glmc_vec_eq_eps(v, 10)); + + /* rotate */ + glm_vec_copy(GLM_YUP, v); + glm_rotate_make(rot1, glm_rad(90), GLM_XUP); + glm_vec_rotate_m4(rot1, v, v1); + glm_mat4_pick3(rot1, rot1m3); + glm_vec_rotate_m3(rot1m3, v, v2); + + test_assert_vec3_eq(v1, v2); + test_assert_vec3_eq(v1, GLM_ZUP); } From 429aff087fb4a36e103de3ca95fb1ed113369637 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 14 Apr 2018 11:35:28 +0300 Subject: [PATCH 114/292] optimize min and max for vec4 --- include/cglm/vec4.h | 8 ++++++++ test/src/test_vec4.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 1824357..f52fd6a 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -633,10 +633,14 @@ glm_vec4_distance(vec4 v1, vec4 v2) { CGLM_INLINE void glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_max_ps(_mm_load_ps(v1), _mm_load_ps(v2))); +#else dest[0] = glm_max(v1[0], v2[0]); dest[1] = glm_max(v1[1], v2[1]); dest[2] = glm_max(v1[2], v2[2]); dest[3] = glm_max(v1[3], v2[3]); +#endif } /*! @@ -649,10 +653,14 @@ glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest) { CGLM_INLINE void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(dest, _mm_min_ps(_mm_load_ps(v1), _mm_load_ps(v2))); +#else dest[0] = glm_min(v1[0], v2[0]); dest[1] = glm_min(v1[1], v2[1]); dest[2] = glm_min(v1[2], v2[2]); dest[3] = glm_min(v1[3], v2[3]); +#endif } /*! diff --git a/test/src/test_vec4.c b/test/src/test_vec4.c index 93ce9f7..b9fb2ab 100644 --- a/test/src/test_vec4.c +++ b/test/src/test_vec4.c @@ -38,9 +38,25 @@ test_vec4_norm(vec4 vec) { return sqrtf(test_vec4_dot(vec, vec)); } +void +test_vec4_maxv(vec4 v1, vec4 v2, vec4 dest) { + dest[0] = glm_max(v1[0], v2[0]); + dest[1] = glm_max(v1[1], v2[1]); + dest[2] = glm_max(v1[2], v2[2]); + dest[3] = glm_max(v1[3], v2[3]); +} + +void +test_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { + dest[0] = glm_min(v1[0], v2[0]); + dest[1] = glm_min(v1[1], v2[1]); + dest[2] = glm_min(v1[2], v2[2]); + dest[3] = glm_min(v1[3], v2[3]); +} + void test_vec4(void **state) { - vec4 v, v1, v2; + vec4 v, v1, v2, v3, v4; int i; float d1, d2; @@ -123,4 +139,16 @@ test_vec4(void **state) { glm_vec4_broadcast(3, v2); glm_vec4_muladd(v1, v2, v); assert_true(glmc_vec4_eq_eps(v, 10)); + + /* min, max */ + test_rand_vec4(v1); + test_rand_vec4(v2); + + glm_vec4_maxv(v1, v2, v3); + test_vec4_maxv(v1, v2, v4); + test_assert_vec4_eq(v3, v4); + + glm_vec4_minv(v1, v2, v3); + test_vec4_minv(v1, v2, v4); + test_assert_vec4_eq(v3, v4); } From 59aacee968d55e4af179fe88dd8bd7c6df5bef89 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 14 Apr 2018 12:49:37 +0300 Subject: [PATCH 115/292] optimize clamp for vec4 --- include/cglm/vec4.h | 5 +++++ test/src/test_vec4.c | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index f52fd6a..aebef4a 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -673,10 +673,15 @@ glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { CGLM_INLINE void glm_vec4_clamp(vec4 v, float minVal, float maxVal) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + _mm_store_ps(v, _mm_min_ps(_mm_max_ps(_mm_load_ps(v), _mm_set1_ps(minVal)), + _mm_set1_ps(maxVal))); +#else v[0] = glm_clamp(v[0], minVal, maxVal); v[1] = glm_clamp(v[1], minVal, maxVal); v[2] = glm_clamp(v[2], minVal, maxVal); v[3] = glm_clamp(v[3], minVal, maxVal); +#endif } /*! diff --git a/test/src/test_vec4.c b/test/src/test_vec4.c index b9fb2ab..8e4fda5 100644 --- a/test/src/test_vec4.c +++ b/test/src/test_vec4.c @@ -54,6 +54,14 @@ test_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { dest[3] = glm_min(v1[3], v2[3]); } +void +test_vec4_clamp(vec4 v, float minVal, float maxVal) { + v[0] = glm_clamp(v[0], minVal, maxVal); + v[1] = glm_clamp(v[1], minVal, maxVal); + v[2] = glm_clamp(v[2], minVal, maxVal); + v[3] = glm_clamp(v[3], minVal, maxVal); +} + void test_vec4(void **state) { vec4 v, v1, v2, v3, v4; @@ -151,4 +159,20 @@ test_vec4(void **state) { glm_vec4_minv(v1, v2, v3); test_vec4_minv(v1, v2, v4); test_assert_vec4_eq(v3, v4); + + glm_vec4_print(v3, stderr); + glm_vec4_print(v4, stderr); + + /* clamp */ + glm_vec4_clamp(v3, 0.1, 0.8); + test_vec4_clamp(v4, 0.1, 0.8); + test_assert_vec4_eq(v3, v4); + + glm_vec4_print(v3, stderr); + glm_vec4_print(v4, stderr); + + assert_true(v3[0] >= 0.0999 && v3[0] <= 0.80001); /* rounding erros */ + assert_true(v3[1] >= 0.0999 && v3[1] <= 0.80001); + assert_true(v3[2] >= 0.0999 && v3[2] <= 0.80001); + assert_true(v3[3] >= 0.0999 && v3[3] <= 0.80001); } From b09b5f260b0f5fd5f0259804a568e0444c4b0014 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 15 Apr 2018 12:44:50 +0300 Subject: [PATCH 116/292] vec: fix rotate vector using mat4 and mat3 rotation matrices --- include/cglm/vec3.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 9976ad9..9bb9379 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -573,7 +573,7 @@ glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) { glm_vec4_scale(x, v[0], res); glm_vec4_muladds(y, v[1], res); - glm_vec4_muladds(y, v[2], res); + glm_vec4_muladds(z, v[2], res); glm_vec3(res, dest); } @@ -600,7 +600,7 @@ glm_vec_rotate_m3(mat3 m, vec3 v, vec3 dest) { glm_vec4_scale(x, v[0], res); glm_vec4_muladds(y, v[1], res); - glm_vec4_muladds(y, v[2], res); + glm_vec4_muladds(z, v[2], res); glm_vec3(res, dest); } From 826ddf0f5bf87a37d507c8cc122047c07383ebef Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 15 Apr 2018 12:46:29 +0300 Subject: [PATCH 117/292] improve normalize vectors --- include/cglm/vec3.h | 2 +- include/cglm/vec4.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 9bb9379..50636a1 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -492,7 +492,7 @@ glm_vec_normalize_to(vec3 vec, vec3 dest) { norm = glm_vec_norm(vec); if (norm == 0.0f) { - dest[0] = dest[1] = dest[2] = 0.0f; + glm_vec_zero(dest); return; } diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index aebef4a..2e9ca45 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -587,8 +587,7 @@ glm_vec4_normalize_to(vec4 vec, vec4 dest) { norm = glm_vec4_norm(vec); if (norm == 0.0f) { - dest[0] = dest[1] = dest[2] = dest[3] = 0.0f; - glm_vec4_broadcast(0.0f, dest); + glm_vec4_zero(dest); return; } From 007ae62e066d100fba598e4918d1c2fcfe06068e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 15 Apr 2018 13:10:07 +0300 Subject: [PATCH 118/292] update docs version --- docs/source/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 7ad96a1..616edfd 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.3.4' +version = u'0.4.1' # The full version, including alpha/beta/rc tags. -release = u'0.3.4' +release = u'0.4.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From f0a27d0ce2833dc99cd49a151aad59da3fc41646 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 15 Apr 2018 20:46:46 +0300 Subject: [PATCH 119/292] now working on v0.4.2 --- configure.ac | 2 +- include/cglm/version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 814f776..0fc55a8 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.4.1], [info@recp.me]) +AC_INIT([cglm], [0.4.2], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/include/cglm/version.h b/include/cglm/version.h index 94fed8a..328a4d2 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 4 -#define CGLM_VERSION_PATCH 1 +#define CGLM_VERSION_PATCH 2 #endif /* cglm_version_h */ From 821c79572f3f2631738c0cb9c5583349fdbf0d9a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 15 Apr 2018 20:47:38 +0300 Subject: [PATCH 120/292] test: add some tests for mat3 --- makefile.am | 3 ++- test/src/test_common.c | 23 +++++++++++++++++ test/src/test_common.h | 6 +++++ test/src/test_main.c | 3 +++ test/src/test_mat3.c | 58 ++++++++++++++++++++++++++++++++++++++++++ test/src/test_tests.h | 3 +++ 6 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 test/src/test_mat3.c diff --git a/makefile.am b/makefile.am index 00800c0..1a27132 100644 --- a/makefile.am +++ b/makefile.am @@ -111,7 +111,8 @@ test_tests_SOURCES=\ test/src/test_euler.c \ test/src/test_quat.c \ test/src/test_vec4.c \ - test/src/test_vec3.c + test/src/test_vec3.c \ + test/src/test_mat3.c all-local: sh ./post-build.sh diff --git a/test/src/test_common.c b/test/src/test_common.c index 60baac3..405000d 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -27,6 +27,17 @@ test_rand_mat4(mat4 dest) { /* glm_scale(dest, (vec3){drand48(), drand48(), drand48()}); */ } +void +test_rand_mat3(mat3 dest) { + mat4 m4; + + srand((unsigned int)time(NULL)); + + /* random rotatation around random axis with random angle */ + glm_rotate_make(m4, drand48(), (vec3){drand48(), drand48(), drand48()}); + glm_mat4_pick3(m4, dest); +} + void test_rand_vec3(vec3 dest) { srand((unsigned int)time(NULL)); @@ -84,6 +95,18 @@ test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps) { } } +void +test_assert_mat3_eq(mat3 m1, mat3 m2) { + int i, j, k; + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + for (k = 0; k < 3; k++) + assert_true(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009); + } + } +} + void test_assert_eqf(float a, float b) { assert_true(fabsf(a - b) <= 0.000009); /* rounding errors */ diff --git a/test/src/test_common.h b/test/src/test_common.h index db113a4..7881e7a 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -25,6 +25,9 @@ void test_rand_mat4(mat4 dest); +void +test_rand_mat3(mat3 dest); + void test_assert_eqf(float a, float b); @@ -34,6 +37,9 @@ test_assert_mat4_eq(mat4 m1, mat4 m2); void test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps); +void +test_assert_mat3_eq(mat3 m1, mat3 m2); + void test_assert_vec3_eq(vec3 v1, vec3 v2); diff --git a/test/src/test_main.c b/test/src/test_main.c index b0649cd..9e4f5aa 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -12,6 +12,9 @@ main(int argc, const char * argv[]) { /* mat4 */ cmocka_unit_test(test_mat4), + /* mat3 */ + cmocka_unit_test(test_mat3), + /* camera */ cmocka_unit_test(test_camera_lookat), cmocka_unit_test(test_camera_decomp), diff --git a/test/src/test_mat3.c b/test/src/test_mat3.c new file mode 100644 index 0000000..d97d1f5 --- /dev/null +++ b/test/src/test_mat3.c @@ -0,0 +1,58 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +#define m 3 +#define n 3 + +void +test_mat3(void **state) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT; + mat3 m2 = GLM_MAT3_IDENTITY_INIT; + mat3 m3; + mat3 m4 = GLM_MAT3_ZERO_INIT; + mat3 m5; + int i, j, k; + + /* test identity matrix multiplication */ + glmc_mat3_mul(m1, m2, m3); + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { + if (i == j) + assert_true(m3[i][j] == 1.0f); + else + assert_true(m3[i][j] == 0.0f); + } + } + + /* test random matrices */ + /* random matrices */ + test_rand_mat3(m1); + test_rand_mat3(m2); + + glmc_mat3_mul(m1, m2, m3); + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { + for (k = 0; k < m; k++) + /* column-major */ + m4[i][j] += m1[k][j] * m2[i][k]; + } + } + + test_assert_mat3_eq(m3, m4); + + for (i = 0; i < 100000; i++) { + test_rand_mat3(m3); + test_rand_mat3(m4); + + /* test inverse precise */ + glmc_mat3_inv(m3, m4); + glmc_mat3_inv(m4, m5); + test_assert_mat3_eq(m3, m5); + } +} diff --git a/test/src/test_tests.h b/test/src/test_tests.h index 224d943..dea8860 100644 --- a/test/src/test_tests.h +++ b/test/src/test_tests.h @@ -9,6 +9,9 @@ /* mat4 */ void test_mat4(void **state); +/* mat3 */ +void test_mat3(void **state); + /* camera */ void test_camera_lookat(void **state); From cefd5fb53d50e0b3089ab075fc220c8c3ae630a1 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 17 Apr 2018 10:33:52 +0300 Subject: [PATCH 121/292] test: add some tests for affine transforms --- makefile.am | 3 +- test/src/test_affine.c | 104 +++++++++++++++++++++++++++++++++++++++++ test/src/test_main.c | 5 +- test/src/test_tests.h | 3 ++ 4 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 test/src/test_affine.c diff --git a/makefile.am b/makefile.am index 1a27132..a0c06a9 100644 --- a/makefile.am +++ b/makefile.am @@ -112,7 +112,8 @@ test_tests_SOURCES=\ test/src/test_quat.c \ test/src/test_vec4.c \ test/src/test_vec3.c \ - test/src/test_mat3.c + test/src/test_mat3.c \ + test/src/test_affine.c all-local: sh ./post-build.sh diff --git a/test/src/test_affine.c b/test/src/test_affine.c new file mode 100644 index 0000000..4ce4a42 --- /dev/null +++ b/test/src/test_affine.c @@ -0,0 +1,104 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +void +test_affine(void **state) { + mat4 t1, t2, t3, t4, t5; + + /* test translate is postmultiplied */ + glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glm_translate_make(t2, (vec3){34, 57, 36}); + + glmc_mat4_mul(t1, t2, t3); /* R * T */ + + glm_translate(t1, (vec3){34, 57, 36}); + test_assert_mat4_eq(t1, t3); + + /* test rotate is postmultiplied */ + glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glm_translate_make(t2, (vec3){34, 57, 36}); + + glmc_mat4_mul(t2, t1, t3); /* T * R */ + + glm_rotate(t2, M_PI_4, GLM_YUP); + test_assert_mat4_eq(t2, t3); + + /* test scale is postmultiplied */ + glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glm_translate_make(t2, (vec3){34, 57, 36}); + glm_scale_make(t4, (vec3){3, 5, 6}); + + glmc_mat4_mul(t2, t1, t3); /* T * R */ + glmc_mat4_mul(t3, t4, t5); /* T * R * S */ + + glm_scale(t3, (vec3){3, 5, 6}); + test_assert_mat4_eq(t3, t5); + + /* test translate_x */ + glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glm_translate_make(t2, (vec3){34, 0, 0}); + + glmc_mat4_mul(t1, t2, t3); /* R * T */ + glm_translate_x(t1, 34); + test_assert_mat4_eq(t1, t3); + + /* test translate_y */ + glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glm_translate_make(t2, (vec3){0, 57, 0}); + + glmc_mat4_mul(t1, t2, t3); /* R * T */ + glm_translate_y(t1, 57); + test_assert_mat4_eq(t1, t3); + + /* test translate_z */ + glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glm_translate_make(t2, (vec3){0, 0, 36}); + + glmc_mat4_mul(t1, t2, t3); /* R * T */ + glm_translate_z(t1, 36); + test_assert_mat4_eq(t1, t3); + + /* test rotate_x */ + glmc_rotate_make(t1, M_PI_4, (vec3){1, 0, 0}); + glm_translate_make(t2, (vec3){34, 57, 36}); + + glmc_mat4_mul(t2, t1, t3); /* T * R */ + + glm_rotate_x(t2, M_PI_4, t2); + test_assert_mat4_eq(t2, t3); + + /* test rotate_y */ + glmc_rotate_make(t1, M_PI_4, (vec3){0, 1, 0}); + glm_translate_make(t2, (vec3){34, 57, 36}); + + glmc_mat4_mul(t2, t1, t3); /* T * R */ + + glm_rotate_y(t2, M_PI_4, t2); + test_assert_mat4_eq(t2, t3); + + /* test rotate_z */ + glmc_rotate_make(t1, M_PI_4, (vec3){0, 0, 1}); + glm_translate_make(t2, (vec3){34, 57, 36}); + + glmc_mat4_mul(t2, t1, t3); /* T * R */ + + glm_rotate_z(t2, M_PI_4, t2); + test_assert_mat4_eq(t2, t3); + + /* test scale_uni */ + glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glm_translate_make(t2, (vec3){34, 57, 36}); + glm_scale_make(t4, (vec3){3, 3, 3}); + + glmc_mat4_mul(t2, t1, t3); /* T * R */ + glmc_mat4_mul(t3, t4, t5); /* T * R * S */ + + glm_scale_uni(t3, 3); + test_assert_mat4_eq(t3, t5); +} diff --git a/test/src/test_main.c b/test/src/test_main.c index 9e4f5aa..ff77b02 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -35,7 +35,10 @@ main(int argc, const char * argv[]) { cmocka_unit_test(test_vec4), /* vec3 */ - cmocka_unit_test(test_vec3) + cmocka_unit_test(test_vec3), + + /* affine */ + cmocka_unit_test(test_affine) }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/test/src/test_tests.h b/test/src/test_tests.h index dea8860..7b9cf0a 100644 --- a/test/src/test_tests.h +++ b/test/src/test_tests.h @@ -37,4 +37,7 @@ test_vec4(void **state); void test_vec3(void **state); +void +test_affine(void **state); + #endif /* test_tests_h */ From a2792178dba99301e4524a30be4338673930d12c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 17 Apr 2018 11:07:57 +0300 Subject: [PATCH 122/292] add missing call funcs for affine transforms --- include/cglm/call/affine.h | 16 ++++++++++++++++ src/affine.c | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/cglm/call/affine.h b/include/cglm/call/affine.h index 3d462ee..65dfae0 100644 --- a/include/cglm/call/affine.h +++ b/include/cglm/call/affine.h @@ -13,6 +13,10 @@ extern "C" { #include "../cglm.h" +CGLM_EXPORT +void +glmc_translate_make(mat4 m, vec3 v); + CGLM_EXPORT void glmc_translate_to(mat4 m, vec3 v, mat4 dest); @@ -33,6 +37,10 @@ CGLM_EXPORT void glmc_translate_z(mat4 m, float to); +CGLM_EXPORT +void +glmc_scale_make(mat4 m, vec3 v); + CGLM_EXPORT void glmc_scale_to(mat4 m, vec3 v, mat4 dest); @@ -45,6 +53,10 @@ CGLM_EXPORT void glmc_scale1(mat4 m, float s); +CGLM_EXPORT +void +glmc_scale_uni(mat4 m, float s); + CGLM_EXPORT void glmc_rotate_x(mat4 m, float rad, mat4 dest); @@ -77,6 +89,10 @@ CGLM_EXPORT void glmc_decompose_scalev(mat4 m, vec3 s); +CGLM_EXPORT +bool +glmc_uniscaled(mat4 m); + CGLM_EXPORT void glmc_decompose_rs(mat4 m, mat4 r, vec3 s); diff --git a/src/affine.c b/src/affine.c index df591df..056947f 100644 --- a/src/affine.c +++ b/src/affine.c @@ -8,6 +8,12 @@ #include "../include/cglm/cglm.h" #include "../include/cglm/call.h" +CGLM_EXPORT +void +glmc_translate_make(mat4 m, vec3 v) { + glm_translate_make(m, v); +} + CGLM_EXPORT void glmc_translate_to(mat4 m, vec3 v, mat4 dest) { @@ -38,6 +44,12 @@ glmc_translate_z(mat4 m, float to) { glm_translate_z(m, to); } +CGLM_EXPORT +void +glmc_scale_make(mat4 m, vec3 v) { + glm_scale_make(m, v); +} + CGLM_EXPORT void glmc_scale_to(mat4 m, vec3 v, mat4 dest) { @@ -56,6 +68,12 @@ glmc_scale1(mat4 m, float s) { glm_scale1(m, s); } +CGLM_EXPORT +void +glmc_scale_uni(mat4 m, float s) { + glm_scale_uni(m, s); +} + CGLM_EXPORT void glmc_rotate_x(mat4 m, float rad, mat4 dest) { @@ -104,6 +122,12 @@ glmc_decompose_scalev(mat4 m, vec3 s) { glm_decompose_scalev(m, s); } +CGLM_EXPORT +bool +glmc_uniscaled(mat4 m) { + return glm_uniscaled(m); +} + CGLM_EXPORT void glmc_decompose_rs(mat4 m, mat4 r, vec3 s) { From c63c6c90aceb7e8ead996775dc9c83f699f60514 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 17 Apr 2018 11:12:18 +0300 Subject: [PATCH 123/292] implement rotate_at --- include/cglm/affine.h | 24 ++++++++++++++++++++++-- include/cglm/call/affine.h | 4 ++++ src/affine.c | 6 ++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/include/cglm/affine.h b/include/cglm/affine.h index 10f190f..39c4290 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -400,7 +400,7 @@ glm_rotate_make(mat4 m, float angle, vec3 axis) { } /*! - * @brief rotate existing transform matrix around Z axis by angle and axis + * @brief rotate existing transform matrix around given axis by angle * * this name may change in the future, axis must be normalized. * @@ -439,7 +439,7 @@ glm_rotate_ndc(mat4 m, float angle, vec3 axis_ndc) { } /*! - * @brief rotate existing transform matrix around Z axis by angle and axis + * @brief rotate existing transform matrix around given axis by angle * * @param[in, out] m affine transfrom * @param[in] angle angle (radians) @@ -454,6 +454,26 @@ glm_rotate(mat4 m, float angle, vec3 axis) { glm_rotate_ndc(m, angle, axis_ndc); } +/*! + * @brief rotate existing transform + * around given axis by angle at given pivot point (rotation center) + * + * @param[in, out] m affine transfrom + * @param[in] angle angle (radians) + * @param[in] axis axis + */ +CGLM_INLINE +void +glm_rotate_at(mat4 model, vec3 pivot, float angle, vec3 axis) { + vec3 pivotInv; + + glm_vec_inv_to(pivot, pivotInv); + + glm_translate(model, pivot); + glm_rotate(model, angle, axis); + glm_translate(model, pivotInv); +} + /*! * @brief decompose scale vector * diff --git a/include/cglm/call/affine.h b/include/cglm/call/affine.h index 65dfae0..6d6b872 100644 --- a/include/cglm/call/affine.h +++ b/include/cglm/call/affine.h @@ -85,6 +85,10 @@ CGLM_EXPORT void glmc_rotate(mat4 m, float angle, vec3 axis); +CGLM_EXPORT +void +glmc_rotate_at(mat4 model, vec3 pivot, float angle, vec3 axis); + CGLM_EXPORT void glmc_decompose_scalev(mat4 m, vec3 s); diff --git a/src/affine.c b/src/affine.c index 056947f..793d8ee 100644 --- a/src/affine.c +++ b/src/affine.c @@ -116,6 +116,12 @@ glmc_rotate(mat4 m, float angle, vec3 axis) { glm_rotate(m, angle, axis); } +CGLM_EXPORT +void +glmc_rotate_at(mat4 model, vec3 pivot, float angle, vec3 axis) { + glm_rotate_at(model, pivot, angle, axis); +} + CGLM_EXPORT void glmc_decompose_scalev(mat4 m, vec3 s) { From 33e951fe2e738cf8a6c8185c181a285ac6964102 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 17 Apr 2018 12:17:04 +0300 Subject: [PATCH 124/292] implement rotate_at for quat and provide make version --- include/cglm/affine.h | 40 ++++++++++++++++++++++++++--- include/cglm/call/affine.h | 6 ++++- include/cglm/call/quat.h | 8 ++++++ include/cglm/quat.h | 52 ++++++++++++++++++++++++++++++++++++++ src/affine.c | 10 ++++++-- src/quat.c | 12 +++++++++ 6 files changed, 121 insertions(+), 7 deletions(-) diff --git a/include/cglm/affine.h b/include/cglm/affine.h index 39c4290..a5abbb6 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -38,6 +38,11 @@ #include "vec4.h" #include "affine-mat.h" #include "util.h" +#include "mat4.h" + +CGLM_INLINE +void +glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest); /*! * @brief translate existing transform matrix by v vector @@ -459,19 +464,46 @@ glm_rotate(mat4 m, float angle, vec3 axis) { * around given axis by angle at given pivot point (rotation center) * * @param[in, out] m affine transfrom + * @param[in] pivot rotation center * @param[in] angle angle (radians) * @param[in] axis axis */ CGLM_INLINE void -glm_rotate_at(mat4 model, vec3 pivot, float angle, vec3 axis) { +glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) { vec3 pivotInv; glm_vec_inv_to(pivot, pivotInv); - glm_translate(model, pivot); - glm_rotate(model, angle, axis); - glm_translate(model, pivotInv); + glm_translate(m, pivot); + glm_rotate(m, angle, axis); + glm_translate(m, pivotInv); +} + +/*! + * @brief creates NEW rotation matrix by angle and axis at given point + * + * this creates rotation matrix, it assumes you don't have a matrix + * + * this should work faster than glm_rotate_at because it reduces + * one glm_translate. + * + * @param[out] m affine transfrom + * @param[in] pivot rotation center + * @param[in] angle angle (radians) + * @param[in] axis axis + */ +CGLM_INLINE +void +glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) { + vec3 pivotInv; + + glm_vec_inv_to(pivot, pivotInv); + + glm_mat4_identity(m); + glm_vec_copy(pivot, m[3]); + glm_rotate(m, angle, axis); + glm_translate(m, pivotInv); } /*! diff --git a/include/cglm/call/affine.h b/include/cglm/call/affine.h index 6d6b872..a9982c2 100644 --- a/include/cglm/call/affine.h +++ b/include/cglm/call/affine.h @@ -87,7 +87,11 @@ glmc_rotate(mat4 m, float angle, vec3 axis); CGLM_EXPORT void -glmc_rotate_at(mat4 model, vec3 pivot, float angle, vec3 axis); +glmc_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis); + +CGLM_EXPORT +void +glmc_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis); CGLM_EXPORT void diff --git a/include/cglm/call/quat.h b/include/cglm/call/quat.h index d250f52..ae4c9ef 100644 --- a/include/cglm/call/quat.h +++ b/include/cglm/call/quat.h @@ -137,6 +137,14 @@ CGLM_EXPORT void glmc_quat_rotate(mat4 m, versor q, mat4 dest); +CGLM_EXPORT +void +glmc_quat_rotate_at(mat4 model, versor q, vec3 pivot); + +CGLM_EXPORT +void +glmc_quat_rotate_atm(mat4 m, versor q, vec3 pivot); + #ifdef __cplusplus } #endif diff --git a/include/cglm/quat.h b/include/cglm/quat.h index fa356d4..1139c1d 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -60,6 +60,10 @@ # include "simd/sse2/quat.h" #endif +CGLM_INLINE +void +glm_mat4_identity(mat4 mat); + CGLM_INLINE void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); @@ -68,6 +72,10 @@ CGLM_INLINE void glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest); +CGLM_INLINE +void +glm_translate(mat4 m, vec3 v); + /* * IMPORTANT: * ---------------------------------------------------------------------------- @@ -740,4 +748,48 @@ glm_quat_rotate(mat4 m, versor q, mat4 dest) { glm_mat4_mul(m, rot, dest); } +/*! + * @brief rotate existing transform matrix using quaternion at pivot point + * + * @param[in, out] m existing transform matrix + * @param[in] q quaternion + * @param[out] pivot pivot + */ +CGLM_INLINE +void +glm_quat_rotate_at(mat4 model, versor q, vec3 pivot) { + vec3 pivotInv; + + glm_vec_inv_to(pivot, pivotInv); + + glm_translate(model, pivot); + glm_quat_rotate(model, q, model); + glm_translate(model, pivotInv); +} + +/*! + * @brief rotate NEW transform matrix using quaternion at pivot point + * + * this creates rotation matrix, it assumes you don't have a matrix + * + * this should work faster than glm_quat_rotate_at because it reduces + * one glm_translate. + * + * @param[out] m existing transform matrix + * @param[in] q quaternion + * @param[in] pivot pivot + */ +CGLM_INLINE +void +glm_quat_rotate_atm(mat4 m, versor q, vec3 pivot) { + vec3 pivotInv; + + glm_vec_inv_to(pivot, pivotInv); + + glm_mat4_identity(m); + glm_vec_copy(pivot, m[3]); + glm_quat_rotate(m, q, m); + glm_translate(m, pivotInv); +} + #endif /* cglm_quat_h */ diff --git a/src/affine.c b/src/affine.c index 793d8ee..1da12d6 100644 --- a/src/affine.c +++ b/src/affine.c @@ -118,8 +118,14 @@ glmc_rotate(mat4 m, float angle, vec3 axis) { CGLM_EXPORT void -glmc_rotate_at(mat4 model, vec3 pivot, float angle, vec3 axis) { - glm_rotate_at(model, pivot, angle, axis); +glmc_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) { + glm_rotate_at(m, pivot, angle, axis); +} + +CGLM_EXPORT +void +glmc_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) { + glm_rotate_atm(m, pivot, angle, axis); } CGLM_EXPORT diff --git a/src/quat.c b/src/quat.c index 8a9a463..c47761d 100644 --- a/src/quat.c +++ b/src/quat.c @@ -194,3 +194,15 @@ void glmc_quat_rotate(mat4 m, versor q, mat4 dest) { glm_quat_rotate(m, q, dest); } + +CGLM_EXPORT +void +glmc_quat_rotate_at(mat4 model, versor q, vec3 pivot) { + glm_quat_rotate_at(model, q, pivot); +} + +CGLM_EXPORT +void +glmc_quat_rotate_atm(mat4 m, versor q, vec3 pivot) { + glm_quat_rotate_atm(m, q, pivot); +} From 27ab6a7dd0c268df32f0d7b57aa6eca5c7d6d970 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 17 Apr 2018 15:42:24 +0300 Subject: [PATCH 125/292] update docs, add clarifications for affine transforms --- docs/source/affine.rst | 117 +++++++++++++++++++++++++++++++++++++++++ docs/source/quat.rst | 24 +++++++++ include/cglm/affine.h | 4 +- include/cglm/quat.h | 8 +-- 4 files changed, 148 insertions(+), 5 deletions(-) diff --git a/docs/source/affine.rst b/docs/source/affine.rst index c34921f..8eaf01c 100644 --- a/docs/source/affine.rst +++ b/docs/source/affine.rst @@ -5,6 +5,8 @@ affine transforms Header: cglm/affine.h +Initialize Transform Matrices +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Functions with **_make** prefix expect you don't have a matrix and they create a matrix for you. You don't need to pass identity matrix. @@ -15,6 +17,96 @@ before sending to transfrom functions. There are also functions to decompose transform matrix. These functions can't decompose matrix after projected. +Rotation Center +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Rotating functions uses origin as rotation center (pivot/anchor point), +since scale factors are stored in rotation matrix, same may also true for scalling. +cglm provides some functions for rotating around at given point e.g. +**glm_rotate_at**, **glm_quat_rotate_at**. Use them or follow next section for algorihm ("Rotate or Scale around specific Point (Pivot Point / Anchor Point)"). + +Rotate or Scale around specific Point (Anchor Point) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you want to rotate model around arbibtrary point follow these steps: + +1. Move model from pivot point to origin: **translate(-pivot.x, -pivot.y, -pivot.z)** +2. Apply rotation (or scaling maybe) +3. Move model back from origin to pivot (reverse of step-1): **translate(pivot.x, pivot.y, pivot.z)** + +**glm_rotate_at**, **glm_quat_rotate_at** and their helper functions works that way. + +Transforms Order +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +It is important to understand this part especially if you call transform +functions multiple times + +`glm_translate`, `glm_rotate`, `glm_scale` and `glm_quat_rotate` and their +helpers functions works like this (cglm may provide reverse order too as alternative in the future): + +.. code-block:: c + :linenos: + + TransformMatrix = TransformMatrix * TraslateMatrix; // glm_translate() + TransformMatrix = TransformMatrix * RotateMatrix; // glm_rotate(), glm_quat_rotate() + TransformMatrix = TransformMatrix * ScaleMatrix; // glm_scale() + +As you can see it is multipled as right matrix. For instance what will happen if you call `glm_translate` twice? + +.. code-block:: c + :linenos: + + glm_translate(transform, translate1); /* transform = transform * translate1 */ + glm_translate(transform, translate2); /* transform = transform * translate2 */ + glm_rotate(transform, angle, axis) /* transform = transform * rotation */ + +Now lets try to understand this: + +1. You call translate using `translate1` and you expect it will be first transform +because you call it first, do you? + +Result will be **`transform = transform * translate1`** + +2. Then you call translate using `translate2` and you expect it will be second transform, really? + +Result will be **`transform = transform * translate2`**. Now lets expand transform, +it was `transform * translate1` before second call. + +Now it is **`transform = transform * translate1 * translate2`**, now do you understand what I say? + +3. After last call transform will be: + +**`transform = transform * translate1 * translate2 * rotation`** + +The order will be; **rotation will be applied first**, then **translate2** then **translate1** + +It is all about matrix multiplication order. It is similar to MVP matrix: +`MVP = Projection * View * Model`, model will be applied first, then view then projection. + +**Confused?** + +As alternative way, you can create transform matrices individually then combine manually, +but don't forget that `glm_translate`, `glm_rotate`, `glm_scale`... are optimized and should be faster (an smaller assembly output) than manual multiplication + +.. code-block:: c + :linenos: + + mat4 transform1, transform2, transform3, finalTransform; + + glm_translate_make(transform1, translate1); + glm_translate_make(transform2, translate2); + glm_rotate_make(transform3, angle, axis); + + /* first apply transform1, then transform2, thentransform3 */ + glm_mat4_mulN((mat4 *[]){&transform3, &transform2, &transform1}, 3, finalTransform); + + /* if you don't want to use mulN, same as above */ + glm_mat4_mul(transform3, transform2, finalTransform); + glm_mat4_mul(finalTransform, transform1, finalTransform); + +Now transform1 will be applied first, then transform2 then transform3 + Table of contents (click to go): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -38,6 +130,8 @@ Functions: #. :c:func:`glm_rotate_make` #. :c:func:`glm_rotate_ndc` #. :c:func:`glm_rotate` +#. :c:func:`glm_rotate_at` +#. :c:func:`glm_rotate_atm` #. :c:func:`glm_decompose_scalev` #. :c:func:`glm_uniscaled` #. :c:func:`glm_decompose_rs` @@ -204,6 +298,29 @@ Functions documentation | *[in]* **angle** angle (radians) | *[in]* **axis** axis +.. c:function:: void glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) + + rotate existing transform around given axis by angle at given pivot point (rotation center) + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **pivot** pivot, anchor point, rotation center + | *[in]* **angle** angle (radians) + | *[in]* **axis** axis + +.. c:function:: void glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) + + | creates NEW rotation matrix by angle and axis at given point + | this creates rotation matrix, it assumes you don't have a matrix + + | this should work faster than glm_rotate_at because it reduces one glm_translate. + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **pivot** pivot, anchor point, rotation center + | *[in]* **angle** angle (radians) + | *[in]* **axis** axis + .. c:function:: void glm_decompose_scalev(mat4 m, vec3 s) decompose scale vector diff --git a/docs/source/quat.rst b/docs/source/quat.rst index ab99838..d9b4680 100644 --- a/docs/source/quat.rst +++ b/docs/source/quat.rst @@ -56,6 +56,9 @@ Functions: #. :c:func:`glm_quat_for` #. :c:func:`glm_quat_forp` #. :c:func:`glm_quat_rotatev` +#. :c:func:`glm_quat_rotate` +#. :c:func:`glm_quat_rotate_at` +#. :c:func:`glm_quat_rotate_atm` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -354,3 +357,24 @@ Functions documentation | *[in]* **m** existing transform matrix to rotate | *[in]* **q** quaternion | *[out]* **dest** rotated matrix/transform + +.. c:function:: void glm_quat_rotate_at(mat4 m, versor q, vec3 pivot) + + | rotate existing transform matrix using quaternion at pivot point + + Parameters: + | *[in, out]* **m** existing transform matrix to rotate + | *[in]* **q** quaternion + | *[in]* **pivot** pivot + +.. c:function:: void glm_quat_rotate(mat4 m, versor q, mat4 dest) + + | rotate NEW transform matrix using quaternion at pivot point + | this creates rotation matrix, it assumes you don't have a matrix + + | this should work faster than glm_quat_rotate_at because it reduces one glm_translate. + + Parameters: + | *[in, out]* **m** existing transform matrix to rotate + | *[in]* **q** quaternion + | *[in]* **pivot** pivot diff --git a/include/cglm/affine.h b/include/cglm/affine.h index a5abbb6..f855399 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -25,6 +25,8 @@ CGLM_INLINE void glm_rotate_make(mat4 m, float angle, vec3 axis); CGLM_INLINE void glm_rotate_ndc(mat4 m, float angle, vec3 axis); CGLM_INLINE void glm_rotate(mat4 m, float angle, vec3 axis); + CGLM_INLINE void glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis); + CGLM_INLINE void glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis); CGLM_INLINE void glm_decompose_scalev(mat4 m, vec3 s); CGLM_INLINE bool glm_uniscaled(mat4 m); CGLM_INLINE void glm_decompose_rs(mat4 m, mat4 r, vec3 s); @@ -521,7 +523,7 @@ glm_decompose_scalev(mat4 m, vec3 s) { } /*! - * @brief returns true if matrix is uniform scaled. This is helpful for + * @brief returns true if matrix is uniform scaled. This is helpful for * creating normal matrix. * * @param[in] m m diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 1139c1d..d1da27f 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -757,14 +757,14 @@ glm_quat_rotate(mat4 m, versor q, mat4 dest) { */ CGLM_INLINE void -glm_quat_rotate_at(mat4 model, versor q, vec3 pivot) { +glm_quat_rotate_at(mat4 m, versor q, vec3 pivot) { vec3 pivotInv; glm_vec_inv_to(pivot, pivotInv); - glm_translate(model, pivot); - glm_quat_rotate(model, q, model); - glm_translate(model, pivotInv); + glm_translate(m, pivot); + glm_quat_rotate(m, q, m); + glm_translate(m, pivotInv); } /*! From f163fcd043d3cf99fd44724c53df5966a88634f1 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 18 Apr 2018 00:00:47 +0300 Subject: [PATCH 126/292] simd: load vec3 helpers for sse/sse2 --- include/cglm/simd/intrin.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index c396686..7fdfc2a 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -46,6 +46,25 @@ glm_simd_norm(__m128 a) { return _mm_sqrt_ps(glm_simd_dot(a, a)); } +static inline +__m128 +glm_simd_load_v3(vec3 v) { + __m128i xy; + __m128 z; + + xy = _mm_loadl_epi64((const __m128i *)v); + z = _mm_load_ss(&v[2]); + + return _mm_movelh_ps(_mm_castsi128_ps(xy), z); +} + +static inline +void +glm_simd_store_v3(__m128 vx, vec3 v) { + _mm_storel_pi((__m64 *)&v[0], vx); + _mm_store_ss(&v[2], _mm_shuffle1_ps(vx, 2, 2, 2, 2)); +} + #endif /* x86, x64 */ From d648f5772def2fa28ec39650982e9768db16fa81 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 18 Apr 2018 10:57:35 +0300 Subject: [PATCH 127/292] affine: drop rotate_ndc functions --- include/cglm/affine.h | 93 ++++++++++---------------------------- include/cglm/call/affine.h | 8 ---- src/affine.c | 12 ----- 3 files changed, 23 insertions(+), 90 deletions(-) diff --git a/include/cglm/affine.h b/include/cglm/affine.h index f855399..f7b3942 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -21,9 +21,7 @@ CGLM_INLINE void glm_rotate_x(mat4 m, float angle, mat4 dest); CGLM_INLINE void glm_rotate_y(mat4 m, float angle, mat4 dest); CGLM_INLINE void glm_rotate_z(mat4 m, float angle, mat4 dest); - CGLM_INLINE void glm_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc); CGLM_INLINE void glm_rotate_make(mat4 m, float angle, vec3 axis); - CGLM_INLINE void glm_rotate_ndc(mat4 m, float angle, vec3 axis); CGLM_INLINE void glm_rotate(mat4 m, float angle, vec3 axis); CGLM_INLINE void glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis); CGLM_INLINE void glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis); @@ -346,48 +344,6 @@ glm_rotate_z(mat4 m, float angle, mat4 dest) { glm_mat4_mul(m, t, dest); } -/*! - * @brief creates NEW rotation matrix by angle and axis - * - * this name may change in the future. axis must be is normalized - * - * @param[out] m affine transfrom - * @param[in] angle angle (radians) - * @param[in] axis_ndc normalized axis - */ -CGLM_INLINE -void -glm_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc) { - /* https://www.opengl.org/sdk/docs/man2/xhtml/glRotate.xml */ - - vec3 v, vs; - float c; - - c = cosf(angle); - - glm_vec_scale(axis_ndc, 1.0f - c, v); - glm_vec_scale(axis_ndc, sinf(angle), vs); - - glm_vec_scale(axis_ndc, v[0], m[0]); - glm_vec_scale(axis_ndc, v[1], m[1]); - glm_vec_scale(axis_ndc, v[2], m[2]); - - m[0][0] += c; - m[0][1] += vs[2]; - m[0][2] -= vs[1]; - - m[1][0] -= vs[2]; - m[1][1] += c; - m[1][2] += vs[0]; - - m[2][0] += vs[1]; - m[2][1] -= vs[0]; - m[2][2] += c; - - m[0][3] = m[1][3] = m[2][3] = m[3][0] = m[3][1] = m[3][2] = 0.0f; - m[3][3] = 1.0f; -} - /*! * @brief creates NEW rotation matrix by angle and axis * @@ -400,27 +356,40 @@ glm_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc) { CGLM_INLINE void glm_rotate_make(mat4 m, float angle, vec3 axis) { - vec3 axis_ndc; + vec3 axisn, v, vs; + float c; - glm_vec_normalize_to(axis, axis_ndc); - glm_rotate_ndc_make(m, angle, axis_ndc); + c = cosf(angle); + + glm_vec_normalize_to(axis, axisn); + glm_vec_scale(axisn, 1.0f - c, v); + glm_vec_scale(axisn, sinf(angle), vs); + + glm_vec_scale(axisn, v[0], m[0]); + glm_vec_scale(axisn, v[1], m[1]); + glm_vec_scale(axisn, v[2], m[2]); + + m[0][0] += c; m[1][0] -= vs[2]; m[2][0] += vs[1]; + m[0][1] += vs[2]; m[1][1] += c; m[2][1] -= vs[0]; + m[0][2] -= vs[1]; m[1][2] += vs[0]; m[2][2] += c; + + m[0][3] = m[1][3] = m[2][3] = m[3][0] = m[3][1] = m[3][2] = 0.0f; + m[3][3] = 1.0f; } /*! * @brief rotate existing transform matrix around given axis by angle * - * this name may change in the future, axis must be normalized. - * - * @param[in, out] m affine transfrom - * @param[in] angle angle (radians) - * @param[in] axis_ndc normalized axis + * @param[in, out] m affine transfrom + * @param[in] angle angle (radians) + * @param[in] axis axis */ CGLM_INLINE void -glm_rotate_ndc(mat4 m, float angle, vec3 axis_ndc) { +glm_rotate(mat4 m, float angle, vec3 axis) { mat4 rot, tmp; - glm_rotate_ndc_make(rot, angle, axis_ndc); + glm_rotate_make(rot, angle, axis); glm_vec4_scale(m[0], rot[0][0], tmp[1]); glm_vec4_scale(m[1], rot[0][1], tmp[0]); @@ -445,22 +414,6 @@ glm_rotate_ndc(mat4 m, float angle, vec3 axis_ndc) { glm_vec4_copy(tmp[3], m[2]); } -/*! - * @brief rotate existing transform matrix around given axis by angle - * - * @param[in, out] m affine transfrom - * @param[in] angle angle (radians) - * @param[in] axis axis - */ -CGLM_INLINE -void -glm_rotate(mat4 m, float angle, vec3 axis) { - vec3 axis_ndc; - - glm_vec_normalize_to(axis, axis_ndc); - glm_rotate_ndc(m, angle, axis_ndc); -} - /*! * @brief rotate existing transform * around given axis by angle at given pivot point (rotation center) diff --git a/include/cglm/call/affine.h b/include/cglm/call/affine.h index a9982c2..4e30fff 100644 --- a/include/cglm/call/affine.h +++ b/include/cglm/call/affine.h @@ -69,18 +69,10 @@ CGLM_EXPORT void glmc_rotate_z(mat4 m, float rad, mat4 dest); -CGLM_EXPORT -void -glmc_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc); - CGLM_EXPORT void glmc_rotate_make(mat4 m, float angle, vec3 axis); -CGLM_EXPORT -void -glmc_rotate_ndc(mat4 m, float angle, vec3 axis_ndc); - CGLM_EXPORT void glmc_rotate(mat4 m, float angle, vec3 axis); diff --git a/src/affine.c b/src/affine.c index 1da12d6..0c028ba 100644 --- a/src/affine.c +++ b/src/affine.c @@ -92,24 +92,12 @@ glmc_rotate_z(mat4 m, float rad, mat4 dest) { glm_rotate_z(m, rad, dest); } -CGLM_EXPORT -void -glmc_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc) { - glm_rotate_ndc_make(m, angle, axis_ndc); -} - CGLM_EXPORT void glmc_rotate_make(mat4 m, float angle, vec3 axis) { glm_rotate_make(m, angle, axis); } -CGLM_EXPORT -void -glmc_rotate_ndc(mat4 m, float angle, vec3 axis_ndc) { - glm_rotate_ndc(m, angle, axis_ndc); -} - CGLM_EXPORT void glmc_rotate(mat4 m, float angle, vec3 axis) { From be0e3fc9f2c5b50d4370522d54051cbf79a047ca Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 18 Apr 2018 14:05:09 +0300 Subject: [PATCH 128/292] new matrix multiplication helper for rotation matrices --- include/cglm/affine-mat.h | 54 +++++++++++++++++++++++++++++++++ include/cglm/simd/sse2/affine.h | 32 +++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/include/cglm/affine-mat.h b/include/cglm/affine-mat.h index 3fd19ef..e015591 100644 --- a/include/cglm/affine-mat.h +++ b/include/cglm/affine-mat.h @@ -81,6 +81,60 @@ glm_mul(mat4 m1, mat4 m2, mat4 dest) { #endif } +/*! + * @brief this is similar to glm_mat4_mul but specialized to affine transform + * + * Right Matrix format should be: + * R R R 0 + * R R R 0 + * R R R 0 + * 0 0 0 1 + * + * this reduces some multiplications. It should be faster than mat4_mul. + * if you are not sure about matrix format then DON'T use this! use mat4_mul + * + * @param[in] m1 affine matrix 1 + * @param[in] m2 affine matrix 2 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_mul_rot(mat4 m1, mat4 m2, mat4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mul_rot_sse2(m1, m2, dest); +#else + 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], + a30 = m1[3][0], a31 = m1[3][1], a32 = m1[3][2], a33 = m1[3][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], + b33 = m2[3][3]; + + dest[0][0] = a00 * b00 + a10 * b01 + a20 * b02; + dest[0][1] = a01 * b00 + a11 * b01 + a21 * b02; + dest[0][2] = a02 * b00 + a12 * b01 + a22 * b02; + dest[0][3] = a03 * b00 + a13 * b01 + a23 * b02; + + dest[1][0] = a00 * b10 + a10 * b11 + a20 * b12; + dest[1][1] = a01 * b10 + a11 * b11 + a21 * b12; + dest[1][2] = a02 * b10 + a12 * b11 + a22 * b12; + dest[1][3] = a03 * b10 + a13 * b11 + a23 * b12; + + dest[2][0] = a00 * b20 + a10 * b21 + a20 * b22; + dest[2][1] = a01 * b20 + a11 * b21 + a21 * b22; + dest[2][2] = a02 * b20 + a12 * b21 + a22 * b22; + dest[2][3] = a03 * b20 + a13 * b21 + a23 * b22; + + dest[3][0] = a30; + dest[3][1] = a31; + dest[3][2] = a32; + dest[3][3] = a33; +#endif +} + /*! * @brief inverse orthonormal rotation + translation matrix (ridig-body) * diff --git a/include/cglm/simd/sse2/affine.h b/include/cglm/simd/sse2/affine.h index 3ec8f5f..b746d0f 100644 --- a/include/cglm/simd/sse2/affine.h +++ b/include/cglm/simd/sse2/affine.h @@ -49,6 +49,38 @@ glm_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); } +CGLM_INLINE +void +glm_mul_rot_sse2(mat4 m1, mat4 m2, mat4 dest) { + /* D = R * L (Column-Major) */ + __m128 l0, l1, l2, l3, r; + + l0 = _mm_load_ps(m1[0]); + l1 = _mm_load_ps(m1[1]); + l2 = _mm_load_ps(m1[2]); + l3 = _mm_load_ps(m1[3]); + + r = _mm_load_ps(m2[0]); + _mm_store_ps(dest[0], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + + r = _mm_load_ps(m2[1]); + _mm_store_ps(dest[1], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + + r = _mm_load_ps(m2[2]); + _mm_store_ps(dest[2], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + + _mm_store_ps(dest[3], l3); +} + CGLM_INLINE void glm_inv_tr_sse2(mat4 mat) { From 4dbcd28fdba604ecc4d4432f15b862a709cdfe17 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 18 Apr 2018 14:12:56 +0300 Subject: [PATCH 129/292] use mul_rot for rotations to make thrm faster --- include/cglm/affine.h | 77 ++++++++++++++---------------------------- include/cglm/types.h | 4 +-- test/src/test_affine.c | 9 +++++ 3 files changed, 37 insertions(+), 53 deletions(-) diff --git a/include/cglm/affine.h b/include/cglm/affine.h index f7b3942..953b31c 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -277,19 +277,18 @@ glm_scale_uni(mat4 m, float s) { CGLM_INLINE void glm_rotate_x(mat4 m, float angle, mat4 dest) { - float cosVal; - float sinVal; mat4 t = GLM_MAT4_IDENTITY_INIT; + float c, s; - cosVal = cosf(angle); - sinVal = sinf(angle); + c = cosf(angle); + s = sinf(angle); - t[1][1] = cosVal; - t[1][2] = sinVal; - t[2][1] = -sinVal; - t[2][2] = cosVal; + t[1][1] = c; + t[1][2] = s; + t[2][1] = -s; + t[2][2] = c; - glm_mat4_mul(m, t, dest); + glm_mul_rot(m, t, dest); } /*! @@ -303,19 +302,18 @@ glm_rotate_x(mat4 m, float angle, mat4 dest) { CGLM_INLINE void glm_rotate_y(mat4 m, float angle, mat4 dest) { - float cosVal; - float sinVal; mat4 t = GLM_MAT4_IDENTITY_INIT; + float c, s; - cosVal = cosf(angle); - sinVal = sinf(angle); + c = cosf(angle); + s = sinf(angle); - t[0][0] = cosVal; - t[0][2] = -sinVal; - t[2][0] = sinVal; - t[2][2] = cosVal; + t[0][0] = c; + t[0][2] = -s; + t[2][0] = s; + t[2][2] = c; - glm_mat4_mul(m, t, dest); + glm_mul_rot(m, t, dest); } /*! @@ -329,19 +327,18 @@ glm_rotate_y(mat4 m, float angle, mat4 dest) { CGLM_INLINE void glm_rotate_z(mat4 m, float angle, mat4 dest) { - float cosVal; - float sinVal; mat4 t = GLM_MAT4_IDENTITY_INIT; + float c, s; - cosVal = cosf(angle); - sinVal = sinf(angle); + c = cosf(angle); + s = sinf(angle); - t[0][0] = cosVal; - t[0][1] = sinVal; - t[1][0] = -sinVal; - t[1][1] = cosVal; + t[0][0] = c; + t[0][1] = s; + t[1][0] = -s; + t[1][1] = c; - glm_mat4_mul(m, t, dest); + glm_mul_rot(m, t, dest); } /*! @@ -387,31 +384,9 @@ glm_rotate_make(mat4 m, float angle, vec3 axis) { CGLM_INLINE void glm_rotate(mat4 m, float angle, vec3 axis) { - mat4 rot, tmp; - + mat4 rot; glm_rotate_make(rot, angle, axis); - - glm_vec4_scale(m[0], rot[0][0], tmp[1]); - glm_vec4_scale(m[1], rot[0][1], tmp[0]); - glm_vec4_add(tmp[1], tmp[0], tmp[1]); - glm_vec4_scale(m[2], rot[0][2], tmp[0]); - glm_vec4_add(tmp[1], tmp[0], tmp[1]); - - glm_vec4_scale(m[0], rot[1][0], tmp[2]); - glm_vec4_scale(m[1], rot[1][1], tmp[0]); - glm_vec4_add(tmp[2], tmp[0], tmp[2]); - glm_vec4_scale(m[2], rot[1][2], tmp[0]); - glm_vec4_add(tmp[2], tmp[0], tmp[2]); - - glm_vec4_scale(m[0], rot[2][0], tmp[3]); - glm_vec4_scale(m[1], rot[2][1], tmp[0]); - glm_vec4_add(tmp[3], tmp[0], tmp[3]); - glm_vec4_scale(m[2], rot[2][2], tmp[0]); - glm_vec4_add(tmp[3], tmp[0], tmp[3]); - - glm_vec4_copy(tmp[1], m[0]); - glm_vec4_copy(tmp[2], m[1]); - glm_vec4_copy(tmp[3], m[2]); + glm_mul_rot(m, rot, m); } /*! diff --git a/include/cglm/types.h b/include/cglm/types.h index c411d8b..5d39a55 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -15,12 +15,12 @@ #endif typedef float vec2[2]; -typedef float vec3[3]; +typedef CGLM_ALIGN(8) float vec3[3]; typedef int ivec3[3]; typedef CGLM_ALIGN(16) float vec4[4]; typedef vec3 mat3[3]; -typedef vec4 mat4[4]; +typedef CGLM_ALIGN(16) vec4 mat4[4]; typedef vec4 versor; diff --git a/test/src/test_affine.c b/test/src/test_affine.c index 4ce4a42..a625a30 100644 --- a/test/src/test_affine.c +++ b/test/src/test_affine.c @@ -91,6 +91,15 @@ test_affine(void **state) { glm_rotate_z(t2, M_PI_4, t2); test_assert_mat4_eq(t2, t3); + /* test rotate */ + glmc_rotate_make(t1, M_PI_4, (vec3){0, 0, 1}); + glm_translate_make(t2, (vec3){34, 57, 36}); + + glmc_mat4_mul(t2, t1, t3); /* T * R */ + glmc_rotate(t2, M_PI_4, (vec3){0, 0, 1}); + + test_assert_mat4_eq(t3, t2); + /* test scale_uni */ glmc_rotate_make(t1, M_PI_4, GLM_YUP); glm_translate_make(t2, (vec3){34, 57, 36}); From 065f93ab3cd0e202974377cae8d019d178d5502a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 18 Apr 2018 14:30:44 +0300 Subject: [PATCH 130/292] update docs, drop scale1 --- docs/source/affine-mat.rst | 22 +++++++++++++++++++++ docs/source/affine.rst | 40 ++++++++++++-------------------------- include/cglm/affine.h | 11 ----------- include/cglm/call/affine.h | 4 ---- src/affine.c | 6 ------ 5 files changed, 34 insertions(+), 49 deletions(-) diff --git a/docs/source/affine-mat.rst b/docs/source/affine-mat.rst index 0c0fcaa..43740cf 100644 --- a/docs/source/affine-mat.rst +++ b/docs/source/affine-mat.rst @@ -33,6 +33,7 @@ Table of contents (click func go): Functions: 1. :c:func:`glm_mul` +#. :c:func:`glm_mul_rot` #. :c:func:`glm_inv_tr` Functions documentation @@ -59,6 +60,27 @@ Functions documentation | *[in]* **m2** affine matrix 2 | *[out]* **dest** result matrix +.. c:function:: void glm_mul_rot(mat4 m1, mat4 m2, mat4 dest) + + | this is similar to glm_mat4_mul but specialized to rotation matrix + + Right Matrix format should be (left is free): + + .. code-block:: text + + R R R 0 + R R R 0 + R R R 0 + 0 0 0 1 + + this reduces some multiplications. It should be faster than mat4_mul. + if you are not sure about matrix format then DON'T use this! use mat4_mul + + Parameters: + | *[in]* **m1** affine matrix 1 + | *[in]* **m2** affine matrix 2 + | *[out]* **dest** result matrix + .. c:function:: void glm_inv_tr(mat4 mat) | inverse orthonormal rotation + translation matrix (ridig-body) diff --git a/docs/source/affine.rst b/docs/source/affine.rst index 8eaf01c..8ded38d 100644 --- a/docs/source/affine.rst +++ b/docs/source/affine.rst @@ -36,6 +36,15 @@ If you want to rotate model around arbibtrary point follow these steps: **glm_rotate_at**, **glm_quat_rotate_at** and their helper functions works that way. +The implementation would be: + +.. code-block:: c + :linenos: + + glm_translate(m, pivot); + glm_rotate(m, angle, axis); + glm_translate(m, pivotInv); /* pivotInv = -pivot */ + Transforms Order ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -68,7 +77,7 @@ because you call it first, do you? Result will be **`transform = transform * translate1`** -2. Then you call translate using `translate2` and you expect it will be second transform, really? +2. Then you call translate using `translate2` and you expect it will be second transform? Result will be **`transform = transform * translate2`**. Now lets expand transform, it was `transform * translate1` before second call. @@ -86,6 +95,8 @@ It is all about matrix multiplication order. It is similar to MVP matrix: **Confused?** +In the end the last function call applied first in shaders. + As alternative way, you can create transform matrices individually then combine manually, but don't forget that `glm_translate`, `glm_rotate`, `glm_scale`... are optimized and should be faster (an smaller assembly output) than manual multiplication @@ -121,14 +132,11 @@ Functions: #. :c:func:`glm_scale_to` #. :c:func:`glm_scale_make` #. :c:func:`glm_scale` -#. :c:func:`glm_scale1` #. :c:func:`glm_scale_uni` #. :c:func:`glm_rotate_x` #. :c:func:`glm_rotate_y` #. :c:func:`glm_rotate_z` -#. :c:func:`glm_rotate_ndc_make` #. :c:func:`glm_rotate_make` -#. :c:func:`glm_rotate_ndc` #. :c:func:`glm_rotate` #. :c:func:`glm_rotate_at` #. :c:func:`glm_rotate_atm` @@ -216,10 +224,6 @@ Functions documentation | *[in, out]* **m** affine transfrom | *[in]* **v** scale vector [x, y, z] -.. c:function:: void glm_scale1(mat4 m, float s) - - DEPRECATED! Use glm_scale_uni - .. c:function:: void glm_scale_uni(mat4 m, float s) applies uniform scale to existing transform matrix v = [s, s, s] @@ -259,16 +263,6 @@ Functions documentation | *[in]* **angle** angle (radians) | *[out]* **dest** rotated matrix -.. c:function:: void glm_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc) - - creates NEW rotation matrix by angle and axis - this name may change in the future. axis must be is normalized - - Parameters: - | *[out]* **m** affine transfrom - | *[in]* **angle** angle (radians) - | *[in]* **axis_ndc** normalized axis - .. c:function:: void glm_rotate_make(mat4 m, float angle, vec3 axis) creates NEW rotation matrix by angle and axis, @@ -279,16 +273,6 @@ Functions documentation | *[in]* **axis** angle (radians) | *[in]* **axis** axis -.. c:function:: void glm_rotate_ndc(mat4 m, float angle, vec3 axis_ndc) - - rotate existing transform matrix around Z axis by angle and axis - this name may change in the future, axis must be normalized. - - Parameters: - | *[out]* **m** affine transfrom - | *[in]* **angle** angle (radians) - | *[in]* **axis_ndc** normalized axis - .. c:function:: void glm_rotate(mat4 m, float angle, vec3 axis) rotate existing transform matrix around Z axis by angle and axis diff --git a/include/cglm/affine.h b/include/cglm/affine.h index 953b31c..95d60b7 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -16,7 +16,6 @@ CGLM_INLINE void glm_scale_to(mat4 m, vec3 v, mat4 dest); CGLM_INLINE void glm_scale_make(mat4 m, vec3 v); CGLM_INLINE void glm_scale(mat4 m, vec3 v); - CGLM_INLINE void glm_scale1(mat4 m, float s); CGLM_INLINE void glm_scale_uni(mat4 m, float s); CGLM_INLINE void glm_rotate_x(mat4 m, float angle, mat4 dest); CGLM_INLINE void glm_rotate_y(mat4 m, float angle, mat4 dest); @@ -242,16 +241,6 @@ glm_scale(mat4 m, vec3 v) { glm_scale_to(m, v, m); } -/*! - * @brief DEPRECATED! Use glm_scale_uni - */ -CGLM_INLINE -void -glm_scale1(mat4 m, float s) { - vec3 v = { s, s, s }; - glm_scale_to(m, v, m); -} - /*! * @brief applies uniform scale to existing transform matrix v = [s, s, s] * and stores result in same matrix diff --git a/include/cglm/call/affine.h b/include/cglm/call/affine.h index 4e30fff..4d3834b 100644 --- a/include/cglm/call/affine.h +++ b/include/cglm/call/affine.h @@ -49,10 +49,6 @@ CGLM_EXPORT void glmc_scale(mat4 m, vec3 v); -CGLM_EXPORT -void -glmc_scale1(mat4 m, float s); - CGLM_EXPORT void glmc_scale_uni(mat4 m, float s); diff --git a/src/affine.c b/src/affine.c index 0c028ba..a271f9f 100644 --- a/src/affine.c +++ b/src/affine.c @@ -62,12 +62,6 @@ glmc_scale(mat4 m, vec3 v) { glm_scale(m, v); } -CGLM_EXPORT -void -glmc_scale1(mat4 m, float s) { - glm_scale1(m, s); -} - CGLM_EXPORT void glmc_scale_uni(mat4 m, float s) { From a723ecdb7ec862b38dce7975563631b1162f7cb9 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 18 Apr 2018 15:11:06 +0300 Subject: [PATCH 131/292] add troubleshooting to docs --- docs/source/index.rst | 1 + docs/source/troubleshooting.rst | 76 +++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 docs/source/troubleshooting.rst diff --git a/docs/source/index.rst b/docs/source/index.rst index 25e7cb3..32e7b48 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -40,6 +40,7 @@ Also currently only **float** type is supported for most operations. getting_started opengl api + troubleshooting Indices and tables ================== diff --git a/docs/source/troubleshooting.rst b/docs/source/troubleshooting.rst new file mode 100644 index 0000000..d0cc9d5 --- /dev/null +++ b/docs/source/troubleshooting.rst @@ -0,0 +1,76 @@ +.. default-domain:: C + +Troubleshooting +================================================================================ + +It is possible that sometimes you may 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. + +You are responsible for allocation of **src** and **dest** parameters. + +Aligment: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**vec4** and **mat4** types requires 16 byte aligment aligment. +These types are marked with align attribute to let compiler know about this +requirement. + +But since MSVC (Windows) throws the error: + +**"formal parameter with requested alignment of 16 won't be aligned"** + +The aligment attribute has been commented for MSVC + +.. code-block:: c + + #if defined(_MSC_VER) + # define CGLM_ALIGN(X) /* __declspec(align(X)) */ + #else + # define CGLM_ALIGN(X) __attribute((aligned(X))) + #endif. + +So MSVC may not know about aligment requirements when creating variables. +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.** + +Crashes, Invalid Memory Access: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Probably you are trying to write to invalid memory location. + +You may used 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. + +Wrong Results: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Again, you may used wrong function. + +For instance if you use **glm_normalize()** or **glm_vec_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. + +Accessing 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 :) + +**Also implementation may be wrong please let us know by creating an issue on Github.** + +Other Issues? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**Please let us know by creating an issue on Github.** From 63966ee5c0c40b585fb5548ed5b7c4a04d270f4a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 18 Apr 2018 15:16:24 +0300 Subject: [PATCH 132/292] quat: use the new "glm_mul_rot" for quaternion * this should be faster than mat4_mul --- include/cglm/quat.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index d1da27f..6f0e87d 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -55,6 +55,7 @@ #include "vec4.h" #include "mat4.h" #include "mat3.h" +#include "affine-mat.h" #ifdef CGLM_SSE_FP # include "simd/sse2/quat.h" @@ -70,7 +71,7 @@ glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); CGLM_INLINE void -glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest); +glm_mul_rot(mat4 m1, mat4 m2, mat4 dest); CGLM_INLINE void @@ -745,7 +746,7 @@ void glm_quat_rotate(mat4 m, versor q, mat4 dest) { mat4 rot; glm_quat_mat4(q, rot); - glm_mat4_mul(m, rot, dest); + glm_mul_rot(m, rot, dest); } /*! From e28cf1d3f6ce21d4ae0bd5ec9fd0481f0e2bd9b6 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 18 Apr 2018 15:23:07 +0300 Subject: [PATCH 133/292] remove unused variable --- include/cglm/affine-mat.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/cglm/affine-mat.h b/include/cglm/affine-mat.h index e015591..b320509 100644 --- a/include/cglm/affine-mat.h +++ b/include/cglm/affine-mat.h @@ -110,8 +110,7 @@ glm_mul_rot(mat4 m1, mat4 m2, mat4 dest) { 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], - b33 = m2[3][3]; + b20 = m2[2][0], b21 = m2[2][1], b22 = m2[2][2]; dest[0][0] = a00 * b00 + a10 * b01 + a20 * b02; dest[0][1] = a01 * b00 + a11 * b01 + a21 * b02; From 22b699174c9a8bb6f2483f8a678b09146ba6ce5e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 18 Apr 2018 21:47:53 +0300 Subject: [PATCH 134/292] build: improve calling libtoolize --- autogen.sh | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/autogen.sh b/autogen.sh index f8d13c8..b3b8d82 100644 --- a/autogen.sh +++ b/autogen.sh @@ -8,17 +8,14 @@ cd $(dirname "$0") -if [ "$(uname)" = "Darwin" ]; then -libtoolBin=$(which glibtoolize) -libtoolBinDir=$(dirname "${libtoolBin}") - -if [ ! -f "${libtoolBinDir}/libtoolize" ]; then -ln -s $libtoolBin "${libtoolBinDir}/libtoolize" -fi -fi - autoheader -libtoolize + +if [ "$(uname)" = "Darwin" ]; then + glibtoolize +else + libtoolize +fi + aclocal -I m4 autoconf automake --add-missing --copy From 6202179c23b04125c0084c6446ff3d05fe5835fe Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 18 Apr 2018 22:30:20 +0300 Subject: [PATCH 135/292] update version --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 0fc55a8..42cdd05 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.4.2], [info@recp.me]) +AC_INIT([cglm], [0.4.3], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index 616edfd..b75537c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.4.1' +version = u'0.4.3' # The full version, including alpha/beta/rc tags. -release = u'0.4.1' +release = u'0.4.3' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index 328a4d2..b9da46c 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 4 -#define CGLM_VERSION_PATCH 2 +#define CGLM_VERSION_PATCH 3 #endif /* cglm_version_h */ From a6a37995e9377fb01efc6a50fb71f2fbe57bac44 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 18 Apr 2018 23:02:15 +0300 Subject: [PATCH 136/292] build: update automake sources --- makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/makefile.am b/makefile.am index a0c06a9..1999b3d 100644 --- a/makefile.am +++ b/makefile.am @@ -54,7 +54,8 @@ cglm_HEADERS = include/cglm/version.h \ include/cglm/plane.h \ include/cglm/frustum.h \ include/cglm/box.h \ - include/cglm/color.h + include/cglm/color.h \ + include/cglm/project.h cglm_calldir=$(includedir)/cglm/call cglm_call_HEADERS = include/cglm/call/mat4.h \ @@ -68,7 +69,8 @@ cglm_call_HEADERS = include/cglm/call/mat4.h \ include/cglm/call/euler.h \ include/cglm/call/plane.h \ include/cglm/call/frustum.h \ - include/cglm/call/box.h + include/cglm/call/box.h \ + include/cglm/call/project.h cglm_simddir=$(includedir)/cglm/simd cglm_simd_HEADERS = include/cglm/simd/intrin.h From 3c7a729729097325e3824ce48739c13879a5efaf Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 20 Apr 2018 15:15:57 +0300 Subject: [PATCH 137/292] build: remove making symbolic link for libtoolize --- build-deps.sh | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/build-deps.sh b/build-deps.sh index 74b1cfa..20365ba 100644 --- a/build-deps.sh +++ b/build-deps.sh @@ -9,19 +9,8 @@ # check if deps are pulled git submodule update --init --recursive -# fix glibtoolize - cd $(dirname "$0") -if [ "$(uname)" = "Darwin" ]; then - libtoolBin=$(which glibtoolize) - libtoolBinDir=$(dirname "${libtoolBin}") - - if [ ! -f "${libtoolBinDir}/libtoolize" ]; then - ln -s $libtoolBin "${libtoolBinDir}/libtoolize" - fi -fi - # general deps: gcc make autoconf automake libtool cmake # test - cmocka From 498a33fac5f6cce134720fd5fbcad18206c8d285 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 21 Apr 2018 22:36:25 +0300 Subject: [PATCH 138/292] fix public header's includes --- include/cglm/affine.h | 5 +++-- include/cglm/box.h | 1 + include/cglm/frustum.h | 3 +++ include/cglm/mat3.h | 1 + include/cglm/mat4.h | 2 ++ include/cglm/plane.h | 2 -- include/cglm/project.h | 2 +- include/cglm/quat.h | 1 + 8 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/cglm/affine.h b/include/cglm/affine.h index 95d60b7..8124930 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -34,10 +34,11 @@ #define cglm_affine_h #include "common.h" -#include "vec4.h" -#include "affine-mat.h" #include "util.h" +#include "vec3.h" +#include "vec4.h" #include "mat4.h" +#include "affine-mat.h" CGLM_INLINE void diff --git a/include/cglm/box.h b/include/cglm/box.h index 7032339..31b0ec2 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -11,6 +11,7 @@ #include "common.h" #include "vec3.h" #include "vec4.h" +#include "util.h" /*! * @brief apply transform to Axis-Aligned Bounding Box diff --git a/include/cglm/frustum.h b/include/cglm/frustum.h index 4f8aff4..d4e8d47 100644 --- a/include/cglm/frustum.h +++ b/include/cglm/frustum.h @@ -10,6 +10,9 @@ #include "common.h" #include "plane.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" #define GLM_LBN 0 /* left bottom near */ #define GLM_LTN 1 /* left top near */ diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 9512aef..87bf9b1 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -31,6 +31,7 @@ #define cglm_mat3_h #include "common.h" +#include "vec3.h" #ifdef CGLM_SSE_FP # include "simd/sse2/mat3.h" diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 27ebe05..1b254a2 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -46,6 +46,8 @@ #include "common.h" #include "quat.h" +#include "vec4.h" +#include "vec3.h" #ifdef CGLM_SSE_FP # include "simd/sse2/mat4.h" diff --git a/include/cglm/plane.h b/include/cglm/plane.h index 9faac9c..e0faed5 100644 --- a/include/cglm/plane.h +++ b/include/cglm/plane.h @@ -9,9 +9,7 @@ #define cglm_plane_h #include "common.h" -#include "mat4.h" #include "vec4.h" -#include "vec3.h" /* Plane equation: Ax + By + Cz + D = 0; diff --git a/include/cglm/project.h b/include/cglm/project.h index fea44b0..c71e735 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -8,9 +8,9 @@ #ifndef cglm_project_h #define cglm_project_h -#include "mat4.h" #include "vec3.h" #include "vec4.h" +#include "mat4.h" /*! * @brief maps the specified viewport coordinates into specified space [1] diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 6f0e87d..f6dc86e 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -52,6 +52,7 @@ #define cglm_quat_h #include "common.h" +#include "vec3.h" #include "vec4.h" #include "mat4.h" #include "mat3.h" From cef97fca3ec7a7e89066ec0df3e3226a13f4713a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 22 Apr 2018 01:03:17 +0300 Subject: [PATCH 139/292] add cocoapods spec --- cglm.podspec | 29 +++++++++++++++++++++++++++++ configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 2 +- 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 cglm.podspec diff --git a/cglm.podspec b/cglm.podspec new file mode 100644 index 0000000..d9faadb --- /dev/null +++ b/cglm.podspec @@ -0,0 +1,29 @@ +Pod::Spec.new do |s| + + # Description + s.name = "cglm" + s.version = "0.4.4" + s.summary = "📽 Optimized OpenGL/Graphics Math (glm) for C" + s.description = <<-DESC +cglm is math library for graphics programming for C. It is similar to original glm but it is written for C instead of C++ (you can use here too). See the documentation or README for all features. + DESC + + s.documentation_url = "http://cglm.readthedocs.io" + + # Home + s.homepage = "https://github.com/recp/cglm" + s.license = { :type => "MIT", :file => "LICENSE" } + s.author = { "Recep Aslantas" => "recp@acm.org" } + + # Sources + s.source = { :git => "https://github.com/recp/cglm.git", :tag => "v#{s.version}" } + s.source_files = "src", "include/cglm/**/*.h" + s.public_header_files = "include", "include/cglm/**/*.h" + s.private_header_files = "src/**/*.h" + s.exclude_files = "src/win/*", "src/dllmain.c" + s.preserve_path = "include" + s.header_mappings_dir = "include" + + # Linking + s.library = "m" +end diff --git a/configure.ac b/configure.ac index 42cdd05..120ac02 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.4.3], [info@recp.me]) +AC_INIT([cglm], [0.4.4], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index b75537c..6ea46ac 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.4.3' +version = u'0.4.4' # The full version, including alpha/beta/rc tags. -release = u'0.4.3' +release = u'0.4.4' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index b9da46c..3ed79fb 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 4 -#define CGLM_VERSION_PATCH 3 +#define CGLM_VERSION_PATCH 4 #endif /* cglm_version_h */ From ada69a7c43a6ea405e871cf4f6eefe3522bf39b2 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 22 Apr 2018 10:14:17 +0300 Subject: [PATCH 140/292] fix cocoapods validation errors --- cglm.podspec | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cglm.podspec b/cglm.podspec index d9faadb..150ca86 100644 --- a/cglm.podspec +++ b/cglm.podspec @@ -19,9 +19,8 @@ cglm is math library for graphics programming for C. It is similar to original g s.source = { :git => "https://github.com/recp/cglm.git", :tag => "v#{s.version}" } s.source_files = "src", "include/cglm/**/*.h" s.public_header_files = "include", "include/cglm/**/*.h" - s.private_header_files = "src/**/*.h" - s.exclude_files = "src/win/*", "src/dllmain.c" - s.preserve_path = "include" + s.exclude_files = "src/win/*", "src/dllmain.c", "src/**/*.h" + s.preserve_paths = "include", "src" s.header_mappings_dir = "include" # Linking From 6c01eff056af1f54b63e12b46b0a78f3ce7502a4 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 30 Apr 2018 10:59:40 +0300 Subject: [PATCH 141/292] now working on v0.4.5 --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 120ac02..76c6123 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.4.4], [info@recp.me]) +AC_INIT([cglm], [0.4.5], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index 6ea46ac..ef9619a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.4.4' +version = u'0.4.5' # The full version, including alpha/beta/rc tags. -release = u'0.4.4' +release = u'0.4.5' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index 3ed79fb..8e405bd 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 4 -#define CGLM_VERSION_PATCH 4 +#define CGLM_VERSION_PATCH 5 #endif /* cglm_version_h */ From 94d6036c388f764cf2697095b088ac076bef65e1 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 30 Apr 2018 11:09:42 +0300 Subject: [PATCH 142/292] suppress warnings for Mingw --- include/cglm/simd/intrin.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index 7fdfc2a..1938cb2 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -10,9 +10,13 @@ #if defined( _WIN32 ) # if (defined(_M_AMD64) || defined(_M_X64)) || _M_IX86_FP == 2 -# define __SSE2__ +# ifndef __SSE2__ +# define __SSE2__ +# endif # elif _M_IX86_FP == 1 -# define __SSE__ +# ifndef __SSE__ +# define __SSE__ +# endif # endif #endif From 064209c917be86d5ffda7a871a2447af7ad0411a Mon Sep 17 00:00:00 2001 From: Federico Santamorena Date: Mon, 30 Apr 2018 17:13:16 +0200 Subject: [PATCH 143/292] replaced _WIN32 with _MSC_VER --- include/cglm/simd/intrin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index 1938cb2..cf6753f 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -8,7 +8,7 @@ #ifndef cglm_intrin_h #define cglm_intrin_h -#if defined( _WIN32 ) +#if defined( _MSC_VER ) # if (defined(_M_AMD64) || defined(_M_X64)) || _M_IX86_FP == 2 # ifndef __SSE2__ # define __SSE2__ From 7c0e9e99c67ddc63ff95d10c8c2885d1105c2bf0 Mon Sep 17 00:00:00 2001 From: Federico Santamorena Date: Mon, 30 Apr 2018 17:17:06 +0200 Subject: [PATCH 144/292] _WIN32 to _MSC_VER --- include/cglm/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/common.h b/include/cglm/common.h index f0eb965..199bfda 100644 --- a/include/cglm/common.h +++ b/include/cglm/common.h @@ -14,7 +14,7 @@ #include #include -#if defined(_WIN32) +#if defined(_MSC_VER) # ifdef CGLM_DLL # define CGLM_EXPORT __declspec(dllexport) # else From a9d56f2daeb9781fe279880997456872cc6697e2 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 4 May 2018 00:50:56 +0300 Subject: [PATCH 145/292] docs: fix typos --- docs/source/getting_started.rst | 6 +++--- docs/source/troubleshooting.rst | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 89c231c..a152371 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -21,17 +21,17 @@ Types: As you can see types don't store extra informations in favor of space. You can send these values e.g. matrix to OpenGL directly without casting or calling a function like *value_ptr* -Aligment is Required: +Alignment is Required: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -**vec4** and **mat4** requires 16 byte aligment because vec4 and mat4 operations are +**vec4** and **mat4** requires 16 byte alignment because vec4 and mat4 operations are vectorized by SIMD instructions (SSE/AVX). Allocations: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *cglm* doesn't alloc any memory on heap. So it doesn't provide any allocator. You must allocate memory yourself. You should alloc memory for out parameters too if you pass pointer of memory location. -When allocating memory don't forget that **vec4** and **mat4** requires aligment. +When allocating memory don't forget that **vec4** and **mat4** requires alignment. **NOTE:** Unaligned vec4 and unaligned mat4 operations will be supported in the future. Check todo list. Because you may want to multiply a CGLM matrix with external matrix. diff --git a/docs/source/troubleshooting.rst b/docs/source/troubleshooting.rst index d0cc9d5..d599c7d 100644 --- a/docs/source/troubleshooting.rst +++ b/docs/source/troubleshooting.rst @@ -15,10 +15,10 @@ makes calculations then copy the result to dest. You are responsible for allocation of **src** and **dest** parameters. -Aligment: +Alignment: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -**vec4** and **mat4** types requires 16 byte aligment aligment. +**vec4** and **mat4** types requires 16 byte alignment. These types are marked with align attribute to let compiler know about this requirement. @@ -26,7 +26,7 @@ But since MSVC (Windows) throws the error: **"formal parameter with requested alignment of 16 won't be aligned"** -The aligment attribute has been commented for MSVC +The alignment attribute has been commented for MSVC .. code-block:: c @@ -36,7 +36,7 @@ The aligment attribute has been commented for MSVC # define CGLM_ALIGN(X) __attribute((aligned(X))) #endif. -So MSVC may not know about aligment requirements when creating variables. +So MSVC may not know about alignment requirements when creating variables. 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. @@ -61,7 +61,7 @@ Again, you may used wrong function. For instance if you use **glm_normalize()** or **glm_vec_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. +Since you need to **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. You only get wrong results if you don't know what you are doing! From 0f339c5c03f73b6751ffeb00e6e9f4a8620bae42 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 7 May 2018 21:12:29 +0300 Subject: [PATCH 146/292] fix header dependencies --- include/cglm/affine-mat.h | 1 + include/cglm/mat4.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/affine-mat.h b/include/cglm/affine-mat.h index b320509..62bfce1 100644 --- a/include/cglm/affine-mat.h +++ b/include/cglm/affine-mat.h @@ -16,6 +16,7 @@ #include "common.h" #include "mat4.h" +#include "mat3.h" #ifdef CGLM_SSE_FP # include "simd/sse2/affine.h" diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 1b254a2..d1a72cb 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -45,7 +45,6 @@ #define cglm_mat_h #include "common.h" -#include "quat.h" #include "vec4.h" #include "vec3.h" From 252bf925fc4ecd9cd939992f3651df15fc84e0c3 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 8 May 2018 15:25:23 +0300 Subject: [PATCH 147/292] simd, sse2: make alignment optional for load operations --- include/cglm/affine.h | 34 ++++++++--------- include/cglm/mat4.h | 8 ++-- include/cglm/quat.h | 2 +- include/cglm/simd/intrin.h | 12 +++++- include/cglm/simd/sse2/affine.h | 38 +++++++++---------- include/cglm/simd/sse2/mat4.h | 66 ++++++++++++++++----------------- include/cglm/simd/sse2/quat.h | 4 +- include/cglm/vec4-ext.h | 6 +-- include/cglm/vec4.h | 58 ++++++++++++++--------------- 9 files changed, 118 insertions(+), 110 deletions(-) diff --git a/include/cglm/affine.h b/include/cglm/affine.h index 8124930..b200f30 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -59,18 +59,18 @@ glm_translate_to(mat4 m, vec3 v, mat4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) _mm_store_ps(dest[3], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_load_ps(t[0]), + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_load(t[0]), _mm_set1_ps(v[0])), - _mm_mul_ps(_mm_load_ps(t[1]), + _mm_mul_ps(glmm_load(t[1]), _mm_set1_ps(v[1]))), - _mm_add_ps(_mm_mul_ps(_mm_load_ps(t[2]), + _mm_add_ps(_mm_mul_ps(glmm_load(t[2]), _mm_set1_ps(v[2])), - _mm_load_ps(t[3])))) + glmm_load(t[3])))) ; - _mm_store_ps(dest[0], _mm_load_ps(m[0])); - _mm_store_ps(dest[1], _mm_load_ps(m[1])); - _mm_store_ps(dest[2], _mm_load_ps(m[2])); + _mm_store_ps(dest[0], glmm_load(m[0])); + _mm_store_ps(dest[1], glmm_load(m[1])); + _mm_store_ps(dest[2], glmm_load(m[2])); #else vec4 v1, v2, v3; @@ -98,13 +98,13 @@ void glm_translate(mat4 m, vec3 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) _mm_store_ps(m[3], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_load_ps(m[0]), + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_load(m[0]), _mm_set1_ps(v[0])), - _mm_mul_ps(_mm_load_ps(m[1]), + _mm_mul_ps(glmm_load(m[1]), _mm_set1_ps(v[1]))), - _mm_add_ps(_mm_mul_ps(_mm_load_ps(m[2]), + _mm_add_ps(_mm_mul_ps(glmm_load(m[2]), _mm_set1_ps(v[2])), - _mm_load_ps(m[3])))) + glmm_load(m[3])))) ; #else vec4 v1, v2, v3; @@ -130,9 +130,9 @@ void glm_translate_x(mat4 m, float x) { #if defined( __SSE__ ) || defined( __SSE2__ ) _mm_store_ps(m[3], - _mm_add_ps(_mm_mul_ps(_mm_load_ps(m[0]), + _mm_add_ps(_mm_mul_ps(glmm_load(m[0]), _mm_set1_ps(x)), - _mm_load_ps(m[3]))) + glmm_load(m[3]))) ; #else vec4 v1; @@ -152,9 +152,9 @@ void glm_translate_y(mat4 m, float y) { #if defined( __SSE__ ) || defined( __SSE2__ ) _mm_store_ps(m[3], - _mm_add_ps(_mm_mul_ps(_mm_load_ps(m[1]), + _mm_add_ps(_mm_mul_ps(glmm_load(m[1]), _mm_set1_ps(y)), - _mm_load_ps(m[3]))) + glmm_load(m[3]))) ; #else vec4 v1; @@ -174,9 +174,9 @@ void glm_translate_z(mat4 m, float z) { #if defined( __SSE__ ) || defined( __SSE2__ ) _mm_store_ps(m[3], - _mm_add_ps(_mm_mul_ps(_mm_load_ps(m[2]), + _mm_add_ps(_mm_mul_ps(glmm_load(m[2]), _mm_set1_ps(z)), - _mm_load_ps(m[3]))) + glmm_load(m[3]))) ; #else vec4 v1; diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index d1a72cb..8cafb7c 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -113,10 +113,10 @@ glm_mat4_copy(mat4 mat, mat4 dest) { _mm256_store_ps(dest[0], _mm256_load_ps(mat[0])); _mm256_store_ps(dest[2], _mm256_load_ps(mat[2])); #elif defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest[0], _mm_load_ps(mat[0])); - _mm_store_ps(dest[1], _mm_load_ps(mat[1])); - _mm_store_ps(dest[2], _mm_load_ps(mat[2])); - _mm_store_ps(dest[3], _mm_load_ps(mat[3])); + _mm_store_ps(dest[0], glmm_load(mat[0])); + _mm_store_ps(dest[1], glmm_load(mat[1])); + _mm_store_ps(dest[2], glmm_load(mat[2])); + _mm_store_ps(dest[3], glmm_load(mat[3])); #else glm_mat4_ucopy(mat, dest); #endif diff --git a/include/cglm/quat.h b/include/cglm/quat.h index f6dc86e..6bff527 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -198,7 +198,7 @@ glm_quat_normalize_to(versor q, versor dest) { __m128 xdot, x0; float dot; - x0 = _mm_load_ps(q); + x0 = glmm_load(q); xdot = glm_simd_dot(x0, x0); dot = _mm_cvtss_f32(xdot); diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index cf6753f..bf1db60 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -35,7 +35,7 @@ _mm_shuffle1_ps(_mm_shuffle_ps(a, b, _MM_SHUFFLE(z0, y0, x0, w0)), \ z1, y1, x1, w1) -CGLM_INLINE +static inline __m128 glm_simd_dot(__m128 a, __m128 b) { __m128 x0; @@ -44,7 +44,7 @@ glm_simd_dot(__m128 a, __m128 b) { return _mm_add_ps(x0, _mm_shuffle1_ps(x0, 0, 1, 0, 1)); } -CGLM_INLINE +static inline __m128 glm_simd_norm(__m128 a) { return _mm_sqrt_ps(glm_simd_dot(a, a)); @@ -69,6 +69,14 @@ glm_simd_store_v3(__m128 vx, vec3 v) { _mm_store_ss(&v[2], _mm_shuffle1_ps(vx, 2, 2, 2, 2)); } +#ifdef CGLM_ALL_UNALIGNED +#define glmm_load(p) _mm_loadu_ps(p) +#define glmm_store(p, a) _mm_storeu_ps(p, a) +#else +#define glmm_load(p) _mm_load_ps(p) +#define glmm_store(p, a) _mm_store_ps(p, a) +#endif + #endif /* x86, x64 */ diff --git a/include/cglm/simd/sse2/affine.h b/include/cglm/simd/sse2/affine.h index b746d0f..df8c166 100644 --- a/include/cglm/simd/sse2/affine.h +++ b/include/cglm/simd/sse2/affine.h @@ -18,30 +18,30 @@ glm_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ __m128 l0, l1, l2, l3, r; - l0 = _mm_load_ps(m1[0]); - l1 = _mm_load_ps(m1[1]); - l2 = _mm_load_ps(m1[2]); - l3 = _mm_load_ps(m1[3]); + l0 = glmm_load(m1[0]); + l1 = glmm_load(m1[1]); + l2 = glmm_load(m1[2]); + l3 = glmm_load(m1[3]); - r = _mm_load_ps(m2[0]); + r = glmm_load(m2[0]); _mm_store_ps(dest[0], _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); - r = _mm_load_ps(m2[1]); + r = glmm_load(m2[1]); _mm_store_ps(dest[1], _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); - r = _mm_load_ps(m2[2]); + r = glmm_load(m2[2]); _mm_store_ps(dest[2], _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); - r = _mm_load_ps(m2[3]); + r = glmm_load(m2[3]); _mm_store_ps(dest[3], _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), @@ -55,24 +55,24 @@ glm_mul_rot_sse2(mat4 m1, mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ __m128 l0, l1, l2, l3, r; - l0 = _mm_load_ps(m1[0]); - l1 = _mm_load_ps(m1[1]); - l2 = _mm_load_ps(m1[2]); - l3 = _mm_load_ps(m1[3]); + l0 = glmm_load(m1[0]); + l1 = glmm_load(m1[1]); + l2 = glmm_load(m1[2]); + l3 = glmm_load(m1[3]); - r = _mm_load_ps(m2[0]); + r = glmm_load(m2[0]); _mm_store_ps(dest[0], _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); - r = _mm_load_ps(m2[1]); + r = glmm_load(m2[1]); _mm_store_ps(dest[1], _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); - r = _mm_load_ps(m2[2]); + r = glmm_load(m2[2]); _mm_store_ps(dest[2], _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), @@ -86,10 +86,10 @@ void glm_inv_tr_sse2(mat4 mat) { __m128 r0, r1, r2, r3, x0, x1; - r0 = _mm_load_ps(mat[0]); - r1 = _mm_load_ps(mat[1]); - r2 = _mm_load_ps(mat[2]); - r3 = _mm_load_ps(mat[3]); + r0 = glmm_load(mat[0]); + r1 = glmm_load(mat[1]); + r2 = glmm_load(mat[2]); + r3 = glmm_load(mat[3]); x1 = _mm_set_ps(1.0f, 0.0f, 0.0f, 0.0f); _MM_TRANSPOSE4_PS(r0, r1, r2, x1); diff --git a/include/cglm/simd/sse2/mat4.h b/include/cglm/simd/sse2/mat4.h index 77874a8..404b496 100644 --- a/include/cglm/simd/sse2/mat4.h +++ b/include/cglm/simd/sse2/mat4.h @@ -20,10 +20,10 @@ glm_mat4_scale_sse2(mat4 m, float s){ __m128 x0; x0 = _mm_set1_ps(s); - _mm_store_ps(m[0], _mm_mul_ps(_mm_load_ps(m[0]), x0)); - _mm_store_ps(m[1], _mm_mul_ps(_mm_load_ps(m[1]), x0)); - _mm_store_ps(m[2], _mm_mul_ps(_mm_load_ps(m[2]), x0)); - _mm_store_ps(m[3], _mm_mul_ps(_mm_load_ps(m[3]), x0)); + _mm_store_ps(m[0], _mm_mul_ps(glmm_load(m[0]), x0)); + _mm_store_ps(m[1], _mm_mul_ps(glmm_load(m[1]), x0)); + _mm_store_ps(m[2], _mm_mul_ps(glmm_load(m[2]), x0)); + _mm_store_ps(m[3], _mm_mul_ps(glmm_load(m[3]), x0)); } CGLM_INLINE @@ -31,10 +31,10 @@ void glm_mat4_transp_sse2(mat4 m, mat4 dest){ __m128 r0, r1, r2, r3; - r0 = _mm_load_ps(m[0]); - r1 = _mm_load_ps(m[1]); - r2 = _mm_load_ps(m[2]); - r3 = _mm_load_ps(m[3]); + r0 = glmm_load(m[0]); + r1 = glmm_load(m[1]); + r2 = glmm_load(m[2]); + r3 = glmm_load(m[3]); _MM_TRANSPOSE4_PS(r0, r1, r2, r3); @@ -51,31 +51,31 @@ glm_mat4_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { __m128 l0, l1, l2, l3, r; - l0 = _mm_load_ps(m1[0]); - l1 = _mm_load_ps(m1[1]); - l2 = _mm_load_ps(m1[2]); - l3 = _mm_load_ps(m1[3]); + l0 = glmm_load(m1[0]); + l1 = glmm_load(m1[1]); + l2 = glmm_load(m1[2]); + l3 = glmm_load(m1[3]); - r = _mm_load_ps(m2[0]); + r = glmm_load(m2[0]); _mm_store_ps(dest[0], _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); - r = _mm_load_ps(m2[1]); + r = glmm_load(m2[1]); _mm_store_ps(dest[1], _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); - r = _mm_load_ps(m2[2]); + r = glmm_load(m2[2]); _mm_store_ps(dest[2], _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); - r = _mm_load_ps(m2[3]); + r = glmm_load(m2[3]); _mm_store_ps(dest[3], _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), @@ -88,15 +88,15 @@ void glm_mat4_mulv_sse2(mat4 m, vec4 v, vec4 dest) { __m128 x0, x1, x2; - x0 = _mm_load_ps(v); - x1 = _mm_add_ps(_mm_mul_ps(_mm_load_ps(m[0]), + x0 = glmm_load(v); + x1 = _mm_add_ps(_mm_mul_ps(glmm_load(m[0]), _mm_shuffle1_ps1(x0, 0)), - _mm_mul_ps(_mm_load_ps(m[1]), + _mm_mul_ps(glmm_load(m[1]), _mm_shuffle1_ps1(x0, 1))); - x2 = _mm_add_ps(_mm_mul_ps(_mm_load_ps(m[2]), + x2 = _mm_add_ps(_mm_mul_ps(glmm_load(m[2]), _mm_shuffle1_ps1(x0, 2)), - _mm_mul_ps(_mm_load_ps(m[3]), + _mm_mul_ps(glmm_load(m[3]), _mm_shuffle1_ps1(x0, 3))); _mm_store_ps(dest, _mm_add_ps(x1, x2)); @@ -108,10 +108,10 @@ glm_mat4_det_sse2(mat4 mat) { __m128 r0, r1, r2, r3, x0, x1, x2; /* 127 <- 0, [square] det(A) = det(At) */ - r0 = _mm_load_ps(mat[0]); /* d c b a */ - r1 = _mm_load_ps(mat[1]); /* h g f e */ - r2 = _mm_load_ps(mat[2]); /* l k j i */ - r3 = _mm_load_ps(mat[3]); /* p o n m */ + r0 = glmm_load(mat[0]); /* d c b a */ + r1 = glmm_load(mat[1]); /* h g f e */ + r2 = glmm_load(mat[2]); /* l k j i */ + r3 = glmm_load(mat[3]); /* p o n m */ /* t[1] = j * p - n * l; @@ -166,10 +166,10 @@ glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { x0, x1, x2, x3, x4, x5, x6, x7; /* 127 <- 0 */ - r0 = _mm_load_ps(mat[0]); /* d c b a */ - r1 = _mm_load_ps(mat[1]); /* h g f e */ - r2 = _mm_load_ps(mat[2]); /* l k j i */ - r3 = _mm_load_ps(mat[3]); /* p o n m */ + r0 = glmm_load(mat[0]); /* d c b a */ + r1 = glmm_load(mat[1]); /* h g f e */ + r2 = glmm_load(mat[2]); /* l k j i */ + r3 = glmm_load(mat[3]); /* p o n m */ x0 = _mm_shuffle_ps(r2, r3, _MM_SHUFFLE(3, 2, 3, 2)); /* p o l k */ x1 = _mm_shuffle1_ps(x0, 1, 3, 3, 3); /* l p p p */ @@ -290,10 +290,10 @@ glm_mat4_inv_sse2(mat4 mat, mat4 dest) { x0, x1, x2, x3, x4, x5, x6, x7; /* 127 <- 0 */ - r0 = _mm_load_ps(mat[0]); /* d c b a */ - r1 = _mm_load_ps(mat[1]); /* h g f e */ - r2 = _mm_load_ps(mat[2]); /* l k j i */ - r3 = _mm_load_ps(mat[3]); /* p o n m */ + r0 = glmm_load(mat[0]); /* d c b a */ + r1 = glmm_load(mat[1]); /* h g f e */ + r2 = glmm_load(mat[2]); /* l k j i */ + r3 = glmm_load(mat[3]); /* p o n m */ x0 = _mm_shuffle_ps(r2, r3, _MM_SHUFFLE(3, 2, 3, 2)); /* p o l k */ x1 = _mm_shuffle1_ps(x0, 1, 3, 3, 3); /* l p p p */ diff --git a/include/cglm/simd/sse2/quat.h b/include/cglm/simd/sse2/quat.h index 5dbf759..4970eff 100644 --- a/include/cglm/simd/sse2/quat.h +++ b/include/cglm/simd/sse2/quat.h @@ -24,8 +24,8 @@ glm_quat_mul_sse2(versor p, versor q, versor dest) { __m128 xp, xq, x0, r; - xp = _mm_load_ps(p); /* 3 2 1 0 */ - xq = _mm_load_ps(q); + xp = glmm_load(p); /* 3 2 1 0 */ + xq = glmm_load(q); r = _mm_mul_ps(_mm_shuffle1_ps1(xp, 3), xq); diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index 7a6cb3d..1055ebe 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -42,7 +42,7 @@ CGLM_INLINE void glm_vec4_mulv(vec4 a, vec4 b, vec4 d) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(d, _mm_mul_ps(_mm_load_ps(a), _mm_load_ps(b))); + _mm_store_ps(d, _mm_mul_ps(glmm_load(a), glmm_load(b))); #else d[0] = a[0] * b[0]; d[1] = a[1] * b[1]; @@ -223,7 +223,7 @@ glm_vec4_sign(vec4 v, vec4 dest) { #if defined( __SSE2__ ) || defined( __SSE2__ ) __m128 x0, x1, x2, x3, x4; - x0 = _mm_load_ps(v); + x0 = glmm_load(v); x1 = _mm_set_ps(0.0f, 0.0f, 1.0f, -1.0f); x2 = _mm_shuffle1_ps1(x1, 2); @@ -249,7 +249,7 @@ CGLM_INLINE void glm_vec4_sqrt(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_sqrt_ps(_mm_load_ps(v))); + _mm_store_ps(dest, _mm_sqrt_ps(glmm_load(v))); #else dest[0] = sqrtf(v[0]); dest[1] = sqrtf(v[1]); diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 2e9ca45..b2a9b97 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -111,7 +111,7 @@ CGLM_INLINE void glm_vec4_copy(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_load_ps(v)); + _mm_store_ps(dest, glmm_load(v)); #else dest[0] = v[0]; dest[1] = v[1]; @@ -169,7 +169,7 @@ float glm_vec4_dot(vec4 a, vec4 b) { #if defined( __SSE__ ) || defined( __SSE2__ ) __m128 x0; - x0 = _mm_mul_ps(_mm_load_ps(a), _mm_load_ps(b)); + x0 = _mm_mul_ps(glmm_load(a), glmm_load(b)); x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 3, 2)); return _mm_cvtss_f32(_mm_add_ss(x0, _mm_shuffle1_ps(x0, 0, 1, 0, 1))); #else @@ -193,7 +193,7 @@ float glm_vec4_norm2(vec4 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) __m128 x0; - x0 = _mm_load_ps(v); + x0 = glmm_load(v); x0 = _mm_mul_ps(x0, x0); x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 3, 2)); return _mm_cvtss_f32(_mm_add_ss(x0, _mm_shuffle1_ps(x0, 0, 1, 0, 1))); @@ -214,7 +214,7 @@ float glm_vec4_norm(vec4 vec) { #if defined( __SSE__ ) || defined( __SSE2__ ) __m128 x0; - x0 = _mm_load_ps(vec); + x0 = glmm_load(vec); return _mm_cvtss_f32(_mm_sqrt_ss(glm_simd_dot(x0, x0))); #else return sqrtf(glm_vec4_norm2(vec)); @@ -232,7 +232,7 @@ CGLM_INLINE void glm_vec4_add(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(a), _mm_load_ps(b))); + _mm_store_ps(dest, _mm_add_ps(glmm_load(a), glmm_load(b))); #else dest[0] = a[0] + b[0]; dest[1] = a[1] + b[1]; @@ -252,7 +252,7 @@ CGLM_INLINE void glm_vec4_adds(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(v), _mm_set1_ps(s))); + _mm_store_ps(dest, _mm_add_ps(glmm_load(v), _mm_set1_ps(s))); #else dest[0] = v[0] + s; dest[1] = v[1] + s; @@ -272,7 +272,7 @@ CGLM_INLINE void glm_vec4_sub(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_sub_ps(_mm_load_ps(a), _mm_load_ps(b))); + _mm_store_ps(dest, _mm_sub_ps(glmm_load(a), glmm_load(b))); #else dest[0] = a[0] - b[0]; dest[1] = a[1] - b[1]; @@ -292,7 +292,7 @@ CGLM_INLINE void glm_vec4_subs(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_sub_ps(_mm_load_ps(v), _mm_set1_ps(s))); + _mm_store_ps(dest, _mm_sub_ps(glmm_load(v), _mm_set1_ps(s))); #else dest[0] = v[0] - s; dest[1] = v[1] - s; @@ -312,7 +312,7 @@ CGLM_INLINE void glm_vec4_mul(vec4 a, vec4 b, vec4 d) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(d, _mm_mul_ps(_mm_load_ps(a), _mm_load_ps(b))); + _mm_store_ps(d, _mm_mul_ps(glmm_load(a), glmm_load(b))); #else d[0] = a[0] * b[0]; d[1] = a[1] * b[1]; @@ -332,7 +332,7 @@ CGLM_INLINE void glm_vec4_scale(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_mul_ps(_mm_load_ps(v), _mm_set1_ps(s))); + _mm_store_ps(dest, _mm_mul_ps(glmm_load(v), _mm_set1_ps(s))); #else dest[0] = v[0] * s; dest[1] = v[1] * s; @@ -373,7 +373,7 @@ CGLM_INLINE void glm_vec4_div(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_div_ps(_mm_load_ps(a), _mm_load_ps(b))); + _mm_store_ps(dest, _mm_div_ps(glmm_load(a), glmm_load(b))); #else dest[0] = a[0] / b[0]; dest[1] = a[1] / b[1]; @@ -393,7 +393,7 @@ CGLM_INLINE void glm_vec4_divs(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_div_ps(_mm_load_ps(v), _mm_set1_ps(s))); + _mm_store_ps(dest, _mm_div_ps(glmm_load(v), _mm_set1_ps(s))); #else glm_vec4_scale(v, 1.0f / s, dest); #endif @@ -413,9 +413,9 @@ CGLM_INLINE void glm_vec4_addadd(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(dest), - _mm_add_ps(_mm_load_ps(a), - _mm_load_ps(b)))); + _mm_store_ps(dest, _mm_add_ps(glmm_load(dest), + _mm_add_ps(glmm_load(a), + glmm_load(b)))); #else dest[0] += a[0] + b[0]; dest[1] += a[1] + b[1]; @@ -437,9 +437,9 @@ CGLM_INLINE void glm_vec4_subadd(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(dest), - _mm_sub_ps(_mm_load_ps(a), - _mm_load_ps(b)))); + _mm_store_ps(dest, _mm_add_ps(glmm_load(dest), + _mm_sub_ps(glmm_load(a), + glmm_load(b)))); #else dest[0] += a[0] - b[0]; dest[1] += a[1] - b[1]; @@ -461,9 +461,9 @@ CGLM_INLINE void glm_vec4_muladd(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(dest), - _mm_mul_ps(_mm_load_ps(a), - _mm_load_ps(b)))); + _mm_store_ps(dest, _mm_add_ps(glmm_load(dest), + _mm_mul_ps(glmm_load(a), + glmm_load(b)))); #else dest[0] += a[0] * b[0]; dest[1] += a[1] * b[1]; @@ -485,8 +485,8 @@ CGLM_INLINE void glm_vec4_muladds(vec4 a, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_add_ps(_mm_load_ps(dest), - _mm_mul_ps(_mm_load_ps(a), + _mm_store_ps(dest, _mm_add_ps(glmm_load(dest), + _mm_mul_ps(glmm_load(a), _mm_set1_ps(s)))); #else dest[0] += a[0] * s; @@ -505,7 +505,7 @@ CGLM_INLINE void glm_vec4_flipsign(vec4 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(v, _mm_xor_ps(_mm_load_ps(v), _mm_set1_ps(-0.0f))); + _mm_store_ps(v, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); #else v[0] = -v[0]; v[1] = -v[1]; @@ -524,7 +524,7 @@ CGLM_INLINE void glm_vec4_flipsign_to(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_xor_ps(_mm_load_ps(v), + _mm_store_ps(dest, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); #else dest[0] = -v[0]; @@ -571,7 +571,7 @@ glm_vec4_normalize_to(vec4 vec, vec4 dest) { __m128 xdot, x0; float dot; - x0 = _mm_load_ps(vec); + x0 = glmm_load(vec); xdot = glm_simd_dot(x0, x0); dot = _mm_cvtss_f32(xdot); @@ -633,7 +633,7 @@ CGLM_INLINE void glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_max_ps(_mm_load_ps(v1), _mm_load_ps(v2))); + _mm_store_ps(dest, _mm_max_ps(glmm_load(v1), glmm_load(v2))); #else dest[0] = glm_max(v1[0], v2[0]); dest[1] = glm_max(v1[1], v2[1]); @@ -653,7 +653,7 @@ CGLM_INLINE void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_min_ps(_mm_load_ps(v1), _mm_load_ps(v2))); + _mm_store_ps(dest, _mm_min_ps(glmm_load(v1), glmm_load(v2))); #else dest[0] = glm_min(v1[0], v2[0]); dest[1] = glm_min(v1[1], v2[1]); @@ -673,7 +673,7 @@ CGLM_INLINE void glm_vec4_clamp(vec4 v, float minVal, float maxVal) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(v, _mm_min_ps(_mm_max_ps(_mm_load_ps(v), _mm_set1_ps(minVal)), + _mm_store_ps(v, _mm_min_ps(_mm_max_ps(glmm_load(v), _mm_set1_ps(minVal)), _mm_set1_ps(maxVal))); #else v[0] = glm_clamp(v[0], minVal, maxVal); From 568001d26a5b047a2e1ac438497e8a778048fb8f Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 8 May 2018 15:31:09 +0300 Subject: [PATCH 148/292] simd, sse2: make alignment optional for store operations --- include/cglm/affine.h | 62 +++++++++++++-------------- include/cglm/mat4.h | 8 ++-- include/cglm/quat.h | 2 +- include/cglm/simd/sse2/affine.h | 68 +++++++++++++++--------------- include/cglm/simd/sse2/mat4.h | 74 ++++++++++++++++----------------- include/cglm/simd/sse2/quat.h | 2 +- include/cglm/vec4-ext.h | 8 ++-- include/cglm/vec4.h | 63 ++++++++++++++-------------- 8 files changed, 143 insertions(+), 144 deletions(-) diff --git a/include/cglm/affine.h b/include/cglm/affine.h index b200f30..dd7dbd1 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -58,19 +58,19 @@ glm_translate_to(mat4 m, vec3 v, mat4 dest) { mat4 t = GLM_MAT4_IDENTITY_INIT; #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest[3], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_load(t[0]), - _mm_set1_ps(v[0])), - _mm_mul_ps(glmm_load(t[1]), - _mm_set1_ps(v[1]))), - _mm_add_ps(_mm_mul_ps(glmm_load(t[2]), - _mm_set1_ps(v[2])), - glmm_load(t[3])))) + glmm_store(dest[3], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_load(t[0]), + _mm_set1_ps(v[0])), + _mm_mul_ps(glmm_load(t[1]), + _mm_set1_ps(v[1]))), + _mm_add_ps(_mm_mul_ps(glmm_load(t[2]), + _mm_set1_ps(v[2])), + glmm_load(t[3])))) ; - _mm_store_ps(dest[0], glmm_load(m[0])); - _mm_store_ps(dest[1], glmm_load(m[1])); - _mm_store_ps(dest[2], glmm_load(m[2])); + glmm_store(dest[0], glmm_load(m[0])); + glmm_store(dest[1], glmm_load(m[1])); + glmm_store(dest[2], glmm_load(m[2])); #else vec4 v1, v2, v3; @@ -97,14 +97,14 @@ CGLM_INLINE void glm_translate(mat4 m, vec3 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(m[3], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_load(m[0]), - _mm_set1_ps(v[0])), - _mm_mul_ps(glmm_load(m[1]), - _mm_set1_ps(v[1]))), - _mm_add_ps(_mm_mul_ps(glmm_load(m[2]), - _mm_set1_ps(v[2])), - glmm_load(m[3])))) + glmm_store(m[3], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_load(m[0]), + _mm_set1_ps(v[0])), + _mm_mul_ps(glmm_load(m[1]), + _mm_set1_ps(v[1]))), + _mm_add_ps(_mm_mul_ps(glmm_load(m[2]), + _mm_set1_ps(v[2])), + glmm_load(m[3])))) ; #else vec4 v1, v2, v3; @@ -129,10 +129,10 @@ CGLM_INLINE void glm_translate_x(mat4 m, float x) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(m[3], - _mm_add_ps(_mm_mul_ps(glmm_load(m[0]), - _mm_set1_ps(x)), - glmm_load(m[3]))) + glmm_store(m[3], + _mm_add_ps(_mm_mul_ps(glmm_load(m[0]), + _mm_set1_ps(x)), + glmm_load(m[3]))) ; #else vec4 v1; @@ -151,10 +151,10 @@ CGLM_INLINE void glm_translate_y(mat4 m, float y) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(m[3], - _mm_add_ps(_mm_mul_ps(glmm_load(m[1]), - _mm_set1_ps(y)), - glmm_load(m[3]))) + glmm_store(m[3], + _mm_add_ps(_mm_mul_ps(glmm_load(m[1]), + _mm_set1_ps(y)), + glmm_load(m[3]))) ; #else vec4 v1; @@ -173,10 +173,10 @@ CGLM_INLINE void glm_translate_z(mat4 m, float z) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(m[3], - _mm_add_ps(_mm_mul_ps(glmm_load(m[2]), - _mm_set1_ps(z)), - glmm_load(m[3]))) + glmm_store(m[3], + _mm_add_ps(_mm_mul_ps(glmm_load(m[2]), + _mm_set1_ps(z)), + glmm_load(m[3]))) ; #else vec4 v1; diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 8cafb7c..88563cb 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -113,10 +113,10 @@ glm_mat4_copy(mat4 mat, mat4 dest) { _mm256_store_ps(dest[0], _mm256_load_ps(mat[0])); _mm256_store_ps(dest[2], _mm256_load_ps(mat[2])); #elif defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest[0], glmm_load(mat[0])); - _mm_store_ps(dest[1], glmm_load(mat[1])); - _mm_store_ps(dest[2], glmm_load(mat[2])); - _mm_store_ps(dest[3], glmm_load(mat[3])); + glmm_store(dest[0], glmm_load(mat[0])); + glmm_store(dest[1], glmm_load(mat[1])); + glmm_store(dest[2], glmm_load(mat[2])); + glmm_store(dest[3], glmm_load(mat[3])); #else glm_mat4_ucopy(mat, dest); #endif diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 6bff527..0ba2cf6 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -207,7 +207,7 @@ glm_quat_normalize_to(versor q, versor dest) { return; } - _mm_store_ps(dest, _mm_div_ps(x0, _mm_sqrt_ps(xdot))); + glmm_store(dest, _mm_div_ps(x0, _mm_sqrt_ps(xdot))); #else float dot; diff --git a/include/cglm/simd/sse2/affine.h b/include/cglm/simd/sse2/affine.h index df8c166..c0c9c04 100644 --- a/include/cglm/simd/sse2/affine.h +++ b/include/cglm/simd/sse2/affine.h @@ -24,29 +24,29 @@ glm_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { l3 = glmm_load(m1[3]); r = glmm_load(m2[0]); - _mm_store_ps(dest[0], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + glmm_store(dest[0], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); r = glmm_load(m2[1]); - _mm_store_ps(dest[1], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + glmm_store(dest[1], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); r = glmm_load(m2[2]); - _mm_store_ps(dest[2], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + glmm_store(dest[2], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); r = glmm_load(m2[3]); - _mm_store_ps(dest[3], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), - _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + glmm_store(dest[3], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), + _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); } CGLM_INLINE @@ -61,24 +61,24 @@ glm_mul_rot_sse2(mat4 m1, mat4 m2, mat4 dest) { l3 = glmm_load(m1[3]); r = glmm_load(m2[0]); - _mm_store_ps(dest[0], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + glmm_store(dest[0], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); r = glmm_load(m2[1]); - _mm_store_ps(dest[1], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + glmm_store(dest[1], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); r = glmm_load(m2[2]); - _mm_store_ps(dest[2], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + glmm_store(dest[2], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); - _mm_store_ps(dest[3], l3); + glmm_store(dest[3], l3); } CGLM_INLINE @@ -101,10 +101,10 @@ glm_inv_tr_sse2(mat4 mat) { x0 = _mm_add_ps(x0, x1); - _mm_store_ps(mat[0], r0); - _mm_store_ps(mat[1], r1); - _mm_store_ps(mat[2], r2); - _mm_store_ps(mat[3], x0); + glmm_store(mat[0], r0); + glmm_store(mat[1], r1); + glmm_store(mat[2], r2); + glmm_store(mat[3], x0); } #endif diff --git a/include/cglm/simd/sse2/mat4.h b/include/cglm/simd/sse2/mat4.h index 404b496..1f82c08 100644 --- a/include/cglm/simd/sse2/mat4.h +++ b/include/cglm/simd/sse2/mat4.h @@ -20,10 +20,10 @@ glm_mat4_scale_sse2(mat4 m, float s){ __m128 x0; x0 = _mm_set1_ps(s); - _mm_store_ps(m[0], _mm_mul_ps(glmm_load(m[0]), x0)); - _mm_store_ps(m[1], _mm_mul_ps(glmm_load(m[1]), x0)); - _mm_store_ps(m[2], _mm_mul_ps(glmm_load(m[2]), x0)); - _mm_store_ps(m[3], _mm_mul_ps(glmm_load(m[3]), x0)); + glmm_store(m[0], _mm_mul_ps(glmm_load(m[0]), x0)); + glmm_store(m[1], _mm_mul_ps(glmm_load(m[1]), x0)); + glmm_store(m[2], _mm_mul_ps(glmm_load(m[2]), x0)); + glmm_store(m[3], _mm_mul_ps(glmm_load(m[3]), x0)); } CGLM_INLINE @@ -38,10 +38,10 @@ glm_mat4_transp_sse2(mat4 m, mat4 dest){ _MM_TRANSPOSE4_PS(r0, r1, r2, r3); - _mm_store_ps(dest[0], r0); - _mm_store_ps(dest[1], r1); - _mm_store_ps(dest[2], r2); - _mm_store_ps(dest[3], r3); + glmm_store(dest[0], r0); + glmm_store(dest[1], r1); + glmm_store(dest[2], r2); + glmm_store(dest[3], r3); } CGLM_INLINE @@ -57,30 +57,30 @@ glm_mat4_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { l3 = glmm_load(m1[3]); r = glmm_load(m2[0]); - _mm_store_ps(dest[0], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), - _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + glmm_store(dest[0], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), + _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); r = glmm_load(m2[1]); - _mm_store_ps(dest[1], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), - _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + glmm_store(dest[1], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), + _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); r = glmm_load(m2[2]); - _mm_store_ps(dest[2], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), - _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + glmm_store(dest[2], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), + _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); r = glmm_load(m2[3]); - _mm_store_ps(dest[3], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), - _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + glmm_store(dest[3], + _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), + _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), + _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); } CGLM_INLINE @@ -99,7 +99,7 @@ glm_mat4_mulv_sse2(mat4 m, vec4 v, vec4 dest) { _mm_mul_ps(glmm_load(m[3]), _mm_shuffle1_ps1(x0, 3))); - _mm_store_ps(dest, _mm_add_ps(x1, x2)); + glmm_store(dest, _mm_add_ps(x1, x2)); } CGLM_INLINE @@ -275,10 +275,10 @@ glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 0, 1)); x0 = _mm_rcp_ps(x0); - _mm_store_ps(dest[0], _mm_mul_ps(v0, x0)); - _mm_store_ps(dest[1], _mm_mul_ps(v1, x0)); - _mm_store_ps(dest[2], _mm_mul_ps(v2, x0)); - _mm_store_ps(dest[3], _mm_mul_ps(v3, x0)); + glmm_store(dest[0], _mm_mul_ps(v0, x0)); + glmm_store(dest[1], _mm_mul_ps(v1, x0)); + glmm_store(dest[2], _mm_mul_ps(v2, x0)); + glmm_store(dest[3], _mm_mul_ps(v3, x0)); } CGLM_INLINE @@ -399,10 +399,10 @@ glm_mat4_inv_sse2(mat4 mat, mat4 dest) { x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 0, 1)); x0 = _mm_div_ps(_mm_set1_ps(1.0f), x0); - _mm_store_ps(dest[0], _mm_mul_ps(v0, x0)); - _mm_store_ps(dest[1], _mm_mul_ps(v1, x0)); - _mm_store_ps(dest[2], _mm_mul_ps(v2, x0)); - _mm_store_ps(dest[3], _mm_mul_ps(v3, x0)); + glmm_store(dest[0], _mm_mul_ps(v0, x0)); + glmm_store(dest[1], _mm_mul_ps(v1, x0)); + glmm_store(dest[2], _mm_mul_ps(v2, x0)); + glmm_store(dest[3], _mm_mul_ps(v3, x0)); } #endif diff --git a/include/cglm/simd/sse2/quat.h b/include/cglm/simd/sse2/quat.h index 4970eff..a8b517c 100644 --- a/include/cglm/simd/sse2/quat.h +++ b/include/cglm/simd/sse2/quat.h @@ -38,7 +38,7 @@ glm_quat_mul_sse2(versor p, versor q, versor dest) { x0 = _mm_xor_ps(_mm_shuffle1_ps1(xp, 2), _mm_set_ps(-0.f, 0.f, 0.f, -0.f)); r = _mm_add_ps(r, _mm_mul_ps(x0, _mm_shuffle1_ps(xq, 2, 3, 0, 1))); - _mm_store_ps(dest, r); + glmm_store(dest, r); } diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index 1055ebe..94150da 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -42,7 +42,7 @@ CGLM_INLINE void glm_vec4_mulv(vec4 a, vec4 b, vec4 d) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(d, _mm_mul_ps(glmm_load(a), glmm_load(b))); + glmm_store(d, _mm_mul_ps(glmm_load(a), glmm_load(b))); #else d[0] = a[0] * b[0]; d[1] = a[1] * b[1]; @@ -61,7 +61,7 @@ CGLM_INLINE void glm_vec4_broadcast(float val, vec4 d) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(d, _mm_set1_ps(val)); + glmm_store(d, _mm_set1_ps(val)); #else d[0] = d[1] = d[2] = d[3] = val; #endif @@ -230,7 +230,7 @@ glm_vec4_sign(vec4 v, vec4 dest) { x3 = _mm_and_ps(_mm_cmpgt_ps(x0, x2), _mm_shuffle1_ps1(x1, 1)); x4 = _mm_and_ps(_mm_cmplt_ps(x0, x2), _mm_shuffle1_ps1(x1, 0)); - _mm_store_ps(dest, _mm_or_ps(x3, x4)); + glmm_store(dest, _mm_or_ps(x3, x4)); #else dest[0] = glm_signf(v[0]); dest[1] = glm_signf(v[1]); @@ -249,7 +249,7 @@ CGLM_INLINE void glm_vec4_sqrt(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_sqrt_ps(glmm_load(v))); + glmm_store(dest, _mm_sqrt_ps(glmm_load(v))); #else dest[0] = sqrtf(v[0]); dest[1] = sqrtf(v[1]); diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index b2a9b97..912932f 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -111,7 +111,7 @@ CGLM_INLINE void glm_vec4_copy(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, glmm_load(v)); + glmm_store(dest, glmm_load(v)); #else dest[0] = v[0]; dest[1] = v[1]; @@ -129,7 +129,7 @@ CGLM_INLINE void glm_vec4_zero(vec4 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(v, _mm_setzero_ps()); + glmm_store(v, _mm_setzero_ps()); #else v[0] = 0.0f; v[1] = 0.0f; @@ -147,7 +147,7 @@ CGLM_INLINE void glm_vec4_one(vec4 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(v, _mm_set1_ps(1.0f)); + glmm_store(v, _mm_set1_ps(1.0f)); #else v[0] = 1.0f; v[1] = 1.0f; @@ -232,7 +232,7 @@ CGLM_INLINE void glm_vec4_add(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_add_ps(glmm_load(a), glmm_load(b))); + glmm_store(dest, _mm_add_ps(glmm_load(a), glmm_load(b))); #else dest[0] = a[0] + b[0]; dest[1] = a[1] + b[1]; @@ -252,7 +252,7 @@ CGLM_INLINE void glm_vec4_adds(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_add_ps(glmm_load(v), _mm_set1_ps(s))); + glmm_store(dest, _mm_add_ps(glmm_load(v), _mm_set1_ps(s))); #else dest[0] = v[0] + s; dest[1] = v[1] + s; @@ -272,7 +272,7 @@ CGLM_INLINE void glm_vec4_sub(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_sub_ps(glmm_load(a), glmm_load(b))); + glmm_store(dest, _mm_sub_ps(glmm_load(a), glmm_load(b))); #else dest[0] = a[0] - b[0]; dest[1] = a[1] - b[1]; @@ -292,7 +292,7 @@ CGLM_INLINE void glm_vec4_subs(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_sub_ps(glmm_load(v), _mm_set1_ps(s))); + glmm_store(dest, _mm_sub_ps(glmm_load(v), _mm_set1_ps(s))); #else dest[0] = v[0] - s; dest[1] = v[1] - s; @@ -312,7 +312,7 @@ CGLM_INLINE void glm_vec4_mul(vec4 a, vec4 b, vec4 d) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(d, _mm_mul_ps(glmm_load(a), glmm_load(b))); + glmm_store(d, _mm_mul_ps(glmm_load(a), glmm_load(b))); #else d[0] = a[0] * b[0]; d[1] = a[1] * b[1]; @@ -332,7 +332,7 @@ CGLM_INLINE void glm_vec4_scale(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_mul_ps(glmm_load(v), _mm_set1_ps(s))); + glmm_store(dest, _mm_mul_ps(glmm_load(v), _mm_set1_ps(s))); #else dest[0] = v[0] * s; dest[1] = v[1] * s; @@ -373,7 +373,7 @@ CGLM_INLINE void glm_vec4_div(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_div_ps(glmm_load(a), glmm_load(b))); + glmm_store(dest, _mm_div_ps(glmm_load(a), glmm_load(b))); #else dest[0] = a[0] / b[0]; dest[1] = a[1] / b[1]; @@ -393,7 +393,7 @@ CGLM_INLINE void glm_vec4_divs(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_div_ps(glmm_load(v), _mm_set1_ps(s))); + glmm_store(dest, _mm_div_ps(glmm_load(v), _mm_set1_ps(s))); #else glm_vec4_scale(v, 1.0f / s, dest); #endif @@ -413,9 +413,9 @@ CGLM_INLINE void glm_vec4_addadd(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_add_ps(glmm_load(dest), - _mm_add_ps(glmm_load(a), - glmm_load(b)))); + glmm_store(dest, _mm_add_ps(glmm_load(dest), + _mm_add_ps(glmm_load(a), + glmm_load(b)))); #else dest[0] += a[0] + b[0]; dest[1] += a[1] + b[1]; @@ -437,9 +437,9 @@ CGLM_INLINE void glm_vec4_subadd(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_add_ps(glmm_load(dest), - _mm_sub_ps(glmm_load(a), - glmm_load(b)))); + glmm_store(dest, _mm_add_ps(glmm_load(dest), + _mm_sub_ps(glmm_load(a), + glmm_load(b)))); #else dest[0] += a[0] - b[0]; dest[1] += a[1] - b[1]; @@ -461,9 +461,9 @@ CGLM_INLINE void glm_vec4_muladd(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_add_ps(glmm_load(dest), - _mm_mul_ps(glmm_load(a), - glmm_load(b)))); + glmm_store(dest, _mm_add_ps(glmm_load(dest), + _mm_mul_ps(glmm_load(a), + glmm_load(b)))); #else dest[0] += a[0] * b[0]; dest[1] += a[1] * b[1]; @@ -485,9 +485,9 @@ CGLM_INLINE void glm_vec4_muladds(vec4 a, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_add_ps(glmm_load(dest), - _mm_mul_ps(glmm_load(a), - _mm_set1_ps(s)))); + glmm_store(dest, _mm_add_ps(glmm_load(dest), + _mm_mul_ps(glmm_load(a), + _mm_set1_ps(s)))); #else dest[0] += a[0] * s; dest[1] += a[1] * s; @@ -505,7 +505,7 @@ CGLM_INLINE void glm_vec4_flipsign(vec4 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(v, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); + glmm_store(v, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); #else v[0] = -v[0]; v[1] = -v[1]; @@ -524,8 +524,7 @@ CGLM_INLINE void glm_vec4_flipsign_to(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_xor_ps(glmm_load(v), - _mm_set1_ps(-0.0f))); + glmm_store(dest, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); #else dest[0] = -v[0]; dest[1] = -v[1]; @@ -576,11 +575,11 @@ glm_vec4_normalize_to(vec4 vec, vec4 dest) { dot = _mm_cvtss_f32(xdot); if (dot == 0.0f) { - _mm_store_ps(dest, _mm_setzero_ps()); + glmm_store(dest, _mm_setzero_ps()); return; } - _mm_store_ps(dest, _mm_div_ps(x0, _mm_sqrt_ps(xdot))); + glmm_store(dest, _mm_div_ps(x0, _mm_sqrt_ps(xdot))); #else float norm; @@ -633,7 +632,7 @@ CGLM_INLINE void glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_max_ps(glmm_load(v1), glmm_load(v2))); + glmm_store(dest, _mm_max_ps(glmm_load(v1), glmm_load(v2))); #else dest[0] = glm_max(v1[0], v2[0]); dest[1] = glm_max(v1[1], v2[1]); @@ -653,7 +652,7 @@ CGLM_INLINE void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(dest, _mm_min_ps(glmm_load(v1), glmm_load(v2))); + glmm_store(dest, _mm_min_ps(glmm_load(v1), glmm_load(v2))); #else dest[0] = glm_min(v1[0], v2[0]); dest[1] = glm_min(v1[1], v2[1]); @@ -673,8 +672,8 @@ CGLM_INLINE void glm_vec4_clamp(vec4 v, float minVal, float maxVal) { #if defined( __SSE__ ) || defined( __SSE2__ ) - _mm_store_ps(v, _mm_min_ps(_mm_max_ps(glmm_load(v), _mm_set1_ps(minVal)), - _mm_set1_ps(maxVal))); + glmm_store(v, _mm_min_ps(_mm_max_ps(glmm_load(v), _mm_set1_ps(minVal)), + _mm_set1_ps(maxVal))); #else v[0] = glm_clamp(v[0], minVal, maxVal); v[1] = glm_clamp(v[1], minVal, maxVal); From 56f0bb0928e127ed993ec6e46aef9ad7d8cfd819 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 8 May 2018 15:35:17 +0300 Subject: [PATCH 149/292] simd, avx: make alignment optional for load/store operations --- include/cglm/mat4.h | 4 ++-- include/cglm/simd/avx/affine.h | 26 +++++++++++++------------- include/cglm/simd/avx/mat4.h | 28 ++++++++++++++-------------- include/cglm/simd/intrin.h | 17 +++++++++++++---- 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 88563cb..f0b6736 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -110,8 +110,8 @@ CGLM_INLINE void glm_mat4_copy(mat4 mat, mat4 dest) { #ifdef __AVX__ - _mm256_store_ps(dest[0], _mm256_load_ps(mat[0])); - _mm256_store_ps(dest[2], _mm256_load_ps(mat[2])); + glmm_store256(dest[0], glmm_load256(mat[0])); + glmm_store256(dest[2], glmm_load256(mat[2])); #elif defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest[0], glmm_load(mat[0])); glmm_store(dest[1], glmm_load(mat[1])); diff --git a/include/cglm/simd/avx/affine.h b/include/cglm/simd/avx/affine.h index 1b0dcea..5c7f71c 100644 --- a/include/cglm/simd/avx/affine.h +++ b/include/cglm/simd/avx/affine.h @@ -21,11 +21,11 @@ glm_mul_avx(mat4 m1, mat4 m2, mat4 dest) { __m256 y0, y1, y2, y3, y4, y5, y6, y7, y8, y9; - y0 = _mm256_load_ps(m2[0]); /* h g f e d c b a */ - y1 = _mm256_load_ps(m2[2]); /* p o n m l k j i */ + y0 = glmm_load256(m2[0]); /* h g f e d c b a */ + y1 = glmm_load256(m2[2]); /* p o n m l k j i */ - y2 = _mm256_load_ps(m1[0]); /* h g f e d c b a */ - y3 = _mm256_load_ps(m1[2]); /* p o n m l k j i */ + y2 = glmm_load256(m1[0]); /* h g f e d c b a */ + y3 = glmm_load256(m1[2]); /* p o n m l k j i */ y4 = _mm256_permute2f128_ps(y2, y2, 0b00000011); /* d c b a h g f e */ y5 = _mm256_permute2f128_ps(y3, y3, 0b00000000); /* l k j i l k j i */ @@ -37,10 +37,10 @@ glm_mul_avx(mat4 m1, mat4 m2, mat4 dest) { y6 = _mm256_permutevar_ps(y0, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); y8 = _mm256_permutevar_ps(y0, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); - _mm256_store_ps(dest[0], - _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), - _mm256_mul_ps(y4, y8)), - _mm256_mul_ps(y5, y7))); + glmm_store256(dest[0], + _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), + _mm256_mul_ps(y4, y8)), + _mm256_mul_ps(y5, y7))); /* n n n n i i i i */ @@ -52,11 +52,11 @@ glm_mul_avx(mat4 m1, mat4 m2, mat4 dest) { y8 = _mm256_permutevar_ps(y1, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); y9 = _mm256_permutevar_ps(y1, _mm256_set_epi32(2, 2, 2, 2, 3, 3, 3, 3)); - _mm256_store_ps(dest[2], - _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), - _mm256_mul_ps(y3, y7)), - _mm256_add_ps(_mm256_mul_ps(y4, y8), - _mm256_mul_ps(y5, y9)))); + glmm_store256(dest[2], + _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), + _mm256_mul_ps(y3, y7)), + _mm256_add_ps(_mm256_mul_ps(y4, y8), + _mm256_mul_ps(y5, y9)))); } #endif diff --git a/include/cglm/simd/avx/mat4.h b/include/cglm/simd/avx/mat4.h index e2ef9da..b5859a7 100644 --- a/include/cglm/simd/avx/mat4.h +++ b/include/cglm/simd/avx/mat4.h @@ -21,11 +21,11 @@ glm_mat4_mul_avx(mat4 m1, mat4 m2, mat4 dest) { __m256 y0, y1, y2, y3, y4, y5, y6, y7, y8, y9; - y0 = _mm256_load_ps(m2[0]); /* h g f e d c b a */ - y1 = _mm256_load_ps(m2[2]); /* p o n m l k j i */ + y0 = glmm_load256(m2[0]); /* h g f e d c b a */ + y1 = glmm_load256(m2[2]); /* p o n m l k j i */ - y2 = _mm256_load_ps(m1[0]); /* h g f e d c b a */ - y3 = _mm256_load_ps(m1[2]); /* p o n m l k j i */ + y2 = glmm_load256(m1[0]); /* h g f e d c b a */ + y3 = glmm_load256(m1[2]); /* p o n m l k j i */ y4 = _mm256_permute2f128_ps(y2, y2, 0b00000011); /* d c b a h g f e */ y5 = _mm256_permute2f128_ps(y3, y3, 0b00000011); /* l k j i p o n m */ @@ -39,11 +39,11 @@ glm_mat4_mul_avx(mat4 m1, mat4 m2, mat4 dest) { y8 = _mm256_permutevar_ps(y0, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); y9 = _mm256_permutevar_ps(y0, _mm256_set_epi32(2, 2, 2, 2, 3, 3, 3, 3)); - _mm256_store_ps(dest[0], - _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), - _mm256_mul_ps(y3, y7)), - _mm256_add_ps(_mm256_mul_ps(y4, y8), - _mm256_mul_ps(y5, y9)))); + glmm_store256(dest[0], + _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), + _mm256_mul_ps(y3, y7)), + _mm256_add_ps(_mm256_mul_ps(y4, y8), + _mm256_mul_ps(y5, y9)))); /* n n n n i i i i */ /* p p p p k k k k */ @@ -54,11 +54,11 @@ glm_mat4_mul_avx(mat4 m1, mat4 m2, mat4 dest) { y8 = _mm256_permutevar_ps(y1, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); y9 = _mm256_permutevar_ps(y1, _mm256_set_epi32(2, 2, 2, 2, 3, 3, 3, 3)); - _mm256_store_ps(dest[2], - _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), - _mm256_mul_ps(y3, y7)), - _mm256_add_ps(_mm256_mul_ps(y4, y8), - _mm256_mul_ps(y5, y9)))); + glmm_store256(dest[2], + _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), + _mm256_mul_ps(y3, y7)), + _mm256_add_ps(_mm256_mul_ps(y4, y8), + _mm256_mul_ps(y5, y9)))); } #endif diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index bf1db60..8fd1526 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -70,11 +70,11 @@ glm_simd_store_v3(__m128 vx, vec3 v) { } #ifdef CGLM_ALL_UNALIGNED -#define glmm_load(p) _mm_loadu_ps(p) -#define glmm_store(p, a) _mm_storeu_ps(p, a) +# define glmm_load(p) _mm_loadu_ps(p) +# define glmm_store(p, a) _mm_storeu_ps(p, a) #else -#define glmm_load(p) _mm_load_ps(p) -#define glmm_store(p, a) _mm_store_ps(p, a) +# define glmm_load(p) _mm_load_ps(p) +# define glmm_store(p, a) _mm_store_ps(p, a) #endif #endif @@ -86,6 +86,15 @@ glm_simd_store_v3(__m128 vx, vec3 v) { #ifdef __AVX__ # define CGLM_AVX_FP 1 + +#ifdef CGLM_ALL_UNALIGNED +# define glmm_load256(p) _mm256_loadu_ps(p) +# define glmm_store256(p, a) _mm256_storeu_ps(p, a) +#else +# define glmm_load256(p) _mm256_load_ps(p) +# define glmm_store256(p, a) _mm256_store_ps(p, a) +#endif + #endif /* ARM Neon */ From 5dbbd0826d1cd18f6722d193447d2b720aea9bdd Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 8 May 2018 15:55:36 +0300 Subject: [PATCH 150/292] simd: replace glm_simd_ with glmm_ * now glmm_ is used as global simd namescape --- include/cglm/quat.h | 2 +- include/cglm/simd/intrin.h | 10 +++++----- include/cglm/vec4.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 0ba2cf6..eac853b 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -199,7 +199,7 @@ glm_quat_normalize_to(versor q, versor dest) { float dot; x0 = glmm_load(q); - xdot = glm_simd_dot(x0, x0); + xdot = glmm_dot(x0, x0); dot = _mm_cvtss_f32(xdot); if (dot <= 0.0f) { diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index 8fd1526..c9ab352 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -37,7 +37,7 @@ static inline __m128 -glm_simd_dot(__m128 a, __m128 b) { +glmm_dot(__m128 a, __m128 b) { __m128 x0; x0 = _mm_mul_ps(a, b); x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 3, 2)); @@ -46,13 +46,13 @@ glm_simd_dot(__m128 a, __m128 b) { static inline __m128 -glm_simd_norm(__m128 a) { - return _mm_sqrt_ps(glm_simd_dot(a, a)); +glmm_norm(__m128 a) { + return _mm_sqrt_ps(glmm_dot(a, a)); } static inline __m128 -glm_simd_load_v3(vec3 v) { +glmm_load3(vec3 v) { __m128i xy; __m128 z; @@ -64,7 +64,7 @@ glm_simd_load_v3(vec3 v) { static inline void -glm_simd_store_v3(__m128 vx, vec3 v) { +glmm_store3(__m128 vx, vec3 v) { _mm_storel_pi((__m64 *)&v[0], vx); _mm_store_ss(&v[2], _mm_shuffle1_ps(vx, 2, 2, 2, 2)); } diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 912932f..b98190b 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -215,7 +215,7 @@ glm_vec4_norm(vec4 vec) { #if defined( __SSE__ ) || defined( __SSE2__ ) __m128 x0; x0 = glmm_load(vec); - return _mm_cvtss_f32(_mm_sqrt_ss(glm_simd_dot(x0, x0))); + return _mm_cvtss_f32(_mm_sqrt_ss(glmm_dot(x0, x0))); #else return sqrtf(glm_vec4_norm2(vec)); #endif @@ -571,7 +571,7 @@ glm_vec4_normalize_to(vec4 vec, vec4 dest) { float dot; x0 = glmm_load(vec); - xdot = glm_simd_dot(x0, x0); + xdot = glmm_dot(x0, x0); dot = _mm_cvtss_f32(xdot); if (dot == 0.0f) { From 835cec2ccb0aaf872c5b10c24feecbd5ae099023 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 8 May 2018 16:26:33 +0300 Subject: [PATCH 151/292] drop alignment requirement if CGLM_ALL_UNALIGNED defined * bring alignment back for visual studio 2017 --- include/cglm/simd/intrin.h | 4 ++-- include/cglm/types.h | 26 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index c9ab352..9fef5a1 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -52,7 +52,7 @@ glmm_norm(__m128 a) { static inline __m128 -glmm_load3(vec3 v) { +glmm_load3(float v[3]) { __m128i xy; __m128 z; @@ -64,7 +64,7 @@ glmm_load3(vec3 v) { static inline void -glmm_store3(__m128 vx, vec3 v) { +glmm_store3(__m128 vx, float v[3]) { _mm_storel_pi((__m64 *)&v[0], vx); _mm_store_ss(&v[2], _mm_shuffle1_ps(vx, 2, 2, 2, 2)); } diff --git a/include/cglm/types.h b/include/cglm/types.h index 5d39a55..ad4eb02 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -9,20 +9,32 @@ #define cglm_types_h #if defined(_MSC_VER) -# define CGLM_ALIGN(X) /* __declspec(align(X)) */ +#if _MSC_VER < 1914 /* Visual Studio 2017 version 15.7 */ +# define CGLM_ALL_UNALIGNED +/* do not use alignment for older visual studio versions */ +# define CGLM_ALIGN(X) /* __declspec(align(X)) */ +#else +# define CGLM_ALIGN(X) __declspec(align(X)) +#endif #else # define CGLM_ALIGN(X) __attribute((aligned(X))) #endif -typedef float vec2[2]; -typedef CGLM_ALIGN(8) float vec3[3]; -typedef int ivec3[3]; -typedef CGLM_ALIGN(16) float vec4[4]; +#ifndef CGLM_ALL_UNALIGNED +# define CGLM_ALIGN_IF(X) CGLM_ALIGN(X) +#else +# define CGLM_ALIGN_IF(X) /* no alignment */ +#endif + +typedef float vec2[2]; +typedef CGLM_ALIGN_IF(8) float vec3[3]; +typedef int ivec3[3]; +typedef CGLM_ALIGN_IF(16) float vec4[4]; typedef vec3 mat3[3]; -typedef CGLM_ALIGN(16) vec4 mat4[4]; +typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; -typedef vec4 versor; +typedef vec4 versor; #define CGLM_PI (float)M_PI #define CGLM_PI_2 (float)M_PI_2 From b27735780057fabc5375d2da3b78104deed972d7 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 8 May 2018 18:28:31 +0300 Subject: [PATCH 152/292] update gitignore --- .gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index 37f68c8..d500b97 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,11 @@ docs/build/* win/cglm_test_* * copy.* *.o +*.obj +*codeanalysis.*.xml +*codeanalysis.xml +*.lib +*.tlog +win/x64 +win/x85 +win/Debug From 0e49e951618544ec802f27314c7652264f8c3751 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 8 May 2018 18:29:02 +0300 Subject: [PATCH 153/292] win: update visual studio version for align requirement --- include/cglm/types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/types.h b/include/cglm/types.h index ad4eb02..4a7d019 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -9,7 +9,7 @@ #define cglm_types_h #if defined(_MSC_VER) -#if _MSC_VER < 1914 /* Visual Studio 2017 version 15.7 */ +#if _MSC_VER < 1913 /* Visual Studio 2017 version 15.6 */ # define CGLM_ALL_UNALIGNED /* do not use alignment for older visual studio versions */ # define CGLM_ALIGN(X) /* __declspec(align(X)) */ From f774925e8a3182c3699f21b70948ba5c8b6d4ce5 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 9 May 2018 15:30:54 +0300 Subject: [PATCH 154/292] win, simd: make sure that CGLM_ALL_UNALIGNED is defined for older visual studios --- include/cglm/simd/intrin.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index 9fef5a1..3d5682d 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -18,6 +18,10 @@ # define __SSE__ # endif # endif +/* do not use alignment for older visual studio versions */ +# if _MSC_VER < 1913 /* Visual Studio 2017 version 15.6 */ +# define CGLM_ALL_UNALIGNED +# endif #endif #if defined( __SSE__ ) || defined( __SSE2__ ) From 94b286f1f92f42cfea8fea88f8ad6a8de793584b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 9 May 2018 16:35:15 +0300 Subject: [PATCH 155/292] docs: add new alignment option to docs --- docs/source/getting_started.rst | 7 +++++++ docs/source/index.rst | 1 + docs/source/opt.rst | 36 +++++++++++++++++++++++++++++++++ docs/source/troubleshooting.rst | 3 +++ include/cglm/types.h | 6 +++--- 5 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 docs/source/opt.rst diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index a152371..05c4440 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -27,6 +27,13 @@ Alignment is Required: **vec4** and **mat4** requires 16 byte alignment because vec4 and mat4 operations are vectorized by SIMD instructions (SSE/AVX). +**UPDATE:** + By starting v0.4.5 cglm provides an option to disable alignment requirement, it is enabled as default + + | Check :doc:`opt` page for more details + + Also alignment is disabled for older msvc verisons as default. Now alignment only is required in Visual Studio 2017 version 15.6+ if CGLM_ALL_UNALIGNED macro is not defined. + Allocations: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *cglm* doesn't alloc any memory on heap. So it doesn't provide any allocator. diff --git a/docs/source/index.rst b/docs/source/index.rst index 32e7b48..cfdf220 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -40,6 +40,7 @@ Also currently only **float** type is supported for most operations. getting_started opengl api + opt troubleshooting Indices and tables diff --git a/docs/source/opt.rst b/docs/source/opt.rst new file mode 100644 index 0000000..c614e42 --- /dev/null +++ b/docs/source/opt.rst @@ -0,0 +1,36 @@ +.. default-domain:: C + +Options +=============================================================================== + +A few options are provided via macros. + +Alignment +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +As default, cglm requires types to be aligned. Alignment requirements: + +vec3: 8 byte +vec4: 16 byte +mat4: 16 byte +versor: 16 byte + +By starting **v0.4.5** cglm provides an option to disable alignment requirement. +To enable this option define **CGLM_ALL_UNALIGNED** macro before all headers. +You can define it in Xcode, Visual Studio (or other IDEs) or you can also prefer +to define it in build system. If you use pre-compiled verisons then you +have to compile cglm with **CGLM_ALL_UNALIGNED** macro. + +**VERY VERY IMPORTANT:** If you use cglm in multiple projects and + those projects are depends on each other, then + + | *ALWAYS* or *NEVER USE* **CGLM_ALL_UNALIGNED** macro in linked projects + + if you do not know what you are doing. Because a cglm header included + via 'project A' may force types to be aligned and another cglm header + included via 'project B' may not require alignment. In this case + cglm functions will read from and write to **INVALID MEMORY LOCATIONs**. + + ALWAYS USE SAME CONFIGURATION / OPTION for **cglm** if you have multiple projects. + + For instance if you set CGLM_ALL_UNALIGNED in a project then set it in other projects too diff --git a/docs/source/troubleshooting.rst b/docs/source/troubleshooting.rst index d599c7d..7c416b0 100644 --- a/docs/source/troubleshooting.rst +++ b/docs/source/troubleshooting.rst @@ -43,6 +43,9 @@ 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 only is required in Visual Studio 2017 version 15.6+ if CGLM_ALL_UNALIGNED macro is defined. + Crashes, Invalid Memory Access: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/cglm/types.h b/include/cglm/types.h index 4a7d019..99226df 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -9,10 +9,10 @@ #define cglm_types_h #if defined(_MSC_VER) -#if _MSC_VER < 1913 /* Visual Studio 2017 version 15.6 */ -# define CGLM_ALL_UNALIGNED /* do not use alignment for older visual studio versions */ -# define CGLM_ALIGN(X) /* __declspec(align(X)) */ +#if _MSC_VER < 1913 /* Visual Studio 2017 version 15.6 */ +# define CGLM_ALL_UNALIGNED +# define CGLM_ALIGN(X) /* no alignment */ #else # define CGLM_ALIGN(X) __declspec(align(X)) #endif From c6d07bb6eb036742c25bdad9b8ccb6d74871cb64 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 10 May 2018 12:18:54 +0300 Subject: [PATCH 156/292] surround PI with parentheses + code style + update docs --- docs/source/getting_started.rst | 4 ++-- docs/source/troubleshooting.rst | 2 +- include/cglm/simd/sse2/affine.h | 2 +- include/cglm/types.h | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 05c4440..2f8511c 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -28,11 +28,11 @@ Alignment is Required: vectorized by SIMD instructions (SSE/AVX). **UPDATE:** - By starting v0.4.5 cglm provides an option to disable alignment requirement, it is enabled as default + By starting v0.4.5 cglm provides an option to disable alignment requirement, it is enabled as default | Check :doc:`opt` page for more details - Also alignment is disabled for older msvc verisons as default. Now alignment only is required in Visual Studio 2017 version 15.6+ if CGLM_ALL_UNALIGNED macro is not defined. + 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. Allocations: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/troubleshooting.rst b/docs/source/troubleshooting.rst index 7c416b0..c897dc2 100644 --- a/docs/source/troubleshooting.rst +++ b/docs/source/troubleshooting.rst @@ -44,7 +44,7 @@ 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 only is required in Visual Studio 2017 version 15.6+ if CGLM_ALL_UNALIGNED macro is defined. +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. Crashes, Invalid Memory Access: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/cglm/simd/sse2/affine.h b/include/cglm/simd/sse2/affine.h index c0c9c04..8a644d3 100644 --- a/include/cglm/simd/sse2/affine.h +++ b/include/cglm/simd/sse2/affine.h @@ -90,7 +90,7 @@ glm_inv_tr_sse2(mat4 mat) { r1 = glmm_load(mat[1]); r2 = glmm_load(mat[2]); r3 = glmm_load(mat[3]); - x1 = _mm_set_ps(1.0f, 0.0f, 0.0f, 0.0f); + x1 = _mm_set_ps(1.0f, 0.0f, 0.0f, 0.0f); _MM_TRANSPOSE4_PS(r0, r1, r2, x1); diff --git a/include/cglm/types.h b/include/cglm/types.h index 99226df..d470e7b 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -27,17 +27,17 @@ #endif typedef float vec2[2]; -typedef CGLM_ALIGN_IF(8) float vec3[3]; +typedef CGLM_ALIGN_IF(8) float vec3[3]; typedef int ivec3[3]; typedef CGLM_ALIGN_IF(16) float vec4[4]; -typedef vec3 mat3[3]; +typedef vec3 mat3[3]; typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; typedef vec4 versor; -#define CGLM_PI (float)M_PI -#define CGLM_PI_2 (float)M_PI_2 -#define CGLM_PI_4 (float)M_PI_4 +#define CGLM_PI ((float)M_PI) +#define CGLM_PI_2 ((float)M_PI_2) +#define CGLM_PI_4 ((float)M_PI_4) #endif /* cglm_types_h */ From 464bd917d094d79b886248596f75fdae9a545865 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 10 May 2018 12:21:33 +0300 Subject: [PATCH 157/292] update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 15f434c..ff1b4df 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ Complete documentation: http://cglm.readthedocs.io - **[bugfix]** euler angles was implemented in reverse order (extrinsic) it was fixed, now they are intrinsic. Make sure that you have the latest version - **[major change]** by starting v0.4.0, quaternions are stored as [x, y, z, w], it was [w, x, y, z] in v0.3.5 and earlier versions +- **[api rename]** by starting v0.4.5, **glm_simd** functions are renamed to **glmm_** +- **[new option]** by starting v0.4.5, you can disable alignment requirement, check options in docs. #### Note for C++ developers: If you don't aware about original GLM library yet, you may also want to look at: From da5ad698631208e5615de476d149a5f186fcd128 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 10 May 2018 14:27:53 +0300 Subject: [PATCH 158/292] simd: rename _mm_ extensions to glmm_ --- include/cglm/simd/intrin.h | 26 ++++---- include/cglm/simd/sse2/affine.h | 50 +++++++------- include/cglm/simd/sse2/mat3.h | 22 +++---- include/cglm/simd/sse2/mat4.h | 112 +++++++++++++++----------------- include/cglm/simd/sse2/quat.h | 14 ++-- include/cglm/vec4-ext.h | 6 +- include/cglm/vec4.h | 8 +-- 7 files changed, 115 insertions(+), 123 deletions(-) diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index a5fa455..2f79b01 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -29,29 +29,27 @@ # include /* OPTIONAL: You may save some instructions but latency (not sure) */ -#ifdef CGLM_USE_INT_DOM_FOR_SHUFF -# define _mm_shuffle1_ps(xmm, z, y, x, w) \ - _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(xmm), \ - _MM_SHUFFLE(z, y, x, w))) +#ifdef CGLM_USE_INT_DOMAIN +# define glmm_shuff1(xmm, z, y, x, w) \ + _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(xmm), \ + _MM_SHUFFLE(z, y, x, w))) #else -# define _mm_shuffle1_ps(xmm, z, y, x, w) \ +# define glmm_shuff1(xmm, z, y, x, w) \ _mm_shuffle_ps(xmm, xmm, _MM_SHUFFLE(z, y, x, w)) #endif -# define _mm_shuffle1_ps1(xmm, x) \ - _mm_shuffle1_ps(xmm, x, x, x, x) - -# define _mm_shuffle2_ps(a, b, z0, y0, x0, w0, z1, y1, x1, w1) \ - _mm_shuffle1_ps(_mm_shuffle_ps(a, b, _MM_SHUFFLE(z0, y0, x0, w0)), \ - z1, y1, x1, w1) +#define glmm_shuff1x(xmm, x) glmm_shuff1(xmm, x, x, x, x) +#define glmm_shuff2(a, b, z0, y0, x0, w0, z1, y1, x1, w1) \ + glmm_shuff1(_mm_shuffle_ps(a, b, _MM_SHUFFLE(z0, y0, x0, w0)), \ + z1, y1, x1, w1) static inline __m128 glmm_dot(__m128 a, __m128 b) { __m128 x0; x0 = _mm_mul_ps(a, b); - x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 3, 2)); - return _mm_add_ps(x0, _mm_shuffle1_ps(x0, 0, 1, 0, 1)); + x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 3, 2)); + return _mm_add_ps(x0, glmm_shuff1(x0, 0, 1, 0, 1)); } static inline @@ -76,7 +74,7 @@ static inline void glmm_store3(__m128 vx, float v[3]) { _mm_storel_pi((__m64 *)&v[0], vx); - _mm_store_ss(&v[2], _mm_shuffle1_ps(vx, 2, 2, 2, 2)); + _mm_store_ss(&v[2], glmm_shuff1(vx, 2, 2, 2, 2)); } #ifdef CGLM_ALL_UNALIGNED diff --git a/include/cglm/simd/sse2/affine.h b/include/cglm/simd/sse2/affine.h index 8a644d3..87db1b8 100644 --- a/include/cglm/simd/sse2/affine.h +++ b/include/cglm/simd/sse2/affine.h @@ -25,28 +25,28 @@ glm_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { r = glmm_load(m2[0]); glmm_store(dest[0], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 0), l0), + _mm_mul_ps(glmm_shuff1x(r, 1), l1)), + _mm_mul_ps(glmm_shuff1x(r, 2), l2))); r = glmm_load(m2[1]); glmm_store(dest[1], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 0), l0), + _mm_mul_ps(glmm_shuff1x(r, 1), l1)), + _mm_mul_ps(glmm_shuff1x(r, 2), l2))); r = glmm_load(m2[2]); glmm_store(dest[2], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 0), l0), + _mm_mul_ps(glmm_shuff1x(r, 1), l1)), + _mm_mul_ps(glmm_shuff1x(r, 2), l2))); r = glmm_load(m2[3]); glmm_store(dest[3], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), - _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 0), l0), + _mm_mul_ps(glmm_shuff1x(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 2), l2), + _mm_mul_ps(glmm_shuff1x(r, 3), l3)))); } CGLM_INLINE @@ -62,21 +62,21 @@ glm_mul_rot_sse2(mat4 m1, mat4 m2, mat4 dest) { r = glmm_load(m2[0]); glmm_store(dest[0], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 0), l0), + _mm_mul_ps(glmm_shuff1x(r, 1), l1)), + _mm_mul_ps(glmm_shuff1x(r, 2), l2))); r = glmm_load(m2[1]); glmm_store(dest[1], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 0), l0), + _mm_mul_ps(glmm_shuff1x(r, 1), l1)), + _mm_mul_ps(glmm_shuff1x(r, 2), l2))); r = glmm_load(m2[2]); glmm_store(dest[2], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2))); + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 0), l0), + _mm_mul_ps(glmm_shuff1x(r, 1), l1)), + _mm_mul_ps(glmm_shuff1x(r, 2), l2))); glmm_store(dest[3], l3); } @@ -94,9 +94,9 @@ glm_inv_tr_sse2(mat4 mat) { _MM_TRANSPOSE4_PS(r0, r1, r2, x1); - x0 = _mm_add_ps(_mm_mul_ps(r0, _mm_shuffle1_ps(r3, 0, 0, 0, 0)), - _mm_mul_ps(r1, _mm_shuffle1_ps(r3, 1, 1, 1, 1))); - x0 = _mm_add_ps(x0, _mm_mul_ps(r2, _mm_shuffle1_ps(r3, 2, 2, 2, 2))); + x0 = _mm_add_ps(_mm_mul_ps(r0, glmm_shuff1(r3, 0, 0, 0, 0)), + _mm_mul_ps(r1, glmm_shuff1(r3, 1, 1, 1, 1))); + x0 = _mm_add_ps(x0, _mm_mul_ps(r2, glmm_shuff1(r3, 2, 2, 2, 2))); x0 = _mm_xor_ps(x0, _mm_set1_ps(-0.f)); x0 = _mm_add_ps(x0, x1); diff --git a/include/cglm/simd/sse2/mat3.h b/include/cglm/simd/sse2/mat3.h index a0dcc02..9c972ff 100644 --- a/include/cglm/simd/sse2/mat3.h +++ b/include/cglm/simd/sse2/mat3.h @@ -27,27 +27,25 @@ glm_mat3_mul_sse2(mat3 m1, mat3 m2, mat3 dest) { r1 = _mm_loadu_ps(&m2[1][1]); r2 = _mm_set1_ps(m2[2][2]); - x1 = _mm_shuffle2_ps(l0, l1, 1, 0, 3, 3, 0, 3, 2, 0); - x2 = _mm_shuffle2_ps(l1, l2, 0, 0, 3, 2, 0, 2, 1, 0); + x1 = glmm_shuff2(l0, l1, 1, 0, 3, 3, 0, 3, 2, 0); + x2 = glmm_shuff2(l1, l2, 0, 0, 3, 2, 0, 2, 1, 0); - x0 = _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps(l0, 0, 2, 1, 0), - _mm_shuffle1_ps(r0, 3, 0, 0, 0)), - _mm_mul_ps(x1, - _mm_shuffle2_ps(r0, r1, 0, 0, 1, 1, 2, 0, 0, 0))); + x0 = _mm_add_ps(_mm_mul_ps(glmm_shuff1(l0, 0, 2, 1, 0), + glmm_shuff1(r0, 3, 0, 0, 0)), + _mm_mul_ps(x1, glmm_shuff2(r0, r1, 0, 0, 1, 1, 2, 0, 0, 0))); x0 = _mm_add_ps(x0, - _mm_mul_ps(x2, - _mm_shuffle2_ps(r0, r1, 1, 1, 2, 2, 2, 0, 0, 0))); + _mm_mul_ps(x2, glmm_shuff2(r0, r1, 1, 1, 2, 2, 2, 0, 0, 0))); _mm_storeu_ps(dest[0], x0); - x0 = _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps(l0, 1, 0, 2, 1), + x0 = _mm_add_ps(_mm_mul_ps(glmm_shuff1(l0, 1, 0, 2, 1), _mm_shuffle_ps(r0, r1, _MM_SHUFFLE(2, 2, 3, 3))), - _mm_mul_ps(_mm_shuffle1_ps(x1, 1, 0, 2, 1), - _mm_shuffle1_ps(r1, 3, 3, 0, 0))); + _mm_mul_ps(glmm_shuff1(x1, 1, 0, 2, 1), + glmm_shuff1(r1, 3, 3, 0, 0))); x0 = _mm_add_ps(x0, - _mm_mul_ps(_mm_shuffle1_ps(x2, 1, 0, 2, 1), + _mm_mul_ps(glmm_shuff1(x2, 1, 0, 2, 1), _mm_shuffle_ps(r1, r2, _MM_SHUFFLE(0, 0, 1, 1)))); _mm_storeu_ps(&dest[1][1], x0); diff --git a/include/cglm/simd/sse2/mat4.h b/include/cglm/simd/sse2/mat4.h index 1f82c08..20afeae 100644 --- a/include/cglm/simd/sse2/mat4.h +++ b/include/cglm/simd/sse2/mat4.h @@ -58,29 +58,29 @@ glm_mat4_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { r = glmm_load(m2[0]); glmm_store(dest[0], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), - _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 0), l0), + _mm_mul_ps(glmm_shuff1x(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 2), l2), + _mm_mul_ps(glmm_shuff1x(r, 3), l3)))); r = glmm_load(m2[1]); glmm_store(dest[1], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), - _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 0), l0), + _mm_mul_ps(glmm_shuff1x(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 2), l2), + _mm_mul_ps(glmm_shuff1x(r, 3), l3)))); r = glmm_load(m2[2]); glmm_store(dest[2], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), - _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 0), l0), + _mm_mul_ps(glmm_shuff1x(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 2), l2), + _mm_mul_ps(glmm_shuff1x(r, 3), l3)))); r = glmm_load(m2[3]); glmm_store(dest[3], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 0), l0), - _mm_mul_ps(_mm_shuffle1_ps1(r, 1), l1)), - _mm_add_ps(_mm_mul_ps(_mm_shuffle1_ps1(r, 2), l2), - _mm_mul_ps(_mm_shuffle1_ps1(r, 3), l3)))); + _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 0), l0), + _mm_mul_ps(glmm_shuff1x(r, 1), l1)), + _mm_add_ps(_mm_mul_ps(glmm_shuff1x(r, 2), l2), + _mm_mul_ps(glmm_shuff1x(r, 3), l3)))); } CGLM_INLINE @@ -89,15 +89,11 @@ glm_mat4_mulv_sse2(mat4 m, vec4 v, vec4 dest) { __m128 x0, x1, x2; x0 = glmm_load(v); - x1 = _mm_add_ps(_mm_mul_ps(glmm_load(m[0]), - _mm_shuffle1_ps1(x0, 0)), - _mm_mul_ps(glmm_load(m[1]), - _mm_shuffle1_ps1(x0, 1))); + x1 = _mm_add_ps(_mm_mul_ps(glmm_load(m[0]), glmm_shuff1x(x0, 0)), + _mm_mul_ps(glmm_load(m[1]), glmm_shuff1x(x0, 1))); - x2 = _mm_add_ps(_mm_mul_ps(glmm_load(m[2]), - _mm_shuffle1_ps1(x0, 2)), - _mm_mul_ps(glmm_load(m[3]), - _mm_shuffle1_ps1(x0, 3))); + x2 = _mm_add_ps(_mm_mul_ps(glmm_load(m[2]), glmm_shuff1x(x0, 2)), + _mm_mul_ps(glmm_load(m[3]), glmm_shuff1x(x0, 3))); glmm_store(dest, _mm_add_ps(x1, x2)); } @@ -119,20 +115,20 @@ glm_mat4_det_sse2(mat4 mat) { t[3] = i * p - m * l; t[4] = i * o - m * k; */ - x0 = _mm_sub_ps(_mm_mul_ps(_mm_shuffle1_ps(r2, 0, 0, 1, 1), - _mm_shuffle1_ps(r3, 2, 3, 2, 3)), - _mm_mul_ps(_mm_shuffle1_ps(r3, 0, 0, 1, 1), - _mm_shuffle1_ps(r2, 2, 3, 2, 3))); + x0 = _mm_sub_ps(_mm_mul_ps(glmm_shuff1(r2, 0, 0, 1, 1), + glmm_shuff1(r3, 2, 3, 2, 3)), + _mm_mul_ps(glmm_shuff1(r3, 0, 0, 1, 1), + glmm_shuff1(r2, 2, 3, 2, 3))); /* t[0] = k * p - o * l; t[0] = k * p - o * l; t[5] = i * n - m * j; t[5] = i * n - m * j; */ - x1 = _mm_sub_ps(_mm_mul_ps(_mm_shuffle1_ps(r2, 0, 0, 2, 2), - _mm_shuffle1_ps(r3, 1, 1, 3, 3)), - _mm_mul_ps(_mm_shuffle1_ps(r3, 0, 0, 2, 2), - _mm_shuffle1_ps(r2, 1, 1, 3, 3))); + x1 = _mm_sub_ps(_mm_mul_ps(glmm_shuff1(r2, 0, 0, 2, 2), + glmm_shuff1(r3, 1, 1, 3, 3)), + _mm_mul_ps(glmm_shuff1(r3, 0, 0, 2, 2), + glmm_shuff1(r2, 1, 1, 3, 3))); /* a * (f * t[0] - g * t[1] + h * t[2]) @@ -140,19 +136,19 @@ glm_mat4_det_sse2(mat4 mat) { + c * (e * t[1] - f * t[3] + h * t[5]) - d * (e * t[2] - f * t[4] + g * t[5]) */ - x2 = _mm_sub_ps(_mm_mul_ps(_mm_shuffle1_ps(r1, 0, 0, 0, 1), + x2 = _mm_sub_ps(_mm_mul_ps(glmm_shuff1(r1, 0, 0, 0, 1), _mm_shuffle_ps(x1, x0, _MM_SHUFFLE(1, 0, 0, 0))), - _mm_mul_ps(_mm_shuffle1_ps(r1, 1, 1, 2, 2), - _mm_shuffle1_ps(x0, 3, 2, 2, 0))); + _mm_mul_ps(glmm_shuff1(r1, 1, 1, 2, 2), + glmm_shuff1(x0, 3, 2, 2, 0))); x2 = _mm_add_ps(x2, - _mm_mul_ps(_mm_shuffle1_ps(r1, 2, 3, 3, 3), + _mm_mul_ps(glmm_shuff1(r1, 2, 3, 3, 3), _mm_shuffle_ps(x0, x1, _MM_SHUFFLE(2, 2, 3, 1)))); x2 = _mm_xor_ps(x2, _mm_set_ps(-0.f, 0.f, -0.f, 0.f)); x0 = _mm_mul_ps(r0, x2); - x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 0, 1, 2, 3)); - x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 3, 3, 1)); + x0 = _mm_add_ps(x0, glmm_shuff1(x0, 0, 1, 2, 3)); + x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 3, 3, 1)); return _mm_cvtss_f32(x0); } @@ -172,8 +168,8 @@ glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { r3 = glmm_load(mat[3]); /* p o n m */ x0 = _mm_shuffle_ps(r2, r3, _MM_SHUFFLE(3, 2, 3, 2)); /* p o l k */ - x1 = _mm_shuffle1_ps(x0, 1, 3, 3, 3); /* l p p p */ - x2 = _mm_shuffle1_ps(x0, 0, 2, 2, 2); /* k o o o */ + x1 = glmm_shuff1(x0, 1, 3, 3, 3); /* l p p p */ + x2 = glmm_shuff1(x0, 0, 2, 2, 2); /* k o o o */ x0 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(3, 3, 3, 3)); /* h h l l */ x3 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(2, 2, 2, 2)); /* g g k k */ @@ -184,7 +180,7 @@ glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { t0 = _mm_sub_ps(_mm_mul_ps(x3, x1), _mm_mul_ps(x2, x0)); x4 = _mm_shuffle_ps(r2, r3, _MM_SHUFFLE(2, 1, 2, 1)); /* o n k j */ - x4 = _mm_shuffle1_ps(x4, 0, 2, 2, 2); /* j n n n */ + x4 = glmm_shuff1(x4, 0, 2, 2, 2); /* j n n n */ x5 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(1, 1, 1, 1)); /* f f j j */ /* t1[1] = j * p - n * l; @@ -200,7 +196,7 @@ glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { t2 = _mm_sub_ps(_mm_mul_ps(x5, x2), _mm_mul_ps(x4, x3)); x6 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(0, 0, 0, 0)); /* e e i i */ - x7 = _mm_shuffle2_ps(r3, r2, 0, 0, 0, 0, 2, 0, 0, 0); /* i m m m */ + x7 = glmm_shuff2(r3, r2, 0, 0, 0, 0, 2, 0, 0, 0); /* i m m m */ /* t1[3] = i * p - m * l; t1[3] = i * p - m * l; @@ -220,10 +216,10 @@ glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { t3[5] = e * j - i * f; */ t5 = _mm_sub_ps(_mm_mul_ps(x6, x4), _mm_mul_ps(x7, x5)); - x0 = _mm_shuffle2_ps(r1, r0, 0, 0, 0, 0, 2, 2, 2, 0); /* a a a e */ - x1 = _mm_shuffle2_ps(r1, r0, 1, 1, 1, 1, 2, 2, 2, 0); /* b b b f */ - x2 = _mm_shuffle2_ps(r1, r0, 2, 2, 2, 2, 2, 2, 2, 0); /* c c c g */ - x3 = _mm_shuffle2_ps(r1, r0, 3, 3, 3, 3, 2, 2, 2, 0); /* d d d h */ + x0 = glmm_shuff2(r1, r0, 0, 0, 0, 0, 2, 2, 2, 0); /* a a a e */ + x1 = glmm_shuff2(r1, r0, 1, 1, 1, 1, 2, 2, 2, 0); /* b b b f */ + x2 = glmm_shuff2(r1, r0, 2, 2, 2, 2, 2, 2, 2, 0); /* c c c g */ + x3 = glmm_shuff2(r1, r0, 3, 3, 3, 3, 2, 2, 2, 0); /* d d d h */ /* dest[0][0] = f * t1[0] - g * t1[1] + h * t1[2]; @@ -271,8 +267,8 @@ glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { x0 = _mm_shuffle_ps(x0, x1, _MM_SHUFFLE(2, 0, 2, 0)); x0 = _mm_mul_ps(x0, r0); - x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 0, 1, 2, 3)); - x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 0, 1)); + x0 = _mm_add_ps(x0, glmm_shuff1(x0, 0, 1, 2, 3)); + x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 0, 1)); x0 = _mm_rcp_ps(x0); glmm_store(dest[0], _mm_mul_ps(v0, x0)); @@ -296,8 +292,8 @@ glm_mat4_inv_sse2(mat4 mat, mat4 dest) { r3 = glmm_load(mat[3]); /* p o n m */ x0 = _mm_shuffle_ps(r2, r3, _MM_SHUFFLE(3, 2, 3, 2)); /* p o l k */ - x1 = _mm_shuffle1_ps(x0, 1, 3, 3, 3); /* l p p p */ - x2 = _mm_shuffle1_ps(x0, 0, 2, 2, 2); /* k o o o */ + x1 = glmm_shuff1(x0, 1, 3, 3, 3); /* l p p p */ + x2 = glmm_shuff1(x0, 0, 2, 2, 2); /* k o o o */ x0 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(3, 3, 3, 3)); /* h h l l */ x3 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(2, 2, 2, 2)); /* g g k k */ @@ -308,7 +304,7 @@ glm_mat4_inv_sse2(mat4 mat, mat4 dest) { t0 = _mm_sub_ps(_mm_mul_ps(x3, x1), _mm_mul_ps(x2, x0)); x4 = _mm_shuffle_ps(r2, r3, _MM_SHUFFLE(2, 1, 2, 1)); /* o n k j */ - x4 = _mm_shuffle1_ps(x4, 0, 2, 2, 2); /* j n n n */ + x4 = glmm_shuff1(x4, 0, 2, 2, 2); /* j n n n */ x5 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(1, 1, 1, 1)); /* f f j j */ /* t1[1] = j * p - n * l; @@ -324,7 +320,7 @@ glm_mat4_inv_sse2(mat4 mat, mat4 dest) { t2 = _mm_sub_ps(_mm_mul_ps(x5, x2), _mm_mul_ps(x4, x3)); x6 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(0, 0, 0, 0)); /* e e i i */ - x7 = _mm_shuffle2_ps(r3, r2, 0, 0, 0, 0, 2, 0, 0, 0); /* i m m m */ + x7 = glmm_shuff2(r3, r2, 0, 0, 0, 0, 2, 0, 0, 0); /* i m m m */ /* t1[3] = i * p - m * l; t1[3] = i * p - m * l; @@ -344,10 +340,10 @@ glm_mat4_inv_sse2(mat4 mat, mat4 dest) { t3[5] = e * j - i * f; */ t5 = _mm_sub_ps(_mm_mul_ps(x6, x4), _mm_mul_ps(x7, x5)); - x0 = _mm_shuffle2_ps(r1, r0, 0, 0, 0, 0, 2, 2, 2, 0); /* a a a e */ - x1 = _mm_shuffle2_ps(r1, r0, 1, 1, 1, 1, 2, 2, 2, 0); /* b b b f */ - x2 = _mm_shuffle2_ps(r1, r0, 2, 2, 2, 2, 2, 2, 2, 0); /* c c c g */ - x3 = _mm_shuffle2_ps(r1, r0, 3, 3, 3, 3, 2, 2, 2, 0); /* d d d h */ + x0 = glmm_shuff2(r1, r0, 0, 0, 0, 0, 2, 2, 2, 0); /* a a a e */ + x1 = glmm_shuff2(r1, r0, 1, 1, 1, 1, 2, 2, 2, 0); /* b b b f */ + x2 = glmm_shuff2(r1, r0, 2, 2, 2, 2, 2, 2, 2, 0); /* c c c g */ + x3 = glmm_shuff2(r1, r0, 3, 3, 3, 3, 2, 2, 2, 0); /* d d d h */ /* dest[0][0] = f * t1[0] - g * t1[1] + h * t1[2]; @@ -395,8 +391,8 @@ glm_mat4_inv_sse2(mat4 mat, mat4 dest) { x0 = _mm_shuffle_ps(x0, x1, _MM_SHUFFLE(2, 0, 2, 0)); x0 = _mm_mul_ps(x0, r0); - x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 0, 1, 2, 3)); - x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 0, 1)); + x0 = _mm_add_ps(x0, glmm_shuff1(x0, 0, 1, 2, 3)); + x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 0, 1)); x0 = _mm_div_ps(_mm_set1_ps(1.0f), x0); glmm_store(dest[0], _mm_mul_ps(v0, x0)); diff --git a/include/cglm/simd/sse2/quat.h b/include/cglm/simd/sse2/quat.h index a8b517c..0173f94 100644 --- a/include/cglm/simd/sse2/quat.h +++ b/include/cglm/simd/sse2/quat.h @@ -27,16 +27,16 @@ glm_quat_mul_sse2(versor p, versor q, versor dest) { xp = glmm_load(p); /* 3 2 1 0 */ xq = glmm_load(q); - r = _mm_mul_ps(_mm_shuffle1_ps1(xp, 3), xq); + r = _mm_mul_ps(glmm_shuff1x(xp, 3), xq); - x0 = _mm_xor_ps(_mm_shuffle1_ps1(xp, 0), _mm_set_ps(-0.f, 0.f, -0.f, 0.f)); - r = _mm_add_ps(r, _mm_mul_ps(x0, _mm_shuffle1_ps(xq, 0, 1, 2, 3))); + x0 = _mm_xor_ps(glmm_shuff1x(xp, 0), _mm_set_ps(-0.f, 0.f, -0.f, 0.f)); + r = _mm_add_ps(r, _mm_mul_ps(x0, glmm_shuff1(xq, 0, 1, 2, 3))); - x0 = _mm_xor_ps(_mm_shuffle1_ps1(xp, 1), _mm_set_ps(-0.f, -0.f, 0.f, 0.f)); - r = _mm_add_ps(r, _mm_mul_ps(x0, _mm_shuffle1_ps(xq, 1, 0, 3, 2))); + x0 = _mm_xor_ps(glmm_shuff1x(xp, 1), _mm_set_ps(-0.f, -0.f, 0.f, 0.f)); + r = _mm_add_ps(r, _mm_mul_ps(x0, glmm_shuff1(xq, 1, 0, 3, 2))); - x0 = _mm_xor_ps(_mm_shuffle1_ps1(xp, 2), _mm_set_ps(-0.f, 0.f, 0.f, -0.f)); - r = _mm_add_ps(r, _mm_mul_ps(x0, _mm_shuffle1_ps(xq, 2, 3, 0, 1))); + x0 = _mm_xor_ps(glmm_shuff1x(xp, 2), _mm_set_ps(-0.f, 0.f, 0.f, -0.f)); + r = _mm_add_ps(r, _mm_mul_ps(x0, glmm_shuff1(xq, 2, 3, 0, 1))); glmm_store(dest, r); } diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index 94150da..b7902b6 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -225,10 +225,10 @@ glm_vec4_sign(vec4 v, vec4 dest) { x0 = glmm_load(v); x1 = _mm_set_ps(0.0f, 0.0f, 1.0f, -1.0f); - x2 = _mm_shuffle1_ps1(x1, 2); + x2 = glmm_shuff1x(x1, 2); - x3 = _mm_and_ps(_mm_cmpgt_ps(x0, x2), _mm_shuffle1_ps1(x1, 1)); - x4 = _mm_and_ps(_mm_cmplt_ps(x0, x2), _mm_shuffle1_ps1(x1, 0)); + x3 = _mm_and_ps(_mm_cmpgt_ps(x0, x2), glmm_shuff1x(x1, 1)); + x4 = _mm_and_ps(_mm_cmplt_ps(x0, x2), glmm_shuff1x(x1, 0)); glmm_store(dest, _mm_or_ps(x3, x4)); #else diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index b98190b..3b3a452 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -170,8 +170,8 @@ glm_vec4_dot(vec4 a, vec4 b) { #if defined( __SSE__ ) || defined( __SSE2__ ) __m128 x0; x0 = _mm_mul_ps(glmm_load(a), glmm_load(b)); - x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 3, 2)); - return _mm_cvtss_f32(_mm_add_ss(x0, _mm_shuffle1_ps(x0, 0, 1, 0, 1))); + x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 3, 2)); + return _mm_cvtss_f32(_mm_add_ss(x0, glmm_shuff1(x0, 0, 1, 0, 1))); #else return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; #endif @@ -195,8 +195,8 @@ glm_vec4_norm2(vec4 v) { __m128 x0; x0 = glmm_load(v); x0 = _mm_mul_ps(x0, x0); - x0 = _mm_add_ps(x0, _mm_shuffle1_ps(x0, 1, 0, 3, 2)); - return _mm_cvtss_f32(_mm_add_ss(x0, _mm_shuffle1_ps(x0, 0, 1, 0, 1))); + x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 3, 2)); + return _mm_cvtss_f32(_mm_add_ss(x0, glmm_shuff1(x0, 0, 1, 0, 1))); #else return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]; #endif From 599524dacf973a96a0e7d6ae7159ad10aa8457a4 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 10 May 2018 16:27:40 +0300 Subject: [PATCH 159/292] docs: add new option to docs --- docs/source/opt.rst | 8 +++++++- include/cglm/simd/intrin.h | 2 +- include/cglm/simd/sse2/mat4.h | 6 +++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/source/opt.rst b/docs/source/opt.rst index c614e42..4acb972 100644 --- a/docs/source/opt.rst +++ b/docs/source/opt.rst @@ -5,7 +5,7 @@ Options A few options are provided via macros. -Alignment +Alignment Option ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ As default, cglm requires types to be aligned. Alignment requirements: @@ -34,3 +34,9 @@ have to compile cglm with **CGLM_ALL_UNALIGNED** macro. ALWAYS USE SAME CONFIGURATION / OPTION for **cglm** if you have multiple projects. For instance if you set CGLM_ALL_UNALIGNED in a project then set it in other projects too + +SSE and SSE2 Shuffle Option +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +**_mm_shuffle_ps** generates **shufps** instruction even if registers are same. +You can force it to generate **pshufd** instruction by defining +**CGLM_USE_INT_DOMAIN** macro. As default it is not defined. diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index 2f79b01..f4854bd 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -32,7 +32,7 @@ #ifdef CGLM_USE_INT_DOMAIN # define glmm_shuff1(xmm, z, y, x, w) \ _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(xmm), \ - _MM_SHUFFLE(z, y, x, w))) + _MM_SHUFFLE(z, y, x, w))) #else # define glmm_shuff1(xmm, z, y, x, w) \ _mm_shuffle_ps(xmm, xmm, _MM_SHUFFLE(z, y, x, w)) diff --git a/include/cglm/simd/sse2/mat4.h b/include/cglm/simd/sse2/mat4.h index 20afeae..c2acb9f 100644 --- a/include/cglm/simd/sse2/mat4.h +++ b/include/cglm/simd/sse2/mat4.h @@ -168,8 +168,8 @@ glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { r3 = glmm_load(mat[3]); /* p o n m */ x0 = _mm_shuffle_ps(r2, r3, _MM_SHUFFLE(3, 2, 3, 2)); /* p o l k */ - x1 = glmm_shuff1(x0, 1, 3, 3, 3); /* l p p p */ - x2 = glmm_shuff1(x0, 0, 2, 2, 2); /* k o o o */ + x1 = glmm_shuff1(x0, 1, 3, 3, 3); /* l p p p */ + x2 = glmm_shuff1(x0, 0, 2, 2, 2); /* k o o o */ x0 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(3, 3, 3, 3)); /* h h l l */ x3 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(2, 2, 2, 2)); /* g g k k */ @@ -180,7 +180,7 @@ glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { t0 = _mm_sub_ps(_mm_mul_ps(x3, x1), _mm_mul_ps(x2, x0)); x4 = _mm_shuffle_ps(r2, r3, _MM_SHUFFLE(2, 1, 2, 1)); /* o n k j */ - x4 = glmm_shuff1(x4, 0, 2, 2, 2); /* j n n n */ + x4 = glmm_shuff1(x4, 0, 2, 2, 2); /* j n n n */ x5 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(1, 1, 1, 1)); /* f f j j */ /* t1[1] = j * p - n * l; From 96c3e604ff366b97ce907815ff2f52e269c40113 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 22 May 2018 17:43:46 +0300 Subject: [PATCH 160/292] now working on v0.4.6 --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 76c6123..6e9c00c 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.4.5], [info@recp.me]) +AC_INIT([cglm], [0.4.6], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index ef9619a..995e5a2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.4.5' +version = u'0.4.6' # The full version, including alpha/beta/rc tags. -release = u'0.4.5' +release = u'0.4.6' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index 8e405bd..370a6a0 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 4 -#define CGLM_VERSION_PATCH 5 +#define CGLM_VERSION_PATCH 6 #endif /* cglm_version_h */ From 4e63325f550267ba1e43d49e3808447e53da3e8d Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 22 May 2018 17:44:36 +0300 Subject: [PATCH 161/292] aabb: add missing call versions --- include/cglm/call/box.h | 19 +++++++++++++++++++ src/box.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/cglm/call/box.h b/include/cglm/call/box.h index 505732e..3b532b5 100644 --- a/include/cglm/call/box.h +++ b/include/cglm/call/box.h @@ -32,6 +32,25 @@ glmc_aabb_crop_until(vec3 box[2], vec3 clampBox[2], vec3 dest[2]); +CGLM_EXPORT +bool +glmc_aabb_frustum(vec3 box[2], vec4 planes[6]); + +CGLM_EXPORT +void +glmc_aabb_invalidate(vec3 box[2]); + +CGLM_EXPORT +bool +glmc_aabb_isvalid(vec3 box[2]); + +CGLM_EXPORT +float +glmc_aabb_size(vec3 box[2]); + +CGLM_EXPORT +float +glmc_aabb_radius(vec3 box[2]); #ifdef __cplusplus } #endif diff --git a/src/box.c b/src/box.c index 2311f4b..6cc51b5 100644 --- a/src/box.c +++ b/src/box.c @@ -34,3 +34,33 @@ glmc_aabb_crop_until(vec3 box[2], vec3 dest[2]) { glm_aabb_crop_until(box, cropBox, clampBox, dest); } + +CGLM_EXPORT +bool +glmc_aabb_frustum(vec3 box[2], vec4 planes[6]) { + return glm_aabb_frustum(box, planes); +} + +CGLM_EXPORT +void +glmc_aabb_invalidate(vec3 box[2]) { + glm_aabb_invalidate(box); +} + +CGLM_EXPORT +bool +glmc_aabb_isvalid(vec3 box[2]) { + return glm_aabb_isvalid(box); +} + +CGLM_EXPORT +float +glmc_aabb_size(vec3 box[2]) { + return glm_aabb_size(box); +} + +CGLM_EXPORT +float +glmc_aabb_radius(vec3 box[2]) { + return glm_aabb_radius(box); +} From fb2cac981657910cd564c914228acfb2158365fc Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 22 May 2018 17:45:37 +0300 Subject: [PATCH 162/292] aabb: center of AABB helper * it is just wrapper of vec_center but it saves to access min and max values of AABB --- include/cglm/box.h | 12 ++++++++++++ include/cglm/call/box.h | 5 +++++ src/box.c | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/include/cglm/box.h b/include/cglm/box.h index 31b0ec2..5ed135e 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -200,4 +200,16 @@ glm_aabb_radius(vec3 box[2]) { return glm_aabb_size(box) * 0.5f; } +/*! + * @brief computes center point of AABB + * + * @param[in] box bounding box + * @param[out] dest center of bounding box + */ +CGLM_INLINE +void +glm_aabb_center(vec3 box[2], vec3 dest) { + glm_vec_center(box[0], box[1], dest); +} + #endif /* cglm_box_h */ diff --git a/include/cglm/call/box.h b/include/cglm/call/box.h index 3b532b5..bf25508 100644 --- a/include/cglm/call/box.h +++ b/include/cglm/call/box.h @@ -51,6 +51,11 @@ glmc_aabb_size(vec3 box[2]); CGLM_EXPORT float glmc_aabb_radius(vec3 box[2]); + +CGLM_EXPORT +void +glmc_aabb_center(vec3 box[2], vec3 dest); + #ifdef __cplusplus } #endif diff --git a/src/box.c b/src/box.c index 6cc51b5..0274390 100644 --- a/src/box.c +++ b/src/box.c @@ -64,3 +64,9 @@ float glmc_aabb_radius(vec3 box[2]) { return glm_aabb_radius(box); } + +CGLM_EXPORT +void +glmc_aabb_center(vec3 box[2], vec3 dest) { + glm_aabb_center(box, dest); +} From 6cd3d52dc568bea984b6c7773416c1200df8ef8d Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 23 May 2018 22:08:12 +0300 Subject: [PATCH 163/292] improve translate_make --- include/cglm/affine.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cglm/affine.h b/include/cglm/affine.h index dd7dbd1..6f60584 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -194,8 +194,8 @@ glm_translate_z(mat4 m, float z) { CGLM_INLINE void glm_translate_make(mat4 m, vec3 v) { - mat4 t = GLM_MAT4_IDENTITY_INIT; - glm_translate_to(t, v, m); + glm_mat4_identity(m); + glm_vec_copy(v, m[3]); } /*! From e12e79b1a5f27906146057c7bfd203fb022fe019 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 23 May 2018 22:11:44 +0300 Subject: [PATCH 164/292] improve scale_make --- include/cglm/affine.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/cglm/affine.h b/include/cglm/affine.h index 6f60584..869422b 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -225,8 +225,10 @@ glm_scale_to(mat4 m, vec3 v, mat4 dest) { CGLM_INLINE void glm_scale_make(mat4 m, vec3 v) { - mat4 t = GLM_MAT4_IDENTITY_INIT; - glm_scale_to(t, v, m); + glm_mat4_identity(m); + m[0][0] = v[0]; + m[1][1] = v[1]; + m[2][2] = v[2]; } /*! From 7d783eeace8d890100be819d06d3cc8762ed9a4b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 23 May 2018 23:04:06 +0300 Subject: [PATCH 165/292] align local variables on stack --- include/cglm/affine.h | 30 ++++++++++++++---------------- include/cglm/cam.h | 6 +++--- include/cglm/mat3.h | 4 ++-- include/cglm/mat4.h | 6 +++--- include/cglm/project.h | 2 +- include/cglm/quat.h | 31 +++++++++++++++---------------- include/cglm/vec3.h | 3 +-- 7 files changed, 39 insertions(+), 43 deletions(-) diff --git a/include/cglm/affine.h b/include/cglm/affine.h index 869422b..e160bdb 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -55,7 +55,7 @@ glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest); CGLM_INLINE void glm_translate_to(mat4 m, vec3 v, mat4 dest) { - mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest[3], @@ -82,7 +82,7 @@ glm_translate_to(mat4 m, vec3 v, mat4 dest) { glm_vec4_add(v2, t[3], t[3]); glm_vec4_add(v3, t[3], t[3]); - glm__memcpy(float, dest, t, sizeof(mat4)); + glm_mat4_copy(t, dest); #endif } @@ -254,7 +254,7 @@ glm_scale(mat4 m, vec3 v) { CGLM_INLINE void glm_scale_uni(mat4 m, float s) { - vec3 v = { s, s, s }; + CGLM_ALIGN(8) vec3 v = { s, s, s }; glm_scale_to(m, v, m); } @@ -269,7 +269,7 @@ glm_scale_uni(mat4 m, float s) { CGLM_INLINE void glm_rotate_x(mat4 m, float angle, mat4 dest) { - mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; c = cosf(angle); @@ -294,7 +294,7 @@ glm_rotate_x(mat4 m, float angle, mat4 dest) { CGLM_INLINE void glm_rotate_y(mat4 m, float angle, mat4 dest) { - mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; c = cosf(angle); @@ -319,7 +319,7 @@ glm_rotate_y(mat4 m, float angle, mat4 dest) { CGLM_INLINE void glm_rotate_z(mat4 m, float angle, mat4 dest) { - mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; c = cosf(angle); @@ -345,7 +345,7 @@ glm_rotate_z(mat4 m, float angle, mat4 dest) { CGLM_INLINE void glm_rotate_make(mat4 m, float angle, vec3 axis) { - vec3 axisn, v, vs; + CGLM_ALIGN(8) vec3 axisn, v, vs; float c; c = cosf(angle); @@ -376,7 +376,7 @@ glm_rotate_make(mat4 m, float angle, vec3 axis) { CGLM_INLINE void glm_rotate(mat4 m, float angle, vec3 axis) { - mat4 rot; + CGLM_ALIGN(16) mat4 rot; glm_rotate_make(rot, angle, axis); glm_mul_rot(m, rot, m); } @@ -393,7 +393,7 @@ glm_rotate(mat4 m, float angle, vec3 axis) { CGLM_INLINE void glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) { - vec3 pivotInv; + CGLM_ALIGN(8) vec3 pivotInv; glm_vec_inv_to(pivot, pivotInv); @@ -418,12 +418,11 @@ glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) { CGLM_INLINE void glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) { - vec3 pivotInv; + CGLM_ALIGN(8) vec3 pivotInv; glm_vec_inv_to(pivot, pivotInv); - glm_mat4_identity(m); - glm_vec_copy(pivot, m[3]); + glm_translate_make(m, pivot); glm_rotate(m, angle, axis); glm_translate(m, pivotInv); } @@ -453,9 +452,8 @@ glm_decompose_scalev(mat4 m, vec3 s) { CGLM_INLINE bool glm_uniscaled(mat4 m) { - vec3 s; + CGLM_ALIGN(8) vec3 s; glm_decompose_scalev(m, s); - return glm_vec_eq_all(s); } @@ -470,8 +468,8 @@ glm_uniscaled(mat4 m) { CGLM_INLINE void glm_decompose_rs(mat4 m, mat4 r, vec3 s) { - vec4 t = {0.0f, 0.0f, 0.0f, 1.0f}; - vec3 v; + CGLM_ALIGN(16) vec4 t = {0.0f, 0.0f, 0.0f, 1.0f}; + CGLM_ALIGN(8) vec3 v; glm_vec4_copy(m[0], r[0]); glm_vec4_copy(m[1], r[1]); diff --git a/include/cglm/cam.h b/include/cglm/cam.h index acd573c..28b8a7d 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -332,7 +332,7 @@ glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) { - vec3 f, u, s; + CGLM_ALIGN(8) vec3 f, u, s; glm_vec_sub(center, eye, f); glm_vec_normalize(f); @@ -372,7 +372,7 @@ glm_lookat(vec3 eye, CGLM_INLINE void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { - vec3 target; + CGLM_ALIGN(8) vec3 target; glm_vec_add(eye, dir, target); glm_lookat(eye, target, up, dest); } @@ -390,7 +390,7 @@ glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { CGLM_INLINE void glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) { - vec3 up; + CGLM_ALIGN(8) vec3 up; glm_vec_ortho(dir, up); glm_look(eye, dir, up, dest); } diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 87bf9b1..1df3a3b 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -81,7 +81,7 @@ glm_mat3_copy(mat3 mat, mat3 dest) { CGLM_INLINE void glm_mat3_identity(mat3 mat) { - mat3 t = GLM_MAT3_IDENTITY_INIT; + CGLM_ALIGN(16) mat3 t = GLM_MAT3_IDENTITY_INIT; glm_mat3_copy(t, mat); } @@ -155,7 +155,7 @@ glm_mat3_transpose_to(mat3 m, mat3 dest) { CGLM_INLINE void glm_mat3_transpose(mat3 m) { - mat3 tmp; + CGLM_ALIGN(16) mat3 tmp; tmp[0][1] = m[1][0]; tmp[0][2] = m[2][0]; diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index f0b6736..6d345f3 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -139,7 +139,7 @@ glm_mat4_copy(mat4 mat, mat4 dest) { CGLM_INLINE void glm_mat4_identity(mat4 mat) { - mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; glm_mat4_copy(t, mat); } @@ -586,7 +586,7 @@ glm_mat4_inv_fast(mat4 mat, mat4 dest) { CGLM_INLINE void glm_mat4_swap_col(mat4 mat, int col1, int col2) { - vec4 tmp; + CGLM_ALIGN(16) vec4 tmp; glm_vec4_copy(mat[col1], tmp); glm_vec4_copy(mat[col2], mat[col1]); glm_vec4_copy(tmp, mat[col2]); @@ -602,7 +602,7 @@ glm_mat4_swap_col(mat4 mat, int col1, int col2) { CGLM_INLINE void glm_mat4_swap_row(mat4 mat, int row1, int row2) { - vec4 tmp; + CGLM_ALIGN(16) vec4 tmp; tmp[0] = mat[0][row1]; tmp[1] = mat[1][row1]; tmp[2] = mat[2][row1]; diff --git a/include/cglm/project.h b/include/cglm/project.h index c71e735..d4295d3 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -100,7 +100,7 @@ glm_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) { CGLM_INLINE void glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { - vec4 pos4, vone = GLM_VEC4_ONE_INIT; + CGLM_ALIGN(16) vec4 pos4, vone = GLM_VEC4_ONE_INIT; glm_vec4(pos, 1.0f, pos4); diff --git a/include/cglm/quat.h b/include/cglm/quat.h index eac853b..fd4f25f 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -99,7 +99,7 @@ glm_translate(mat4 m, vec3 v); CGLM_INLINE void glm_quat_identity(versor q) { - versor v = GLM_QUAT_IDENTITY_INIT; + CGLM_ALIGN(16) versor v = GLM_QUAT_IDENTITY_INIT; glm_vec4_copy(v, q); } @@ -131,7 +131,7 @@ glm_quat_init(versor q, float x, float y, float z, float w) { CGLM_INLINE void glm_quatv(versor q, float angle, vec3 axis) { - vec3 k; + CGLM_ALIGN(8) vec3 k; float a, c, s; a = angle * 0.5f; @@ -158,7 +158,7 @@ glm_quatv(versor q, float angle, vec3 axis) { CGLM_INLINE void glm_quat(versor q, float angle, float x, float y, float z) { - vec3 axis = {x, y, z}; + CGLM_ALIGN(8) vec3 axis = {x, y, z}; glm_quatv(q, angle, axis); } @@ -267,7 +267,7 @@ glm_quat_conjugate(versor q, versor dest) { CGLM_INLINE void glm_quat_inv(versor q, versor dest) { - versor conj; + CGLM_ALIGN(8) versor conj; glm_quat_conjugate(q, conj); glm_vec4_scale(conj, 1.0f / glm_vec4_norm2(q), dest); } @@ -603,7 +603,7 @@ glm_quat_lerp(versor from, versor to, float t, versor dest) { CGLM_INLINE void glm_quat_slerp(versor from, versor to, float t, versor dest) { - vec4 q1, q2; + CGLM_ALIGN(16) vec4 q1, q2; float cosTheta, sinTheta, angle; cosTheta = glm_quat_dot(from, to); @@ -646,7 +646,7 @@ glm_quat_slerp(versor from, versor to, float t, versor dest) { CGLM_INLINE void glm_quat_look(vec3 eye, versor ori, mat4 dest) { - vec4 t; + CGLM_ALIGN(16) vec4 t; /* orientation */ glm_quat_mat4t(ori, dest); @@ -668,7 +668,7 @@ glm_quat_look(vec3 eye, versor ori, mat4 dest) { CGLM_INLINE void glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) { - vec3 axis; + CGLM_ALIGN(8) vec3 axis; float dot, angle; dot = glm_vec_dot(dir, fwd); @@ -702,7 +702,7 @@ glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) { CGLM_INLINE void glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { - vec3 dir; + CGLM_ALIGN(8) vec3 dir; glm_vec_sub(to, from, dir); glm_quat_for(dir, fwd, up, dest); } @@ -717,9 +717,9 @@ glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { CGLM_INLINE void glm_quat_rotatev(versor q, vec3 v, vec3 dest) { - versor p; - vec3 u, v1, v2; - float s; + CGLM_ALIGN(16) versor p; + CGLM_ALIGN(8) vec3 u, v1, v2; + float s; glm_quat_normalize_to(q, p); glm_quat_imag(p, u); @@ -745,7 +745,7 @@ glm_quat_rotatev(versor q, vec3 v, vec3 dest) { CGLM_INLINE void glm_quat_rotate(mat4 m, versor q, mat4 dest) { - mat4 rot; + CGLM_ALIGN(16) mat4 rot; glm_quat_mat4(q, rot); glm_mul_rot(m, rot, dest); } @@ -760,7 +760,7 @@ glm_quat_rotate(mat4 m, versor q, mat4 dest) { CGLM_INLINE void glm_quat_rotate_at(mat4 m, versor q, vec3 pivot) { - vec3 pivotInv; + CGLM_ALIGN(8) vec3 pivotInv; glm_vec_inv_to(pivot, pivotInv); @@ -784,12 +784,11 @@ glm_quat_rotate_at(mat4 m, versor q, vec3 pivot) { CGLM_INLINE void glm_quat_rotate_atm(mat4 m, versor q, vec3 pivot) { - vec3 pivotInv; + CGLM_ALIGN(8) vec3 pivotInv; glm_vec_inv_to(pivot, pivotInv); - glm_mat4_identity(m); - glm_vec_copy(pivot, m[3]); + glm_translate_make(m, pivot); glm_quat_rotate(m, q, m); glm_translate(m, pivotInv); } diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 50636a1..34a910c 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -454,8 +454,7 @@ glm_vec_inv(vec3 v) { CGLM_INLINE void glm_vec_inv_to(vec3 v, vec3 dest) { - glm_vec_copy(v, dest); - glm_vec_flipsign(dest); + glm_vec_flipsign_to(v, dest); } /*! From 1362bef50ff87ff520b55d1fe5503298b2f9c3ed Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 23 May 2018 23:13:41 +0300 Subject: [PATCH 166/292] fix glm_translate_to --- include/cglm/affine.h | 59 +++++++++++++------------------------------ 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/include/cglm/affine.h b/include/cglm/affine.h index e160bdb..e8f98bb 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -44,48 +44,6 @@ CGLM_INLINE void glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest); -/*! - * @brief translate existing transform matrix by v vector - * and store result in dest - * - * @param[in] m affine transfrom - * @param[in] v translate vector [x, y, z] - * @param[out] dest translated matrix - */ -CGLM_INLINE -void -glm_translate_to(mat4 m, vec3 v, mat4 dest) { - CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; - -#if defined( __SSE__ ) || defined( __SSE2__ ) - glmm_store(dest[3], - _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_load(t[0]), - _mm_set1_ps(v[0])), - _mm_mul_ps(glmm_load(t[1]), - _mm_set1_ps(v[1]))), - _mm_add_ps(_mm_mul_ps(glmm_load(t[2]), - _mm_set1_ps(v[2])), - glmm_load(t[3])))) - ; - - glmm_store(dest[0], glmm_load(m[0])); - glmm_store(dest[1], glmm_load(m[1])); - glmm_store(dest[2], glmm_load(m[2])); -#else - vec4 v1, v2, v3; - - glm_vec4_scale(t[0], v[0], v1); - glm_vec4_scale(t[1], v[1], v2); - glm_vec4_scale(t[2], v[2], v3); - - glm_vec4_add(v1, t[3], t[3]); - glm_vec4_add(v2, t[3], t[3]); - glm_vec4_add(v3, t[3], t[3]); - - glm_mat4_copy(t, dest); -#endif -} - /*! * @brief translate existing transform matrix by v vector * and stores result in same matrix @@ -119,6 +77,23 @@ glm_translate(mat4 m, vec3 v) { #endif } +/*! + * @brief translate existing transform matrix by v vector + * and store result in dest + * + * source matrix will remain same + * + * @param[in] m affine transfrom + * @param[in] v translate vector [x, y, z] + * @param[out] dest translated matrix + */ +CGLM_INLINE +void +glm_translate_to(mat4 m, vec3 v, mat4 dest) { + glm_mat4_copy(m, dest); + glm_translate(dest, v); +} + /*! * @brief translate existing transform matrix by x factor * From 73c073cf324462e088401ba7737fa817cc90a147 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 27 May 2018 11:44:06 +0300 Subject: [PATCH 167/292] add missing call functions --- include/cglm/call/affine.h | 14 +++++ include/cglm/call/cam.h | 80 ++++++++++++++++++++++++++ include/cglm/call/mat3.h | 4 ++ include/cglm/call/mat4.h | 4 ++ include/cglm/call/vec3.h | 4 ++ src/affine.c | 18 ++++++ src/cam.c | 114 +++++++++++++++++++++++++++++++++++++ src/mat3.c | 6 ++ src/mat4.c | 6 ++ src/vec3.c | 6 ++ 10 files changed, 256 insertions(+) diff --git a/include/cglm/call/affine.h b/include/cglm/call/affine.h index 4d3834b..c11405b 100644 --- a/include/cglm/call/affine.h +++ b/include/cglm/call/affine.h @@ -97,6 +97,20 @@ CGLM_EXPORT void glmc_decompose(mat4 m, vec4 t, mat4 r, vec3 s); +/* affine-mat */ + +CGLM_EXPORT +void +glmc_mul(mat4 m1, mat4 m2, mat4 dest); + +CGLM_EXPORT +void +glmc_mul_rot(mat4 m1, mat4 m2, mat4 dest); + +CGLM_EXPORT +void +glmc_inv_tr(mat4 mat); + #ifdef __cplusplus } #endif diff --git a/include/cglm/call/cam.h b/include/cglm/call/cam.h index 35fb18d..befc9b4 100644 --- a/include/cglm/call/cam.h +++ b/include/cglm/call/cam.h @@ -33,6 +33,26 @@ glmc_ortho(float left, float farVal, mat4 dest); +CGLM_EXPORT +void +glmc_ortho_aabb(vec3 box[2], mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_p(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default(float aspect, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_s(float aspect, float size, mat4 dest); + CGLM_EXPORT void glmc_perspective(float fovy, @@ -41,6 +61,14 @@ glmc_perspective(float fovy, float farVal, mat4 dest); +CGLM_EXPORT +void +glmc_perspective_default(float aspect, mat4 dest); + +CGLM_EXPORT +void +glmc_perspective_resize(float aspect, mat4 proj); + CGLM_EXPORT void glmc_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest); @@ -53,6 +81,58 @@ CGLM_EXPORT void glmc_look_anyup(vec3 eye, vec3 dir, mat4 dest); +CGLM_EXPORT +void +glmc_persp_decomp(mat4 proj, + float * __restrict nearVal, + float * __restrict farVal, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decompv(mat4 proj, float dest[6]); + +CGLM_EXPORT +void +glmc_persp_decomp_x(mat4 proj, + float * __restrict left, + float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decomp_y(mat4 proj, + float * __restrict top, + float * __restrict bottom); + +CGLM_EXPORT +void +glmc_persp_decomp_z(mat4 proj, + float * __restrict nearVal, + float * __restrict farVal); + +CGLM_EXPORT +void +glmc_persp_decomp_far(mat4 proj, float * __restrict farVal); + +CGLM_EXPORT +void +glmc_persp_decomp_near(mat4 proj, float * __restrict nearVal); + +CGLM_EXPORT +float +glmc_persp_fovy(mat4 proj); + +CGLM_EXPORT +float +glmc_persp_aspect(mat4 proj); + +CGLM_EXPORT +void +glmc_persp_sizes(mat4 proj, float fovy, vec4 dest); + #ifdef __cplusplus } #endif diff --git a/include/cglm/call/mat3.h b/include/cglm/call/mat3.h index ceebc7e..1a92de4 100644 --- a/include/cglm/call/mat3.h +++ b/include/cglm/call/mat3.h @@ -40,6 +40,10 @@ CGLM_EXPORT void glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest); +CGLM_EXPORT +void +glmc_mat3_quat(mat3 m, versor dest); + CGLM_EXPORT void glmc_mat3_scale(mat3 m, float s); diff --git a/include/cglm/call/mat4.h b/include/cglm/call/mat4.h index c9ad796..ef75623 100644 --- a/include/cglm/call/mat4.h +++ b/include/cglm/call/mat4.h @@ -85,6 +85,10 @@ CGLM_EXPORT void glmc_mat4_inv_precise(mat4 mat, mat4 dest); +CGLM_EXPORT +void +glmc_mat4_inv_fast(mat4 mat, mat4 dest); + CGLM_EXPORT void glmc_mat4_swap_col(mat4 mat, int col1, int col2); diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 8fcee4f..50a6b22 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -136,6 +136,10 @@ CGLM_EXPORT void glmc_vec_rotate_m4(mat4 m, vec3 v, vec3 dest); +CGLM_EXPORT +void +glmc_vec_rotate_m3(mat3 m, vec3 v, vec3 dest); + CGLM_EXPORT void glmc_vec_proj(vec3 a, vec3 b, vec3 dest); diff --git a/src/affine.c b/src/affine.c index a271f9f..a818bd1 100644 --- a/src/affine.c +++ b/src/affine.c @@ -133,3 +133,21 @@ void glmc_decompose(mat4 m, vec4 t, mat4 r, vec3 s) { glm_decompose(m, t, r, s); } + +CGLM_EXPORT +void +glmc_mul(mat4 m1, mat4 m2, mat4 dest) { + glm_mul(m1, m2, dest); +} + +CGLM_EXPORT +void +glmc_mul_rot(mat4 m1, mat4 m2, mat4 dest) { + glm_mul_rot(m1, m2, dest); +} + +CGLM_EXPORT +void +glmc_inv_tr(mat4 mat) { + glm_inv_tr(mat); +} diff --git a/src/cam.c b/src/cam.c index aeac3c7..4a8567f 100644 --- a/src/cam.c +++ b/src/cam.c @@ -44,6 +44,36 @@ glmc_ortho(float left, dest); } +CGLM_EXPORT +void +glmc_ortho_aabb(vec3 box[2], mat4 dest) { + glm_ortho_aabb(box, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_p(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_pz(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default(float aspect, mat4 dest) { + glm_ortho_default(aspect, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_s(float aspect, float size, mat4 dest) { + glm_ortho_default_s(aspect, size, dest); +} + CGLM_EXPORT void glmc_perspective(float fovy, @@ -58,6 +88,18 @@ glmc_perspective(float fovy, dest); } +CGLM_EXPORT +void +glmc_perspective_default(float aspect, mat4 dest) { + glm_perspective_default(aspect, dest); +} + +CGLM_EXPORT +void +glmc_perspective_resize(float aspect, mat4 proj) { + glm_perspective_resize(aspect, proj); +} + CGLM_EXPORT void glmc_lookat(vec3 eye, @@ -78,3 +120,75 @@ void glmc_look_anyup(vec3 eye, vec3 dir, mat4 dest) { glm_look_anyup(eye, dir, dest); } + +CGLM_EXPORT +void +glmc_persp_decomp(mat4 proj, + float * __restrict nearVal, + float * __restrict farVal, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp(proj, nearVal, farVal, top, bottom, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decompv(mat4 proj, float dest[6]) { + glm_persp_decompv(proj, dest); +} + +CGLM_EXPORT +void +glmc_persp_decomp_x(mat4 proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x(proj, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decomp_y(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y(proj, top, bottom); +} + +CGLM_EXPORT +void +glmc_persp_decomp_z(mat4 proj, + float * __restrict nearVal, + float * __restrict farVal) { + glm_persp_decomp_z(proj, nearVal, farVal); +} + +CGLM_EXPORT +void +glmc_persp_decomp_far(mat4 proj, float * __restrict farVal) { + glm_persp_decomp_far(proj, farVal); +} + +CGLM_EXPORT +void +glmc_persp_decomp_near(mat4 proj, float * __restrict nearVal) { + glm_persp_decomp_near(proj, nearVal); +} + +CGLM_EXPORT +float +glmc_persp_fovy(mat4 proj) { + return glm_persp_fovy(proj); +} + +CGLM_EXPORT +float +glmc_persp_aspect(mat4 proj) { + return glm_persp_aspect(proj); +} + +CGLM_EXPORT +void +glmc_persp_sizes(mat4 proj, float fovy, vec4 dest) { + glm_persp_sizes(proj, fovy, dest); +} diff --git a/src/mat3.c b/src/mat3.c index c39932d..4455b0f 100644 --- a/src/mat3.c +++ b/src/mat3.c @@ -44,6 +44,12 @@ glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest) { glm_mat3_mulv(m, v, dest); } +CGLM_EXPORT +void +glmc_mat3_quat(mat3 m, versor dest) { + glm_mat3_quat(m, dest); +} + CGLM_EXPORT void glmc_mat3_scale(mat3 m, float s) { diff --git a/src/mat4.c b/src/mat4.c index 9407684..95f6690 100644 --- a/src/mat4.c +++ b/src/mat4.c @@ -110,6 +110,12 @@ glmc_mat4_inv_precise(mat4 mat, mat4 dest) { glm_mat4_inv_precise(mat, dest); } +CGLM_EXPORT +void +glmc_mat4_inv_fast(mat4 mat, mat4 dest) { + glm_mat4_inv_fast(mat, dest); +} + CGLM_EXPORT void glmc_mat4_swap_col(mat4 mat, int col1, int col2) { diff --git a/src/vec3.c b/src/vec3.c index 28fda51..401b983 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -188,6 +188,12 @@ glmc_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) { glm_vec_rotate_m4(m, v, dest); } +CGLM_EXPORT +void +glmc_vec_rotate_m3(mat3 m, vec3 v, vec3 dest) { + glm_vec_rotate_m3(m, v, dest); +} + CGLM_EXPORT void glmc_vec_proj(vec3 a, vec3 b, vec3 dest) { From e5d61b34337ac783eae1ba35f52cf616820e6a6b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 27 May 2018 11:46:27 +0300 Subject: [PATCH 168/292] update mat4_mulv3 api to include translation --- include/cglm/call/mat4.h | 4 ++++ include/cglm/mat4.h | 16 ++++++++-------- src/mat4.c | 6 ++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/cglm/call/mat4.h b/include/cglm/call/mat4.h index ef75623..ef86682 100644 --- a/include/cglm/call/mat4.h +++ b/include/cglm/call/mat4.h @@ -53,6 +53,10 @@ CGLM_EXPORT void glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest); +CGLM_EXPORT +void +glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest); + CGLM_EXPORT void glmc_mat4_quat(mat4 m, versor dest); diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 6d345f3..53e69de 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -370,20 +370,20 @@ glm_mat4_quat(mat4 m, versor dest) { } /*! - * @brief multiply vector with mat4's mat3 part(rotation) + * @brief multiply vector with mat4 * * @param[in] m mat4(affine transform) * @param[in] v vec3 - * @param[out] dest vec3 + * @param[in] last 4th item to make it vec4 + * @param[out] dest result vector (vec3) */ CGLM_INLINE void -glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest) { - vec3 res; - res[0] = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0] * v[2]; - res[1] = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1] * v[2]; - res[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2]; - glm_vec_copy(res, dest); +glm_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest) { + vec4 res; + glm_vec4(v, last, res); + glm_mat4_mulv(m, res, res); + glm_vec3(res, dest); } /*! diff --git a/src/mat4.c b/src/mat4.c index 95f6690..4bca6f7 100644 --- a/src/mat4.c +++ b/src/mat4.c @@ -62,6 +62,12 @@ glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest) { glm_mat4_mulv(m, v, dest); } +CGLM_EXPORT +void +glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest) { + glm_mat4_mulv3(m, v, last, dest); +} + CGLM_EXPORT void glmc_mat4_quat(mat4 m, versor dest) { From ef0653640f45266f549aee3ec34fe2892880ca02 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 27 May 2018 11:53:48 +0300 Subject: [PATCH 169/292] update cocoapod version tag --- cglm.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cglm.podspec b/cglm.podspec index 150ca86..00d1df9 100644 --- a/cglm.podspec +++ b/cglm.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| # Description s.name = "cglm" - s.version = "0.4.4" + s.version = "0.4.6" s.summary = "📽 Optimized OpenGL/Graphics Math (glm) for C" s.description = <<-DESC cglm is math library for graphics programming for C. It is similar to original glm but it is written for C instead of C++ (you can use here too). See the documentation or README for all features. From 059bdfdd4b6ea58f09372cfd170518e50575ca3b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 27 May 2018 11:54:05 +0300 Subject: [PATCH 170/292] update docs --- docs/source/box.rst | 9 +++++++++ docs/source/mat3.rst | 9 +++++++++ docs/source/mat4.rst | 9 +++++++++ include/cglm/mat3.h | 4 ++-- include/cglm/mat4.h | 2 +- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/docs/source/box.rst b/docs/source/box.rst index 6aa4d62..6430c64 100644 --- a/docs/source/box.rst +++ b/docs/source/box.rst @@ -28,6 +28,7 @@ Functions: #. :c:func:`glm_aabb_isvalid` #. :c:func:`glm_aabb_size` #. :c:func:`glm_aabb_radius` +#. :c:func:`glm_aabb_center` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -131,3 +132,11 @@ Functions documentation Parameters: | *[in]* **box** bounding box + +.. c:function:: void glm_aabb_center(vec3 box[2], vec3 dest) + + | computes center point of AABB + + Parameters: + | *[in]* **box** bounding box + | *[out]* **box** center of bounding box diff --git a/docs/source/mat3.rst b/docs/source/mat3.rst index 9b00417..b9f56ee 100644 --- a/docs/source/mat3.rst +++ b/docs/source/mat3.rst @@ -24,6 +24,7 @@ Functions: #. :c:func:`glm_mat3_transpose_to` #. :c:func:`glm_mat3_transpose` #. :c:func:`glm_mat3_mulv` +#. :c:func:`glm_mat3_quat` #. :c:func:`glm_mat3_scale` #. :c:func:`glm_mat3_det` #. :c:func:`glm_mat3_inv` @@ -89,6 +90,14 @@ Functions documentation | *[in]* **v** vec3 (right, column vector) | *[out]* **dest** destination (result, column vector) +.. c:function:: void glm_mat3_quat(mat3 m, versor dest) + + convert mat3 to quaternion + + Parameters: + | *[in]* **m** rotation matrix + | *[out]* **dest** destination quaternion + .. c:function:: void glm_mat3_scale(mat3 m, float s) multiply matrix with scalar diff --git a/docs/source/mat4.rst b/docs/source/mat4.rst index 1a391cb..7fb0857 100644 --- a/docs/source/mat4.rst +++ b/docs/source/mat4.rst @@ -32,6 +32,7 @@ Functions: #. :c:func:`glm_mat4_mulN` #. :c:func:`glm_mat4_mulv` #. :c:func:`glm_mat4_mulv3` +#. :c:func:`glm_mat4_quat` #. :c:func:`glm_mat4_transpose_to` #. :c:func:`glm_mat4_transpose` #. :c:func:`glm_mat4_scale_p` @@ -146,6 +147,14 @@ Functions documentation | *[in]* **v** vec3 (right, column vector) | *[out]* **dest** vec3 (result, column vector) +.. c:function:: void glm_mat4_quat(mat4 m, versor dest) + + convert mat4's rotation part to quaternion + + Parameters: + | *[in]* **m** affine matrix + | *[out]* **dest** destination quaternion + .. c:function:: void glm_mat4_transpose_to(mat4 m, mat4 dest) transpose mat4 and store in dest diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 1df3a3b..f932bce 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -189,9 +189,9 @@ glm_mat3_mulv(mat3 m, vec3 v, vec3 dest) { /*! - * @brief convert mat4's rotation part to quaternion + * @brief convert mat3 to quaternion * - * @param[in] m left matrix + * @param[in] m rotation matrix * @param[out] dest destination quaternion */ CGLM_INLINE diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 53e69de..e6e358f 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -323,7 +323,7 @@ glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) { /*! * @brief convert mat4's rotation part to quaternion * - * @param[in] m left matrix + * @param[in] m affine matrix * @param[out] dest destination quaternion */ CGLM_INLINE From af812e86ebc06aca69d27a058bcd6e5d4ec52923 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 29 May 2018 11:30:38 +0300 Subject: [PATCH 171/292] add a note to clarify up vector restriction for glm_lookat and glm_look --- docs/source/cam.rst | 12 ++++++++---- include/cglm/cam.h | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/source/cam.rst b/docs/source/cam.rst index a9f1ce7..79b2bd4 100644 --- a/docs/source/cam.rst +++ b/docs/source/cam.rst @@ -167,11 +167,13 @@ Functions documentation | set up view matrix + **NOTE:** The UP vector must not be parallel to the line of sight from the eye point to the reference point. + Parameters: - | *[in]* **eye** eye vector - | *[in]* **center** center vector - | *[in]* **up** up vector - | *[out]* **dest** result matrix + | *[in]* **eye** eye vector + | *[in]* **center** center vector + | *[in]* **up** up vector + | *[out]* **dest** result matrix .. c:function:: void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) @@ -181,6 +183,8 @@ Functions documentation target self then this might be useful. Because you need to get target from direction. + **NOTE:** The UP vector must not be parallel to the line of sight from the eye point to the reference point. + Parameters: | *[in]* **eye** eye vector | *[in]* **center** direction vector diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 28b8a7d..6e5fc16 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -321,6 +321,9 @@ glm_perspective_resize(float aspect, /*! * @brief set up view matrix * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * * @param[in] eye eye vector * @param[in] center center vector * @param[in] up up vector @@ -364,6 +367,9 @@ glm_lookat(vec3 eye, * convenient wrapper for lookat: if you only have direction not target self * then this might be useful. Because you need to get target from direction. * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * * @param[in] eye eye vector * @param[in] dir direction vector * @param[in] up up vector From 5b3aabc103efa7bf2d0a4dfe057e9cc5a24e1b27 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 29 May 2018 23:19:39 +0300 Subject: [PATCH 172/292] aabb intersect functions * AABB vs AABB * AABB vs Point * AABB vs Sphere * AABB contains AABB --- include/cglm/box.h | 65 +++++++++++++++++++++++++++++++++++++++++ include/cglm/call/box.h | 16 ++++++++++ src/box.c | 24 +++++++++++++++ 3 files changed, 105 insertions(+) diff --git a/include/cglm/box.h b/include/cglm/box.h index 5ed135e..72f8b8f 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -212,4 +212,69 @@ glm_aabb_center(vec3 box[2], vec3 dest) { glm_vec_center(box[0], box[1], dest); } +/*! + * @brief check if two AABB intersects + * + * @param[in] box bounding box + * @param[in] other other bounding box + */ +CGLM_INLINE +bool +glm_aabb_aabb(vec3 box[2], vec3 other[2]) { + return (box[0][0] <= other[1][0] && box[1][0] >= other[0][0]) + && (box[0][1] <= other[1][1] && box[1][1] >= other[0][1]) + && (box[0][2] <= other[1][2] && box[1][2] >= other[0][2]); +} + +/*! + * @brief check if AABB intersects with sphere + * + * @param[in] box bounding box + * @param[in] other other bounding box + */ +CGLM_INLINE +bool +glm_aabb_sphere(vec3 box[2], vec4 sph) { + vec3 v; + float dist; + + /* get box closest point to sphere center by clamping */ + v[0] = glm_max(box[0][0], glm_min(sph[0], box[1][0])); + v[1] = glm_max(box[0][1], glm_min(sph[1], box[1][1])); + v[2] = glm_max(box[0][2], glm_min(sph[2], box[1][2])); + + /* this is the same as glm_sphere_point */ + dist = glm_vec_distance(v, sph); + + return dist < sph[3]; +} + +/*! + * @brief check if point is inside of AABB + * + * @param[in] box bounding box + * @param[in] point point + */ +CGLM_INLINE +bool +glm_aabb_point(vec3 box[2], vec3 point) { + return (point[0] >= box[0][0] && point[0] <= box[1][0]) + && (point[1] >= box[0][1] && point[1] <= box[1][1]) + && (point[2] >= box[0][2] && point[2] <= box[1][2]); +} + +/*! + * @brief check if AABB contains other AABB + * + * @param[in] box bounding box + * @param[in] other other bounding box + */ +CGLM_INLINE +bool +glm_aabb_contains(vec3 box[2], vec3 other[2]) { + return (box[0][0] <= other[0][0] && box[1][0] >= other[1][0]) + && (box[0][1] <= other[0][1] && box[1][1] >= other[1][1]) + && (box[0][2] <= other[0][2] && box[1][2] >= other[1][2]); +} + #endif /* cglm_box_h */ diff --git a/include/cglm/call/box.h b/include/cglm/call/box.h index bf25508..0d4c8c1 100644 --- a/include/cglm/call/box.h +++ b/include/cglm/call/box.h @@ -56,6 +56,22 @@ CGLM_EXPORT void glmc_aabb_center(vec3 box[2], vec3 dest); +CGLM_EXPORT +bool +glmc_aabb_aabb(vec3 box[2], vec3 other[2]); + +CGLM_EXPORT +bool +glmc_aabb_point(vec3 box[2], vec3 point); + +CGLM_EXPORT +bool +glmc_aabb_contains(vec3 box[2], vec3 other[2]); + +CGLM_EXPORT +bool +glmc_aabb_sphere(vec3 box[2], vec4 sph); + #ifdef __cplusplus } #endif diff --git a/src/box.c b/src/box.c index 0274390..1352f97 100644 --- a/src/box.c +++ b/src/box.c @@ -70,3 +70,27 @@ void glmc_aabb_center(vec3 box[2], vec3 dest) { glm_aabb_center(box, dest); } + +CGLM_EXPORT +bool +glmc_aabb_aabb(vec3 box[2], vec3 other[2]) { + return glm_aabb_aabb(box, other); +} + +CGLM_EXPORT +bool +glmc_aabb_point(vec3 box[2], vec3 point) { + return glm_aabb_point(box, point); +} + +CGLM_EXPORT +bool +glmc_aabb_contains(vec3 box[2], vec3 other[2]) { + return glm_aabb_contains(box, other); +} + +CGLM_EXPORT +bool +glmc_aabb_sphere(vec3 box[2], vec4 sph) { + return glm_aabb_sphere(box, sph); +} From c8fc460ba10e440f4b5a56e1e5931821499d6a4c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 29 May 2018 23:29:09 +0300 Subject: [PATCH 173/292] add support for spheres --- include/cglm/cglm.h | 1 + include/cglm/sphere.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 include/cglm/sphere.h diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index 52c7e97..720ae08 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -24,5 +24,6 @@ #include "util.h" #include "io.h" #include "project.h" +#include "sphere.h" #endif /* cglm_h */ diff --git a/include/cglm/sphere.h b/include/cglm/sphere.h new file mode 100644 index 0000000..e837972 --- /dev/null +++ b/include/cglm/sphere.h @@ -0,0 +1,40 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_sphere_h +#define cglm_sphere_h + +#include "common.h" +#include "mat4.h" + +/* + Sphere Representation in cglm: [center.x, center.y, center.z, radii] + + You could use this representation or you can convert it to vec4 before call + any function + */ + +CGLM_INLINE +void +glm_sphere_transform(vec4 s, mat4 m, vec4 dest) { + glm_mat4_mulv3(m, s, 1.0f, dest); + dest[3] = s[3]; +} + +CGLM_INLINE +void +glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { + float dist, radii; + + dist = glm_vec_distance(s1, s2); + radii = dist + s1[3] + s2[3]; + + glm_vec_center(s1, s2, dest); + dest[3] = radii; +} + +#endif /* cglm_sphere_h */ From 6b2b4b4f120dec6427ab42835a6101b8ec0ceaa4 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 30 May 2018 23:00:18 +0300 Subject: [PATCH 174/292] implement glm_aabb_sphere as GraphicsGems Solid Box - Solid Sphere test --- CREDITS | 8 +++++--- include/cglm/box.h | 27 +++++++++++++++------------ include/cglm/call/box.h | 2 +- include/cglm/util.h | 1 - src/box.c | 4 ++-- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CREDITS b/CREDITS index 44e55a8..0488bad 100644 --- a/CREDITS +++ b/CREDITS @@ -1,7 +1,7 @@ This library [initially] used some [piece of] implementations (may include codes) from these open source projects/resources: -1. Affine Transforms +1. Initial Affine Transforms The original glm repo (g-truc), url: https://github.com/g-truc/glm LICENSE[S]: @@ -11,7 +11,7 @@ LICENSE[S]: FULL LICENSE: https://github.com/g-truc/glm/blob/master/copying.txt -2. Quaternions +2. Initial Quaternions Anton's OpenGL 4 Tutorials book source code: LICENSE: @@ -47,6 +47,8 @@ http://old.cescg.org/CESCG-2002/DSykoraJJelinek/ 7. Quaternions Initial mat4_quat is borrowed from Apple's simd library - 8. Vector Rotation using Quaternion https://gamedev.stackexchange.com/questions/28395/rotating-vector3-by-a-quaternion + +9. Sphere AABB intersect +https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c diff --git a/include/cglm/box.h b/include/cglm/box.h index 72f8b8f..3708107 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -229,24 +229,27 @@ glm_aabb_aabb(vec3 box[2], vec3 other[2]) { /*! * @brief check if AABB intersects with sphere * - * @param[in] box bounding box - * @param[in] other other bounding box + * https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c + * Solid Box - Solid Sphere test. + * + * @param[in] box solid bounding box + * @param[in] s solid sphere */ CGLM_INLINE bool -glm_aabb_sphere(vec3 box[2], vec4 sph) { - vec3 v; - float dist; +glm_aabb_sphere(vec3 box[2], vec4 s) { + float dmin; + int a, b, c; - /* get box closest point to sphere center by clamping */ - v[0] = glm_max(box[0][0], glm_min(sph[0], box[1][0])); - v[1] = glm_max(box[0][1], glm_min(sph[1], box[1][1])); - v[2] = glm_max(box[0][2], glm_min(sph[2], box[1][2])); + a = s[0] >= box[0][0]; + b = s[1] >= box[0][1]; + c = s[2] >= box[0][2]; - /* this is the same as glm_sphere_point */ - dist = glm_vec_distance(v, sph); + dmin = glm_pow2(s[0] - box[a][0]) + + glm_pow2(s[1] - box[b][1]) + + glm_pow2(s[2] - box[c][2]); - return dist < sph[3]; + return dmin <= glm_pow2(s[3]); } /*! diff --git a/include/cglm/call/box.h b/include/cglm/call/box.h index 0d4c8c1..afb7558 100644 --- a/include/cglm/call/box.h +++ b/include/cglm/call/box.h @@ -70,7 +70,7 @@ glmc_aabb_contains(vec3 box[2], vec3 other[2]); CGLM_EXPORT bool -glmc_aabb_sphere(vec3 box[2], vec4 sph); +glmc_aabb_sphere(vec3 box[2], vec4 s); #ifdef __cplusplus } diff --git a/include/cglm/util.h b/include/cglm/util.h index b272d44..af7514c 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -98,7 +98,6 @@ glm_make_deg(float *rad) { CGLM_INLINE float glm_pow2(float x) { - return x * x; } diff --git a/src/box.c b/src/box.c index 1352f97..fd639ea 100644 --- a/src/box.c +++ b/src/box.c @@ -91,6 +91,6 @@ glmc_aabb_contains(vec3 box[2], vec3 other[2]) { CGLM_EXPORT bool -glmc_aabb_sphere(vec3 box[2], vec4 sph) { - return glm_aabb_sphere(box, sph); +glmc_aabb_sphere(vec3 box[2], vec4 s) { + return glm_aabb_sphere(box, s); } From 3dc9070909208a9214b36766f3772a9de526cef3 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 30 May 2018 23:35:59 +0300 Subject: [PATCH 175/292] squared distance for vec3 --- docs/source/vec3.rst | 12 ++++++++++++ include/cglm/call/vec3.h | 4 ++++ include/cglm/vec3.h | 19 ++++++++++++++++--- src/vec3.c | 6 ++++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index fcbfbfb..e4a2746 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -56,6 +56,7 @@ Functions: #. :c:func:`glm_vec_inv_to` #. :c:func:`glm_vec_normalize` #. :c:func:`glm_vec_normalize_to` +#. :c:func:`glm_vec_distance2` #. :c:func:`glm_vec_distance` #. :c:func:`glm_vec_angle` #. :c:func:`glm_vec_rotate` @@ -366,6 +367,17 @@ Functions documentation | *[in]* **v2** vector2 | *[out]* **dest** center point +.. c:function:: float glm_vec_distance2(vec3 v1, vec3 v2) + + squared distance between two vectors + + Parameters: + | *[in]* **mat** vector1 + | *[in]* **row1** vector2 + + Returns: + | squared distance (distance * distance) + .. c:function:: float glm_vec_distance(vec3 v1, vec3 v2) distance between two vectors diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 50a6b22..ae21620 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -148,6 +148,10 @@ CGLM_EXPORT void glmc_vec_center(vec3 v1, vec3 v2, vec3 dest); +CGLM_EXPORT +float +glmc_vec_distance2(vec3 v1, vec3 v2); + CGLM_EXPORT float glmc_vec_distance(vec3 v1, vec3 v2); diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 34a910c..18d8a7b 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -633,6 +633,21 @@ glm_vec_center(vec3 v1, vec3 v2, vec3 dest) { glm_vec_scale(dest, 0.5f, dest); } +/** + * @brief squared distance between two vectors + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @return returns squared distance (distance * distance) + */ +CGLM_INLINE +float +glm_vec_distance2(vec3 v1, vec3 v2) { + return glm_pow2(v2[0] - v1[0]) + + glm_pow2(v2[1] - v1[1]) + + glm_pow2(v2[2] - v1[2]); +} + /** * @brief distance between two vectors * @@ -643,9 +658,7 @@ glm_vec_center(vec3 v1, vec3 v2, vec3 dest) { CGLM_INLINE float glm_vec_distance(vec3 v1, vec3 v2) { - return sqrtf(glm_pow2(v2[0] - v1[0]) - + glm_pow2(v2[1] - v1[1]) - + glm_pow2(v2[2] - v1[2])); + return sqrtf(glm_vec_distance2(v1, v2)); } /*! diff --git a/src/vec3.c b/src/vec3.c index 401b983..a2ab499 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -206,6 +206,12 @@ glmc_vec_center(vec3 v1, vec3 v2, vec3 dest) { glm_vec_center(v1, v2, dest); } +CGLM_EXPORT +float +glmc_vec_distance2(vec3 v1, vec3 v2) { + return glm_vec_distance2(v1, v2); +} + CGLM_EXPORT float glmc_vec_distance(vec3 v1, vec3 v2) { From 720b617ee06ff544695ef4241864b4045e4bb57f Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 30 May 2018 23:42:22 +0300 Subject: [PATCH 176/292] sphere and aabb --- docs/source/api.rst | 1 + docs/source/box.rst | 41 +++++++++++++++++++++++- docs/source/sphere.rst | 65 ++++++++++++++++++++++++++++++++++++++ include/cglm/call.h | 1 + include/cglm/call/sphere.h | 32 +++++++++++++++++++ include/cglm/sphere.h | 45 ++++++++++++++++++++++++++ makefile.am | 9 ++++-- src/sphere.c | 33 +++++++++++++++++++ win/cglm.vcxproj | 3 ++ win/cglm.vcxproj.filters | 9 ++++++ 10 files changed, 235 insertions(+), 4 deletions(-) create mode 100644 docs/source/sphere.rst create mode 100644 include/cglm/call/sphere.h create mode 100644 src/sphere.c diff --git a/docs/source/api.rst b/docs/source/api.rst index c61365b..d0e4721 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -45,3 +45,4 @@ Follow the :doc:`build` documentation for this util io call + sphere diff --git a/docs/source/box.rst b/docs/source/box.rst index 6430c64..7a388e2 100644 --- a/docs/source/box.rst +++ b/docs/source/box.rst @@ -29,6 +29,10 @@ Functions: #. :c:func:`glm_aabb_size` #. :c:func:`glm_aabb_radius` #. :c:func:`glm_aabb_center` +#. :c:func:`glm_aabb_aabb` +#. :c:func:`glm_aabb_sphere` +#. :c:func:`glm_aabb_point` +#. :c:func:`glm_aabb_contains` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -137,6 +141,41 @@ Functions documentation | computes center point of AABB + Parameters: + | *[in]* **box** bounding box + | *[out]* **dest** center of bounding box + +.. c:function:: bool glm_aabb_aabb(vec3 box[2], vec3 other[2]) + + | check if two AABB intersects + Parameters: | *[in]* **box** bounding box - | *[out]* **box** center of bounding box + | *[out]* **other** other bounding box + +.. c:function:: bool glm_aabb_sphere(vec3 box[2], vec4 s) + + | check if AABB intersects with sphere + + | https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c + | Solid Box - Solid Sphere test. + + Parameters: + | *[in]* **box** solid bounding box + | *[out]* **s** solid sphere + +.. c:function:: bool glm_aabb_point(vec3 box[2], vec3 point) + + | check if point is inside of AABB + + Parameters: + | *[in]* **box** bounding box + | *[out]* **point** point + +.. c:function:: bool glm_aabb_contains(vec3 box[2], vec3 other[2]) + + | check if AABB contains other AABB + + Parameters: + | *[in]* **box** bounding box + | *[out]* **other** other bounding box diff --git a/docs/source/sphere.rst b/docs/source/sphere.rst new file mode 100644 index 0000000..427200e --- /dev/null +++ b/docs/source/sphere.rst @@ -0,0 +1,65 @@ +.. default-domain:: C + +Sphere +================================================================================ + +Header: cglm/sphere.h + +**Definition of sphere:** + +Sphere Representation in cglm is *vec4*: **[center.x, center.y, center.z, radii]** + +You can call any vec3 function by pasing sphere. Because first three elements +defines center of sphere. + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_sphere_radii` +#. :c:func:`glm_sphere_transform` +#. :c:func:`glm_sphere_merge` +#. :c:func:`glm_sphere_sphere` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: float glm_sphere_radii(vec4 s) + + | helper for getting sphere radius + + Parameters: + | *[in]* **s** sphere + + Returns: + returns radii + +.. c:function:: void glm_sphere_transform(vec4 s, mat4 m, vec4 dest) + + | apply transform to sphere, it is just wrapper for glm_mat4_mulv3 + + Parameters: + | *[in]* **s** sphere + | *[in]* **m** transform matrix + | *[out]* **dest** transformed sphere + +.. c:function:: void glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) + + | merges two spheres and creates a new one + + two sphere must be in same space, for instance if one in world space then + the other must be in world space too, not in local space. + + Parameters: + | *[in]* **s1** sphere 1 + | *[in]* **s2** sphere 2 + | *[out]* **dest** merged/extended sphere + +.. c:function:: bool glm_sphere_sphere(vec4 s1, vec4 s2) + + | check if two sphere intersects + + Parameters: + | *[in]* **s1** sphere + | *[in]* **s2** other sphere diff --git a/include/cglm/call.h b/include/cglm/call.h index ce08b78..77148ac 100644 --- a/include/cglm/call.h +++ b/include/cglm/call.h @@ -25,6 +25,7 @@ extern "C" { #include "call/box.h" #include "call/io.h" #include "call/project.h" +#include "call/sphere.h" #ifdef __cplusplus } diff --git a/include/cglm/call/sphere.h b/include/cglm/call/sphere.h new file mode 100644 index 0000000..9a9a59f --- /dev/null +++ b/include/cglm/call/sphere.h @@ -0,0 +1,32 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_sphere_h +#define cglmc_sphere_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +float +glmc_sphere_radii(vec4 s); + +CGLM_EXPORT +void +glmc_sphere_transform(vec4 s, mat4 m, vec4 dest); + +CGLM_EXPORT +void +glmc_sphere_merge(vec4 s1, vec4 s2, vec4 dest); + +CGLM_EXPORT +bool +glmc_sphere_sphere(vec4 s1, vec4 s2); + +#endif /* cglmc_sphere_h */ diff --git a/include/cglm/sphere.h b/include/cglm/sphere.h index e837972..4c9d79b 100644 --- a/include/cglm/sphere.h +++ b/include/cglm/sphere.h @@ -18,6 +18,26 @@ any function */ +/*! + * @brief helper for getting sphere radius + * + * @param[in] s sphere + * + * @return returns radii + */ +CGLM_INLINE +float +glm_sphere_radii(vec4 s) { + return s[3]; +} + +/*! + * @brief apply transform to sphere, it is just wrapper for glm_mat4_mulv3 + * + * @param[in] s sphere + * @param[in] m transform matrix + * @param[out] dest transformed sphere + */ CGLM_INLINE void glm_sphere_transform(vec4 s, mat4 m, vec4 dest) { @@ -25,6 +45,16 @@ glm_sphere_transform(vec4 s, mat4 m, vec4 dest) { dest[3] = s[3]; } +/*! + * @brief merges two spheres and creates a new one + * + * two sphere must be in same space, for instance if one in world space then + * the other must be in world space too, not in local space. + * + * @param[in] s1 sphere 1 + * @param[in] s2 sphere 2 + * @param[out] dest merged/extended sphere + */ CGLM_INLINE void glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { @@ -33,8 +63,23 @@ glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { dist = glm_vec_distance(s1, s2); radii = dist + s1[3] + s2[3]; + radii = glm_max(radii, s1[3]); + radii = glm_max(radii, s2[3]); + glm_vec_center(s1, s2, dest); dest[3] = radii; } +/*! + * @brief check if two sphere intersects + * + * @param[in] s1 sphere + * @param[in] s2 other sphere + */ +CGLM_INLINE +bool +glm_sphere_sphere(vec4 s1, vec4 s2) { + return glm_vec_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]); +} + #endif /* cglm_sphere_h */ diff --git a/makefile.am b/makefile.am index 1999b3d..7ee0904 100644 --- a/makefile.am +++ b/makefile.am @@ -55,7 +55,8 @@ cglm_HEADERS = include/cglm/version.h \ include/cglm/frustum.h \ include/cglm/box.h \ include/cglm/color.h \ - include/cglm/project.h + include/cglm/project.h \ + include/cglm/sphere.h cglm_calldir=$(includedir)/cglm/call cglm_call_HEADERS = include/cglm/call/mat4.h \ @@ -70,7 +71,8 @@ cglm_call_HEADERS = include/cglm/call/mat4.h \ include/cglm/call/plane.h \ include/cglm/call/frustum.h \ include/cglm/call/box.h \ - include/cglm/call/project.h + include/cglm/call/project.h \ + include/cglm/call/sphere.h cglm_simddir=$(includedir)/cglm/simd cglm_simd_HEADERS = include/cglm/simd/intrin.h @@ -101,7 +103,8 @@ libcglm_la_SOURCES=\ src/plane.c \ src/frustum.c \ src/box.c \ - src/project.c + src/project.c \ + src/sphere.c test_tests_SOURCES=\ test/src/test_common.c \ diff --git a/src/sphere.c b/src/sphere.c new file mode 100644 index 0000000..e6b46fc --- /dev/null +++ b/src/sphere.c @@ -0,0 +1,33 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +float +glmc_sphere_radii(vec4 s) { + return glm_sphere_radii(s); +} + +CGLM_EXPORT +void +glmc_sphere_transform(vec4 s, mat4 m, vec4 dest) { + glm_sphere_transform(s, m, dest); +} + +CGLM_EXPORT +void +glmc_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { + glm_sphere_merge(s1, s2, dest); +} + +CGLM_EXPORT +bool +glmc_sphere_sphere(vec4 s1, vec4 s2) { + return glm_sphere_sphere(s1, s2); +} diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj index 415a87d..556a24e 100644 --- a/win/cglm.vcxproj +++ b/win/cglm.vcxproj @@ -31,6 +31,7 @@ + @@ -50,6 +51,7 @@ + @@ -72,6 +74,7 @@ + diff --git a/win/cglm.vcxproj.filters b/win/cglm.vcxproj.filters index 3090d72..cf7634b 100644 --- a/win/cglm.vcxproj.filters +++ b/win/cglm.vcxproj.filters @@ -78,6 +78,9 @@ src + + src + @@ -215,5 +218,11 @@ include\cglm\call + + include\cglm\call + + + include\cglm + \ No newline at end of file From 7a8017835703838bca6de519805245dea48ca3a8 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 9 Jun 2018 18:10:44 +0300 Subject: [PATCH 177/292] improve quat_look --- include/cglm/quat.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index fd4f25f..aa303ca 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -646,15 +646,12 @@ glm_quat_slerp(versor from, versor to, float t, versor dest) { CGLM_INLINE void glm_quat_look(vec3 eye, versor ori, mat4 dest) { - CGLM_ALIGN(16) vec4 t; - /* orientation */ glm_quat_mat4t(ori, dest); /* translate */ - glm_vec4(eye, 1.0f, t); - glm_mat4_mulv(dest, t, t); - glm_vec_flipsign_to(t, dest[3]); + glm_mat4_mulv3(dest, eye, 1.0f, dest[3]); + glm_vec_flipsign(dest[3]); } /*! From fc14cedf89a1ce45b47fed6cb772d6e6fe9e2b86 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 9 Jun 2018 18:10:54 +0300 Subject: [PATCH 178/292] update version --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 6e9c00c..af3a0d9 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.4.6], [info@recp.me]) +AC_INIT([cglm], [0.4.7], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index 995e5a2..8bfd1b1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.4.6' +version = u'0.4.7' # The full version, including alpha/beta/rc tags. -release = u'0.4.6' +release = u'0.4.7' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index 370a6a0..6eee580 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 4 -#define CGLM_VERSION_PATCH 6 +#define CGLM_VERSION_PATCH 7 #endif /* cglm_version_h */ From 857265b89230fb8a50e23684fc9618e629b2c15a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 9 Jun 2018 18:21:29 +0300 Subject: [PATCH 179/292] sphere point intersection --- docs/source/sphere.rst | 9 +++++++++ include/cglm/call/sphere.h | 4 ++++ include/cglm/sphere.h | 14 ++++++++++++++ src/sphere.c | 6 ++++++ 4 files changed, 33 insertions(+) diff --git a/docs/source/sphere.rst b/docs/source/sphere.rst index 427200e..db238f4 100644 --- a/docs/source/sphere.rst +++ b/docs/source/sphere.rst @@ -21,6 +21,7 @@ Functions: #. :c:func:`glm_sphere_transform` #. :c:func:`glm_sphere_merge` #. :c:func:`glm_sphere_sphere` +#. :c:func:`glm_sphere_point` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -63,3 +64,11 @@ Functions documentation Parameters: | *[in]* **s1** sphere | *[in]* **s2** other sphere + +.. c:function:: bool glm_sphere_point(vec4 s, vec3 point) + + | check if sphere intersects with point + + Parameters: + | *[in]* **s** sphere + | *[in]* **point** point diff --git a/include/cglm/call/sphere.h b/include/cglm/call/sphere.h index 9a9a59f..02c3d55 100644 --- a/include/cglm/call/sphere.h +++ b/include/cglm/call/sphere.h @@ -29,4 +29,8 @@ CGLM_EXPORT bool glmc_sphere_sphere(vec4 s1, vec4 s2); +CGLM_EXPORT +bool +glmc_sphere_point(vec4 s, vec3 point); + #endif /* cglmc_sphere_h */ diff --git a/include/cglm/sphere.h b/include/cglm/sphere.h index 4c9d79b..a7501b9 100644 --- a/include/cglm/sphere.h +++ b/include/cglm/sphere.h @@ -82,4 +82,18 @@ glm_sphere_sphere(vec4 s1, vec4 s2) { return glm_vec_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]); } +/*! + * @brief check if sphere intersects with point + * + * @param[in] s sphere + * @param[in] point point + */ +CGLM_INLINE +bool +glm_sphere_point(vec4 s, vec3 point) { + float rr; + rr = s[3] * s[3]; + return glm_vec_distance2(point, s) <= rr; +} + #endif /* cglm_sphere_h */ diff --git a/src/sphere.c b/src/sphere.c index e6b46fc..003ef87 100644 --- a/src/sphere.c +++ b/src/sphere.c @@ -31,3 +31,9 @@ bool glmc_sphere_sphere(vec4 s1, vec4 s2) { return glm_sphere_sphere(s1, s2); } + +CGLM_EXPORT +bool +glmc_sphere_point(vec4 s, vec3 point) { + return glm_sphere_point(s, point); +} From 564324f5d21e5d6a93469df503f28061b1bb73bd Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 10 Jun 2018 10:29:02 +0300 Subject: [PATCH 180/292] easing functions --- include/cglm/call.h | 1 + include/cglm/call/ease.h | 140 +++++++++++++++++ include/cglm/cglm.h | 1 + include/cglm/ease.h | 318 +++++++++++++++++++++++++++++++++++++++ src/ease.c | 195 ++++++++++++++++++++++++ 5 files changed, 655 insertions(+) create mode 100644 include/cglm/call/ease.h create mode 100644 include/cglm/ease.h create mode 100644 src/ease.c diff --git a/include/cglm/call.h b/include/cglm/call.h index 77148ac..b7fa6e1 100644 --- a/include/cglm/call.h +++ b/include/cglm/call.h @@ -26,6 +26,7 @@ extern "C" { #include "call/io.h" #include "call/project.h" #include "call/sphere.h" +#include "call/ease.h" #ifdef __cplusplus } diff --git a/include/cglm/call/ease.h b/include/cglm/call/ease.h new file mode 100644 index 0000000..9f1757e --- /dev/null +++ b/include/cglm/call/ease.h @@ -0,0 +1,140 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ease_h +#define cglmc_ease_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +float +glmc_ease_linear(float t); + +CGLM_EXPORT +float +glmc_ease_sine_in(float t); + +CGLM_EXPORT +float +glmc_ease_sine_out(float t); + +CGLM_EXPORT +float +glmc_ease_sine_inout(float t); + +CGLM_EXPORT +float +glmc_ease_quad_in(float t); + +CGLM_EXPORT +float +glmc_ease_quad_out(float t); + +CGLM_EXPORT +float +glmc_ease_quad_inout(float t); + +CGLM_EXPORT +float +glmc_ease_cubic_in(float t); + +CGLM_EXPORT +float +glmc_ease_cubic_out(float t); + +CGLM_EXPORT +float +glmc_ease_cubic_inout(float t); + +CGLM_EXPORT +float +glmc_ease_quart_in(float t); + +CGLM_EXPORT +float +glmc_ease_quart_out(float t); + +CGLM_EXPORT +float +glmc_ease_quart_inout(float t); + +CGLM_EXPORT +float +glmc_ease_quint_in(float t); + +CGLM_EXPORT +float +glmc_ease_quint_out(float t); + +CGLM_EXPORT +float +glmc_ease_quint_inout(float t); + +CGLM_EXPORT +float +glmc_ease_exp_in(float t); + +CGLM_EXPORT +float +glmc_ease_exp_out(float t); + +CGLM_EXPORT +float +glmc_ease_exp_inout(float t); + +CGLM_EXPORT +float +glmc_ease_circ_in(float t); + +CGLM_EXPORT +float +glmc_ease_circ_out(float t); + +CGLM_EXPORT +float +glmc_ease_circ_inout(float t); + +CGLM_EXPORT +float +glmc_ease_back_in(float t); + +CGLM_EXPORT +float +glmc_ease_back_out(float t); + +CGLM_EXPORT +float +glmc_ease_back_inout(float t); + +CGLM_EXPORT +float +glmc_ease_elast_in(float t); + +CGLM_EXPORT +float +glmc_ease_elast_out(float t); + +CGLM_EXPORT +float +glmc_ease_elast_inout(float t); + +CGLM_EXPORT +float +glmc_ease_bounce_out(float t); + +CGLM_EXPORT +float +glmc_ease_bounce_in(float t); + +CGLM_EXPORT +float +glmc_ease_bounce_inout(float t); + +#endif /* cglmc_ease_h */ diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index 720ae08..8b37162 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -25,5 +25,6 @@ #include "io.h" #include "project.h" #include "sphere.h" +#include "ease.h" #endif /* cglm_h */ diff --git a/include/cglm/ease.h b/include/cglm/ease.h new file mode 100644 index 0000000..fca9691 --- /dev/null +++ b/include/cglm/ease.h @@ -0,0 +1,318 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_ease_h +#define cglm_ease_h + +#include "common.h" + +CGLM_INLINE +float +glm_ease_linear(float t) { + return t; +} + +CGLM_INLINE +float +glm_ease_sine_in(float t) { + return sinf((t - 1.0f) * CGLM_PI_2) + 1.0f; +} + +CGLM_INLINE +float +glm_ease_sine_out(float t) { + return sinf(t * CGLM_PI_2); +} + +CGLM_INLINE +float +glm_ease_sine_inout(float t) { + return 0.5f * (1.0f - cosf(t * CGLM_PI)); +} + +CGLM_INLINE +float +glm_ease_quad_in(float t) { + return t * t; +} + +CGLM_INLINE +float +glm_ease_quad_out(float t) { + return -(t * (t - 2.0f)); +} + +CGLM_INLINE +float +glm_ease_quad_inout(float t) { + float tt; + + tt = t * t; + if (t < 0.5f) + return 2.0f * tt; + + return (-2.0f * tt) + (4.0f * t) - 1.0f; +} + +CGLM_INLINE +float +glm_ease_cubic_in(float t) { + return t * t * t; +} + +CGLM_INLINE +float +glm_ease_cubic_out(float t) { + float f; + f = t - 1.0f; + return f * f * f + 1.0f; +} + +CGLM_INLINE +float +glm_ease_cubic_inout(float t) { + float f; + + if (t < 0.5f) + return 4.0f * t * t * t; + + f = 2.0f * t - 2.0f; + + return 0.5f * f * f * f + 1.0f; +} + +CGLM_INLINE +float +glm_ease_quart_in(float t) { + float f; + f = t * t; + return f * f; +} + +CGLM_INLINE +float +glm_ease_quart_out(float t) { + float f; + + f = t - 1.0f; + + return f * f * f * (1.0f - t) + 1.0f; +} + +CGLM_INLINE +float +glm_ease_quart_inout(float t) { + float f, g; + + if (t < 0.5f) { + f = t * t; + return 8.0f * f * f; + } + + f = t - 1.0f; + g = f * f; + + return -8.0f * g * g + 1.0f; +} + +CGLM_INLINE +float +glm_ease_quint_in(float t) { + float f; + f = t * t; + return f * f * t; +} + +CGLM_INLINE +float +glm_ease_quint_out(float t) { + float f, g; + + f = t - 1.0f; + g = f * f; + + return g * g * f + 1.0f; +} + +CGLM_INLINE +float +glm_ease_quint_inout(float t) { + float f, g; + + if (t < 0.5f) { + f = t * t; + return 16.0f * f * f * f; + } + + f = 2.0f * t - 2.0f; + g = f * f; + + return 0.5f * g * g * f + 1.0f; +} + +CGLM_INLINE +float +glm_ease_exp_in(float t) { + float c; + + if (t <= 0.0f) + return t; + + c = t - 1.0f; + + return powf(2.0f, c * 10.0f); +} + +CGLM_INLINE +float +glm_ease_exp_out(float t) { + if (t >= 1.0f) + return t; + + return 1.0f - powf(2.0f, -10.0f * t); +} + +CGLM_INLINE +float +glm_ease_exp_inout(float t) { + if (t < 0.5f) + return 0.5f * powf(2.0f, (20.0f * t) - 10.0f); + + return -0.5f * powf(2.0f, (-20.0f * t) + 10.0f) + 1.0f; +} + +CGLM_INLINE +float +glm_ease_circ_in(float t) { + return 1.0f - sqrtf(1.0f - (t * t)); +} + +CGLM_INLINE +float +glm_ease_circ_out(float t) { + return sqrtf((2.0f - t) * t); +} + +CGLM_INLINE +float +glm_ease_circ_inout(float t) { + if (t < 0.5f) + return 0.5f * (1.0f - sqrtf(1.0f - 4.0f * (t * t))); + + return 0.5f * (sqrtf(-((2.0f * t) - 3.0f) * ((2.0f * t) - 1.0f)) + 1.0f); +} + +CGLM_INLINE +float +glm_ease_back_in(float t) { + float o, z; + + o = 1.70158f; + z = ((o + 1.0f) * t) - o; + + return t * t * z; +} + +CGLM_INLINE +float +glm_ease_back_out(float t) { + float o, z, n; + + o = 1.70158f; + n = t - 1.0f; + z = (o + 1.0f) * n + o; + + return n * n * z + 1.0f; +} + +CGLM_INLINE +float +glm_ease_back_inout(float t) { + float o, z, n, m, s, x; + + o = 1.70158f; + s = o * 1.525f; + x = 0.5; + n = t / 0.5f; + + if (n < 1) { + z = ((s + 1) * n) - s; + m = n * n * z; + return x * m; + } + + n -= 2; + z = ((s + 1) * n) + s; + m = (n * n * z) + 2; + + return x * m; +} + +CGLM_INLINE +float +glm_ease_elast_in(float t) { + return sinf(13.0f * CGLM_PI_2 * t) * powf(2.0f, 10.0f * (t - 1.0f)); +} + +CGLM_INLINE +float +glm_ease_elast_out(float t) { + return sinf(-13.0f * CGLM_PI_2 * (t + 1.0f)) * powf(2.0f, -10.0f * t) + 1.0f; +} + +CGLM_INLINE +float +glm_ease_elast_inout(float t) { + float a; + + a = 2.0f * t; + + if (t < 0.5f) + return 0.5f * sinf(13.0f * CGLM_PI_2 * (a)) + * powf(2.0f, 10.0f * ((a) - 1.0f)); + + return 0.5f * (sinf(-13.0f * CGLM_PI_2 * ((a - 1.0f) + 1.0f)) + * powf(2.0f, -10.0f * (a - 1.0f)) + 2.0f); +} + +CGLM_INLINE +float +glm_ease_bounce_out(float t) { + float tt; + + tt = t * t; + + if (t < (4.0f / 11.0f)) + return (121.0f * tt) / 16.0f; + + if (t < 8.0f / 11.0f) + return ((363.0f / 40.0f) * tt) - ((99.0f / 10.0f) * t) + (17.0f / 5.0f); + + if (t < (9.0f / 10.0f)) + return (4356.0f / 361.0f) * tt + - (35442.0f / 1805.0f) * t + + (16061.0f / 1805.0f); + + return ((54.0f / 5.0f) * tt) - ((513.0f / 25.0f) * t) + (268.0f / 25.0f); +} + +CGLM_INLINE +float +glm_ease_bounce_in(float t) { + return 1.0f - glm_ease_bounce_out(1.0f - t); +} + +CGLM_INLINE +float +glm_ease_bounce_inout(float t) { + if (t < 0.5f) + return 0.5f * (1.0f - glm_ease_bounce_out(t * 2.0f)); + + return 0.5f * glm_ease_bounce_out(t * 2.0f - 1.0f) + 0.5f; +} + +#endif /* cglm_ease_h */ diff --git a/src/ease.c b/src/ease.c new file mode 100644 index 0000000..702dfce --- /dev/null +++ b/src/ease.c @@ -0,0 +1,195 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +float +glmc_ease_linear(float t) { + return glm_ease_linear(t); +} + +CGLM_EXPORT +float +glmc_ease_sine_in(float t) { + return glm_ease_sine_in(t); +} + +CGLM_EXPORT +float +glmc_ease_sine_out(float t) { + return glm_ease_sine_out(t); +} + +CGLM_EXPORT +float +glmc_ease_sine_inout(float t) { + return glm_ease_sine_inout(t); +} + +CGLM_EXPORT +float +glmc_ease_quad_in(float t) { + return glm_ease_quad_in(t); +} + +CGLM_EXPORT +float +glmc_ease_quad_out(float t) { + return glm_ease_quad_out(t); +} + +CGLM_EXPORT +float +glmc_ease_quad_inout(float t) { + return glm_ease_quad_inout(t); +} + +CGLM_EXPORT +float +glmc_ease_cubic_in(float t) { + return glm_ease_cubic_in(t); +} + +CGLM_EXPORT +float +glmc_ease_cubic_out(float t) { + return glm_ease_cubic_out(t); +} + +CGLM_EXPORT +float +glmc_ease_cubic_inout(float t) { + return glm_ease_cubic_inout(t); +} + +CGLM_EXPORT +float +glmc_ease_quart_in(float t) { + return glm_ease_quart_in(t); +} + +CGLM_EXPORT +float +glmc_ease_quart_out(float t) { + return glm_ease_quart_out(t); +} + +CGLM_EXPORT +float +glmc_ease_quart_inout(float t) { + return glm_ease_quart_inout(t); +} + +CGLM_EXPORT +float +glmc_ease_quint_in(float t) { + return glm_ease_quint_in(t); +} + +CGLM_EXPORT +float +glmc_ease_quint_out(float t) { + return glm_ease_quint_out(t); +} + +CGLM_EXPORT +float +glmc_ease_quint_inout(float t) { + return glm_ease_quint_inout(t); +} + +CGLM_EXPORT +float +glmc_ease_exp_in(float t) { + return glm_ease_exp_in(t); +} + +CGLM_EXPORT +float +glmc_ease_exp_out(float t) { + return glm_ease_exp_out(t); +} + +CGLM_EXPORT +float +glmc_ease_exp_inout(float t) { + return glm_ease_exp_inout(t); +} + +CGLM_EXPORT +float +glmc_ease_circ_in(float t) { + return glm_ease_circ_in(t); +} + +CGLM_EXPORT +float +glmc_ease_circ_out(float t) { + return glm_ease_circ_out(t); +} + +CGLM_EXPORT +float +glmc_ease_circ_inout(float t) { + return glm_ease_circ_inout(t); +} + +CGLM_EXPORT +float +glmc_ease_back_in(float t) { + return glm_ease_back_in(t); +} + +CGLM_EXPORT +float +glmc_ease_back_out(float t) { + return glm_ease_back_out(t); +} + +CGLM_EXPORT +float +glmc_ease_back_inout(float t) { + return glm_ease_back_inout(t); +} + +CGLM_EXPORT +float +glmc_ease_elast_in(float t) { + return glm_ease_elast_in(t); +} + +CGLM_EXPORT +float +glmc_ease_elast_out(float t) { + return glm_ease_elast_out(t); +} + +CGLM_EXPORT +float +glmc_ease_elast_inout(float t) { + return glm_ease_elast_inout(t); +} + +CGLM_EXPORT +float +glmc_ease_bounce_out(float t) { + return glm_ease_bounce_out(t); +} + +CGLM_EXPORT +float +glmc_ease_bounce_in(float t) { + return glm_ease_bounce_in(t); +} + +CGLM_EXPORT +float +glmc_ease_bounce_inout(float t) { + return glm_ease_bounce_inout(t); +} From 02f6c67393355b6e76d944e241da27771ccc6341 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 15 Jun 2018 08:55:59 +0300 Subject: [PATCH 181/292] improve easing funcs --- include/cglm/ease.h | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/include/cglm/ease.h b/include/cglm/ease.h index fca9691..30ecf9b 100644 --- a/include/cglm/ease.h +++ b/include/cglm/ease.h @@ -145,7 +145,7 @@ glm_ease_quint_inout(float t) { if (t < 0.5f) { f = t * t; - return 16.0f * f * f * f; + return 16.0f * f * f * t; } f = 2.0f * t - 2.0f; @@ -157,20 +157,16 @@ glm_ease_quint_inout(float t) { CGLM_INLINE float glm_ease_exp_in(float t) { - float c; - - if (t <= 0.0f) + if (t == 0.0f) return t; - c = t - 1.0f; - - return powf(2.0f, c * 10.0f); + return powf(2.0f, 10.0f * (t - 1.0f)); } CGLM_INLINE float glm_ease_exp_out(float t) { - if (t >= 1.0f) + if (t == 1.0f) return t; return 1.0f - powf(2.0f, -10.0f * t); @@ -179,6 +175,9 @@ glm_ease_exp_out(float t) { CGLM_INLINE float glm_ease_exp_inout(float t) { + if (t == 0.0f || t == 1.0f) + return t; + if (t < 0.5f) return 0.5f * powf(2.0f, (20.0f * t) - 10.0f); @@ -239,14 +238,14 @@ glm_ease_back_inout(float t) { x = 0.5; n = t / 0.5f; - if (n < 1) { - z = ((s + 1) * n) - s; + if (n < 1.0f) { + z = (s + 1) * n - s; m = n * n * z; return x * m; } - n -= 2; - z = ((s + 1) * n) + s; + n -= 2.0f; + z = (s + 1.0f) * n + s; m = (n * n * z) + 2; return x * m; @@ -272,10 +271,10 @@ glm_ease_elast_inout(float t) { a = 2.0f * t; if (t < 0.5f) - return 0.5f * sinf(13.0f * CGLM_PI_2 * (a)) - * powf(2.0f, 10.0f * ((a) - 1.0f)); + return 0.5f * sinf(13.0f * CGLM_PI_2 * a) + * powf(2.0f, 10.0f * (a - 1.0f)); - return 0.5f * (sinf(-13.0f * CGLM_PI_2 * ((a - 1.0f) + 1.0f)) + return 0.5f * (sinf(-13.0f * CGLM_PI_2 * a) * powf(2.0f, -10.0f * (a - 1.0f)) + 2.0f); } From 669777eb37eaffd6079ba06893b87ccf1a352183 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 18 Jun 2018 17:55:25 +0300 Subject: [PATCH 182/292] additional utils --- docs/source/util.rst | 35 +++++++++++++++++++++++++++++++++++ include/cglm/util.h | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/docs/source/util.rst b/docs/source/util.rst index f8dbac4..846934f 100644 --- a/docs/source/util.rst +++ b/docs/source/util.rst @@ -136,3 +136,38 @@ Functions documentation Returns: interpolated value + +.. c:function:: bool glm_eq(float a, float b) + + check if two float equal with using EPSILON + + Parameters: + | *[in]* **a** a + | *[in]* **b** b + + Returns: + true if a and b equals + +.. c:function:: float glm_percent(float from, float to, float current) + + percentage of current value between start and end value + + Parameters: + | *[in]* **from** from value + | *[in]* **to** to value + | *[in]* **current** value between from and to values + + Returns: + clamped normalized percent (0-100 in 0-1) + +.. c:function:: float glm_percentc(float from, float to, float current) + + clamped percentage of current value between start and end value + + Parameters: + | *[in]* **from** from value + | *[in]* **to** to value + | *[in]* **current** value between from and to values + + Returns: + clamped normalized percent (0-100 in 0-1) diff --git a/include/cglm/util.h b/include/cglm/util.h index af7514c..7a7b004 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -19,6 +19,7 @@ #define cglm_util_h #include "common.h" +#include /*! * @brief get sign of 32 bit integer as +1, -1, 0 @@ -157,4 +158,44 @@ glm_lerp(float from, float to, float t) { return from + glm_clamp(t, 0.0f, 1.0f) * (to - from); } +/*! + * @brief check if two float equal with using EPSILON + * + * @param[in] a a + * @param[in] b b + */ +CGLM_INLINE +bool +glm_eq(float a, float b) { + return fabsf(a - b) <= FLT_EPSILON; +} + +/*! + * @brief percentage of current value between start and end value + * + * maybe fraction could be alternative name. + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t current value + */ +CGLM_INLINE +float +glm_percent(float from, float to, float current) { + return (current - from) / (to - from); +} + +/*! + * @brief clamped percentage of current value between start and end value + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t current value + */ +CGLM_INLINE +float +glm_percentc(float from, float to, float current) { + return glm_clamp(glm_percent(from, to, current), 0.0f, 1.0f); +} + #endif /* cglm_util_h */ From 3adeac06f88a2cf3c1465c4ddb074ca59f78fc8a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 21 Jun 2018 10:07:51 +0300 Subject: [PATCH 183/292] update build files --- makefile.am | 9 ++++++--- win/cglm.vcxproj | 3 +++ win/cglm.vcxproj.filters | 9 +++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/makefile.am b/makefile.am index 7ee0904..2e9336c 100644 --- a/makefile.am +++ b/makefile.am @@ -56,7 +56,8 @@ cglm_HEADERS = include/cglm/version.h \ include/cglm/box.h \ include/cglm/color.h \ include/cglm/project.h \ - include/cglm/sphere.h + include/cglm/sphere.h \ + include/cglm/ease.h cglm_calldir=$(includedir)/cglm/call cglm_call_HEADERS = include/cglm/call/mat4.h \ @@ -72,7 +73,8 @@ cglm_call_HEADERS = include/cglm/call/mat4.h \ include/cglm/call/frustum.h \ include/cglm/call/box.h \ include/cglm/call/project.h \ - include/cglm/call/sphere.h + include/cglm/call/sphere.h \ + include/cglm/call/ease.h cglm_simddir=$(includedir)/cglm/simd cglm_simd_HEADERS = include/cglm/simd/intrin.h @@ -104,7 +106,8 @@ libcglm_la_SOURCES=\ src/frustum.c \ src/box.c \ src/project.c \ - src/sphere.c + src/sphere.c \ + src/ease.c test_tests_SOURCES=\ test/src/test_common.c \ diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj index 556a24e..5678688 100644 --- a/win/cglm.vcxproj +++ b/win/cglm.vcxproj @@ -23,6 +23,7 @@ + @@ -43,6 +44,7 @@ + @@ -58,6 +60,7 @@ + diff --git a/win/cglm.vcxproj.filters b/win/cglm.vcxproj.filters index cf7634b..5e65853 100644 --- a/win/cglm.vcxproj.filters +++ b/win/cglm.vcxproj.filters @@ -81,6 +81,9 @@ src + + src + @@ -224,5 +227,11 @@ include\cglm + + include\cglm\call + + + include\cglm + \ No newline at end of file From eb8e0df6dfcd6076f6e7472ee5bb3fdb865191cb Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 21 Jun 2018 10:54:53 +0300 Subject: [PATCH 184/292] update version --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index af3a0d9..99b8051 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.4.7], [info@recp.me]) +AC_INIT([cglm], [0.4.8], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index 8bfd1b1..af518fa 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.4.7' +version = u'0.4.8' # The full version, including alpha/beta/rc tags. -release = u'0.4.7' +release = u'0.4.8' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index 6eee580..87515f5 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 4 -#define CGLM_VERSION_PATCH 7 +#define CGLM_VERSION_PATCH 8 #endif /* cglm_version_h */ From c216c0cb7ecbcefe6108c72f45338bd84b348e2e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 26 Jun 2018 15:27:53 +0300 Subject: [PATCH 185/292] add MIN and MAX macros because we could use min/max for intergers too. it may not guarantee that MIN and MAX macros will always be defined by compiler --- include/cglm/util.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/cglm/util.h b/include/cglm/util.h index 7a7b004..d1929f2 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -21,6 +21,9 @@ #include "common.h" #include +#define GLM_MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) +#define GLM_MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) + /*! * @brief get sign of 32 bit integer as +1, -1, 0 * From 5d605ce372c7f559f682eb8ab6b3316f251e8c7d Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 10 Jul 2018 10:54:31 +0300 Subject: [PATCH 186/292] avoid zero division for percent * two value may be same, in this case now returns 1. * to must be >= from and current <= to && current >= from --- include/cglm/util.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/cglm/util.h b/include/cglm/util.h index d1929f2..34be9b9 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -185,7 +185,12 @@ glm_eq(float a, float b) { CGLM_INLINE float glm_percent(float from, float to, float current) { - return (current - from) / (to - from); + float t; + + if ((t = to - from) == 0.0f) + return 1.0f; + + return (current - from) / t; } /*! From c5f5032fcc5b09c89612fcea2205d659328ac95d Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 10 Jul 2018 11:42:18 +0300 Subject: [PATCH 187/292] fix function params docs --- include/cglm/util.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/cglm/util.h b/include/cglm/util.h index 34be9b9..3782af0 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -178,9 +178,9 @@ glm_eq(float a, float b) { * * maybe fraction could be alternative name. * - * @param[in] from from value - * @param[in] to to value - * @param[in] t current value + * @param[in] from from value + * @param[in] to to value + * @param[in] current current value */ CGLM_INLINE float @@ -196,9 +196,9 @@ glm_percent(float from, float to, float current) { /*! * @brief clamped percentage of current value between start and end value * - * @param[in] from from value - * @param[in] to to value - * @param[in] t current value + * @param[in] from from value + * @param[in] to to value + * @param[in] current current value */ CGLM_INLINE float From 43c4d05d4a57e0abbec5a9d1b26638e94375d876 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 12 Jul 2018 11:39:56 +0300 Subject: [PATCH 188/292] new version for clamp: clamp to zero and one --- include/cglm/util.h | 13 ++++++++++++- include/cglm/vec3.h | 2 +- include/cglm/vec4.h | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/cglm/util.h b/include/cglm/util.h index 3782af0..321b152 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -146,6 +146,17 @@ glm_clamp(float val, float minVal, float maxVal) { return glm_min(glm_max(val, minVal), maxVal); } +/*! + * @brief clamp a number to zero and one + * + * @param[in] val value to clamp + */ +CGLM_INLINE +float +glm_clamp_zo(float val) { + return glm_clamp(val, 0.0f, 1.0f); +} + /*! * @brief linear interpolation between two number * @@ -158,7 +169,7 @@ glm_clamp(float val, float minVal, float maxVal) { CGLM_INLINE float glm_lerp(float from, float to, float t) { - return from + glm_clamp(t, 0.0f, 1.0f) * (to - from); + return from + glm_clamp_zo(t) * (to - from); } /*! diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 18d8a7b..fc763a7 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -736,7 +736,7 @@ glm_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) { vec3 s, v; /* from + s * (to - from) */ - glm_vec_broadcast(glm_clamp(t, 0.0f, 1.0f), s); + glm_vec_broadcast(glm_clamp_zo(t), s); glm_vec_sub(to, from, v); glm_vec_mulv(s, v, v); glm_vec_add(from, v, dest); diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 3b3a452..fa9f82c 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -698,7 +698,7 @@ glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) { vec4 s, v; /* from + s * (to - from) */ - glm_vec4_broadcast(glm_clamp(t, 0.0f, 1.0f), s); + glm_vec4_broadcast(glm_clamp_zo(t), s); glm_vec4_sub(to, from, v); glm_vec4_mulv(s, v, v); glm_vec4_add(from, v, dest); From 1d527dc2f00c15ef323939f25dabb82235ad4584 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 14 Jul 2018 12:03:42 +0300 Subject: [PATCH 189/292] unalignned version for vec4_copy --- include/cglm/call/vec4.h | 4 ++++ include/cglm/vec4.h | 15 +++++++++++++++ src/vec4.c | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index adcfc94..729a3f2 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -37,6 +37,10 @@ CGLM_EXPORT void glmc_vec4_copy(vec4 v, vec4 dest); +CGLM_EXPORT +void +glmc_vec4_ucopy(vec4 v, vec4 dest); + CGLM_EXPORT float glmc_vec4_dot(vec4 a, vec4 b); diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index fa9f82c..d8d6b0a 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -120,6 +120,21 @@ glm_vec4_copy(vec4 v, vec4 dest) { #endif } +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] v source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_ucopy(vec4 v, vec4 dest) { + dest[0] = v[0]; + dest[1] = v[1]; + dest[2] = v[2]; + dest[3] = v[3]; +} + /*! * @brief make vector zero * diff --git a/src/vec4.c b/src/vec4.c index fb22796..29ccc4d 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -38,6 +38,12 @@ glmc_vec4_copy(vec4 v, vec4 dest) { glm_vec4_copy(v, dest); } +CGLM_EXPORT +void +glmc_vec4_ucopy(vec4 v, vec4 dest) { + glm_vec4_ucopy(v, dest); +} + CGLM_EXPORT float glmc_vec4_dot(vec4 a, vec4 b) { From 373849992761ff09090a93683e40bdfdbee03059 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 14 Jul 2018 12:12:15 +0300 Subject: [PATCH 190/292] update doc for vec4_ucopy --- docs/source/vec4.rst | 11 +++++++++++ include/cglm/vec4.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index a1b7250..947a2da 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -24,6 +24,7 @@ Functions: 1. :c:func:`glm_vec4` #. :c:func:`glm_vec4_copy3` #. :c:func:`glm_vec4_copy` +#. :c:func:`glm_vec4_ucopy` #. :c:func:`glm_vec4_zero` #. :c:func:`glm_vec4_one` #. :c:func:`glm_vec4_dot` @@ -89,6 +90,16 @@ Functions documentation | *[in]* **v** source | *[in]* **dest** destination +.. c:function:: void glm_vec4_ucopy(vec4 v, vec4 dest) + + copy all members of [a] to [dest] + + | alignment is not required + + Parameters: + | *[in]* **v** source + | *[in]* **dest** destination + .. c:function:: void glm_vec4_zero(vec4 v) makes all members zero diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index d8d6b0a..d0221d4 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -25,6 +25,7 @@ CGLM_INLINE void glm_vec4(vec3 v3, float last, vec4 dest); CGLM_INLINE void glm_vec4_copy3(vec4 a, vec3 dest); CGLM_INLINE void glm_vec4_copy(vec4 v, vec4 dest); + CGLM_INLINE void glm_vec4_ucopy(vec4 v, vec4 dest); CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b); CGLM_INLINE float glm_vec4_norm2(vec4 v); CGLM_INLINE float glm_vec4_norm(vec4 vec); @@ -123,6 +124,8 @@ glm_vec4_copy(vec4 v, vec4 dest) { /*! * @brief copy all members of [a] to [dest] * + * alignment is not required + * * @param[in] v source * @param[out] dest destination */ From 2d63d7e0cd210edee125c686d84c998609779f4a Mon Sep 17 00:00:00 2001 From: Jonathan Platzer Date: Wed, 18 Jul 2018 12:00:46 +0200 Subject: [PATCH 191/292] Fix alignment issue when using AVX --- include/cglm/mat4.h | 2 +- include/cglm/types.h | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index e6e358f..a0a50e7 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -139,7 +139,7 @@ glm_mat4_copy(mat4 mat, mat4 dest) { CGLM_INLINE void glm_mat4_identity(mat4 mat) { - CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; + mat4 t = GLM_MAT4_IDENTITY_INIT; glm_mat4_copy(t, mat); } diff --git a/include/cglm/types.h b/include/cglm/types.h index d470e7b..6fca0fe 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -31,8 +31,14 @@ typedef CGLM_ALIGN_IF(8) float vec3[3]; typedef int ivec3[3]; typedef CGLM_ALIGN_IF(16) float vec4[4]; -typedef vec3 mat3[3]; +#ifdef __AVX__ +typedef CGLM_ALIGN_IF(32) vec3 mat3[3]; +typedef CGLM_ALIGN_IF(32) vec4 mat4[4]; +#else +typedef vec3 mat3[3]; typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; +#endif + typedef vec4 versor; From cc5f533fc924d09771a9c315e03bf73dcea2c462 Mon Sep 17 00:00:00 2001 From: Jonathan Platzer Date: Thu, 19 Jul 2018 10:14:30 +0200 Subject: [PATCH 192/292] Add macro for automatic alignment of matrices --- include/cglm/affine-mat.h | 2 +- include/cglm/affine.h | 8 ++++---- include/cglm/mat3.h | 4 ++-- include/cglm/mat4.h | 2 +- include/cglm/quat.h | 2 +- include/cglm/types.h | 6 ++++++ 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/cglm/affine-mat.h b/include/cglm/affine-mat.h index 62bfce1..1f66776 100644 --- a/include/cglm/affine-mat.h +++ b/include/cglm/affine-mat.h @@ -151,7 +151,7 @@ glm_inv_tr(mat4 mat) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_inv_tr_sse2(mat); #else - CGLM_ALIGN(16) mat3 r; + CGLM_ALIGN_MAT mat3 r; CGLM_ALIGN(16) vec3 t; /* rotate */ diff --git a/include/cglm/affine.h b/include/cglm/affine.h index e8f98bb..dd2f619 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -244,7 +244,7 @@ glm_scale_uni(mat4 m, float s) { CGLM_INLINE void glm_rotate_x(mat4 m, float angle, mat4 dest) { - CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; c = cosf(angle); @@ -269,7 +269,7 @@ glm_rotate_x(mat4 m, float angle, mat4 dest) { CGLM_INLINE void glm_rotate_y(mat4 m, float angle, mat4 dest) { - CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; c = cosf(angle); @@ -294,7 +294,7 @@ glm_rotate_y(mat4 m, float angle, mat4 dest) { CGLM_INLINE void glm_rotate_z(mat4 m, float angle, mat4 dest) { - CGLM_ALIGN(16) mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; c = cosf(angle); @@ -351,7 +351,7 @@ glm_rotate_make(mat4 m, float angle, vec3 axis) { CGLM_INLINE void glm_rotate(mat4 m, float angle, vec3 axis) { - CGLM_ALIGN(16) mat4 rot; + CGLM_ALIGN_MAT mat4 rot; glm_rotate_make(rot, angle, axis); glm_mul_rot(m, rot, m); } diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index f932bce..d0135a4 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -81,7 +81,7 @@ glm_mat3_copy(mat3 mat, mat3 dest) { CGLM_INLINE void glm_mat3_identity(mat3 mat) { - CGLM_ALIGN(16) mat3 t = GLM_MAT3_IDENTITY_INIT; + CGLM_ALIGN_MAT mat3 t = GLM_MAT3_IDENTITY_INIT; glm_mat3_copy(t, mat); } @@ -155,7 +155,7 @@ glm_mat3_transpose_to(mat3 m, mat3 dest) { CGLM_INLINE void glm_mat3_transpose(mat3 m) { - CGLM_ALIGN(16) mat3 tmp; + CGLM_ALIGN_MAT mat3 tmp; tmp[0][1] = m[1][0]; tmp[0][2] = m[2][0]; diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index a0a50e7..4162cd1 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -139,7 +139,7 @@ glm_mat4_copy(mat4 mat, mat4 dest) { CGLM_INLINE void glm_mat4_identity(mat4 mat) { - mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; glm_mat4_copy(t, mat); } diff --git a/include/cglm/quat.h b/include/cglm/quat.h index aa303ca..e97e922 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -742,7 +742,7 @@ glm_quat_rotatev(versor q, vec3 v, vec3 dest) { CGLM_INLINE void glm_quat_rotate(mat4 m, versor q, mat4 dest) { - CGLM_ALIGN(16) mat4 rot; + CGLM_ALIGN_MAT mat4 rot; glm_quat_mat4(q, rot); glm_mul_rot(m, rot, dest); } diff --git a/include/cglm/types.h b/include/cglm/types.h index 6fca0fe..76c3646 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -26,6 +26,12 @@ # define CGLM_ALIGN_IF(X) /* no alignment */ #endif +#ifdef __AVX__ +# define CGLM_ALIGN_MAT CGLM_ALIGN(32) +#else +# define CGLM_ALIGN_MAT CGLM_ALIGN(16) +#endif + typedef float vec2[2]; typedef CGLM_ALIGN_IF(8) float vec3[3]; typedef int ivec3[3]; From 98da3daf82fc37b0c67d2dff1c490610d6a313f0 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 12 Sep 2018 12:44:11 +0300 Subject: [PATCH 193/292] identiy helper for arrays (matrix/quaternion) this helpers makes all array elements identity --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- docs/source/mat3.rst | 9 +++++++++ docs/source/mat4.rst | 9 +++++++++ docs/source/quat.rst | 9 +++++++++ include/cglm/call/mat3.h | 4 ++++ include/cglm/call/mat4.h | 4 ++++ include/cglm/call/quat.h | 4 ++++ include/cglm/mat3.h | 20 ++++++++++++++++++++ include/cglm/mat4.h | 20 ++++++++++++++++++++ include/cglm/quat.h | 19 +++++++++++++++++++ include/cglm/simd/sse2/mat4.h | 4 ++-- include/cglm/version.h | 2 +- src/mat3.c | 6 ++++++ src/mat4.c | 6 ++++++ src/quat.c | 7 ++++++- 16 files changed, 122 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 99b8051..e6d602d 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.4.8], [info@recp.me]) +AC_INIT([cglm], [0.4.9], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index af518fa..704d24e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.4.8' +version = u'0.4.9' # The full version, including alpha/beta/rc tags. -release = u'0.4.8' +release = u'0.4.9' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/source/mat3.rst b/docs/source/mat3.rst index b9f56ee..5d590d9 100644 --- a/docs/source/mat3.rst +++ b/docs/source/mat3.rst @@ -20,6 +20,7 @@ Functions: 1. :c:func:`glm_mat3_copy` #. :c:func:`glm_mat3_identity` +#. :c:func:`glm_mat3_identity_array` #. :c:func:`glm_mat3_mul` #. :c:func:`glm_mat3_transpose_to` #. :c:func:`glm_mat3_transpose` @@ -49,6 +50,14 @@ Functions documentation Parameters: | *[out]* **mat** matrix +.. c:function:: void glm_mat3_identity_array(mat3 * __restrict mat, size_t count) + + make given matrix array's each element identity matrix + + Parameters: + | *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled) + | *[in]* **count** count of matrices + .. c:function:: void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest) multiply m1 and m2 to dest diff --git a/docs/source/mat4.rst b/docs/source/mat4.rst index 7fb0857..ae37147 100644 --- a/docs/source/mat4.rst +++ b/docs/source/mat4.rst @@ -25,6 +25,7 @@ Functions: 1. :c:func:`glm_mat4_ucopy` #. :c:func:`glm_mat4_copy` #. :c:func:`glm_mat4_identity` +#. :c:func:`glm_mat4_identity_array` #. :c:func:`glm_mat4_pick3` #. :c:func:`glm_mat4_pick3t` #. :c:func:`glm_mat4_ins3` @@ -69,6 +70,14 @@ Functions documentation Parameters: | *[out]* **mat** matrix +.. c:function:: void glm_mat4_identity_array(mat4 * __restrict mat, size_t count) + + make given matrix array's each element identity matrix + + Parameters: + | *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled) + | *[in]* **count** count of matrices + .. c:function:: void glm_mat4_pick3(mat4 mat, mat3 dest) copy upper-left of mat4 to mat3 diff --git a/docs/source/quat.rst b/docs/source/quat.rst index d9b4680..caac1bf 100644 --- a/docs/source/quat.rst +++ b/docs/source/quat.rst @@ -27,6 +27,7 @@ Macros: Functions: 1. :c:func:`glm_quat_identity` +#. :c:func:`glm_quat_identity_array` #. :c:func:`glm_quat_init` #. :c:func:`glm_quat` #. :c:func:`glm_quatv` @@ -70,6 +71,14 @@ Functions documentation Parameters: | *[in, out]* **q** quaternion +.. c:function:: void glm_quat_identity_array(versor * __restrict q, size_t count) + + | make given quaternion array's each element identity quaternion + + Parameters: + | *[in, out]* **q** quat array (must be aligned (16) if alignment is not disabled) + | *[in]* **count** count of quaternions + .. c:function:: void glm_quat_init(versor q, float x, float y, float z, float w) | inits quaternion with given values diff --git a/include/cglm/call/mat3.h b/include/cglm/call/mat3.h index 1a92de4..9270113 100644 --- a/include/cglm/call/mat3.h +++ b/include/cglm/call/mat3.h @@ -24,6 +24,10 @@ CGLM_EXPORT void glmc_mat3_identity(mat3 mat); +CGLM_EXPORT +void +glmc_mat3_identity_array(mat3 * __restrict mat, size_t count); + CGLM_EXPORT void glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest); diff --git a/include/cglm/call/mat4.h b/include/cglm/call/mat4.h index ef86682..daa7b7e 100644 --- a/include/cglm/call/mat4.h +++ b/include/cglm/call/mat4.h @@ -29,6 +29,10 @@ CGLM_EXPORT void glmc_mat4_identity(mat4 mat); +CGLM_EXPORT +void +glmc_mat4_identity_array(mat4 * __restrict mat, size_t count); + CGLM_EXPORT void glmc_mat4_pick3(mat4 mat, mat3 dest); diff --git a/include/cglm/call/quat.h b/include/cglm/call/quat.h index ae4c9ef..2778a58 100644 --- a/include/cglm/call/quat.h +++ b/include/cglm/call/quat.h @@ -17,6 +17,10 @@ CGLM_EXPORT void glmc_quat_identity(versor q); +CGLM_EXPORT +void +glmc_quat_identity_array(versor * __restrict q, size_t count); + CGLM_EXPORT void glmc_quat_init(versor q, float x, float y, float z, float w); diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index d0135a4..5d0d6ac 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -16,6 +16,7 @@ Functions: CGLM_INLINE void glm_mat3_copy(mat3 mat, mat3 dest); CGLM_INLINE void glm_mat3_identity(mat3 mat); + CGLM_INLINE void glm_mat3_identity_array(mat3 * restrict mat, size_t count); CGLM_INLINE void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest); CGLM_INLINE void glm_mat3_transpose_to(mat3 m, mat3 dest); CGLM_INLINE void glm_mat3_transpose(mat3 m); @@ -85,6 +86,25 @@ glm_mat3_identity(mat3 mat) { glm_mat3_copy(t, mat); } +/*! + * @brief make given matrix array's each element identity matrix + * + * @param[in, out] mat matrix array (must be aligned (16/32) + * if alignment is not disabled) + * + * @param[in] count count of matrices + */ +CGLM_INLINE +void +glm_mat3_identity_array(mat3 * __restrict mat, size_t count) { + CGLM_ALIGN_MAT mat3 t = GLM_MAT3_IDENTITY_INIT; + size_t i; + + for (i = 0; i < count; i++) { + glm_mat3_copy(t, mat[i]); + } +} + /*! * @brief multiply m1 and m2 to dest * diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 4162cd1..dc8ef88 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -23,6 +23,7 @@ CGLM_INLINE void glm_mat4_ucopy(mat4 mat, mat4 dest); CGLM_INLINE void glm_mat4_copy(mat4 mat, mat4 dest); CGLM_INLINE void glm_mat4_identity(mat4 mat); + CGLM_INLINE void glm_mat4_identity_array(mat4 * restrict mat, size_t count); CGLM_INLINE void glm_mat4_pick3(mat4 mat, mat3 dest); CGLM_INLINE void glm_mat4_pick3t(mat4 mat, mat3 dest); CGLM_INLINE void glm_mat4_ins3(mat3 mat, mat4 dest); @@ -143,6 +144,25 @@ glm_mat4_identity(mat4 mat) { glm_mat4_copy(t, mat); } +/*! + * @brief make given matrix array's each element identity matrix + * + * @param[in, out] mat matrix array (must be aligned (16/32) + * if alignment is not disabled) + * + * @param[in] count count of matrices + */ +CGLM_INLINE +void +glm_mat4_identity_array(mat4 * __restrict mat, size_t count) { + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; + size_t i; + + for (i = 0; i < count; i++) { + glm_mat4_copy(t, mat[i]); + } +} + /*! * @brief copy upper-left of mat4 to mat3 * diff --git a/include/cglm/quat.h b/include/cglm/quat.h index e97e922..289b0ad 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -103,6 +103,25 @@ glm_quat_identity(versor q) { glm_vec4_copy(v, q); } +/*! + * @brief make given quaternion array's each element identity quaternion + * + * @param[in, out] q quat array (must be aligned (16) + * if alignment is not disabled) + * + * @param[in] count count of quaternions + */ +CGLM_INLINE +void +glm_quat_identity_array(versor * __restrict q, size_t count) { + CGLM_ALIGN(16) versor v = GLM_QUAT_IDENTITY_INIT; + size_t i; + + for (i = 0; i < count; i++) { + glm_vec4_copy(v, q[i]); + } +} + /*! * @brief inits quaterion with raw values * diff --git a/include/cglm/simd/sse2/mat4.h b/include/cglm/simd/sse2/mat4.h index c2acb9f..7c87eb5 100644 --- a/include/cglm/simd/sse2/mat4.h +++ b/include/cglm/simd/sse2/mat4.h @@ -16,7 +16,7 @@ CGLM_INLINE void -glm_mat4_scale_sse2(mat4 m, float s){ +glm_mat4_scale_sse2(mat4 m, float s) { __m128 x0; x0 = _mm_set1_ps(s); @@ -28,7 +28,7 @@ glm_mat4_scale_sse2(mat4 m, float s){ CGLM_INLINE void -glm_mat4_transp_sse2(mat4 m, mat4 dest){ +glm_mat4_transp_sse2(mat4 m, mat4 dest) { __m128 r0, r1, r2, r3; r0 = glmm_load(m[0]); diff --git a/include/cglm/version.h b/include/cglm/version.h index 87515f5..7ec929b 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 4 -#define CGLM_VERSION_PATCH 8 +#define CGLM_VERSION_PATCH 9 #endif /* cglm_version_h */ diff --git a/src/mat3.c b/src/mat3.c index 4455b0f..be603e8 100644 --- a/src/mat3.c +++ b/src/mat3.c @@ -20,6 +20,12 @@ glmc_mat3_identity(mat3 mat) { glm_mat3_identity(mat); } +CGLM_EXPORT +void +glmc_mat3_identity_array(mat3 * __restrict mat, size_t count) { + glm_mat3_identity_array(mat, count); +} + CGLM_EXPORT void glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest) { diff --git a/src/mat4.c b/src/mat4.c index 4bca6f7..7bb99e2 100644 --- a/src/mat4.c +++ b/src/mat4.c @@ -26,6 +26,12 @@ glmc_mat4_identity(mat4 mat) { glm_mat4_identity(mat); } +CGLM_EXPORT +void +glmc_mat4_identity_array(mat4 * __restrict mat, size_t count) { + glm_mat4_identity_array(mat, count); +} + CGLM_EXPORT void glmc_mat4_pick3(mat4 mat, mat3 dest) { diff --git a/src/quat.c b/src/quat.c index c47761d..32674a7 100644 --- a/src/quat.c +++ b/src/quat.c @@ -8,13 +8,18 @@ #include "../include/cglm/cglm.h" #include "../include/cglm/call.h" - CGLM_EXPORT void glmc_quat_identity(versor q) { glm_quat_identity(q); } +CGLM_EXPORT +void +glmc_quat_identity_array(versor * __restrict q, size_t count) { + glm_quat_identity_array(q, count); +} + CGLM_EXPORT void glmc_quat_init(versor q, float x, float y, float z, float w) { From d3c50147cb6a8df5ce797cab63da3e956d822c50 Mon Sep 17 00:00:00 2001 From: Carsten Hartenfels Date: Wed, 19 Sep 2018 20:42:05 +0200 Subject: [PATCH 194/292] Replace non-standard M_PI* constants with literals M_PI, M_PI_2 and M_PI_4 aren't part of the C standard. If you put your gcc into strict standards mode, like `-std=c11`, you won't get these constants and including cglm.h will fail. This commit replaces those constants with their literal values. The cast to a float remains, to keep exactly the same behavior as before. --- include/cglm/types.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/cglm/types.h b/include/cglm/types.h index 76c3646..49b65e4 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -48,8 +48,8 @@ typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; typedef vec4 versor; -#define CGLM_PI ((float)M_PI) -#define CGLM_PI_2 ((float)M_PI_2) -#define CGLM_PI_4 ((float)M_PI_4) +#define CGLM_PI ((float)3.14159265358979323846) +#define CGLM_PI_2 ((float)1.57079632679489661923) +#define CGLM_PI_4 ((float)0.78539816339744830962) #endif /* cglm_types_h */ From b00f2b9ccc8a96b8c1b1a84bd93d7e014bc24343 Mon Sep 17 00:00:00 2001 From: Carsten Hartenfels Date: Wed, 19 Sep 2018 20:46:37 +0200 Subject: [PATCH 195/292] Replace M_PI_4 in test_affine with CGLM_PI_4 As in the previous commit, because it's non-standard and depending on your settings it can fail to compile because of it. --- test/src/test_affine.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/src/test_affine.c b/test/src/test_affine.c index a625a30..aebd0ff 100644 --- a/test/src/test_affine.c +++ b/test/src/test_affine.c @@ -12,7 +12,7 @@ test_affine(void **state) { mat4 t1, t2, t3, t4, t5; /* test translate is postmultiplied */ - glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); glm_translate_make(t2, (vec3){34, 57, 36}); glmc_mat4_mul(t1, t2, t3); /* R * T */ @@ -21,16 +21,16 @@ test_affine(void **state) { test_assert_mat4_eq(t1, t3); /* test rotate is postmultiplied */ - glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); glm_translate_make(t2, (vec3){34, 57, 36}); glmc_mat4_mul(t2, t1, t3); /* T * R */ - glm_rotate(t2, M_PI_4, GLM_YUP); + glm_rotate(t2, CGLM_PI_4, GLM_YUP); test_assert_mat4_eq(t2, t3); /* test scale is postmultiplied */ - glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); glm_translate_make(t2, (vec3){34, 57, 36}); glm_scale_make(t4, (vec3){3, 5, 6}); @@ -41,7 +41,7 @@ test_affine(void **state) { test_assert_mat4_eq(t3, t5); /* test translate_x */ - glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); glm_translate_make(t2, (vec3){34, 0, 0}); glmc_mat4_mul(t1, t2, t3); /* R * T */ @@ -49,7 +49,7 @@ test_affine(void **state) { test_assert_mat4_eq(t1, t3); /* test translate_y */ - glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); glm_translate_make(t2, (vec3){0, 57, 0}); glmc_mat4_mul(t1, t2, t3); /* R * T */ @@ -57,7 +57,7 @@ test_affine(void **state) { test_assert_mat4_eq(t1, t3); /* test translate_z */ - glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); glm_translate_make(t2, (vec3){0, 0, 36}); glmc_mat4_mul(t1, t2, t3); /* R * T */ @@ -65,43 +65,43 @@ test_affine(void **state) { test_assert_mat4_eq(t1, t3); /* test rotate_x */ - glmc_rotate_make(t1, M_PI_4, (vec3){1, 0, 0}); + glmc_rotate_make(t1, CGLM_PI_4, (vec3){1, 0, 0}); glm_translate_make(t2, (vec3){34, 57, 36}); glmc_mat4_mul(t2, t1, t3); /* T * R */ - glm_rotate_x(t2, M_PI_4, t2); + glm_rotate_x(t2, CGLM_PI_4, t2); test_assert_mat4_eq(t2, t3); /* test rotate_y */ - glmc_rotate_make(t1, M_PI_4, (vec3){0, 1, 0}); + glmc_rotate_make(t1, CGLM_PI_4, (vec3){0, 1, 0}); glm_translate_make(t2, (vec3){34, 57, 36}); glmc_mat4_mul(t2, t1, t3); /* T * R */ - glm_rotate_y(t2, M_PI_4, t2); + glm_rotate_y(t2, CGLM_PI_4, t2); test_assert_mat4_eq(t2, t3); /* test rotate_z */ - glmc_rotate_make(t1, M_PI_4, (vec3){0, 0, 1}); + glmc_rotate_make(t1, CGLM_PI_4, (vec3){0, 0, 1}); glm_translate_make(t2, (vec3){34, 57, 36}); glmc_mat4_mul(t2, t1, t3); /* T * R */ - glm_rotate_z(t2, M_PI_4, t2); + glm_rotate_z(t2, CGLM_PI_4, t2); test_assert_mat4_eq(t2, t3); /* test rotate */ - glmc_rotate_make(t1, M_PI_4, (vec3){0, 0, 1}); + glmc_rotate_make(t1, CGLM_PI_4, (vec3){0, 0, 1}); glm_translate_make(t2, (vec3){34, 57, 36}); glmc_mat4_mul(t2, t1, t3); /* T * R */ - glmc_rotate(t2, M_PI_4, (vec3){0, 0, 1}); + glmc_rotate(t2, CGLM_PI_4, (vec3){0, 0, 1}); test_assert_mat4_eq(t3, t2); /* test scale_uni */ - glmc_rotate_make(t1, M_PI_4, GLM_YUP); + glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); glm_translate_make(t2, (vec3){34, 57, 36}); glm_scale_make(t4, (vec3){3, 3, 3}); From 59ee8c1fd2a402530231ea6984091804446d1faf Mon Sep 17 00:00:00 2001 From: Carsten Hartenfels Date: Fri, 21 Sep 2018 07:26:55 +0200 Subject: [PATCH 196/292] Use even more precise definitions for pi constants See https://github.com/recp/cglm/pull/61#issuecomment-422955122 --- include/cglm/types.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/cglm/types.h b/include/cglm/types.h index 49b65e4..e9b177c 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -48,8 +48,8 @@ typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; typedef vec4 versor; -#define CGLM_PI ((float)3.14159265358979323846) -#define CGLM_PI_2 ((float)1.57079632679489661923) -#define CGLM_PI_4 ((float)0.78539816339744830962) +#define CGLM_PI ((float)3.14159265358979323846264338327950288) +#define CGLM_PI_2 ((float)1.57079632679489661923132169163975144) +#define CGLM_PI_4 ((float)0.785398163397448309615660845819875721) #endif /* cglm_types_h */ From 3fd12032e60afbe8cf430aafdafcbc160a431e7c Mon Sep 17 00:00:00 2001 From: Carsten Hartenfels Date: Fri, 21 Sep 2018 07:29:54 +0200 Subject: [PATCH 197/292] Clean up pi constants, deprecating the old names GLM_PI* is now used for the double versions, GLM_PI*f for the float versions. The CGLM_ prefixed versions are now deprecated, since that prefix is kinda only used for constants. See https://github.com/recp/cglm/pull/61#issuecomment-423069770 --- include/cglm/types.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/cglm/types.h b/include/cglm/types.h index e9b177c..72852e1 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -48,8 +48,17 @@ typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; typedef vec4 versor; -#define CGLM_PI ((float)3.14159265358979323846264338327950288) -#define CGLM_PI_2 ((float)1.57079632679489661923132169163975144) -#define CGLM_PI_4 ((float)0.785398163397448309615660845819875721) +#define GLM_PI 3.14159265358979323846264338327950288 +#define GLM_PI_2 1.57079632679489661923132169163975144 +#define GLM_PI_4 0.785398163397448309615660845819875721 + +#define GLM_PIf ((float)GLM_PI) +#define GLM_PI_2f ((float)GLM_PI_2) +#define GLM_PI_4f ((float)GLM_PI_4) + +/* DEPRECATED! use GLM_PI and friends */ +#define CGLM_PI GLM_PIf +#define CGLM_PI_2 GLM_PI_2f +#define CGLM_PI_4 GLM_PI_4f #endif /* cglm_types_h */ From b9021978cb1628de4f5b15d4ff4dc08482e2f8df Mon Sep 17 00:00:00 2001 From: Carsten Hartenfels Date: Fri, 21 Sep 2018 07:34:05 +0200 Subject: [PATCH 198/292] Replace the use of deprecated CGLM_PI* constants --- include/cglm/cam.h | 2 +- include/cglm/ease.h | 14 +++++++------- include/cglm/euler.h | 4 ++-- include/cglm/quat.h | 2 +- include/cglm/util.h | 8 ++++---- test/src/test_affine.c | 32 ++++++++++++++++---------------- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 6e5fc16..6ce5754 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -293,7 +293,7 @@ CGLM_INLINE void glm_perspective_default(float aspect, mat4 dest) { - glm_perspective((float)CGLM_PI_4, + glm_perspective(GLM_PI_4f, aspect, 0.01f, 100.0f, diff --git a/include/cglm/ease.h b/include/cglm/ease.h index 30ecf9b..b40b75e 100644 --- a/include/cglm/ease.h +++ b/include/cglm/ease.h @@ -19,19 +19,19 @@ glm_ease_linear(float t) { CGLM_INLINE float glm_ease_sine_in(float t) { - return sinf((t - 1.0f) * CGLM_PI_2) + 1.0f; + return sinf((t - 1.0f) * GLM_PI_2f) + 1.0f; } CGLM_INLINE float glm_ease_sine_out(float t) { - return sinf(t * CGLM_PI_2); + return sinf(t * GLM_PI_2f); } CGLM_INLINE float glm_ease_sine_inout(float t) { - return 0.5f * (1.0f - cosf(t * CGLM_PI)); + return 0.5f * (1.0f - cosf(t * GLM_PIf)); } CGLM_INLINE @@ -254,13 +254,13 @@ glm_ease_back_inout(float t) { CGLM_INLINE float glm_ease_elast_in(float t) { - return sinf(13.0f * CGLM_PI_2 * t) * powf(2.0f, 10.0f * (t - 1.0f)); + return sinf(13.0f * GLM_PI_2f * t) * powf(2.0f, 10.0f * (t - 1.0f)); } CGLM_INLINE float glm_ease_elast_out(float t) { - return sinf(-13.0f * CGLM_PI_2 * (t + 1.0f)) * powf(2.0f, -10.0f * t) + 1.0f; + return sinf(-13.0f * GLM_PI_2f * (t + 1.0f)) * powf(2.0f, -10.0f * t) + 1.0f; } CGLM_INLINE @@ -271,10 +271,10 @@ glm_ease_elast_inout(float t) { a = 2.0f * t; if (t < 0.5f) - return 0.5f * sinf(13.0f * CGLM_PI_2 * a) + return 0.5f * sinf(13.0f * GLM_PI_2f * a) * powf(2.0f, 10.0f * (a - 1.0f)); - return 0.5f * (sinf(-13.0f * CGLM_PI_2 * a) + return 0.5f * (sinf(-13.0f * GLM_PI_2f * a) * powf(2.0f, -10.0f * (a - 1.0f)) + 2.0f); } diff --git a/include/cglm/euler.h b/include/cglm/euler.h index bb455a8..1ff5f6d 100644 --- a/include/cglm/euler.h +++ b/include/cglm/euler.h @@ -84,12 +84,12 @@ glm_euler_angles(mat4 m, vec3 dest) { thetaZ = atan2f(-m10, m00); } else { /* m20 == -1 */ /* Not a unique solution */ - thetaY = -CGLM_PI_2; + thetaY = -GLM_PI_2f; thetaX = -atan2f(m01, m11); thetaZ = 0.0f; } } else { /* m20 == +1 */ - thetaY = CGLM_PI_2; + thetaY = GLM_PI_2f; thetaX = atan2f(m01, m11); thetaZ = 0.0f; } diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 289b0ad..d07db8e 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -689,7 +689,7 @@ glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) { dot = glm_vec_dot(dir, fwd); if (fabsf(dot + 1.0f) < 0.000001f) { - glm_quat_init(dest, up[0], up[1], up[2], CGLM_PI); + glm_quat_init(dest, up[0], up[1], up[2], GLM_PIf); return; } diff --git a/include/cglm/util.h b/include/cglm/util.h index 321b152..af73eb8 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -58,7 +58,7 @@ glm_signf(float val) { CGLM_INLINE float glm_rad(float deg) { - return deg * CGLM_PI / 180.0f; + return deg * GLM_PIf / 180.0f; } /*! @@ -69,7 +69,7 @@ glm_rad(float deg) { CGLM_INLINE float glm_deg(float rad) { - return rad * 180.0f / CGLM_PI; + return rad * 180.0f / GLM_PIf; } /*! @@ -80,7 +80,7 @@ glm_deg(float rad) { CGLM_INLINE void glm_make_rad(float *deg) { - *deg = *deg * CGLM_PI / 180.0f; + *deg = *deg * GLM_PIf / 180.0f; } /*! @@ -91,7 +91,7 @@ glm_make_rad(float *deg) { CGLM_INLINE void glm_make_deg(float *rad) { - *rad = *rad * 180.0f / CGLM_PI; + *rad = *rad * 180.0f / GLM_PIf; } /*! diff --git a/test/src/test_affine.c b/test/src/test_affine.c index aebd0ff..bb1be15 100644 --- a/test/src/test_affine.c +++ b/test/src/test_affine.c @@ -12,7 +12,7 @@ test_affine(void **state) { mat4 t1, t2, t3, t4, t5; /* test translate is postmultiplied */ - glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); + glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP); glm_translate_make(t2, (vec3){34, 57, 36}); glmc_mat4_mul(t1, t2, t3); /* R * T */ @@ -21,16 +21,16 @@ test_affine(void **state) { test_assert_mat4_eq(t1, t3); /* test rotate is postmultiplied */ - glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); + glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP); glm_translate_make(t2, (vec3){34, 57, 36}); glmc_mat4_mul(t2, t1, t3); /* T * R */ - glm_rotate(t2, CGLM_PI_4, GLM_YUP); + glm_rotate(t2, GLM_PI_4f, GLM_YUP); test_assert_mat4_eq(t2, t3); /* test scale is postmultiplied */ - glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); + glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP); glm_translate_make(t2, (vec3){34, 57, 36}); glm_scale_make(t4, (vec3){3, 5, 6}); @@ -41,7 +41,7 @@ test_affine(void **state) { test_assert_mat4_eq(t3, t5); /* test translate_x */ - glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); + glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP); glm_translate_make(t2, (vec3){34, 0, 0}); glmc_mat4_mul(t1, t2, t3); /* R * T */ @@ -49,7 +49,7 @@ test_affine(void **state) { test_assert_mat4_eq(t1, t3); /* test translate_y */ - glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); + glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP); glm_translate_make(t2, (vec3){0, 57, 0}); glmc_mat4_mul(t1, t2, t3); /* R * T */ @@ -57,7 +57,7 @@ test_affine(void **state) { test_assert_mat4_eq(t1, t3); /* test translate_z */ - glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); + glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP); glm_translate_make(t2, (vec3){0, 0, 36}); glmc_mat4_mul(t1, t2, t3); /* R * T */ @@ -65,43 +65,43 @@ test_affine(void **state) { test_assert_mat4_eq(t1, t3); /* test rotate_x */ - glmc_rotate_make(t1, CGLM_PI_4, (vec3){1, 0, 0}); + glmc_rotate_make(t1, GLM_PI_4f, (vec3){1, 0, 0}); glm_translate_make(t2, (vec3){34, 57, 36}); glmc_mat4_mul(t2, t1, t3); /* T * R */ - glm_rotate_x(t2, CGLM_PI_4, t2); + glm_rotate_x(t2, GLM_PI_4f, t2); test_assert_mat4_eq(t2, t3); /* test rotate_y */ - glmc_rotate_make(t1, CGLM_PI_4, (vec3){0, 1, 0}); + glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 1, 0}); glm_translate_make(t2, (vec3){34, 57, 36}); glmc_mat4_mul(t2, t1, t3); /* T * R */ - glm_rotate_y(t2, CGLM_PI_4, t2); + glm_rotate_y(t2, GLM_PI_4f, t2); test_assert_mat4_eq(t2, t3); /* test rotate_z */ - glmc_rotate_make(t1, CGLM_PI_4, (vec3){0, 0, 1}); + glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 0, 1}); glm_translate_make(t2, (vec3){34, 57, 36}); glmc_mat4_mul(t2, t1, t3); /* T * R */ - glm_rotate_z(t2, CGLM_PI_4, t2); + glm_rotate_z(t2, GLM_PI_4f, t2); test_assert_mat4_eq(t2, t3); /* test rotate */ - glmc_rotate_make(t1, CGLM_PI_4, (vec3){0, 0, 1}); + glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 0, 1}); glm_translate_make(t2, (vec3){34, 57, 36}); glmc_mat4_mul(t2, t1, t3); /* T * R */ - glmc_rotate(t2, CGLM_PI_4, (vec3){0, 0, 1}); + glmc_rotate(t2, GLM_PI_4f, (vec3){0, 0, 1}); test_assert_mat4_eq(t3, t2); /* test scale_uni */ - glmc_rotate_make(t1, CGLM_PI_4, GLM_YUP); + glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP); glm_translate_make(t2, (vec3){34, 57, 36}); glm_scale_make(t4, (vec3){3, 3, 3}); From eefafefbae6a95ac1397dc0e9ecb3cde865b1f46 Mon Sep 17 00:00:00 2001 From: Carsten Hartenfels Date: Fri, 21 Sep 2018 20:03:28 +0200 Subject: [PATCH 199/292] Also add a load of other number constants These are all missing from standard C, so we might as well define em. See https://github.com/recp/cglm/pull/61#discussion_r219406859 --- include/cglm/types.h | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/include/cglm/types.h b/include/cglm/types.h index 72852e1..548965d 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -48,13 +48,33 @@ typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; typedef vec4 versor; -#define GLM_PI 3.14159265358979323846264338327950288 -#define GLM_PI_2 1.57079632679489661923132169163975144 -#define GLM_PI_4 0.785398163397448309615660845819875721 +#define GLM_E 2.71828182845904523536028747135266250 /* e */ +#define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */ +#define GLM_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */ +#define GLM_LN2 0.693147180559945309417232121458176568 /* loge(2) */ +#define GLM_LN10 2.30258509299404568401799145468436421 /* loge(10) */ +#define GLM_PI 3.14159265358979323846264338327950288 /* pi */ +#define GLM_PI_2 1.57079632679489661923132169163975144 /* pi/2 */ +#define GLM_PI_4 0.785398163397448309615660845819875721 /* pi/4 */ +#define GLM_1_PI 0.318309886183790671537767526745028724 /* 1/pi */ +#define GLM_2_PI 0.636619772367581343075535053490057448 /* 2/pi */ +#define GLM_2_SQRTPI 1.12837916709551257389615890312154517 /* 2/sqrt(pi) */ +#define GLM_SQRT2 1.41421356237309504880168872420969808 /* sqrt(2) */ +#define GLM_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */ -#define GLM_PIf ((float)GLM_PI) -#define GLM_PI_2f ((float)GLM_PI_2) -#define GLM_PI_4f ((float)GLM_PI_4) +#define GLM_Ef ((float) GLM_E) +#define GLM_LOG2Ef ((float) GLM_LOG2E) +#define GLM_LOG10Ef ((float) GLM_LOG10E) +#define GLM_LN2f ((float) GLM_LN2) +#define GLM_LN10f ((float) GLM_LN10) +#define GLM_PIf ((float) GLM_PI) +#define GLM_PI_2f ((float) GLM_PI_2) +#define GLM_PI_4f ((float) GLM_PI_4) +#define GLM_1_PIf ((float) GLM_1_PI) +#define GLM_2_PIf ((float) GLM_2_PI) +#define GLM_2_SQRTPIf ((float) GLM_2_SQRTPI) +#define GLM_SQRT2f ((float) GLM_SQRT2) +#define GLM_SQRT1_2f ((float) GLM_SQRT1_2) /* DEPRECATED! use GLM_PI and friends */ #define CGLM_PI GLM_PIf From 7405d5e1d0be0305b21b0a31515f2d72fd6aca97 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 21 Sep 2018 23:33:42 +0300 Subject: [PATCH 200/292] Update types.h --- include/cglm/types.h | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/include/cglm/types.h b/include/cglm/types.h index 548965d..208d79a 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -45,7 +45,6 @@ typedef vec3 mat3[3]; typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; #endif - typedef vec4 versor; #define GLM_E 2.71828182845904523536028747135266250 /* e */ @@ -62,23 +61,23 @@ typedef vec4 versor; #define GLM_SQRT2 1.41421356237309504880168872420969808 /* sqrt(2) */ #define GLM_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */ -#define GLM_Ef ((float) GLM_E) -#define GLM_LOG2Ef ((float) GLM_LOG2E) -#define GLM_LOG10Ef ((float) GLM_LOG10E) -#define GLM_LN2f ((float) GLM_LN2) -#define GLM_LN10f ((float) GLM_LN10) -#define GLM_PIf ((float) GLM_PI) -#define GLM_PI_2f ((float) GLM_PI_2) -#define GLM_PI_4f ((float) GLM_PI_4) -#define GLM_1_PIf ((float) GLM_1_PI) -#define GLM_2_PIf ((float) GLM_2_PI) -#define GLM_2_SQRTPIf ((float) GLM_2_SQRTPI) -#define GLM_SQRT2f ((float) GLM_SQRT2) -#define GLM_SQRT1_2f ((float) GLM_SQRT1_2) +#define GLM_Ef ((float)GLM_E) +#define GLM_LOG2Ef ((float)GLM_LOG2E) +#define GLM_LOG10Ef ((float)GLM_LOG10E) +#define GLM_LN2f ((float)GLM_LN2) +#define GLM_LN10f ((float)GLM_LN10) +#define GLM_PIf ((float)GLM_PI) +#define GLM_PI_2f ((float)GLM_PI_2) +#define GLM_PI_4f ((float)GLM_PI_4) +#define GLM_1_PIf ((float)GLM_1_PI) +#define GLM_2_PIf ((float)GLM_2_PI) +#define GLM_2_SQRTPIf ((float)GLM_2_SQRTPI) +#define GLM_SQRT2f ((float)GLM_SQRT2) +#define GLM_SQRT1_2f ((float)GLM_SQRT1_2) /* DEPRECATED! use GLM_PI and friends */ -#define CGLM_PI GLM_PIf -#define CGLM_PI_2 GLM_PI_2f -#define CGLM_PI_4 GLM_PI_4f +#define CGLM_PI GLM_PIf +#define CGLM_PI_2 GLM_PI_2f +#define CGLM_PI_4 GLM_PI_4f #endif /* cglm_types_h */ From aa2b0f26317f681c5038d36ae854ff2159085aaa Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 22 Sep 2018 00:10:50 +0300 Subject: [PATCH 201/292] code style and minor optimization[s] --- include/cglm/cam.h | 33 ++++++++------------------------- include/cglm/io.h | 12 ++++++------ include/cglm/types.h | 26 +++++++++++++------------- 3 files changed, 27 insertions(+), 44 deletions(-) diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 6ce5754..1360c81 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -198,26 +198,15 @@ glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) { */ CGLM_INLINE void -glm_ortho_default(float aspect, - mat4 dest) { +glm_ortho_default(float aspect, mat4 dest) { if (aspect >= 1.0f) { - glm_ortho(-1.0f * aspect, - 1.0f * aspect, - -1.0f, - 1.0f, - -100.0f, - 100.0f, - dest); + glm_ortho(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest); return; } - glm_ortho(-1.0f, - 1.0f, - -1.0f / aspect, - 1.0f / aspect, - -100.0f, - 100.0f, - dest); + aspect = 1.0f / aspect; + + glm_ortho(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest); } /*! @@ -291,13 +280,8 @@ glm_perspective(float fovy, */ CGLM_INLINE void -glm_perspective_default(float aspect, - mat4 dest) { - glm_perspective(GLM_PI_4f, - aspect, - 0.01f, - 100.0f, - dest); +glm_perspective_default(float aspect, mat4 dest) { + glm_perspective(GLM_PI_4f, aspect, 0.01f, 100.0f, dest); } /*! @@ -310,8 +294,7 @@ glm_perspective_default(float aspect, */ CGLM_INLINE void -glm_perspective_resize(float aspect, - mat4 proj) { +glm_perspective_resize(float aspect, mat4 proj) { if (proj[0][0] == 0.0f) return; diff --git a/include/cglm/io.h b/include/cglm/io.h index f38fad7..ac0bfeb 100644 --- a/include/cglm/io.h +++ b/include/cglm/io.h @@ -25,7 +25,7 @@ CGLM_INLINE void -glm_mat4_print(mat4 matrix, +glm_mat4_print(mat4 matrix, FILE * __restrict ostream) { int i; int j; @@ -55,7 +55,7 @@ glm_mat4_print(mat4 matrix, CGLM_INLINE void -glm_mat3_print(mat3 matrix, +glm_mat3_print(mat3 matrix, FILE * __restrict ostream) { int i; int j; @@ -85,7 +85,7 @@ glm_mat3_print(mat3 matrix, CGLM_INLINE void -glm_vec4_print(vec4 vec, +glm_vec4_print(vec4 vec, FILE * __restrict ostream) { int i; @@ -107,7 +107,7 @@ glm_vec4_print(vec4 vec, CGLM_INLINE void -glm_vec3_print(vec3 vec, +glm_vec3_print(vec3 vec, FILE * __restrict ostream) { int i; @@ -129,7 +129,7 @@ glm_vec3_print(vec3 vec, CGLM_INLINE void -glm_ivec3_print(ivec3 vec, +glm_ivec3_print(ivec3 vec, FILE * __restrict ostream) { int i; @@ -151,7 +151,7 @@ glm_ivec3_print(ivec3 vec, CGLM_INLINE void -glm_versor_print(versor vec, +glm_versor_print(versor vec, FILE * __restrict ostream) { int i; diff --git a/include/cglm/types.h b/include/cglm/types.h index 208d79a..cad1042 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -47,19 +47,19 @@ typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; typedef vec4 versor; -#define GLM_E 2.71828182845904523536028747135266250 /* e */ -#define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */ -#define GLM_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */ -#define GLM_LN2 0.693147180559945309417232121458176568 /* loge(2) */ -#define GLM_LN10 2.30258509299404568401799145468436421 /* loge(10) */ -#define GLM_PI 3.14159265358979323846264338327950288 /* pi */ -#define GLM_PI_2 1.57079632679489661923132169163975144 /* pi/2 */ -#define GLM_PI_4 0.785398163397448309615660845819875721 /* pi/4 */ -#define GLM_1_PI 0.318309886183790671537767526745028724 /* 1/pi */ -#define GLM_2_PI 0.636619772367581343075535053490057448 /* 2/pi */ -#define GLM_2_SQRTPI 1.12837916709551257389615890312154517 /* 2/sqrt(pi) */ -#define GLM_SQRT2 1.41421356237309504880168872420969808 /* sqrt(2) */ -#define GLM_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */ +#define GLM_E 2.71828182845904523536028747135266250 /* e */ +#define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */ +#define GLM_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */ +#define GLM_LN2 0.693147180559945309417232121458176568 /* loge(2) */ +#define GLM_LN10 2.30258509299404568401799145468436421 /* loge(10) */ +#define GLM_PI 3.14159265358979323846264338327950288 /* pi */ +#define GLM_PI_2 1.57079632679489661923132169163975144 /* pi/2 */ +#define GLM_PI_4 0.785398163397448309615660845819875721 /* pi/4 */ +#define GLM_1_PI 0.318309886183790671537767526745028724 /* 1/pi */ +#define GLM_2_PI 0.636619772367581343075535053490057448 /* 2/pi */ +#define GLM_2_SQRTPI 1.12837916709551257389615890312154517 /* 2/sqrt(pi) */ +#define GLM_SQRT2 1.41421356237309504880168872420969808 /* sqrt(2) */ +#define GLM_SQRT1_2 0.707106781186547524400844362104849039 /* 1/sqrt(2) */ #define GLM_Ef ((float)GLM_E) #define GLM_LOG2Ef ((float)GLM_LOG2E) From 20360f22965e80176dbb6931e727eb6f41fa9796 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 12 Oct 2018 09:05:42 +0300 Subject: [PATCH 202/292] avx: replace binary constants with hex --- include/cglm/cam.h | 4 ++-- include/cglm/simd/avx/affine.h | 7 ++++--- include/cglm/simd/avx/mat4.h | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 1360c81..284ae82 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -201,7 +201,7 @@ void glm_ortho_default(float aspect, mat4 dest) { if (aspect >= 1.0f) { glm_ortho(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest); - return; + return; } aspect = 1.0f / aspect; @@ -229,7 +229,7 @@ glm_ortho_default_s(float aspect, -size - 100.0f, size + 100.0f, dest); - return; + return; } glm_ortho(-size, diff --git a/include/cglm/simd/avx/affine.h b/include/cglm/simd/avx/affine.h index 5c7f71c..369bcf7 100644 --- a/include/cglm/simd/avx/affine.h +++ b/include/cglm/simd/avx/affine.h @@ -27,13 +27,14 @@ glm_mul_avx(mat4 m1, mat4 m2, mat4 dest) { y2 = glmm_load256(m1[0]); /* h g f e d c b a */ y3 = glmm_load256(m1[2]); /* p o n m l k j i */ - y4 = _mm256_permute2f128_ps(y2, y2, 0b00000011); /* d c b a h g f e */ - y5 = _mm256_permute2f128_ps(y3, y3, 0b00000000); /* l k j i l k j i */ + /* 0x03: 0b00000011 */ + y4 = _mm256_permute2f128_ps(y2, y2, 0x03); /* d c b a h g f e */ + y5 = _mm256_permute2f128_ps(y3, y3, 0x03); /* l k j i l k j i */ /* f f f f a a a a */ /* g g g g c c c c */ /* e e e e b b b b */ - y7 = _mm256_permute_ps(y0, 0b10101010); + y7 = _mm256_permute_ps(y0, 0xAA); /* 0xAA: 0b10101010 */ y6 = _mm256_permutevar_ps(y0, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); y8 = _mm256_permutevar_ps(y0, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); diff --git a/include/cglm/simd/avx/mat4.h b/include/cglm/simd/avx/mat4.h index b5859a7..944769b 100644 --- a/include/cglm/simd/avx/mat4.h +++ b/include/cglm/simd/avx/mat4.h @@ -27,8 +27,9 @@ glm_mat4_mul_avx(mat4 m1, mat4 m2, mat4 dest) { y2 = glmm_load256(m1[0]); /* h g f e d c b a */ y3 = glmm_load256(m1[2]); /* p o n m l k j i */ - y4 = _mm256_permute2f128_ps(y2, y2, 0b00000011); /* d c b a h g f e */ - y5 = _mm256_permute2f128_ps(y3, y3, 0b00000011); /* l k j i p o n m */ + /* 0x03: 0b00000011 */ + y4 = _mm256_permute2f128_ps(y2, y2, 0x03); /* d c b a h g f e */ + y5 = _mm256_permute2f128_ps(y3, y3, 0x03); /* l k j i p o n m */ /* f f f f a a a a */ /* h h h h c c c c */ From dadae4b773b01e1713b01f0c16180e2302568d49 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 19 Oct 2018 09:40:40 +0300 Subject: [PATCH 203/292] avx: fix glm_mul_avx * use glm_mat4_mul_avx here. because it seems there is no big difference for now. --- include/cglm/simd/avx/affine.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/include/cglm/simd/avx/affine.h b/include/cglm/simd/avx/affine.h index 369bcf7..b02ff0c 100644 --- a/include/cglm/simd/avx/affine.h +++ b/include/cglm/simd/avx/affine.h @@ -29,20 +29,22 @@ glm_mul_avx(mat4 m1, mat4 m2, mat4 dest) { /* 0x03: 0b00000011 */ y4 = _mm256_permute2f128_ps(y2, y2, 0x03); /* d c b a h g f e */ - y5 = _mm256_permute2f128_ps(y3, y3, 0x03); /* l k j i l k j i */ + y5 = _mm256_permute2f128_ps(y3, y3, 0x03); /* l k j i p o n m */ /* f f f f a a a a */ - /* g g g g c c c c */ + /* h h h h c c c c */ /* e e e e b b b b */ - y7 = _mm256_permute_ps(y0, 0xAA); /* 0xAA: 0b10101010 */ + /* g g g g d d d d */ y6 = _mm256_permutevar_ps(y0, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); + y7 = _mm256_permutevar_ps(y0, _mm256_set_epi32(3, 3, 3, 3, 2, 2, 2, 2)); y8 = _mm256_permutevar_ps(y0, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); + y9 = _mm256_permutevar_ps(y0, _mm256_set_epi32(2, 2, 2, 2, 3, 3, 3, 3)); glmm_store256(dest[0], _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), - _mm256_mul_ps(y4, y8)), - _mm256_mul_ps(y5, y7))); - + _mm256_mul_ps(y3, y7)), + _mm256_add_ps(_mm256_mul_ps(y4, y8), + _mm256_mul_ps(y5, y9)))); /* n n n n i i i i */ /* p p p p k k k k */ From 20a23123515332e8e2b7b9152c5e6e5e0e291a4b Mon Sep 17 00:00:00 2001 From: Colin MacKenzie IV Date: Fri, 16 Nov 2018 19:25:44 -0500 Subject: [PATCH 204/292] fix versor alignment --- include/cglm/quat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index d07db8e..c544f0d 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -286,7 +286,7 @@ glm_quat_conjugate(versor q, versor dest) { CGLM_INLINE void glm_quat_inv(versor q, versor dest) { - CGLM_ALIGN(8) versor conj; + CGLM_ALIGN(16) versor conj; glm_quat_conjugate(q, conj); glm_vec4_scale(conj, 1.0f / glm_vec4_norm2(q), dest); } From a7cdbcec2b08d806ef4c72017c6ac017d88bb415 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 17 Nov 2018 22:31:51 +0300 Subject: [PATCH 205/292] now working on v0.5.0 --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index e6d602d..6d878d7 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.4.9], [info@recp.me]) +AC_INIT([cglm], [0.5.0], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index 704d24e..5ce0313 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.4.9' +version = u'0.5.0' # The full version, including alpha/beta/rc tags. -release = u'0.4.9' +release = u'0.5.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index 7ec929b..d76d84f 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -9,7 +9,7 @@ #define cglm_version_h #define CGLM_VERSION_MAJOR 0 -#define CGLM_VERSION_MINOR 4 -#define CGLM_VERSION_PATCH 9 +#define CGLM_VERSION_MINOR 5 +#define CGLM_VERSION_PATCH 0 #endif /* cglm_version_h */ From 463099350ac160f70e87ad5e10eba7fc2c35879b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 28 Nov 2018 10:28:00 +0300 Subject: [PATCH 206/292] vec: use `_negate` instead of `_flipsign` and `_inv` * negate is better and common name, flipsign is deprecated now. --- docs/source/vec3.rst | 17 ++++++++++++ include/cglm/affine-mat.h | 2 +- include/cglm/affine.h | 6 ++--- include/cglm/call/vec3.h | 8 ++++++ include/cglm/quat.h | 6 ++--- include/cglm/vec3.h | 55 +++++++++++++++++++++++++++++++++------ src/vec3.c | 12 +++++++++ 7 files changed, 91 insertions(+), 15 deletions(-) diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index e4a2746..252c8f5 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -52,6 +52,8 @@ Functions: #. :c:func:`glm_vec_muladds` #. :c:func:`glm_vec_flipsign` #. :c:func:`glm_vec_flipsign_to` +#. :c:func:`glm_vec_negate` +#. :c:func:`glm_vec_negate_to` #. :c:func:`glm_vec_inv` #. :c:func:`glm_vec_inv_to` #. :c:func:`glm_vec_normalize` @@ -281,6 +283,21 @@ Functions documentation | *[in]* **v** vector | *[out]* **dest** negated vector +.. c:function:: void glm_vec_negate(vec3 v) + + negate vector components + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec_negate_to(vec3 v, vec3 dest) + + negate vector components and store result in dest + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** negated vector + .. c:function:: void glm_vec_inv(vec3 v) make vector as inverse/opposite of itself diff --git a/include/cglm/affine-mat.h b/include/cglm/affine-mat.h index 1f66776..d26857b 100644 --- a/include/cglm/affine-mat.h +++ b/include/cglm/affine-mat.h @@ -160,7 +160,7 @@ glm_inv_tr(mat4 mat) { /* translate */ glm_mat3_mulv(r, mat[3], t); - glm_vec_flipsign(t); + glm_vec_negate(t); glm_vec_copy(t, mat[3]); #endif } diff --git a/include/cglm/affine.h b/include/cglm/affine.h index dd2f619..4c0e1e9 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -370,7 +370,7 @@ void glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) { CGLM_ALIGN(8) vec3 pivotInv; - glm_vec_inv_to(pivot, pivotInv); + glm_vec_negate_to(pivot, pivotInv); glm_translate(m, pivot); glm_rotate(m, angle, axis); @@ -395,7 +395,7 @@ void glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) { CGLM_ALIGN(8) vec3 pivotInv; - glm_vec_inv_to(pivot, pivotInv); + glm_vec_negate_to(pivot, pivotInv); glm_translate_make(m, pivot); glm_rotate(m, angle, axis); @@ -467,7 +467,7 @@ glm_decompose_rs(mat4 m, mat4 r, vec3 s) { glm_vec4_flipsign(r[0]); glm_vec4_flipsign(r[1]); glm_vec4_flipsign(r[2]); - glm_vec_flipsign(s); + glm_vec_negate(s); } } diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index ae21620..d96de98 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -116,6 +116,14 @@ CGLM_EXPORT void glmc_vec_flipsign_to(vec3 v, vec3 dest); +CGLM_EXPORT +void +glmc_vec_negate(vec3 v); + +CGLM_EXPORT +void +glmc_vec_negate_to(vec3 v, vec3 dest); + CGLM_EXPORT void glmc_vec_inv(vec3 v); diff --git a/include/cglm/quat.h b/include/cglm/quat.h index c544f0d..b4283b6 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -670,7 +670,7 @@ glm_quat_look(vec3 eye, versor ori, mat4 dest) { /* translate */ glm_mat4_mulv3(dest, eye, 1.0f, dest[3]); - glm_vec_flipsign(dest[3]); + glm_vec_negate(dest[3]); } /*! @@ -778,7 +778,7 @@ void glm_quat_rotate_at(mat4 m, versor q, vec3 pivot) { CGLM_ALIGN(8) vec3 pivotInv; - glm_vec_inv_to(pivot, pivotInv); + glm_vec_negate_to(pivot, pivotInv); glm_translate(m, pivot); glm_quat_rotate(m, q, m); @@ -802,7 +802,7 @@ void glm_quat_rotate_atm(mat4 m, versor q, vec3 pivot) { CGLM_ALIGN(8) vec3 pivotInv; - glm_vec_inv_to(pivot, pivotInv); + glm_vec_negate_to(pivot, pivotInv); glm_translate_make(m, pivot); glm_quat_rotate(m, q, m); diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index fc763a7..9ffcc9c 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -24,6 +24,8 @@ Functions: CGLM_INLINE void glm_vec3(vec4 v4, vec3 dest); CGLM_INLINE void glm_vec_copy(vec3 a, vec3 dest); + CGLM_INLINE void glm_vec_zero(vec3 v); + CGLM_INLINE void glm_vec_one(vec3 v); CGLM_INLINE float glm_vec_dot(vec3 a, vec3 b); CGLM_INLINE void glm_vec_cross(vec3 a, vec3 b, vec3 d); CGLM_INLINE float glm_vec_norm2(vec3 v); @@ -40,7 +42,11 @@ CGLM_INLINE void glm_vec_addadd(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec_subadd(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec_muladd(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec_muladds(vec3 a, float s, vec3 dest); CGLM_INLINE void glm_vec_flipsign(vec3 v); + CGLM_INLINE void glm_vec_flipsign_to(vec3 v, vec3 dest); + CGLM_INLINE void glm_vec_negate_to(vec3 v, vec3 dest); + CGLM_INLINE void glm_vec_negate(vec3 v); CGLM_INLINE void glm_vec_inv(vec3 v); CGLM_INLINE void glm_vec_inv_to(vec3 v, vec3 dest); CGLM_INLINE void glm_vec_normalize(vec3 v); @@ -49,18 +55,26 @@ CGLM_INLINE float glm_vec_angle(vec3 v1, vec3 v2); CGLM_INLINE void glm_vec_rotate(vec3 v, float angle, vec3 axis); CGLM_INLINE void glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest); + CGLM_INLINE void glm_vec_rotate_m4(mat3 m, vec3 v, vec3 dest); CGLM_INLINE void glm_vec_proj(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec_center(vec3 v1, vec3 v2, vec3 dest); + CGLM_INLINE float glm_vec_distance2(vec3 v1, vec3 v2); CGLM_INLINE void glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest); CGLM_INLINE void glm_vec_minv(vec3 v1, vec3 v2, vec3 dest); CGLM_INLINE void glm_vec_ortho(vec3 v, vec3 dest); CGLM_INLINE void glm_vec_clamp(vec3 v, float minVal, float maxVal); + CGLM_INLINE void glm_vec_lerp(vec3 from, vec3 to, float t, vec3 dest); Convenient: CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d); CGLM_INLINE float glm_dot(vec3 a, vec3 b); CGLM_INLINE void glm_normalize(vec3 v); CGLM_INLINE void glm_normalize_to(vec3 v, vec3 dest); + + DEPRECATED: + glm_vec_dup + glm_vec_flipsign + glm_vec_flipsign_to */ #ifndef cglm_vec3_h @@ -120,9 +134,7 @@ glm_vec_copy(vec3 a, vec3 dest) { CGLM_INLINE void glm_vec_zero(vec3 v) { - v[0] = 0.0f; - v[1] = 0.0f; - v[2] = 0.0f; + v[0] = v[1] = v[2] = 0.0f; } /*! @@ -133,9 +145,7 @@ glm_vec_zero(vec3 v) { CGLM_INLINE void glm_vec_one(vec3 v) { - v[0] = 1.0f; - v[1] = 1.0f; - v[2] = 1.0f; + v[0] = v[1] = v[2] = 1.0f; } /*! @@ -408,7 +418,9 @@ glm_vec_muladds(vec3 a, float s, vec3 dest) { } /*! - * @brief flip sign of all vec3 members + * DEPRECATED! use glm_vec_negate and friends + * + * @brief negate vector components * * @param[in, out] v vector */ @@ -421,7 +433,9 @@ glm_vec_flipsign(vec3 v) { } /*! - * @brief flip sign of all vec3 members and store result in dest + * DEPRECATED! use glm_vec_negate and friends + * + * @brief negate vector components and store result in dest * * @param[in] v vector * @param[out] dest result vector @@ -434,6 +448,31 @@ glm_vec_flipsign_to(vec3 v, vec3 dest) { dest[2] = -v[2]; } +/*! + * @brief negate vector components and store result in dest + * + * @param[in] v vector + * @param[out] dest result vector + */ +CGLM_INLINE +void +glm_vec_negate_to(vec3 v, vec3 dest) { + dest[0] = -v[0]; + dest[1] = -v[1]; + dest[2] = -v[2]; +} + +/*! + * @brief negate vector components + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec_negate(vec3 v) { + glm_vec_negate_to(v, v); +} + /*! * @brief make vector as inverse/opposite of itself * diff --git a/src/vec3.c b/src/vec3.c index a2ab499..541dd13 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -158,6 +158,18 @@ glmc_vec_flipsign_to(vec3 v, vec3 dest) { glm_vec_flipsign_to(v, dest); } +CGLM_EXPORT +void +glmc_vec_negate(vec3 v) { + glm_vec_negate(v); +} + +CGLM_EXPORT +void +glmc_vec_negate_to(vec3 v, vec3 dest) { + glm_vec_negate_to(v, dest); +} + CGLM_EXPORT void glmc_vec_inv(vec3 v) { From 9af61d2101a471f958f4a3f5f56a2a0e1caf82c5 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 28 Nov 2018 10:50:21 +0300 Subject: [PATCH 207/292] vec: use `_negate` instead of `_flipsign` and `_inv` --- include/cglm/vec3.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 9ffcc9c..4534969 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -481,7 +481,7 @@ glm_vec_negate(vec3 v) { CGLM_INLINE void glm_vec_inv(vec3 v) { - glm_vec_flipsign(v); + glm_vec_negate(v); } /*! @@ -493,7 +493,7 @@ glm_vec_inv(vec3 v) { CGLM_INLINE void glm_vec_inv_to(vec3 v, vec3 dest) { - glm_vec_flipsign_to(v, dest); + glm_vec_negate_to(v, dest); } /*! From ef6134263e852363d8f412d55f5cd63c88caad48 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 28 Nov 2018 14:48:12 +0300 Subject: [PATCH 208/292] vec: improve angle between two vector * because `acosf()` may return NaN if cosine/dot is out of range --- include/cglm/vec3.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 4534969..5dfe612 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -548,11 +548,18 @@ glm_vec_normalize_to(vec3 vec, vec3 dest) { CGLM_INLINE float glm_vec_angle(vec3 v1, vec3 v2) { - float norm; + float norm, dot; /* maybe compiler generate approximation instruction (rcp) */ norm = 1.0f / (glm_vec_norm(v1) * glm_vec_norm(v2)); - return acosf(glm_vec_dot(v1, v2) * norm); + dot = glm_vec_dot(v1, v2) * norm; + + if (dot > 1.0f) + return 0.0f; + else if (dot < -1.0f) + return CGLM_PI; + + return acosf(dot); } /*! From 0b8c63a90e942f4db4cc929e3918010cca2e7385 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 28 Nov 2018 23:22:30 +0300 Subject: [PATCH 209/292] vec: rename `glm_vec_` namespace to `glm_vec3_` --- README.md | 10 +- include/cglm/affine-mat.h | 4 +- include/cglm/affine.h | 38 +++--- include/cglm/box.h | 52 ++++---- include/cglm/call/vec3.h | 113 +++++++++-------- include/cglm/cam.h | 20 +-- include/cglm/frustum.h | 12 +- include/cglm/mat3.h | 6 +- include/cglm/plane.h | 2 +- include/cglm/quat.h | 24 ++-- include/cglm/sphere.h | 8 +- include/cglm/vec3-ext.h | 59 +++++---- include/cglm/vec3.h | 251 +++++++++++++++++++------------------- include/cglm/vec4-ext.h | 23 ++-- include/cglm/vec4.h | 5 - src/vec3.c | 220 ++++++++++++++++----------------- test/src/test_cam.c | 2 +- test/src/test_clamp.c | 2 +- test/src/test_quat.c | 4 +- test/src/test_vec3.c | 68 +++++------ 20 files changed, 460 insertions(+), 463 deletions(-) diff --git a/README.md b/README.md index ff1b4df..9567960 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Complete documentation: http://cglm.readthedocs.io #### Note for previous versions: -- _dup (duplicate) is changed to _copy. For instance `glm_vec_dup -> glm_vec_copy` +- _dup (duplicate) is changed to _copy. For instance `glm_vec_dup -> glm_vec3_copy` - OpenGL related functions are dropped to make this lib platform/third-party independent - make sure you have latest version and feel free to report bugs, troubles - **[bugfix]** euler angles was implemented in reverse order (extrinsic) it was fixed, now they are intrinsic. Make sure that @@ -201,15 +201,15 @@ If you want to use inline versions of funcstions then; include main header ``` the header will include all headers. Then call func you want e.g. rotate vector by axis: ```C -glm_vec_rotate(v1, glm_rad(45), (vec3){1.0f, 0.0f, 0.0f}); +glm_vec3_rotate(v1, glm_rad(45), (vec3){1.0f, 0.0f, 0.0f}); ``` some functions are overloaded :) e.g you can normalize vector: ```C -glm_vec_normalize(vec); +glm_vec3_normalize(vec); ``` this will normalize vec and store normalized vector into `vec` but if you will store normalized vector into another vector do this: ```C -glm_vec_normalize_to(vec, result); +glm_vec3_normalize_to(vec, result); ``` like this function you may see `_to` postfix, this functions store results to another variables and save temp memory @@ -220,7 +220,7 @@ to call pre-compiled versions include header with `c` postfix, c means call. Pre ``` this header will include all headers with c postfix. You need to call functions with c posfix: ```C -glmc_vec_normalize(vec); +glmc_vec3_normalize(vec); ``` Function usage and parameters are documented inside related headers. You may see same parameter passed twice in some examples like this: diff --git a/include/cglm/affine-mat.h b/include/cglm/affine-mat.h index d26857b..0dcb447 100644 --- a/include/cglm/affine-mat.h +++ b/include/cglm/affine-mat.h @@ -160,8 +160,8 @@ glm_inv_tr(mat4 mat) { /* translate */ glm_mat3_mulv(r, mat[3], t); - glm_vec_negate(t); - glm_vec_copy(t, mat[3]); + glm_vec3_negate(t); + glm_vec3_copy(t, mat[3]); #endif } diff --git a/include/cglm/affine.h b/include/cglm/affine.h index 4c0e1e9..364ed20 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -170,7 +170,7 @@ CGLM_INLINE void glm_translate_make(mat4 m, vec3 v) { glm_mat4_identity(m); - glm_vec_copy(v, m[3]); + glm_vec3_copy(v, m[3]); } /*! @@ -325,13 +325,13 @@ glm_rotate_make(mat4 m, float angle, vec3 axis) { c = cosf(angle); - glm_vec_normalize_to(axis, axisn); - glm_vec_scale(axisn, 1.0f - c, v); - glm_vec_scale(axisn, sinf(angle), vs); + glm_vec3_normalize_to(axis, axisn); + glm_vec3_scale(axisn, 1.0f - c, v); + glm_vec3_scale(axisn, sinf(angle), vs); - glm_vec_scale(axisn, v[0], m[0]); - glm_vec_scale(axisn, v[1], m[1]); - glm_vec_scale(axisn, v[2], m[2]); + glm_vec3_scale(axisn, v[0], m[0]); + glm_vec3_scale(axisn, v[1], m[1]); + glm_vec3_scale(axisn, v[2], m[2]); m[0][0] += c; m[1][0] -= vs[2]; m[2][0] += vs[1]; m[0][1] += vs[2]; m[1][1] += c; m[2][1] -= vs[0]; @@ -370,7 +370,7 @@ void glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) { CGLM_ALIGN(8) vec3 pivotInv; - glm_vec_negate_to(pivot, pivotInv); + glm_vec3_negate_to(pivot, pivotInv); glm_translate(m, pivot); glm_rotate(m, angle, axis); @@ -395,7 +395,7 @@ void glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) { CGLM_ALIGN(8) vec3 pivotInv; - glm_vec_negate_to(pivot, pivotInv); + glm_vec3_negate_to(pivot, pivotInv); glm_translate_make(m, pivot); glm_rotate(m, angle, axis); @@ -411,9 +411,9 @@ glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) { CGLM_INLINE void glm_decompose_scalev(mat4 m, vec3 s) { - s[0] = glm_vec_norm(m[0]); - s[1] = glm_vec_norm(m[1]); - s[2] = glm_vec_norm(m[2]); + s[0] = glm_vec3_norm(m[0]); + s[1] = glm_vec3_norm(m[1]); + s[2] = glm_vec3_norm(m[2]); } /*! @@ -429,7 +429,7 @@ bool glm_uniscaled(mat4 m) { CGLM_ALIGN(8) vec3 s; glm_decompose_scalev(m, s); - return glm_vec_eq_all(s); + return glm_vec3_eq_all(s); } /*! @@ -451,9 +451,9 @@ glm_decompose_rs(mat4 m, mat4 r, vec3 s) { glm_vec4_copy(m[2], r[2]); glm_vec4_copy(t, r[3]); - s[0] = glm_vec_norm(m[0]); - s[1] = glm_vec_norm(m[1]); - s[2] = glm_vec_norm(m[2]); + s[0] = glm_vec3_norm(m[0]); + s[1] = glm_vec3_norm(m[1]); + s[2] = glm_vec3_norm(m[2]); glm_vec4_scale(r[0], 1.0f/s[0], r[0]); glm_vec4_scale(r[1], 1.0f/s[1], r[1]); @@ -462,12 +462,12 @@ glm_decompose_rs(mat4 m, mat4 r, vec3 s) { /* Note from Apple Open Source (asume that the matrix is orthonormal): check for a coordinate system flip. If the determinant is -1, then negate the matrix and the scaling factors. */ - glm_vec_cross(m[0], m[1], v); - if (glm_vec_dot(v, m[2]) < 0.0f) { + glm_vec3_cross(m[0], m[1], v); + if (glm_vec3_dot(v, m[2]) < 0.0f) { glm_vec4_flipsign(r[0]); glm_vec4_flipsign(r[1]); glm_vec4_flipsign(r[2]); - glm_vec_negate(s); + glm_vec3_negate(s); } } diff --git a/include/cglm/box.h b/include/cglm/box.h index 3708107..0fec3ee 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -25,33 +25,33 @@ void glm_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]) { vec3 v[2], xa, xb, ya, yb, za, zb, tmp; - glm_vec_scale(m[0], box[0][0], xa); - glm_vec_scale(m[0], box[1][0], xb); + glm_vec3_scale(m[0], box[0][0], xa); + glm_vec3_scale(m[0], box[1][0], xb); - glm_vec_scale(m[1], box[0][1], ya); - glm_vec_scale(m[1], box[1][1], yb); + glm_vec3_scale(m[1], box[0][1], ya); + glm_vec3_scale(m[1], box[1][1], yb); - glm_vec_scale(m[2], box[0][2], za); - glm_vec_scale(m[2], box[1][2], zb); + glm_vec3_scale(m[2], box[0][2], za); + glm_vec3_scale(m[2], box[1][2], zb); /* min(xa, xb) + min(ya, yb) + min(za, zb) + translation */ - glm_vec_minv(xa, xb, v[0]); - glm_vec_minv(ya, yb, tmp); - glm_vec_add(v[0], tmp, v[0]); - glm_vec_minv(za, zb, tmp); - glm_vec_add(v[0], tmp, v[0]); - glm_vec_add(v[0], m[3], v[0]); + glm_vec3_minv(xa, xb, v[0]); + glm_vec3_minv(ya, yb, tmp); + glm_vec3_add(v[0], tmp, v[0]); + glm_vec3_minv(za, zb, tmp); + glm_vec3_add(v[0], tmp, v[0]); + glm_vec3_add(v[0], m[3], v[0]); /* max(xa, xb) + max(ya, yb) + max(za, zb) + translation */ - glm_vec_maxv(xa, xb, v[1]); - glm_vec_maxv(ya, yb, tmp); - glm_vec_add(v[1], tmp, v[1]); - glm_vec_maxv(za, zb, tmp); - glm_vec_add(v[1], tmp, v[1]); - glm_vec_add(v[1], m[3], v[1]); + glm_vec3_maxv(xa, xb, v[1]); + glm_vec3_maxv(ya, yb, tmp); + glm_vec3_add(v[1], tmp, v[1]); + glm_vec3_maxv(za, zb, tmp); + glm_vec3_add(v[1], tmp, v[1]); + glm_vec3_add(v[1], m[3], v[1]); - glm_vec_copy(v[0], dest[0]); - glm_vec_copy(v[1], dest[1]); + glm_vec3_copy(v[0], dest[0]); + glm_vec3_copy(v[1], dest[1]); } /*! @@ -162,8 +162,8 @@ glm_aabb_frustum(vec3 box[2], vec4 planes[6]) { CGLM_INLINE void glm_aabb_invalidate(vec3 box[2]) { - glm_vec_broadcast(FLT_MAX, box[0]); - glm_vec_broadcast(-FLT_MAX, box[1]); + glm_vec3_broadcast(FLT_MAX, box[0]); + glm_vec3_broadcast(-FLT_MAX, box[1]); } /*! @@ -174,8 +174,8 @@ glm_aabb_invalidate(vec3 box[2]) { CGLM_INLINE bool glm_aabb_isvalid(vec3 box[2]) { - return glm_vec_max(box[0]) != FLT_MAX - && glm_vec_min(box[1]) != -FLT_MAX; + return glm_vec3_max(box[0]) != FLT_MAX + && glm_vec3_min(box[1]) != -FLT_MAX; } /*! @@ -186,7 +186,7 @@ glm_aabb_isvalid(vec3 box[2]) { CGLM_INLINE float glm_aabb_size(vec3 box[2]) { - return glm_vec_distance(box[0], box[1]); + return glm_vec3_distance(box[0], box[1]); } /*! @@ -209,7 +209,7 @@ glm_aabb_radius(vec3 box[2]) { CGLM_INLINE void glm_aabb_center(vec3 box[2], vec3 dest) { - glm_vec_center(box[0], box[1], dest); + glm_vec3_center(box[0], box[1], dest); } /*! diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index d96de98..1cd2e08 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -13,234 +13,231 @@ extern "C" { #include "../cglm.h" -/* DEPRECATED! use _copy, _ucopy versions */ -#define glmc_vec_dup(v, dest) glmc_vec_copy(v, dest) - CGLM_EXPORT void glmc_vec3(vec4 v4, vec3 dest); CGLM_EXPORT void -glmc_vec_copy(vec3 a, vec3 dest); +glmc_vec3_copy(vec3 a, vec3 dest); CGLM_EXPORT void -glmc_vec_zero(vec3 v); +glmc_vec3_zero(vec3 v); CGLM_EXPORT void -glmc_vec_one(vec3 v); +glmc_vec3_one(vec3 v); CGLM_EXPORT float -glmc_vec_dot(vec3 a, vec3 b); +glmc_vec3_dot(vec3 a, vec3 b); CGLM_EXPORT void -glmc_vec_cross(vec3 a, vec3 b, vec3 d); +glmc_vec3_cross(vec3 a, vec3 b, vec3 d); CGLM_EXPORT float -glmc_vec_norm(vec3 vec); +glmc_vec3_norm(vec3 vec); CGLM_EXPORT float -glmc_vec_norm2(vec3 vec); +glmc_vec3_norm2(vec3 vec); CGLM_EXPORT void -glmc_vec_normalize_to(vec3 vec, vec3 dest); +glmc_vec3_normalize_to(vec3 vec, vec3 dest); CGLM_EXPORT void -glmc_vec_normalize(vec3 v); +glmc_vec3_normalize(vec3 v); CGLM_EXPORT void -glmc_vec_add(vec3 v1, vec3 v2, vec3 dest); +glmc_vec3_add(vec3 v1, vec3 v2, vec3 dest); CGLM_EXPORT void -glmc_vec_adds(vec3 v, float s, vec3 dest); +glmc_vec3_adds(vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec_sub(vec3 a, vec3 b, vec3 dest); +glmc_vec3_sub(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec_subs(vec3 v, float s, vec3 dest); +glmc_vec3_subs(vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec_mul(vec3 a, vec3 b, vec3 d); +glmc_vec3_mul(vec3 a, vec3 b, vec3 d); CGLM_EXPORT void -glmc_vec_scale(vec3 v, float s, vec3 dest); +glmc_vec3_scale(vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec_scale_as(vec3 v, float s, vec3 dest); +glmc_vec3_scale_as(vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec_div(vec3 a, vec3 b, vec3 dest); +glmc_vec3_div(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec_divs(vec3 a, float s, vec3 dest); +glmc_vec3_divs(vec3 a, float s, vec3 dest); CGLM_EXPORT void -glmc_vec_addadd(vec3 a, vec3 b, vec3 dest); +glmc_vec3_addadd(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec_subadd(vec3 a, vec3 b, vec3 dest); +glmc_vec3_subadd(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec_muladd(vec3 a, vec3 b, vec3 dest); +glmc_vec3_muladd(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec_muladds(vec3 a, float s, vec3 dest); +glmc_vec3_muladds(vec3 a, float s, vec3 dest); CGLM_EXPORT void -glmc_vec_flipsign(vec3 v); +glmc_vec3_flipsign(vec3 v); CGLM_EXPORT void -glmc_vec_flipsign_to(vec3 v, vec3 dest); +glmc_vec3_flipsign_to(vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec_negate(vec3 v); +glmc_vec3_negate(vec3 v); CGLM_EXPORT void -glmc_vec_negate_to(vec3 v, vec3 dest); +glmc_vec3_negate_to(vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec_inv(vec3 v); +glmc_vec3_inv(vec3 v); CGLM_EXPORT void -glmc_vec_inv_to(vec3 v, vec3 dest); +glmc_vec3_inv_to(vec3 v, vec3 dest); CGLM_EXPORT float -glmc_vec_angle(vec3 v1, vec3 v2); +glmc_vec3_angle(vec3 v1, vec3 v2); CGLM_EXPORT void -glmc_vec_rotate(vec3 v, float angle, vec3 axis); +glmc_vec3_rotate(vec3 v, float angle, vec3 axis); CGLM_EXPORT void -glmc_vec_rotate_m4(mat4 m, vec3 v, vec3 dest); +glmc_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec_rotate_m3(mat3 m, vec3 v, vec3 dest); +glmc_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec_proj(vec3 a, vec3 b, vec3 dest); +glmc_vec3_proj(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec_center(vec3 v1, vec3 v2, vec3 dest); +glmc_vec3_center(vec3 v1, vec3 v2, vec3 dest); CGLM_EXPORT float -glmc_vec_distance2(vec3 v1, vec3 v2); +glmc_vec3_distance2(vec3 v1, vec3 v2); CGLM_EXPORT float -glmc_vec_distance(vec3 v1, vec3 v2); +glmc_vec3_distance(vec3 v1, vec3 v2); CGLM_EXPORT void -glmc_vec_maxv(vec3 v1, vec3 v2, vec3 dest); +glmc_vec3_maxv(vec3 v1, vec3 v2, vec3 dest); CGLM_EXPORT void -glmc_vec_minv(vec3 v1, vec3 v2, vec3 dest); +glmc_vec3_minv(vec3 v1, vec3 v2, vec3 dest); CGLM_EXPORT void -glmc_vec_clamp(vec3 v, float minVal, float maxVal); +glmc_vec3_clamp(vec3 v, float minVal, float maxVal); CGLM_EXPORT void -glmc_vec_ortho(vec3 v, vec3 dest); +glmc_vec3_ortho(vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec_lerp(vec3 from, vec3 to, float t, vec3 dest); +glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest); /* ext */ CGLM_EXPORT void -glmc_vec_mulv(vec3 a, vec3 b, vec3 d); +glmc_vec3_mulv(vec3 a, vec3 b, vec3 d); CGLM_EXPORT void -glmc_vec_broadcast(float val, vec3 d); +glmc_vec3_broadcast(float val, vec3 d); CGLM_EXPORT bool -glmc_vec_eq(vec3 v, float val); +glmc_vec3_eq(vec3 v, float val); CGLM_EXPORT bool -glmc_vec_eq_eps(vec3 v, float val); +glmc_vec3_eq_eps(vec3 v, float val); CGLM_EXPORT bool -glmc_vec_eq_all(vec3 v); +glmc_vec3_eq_all(vec3 v); CGLM_EXPORT bool -glmc_vec_eqv(vec3 v1, vec3 v2); +glmc_vec3_eqv(vec3 v1, vec3 v2); CGLM_EXPORT bool -glmc_vec_eqv_eps(vec3 v1, vec3 v2); +glmc_vec3_eqv_eps(vec3 v1, vec3 v2); CGLM_EXPORT float -glmc_vec_max(vec3 v); +glmc_vec3_max(vec3 v); CGLM_EXPORT float -glmc_vec_min(vec3 v); +glmc_vec3_min(vec3 v); CGLM_EXPORT bool -glmc_vec_isnan(vec3 v); +glmc_vec3_isnan(vec3 v); CGLM_EXPORT bool -glmc_vec_isinf(vec3 v); +glmc_vec3_isinf(vec3 v); CGLM_EXPORT bool -glmc_vec_isvalid(vec3 v); +glmc_vec3_isvalid(vec3 v); CGLM_EXPORT void -glmc_vec_sign(vec3 v, vec3 dest); +glmc_vec3_sign(vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec_sqrt(vec3 v, vec3 dest); +glmc_vec3_sqrt(vec3 v, vec3 dest); #ifdef __cplusplus } diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 284ae82..acfa970 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -320,13 +320,13 @@ glm_lookat(vec3 eye, mat4 dest) { CGLM_ALIGN(8) vec3 f, u, s; - glm_vec_sub(center, eye, f); - glm_vec_normalize(f); + glm_vec3_sub(center, eye, f); + glm_vec3_normalize(f); - glm_vec_cross(f, up, s); - glm_vec_normalize(s); + glm_vec3_cross(f, up, s); + glm_vec3_normalize(s); - glm_vec_cross(s, f, u); + glm_vec3_cross(s, f, u); dest[0][0] = s[0]; dest[0][1] = u[0]; @@ -337,9 +337,9 @@ glm_lookat(vec3 eye, dest[2][0] = s[2]; dest[2][1] = u[2]; dest[2][2] =-f[2]; - dest[3][0] =-glm_vec_dot(s, eye); - dest[3][1] =-glm_vec_dot(u, eye); - dest[3][2] = glm_vec_dot(f, eye); + dest[3][0] =-glm_vec3_dot(s, eye); + dest[3][1] =-glm_vec3_dot(u, eye); + dest[3][2] = glm_vec3_dot(f, eye); dest[0][3] = dest[1][3] = dest[2][3] = 0.0f; dest[3][3] = 1.0f; } @@ -362,7 +362,7 @@ CGLM_INLINE void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { CGLM_ALIGN(8) vec3 target; - glm_vec_add(eye, dir, target); + glm_vec3_add(eye, dir, target); glm_lookat(eye, target, up, dest); } @@ -380,7 +380,7 @@ CGLM_INLINE void glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) { CGLM_ALIGN(8) vec3 up; - glm_vec_ortho(dir, up); + glm_vec3_ortho(dir, up); glm_look(eye, dir, up, dest); } diff --git a/include/cglm/frustum.h b/include/cglm/frustum.h index d4e8d47..78b39d2 100644 --- a/include/cglm/frustum.h +++ b/include/cglm/frustum.h @@ -106,7 +106,7 @@ glm_frustum_planes(mat4 m, vec4 dest[6]) { * * Find center coordinates: * for (j = 0; j < 4; j++) { - * glm_vec_center(corners[i], corners[i + 4], centerCorners[i]); + * glm_vec3_center(corners[i], corners[i + 4], centerCorners[i]); * } * * @param[in] invMat matrix (see brief) @@ -187,8 +187,8 @@ glm_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) { vec3 min, max; int i; - glm_vec_broadcast(FLT_MAX, min); - glm_vec_broadcast(-FLT_MAX, max); + glm_vec3_broadcast(FLT_MAX, min); + glm_vec3_broadcast(-FLT_MAX, max); for (i = 0; i < 8; i++) { glm_mat4_mulv(m, corners[i], v); @@ -202,8 +202,8 @@ glm_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) { max[2] = glm_max(max[2], v[2]); } - glm_vec_copy(min, box[0]); - glm_vec_copy(max, box[1]); + glm_vec3_copy(min, box[0]); + glm_vec3_copy(max, box[1]); } /*! @@ -228,7 +228,7 @@ glm_frustum_corners_at(vec4 corners[8], float dist, sc; /* because distance and scale is same for all */ - dist = glm_vec_distance(corners[GLM_RTF], corners[GLM_RTN]); + dist = glm_vec3_distance(corners[GLM_RTF], corners[GLM_RTN]); sc = dist * (splitDist / farDist); /* left bottom */ diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 5d0d6ac..2d6523c 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -330,9 +330,9 @@ CGLM_INLINE void glm_mat3_swap_col(mat3 mat, int col1, int col2) { vec3 tmp; - glm_vec_copy(mat[col1], tmp); - glm_vec_copy(mat[col2], mat[col1]); - glm_vec_copy(tmp, mat[col2]); + glm_vec3_copy(mat[col1], tmp); + glm_vec3_copy(mat[col2], mat[col1]); + glm_vec3_copy(tmp, mat[col2]); } /*! diff --git a/include/cglm/plane.h b/include/cglm/plane.h index e0faed5..48fe879 100644 --- a/include/cglm/plane.h +++ b/include/cglm/plane.h @@ -30,7 +30,7 @@ CGLM_INLINE void glm_plane_normalize(vec4 plane) { - glm_vec4_scale(plane, 1.0f / glm_vec_norm(plane), plane); + glm_vec4_scale(plane, 1.0f / glm_vec3_norm(plane), plane); } #endif /* cglm_plane_h */ diff --git a/include/cglm/quat.h b/include/cglm/quat.h index b4283b6..37aba8d 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -361,7 +361,7 @@ glm_quat_imagn(versor q, vec3 dest) { CGLM_INLINE float glm_quat_imaglen(versor q) { - return glm_vec_norm(q); + return glm_vec3_norm(q); } /*! @@ -670,7 +670,7 @@ glm_quat_look(vec3 eye, versor ori, mat4 dest) { /* translate */ glm_mat4_mulv3(dest, eye, 1.0f, dest[3]); - glm_vec_negate(dest[3]); + glm_vec3_negate(dest[3]); } /*! @@ -687,7 +687,7 @@ glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) { CGLM_ALIGN(8) vec3 axis; float dot, angle; - dot = glm_vec_dot(dir, fwd); + dot = glm_vec3_dot(dir, fwd); if (fabsf(dot + 1.0f) < 0.000001f) { glm_quat_init(dest, up[0], up[1], up[2], GLM_PIf); return; @@ -719,7 +719,7 @@ CGLM_INLINE void glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { CGLM_ALIGN(8) vec3 dir; - glm_vec_sub(to, from, dir); + glm_vec3_sub(to, from, dir); glm_quat_for(dir, fwd, up, dest); } @@ -741,14 +741,14 @@ glm_quat_rotatev(versor q, vec3 v, vec3 dest) { glm_quat_imag(p, u); s = glm_quat_real(p); - glm_vec_scale(u, 2.0f * glm_vec_dot(u, v), v1); - glm_vec_scale(v, s * s - glm_vec_dot(u, u), v2); - glm_vec_add(v1, v2, v1); + glm_vec3_scale(u, 2.0f * glm_vec3_dot(u, v), v1); + glm_vec3_scale(v, s * s - glm_vec3_dot(u, u), v2); + glm_vec3_add(v1, v2, v1); - glm_vec_cross(u, v, v2); - glm_vec_scale(v2, 2.0f * s, v2); + glm_vec3_cross(u, v, v2); + glm_vec3_scale(v2, 2.0f * s, v2); - glm_vec_add(v1, v2, dest); + glm_vec3_add(v1, v2, dest); } /*! @@ -778,7 +778,7 @@ void glm_quat_rotate_at(mat4 m, versor q, vec3 pivot) { CGLM_ALIGN(8) vec3 pivotInv; - glm_vec_negate_to(pivot, pivotInv); + glm_vec3_negate_to(pivot, pivotInv); glm_translate(m, pivot); glm_quat_rotate(m, q, m); @@ -802,7 +802,7 @@ void glm_quat_rotate_atm(mat4 m, versor q, vec3 pivot) { CGLM_ALIGN(8) vec3 pivotInv; - glm_vec_negate_to(pivot, pivotInv); + glm_vec3_negate_to(pivot, pivotInv); glm_translate_make(m, pivot); glm_quat_rotate(m, q, m); diff --git a/include/cglm/sphere.h b/include/cglm/sphere.h index a7501b9..334b83a 100644 --- a/include/cglm/sphere.h +++ b/include/cglm/sphere.h @@ -60,13 +60,13 @@ void glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { float dist, radii; - dist = glm_vec_distance(s1, s2); + dist = glm_vec3_distance(s1, s2); radii = dist + s1[3] + s2[3]; radii = glm_max(radii, s1[3]); radii = glm_max(radii, s2[3]); - glm_vec_center(s1, s2, dest); + glm_vec3_center(s1, s2, dest); dest[3] = radii; } @@ -79,7 +79,7 @@ glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { CGLM_INLINE bool glm_sphere_sphere(vec4 s1, vec4 s2) { - return glm_vec_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]); + return glm_vec3_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]); } /*! @@ -93,7 +93,7 @@ bool glm_sphere_point(vec4 s, vec3 point) { float rr; rr = s[3] * s[3]; - return glm_vec_distance2(point, s) <= rr; + return glm_vec3_distance2(point, s) <= rr; } #endif /* cglm_sphere_h */ diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index e12c133..34166f4 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -11,15 +11,20 @@ /* Functions: - CGLM_INLINE void glm_vec_mulv(vec3 a, vec3 b, vec3 d); - CGLM_INLINE void glm_vec_broadcast(float val, vec3 d); - CGLM_INLINE bool glm_vec_eq(vec3 v, float val); - CGLM_INLINE bool glm_vec_eq_eps(vec3 v, float val); - CGLM_INLINE bool glm_vec_eq_all(vec3 v); - CGLM_INLINE bool glm_vec_eqv(vec3 v1, vec3 v2); - CGLM_INLINE bool glm_vec_eqv_eps(vec3 v1, vec3 v2); - CGLM_INLINE float glm_vec_max(vec3 v); - CGLM_INLINE float glm_vec_min(vec3 v); + CGLM_INLINE void glm_vec3_mulv(vec3 a, vec3 b, vec3 d); + CGLM_INLINE void glm_vec3_broadcast(float val, vec3 d); + CGLM_INLINE bool glm_vec3_eq(vec3 v, float val); + CGLM_INLINE bool glm_vec3_eq_eps(vec3 v, float val); + CGLM_INLINE bool glm_vec3_eq_all(vec3 v); + CGLM_INLINE bool glm_vec3_eqv(vec3 v1, vec3 v2); + CGLM_INLINE bool glm_vec3_eqv_eps(vec3 v1, vec3 v2); + CGLM_INLINE float glm_vec3_max(vec3 v); + CGLM_INLINE float glm_vec3_min(vec3 v); + CGLM_INLINE bool glm_vec3_isnan(vec3 v); + CGLM_INLINE bool glm_vec3_isinf(vec3 v); + CGLM_INLINE bool glm_vec3_isvalid(vec3 v); + CGLM_INLINE void glm_vec3_sign(vec3 v, vec3 dest); + CGLM_INLINE void glm_vec3_sqrt(vec3 v, vec3 dest); */ #ifndef cglm_vec3_ext_h @@ -32,7 +37,7 @@ #include /*! - * @brief DEPRECATED! use glm_vec_mul + * @brief DEPRECATED! use glm_vec3_mul * * @param[in] a vec1 * @param[in] b vec2 @@ -40,7 +45,7 @@ */ CGLM_INLINE void -glm_vec_mulv(vec3 a, vec3 b, vec3 d) { +glm_vec3_mulv(vec3 a, vec3 b, vec3 d) { d[0] = a[0] * b[0]; d[1] = a[1] * b[1]; d[2] = a[2] * b[2]; @@ -54,7 +59,7 @@ glm_vec_mulv(vec3 a, vec3 b, vec3 d) { */ CGLM_INLINE void -glm_vec_broadcast(float val, vec3 d) { +glm_vec3_broadcast(float val, vec3 d) { d[0] = d[1] = d[2] = val; } @@ -66,7 +71,7 @@ glm_vec_broadcast(float val, vec3 d) { */ CGLM_INLINE bool -glm_vec_eq(vec3 v, float val) { +glm_vec3_eq(vec3 v, float val) { return v[0] == val && v[0] == v[1] && v[0] == v[2]; } @@ -78,7 +83,7 @@ glm_vec_eq(vec3 v, float val) { */ CGLM_INLINE bool -glm_vec_eq_eps(vec3 v, float val) { +glm_vec3_eq_eps(vec3 v, float val) { return fabsf(v[0] - val) <= FLT_EPSILON && fabsf(v[1] - val) <= FLT_EPSILON && fabsf(v[2] - val) <= FLT_EPSILON; @@ -91,7 +96,7 @@ glm_vec_eq_eps(vec3 v, float val) { */ CGLM_INLINE bool -glm_vec_eq_all(vec3 v) { +glm_vec3_eq_all(vec3 v) { return v[0] == v[1] && v[0] == v[2]; } @@ -103,10 +108,10 @@ glm_vec_eq_all(vec3 v) { */ CGLM_INLINE bool -glm_vec_eqv(vec3 v1, vec3 v2) { +glm_vec3_eqv(vec3 v1, vec3 v2) { return v1[0] == v2[0] - && v1[1] == v2[1] - && v1[2] == v2[2]; + && v1[1] == v2[1] + && v1[2] == v2[2]; } /*! @@ -117,7 +122,7 @@ glm_vec_eqv(vec3 v1, vec3 v2) { */ CGLM_INLINE bool -glm_vec_eqv_eps(vec3 v1, vec3 v2) { +glm_vec3_eqv_eps(vec3 v1, vec3 v2) { return fabsf(v1[0] - v2[0]) <= FLT_EPSILON && fabsf(v1[1] - v2[1]) <= FLT_EPSILON && fabsf(v1[2] - v2[2]) <= FLT_EPSILON; @@ -130,7 +135,7 @@ glm_vec_eqv_eps(vec3 v1, vec3 v2) { */ CGLM_INLINE float -glm_vec_max(vec3 v) { +glm_vec3_max(vec3 v) { float max; max = v[0]; @@ -149,7 +154,7 @@ glm_vec_max(vec3 v) { */ CGLM_INLINE float -glm_vec_min(vec3 v) { +glm_vec3_min(vec3 v) { float min; min = v[0]; @@ -169,7 +174,7 @@ glm_vec_min(vec3 v) { */ CGLM_INLINE bool -glm_vec_isnan(vec3 v) { +glm_vec3_isnan(vec3 v) { return isnan(v[0]) || isnan(v[1]) || isnan(v[2]); } @@ -181,7 +186,7 @@ glm_vec_isnan(vec3 v) { */ CGLM_INLINE bool -glm_vec_isinf(vec3 v) { +glm_vec3_isinf(vec3 v) { return isinf(v[0]) || isinf(v[1]) || isinf(v[2]); } @@ -193,8 +198,8 @@ glm_vec_isinf(vec3 v) { */ CGLM_INLINE bool -glm_vec_isvalid(vec3 v) { - return !glm_vec_isnan(v) && !glm_vec_isinf(v); +glm_vec3_isvalid(vec3 v) { + return !glm_vec3_isnan(v) && !glm_vec3_isinf(v); } /*! @@ -206,7 +211,7 @@ glm_vec_isvalid(vec3 v) { */ CGLM_INLINE void -glm_vec_sign(vec3 v, vec3 dest) { +glm_vec3_sign(vec3 v, vec3 dest) { dest[0] = glm_signf(v[0]); dest[1] = glm_signf(v[1]); dest[2] = glm_signf(v[2]); @@ -220,7 +225,7 @@ glm_vec_sign(vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec_sqrt(vec3 v, vec3 dest) { +glm_vec3_sqrt(vec3 v, vec3 dest) { dest[0] = sqrtf(v[0]); dest[1] = sqrtf(v[1]); dest[2] = sqrtf(v[2]); diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 5dfe612..eb64c80 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -5,11 +5,6 @@ * Full license can be found in the LICENSE file */ -/*! - * vec3 functions dont have suffix e.g glm_vec_dot (not glm_vec3_dot) - * all functions without suffix are vec3 functions - */ - /* Macros: glm_vec_dup(v, dest) @@ -23,47 +18,47 @@ Functions: CGLM_INLINE void glm_vec3(vec4 v4, vec3 dest); - CGLM_INLINE void glm_vec_copy(vec3 a, vec3 dest); - CGLM_INLINE void glm_vec_zero(vec3 v); - CGLM_INLINE void glm_vec_one(vec3 v); - CGLM_INLINE float glm_vec_dot(vec3 a, vec3 b); - CGLM_INLINE void glm_vec_cross(vec3 a, vec3 b, vec3 d); - CGLM_INLINE float glm_vec_norm2(vec3 v); - CGLM_INLINE float glm_vec_norm(vec3 vec); - CGLM_INLINE void glm_vec_add(vec3 a, vec3 b, vec3 dest); - CGLM_INLINE void glm_vec_adds(vec3 a, float s, vec3 dest); - CGLM_INLINE void glm_vec_sub(vec3 a, vec3 b, vec3 dest); - CGLM_INLINE void glm_vec_subs(vec3 a, float s, vec3 dest); - CGLM_INLINE void glm_vec_mul(vec3 a, vec3 b, vec3 dest); - CGLM_INLINE void glm_vec_scale(vec3 v, float s, vec3 dest); - CGLM_INLINE void glm_vec_scale_as(vec3 v, float s, vec3 dest); - CGLM_INLINE void glm_vec_div(vec3 a, vec3 b, vec3 dest); - CGLM_INLINE void glm_vec_divs(vec3 a, float s, vec3 dest); - CGLM_INLINE void glm_vec_addadd(vec3 a, vec3 b, vec3 dest); - CGLM_INLINE void glm_vec_subadd(vec3 a, vec3 b, vec3 dest); - CGLM_INLINE void glm_vec_muladd(vec3 a, vec3 b, vec3 dest); - CGLM_INLINE void glm_vec_muladds(vec3 a, float s, vec3 dest); - CGLM_INLINE void glm_vec_flipsign(vec3 v); - CGLM_INLINE void glm_vec_flipsign_to(vec3 v, vec3 dest); - CGLM_INLINE void glm_vec_negate_to(vec3 v, vec3 dest); - CGLM_INLINE void glm_vec_negate(vec3 v); - CGLM_INLINE void glm_vec_inv(vec3 v); - CGLM_INLINE void glm_vec_inv_to(vec3 v, vec3 dest); - CGLM_INLINE void glm_vec_normalize(vec3 v); - CGLM_INLINE void glm_vec_normalize_to(vec3 vec, vec3 dest); - CGLM_INLINE float glm_vec_distance(vec3 v1, vec3 v2); - CGLM_INLINE float glm_vec_angle(vec3 v1, vec3 v2); - CGLM_INLINE void glm_vec_rotate(vec3 v, float angle, vec3 axis); - CGLM_INLINE void glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest); - CGLM_INLINE void glm_vec_rotate_m4(mat3 m, vec3 v, vec3 dest); - CGLM_INLINE void glm_vec_proj(vec3 a, vec3 b, vec3 dest); - CGLM_INLINE void glm_vec_center(vec3 v1, vec3 v2, vec3 dest); - CGLM_INLINE float glm_vec_distance2(vec3 v1, vec3 v2); - CGLM_INLINE void glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest); - CGLM_INLINE void glm_vec_minv(vec3 v1, vec3 v2, vec3 dest); - CGLM_INLINE void glm_vec_ortho(vec3 v, vec3 dest); - CGLM_INLINE void glm_vec_clamp(vec3 v, float minVal, float maxVal); - CGLM_INLINE void glm_vec_lerp(vec3 from, vec3 to, float t, vec3 dest); + CGLM_INLINE void glm_vec3_copy(vec3 a, vec3 dest); + CGLM_INLINE void glm_vec3_zero(vec3 v); + CGLM_INLINE void glm_vec3_one(vec3 v); + CGLM_INLINE float glm_vec3_dot(vec3 a, vec3 b); + CGLM_INLINE void glm_vec3_cross(vec3 a, vec3 b, vec3 d); + CGLM_INLINE float glm_vec3_norm2(vec3 v); + CGLM_INLINE float glm_vec3_norm(vec3 vec); + CGLM_INLINE void glm_vec3_add(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec3_adds(vec3 a, float s, vec3 dest); + CGLM_INLINE void glm_vec3_sub(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec3_subs(vec3 a, float s, vec3 dest); + CGLM_INLINE void glm_vec3_mul(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec3_scale(vec3 v, float s, vec3 dest); + CGLM_INLINE void glm_vec3_scale_as(vec3 v, float s, vec3 dest); + CGLM_INLINE void glm_vec3_div(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec3_divs(vec3 a, float s, vec3 dest); + CGLM_INLINE void glm_vec3_addadd(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec3_subadd(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec3_muladd(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec3_muladds(vec3 a, float s, vec3 dest); + CGLM_INLINE void glm_vec3_flipsign(vec3 v); + CGLM_INLINE void glm_vec3_flipsign_to(vec3 v, vec3 dest); + CGLM_INLINE void glm_vec3_negate_to(vec3 v, vec3 dest); + CGLM_INLINE void glm_vec3_negate(vec3 v); + CGLM_INLINE void glm_vec3_inv(vec3 v); + CGLM_INLINE void glm_vec3_inv_to(vec3 v, vec3 dest); + CGLM_INLINE void glm_vec3_normalize(vec3 v); + CGLM_INLINE void glm_vec3_normalize_to(vec3 vec, vec3 dest); + CGLM_INLINE float glm_vec3_distance(vec3 v1, vec3 v2); + CGLM_INLINE float glm_vec3_angle(vec3 v1, vec3 v2); + CGLM_INLINE void glm_vec3_rotate(vec3 v, float angle, vec3 axis); + CGLM_INLINE void glm_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest); + CGLM_INLINE void glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest); + CGLM_INLINE void glm_vec3_proj(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec3_center(vec3 v1, vec3 v2, vec3 dest); + CGLM_INLINE float glm_vec3_distance2(vec3 v1, vec3 v2); + CGLM_INLINE void glm_vec3_maxv(vec3 v1, vec3 v2, vec3 dest); + CGLM_INLINE void glm_vec3_minv(vec3 v1, vec3 v2, vec3 dest); + CGLM_INLINE void glm_vec3_ortho(vec3 v, vec3 dest); + CGLM_INLINE void glm_vec3_clamp(vec3 v, float minVal, float maxVal); + CGLM_INLINE void glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest); Convenient: CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d); @@ -73,8 +68,8 @@ DEPRECATED: glm_vec_dup - glm_vec_flipsign - glm_vec_flipsign_to + glm_vec3_flipsign + glm_vec3_flipsign_to */ #ifndef cglm_vec3_h @@ -86,7 +81,7 @@ #include "util.h" /* DEPRECATED! use _copy, _ucopy versions */ -#define glm_vec_dup(v, dest) glm_vec_copy(v, dest) +#define glm_vec_dup(v, dest) glm_vec3_copy(v, dest) #define GLM_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f} #define GLM_VEC3_ZERO_INIT {0.0f, 0.0f, 0.0f} @@ -120,7 +115,7 @@ glm_vec3(vec4 v4, vec3 dest) { */ CGLM_INLINE void -glm_vec_copy(vec3 a, vec3 dest) { +glm_vec3_copy(vec3 a, vec3 dest) { dest[0] = a[0]; dest[1] = a[1]; dest[2] = a[2]; @@ -133,7 +128,7 @@ glm_vec_copy(vec3 a, vec3 dest) { */ CGLM_INLINE void -glm_vec_zero(vec3 v) { +glm_vec3_zero(vec3 v) { v[0] = v[1] = v[2] = 0.0f; } @@ -144,7 +139,7 @@ glm_vec_zero(vec3 v) { */ CGLM_INLINE void -glm_vec_one(vec3 v) { +glm_vec3_one(vec3 v) { v[0] = v[1] = v[2] = 1.0f; } @@ -158,7 +153,7 @@ glm_vec_one(vec3 v) { */ CGLM_INLINE float -glm_vec_dot(vec3 a, vec3 b) { +glm_vec3_dot(vec3 a, vec3 b) { return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; } @@ -171,7 +166,7 @@ glm_vec_dot(vec3 a, vec3 b) { */ CGLM_INLINE void -glm_vec_cross(vec3 a, vec3 b, vec3 d) { +glm_vec3_cross(vec3 a, vec3 b, vec3 d) { /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ d[0] = a[1] * b[2] - a[2] * b[1]; d[1] = a[2] * b[0] - a[0] * b[2]; @@ -191,8 +186,8 @@ glm_vec_cross(vec3 a, vec3 b, vec3 d) { */ CGLM_INLINE float -glm_vec_norm2(vec3 v) { - return glm_vec_dot(v, v); +glm_vec3_norm2(vec3 v) { + return glm_vec3_dot(v, v); } /*! @@ -204,8 +199,8 @@ glm_vec_norm2(vec3 v) { */ CGLM_INLINE float -glm_vec_norm(vec3 vec) { - return sqrtf(glm_vec_norm2(vec)); +glm_vec3_norm(vec3 vec) { + return sqrtf(glm_vec3_norm2(vec)); } /*! @@ -217,7 +212,7 @@ glm_vec_norm(vec3 vec) { */ CGLM_INLINE void -glm_vec_add(vec3 a, vec3 b, vec3 dest) { +glm_vec3_add(vec3 a, vec3 b, vec3 dest) { dest[0] = a[0] + b[0]; dest[1] = a[1] + b[1]; dest[2] = a[2] + b[2]; @@ -232,7 +227,7 @@ glm_vec_add(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec_adds(vec3 v, float s, vec3 dest) { +glm_vec3_adds(vec3 v, float s, vec3 dest) { dest[0] = v[0] + s; dest[1] = v[1] + s; dest[2] = v[2] + s; @@ -247,7 +242,7 @@ glm_vec_adds(vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec_sub(vec3 a, vec3 b, vec3 dest) { +glm_vec3_sub(vec3 a, vec3 b, vec3 dest) { dest[0] = a[0] - b[0]; dest[1] = a[1] - b[1]; dest[2] = a[2] - b[2]; @@ -262,7 +257,7 @@ glm_vec_sub(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec_subs(vec3 v, float s, vec3 dest) { +glm_vec3_subs(vec3 v, float s, vec3 dest) { dest[0] = v[0] - s; dest[1] = v[1] - s; dest[2] = v[2] - s; @@ -277,7 +272,7 @@ glm_vec_subs(vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec_mul(vec3 a, vec3 b, vec3 d) { +glm_vec3_mul(vec3 a, vec3 b, vec3 d) { d[0] = a[0] * b[0]; d[1] = a[1] * b[1]; d[2] = a[2] * b[2]; @@ -292,7 +287,7 @@ glm_vec_mul(vec3 a, vec3 b, vec3 d) { */ CGLM_INLINE void -glm_vec_scale(vec3 v, float s, vec3 dest) { +glm_vec3_scale(vec3 v, float s, vec3 dest) { dest[0] = v[0] * s; dest[1] = v[1] * s; dest[2] = v[2] * s; @@ -307,16 +302,16 @@ glm_vec_scale(vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec_scale_as(vec3 v, float s, vec3 dest) { +glm_vec3_scale_as(vec3 v, float s, vec3 dest) { float norm; - norm = glm_vec_norm(v); + norm = glm_vec3_norm(v); if (norm == 0.0f) { - glm_vec_zero(dest); + glm_vec3_zero(dest); return; } - glm_vec_scale(v, s / norm, dest); + glm_vec3_scale(v, s / norm, dest); } /*! @@ -328,7 +323,7 @@ glm_vec_scale_as(vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec_div(vec3 a, vec3 b, vec3 dest) { +glm_vec3_div(vec3 a, vec3 b, vec3 dest) { dest[0] = a[0] / b[0]; dest[1] = a[1] / b[1]; dest[2] = a[2] / b[2]; @@ -343,7 +338,7 @@ glm_vec_div(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec_divs(vec3 v, float s, vec3 dest) { +glm_vec3_divs(vec3 v, float s, vec3 dest) { dest[0] = v[0] / s; dest[1] = v[1] / s; dest[2] = v[2] / s; @@ -360,7 +355,7 @@ glm_vec_divs(vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec_addadd(vec3 a, vec3 b, vec3 dest) { +glm_vec3_addadd(vec3 a, vec3 b, vec3 dest) { dest[0] += a[0] + b[0]; dest[1] += a[1] + b[1]; dest[2] += a[2] + b[2]; @@ -377,7 +372,7 @@ glm_vec_addadd(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec_subadd(vec3 a, vec3 b, vec3 dest) { +glm_vec3_subadd(vec3 a, vec3 b, vec3 dest) { dest[0] += a[0] - b[0]; dest[1] += a[1] - b[1]; dest[2] += a[2] - b[2]; @@ -394,7 +389,7 @@ glm_vec_subadd(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec_muladd(vec3 a, vec3 b, vec3 dest) { +glm_vec3_muladd(vec3 a, vec3 b, vec3 dest) { dest[0] += a[0] * b[0]; dest[1] += a[1] * b[1]; dest[2] += a[2] * b[2]; @@ -411,14 +406,14 @@ glm_vec_muladd(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec_muladds(vec3 a, float s, vec3 dest) { +glm_vec3_muladds(vec3 a, float s, vec3 dest) { dest[0] += a[0] * s; dest[1] += a[1] * s; dest[2] += a[2] * s; } /*! - * DEPRECATED! use glm_vec_negate and friends + * DEPRECATED! use glm_vec3_negate and friends * * @brief negate vector components * @@ -426,14 +421,14 @@ glm_vec_muladds(vec3 a, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec_flipsign(vec3 v) { +glm_vec3_flipsign(vec3 v) { v[0] = -v[0]; v[1] = -v[1]; v[2] = -v[2]; } /*! - * DEPRECATED! use glm_vec_negate and friends + * DEPRECATED! use glm_vec3_negate and friends * * @brief negate vector components and store result in dest * @@ -442,7 +437,7 @@ glm_vec_flipsign(vec3 v) { */ CGLM_INLINE void -glm_vec_flipsign_to(vec3 v, vec3 dest) { +glm_vec3_flipsign_to(vec3 v, vec3 dest) { dest[0] = -v[0]; dest[1] = -v[1]; dest[2] = -v[2]; @@ -456,7 +451,7 @@ glm_vec_flipsign_to(vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec_negate_to(vec3 v, vec3 dest) { +glm_vec3_negate_to(vec3 v, vec3 dest) { dest[0] = -v[0]; dest[1] = -v[1]; dest[2] = -v[2]; @@ -469,8 +464,8 @@ glm_vec_negate_to(vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec_negate(vec3 v) { - glm_vec_negate_to(v, v); +glm_vec3_negate(vec3 v) { + glm_vec3_negate_to(v, v); } /*! @@ -480,8 +475,8 @@ glm_vec_negate(vec3 v) { */ CGLM_INLINE void -glm_vec_inv(vec3 v) { - glm_vec_negate(v); +glm_vec3_inv(vec3 v) { + glm_vec3_negate(v); } /*! @@ -492,8 +487,8 @@ glm_vec_inv(vec3 v) { */ CGLM_INLINE void -glm_vec_inv_to(vec3 v, vec3 dest) { - glm_vec_negate_to(v, dest); +glm_vec3_inv_to(vec3 v, vec3 dest) { + glm_vec3_negate_to(v, dest); } /*! @@ -503,17 +498,17 @@ glm_vec_inv_to(vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec_normalize(vec3 v) { +glm_vec3_normalize(vec3 v) { float norm; - norm = glm_vec_norm(v); + norm = glm_vec3_norm(v); if (norm == 0.0f) { v[0] = v[1] = v[2] = 0.0f; return; } - glm_vec_scale(v, 1.0f / norm, v); + glm_vec3_scale(v, 1.0f / norm, v); } /*! @@ -524,17 +519,17 @@ glm_vec_normalize(vec3 v) { */ CGLM_INLINE void -glm_vec_normalize_to(vec3 vec, vec3 dest) { +glm_vec3_normalize_to(vec3 vec, vec3 dest) { float norm; - norm = glm_vec_norm(vec); + norm = glm_vec3_norm(vec); if (norm == 0.0f) { - glm_vec_zero(dest); + glm_vec3_zero(dest); return; } - glm_vec_scale(vec, 1.0f / norm, dest); + glm_vec3_scale(vec, 1.0f / norm, dest); } /*! @@ -547,12 +542,12 @@ glm_vec_normalize_to(vec3 vec, vec3 dest) { */ CGLM_INLINE float -glm_vec_angle(vec3 v1, vec3 v2) { +glm_vec3_angle(vec3 v1, vec3 v2) { float norm, dot; /* maybe compiler generate approximation instruction (rcp) */ - norm = 1.0f / (glm_vec_norm(v1) * glm_vec_norm(v2)); - dot = glm_vec_dot(v1, v2) * norm; + norm = 1.0f / (glm_vec3_norm(v1) * glm_vec3_norm(v2)); + dot = glm_vec3_dot(v1, v2) * norm; if (dot > 1.0f) return 0.0f; @@ -571,27 +566,27 @@ glm_vec_angle(vec3 v1, vec3 v2) { */ CGLM_INLINE void -glm_vec_rotate(vec3 v, float angle, vec3 axis) { +glm_vec3_rotate(vec3 v, float angle, vec3 axis) { vec3 v1, v2, k; float c, s; c = cosf(angle); s = sinf(angle); - glm_vec_normalize_to(axis, k); + glm_vec3_normalize_to(axis, k); /* Right Hand, Rodrigues' rotation formula: v = v*cos(t) + (kxv)sin(t) + k*(k.v)(1 - cos(t)) */ - glm_vec_scale(v, c, v1); + glm_vec3_scale(v, c, v1); - glm_vec_cross(k, v, v2); - glm_vec_scale(v2, s, v2); + glm_vec3_cross(k, v, v2); + glm_vec3_scale(v2, s, v2); - glm_vec_add(v1, v2, v1); + glm_vec3_add(v1, v2, v1); - glm_vec_scale(k, glm_vec_dot(k, v) * (1.0f - c), v2); - glm_vec_add(v1, v2, v); + glm_vec3_scale(k, glm_vec3_dot(k, v) * (1.0f - c), v2); + glm_vec3_add(v1, v2, v); } /*! @@ -609,7 +604,7 @@ glm_vec_rotate(vec3 v, float angle, vec3 axis) { */ CGLM_INLINE void -glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) { +glm_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest) { vec4 x, y, z, res; glm_vec4_normalize_to(m[0], x); @@ -632,7 +627,7 @@ glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec_rotate_m3(mat3 m, vec3 v, vec3 dest) { +glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest) { vec4 res, x, y, z; glm_vec4(m[0], 0.0f, x); @@ -659,10 +654,10 @@ glm_vec_rotate_m3(mat3 m, vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec_proj(vec3 a, vec3 b, vec3 dest) { - glm_vec_scale(b, - glm_vec_dot(a, b) / glm_vec_norm2(b), - dest); +glm_vec3_proj(vec3 a, vec3 b, vec3 dest) { + glm_vec3_scale(b, + glm_vec3_dot(a, b) / glm_vec3_norm2(b), + dest); } /** @@ -674,9 +669,9 @@ glm_vec_proj(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec_center(vec3 v1, vec3 v2, vec3 dest) { - glm_vec_add(v1, v2, dest); - glm_vec_scale(dest, 0.5f, dest); +glm_vec3_center(vec3 v1, vec3 v2, vec3 dest) { + glm_vec3_add(v1, v2, dest); + glm_vec3_scale(dest, 0.5f, dest); } /** @@ -688,7 +683,7 @@ glm_vec_center(vec3 v1, vec3 v2, vec3 dest) { */ CGLM_INLINE float -glm_vec_distance2(vec3 v1, vec3 v2) { +glm_vec3_distance2(vec3 v1, vec3 v2) { return glm_pow2(v2[0] - v1[0]) + glm_pow2(v2[1] - v1[1]) + glm_pow2(v2[2] - v1[2]); @@ -703,8 +698,8 @@ glm_vec_distance2(vec3 v1, vec3 v2) { */ CGLM_INLINE float -glm_vec_distance(vec3 v1, vec3 v2) { - return sqrtf(glm_vec_distance2(v1, v2)); +glm_vec3_distance(vec3 v1, vec3 v2) { + return sqrtf(glm_vec3_distance2(v1, v2)); } /*! @@ -716,7 +711,7 @@ glm_vec_distance(vec3 v1, vec3 v2) { */ CGLM_INLINE void -glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest) { +glm_vec3_maxv(vec3 v1, vec3 v2, vec3 dest) { dest[0] = glm_max(v1[0], v2[0]); dest[1] = glm_max(v1[1], v2[1]); dest[2] = glm_max(v1[2], v2[2]); @@ -731,7 +726,7 @@ glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest) { */ CGLM_INLINE void -glm_vec_minv(vec3 v1, vec3 v2, vec3 dest) { +glm_vec3_minv(vec3 v1, vec3 v2, vec3 dest) { dest[0] = glm_min(v1[0], v2[0]); dest[1] = glm_min(v1[1], v2[1]); dest[2] = glm_min(v1[2], v2[2]); @@ -745,7 +740,7 @@ glm_vec_minv(vec3 v1, vec3 v2, vec3 dest) { */ CGLM_INLINE void -glm_vec_ortho(vec3 v, vec3 dest) { +glm_vec3_ortho(vec3 v, vec3 dest) { dest[0] = v[1] - v[2]; dest[1] = v[2] - v[0]; dest[2] = v[0] - v[1]; @@ -760,7 +755,7 @@ glm_vec_ortho(vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec_clamp(vec3 v, float minVal, float maxVal) { +glm_vec3_clamp(vec3 v, float minVal, float maxVal) { v[0] = glm_clamp(v[0], minVal, maxVal); v[1] = glm_clamp(v[1], minVal, maxVal); v[2] = glm_clamp(v[2], minVal, maxVal); @@ -778,14 +773,14 @@ glm_vec_clamp(vec3 v, float minVal, float maxVal) { */ CGLM_INLINE void -glm_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) { +glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) { vec3 s, v; /* from + s * (to - from) */ - glm_vec_broadcast(glm_clamp_zo(t), s); - glm_vec_sub(to, from, v); - glm_vec_mulv(s, v, v); - glm_vec_add(from, v, dest); + glm_vec3_broadcast(glm_clamp_zo(t), s); + glm_vec3_sub(to, from, v); + glm_vec3_mulv(s, v, v); + glm_vec3_add(from, v, dest); } /*! @@ -800,7 +795,7 @@ glm_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) { CGLM_INLINE void glm_cross(vec3 a, vec3 b, vec3 d) { - glm_vec_cross(a, b, d); + glm_vec3_cross(a, b, d); } /*! @@ -816,7 +811,7 @@ glm_cross(vec3 a, vec3 b, vec3 d) { CGLM_INLINE float glm_dot(vec3 a, vec3 b) { - return glm_vec_dot(a, b); + return glm_vec3_dot(a, b); } /*! @@ -829,7 +824,7 @@ glm_dot(vec3 a, vec3 b) { CGLM_INLINE void glm_normalize(vec3 v) { - glm_vec_normalize(v); + glm_vec3_normalize(v); } /*! @@ -843,7 +838,7 @@ glm_normalize(vec3 v) { CGLM_INLINE void glm_normalize_to(vec3 v, vec3 dest) { - glm_vec_normalize_to(v, dest); + glm_vec3_normalize_to(v, dest); } #endif /* cglm_vec3_h */ diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index b7902b6..e45ef85 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -11,15 +11,20 @@ /* Functions: - CGLM_INLINE void glm_vec4_mulv(vec4 a, vec4 b, vec4 d); - CGLM_INLINE void glm_vec4_broadcast(float val, vec4 d); - CGLM_INLINE bool glm_vec4_eq(vec4 v, float val); - CGLM_INLINE bool glm_vec4_eq_eps(vec4 v, float val); - CGLM_INLINE bool glm_vec4_eq_all(vec4 v); - CGLM_INLINE bool glm_vec4_eqv(vec4 v1, vec4 v2); - CGLM_INLINE bool glm_vec4_eqv_eps(vec4 v1, vec4 v2); + CGLM_INLINE void glm_vec4_mulv(vec4 a, vec4 b, vec4 d); + CGLM_INLINE void glm_vec4_broadcast(float val, vec4 d); + CGLM_INLINE bool glm_vec4_eq(vec4 v, float val); + CGLM_INLINE bool glm_vec4_eq_eps(vec4 v, float val); + CGLM_INLINE bool glm_vec4_eq_all(vec4 v); + CGLM_INLINE bool glm_vec4_eqv(vec4 v1, vec4 v2); + CGLM_INLINE bool glm_vec4_eqv_eps(vec4 v1, vec4 v2); CGLM_INLINE float glm_vec4_max(vec4 v); CGLM_INLINE float glm_vec4_min(vec4 v); + CGLM_INLINE bool glm_vec4_isnan(vec4 v); + CGLM_INLINE bool glm_vec4_isinf(vec4 v); + CGLM_INLINE bool glm_vec4_isvalid(vec4 v); + CGLM_INLINE void glm_vec4_sign(vec4 v, vec4 dest); + CGLM_INLINE void glm_vec4_sqrt(vec4 v, vec4 dest); */ #ifndef cglm_vec4_ext_h @@ -150,7 +155,7 @@ float glm_vec4_max(vec4 v) { float max; - max = glm_vec_max(v); + max = glm_vec3_max(v); if (v[3] > max) max = v[3]; @@ -167,7 +172,7 @@ float glm_vec4_min(vec4 v) { float min; - min = glm_vec_min(v); + min = glm_vec3_min(v); if (v[3] < min) min = v[3]; diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index d0221d4..ec14ce3 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -5,11 +5,6 @@ * Full license can be found in the LICENSE file */ -/*! - * vec3 functions dont have suffix e.g glm_vec_dot (not glm_vec3_dot) - * all functions without suffix are vec3 functions - */ - /* Macros: glm_vec4_dup3(v, dest) diff --git a/src/vec3.c b/src/vec3.c index 541dd13..5f743b3 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -16,332 +16,332 @@ glmc_vec3(vec4 v4, vec3 dest) { CGLM_EXPORT void -glmc_vec_copy(vec3 a, vec3 dest) { - glm_vec_copy(a, dest); +glmc_vec3_copy(vec3 a, vec3 dest) { + glm_vec3_copy(a, dest); } CGLM_EXPORT void -glmc_vec_zero(vec3 v) { - glm_vec_zero(v); +glmc_vec3_zero(vec3 v) { + glm_vec3_zero(v); } CGLM_EXPORT void -glmc_vec_one(vec3 v) { - glm_vec_one(v); +glmc_vec3_one(vec3 v) { + glm_vec3_one(v); } CGLM_EXPORT float -glmc_vec_dot(vec3 a, vec3 b) { - return glm_vec_dot(a, b); +glmc_vec3_dot(vec3 a, vec3 b) { + return glm_vec3_dot(a, b); } CGLM_EXPORT void -glmc_vec_cross(vec3 a, vec3 b, vec3 d) { - glm_vec_cross(a, b, d); +glmc_vec3_cross(vec3 a, vec3 b, vec3 d) { + glm_vec3_cross(a, b, d); } CGLM_EXPORT float -glmc_vec_norm(vec3 vec) { - return glm_vec_norm(vec); +glmc_vec3_norm(vec3 vec) { + return glm_vec3_norm(vec); } CGLM_EXPORT void -glmc_vec_normalize_to(vec3 vec, vec3 dest) { - glm_vec_normalize_to(vec, dest); +glmc_vec3_normalize_to(vec3 vec, vec3 dest) { + glm_vec3_normalize_to(vec, dest); } CGLM_EXPORT void -glmc_vec_normalize(vec3 v) { - glm_vec_normalize(v); +glmc_vec3_normalize(vec3 v) { + glm_vec3_normalize(v); } CGLM_EXPORT float -glmc_vec_norm2(vec3 vec) { - return glm_vec_norm2(vec); +glmc_vec3_norm2(vec3 vec) { + return glm_vec3_norm2(vec); } CGLM_EXPORT void -glmc_vec_add(vec3 v1, vec3 v2, vec3 dest) { - glm_vec_add(v1, v2, dest); +glmc_vec3_add(vec3 v1, vec3 v2, vec3 dest) { + glm_vec3_add(v1, v2, dest); } CGLM_EXPORT void -glmc_vec_adds(vec3 v, float s, vec3 dest) { - glm_vec_adds(v, s, dest); +glmc_vec3_adds(vec3 v, float s, vec3 dest) { + glm_vec3_adds(v, s, dest); } CGLM_EXPORT void -glmc_vec_sub(vec3 a, vec3 b, vec3 dest) { - glm_vec_sub(a, b, dest); +glmc_vec3_sub(vec3 a, vec3 b, vec3 dest) { + glm_vec3_sub(a, b, dest); } CGLM_EXPORT void -glmc_vec_subs(vec3 v, float s, vec3 dest) { - glm_vec_subs(v, s, dest); +glmc_vec3_subs(vec3 v, float s, vec3 dest) { + glm_vec3_subs(v, s, dest); } CGLM_EXPORT void -glmc_vec_mul(vec3 a, vec3 b, vec3 d) { - glm_vec_mul(a, b, d); +glmc_vec3_mul(vec3 a, vec3 b, vec3 d) { + glm_vec3_mul(a, b, d); } CGLM_EXPORT void -glmc_vec_scale(vec3 v, float s, vec3 dest) { - glm_vec_scale(v, s, dest); +glmc_vec3_scale(vec3 v, float s, vec3 dest) { + glm_vec3_scale(v, s, dest); } CGLM_EXPORT void -glmc_vec_scale_as(vec3 v, float s, vec3 dest) { - glm_vec_scale_as(v, s, dest); +glmc_vec3_scale_as(vec3 v, float s, vec3 dest) { + glm_vec3_scale_as(v, s, dest); } CGLM_EXPORT void -glmc_vec_div(vec3 a, vec3 b, vec3 dest) { - glm_vec_div(a, b, dest); +glmc_vec3_div(vec3 a, vec3 b, vec3 dest) { + glm_vec3_div(a, b, dest); } CGLM_EXPORT void -glmc_vec_divs(vec3 a, float s, vec3 dest) { - glm_vec_divs(a, s, dest); +glmc_vec3_divs(vec3 a, float s, vec3 dest) { + glm_vec3_divs(a, s, dest); } CGLM_EXPORT void -glmc_vec_addadd(vec3 a, vec3 b, vec3 dest) { - glm_vec_addadd(a, b, dest); +glmc_vec3_addadd(vec3 a, vec3 b, vec3 dest) { + glm_vec3_addadd(a, b, dest); } CGLM_EXPORT void -glmc_vec_subadd(vec3 a, vec3 b, vec3 dest) { - glm_vec_subadd(a, b, dest); +glmc_vec3_subadd(vec3 a, vec3 b, vec3 dest) { + glm_vec3_subadd(a, b, dest); } CGLM_EXPORT void -glmc_vec_muladd(vec3 a, vec3 b, vec3 dest) { - glm_vec_muladd(a, b, dest); +glmc_vec3_muladd(vec3 a, vec3 b, vec3 dest) { + glm_vec3_muladd(a, b, dest); } CGLM_EXPORT void -glmc_vec_muladds(vec3 a, float s, vec3 dest) { - glm_vec_muladds(a, s, dest); +glmc_vec3_muladds(vec3 a, float s, vec3 dest) { + glm_vec3_muladds(a, s, dest); } CGLM_EXPORT void -glmc_vec_flipsign(vec3 v) { - glm_vec_flipsign(v); +glmc_vec3_flipsign(vec3 v) { + glm_vec3_flipsign(v); } CGLM_EXPORT void -glmc_vec_flipsign_to(vec3 v, vec3 dest) { - glm_vec_flipsign_to(v, dest); +glmc_vec3_flipsign_to(vec3 v, vec3 dest) { + glm_vec3_flipsign_to(v, dest); } CGLM_EXPORT void -glmc_vec_negate(vec3 v) { - glm_vec_negate(v); +glmc_vec3_negate(vec3 v) { + glm_vec3_negate(v); } CGLM_EXPORT void -glmc_vec_negate_to(vec3 v, vec3 dest) { - glm_vec_negate_to(v, dest); +glmc_vec3_negate_to(vec3 v, vec3 dest) { + glm_vec3_negate_to(v, dest); } CGLM_EXPORT void -glmc_vec_inv(vec3 v) { - glm_vec_inv(v); +glmc_vec3_inv(vec3 v) { + glm_vec3_inv(v); } CGLM_EXPORT void -glmc_vec_inv_to(vec3 v, vec3 dest) { - glm_vec_inv_to(v, dest); +glmc_vec3_inv_to(vec3 v, vec3 dest) { + glm_vec3_inv_to(v, dest); } CGLM_EXPORT float -glmc_vec_angle(vec3 v1, vec3 v2) { - return glm_vec_angle(v1, v2); +glmc_vec3_angle(vec3 v1, vec3 v2) { + return glm_vec3_angle(v1, v2); } CGLM_EXPORT void -glmc_vec_rotate(vec3 v, float angle, vec3 axis) { - glm_vec_rotate(v, angle, axis); +glmc_vec3_rotate(vec3 v, float angle, vec3 axis) { + glm_vec3_rotate(v, angle, axis); } CGLM_EXPORT void -glmc_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) { - glm_vec_rotate_m4(m, v, dest); +glmc_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest) { + glm_vec3_rotate_m4(m, v, dest); } CGLM_EXPORT void -glmc_vec_rotate_m3(mat3 m, vec3 v, vec3 dest) { - glm_vec_rotate_m3(m, v, dest); +glmc_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest) { + glm_vec3_rotate_m3(m, v, dest); } CGLM_EXPORT void -glmc_vec_proj(vec3 a, vec3 b, vec3 dest) { - glm_vec_proj(a, b, dest); +glmc_vec3_proj(vec3 a, vec3 b, vec3 dest) { + glm_vec3_proj(a, b, dest); } CGLM_EXPORT void -glmc_vec_center(vec3 v1, vec3 v2, vec3 dest) { - glm_vec_center(v1, v2, dest); +glmc_vec3_center(vec3 v1, vec3 v2, vec3 dest) { + glm_vec3_center(v1, v2, dest); } CGLM_EXPORT float -glmc_vec_distance2(vec3 v1, vec3 v2) { - return glm_vec_distance2(v1, v2); +glmc_vec3_distance2(vec3 v1, vec3 v2) { + return glm_vec3_distance2(v1, v2); } CGLM_EXPORT float -glmc_vec_distance(vec3 v1, vec3 v2) { - return glm_vec_distance(v1, v2); +glmc_vec3_distance(vec3 v1, vec3 v2) { + return glm_vec3_distance(v1, v2); } CGLM_EXPORT void -glmc_vec_maxv(vec3 v1, vec3 v2, vec3 dest) { - glm_vec_minv(v1, v2, dest); +glmc_vec3_maxv(vec3 v1, vec3 v2, vec3 dest) { + glm_vec3_minv(v1, v2, dest); } CGLM_EXPORT void -glmc_vec_minv(vec3 v1, vec3 v2, vec3 dest) { - glm_vec_maxv(v1, v2, dest); +glmc_vec3_minv(vec3 v1, vec3 v2, vec3 dest) { + glm_vec3_maxv(v1, v2, dest); } CGLM_EXPORT void -glmc_vec_clamp(vec3 v, float minVal, float maxVal) { - glm_vec_clamp(v, minVal, maxVal); +glmc_vec3_clamp(vec3 v, float minVal, float maxVal) { + glm_vec3_clamp(v, minVal, maxVal); } CGLM_EXPORT void -glmc_vec_ortho(vec3 v, vec3 dest) { - glm_vec_ortho(v, dest); +glmc_vec3_ortho(vec3 v, vec3 dest) { + glm_vec3_ortho(v, dest); } CGLM_EXPORT void -glmc_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) { - glm_vec_lerp(from, to, t, dest); +glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) { + glm_vec3_lerp(from, to, t, dest); } /* ext */ CGLM_EXPORT void -glmc_vec_mulv(vec3 a, vec3 b, vec3 d) { - glm_vec_mulv(a, b, d); +glmc_vec3_mulv(vec3 a, vec3 b, vec3 d) { + glm_vec3_mulv(a, b, d); } CGLM_EXPORT void -glmc_vec_broadcast(float val, vec3 d) { - glm_vec_broadcast(val, d); +glmc_vec3_broadcast(float val, vec3 d) { + glm_vec3_broadcast(val, d); } CGLM_EXPORT bool -glmc_vec_eq(vec3 v, float val) { - return glm_vec_eq(v, val); +glmc_vec3_eq(vec3 v, float val) { + return glm_vec3_eq(v, val); } CGLM_EXPORT bool -glmc_vec_eq_eps(vec3 v, float val) { - return glm_vec_eq_eps(v, val); +glmc_vec3_eq_eps(vec3 v, float val) { + return glm_vec3_eq_eps(v, val); } CGLM_EXPORT bool -glmc_vec_eq_all(vec3 v) { - return glm_vec_eq_all(v); +glmc_vec3_eq_all(vec3 v) { + return glm_vec3_eq_all(v); } CGLM_EXPORT bool -glmc_vec_eqv(vec3 v1, vec3 v2) { - return glm_vec_eqv(v1, v2); +glmc_vec3_eqv(vec3 v1, vec3 v2) { + return glm_vec3_eqv(v1, v2); } CGLM_EXPORT bool -glmc_vec_eqv_eps(vec3 v1, vec3 v2) { - return glm_vec_eqv_eps(v1, v2); +glmc_vec3_eqv_eps(vec3 v1, vec3 v2) { + return glm_vec3_eqv_eps(v1, v2); } CGLM_EXPORT float -glmc_vec_max(vec3 v) { - return glm_vec_max(v); +glmc_vec3_max(vec3 v) { + return glm_vec3_max(v); } CGLM_EXPORT float -glmc_vec_min(vec3 v) { - return glm_vec_min(v); +glmc_vec3_min(vec3 v) { + return glm_vec3_min(v); } CGLM_EXPORT bool -glmc_vec_isnan(vec3 v) { - return glm_vec_isnan(v); +glmc_vec3_isnan(vec3 v) { + return glm_vec3_isnan(v); } CGLM_EXPORT bool -glmc_vec_isinf(vec3 v) { - return glm_vec_isinf(v); +glmc_vec3_isinf(vec3 v) { + return glm_vec3_isinf(v); } CGLM_EXPORT bool -glmc_vec_isvalid(vec3 v) { - return glm_vec_isvalid(v); +glmc_vec3_isvalid(vec3 v) { + return glm_vec3_isvalid(v); } CGLM_EXPORT void -glmc_vec_sign(vec3 v, vec3 dest) { - glm_vec_sign(v, dest); +glmc_vec3_sign(vec3 v, vec3 dest) { + glm_vec3_sign(v, dest); } CGLM_EXPORT void -glmc_vec_sqrt(vec3 v, vec3 dest) { - glm_vec_sqrt(v, dest); +glmc_vec3_sqrt(vec3 v, vec3 dest) { + glm_vec3_sqrt(v, dest); } diff --git a/test/src/test_cam.c b/test/src/test_cam.c index f54c984..c1f31e1 100644 --- a/test/src/test_cam.c +++ b/test/src/test_cam.c @@ -16,7 +16,7 @@ test_camera_lookat(void **state) { up = {0.0f, 1.0f, 0.0f} ; - glm_vec_add(eye, dir, center); + glm_vec3_add(eye, dir, center); glm_lookat(eye, center, up, view1); glm_look(eye, dir, up, view2); diff --git a/test/src/test_clamp.c b/test/src/test_clamp.c index ee98958..70d684b 100644 --- a/test/src/test_clamp.c +++ b/test/src/test_clamp.c @@ -16,7 +16,7 @@ test_clamp(void **state) { assert_true(glm_clamp(-1.6f, 0.0f, 1.0f) == 0.0f); assert_true(glm_clamp(0.6f, 0.0f, 1.0f) == 0.6f); - glm_vec_clamp(v3, 0.0, 1.0); + glm_vec3_clamp(v3, 0.0, 1.0); glm_vec4_clamp(v4, 1.5, 3.0); assert_true(v3[0] == 1.0f); diff --git a/test/src/test_quat.c b/test/src/test_quat.c index 74d12b5..62e2306 100644 --- a/test/src/test_quat.c +++ b/test/src/test_quat.c @@ -128,7 +128,7 @@ test_quat(void **state) { axis[1] = sinf(glm_rad(-90.0f) * 0.5f) * 1.0f; axis[2] = 0.0f; - assert_true(glm_vec_eqv_eps(imag, axis)); + assert_true(glm_vec3_eqv_eps(imag, axis)); /* 9.2 axis */ glm_quat_axis(q4, axis); @@ -143,7 +143,7 @@ test_quat(void **state) { v1[0] = 0.0f; v1[1] = 0.0f; v1[2] = -1.0f; v2[0] = 0.0f; v2[1] = 0.0f; v2[2] = -1.0f; - glm_vec_rotate(v1, glm_rad(90.0f), (vec3){1.0f, 0.0f, 0.0f}); + glm_vec3_rotate(v1, glm_rad(90.0f), (vec3){1.0f, 0.0f, 0.0f}); glm_quatv(q3, glm_rad(90.0f), (vec3){1.0f, 0.0f, 0.0f}); glm_vec4_scale(q3, 1.5, q3); diff --git a/test/src/test_vec3.c b/test/src/test_vec3.c index dd0c55d..6cfc593 100644 --- a/test/src/test_vec3.c +++ b/test/src/test_vec3.c @@ -14,64 +14,64 @@ test_vec3(void **state) { vec3 v, v1, v2; /* test zero */ - glm_vec_zero(v); + glm_vec3_zero(v); test_assert_vec3_eq(GLM_VEC3_ZERO, v); /* test one */ - glm_vec_one(v); + glm_vec3_one(v); test_assert_vec3_eq(GLM_VEC3_ONE, v); /* adds, subs, div, divs, mul */ - glm_vec_add(v, GLM_VEC3_ONE, v); - assert_true(glmc_vec_eq_eps(v, 2)); + glm_vec3_add(v, GLM_VEC3_ONE, v); + assert_true(glmc_vec3_eq_eps(v, 2)); - glm_vec_adds(v, 10, v); - assert_true(glmc_vec_eq_eps(v, 12)); + glm_vec3_adds(v, 10, v); + assert_true(glmc_vec3_eq_eps(v, 12)); - glm_vec_sub(v, GLM_VEC3_ONE, v); - assert_true(glmc_vec_eq_eps(v, 11)); + glm_vec3_sub(v, GLM_VEC3_ONE, v); + assert_true(glmc_vec3_eq_eps(v, 11)); - glm_vec_subs(v, 1, v); - assert_true(glmc_vec_eq_eps(v, 10)); + glm_vec3_subs(v, 1, v); + assert_true(glmc_vec3_eq_eps(v, 10)); - glm_vec_broadcast(2, v1); - glm_vec_div(v, v1, v); - assert_true(glmc_vec_eq_eps(v, 5)); + glm_vec3_broadcast(2, v1); + glm_vec3_div(v, v1, v); + assert_true(glmc_vec3_eq_eps(v, 5)); - glm_vec_divs(v, 0.5, v); - assert_true(glmc_vec_eq_eps(v, 10)); + glm_vec3_divs(v, 0.5, v); + assert_true(glmc_vec3_eq_eps(v, 10)); - glm_vec_mul(v, v1, v); - assert_true(glmc_vec_eq_eps(v, 20)); + glm_vec3_mul(v, v1, v); + assert_true(glmc_vec3_eq_eps(v, 20)); - glm_vec_scale(v, 0.5, v); - assert_true(glmc_vec_eq_eps(v, 10)); + glm_vec3_scale(v, 0.5, v); + assert_true(glmc_vec3_eq_eps(v, 10)); - glm_vec_normalize_to(v, v1); - glm_vec_scale(v1, 0.8, v1); - glm_vec_scale_as(v, 0.8, v); + glm_vec3_normalize_to(v, v1); + glm_vec3_scale(v1, 0.8, v1); + glm_vec3_scale_as(v, 0.8, v); test_assert_vec3_eq(v1, v); /* addadd, subadd, muladd */ - glm_vec_one(v); + glm_vec3_one(v); - glm_vec_addadd(GLM_VEC3_ONE, GLM_VEC3_ONE, v); - assert_true(glmc_vec_eq_eps(v, 3)); + glm_vec3_addadd(GLM_VEC3_ONE, GLM_VEC3_ONE, v); + assert_true(glmc_vec3_eq_eps(v, 3)); - glm_vec_subadd(GLM_VEC3_ONE, GLM_VEC3_ZERO, v); - assert_true(glmc_vec_eq_eps(v, 4)); + glm_vec3_subadd(GLM_VEC3_ONE, GLM_VEC3_ZERO, v); + assert_true(glmc_vec3_eq_eps(v, 4)); - glm_vec_broadcast(2, v1); - glm_vec_broadcast(3, v2); - glm_vec_muladd(v1, v2, v); - assert_true(glmc_vec_eq_eps(v, 10)); + glm_vec3_broadcast(2, v1); + glm_vec3_broadcast(3, v2); + glm_vec3_muladd(v1, v2, v); + assert_true(glmc_vec3_eq_eps(v, 10)); /* rotate */ - glm_vec_copy(GLM_YUP, v); + glm_vec3_copy(GLM_YUP, v); glm_rotate_make(rot1, glm_rad(90), GLM_XUP); - glm_vec_rotate_m4(rot1, v, v1); + glm_vec3_rotate_m4(rot1, v, v1); glm_mat4_pick3(rot1, rot1m3); - glm_vec_rotate_m3(rot1m3, v, v2); + glm_vec3_rotate_m3(rot1m3, v, v2); test_assert_vec3_eq(v1, v2); test_assert_vec3_eq(v1, GLM_ZUP); From b4bf8f3537b01039ebb1c46230b856efe5d4708a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 29 Nov 2018 09:07:48 +0300 Subject: [PATCH 210/292] vec: rename `glm_vec_` to `glm_vec3_` (continue) * add missing functions to vec4 * update docs --- README.md | 4 +- docs/source/api.rst | 4 +- docs/source/cam.rst | 2 +- docs/source/frustum.rst | 2 +- docs/source/troubleshooting.rst | 2 +- docs/source/vec3-ext.rst | 56 +++++----- docs/source/vec3.rst | 181 +++++++++++++++++--------------- docs/source/vec4.rst | 27 ++++- include/cglm/affine.h | 6 +- include/cglm/call/vec3.h | 5 + include/cglm/call/vec4.h | 10 +- include/cglm/mat4.h | 2 - include/cglm/quat.h | 4 +- include/cglm/vec3.h | 39 +------ include/cglm/vec4-ext.h | 24 ++--- include/cglm/vec4.h | 47 ++++----- src/vec3.c | 12 --- src/vec4.c | 8 +- 18 files changed, 214 insertions(+), 221 deletions(-) diff --git a/README.md b/README.md index 9567960..c9d92c0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Documentation Status](https://readthedocs.org/projects/cglm/badge/?version=latest)](http://cglm.readthedocs.io/en/latest/?badge=latest) [![Coverage Status](https://coveralls.io/repos/github/recp/cglm/badge.svg?branch=master)](https://coveralls.io/github/recp/cglm?branch=master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/6a62b37d5f214f178ebef269dc4a6bf1)](https://www.codacy.com/app/recp/cglm?utm_source=github.com&utm_medium=referral&utm_content=recp/cglm&utm_campaign=Badge_Grade) -[![Backers on Open Collective](https://opencollective.com/cglm/backers/badge.svg)](#backers) +[![Backers on Open Collective](https://opencollective.com/cglm/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/cglm/sponsors/badge.svg)](#sponsors) The original glm library is for C++ only (templates, namespaces, classes...), this library targeted to C99 but currently you can use it for C89 safely by language extensions e.g `__restrict` @@ -19,7 +19,7 @@ Complete documentation: http://cglm.readthedocs.io - _dup (duplicate) is changed to _copy. For instance `glm_vec_dup -> glm_vec3_copy` - OpenGL related functions are dropped to make this lib platform/third-party independent - make sure you have latest version and feel free to report bugs, troubles -- **[bugfix]** euler angles was implemented in reverse order (extrinsic) it was fixed, now they are intrinsic. Make sure that +- **[bugfix]** euler angles was implemented in reverse order (extrinsic) it was fixed, now they are intrinsic. Make sure that you have the latest version - **[major change]** by starting v0.4.0, quaternions are stored as [x, y, z, w], it was [w, x, y, z] in v0.3.5 and earlier versions - **[api rename]** by starting v0.4.5, **glm_simd** functions are renamed to **glmm_** diff --git a/docs/source/api.rst b/docs/source/api.rst index d0e4721..e88b426 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -5,14 +5,14 @@ Some functions may exist twice, once for their namespace and once for global namespace to make easier to write very common functions -For instance, in general we use :code:`glm_vec_dot` to get dot product +For instance, in general we use :code:`glm_vec3_dot` to get dot product of two **vec3**. Now we can also do this with :code:`glm_dot`, same for *_cross* and so on... The original function stays where it is, the function in global namespace of same name is just an alias, so there is no call version of those functions. e.g there is no func like :code:`glmc_dot` because *glm_dot* is just alias for -:code:`glm_vec_dot` +:code:`glm_vec3_dot` By including **cglm/cglm.h** header you will include all inline version of functions. Since functions in this header[s] are inline you don't need to diff --git a/docs/source/cam.rst b/docs/source/cam.rst index 79b2bd4..6e4cc94 100644 --- a/docs/source/cam.rst +++ b/docs/source/cam.rst @@ -9,7 +9,7 @@ There are many convenient functions for camera. For instance :c:func:`glm_look` is just wrapper for :c:func:`glm_lookat`. Sometimes you only have direction instead of target, so that makes easy to build view matrix using direction. There is also :c:func:`glm_look_anyup` function which can help build view matrix -without providing UP axis. It uses :c:func:`glm_vec_ortho` to get a UP axis and +without providing UP axis. It uses :c:func:`glm_vec3_ortho` to get a UP axis and builds view matrix. You can also *_default* versions of ortho and perspective to build projection diff --git a/docs/source/frustum.rst b/docs/source/frustum.rst index 0ace87d..b58913c 100644 --- a/docs/source/frustum.rst +++ b/docs/source/frustum.rst @@ -127,7 +127,7 @@ Functions documentation .. code-block:: c for (j = 0; j < 4; j++) { - glm_vec_center(corners[i], corners[i + 4], centerCorners[i]); + glm_vec3_center(corners[i], corners[i + 4], centerCorners[i]); } corners[i + 4] is far of corners[i] point. diff --git a/docs/source/troubleshooting.rst b/docs/source/troubleshooting.rst index c897dc2..e4cea9f 100644 --- a/docs/source/troubleshooting.rst +++ b/docs/source/troubleshooting.rst @@ -62,7 +62,7 @@ Wrong Results: Again, you may used wrong function. -For instance if you use **glm_normalize()** or **glm_vec_normalize()** for **vec4**, +For instance if you use **glm_normalize()** or **glm_vec3_normalize()** for **vec4**, it will assume that passed param is **vec3** and will normalize it for **vec3**. Since you need to **vec4** to be normalized in your case, you will get wrong results. diff --git a/docs/source/vec3-ext.rst b/docs/source/vec3-ext.rst index c2c0bfc..88f3699 100644 --- a/docs/source/vec3-ext.rst +++ b/docs/source/vec3-ext.rst @@ -14,25 +14,25 @@ Table of contents (click to go): Functions: -1. :c:func:`glm_vec_mulv` -#. :c:func:`glm_vec_broadcast` -#. :c:func:`glm_vec_eq` -#. :c:func:`glm_vec_eq_eps` -#. :c:func:`glm_vec_eq_all` -#. :c:func:`glm_vec_eqv` -#. :c:func:`glm_vec_eqv_eps` -#. :c:func:`glm_vec_max` -#. :c:func:`glm_vec_min` -#. :c:func:`glm_vec_isnan` -#. :c:func:`glm_vec_isinf` -#. :c:func:`glm_vec_isvalid` -#. :c:func:`glm_vec_sign` -#. :c:func:`glm_vec_sqrt` +1. :c:func:`glm_vec3_mulv` +#. :c:func:`glm_vec3_broadcast` +#. :c:func:`glm_vec3_eq` +#. :c:func:`glm_vec3_eq_eps` +#. :c:func:`glm_vec3_eq_all` +#. :c:func:`glm_vec3_eqv` +#. :c:func:`glm_vec3_eqv_eps` +#. :c:func:`glm_vec3_max` +#. :c:func:`glm_vec3_min` +#. :c:func:`glm_vec3_isnan` +#. :c:func:`glm_vec3_isinf` +#. :c:func:`glm_vec3_isvalid` +#. :c:func:`glm_vec3_sign` +#. :c:func:`glm_vec3_sqrt` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ -.. c:function:: void glm_vec_mulv(vec3 a, vec3 b, vec3 d) +.. c:function:: void glm_vec3_mulv(vec3 a, vec3 b, vec3 d) multiplies individual items @@ -41,7 +41,7 @@ Functions documentation | *[in]* **b** vec2 | *[out]* **d** destination (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]) -.. c:function:: void glm_vec_broadcast(float val, vec3 d) +.. c:function:: void glm_vec3_broadcast(float val, vec3 d) fill a vector with specified value @@ -49,7 +49,7 @@ Functions documentation | *[in]* **val** value | *[out]* **dest** destination -.. c:function:: bool glm_vec_eq(vec3 v, float val) +.. c:function:: bool glm_vec3_eq(vec3 v, float val) check if vector is equal to value (without epsilon) @@ -57,7 +57,7 @@ Functions documentation | *[in]* **v** vector | *[in]* **val** value -.. c:function:: bool glm_vec_eq_eps(vec3 v, float val) +.. c:function:: bool glm_vec3_eq_eps(vec3 v, float val) check if vector is equal to value (with epsilon) @@ -65,14 +65,14 @@ Functions documentation | *[in]* **v** vector | *[in]* **val** value -.. c:function:: bool glm_vec_eq_all(vec3 v) +.. c:function:: bool glm_vec3_eq_all(vec3 v) check if vectors members are equal (without epsilon) Parameters: | *[in]* **v** vector -.. c:function:: bool glm_vec_eqv(vec3 v1, vec3 v2) +.. c:function:: bool glm_vec3_eqv(vec3 v1, vec3 v2) check if vector is equal to another (without epsilon) vector @@ -80,7 +80,7 @@ Functions documentation | *[in]* **vec** vector 1 | *[in]* **vec** vector 2 -.. c:function:: bool glm_vec_eqv_eps(vec3 v1, vec3 v2) +.. c:function:: bool glm_vec3_eqv_eps(vec3 v1, vec3 v2) check if vector is equal to another (with epsilon) @@ -88,21 +88,21 @@ Functions documentation | *[in]* **v1** vector1 | *[in]* **v2** vector2 -.. c:function:: float glm_vec_max(vec3 v) +.. c:function:: float glm_vec3_max(vec3 v) max value of vector Parameters: | *[in]* **v** vector -.. c:function:: float glm_vec_min(vec3 v) +.. c:function:: float glm_vec3_min(vec3 v) min value of vector Parameters: | *[in]* **v** vector -.. c:function:: bool glm_vec_isnan(vec3 v) +.. c:function:: bool glm_vec3_isnan(vec3 v) | check if one of items is NaN (not a number) | you should only use this in DEBUG mode or very critical asserts @@ -110,7 +110,7 @@ Functions documentation Parameters: | *[in]* **v** vector -.. c:function:: bool glm_vec_isinf(vec3 v) +.. c:function:: bool glm_vec3_isinf(vec3 v) | check if one of items is INFINITY | you should only use this in DEBUG mode or very critical asserts @@ -118,7 +118,7 @@ Functions documentation Parameters: | *[in]* **v** vector -.. c:function:: bool glm_vec_isvalid(vec3 v) +.. c:function:: bool glm_vec3_isvalid(vec3 v) | check if all items are valid number | you should only use this in DEBUG mode or very critical asserts @@ -126,7 +126,7 @@ Functions documentation Parameters: | *[in]* **v** vector -.. c:function:: void glm_vec_sign(vec3 v, vec3 dest) +.. c:function:: void glm_vec3_sign(vec3 v, vec3 dest) get sign of 32 bit float as +1, -1, 0 @@ -134,7 +134,7 @@ Functions documentation | *[in]* **v** vector | *[out]* **dest** sign vector (only keeps signs as -1, 0, -1) -.. c:function:: void glm_vec_sqrt(vec3 v, vec3 dest) +.. c:function:: void glm_vec3_sqrt(vec3 v, vec3 dest) square root of each vector item diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index 252c8f5..e452550 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -5,9 +5,14 @@ vec3 Header: cglm/vec3.h + **Important:** *cglm* was used **glm_vec_** namespace for vec3 functions until + **v0.5.0**, since **v0.5.0** cglm uses **glm_vec3_** namespace for vec3. + + Also `glm_vec3_flipsign` has been renamed to `glm_vec3_negate` + We mostly use vectors in graphics math, to make writing code faster and easy to read, some *vec3* functions are aliased in global namespace. -For instance :c:func:`glm_dot` is alias of :c:func:`glm_vec_dot`, +For instance :c:func:`glm_dot` is alias of :c:func:`glm_vec3_dot`, alias means inline wrapper here. There is no call verison of alias functions There are also functions for rotating *vec3* vector. **_m4**, **_m3** prefixes @@ -18,7 +23,7 @@ Table of contents (click to go): Macros: -1. glm_vec_dup(v, dest) +1. glm_vec3_dup(v, dest) #. GLM_VEC3_ONE_INIT #. GLM_VEC3_ZERO_INIT #. GLM_VEC3_ONE @@ -30,47 +35,47 @@ Macros: Functions: 1. :c:func:`glm_vec3` -#. :c:func:`glm_vec_copy` -#. :c:func:`glm_vec_zero` -#. :c:func:`glm_vec_one` -#. :c:func:`glm_vec_dot` -#. :c:func:`glm_vec_cross` -#. :c:func:`glm_vec_norm2` -#. :c:func:`glm_vec_norm` -#. :c:func:`glm_vec_add` -#. :c:func:`glm_vec_adds` -#. :c:func:`glm_vec_sub` -#. :c:func:`glm_vec_subs` -#. :c:func:`glm_vec_mul` -#. :c:func:`glm_vec_scale` -#. :c:func:`glm_vec_scale_as` -#. :c:func:`glm_vec_div` -#. :c:func:`glm_vec_divs` -#. :c:func:`glm_vec_addadd` -#. :c:func:`glm_vec_subadd` -#. :c:func:`glm_vec_muladd` -#. :c:func:`glm_vec_muladds` -#. :c:func:`glm_vec_flipsign` -#. :c:func:`glm_vec_flipsign_to` -#. :c:func:`glm_vec_negate` -#. :c:func:`glm_vec_negate_to` -#. :c:func:`glm_vec_inv` -#. :c:func:`glm_vec_inv_to` -#. :c:func:`glm_vec_normalize` -#. :c:func:`glm_vec_normalize_to` -#. :c:func:`glm_vec_distance2` -#. :c:func:`glm_vec_distance` -#. :c:func:`glm_vec_angle` -#. :c:func:`glm_vec_rotate` -#. :c:func:`glm_vec_rotate_m4` -#. :c:func:`glm_vec_rotate_m3` -#. :c:func:`glm_vec_proj` -#. :c:func:`glm_vec_center` -#. :c:func:`glm_vec_maxv` -#. :c:func:`glm_vec_minv` -#. :c:func:`glm_vec_ortho` -#. :c:func:`glm_vec_clamp` -#. :c:func:`glm_vec_lerp` +#. :c:func:`glm_vec3_copy` +#. :c:func:`glm_vec3_zero` +#. :c:func:`glm_vec3_one` +#. :c:func:`glm_vec3_dot` +#. :c:func:`glm_vec3_cross` +#. :c:func:`glm_vec3_norm2` +#. :c:func:`glm_vec3_norm` +#. :c:func:`glm_vec3_add` +#. :c:func:`glm_vec3_adds` +#. :c:func:`glm_vec3_sub` +#. :c:func:`glm_vec3_subs` +#. :c:func:`glm_vec3_mul` +#. :c:func:`glm_vec3_scale` +#. :c:func:`glm_vec3_scale_as` +#. :c:func:`glm_vec3_div` +#. :c:func:`glm_vec3_divs` +#. :c:func:`glm_vec3_addadd` +#. :c:func:`glm_vec3_subadd` +#. :c:func:`glm_vec3_muladd` +#. :c:func:`glm_vec3_muladds` +#. :c:func:`glm_vec3_flipsign` +#. :c:func:`glm_vec3_flipsign_to` +#. :c:func:`glm_vec3_negate` +#. :c:func:`glm_vec3_negate_to` +#. :c:func:`glm_vec3_inv` +#. :c:func:`glm_vec3_inv_to` +#. :c:func:`glm_vec3_normalize` +#. :c:func:`glm_vec3_normalize_to` +#. :c:func:`glm_vec3_distance2` +#. :c:func:`glm_vec3_distance` +#. :c:func:`glm_vec3_angle` +#. :c:func:`glm_vec3_rotate` +#. :c:func:`glm_vec3_rotate_m4` +#. :c:func:`glm_vec3_rotate_m3` +#. :c:func:`glm_vec3_proj` +#. :c:func:`glm_vec3_center` +#. :c:func:`glm_vec3_maxv` +#. :c:func:`glm_vec3_minv` +#. :c:func:`glm_vec3_ortho` +#. :c:func:`glm_vec3_clamp` +#. :c:func:`glm_vec3_lerp` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -83,7 +88,7 @@ Functions documentation | *[in]* **v4** vector4 | *[out]* **dest** destination -.. c:function:: void glm_vec_copy(vec3 a, vec3 dest) +.. c:function:: void glm_vec3_copy(vec3 a, vec3 dest) copy all members of [a] to [dest] @@ -91,21 +96,21 @@ Functions documentation | *[in]* **a** source | *[out]* **dest** destination -.. c:function:: void glm_vec_zero(vec3 v) +.. c:function:: void glm_vec3_zero(vec3 v) makes all members 0.0f (zero) Parameters: | *[in, out]* **v** vector -.. c:function:: void glm_vec_one(vec3 v) +.. c:function:: void glm_vec3_one(vec3 v) makes all members 1.0f (one) Parameters: | *[in, out]* **v** vector -.. c:function:: float glm_vec_dot(vec3 a, vec3 b) +.. c:function:: float glm_vec3_dot(vec3 a, vec3 b) dot product of vec3 @@ -116,7 +121,7 @@ Functions documentation Returns: dot product -.. c:function:: void glm_vec_cross(vec3 a, vec3 b, vec3 d) +.. c:function:: void glm_vec3_cross(vec3 a, vec3 b, vec3 d) cross product @@ -125,7 +130,7 @@ Functions documentation | *[in]* **b** source 2 | *[out]* **d** destination -.. c:function:: float glm_vec_norm2(vec3 v) +.. c:function:: float glm_vec3_norm2(vec3 v) norm * norm (magnitude) of vector @@ -139,14 +144,14 @@ Functions documentation Returns: square of norm / magnitude -.. c:function:: float glm_vec_norm(vec3 vec) +.. c:function:: float glm_vec3_norm(vec3 vec) norm (magnitude) of vec3 Parameters: | *[in]* **vec** vector -.. c:function:: void glm_vec_add(vec3 a, vec3 b, vec3 dest) +.. c:function:: void glm_vec3_add(vec3 a, vec3 b, vec3 dest) add a vector to b vector store result in dest @@ -155,7 +160,7 @@ Functions documentation | *[in]* **b** vector2 | *[out]* **dest** destination vector -.. c:function:: void glm_vec_adds(vec3 a, float s, vec3 dest) +.. c:function:: void glm_vec3_adds(vec3 a, float s, vec3 dest) add scalar to v vector store result in dest (d = v + vec(s)) @@ -164,7 +169,7 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** destination vector -.. c:function:: void glm_vec_sub(vec3 v1, vec3 v2, vec3 dest) +.. c:function:: void glm_vec3_sub(vec3 v1, vec3 v2, vec3 dest) subtract b vector from a vector store result in dest (d = v1 - v2) @@ -173,7 +178,7 @@ Functions documentation | *[in]* **b** vector2 | *[out]* **dest** destination vector -.. c:function:: void glm_vec_subs(vec3 v, float s, vec3 dest) +.. c:function:: void glm_vec3_subs(vec3 v, float s, vec3 dest) subtract scalar from v vector store result in dest (d = v - vec(s)) @@ -182,7 +187,7 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** destination vector -.. c:function:: void glm_vec_mul(vec3 a, vec3 b, vec3 d) +.. c:function:: void glm_vec3_mul(vec3 a, vec3 b, vec3 d) multiply two vector (component-wise multiplication) @@ -191,7 +196,7 @@ Functions documentation | *[in]* **b** scalar | *[out]* **d** result = (a[0] * b[0], a[1] * b[1], a[2] * b[2]) -.. c:function:: void glm_vec_scale(vec3 v, float s, vec3 dest) +.. c:function:: void glm_vec3_scale(vec3 v, float s, vec3 dest) multiply/scale vec3 vector with scalar: result = v * s @@ -201,7 +206,7 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** destination vector -.. c:function:: void glm_vec_scale_as(vec3 v, float s, vec3 dest) +.. c:function:: void glm_vec3_scale_as(vec3 v, float s, vec3 dest) make vec3 vector scale as specified: result = unit(v) * s @@ -210,7 +215,7 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** destination vector -.. c:function:: void glm_vec_div(vec3 a, vec3 b, vec3 dest) +.. c:function:: void glm_vec3_div(vec3 a, vec3 b, vec3 dest) div vector with another component-wise division: d = a / b @@ -219,7 +224,7 @@ Functions documentation | *[in]* **b** vector 2 | *[out]* **dest** result = (a[0] / b[0], a[1] / b[1], a[2] / b[2]) -.. c:function:: void glm_vec_divs(vec3 v, float s, vec3 dest) +.. c:function:: void glm_vec3_divs(vec3 v, float s, vec3 dest) div vector with scalar: d = v / s @@ -228,7 +233,7 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s]) -.. c:function:: void glm_vec_addadd(vec3 a, vec3 b, vec3 dest) +.. c:function:: void glm_vec3_addadd(vec3 a, vec3 b, vec3 dest) | add two vectors and add result to sum | it applies += operator so dest must be initialized @@ -238,7 +243,7 @@ Functions documentation | *[in]* **b** vector 2 | *[out]* **dest** dest += (a + b) -.. c:function:: void glm_vec_subadd(vec3 a, vec3 b, vec3 dest) +.. c:function:: void glm_vec3_subadd(vec3 a, vec3 b, vec3 dest) | sub two vectors and add result to sum | it applies += operator so dest must be initialized @@ -248,7 +253,7 @@ Functions documentation | *[in]* **b** vector 2 | *[out]* **dest** dest += (a - b) -.. c:function:: void glm_vec_muladd(vec3 a, vec3 b, vec3 dest) +.. c:function:: void glm_vec3_muladd(vec3 a, vec3 b, vec3 dest) | mul two vectors and add result to sum | it applies += operator so dest must be initialized @@ -258,7 +263,7 @@ Functions documentation | *[in]* **b** vector 2 | *[out]* **dest** dest += (a * b) -.. c:function:: void glm_vec_muladds(vec3 a, float s, vec3 dest) +.. c:function:: void glm_vec3_muladds(vec3 a, float s, vec3 dest) | mul vector with scalar and add result to sum | it applies += operator so dest must be initialized @@ -268,29 +273,33 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** dest += (a * b) -.. c:function:: void glm_vec_flipsign(vec3 v) +.. c:function:: void glm_vec3_flipsign(vec3 v) - flip sign of all vec3 members + **DEPRACATED!** + + use :c:func:`glm_vec3_negate` Parameters: | *[in, out]* **v** vector -.. c:function:: void glm_vec_flipsign_to(vec3 v, vec3 dest) +.. c:function:: void glm_vec3_flipsign_to(vec3 v, vec3 dest) - flip sign of all vec3 members and store result in dest + **DEPRACATED!** + + use :c:func:`glm_vec3_negate_to` Parameters: | *[in]* **v** vector | *[out]* **dest** negated vector -.. c:function:: void glm_vec_negate(vec3 v) +.. c:function:: void glm_vec3_negate(vec3 v) negate vector components Parameters: | *[in, out]* **v** vector -.. c:function:: void glm_vec_negate_to(vec3 v, vec3 dest) +.. c:function:: void glm_vec3_negate_to(vec3 v, vec3 dest) negate vector components and store result in dest @@ -298,14 +307,14 @@ Functions documentation | *[in]* **v** vector | *[out]* **dest** negated vector -.. c:function:: void glm_vec_inv(vec3 v) +.. c:function:: void glm_vec3_inv(vec3 v) make vector as inverse/opposite of itself Parameters: | *[in, out]* **v** vector -.. c:function:: void glm_vec_inv_to(vec3 v, vec3 dest) +.. c:function:: void glm_vec3_inv_to(vec3 v, vec3 dest) inverse/opposite vector @@ -313,14 +322,14 @@ Functions documentation | *[in]* **v** source | *[out]* **dest** destination -.. c:function:: void glm_vec_normalize(vec3 v) +.. c:function:: void glm_vec3_normalize(vec3 v) normalize vec3 and store result in same vec Parameters: | *[in, out]* **v** vector -.. c:function:: void glm_vec_normalize_to(vec3 vec, vec3 dest) +.. c:function:: void glm_vec3_normalize_to(vec3 vec, vec3 dest) normalize vec3 to dest @@ -328,7 +337,7 @@ Functions documentation | *[in]* **vec** source | *[out]* **dest** destination -.. c:function:: float glm_vec_angle(vec3 v1, vec3 v2) +.. c:function:: float glm_vec3_angle(vec3 v1, vec3 v2) angle betwen two vector @@ -339,7 +348,7 @@ Functions documentation Return: | angle as radians -.. c:function:: void glm_vec_rotate(vec3 v, float angle, vec3 axis) +.. c:function:: void glm_vec3_rotate(vec3 v, float angle, vec3 axis) rotate vec3 around axis by angle using Rodrigues' rotation formula @@ -348,7 +357,7 @@ Functions documentation | *[in]* **axis** axis vector (will be normalized) | *[out]* **angle** angle (radians) -.. c:function:: void glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest) +.. c:function:: void glm_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest) apply rotation matrix to vector @@ -357,7 +366,7 @@ Functions documentation | *[in]* **v** vector | *[out]* **dest** rotated vector -.. c:function:: void glm_vec_rotate_m3(mat3 m, vec3 v, vec3 dest) +.. c:function:: void glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest) apply rotation matrix to vector @@ -366,7 +375,7 @@ Functions documentation | *[in]* **v** vector | *[out]* **dest** rotated vector -.. c:function:: void glm_vec_proj(vec3 a, vec3 b, vec3 dest) +.. c:function:: void glm_vec3_proj(vec3 a, vec3 b, vec3 dest) project a vector onto b vector @@ -375,7 +384,7 @@ Functions documentation | *[in]* **b** vector2 | *[out]* **dest** projected vector -.. c:function:: void glm_vec_center(vec3 v1, vec3 v2, vec3 dest) +.. c:function:: void glm_vec3_center(vec3 v1, vec3 v2, vec3 dest) find center point of two vector @@ -384,7 +393,7 @@ Functions documentation | *[in]* **v2** vector2 | *[out]* **dest** center point -.. c:function:: float glm_vec_distance2(vec3 v1, vec3 v2) +.. c:function:: float glm_vec3_distance2(vec3 v1, vec3 v2) squared distance between two vectors @@ -395,7 +404,7 @@ Functions documentation Returns: | squared distance (distance * distance) -.. c:function:: float glm_vec_distance(vec3 v1, vec3 v2) +.. c:function:: float glm_vec3_distance(vec3 v1, vec3 v2) distance between two vectors @@ -406,7 +415,7 @@ Functions documentation Returns: | distance -.. c:function:: void glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest) +.. c:function:: void glm_vec3_maxv(vec3 v1, vec3 v2, vec3 dest) max values of vectors @@ -415,7 +424,7 @@ Functions documentation | *[in]* **v2** vector2 | *[out]* **dest** destination -.. c:function:: void glm_vec_minv(vec3 v1, vec3 v2, vec3 dest) +.. c:function:: void glm_vec3_minv(vec3 v1, vec3 v2, vec3 dest) min values of vectors @@ -424,7 +433,7 @@ Functions documentation | *[in]* **v2** vector2 | *[out]* **dest** destination -.. c:function:: void glm_vec_ortho(vec3 v, vec3 dest) +.. c:function:: void glm_vec3_ortho(vec3 v, vec3 dest) possible orthogonal/perpendicular vector @@ -432,7 +441,7 @@ Functions documentation | *[in]* **mat** vector | *[out]* **dest** orthogonal/perpendicular vector -.. c:function:: void glm_vec_clamp(vec3 v, float minVal, float maxVal) +.. c:function:: void glm_vec3_clamp(vec3 v, float minVal, float maxVal) constrain a value to lie between two further values @@ -441,7 +450,7 @@ Functions documentation | *[in]* **minVal** minimum value | *[in]* **maxVal** maximum value -.. c:function:: void glm_vec_lerp(vec3 from, vec3 to, float t, vec3 dest) +.. c:function:: void glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) linear interpolation between two vector diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index 947a2da..cf025e6 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -44,7 +44,9 @@ Functions: #. :c:func:`glm_vec4_muladd` #. :c:func:`glm_vec4_muladds` #. :c:func:`glm_vec4_flipsign` -#. :c:func:`glm_vec_flipsign_to` +#. :c:func:`glm_vec4_flipsign_to` +#. :c:func:`glm_vec4_negate` +#. :c:func:`glm_vec4_negate_to` #. :c:func:`glm_vec4_inv` #. :c:func:`glm_vec4_inv_to` #. :c:func:`glm_vec4_normalize` @@ -262,14 +264,33 @@ Functions documentation .. c:function:: void glm_vec4_flipsign(vec4 v) - flip sign of all vec4 members + **DEPRACATED!** + + use :c:func:`glm_vec4_negate` Parameters: | *[in, out]* **v** vector .. c:function:: void glm_vec4_flipsign_to(vec4 v, vec4 dest) - flip sign of all vec4 members and store result in dest + **DEPRACATED!** + + use :c:func:`glm_vec4_negate_TO` + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** negated vector + +.. c:function:: void glm_vec4_negate(vec4 v) + + negate vector components + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec4_negate_to(vec4 v, vec4 dest) + + negate vector components and store result in dest Parameters: | *[in]* **v** vector diff --git a/include/cglm/affine.h b/include/cglm/affine.h index 364ed20..84ead4b 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -464,9 +464,9 @@ glm_decompose_rs(mat4 m, mat4 r, vec3 s) { is -1, then negate the matrix and the scaling factors. */ glm_vec3_cross(m[0], m[1], v); if (glm_vec3_dot(v, m[2]) < 0.0f) { - glm_vec4_flipsign(r[0]); - glm_vec4_flipsign(r[1]); - glm_vec4_flipsign(r[2]); + glm_vec4_negate(r[0]); + glm_vec4_negate(r[1]); + glm_vec4_negate(r[2]); glm_vec3_negate(s); } } diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 1cd2e08..89e2fe2 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -13,6 +13,11 @@ extern "C" { #include "../cglm.h" +/* DEPRECATED! use _copy, _ucopy versions */ +#define glmc_vec_dup(v, dest) glmc_vec3_copy(v, dest) +#define glmc_vec3_flipsign(v) glmc_vec3_negate(v) +#define glmc_vec3_flipsign_to(v, dest) glmc_vec3_negate_to(v, dest) + CGLM_EXPORT void glmc_vec3(vec4 v4, vec3 dest); diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index 729a3f2..78c39ae 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -14,8 +14,10 @@ extern "C" { #include "../cglm.h" /* DEPRECATED! use _copy, _ucopy versions */ -#define glmc_vec4_dup3(v, dest) glmc_vec4_copy3(v, dest) -#define glmc_vec4_dup(v, dest) glmc_vec4_copy(v, dest) +#define glmc_vec4_dup3(v, dest) glmc_vec4_copy3(v, dest) +#define glmc_vec4_dup(v, dest) glmc_vec4_copy(v, dest) +#define glmc_vec4_flipsign(v) glmc_vec4_negate(v) +#define glmc_vec4_flipsign_to(v, dest) glmc_vec4_negate_to(v, dest) CGLM_EXPORT void @@ -115,11 +117,11 @@ glmc_vec4_muladds(vec4 a, float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_flipsign(vec4 v); +glmc_vec4_negate(vec4 v); CGLM_EXPORT void -glmc_vec4_flipsign_to(vec4 v, vec4 dest); +glmc_vec4_negate_to(vec4 v, vec4 dest); CGLM_EXPORT void diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index dc8ef88..8ce027d 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -16,8 +16,6 @@ GLM_MAT4_ZERO_INIT GLM_MAT4_IDENTITY GLM_MAT4_ZERO - glm_mat4_udup(mat, dest) - glm_mat4_dup(mat, dest) Functions: CGLM_INLINE void glm_mat4_ucopy(mat4 mat, mat4 dest); diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 37aba8d..eee4f53 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -273,7 +273,7 @@ glm_quat_dot(versor p, versor q) { CGLM_INLINE void glm_quat_conjugate(versor q, versor dest) { - glm_vec4_flipsign_to(q, dest); + glm_vec4_negate_to(q, dest); dest[3] = -dest[3]; } @@ -634,7 +634,7 @@ glm_quat_slerp(versor from, versor to, float t, versor dest) { } if (cosTheta < 0.0f) { - glm_vec4_flipsign(q1); + glm_vec4_negate(q1); cosTheta = -cosTheta; } diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index eb64c80..9b9efc4 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -7,7 +7,7 @@ /* Macros: - glm_vec_dup(v, dest) + glm_vec3_dup(v, dest) GLM_VEC3_ONE_INIT GLM_VEC3_ZERO_INIT GLM_VEC3_ONE @@ -67,7 +67,7 @@ CGLM_INLINE void glm_normalize_to(vec3 v, vec3 dest); DEPRECATED: - glm_vec_dup + glm_vec3_dup glm_vec3_flipsign glm_vec3_flipsign_to */ @@ -81,7 +81,9 @@ #include "util.h" /* DEPRECATED! use _copy, _ucopy versions */ -#define glm_vec_dup(v, dest) glm_vec3_copy(v, dest) +#define glm_vec3_dup(v, dest) glm_vec3_copy(v, dest) +#define glm_vec3_flipsign(v) glm_vec3_negate(v) +#define glm_vec3_flipsign_to(v, dest) glm_vec3_negate_to(v, dest) #define GLM_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f} #define GLM_VEC3_ZERO_INIT {0.0f, 0.0f, 0.0f} @@ -412,37 +414,6 @@ glm_vec3_muladds(vec3 a, float s, vec3 dest) { dest[2] += a[2] * s; } -/*! - * DEPRECATED! use glm_vec3_negate and friends - * - * @brief negate vector components - * - * @param[in, out] v vector - */ -CGLM_INLINE -void -glm_vec3_flipsign(vec3 v) { - v[0] = -v[0]; - v[1] = -v[1]; - v[2] = -v[2]; -} - -/*! - * DEPRECATED! use glm_vec3_negate and friends - * - * @brief negate vector components and store result in dest - * - * @param[in] v vector - * @param[out] dest result vector - */ -CGLM_INLINE -void -glm_vec3_flipsign_to(vec3 v, vec3 dest) { - dest[0] = -v[0]; - dest[1] = -v[1]; - dest[2] = -v[2]; -} - /*! * @brief negate vector components and store result in dest * diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index e45ef85..3e41c30 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -11,20 +11,20 @@ /* Functions: - CGLM_INLINE void glm_vec4_mulv(vec4 a, vec4 b, vec4 d); - CGLM_INLINE void glm_vec4_broadcast(float val, vec4 d); - CGLM_INLINE bool glm_vec4_eq(vec4 v, float val); - CGLM_INLINE bool glm_vec4_eq_eps(vec4 v, float val); - CGLM_INLINE bool glm_vec4_eq_all(vec4 v); - CGLM_INLINE bool glm_vec4_eqv(vec4 v1, vec4 v2); - CGLM_INLINE bool glm_vec4_eqv_eps(vec4 v1, vec4 v2); + CGLM_INLINE void glm_vec4_mulv(vec4 a, vec4 b, vec4 d); + CGLM_INLINE void glm_vec4_broadcast(float val, vec4 d); + CGLM_INLINE bool glm_vec4_eq(vec4 v, float val); + CGLM_INLINE bool glm_vec4_eq_eps(vec4 v, float val); + CGLM_INLINE bool glm_vec4_eq_all(vec4 v); + CGLM_INLINE bool glm_vec4_eqv(vec4 v1, vec4 v2); + CGLM_INLINE bool glm_vec4_eqv_eps(vec4 v1, vec4 v2); CGLM_INLINE float glm_vec4_max(vec4 v); CGLM_INLINE float glm_vec4_min(vec4 v); - CGLM_INLINE bool glm_vec4_isnan(vec4 v); - CGLM_INLINE bool glm_vec4_isinf(vec4 v); - CGLM_INLINE bool glm_vec4_isvalid(vec4 v); - CGLM_INLINE void glm_vec4_sign(vec4 v, vec4 dest); - CGLM_INLINE void glm_vec4_sqrt(vec4 v, vec4 dest); + CGLM_INLINE bool glm_vec4_isnan(vec4 v); + CGLM_INLINE bool glm_vec4_isinf(vec4 v); + CGLM_INLINE bool glm_vec4_isvalid(vec4 v); + CGLM_INLINE void glm_vec4_sign(vec4 v, vec4 dest); + CGLM_INLINE void glm_vec4_sqrt(vec4 v, vec4 dest); */ #ifndef cglm_vec4_ext_h diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index ec14ce3..dad9a9e 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -36,7 +36,7 @@ CGLM_INLINE void glm_vec4_addadd(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_subadd(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_muladd(vec4 a, vec4 b, vec4 dest); - CGLM_INLINE void glm_vec4_flipsign(vec4 v); + CGLM_INLINE void glm_vec4_negate(vec4 v); CGLM_INLINE void glm_vec4_inv(vec4 v); CGLM_INLINE void glm_vec4_inv_to(vec4 v, vec4 dest); CGLM_INLINE void glm_vec4_normalize(vec4 v); @@ -46,6 +46,12 @@ CGLM_INLINE void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest); CGLM_INLINE void glm_vec4_clamp(vec4 v, float minVal, float maxVal); CGLM_INLINE void glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) + + + DEPRECATED: + glm_vec4_dup + glm_vec4_flipsign + glm_vec4_flipsign_to */ #ifndef cglm_vec4_h @@ -510,32 +516,14 @@ glm_vec4_muladds(vec4 a, float s, vec4 dest) { } /*! - * @brief flip sign of all vec4 members - * - * @param[in, out] v vector - */ -CGLM_INLINE -void -glm_vec4_flipsign(vec4 v) { -#if defined( __SSE__ ) || defined( __SSE2__ ) - glmm_store(v, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); -#else - v[0] = -v[0]; - v[1] = -v[1]; - v[2] = -v[2]; - v[3] = -v[3]; -#endif -} - -/*! - * @brief flip sign of all vec4 members and store result in dest + * @brief negate vector components and store result in dest * * @param[in] v vector - * @param[out] dest vector + * @param[out] dest result vector */ CGLM_INLINE void -glm_vec4_flipsign_to(vec4 v, vec4 dest) { +glm_vec4_negate_to(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); #else @@ -546,6 +534,17 @@ glm_vec4_flipsign_to(vec4 v, vec4 dest) { #endif } +/*! + * @brief flip sign of all vec4 members + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec4_negate(vec4 v) { + glm_vec4_negate_to(v, v); +} + /*! * @brief make vector as inverse/opposite of itself * @@ -554,7 +553,7 @@ glm_vec4_flipsign_to(vec4 v, vec4 dest) { CGLM_INLINE void glm_vec4_inv(vec4 v) { - glm_vec4_flipsign(v); + glm_vec4_negate(v); } /*! @@ -567,7 +566,7 @@ CGLM_INLINE void glm_vec4_inv_to(vec4 v, vec4 dest) { glm_vec4_copy(v, dest); - glm_vec4_flipsign(dest); + glm_vec4_negate(dest); } /*! diff --git a/src/vec3.c b/src/vec3.c index 5f743b3..c150b0b 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -146,18 +146,6 @@ glmc_vec3_muladds(vec3 a, float s, vec3 dest) { glm_vec3_muladds(a, s, dest); } -CGLM_EXPORT -void -glmc_vec3_flipsign(vec3 v) { - glm_vec3_flipsign(v); -} - -CGLM_EXPORT -void -glmc_vec3_flipsign_to(vec3 v, vec3 dest) { - glm_vec3_flipsign_to(v, dest); -} - CGLM_EXPORT void glmc_vec3_negate(vec3 v) { diff --git a/src/vec4.c b/src/vec4.c index 29ccc4d..379d527 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -154,14 +154,14 @@ glmc_vec4_muladds(vec4 a, float s, vec4 dest) { CGLM_EXPORT void -glmc_vec4_flipsign(vec4 v) { - glm_vec4_flipsign(v); +glmc_vec4_negate(vec4 v) { + glm_vec4_negate(v); } CGLM_EXPORT void -glmc_vec4_flipsign_to(vec4 v, vec4 dest) { - glm_vec4_flipsign_to(v, dest); +glmc_vec4_negate_to(vec4 v, vec4 dest) { + glm_vec4_negate_to(v, dest); } CGLM_EXPORT From aee381d869a3c7343c01736c010fecb841d680e4 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 29 Nov 2018 09:23:14 +0300 Subject: [PATCH 211/292] vec: deprecate `glm_vec_inv` and `glm_vec4_inv` * because in the current implementation, `glm_vec3_negate` does same thing. It is duplicate. --- docs/source/vec3.rst | 38 +++++++++++++++++++++----------------- docs/source/vec4.rst | 40 ++++++++++++++++++++++------------------ include/cglm/call/vec3.h | 18 ++---------------- include/cglm/call/vec4.h | 10 ++-------- include/cglm/vec3.h | 27 ++++----------------------- include/cglm/vec4.h | 36 +++++++++--------------------------- src/vec3.c | 12 ------------ src/vec4.c | 12 ------------ 8 files changed, 60 insertions(+), 133 deletions(-) diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index e452550..d8f7ced 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -57,10 +57,10 @@ Functions: #. :c:func:`glm_vec3_muladds` #. :c:func:`glm_vec3_flipsign` #. :c:func:`glm_vec3_flipsign_to` -#. :c:func:`glm_vec3_negate` -#. :c:func:`glm_vec3_negate_to` #. :c:func:`glm_vec3_inv` #. :c:func:`glm_vec3_inv_to` +#. :c:func:`glm_vec3_negate` +#. :c:func:`glm_vec3_negate_to` #. :c:func:`glm_vec3_normalize` #. :c:func:`glm_vec3_normalize_to` #. :c:func:`glm_vec3_distance2` @@ -292,6 +292,25 @@ Functions documentation | *[in]* **v** vector | *[out]* **dest** negated vector +.. c:function:: void glm_vec3_inv(vec3 v) + + **DEPRACATED!** + + use :c:func:`glm_vec3_negate` + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec3_inv_to(vec3 v, vec3 dest) + + **DEPRACATED!** + + use :c:func:`glm_vec3_negate_to` + + Parameters: + | *[in]* **v** source + | *[out]* **dest** destination + .. c:function:: void glm_vec3_negate(vec3 v) negate vector components @@ -307,21 +326,6 @@ Functions documentation | *[in]* **v** vector | *[out]* **dest** negated vector -.. c:function:: void glm_vec3_inv(vec3 v) - - make vector as inverse/opposite of itself - - Parameters: - | *[in, out]* **v** vector - -.. c:function:: void glm_vec3_inv_to(vec3 v, vec3 dest) - - inverse/opposite vector - - Parameters: - | *[in]* **v** source - | *[out]* **dest** destination - .. c:function:: void glm_vec3_normalize(vec3 v) normalize vec3 and store result in same vec diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index cf025e6..99f65cc 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -45,10 +45,10 @@ Functions: #. :c:func:`glm_vec4_muladds` #. :c:func:`glm_vec4_flipsign` #. :c:func:`glm_vec4_flipsign_to` -#. :c:func:`glm_vec4_negate` -#. :c:func:`glm_vec4_negate_to` #. :c:func:`glm_vec4_inv` #. :c:func:`glm_vec4_inv_to` +#. :c:func:`glm_vec4_negate` +#. :c:func:`glm_vec4_negate_to` #. :c:func:`glm_vec4_normalize` #. :c:func:`glm_vec4_normalize_to` #. :c:func:`glm_vec4_distance` @@ -275,12 +275,31 @@ Functions documentation **DEPRACATED!** - use :c:func:`glm_vec4_negate_TO` + use :c:func:`glm_vec4_negate_to` Parameters: | *[in]* **v** vector | *[out]* **dest** negated vector +.. c:function:: void glm_vec4_inv(vec4 v) + + **DEPRACATED!** + + use :c:func:`glm_vec4_negate` + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec4_inv_to(vec4 v, vec4 dest) + + **DEPRACATED!** + + use :c:func:`glm_vec4_negate_to` + + Parameters: + | *[in]* **v** source + | *[out]* **dest** destination + .. c:function:: void glm_vec4_negate(vec4 v) negate vector components @@ -296,21 +315,6 @@ Functions documentation | *[in]* **v** vector | *[out]* **dest** negated vector -.. c:function:: void glm_vec4_inv(vec4 v) - - make vector as inverse/opposite of itself - - Parameters: - | *[in, out]* **v** vector - -.. c:function:: void glm_vec4_inv_to(vec4 v, vec4 dest) - - inverse/opposite vector - - Parameters: - | *[in]* **v** source - | *[out]* **dest** destination - .. c:function:: void glm_vec4_normalize(vec4 v) normalize vec4 and store result in same vec diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 89e2fe2..63d7e38 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -17,6 +17,8 @@ extern "C" { #define glmc_vec_dup(v, dest) glmc_vec3_copy(v, dest) #define glmc_vec3_flipsign(v) glmc_vec3_negate(v) #define glmc_vec3_flipsign_to(v, dest) glmc_vec3_negate_to(v, dest) +#define glmc_vec3_inv(v) glmc_vec3_negate(v) +#define glmc_vec3_inv_to(v, dest) glmc_vec3_negate_to(v, dest) CGLM_EXPORT void @@ -110,14 +112,6 @@ CGLM_EXPORT void glmc_vec3_muladds(vec3 a, float s, vec3 dest); -CGLM_EXPORT -void -glmc_vec3_flipsign(vec3 v); - -CGLM_EXPORT -void -glmc_vec3_flipsign_to(vec3 v, vec3 dest); - CGLM_EXPORT void glmc_vec3_negate(vec3 v); @@ -126,14 +120,6 @@ CGLM_EXPORT void glmc_vec3_negate_to(vec3 v, vec3 dest); -CGLM_EXPORT -void -glmc_vec3_inv(vec3 v); - -CGLM_EXPORT -void -glmc_vec3_inv_to(vec3 v, vec3 dest); - CGLM_EXPORT float glmc_vec3_angle(vec3 v1, vec3 v2); diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index 78c39ae..c71f440 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -18,6 +18,8 @@ extern "C" { #define glmc_vec4_dup(v, dest) glmc_vec4_copy(v, dest) #define glmc_vec4_flipsign(v) glmc_vec4_negate(v) #define glmc_vec4_flipsign_to(v, dest) glmc_vec4_negate_to(v, dest) +#define glmc_vec4_inv(v) glmc_vec4_negate(v) +#define glmc_vec4_inv_to(v, dest) glmc_vec4_negate_to(v, dest) CGLM_EXPORT void @@ -123,14 +125,6 @@ CGLM_EXPORT void glmc_vec4_negate_to(vec4 v, vec4 dest); -CGLM_EXPORT -void -glmc_vec4_inv(vec4 v); - -CGLM_EXPORT -void -glmc_vec4_inv_to(vec4 v, vec4 dest); - CGLM_EXPORT float glmc_vec4_distance(vec4 v1, vec4 v2); diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 9b9efc4..de83ada 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -70,6 +70,8 @@ glm_vec3_dup glm_vec3_flipsign glm_vec3_flipsign_to + glm_vec3_inv + glm_vec3_inv_to */ #ifndef cglm_vec3_h @@ -84,6 +86,8 @@ #define glm_vec3_dup(v, dest) glm_vec3_copy(v, dest) #define glm_vec3_flipsign(v) glm_vec3_negate(v) #define glm_vec3_flipsign_to(v, dest) glm_vec3_negate_to(v, dest) +#define glm_vec3_inv(v) glm_vec3_negate(v) +#define glm_vec3_inv_to(v, dest) glm_vec3_negate_to(v, dest) #define GLM_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f} #define GLM_VEC3_ZERO_INIT {0.0f, 0.0f, 0.0f} @@ -439,29 +443,6 @@ glm_vec3_negate(vec3 v) { glm_vec3_negate_to(v, v); } -/*! - * @brief make vector as inverse/opposite of itself - * - * @param[in, out] v vector - */ -CGLM_INLINE -void -glm_vec3_inv(vec3 v) { - glm_vec3_negate(v); -} - -/*! - * @brief inverse/opposite vector - * - * @param[in] v source - * @param[out] dest destination - */ -CGLM_INLINE -void -glm_vec3_inv_to(vec3 v, vec3 dest) { - glm_vec3_negate_to(v, dest); -} - /*! * @brief normalize vec3 and store result in same vec * diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index dad9a9e..b170530 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -52,6 +52,8 @@ glm_vec4_dup glm_vec4_flipsign glm_vec4_flipsign_to + glm_vec4_inv + glm_vec4_inv_to */ #ifndef cglm_vec4_h @@ -61,9 +63,13 @@ #include "vec4-ext.h" #include "util.h" -/* DEPRECATED! use _copy, _ucopy versions */ -#define glm_vec4_dup3(v, dest) glm_vec4_copy3(v, dest) -#define glm_vec4_dup(v, dest) glm_vec4_copy(v, dest) +/* DEPRECATED! functions */ +#define glm_vec4_dup3(v, dest) glm_vec4_copy3(v, dest) +#define glm_vec4_dup(v, dest) glm_vec4_copy(v, dest) +#define glm_vec4_flipsign(v) glm_vec4_negate(v) +#define glm_vec4_flipsign_to(v, dest) glm_vec4_negate_to(v, dest) +#define glm_vec4_inv(v) glm_vec4_negate(v) +#define glm_vec4_inv_to(v, dest) glm_vec4_negate_to(v, dest) #define GLM_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f} #define GLM_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f} @@ -545,30 +551,6 @@ glm_vec4_negate(vec4 v) { glm_vec4_negate_to(v, v); } -/*! - * @brief make vector as inverse/opposite of itself - * - * @param[in, out] v vector - */ -CGLM_INLINE -void -glm_vec4_inv(vec4 v) { - glm_vec4_negate(v); -} - -/*! - * @brief inverse/opposite vector - * - * @param[in] v source - * @param[out] dest destination - */ -CGLM_INLINE -void -glm_vec4_inv_to(vec4 v, vec4 dest) { - glm_vec4_copy(v, dest); - glm_vec4_negate(dest); -} - /*! * @brief normalize vec4 to dest * diff --git a/src/vec3.c b/src/vec3.c index c150b0b..9e26cc4 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -158,18 +158,6 @@ glmc_vec3_negate_to(vec3 v, vec3 dest) { glm_vec3_negate_to(v, dest); } -CGLM_EXPORT -void -glmc_vec3_inv(vec3 v) { - glm_vec3_inv(v); -} - -CGLM_EXPORT -void -glmc_vec3_inv_to(vec3 v, vec3 dest) { - glm_vec3_inv_to(v, dest); -} - CGLM_EXPORT float glmc_vec3_angle(vec3 v1, vec3 v2) { diff --git a/src/vec4.c b/src/vec4.c index 379d527..a559b12 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -164,18 +164,6 @@ glmc_vec4_negate_to(vec4 v, vec4 dest) { glm_vec4_negate_to(v, dest); } -CGLM_EXPORT -void -glmc_vec4_inv(vec4 v) { - glm_vec4_inv(v); -} - -CGLM_EXPORT -void -glmc_vec4_inv_to(vec4 v, vec4 dest) { - glm_vec4_inv_to(v, dest); -} - CGLM_EXPORT float glmc_vec4_distance(vec4 v1, vec4 v2) { From 4e08b7e335faf77eeb03c402e9bde017f1fe7b0e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 29 Nov 2018 09:55:27 +0300 Subject: [PATCH 212/292] vec: rename parameter names --- include/cglm/call/vec3.h | 24 ++++---- include/cglm/call/vec4.h | 18 +++--- include/cglm/quat.h | 2 +- include/cglm/vec3-ext.h | 44 +++++---------- include/cglm/vec3.h | 115 ++++++++++++++++++++------------------- include/cglm/vec4-ext.h | 53 ++++++------------ include/cglm/vec4.h | 100 +++++++++++++++++----------------- src/vec3.c | 48 ++++++++-------- src/vec4.c | 36 ++++++------ 9 files changed, 202 insertions(+), 238 deletions(-) diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 63d7e38..106257e 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -46,15 +46,15 @@ glmc_vec3_cross(vec3 a, vec3 b, vec3 d); CGLM_EXPORT float -glmc_vec3_norm(vec3 vec); +glmc_vec3_norm(vec3 v); CGLM_EXPORT float -glmc_vec3_norm2(vec3 vec); +glmc_vec3_norm2(vec3 v); CGLM_EXPORT void -glmc_vec3_normalize_to(vec3 vec, vec3 dest); +glmc_vec3_normalize_to(vec3 v, vec3 dest); CGLM_EXPORT void @@ -62,7 +62,7 @@ glmc_vec3_normalize(vec3 v); CGLM_EXPORT void -glmc_vec3_add(vec3 v1, vec3 v2, vec3 dest); +glmc_vec3_add(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void @@ -122,7 +122,7 @@ glmc_vec3_negate_to(vec3 v, vec3 dest); CGLM_EXPORT float -glmc_vec3_angle(vec3 v1, vec3 v2); +glmc_vec3_angle(vec3 a, vec3 b); CGLM_EXPORT void @@ -142,23 +142,23 @@ glmc_vec3_proj(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_center(vec3 v1, vec3 v2, vec3 dest); +glmc_vec3_center(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT float -glmc_vec3_distance2(vec3 v1, vec3 v2); +glmc_vec3_distance2(vec3 a, vec3 b); CGLM_EXPORT float -glmc_vec3_distance(vec3 v1, vec3 v2); +glmc_vec3_distance(vec3 a, vec3 b); CGLM_EXPORT void -glmc_vec3_maxv(vec3 v1, vec3 v2, vec3 dest); +glmc_vec3_maxv(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_minv(vec3 v1, vec3 v2, vec3 dest); +glmc_vec3_minv(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void @@ -196,11 +196,11 @@ glmc_vec3_eq_all(vec3 v); CGLM_EXPORT bool -glmc_vec3_eqv(vec3 v1, vec3 v2); +glmc_vec3_eqv(vec3 a, vec3 b); CGLM_EXPORT bool -glmc_vec3_eqv_eps(vec3 v1, vec3 v2); +glmc_vec3_eqv_eps(vec3 a, vec3 b); CGLM_EXPORT float diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index c71f440..1923da6 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -35,7 +35,7 @@ glmc_vec4_one(vec4 v); CGLM_EXPORT void -glmc_vec4_copy3(vec4 a, vec3 dest); +glmc_vec4_copy3(vec4 v, vec3 dest); CGLM_EXPORT void @@ -51,15 +51,15 @@ glmc_vec4_dot(vec4 a, vec4 b); CGLM_EXPORT float -glmc_vec4_norm(vec4 vec); +glmc_vec4_norm(vec4 v); CGLM_EXPORT float -glmc_vec4_norm2(vec4 vec); +glmc_vec4_norm2(vec4 v); CGLM_EXPORT void -glmc_vec4_normalize_to(vec4 vec, vec4 dest); +glmc_vec4_normalize_to(vec4 v, vec4 dest); CGLM_EXPORT void @@ -127,15 +127,15 @@ glmc_vec4_negate_to(vec4 v, vec4 dest); CGLM_EXPORT float -glmc_vec4_distance(vec4 v1, vec4 v2); +glmc_vec4_distance(vec4 a, vec4 b); CGLM_EXPORT void -glmc_vec4_maxv(vec4 v1, vec4 v2, vec4 dest); +glmc_vec4_maxv(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_minv(vec4 v1, vec4 v2, vec4 dest); +glmc_vec4_minv(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void @@ -169,11 +169,11 @@ glmc_vec4_eq_all(vec4 v); CGLM_EXPORT bool -glmc_vec4_eqv(vec4 v1, vec4 v2); +glmc_vec4_eqv(vec4 a, vec4 b); CGLM_EXPORT bool -glmc_vec4_eqv_eps(vec4 v1, vec4 v2); +glmc_vec4_eqv_eps(vec4 a, vec4 b); CGLM_EXPORT float diff --git a/include/cglm/quat.h b/include/cglm/quat.h index eee4f53..1db0161 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -19,7 +19,7 @@ CGLM_INLINE float glm_quat_norm(versor q); CGLM_INLINE void glm_quat_normalize(versor q); CGLM_INLINE void glm_quat_normalize_to(versor q, versor dest); - CGLM_INLINE float glm_quat_dot(versor q1, versor q2); + CGLM_INLINE float glm_quat_dot(versor p, versor q); CGLM_INLINE void glm_quat_conjugate(versor q, versor dest); CGLM_INLINE void glm_quat_inv(versor q, versor dest); CGLM_INLINE void glm_quat_add(versor p, versor q, versor dest); diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index 34166f4..0e64325 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -11,13 +11,12 @@ /* Functions: - CGLM_INLINE void glm_vec3_mulv(vec3 a, vec3 b, vec3 d); CGLM_INLINE void glm_vec3_broadcast(float val, vec3 d); CGLM_INLINE bool glm_vec3_eq(vec3 v, float val); CGLM_INLINE bool glm_vec3_eq_eps(vec3 v, float val); CGLM_INLINE bool glm_vec3_eq_all(vec3 v); - CGLM_INLINE bool glm_vec3_eqv(vec3 v1, vec3 v2); - CGLM_INLINE bool glm_vec3_eqv_eps(vec3 v1, vec3 v2); + CGLM_INLINE bool glm_vec3_eqv(vec3 a, vec3 b); + CGLM_INLINE bool glm_vec3_eqv_eps(vec3 a, vec3 b); CGLM_INLINE float glm_vec3_max(vec3 v); CGLM_INLINE float glm_vec3_min(vec3 v); CGLM_INLINE bool glm_vec3_isnan(vec3 v); @@ -36,21 +35,6 @@ #include #include -/*! - * @brief DEPRECATED! use glm_vec3_mul - * - * @param[in] a vec1 - * @param[in] b vec2 - * @param[out] d vec3 = (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]) - */ -CGLM_INLINE -void -glm_vec3_mulv(vec3 a, vec3 b, vec3 d) { - d[0] = a[0] * b[0]; - d[1] = a[1] * b[1]; - d[2] = a[2] * b[2]; -} - /*! * @brief fill a vector with specified value * @@ -103,29 +87,29 @@ glm_vec3_eq_all(vec3 v) { /*! * @brief check if vector is equal to another (without epsilon) * - * @param[in] v1 vector - * @param[in] v2 vector + * @param[in] a vector + * @param[in] b vector */ CGLM_INLINE bool -glm_vec3_eqv(vec3 v1, vec3 v2) { - return v1[0] == v2[0] - && v1[1] == v2[1] - && v1[2] == v2[2]; +glm_vec3_eqv(vec3 a, vec3 b) { + return a[0] == b[0] + && a[1] == b[1] + && a[2] == b[2]; } /*! * @brief check if vector is equal to another (with epsilon) * - * @param[in] v1 vector - * @param[in] v2 vector + * @param[in] a vector + * @param[in] b vector */ CGLM_INLINE bool -glm_vec3_eqv_eps(vec3 v1, vec3 v2) { - return fabsf(v1[0] - v2[0]) <= FLT_EPSILON - && fabsf(v1[1] - v2[1]) <= FLT_EPSILON - && fabsf(v1[2] - v2[2]) <= FLT_EPSILON; +glm_vec3_eqv_eps(vec3 a, vec3 b) { + return fabsf(a[0] - b[0]) <= FLT_EPSILON + && fabsf(a[1] - b[1]) <= FLT_EPSILON + && fabsf(a[2] - b[2]) <= FLT_EPSILON; } /*! diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index de83ada..d311c27 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -7,7 +7,6 @@ /* Macros: - glm_vec3_dup(v, dest) GLM_VEC3_ONE_INIT GLM_VEC3_ZERO_INIT GLM_VEC3_ONE @@ -24,7 +23,7 @@ CGLM_INLINE float glm_vec3_dot(vec3 a, vec3 b); CGLM_INLINE void glm_vec3_cross(vec3 a, vec3 b, vec3 d); CGLM_INLINE float glm_vec3_norm2(vec3 v); - CGLM_INLINE float glm_vec3_norm(vec3 vec); + CGLM_INLINE float glm_vec3_norm(vec3 v); CGLM_INLINE void glm_vec3_add(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_adds(vec3 a, float s, vec3 dest); CGLM_INLINE void glm_vec3_sub(vec3 a, vec3 b, vec3 dest); @@ -45,17 +44,17 @@ CGLM_INLINE void glm_vec3_inv(vec3 v); CGLM_INLINE void glm_vec3_inv_to(vec3 v, vec3 dest); CGLM_INLINE void glm_vec3_normalize(vec3 v); - CGLM_INLINE void glm_vec3_normalize_to(vec3 vec, vec3 dest); - CGLM_INLINE float glm_vec3_distance(vec3 v1, vec3 v2); - CGLM_INLINE float glm_vec3_angle(vec3 v1, vec3 v2); + CGLM_INLINE void glm_vec3_normalize_to(vec3 v, vec3 dest); + CGLM_INLINE float glm_vec3_distance(vec3 a, vec3 b); + CGLM_INLINE float glm_vec3_angle(vec3 a, vec3 b); CGLM_INLINE void glm_vec3_rotate(vec3 v, float angle, vec3 axis); CGLM_INLINE void glm_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest); CGLM_INLINE void glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest); CGLM_INLINE void glm_vec3_proj(vec3 a, vec3 b, vec3 dest); - CGLM_INLINE void glm_vec3_center(vec3 v1, vec3 v2, vec3 dest); - CGLM_INLINE float glm_vec3_distance2(vec3 v1, vec3 v2); - CGLM_INLINE void glm_vec3_maxv(vec3 v1, vec3 v2, vec3 dest); - CGLM_INLINE void glm_vec3_minv(vec3 v1, vec3 v2, vec3 dest); + CGLM_INLINE void glm_vec3_center(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE float glm_vec3_distance2(vec3 a, vec3 b); + CGLM_INLINE void glm_vec3_maxv(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec3_minv(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_ortho(vec3 v, vec3 dest); CGLM_INLINE void glm_vec3_clamp(vec3 v, float minVal, float maxVal); CGLM_INLINE void glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest); @@ -72,6 +71,7 @@ glm_vec3_flipsign_to glm_vec3_inv glm_vec3_inv_to + glm_vec3_mulv */ #ifndef cglm_vec3_h @@ -88,6 +88,7 @@ #define glm_vec3_flipsign_to(v, dest) glm_vec3_negate_to(v, dest) #define glm_vec3_inv(v) glm_vec3_negate(v) #define glm_vec3_inv_to(v, dest) glm_vec3_negate_to(v, dest) +#define glm_vec3_mulv(a, b, d) glm_vec3_mul(a, b, d) #define GLM_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f} #define GLM_VEC3_ZERO_INIT {0.0f, 0.0f, 0.0f} @@ -199,14 +200,14 @@ glm_vec3_norm2(vec3 v) { /*! * @brief norm (magnitude) of vec3 * - * @param[in] vec vector + * @param[in] v vector * * @return norm */ CGLM_INLINE float -glm_vec3_norm(vec3 vec) { - return sqrtf(glm_vec3_norm2(vec)); +glm_vec3_norm(vec3 v) { + return sqrtf(glm_vec3_norm2(v)); } /*! @@ -240,7 +241,7 @@ glm_vec3_adds(vec3 v, float s, vec3 dest) { } /*! - * @brief subtract v2 vector from v1 vector store result in dest + * @brief subtract b vector from a vector store result in dest * * @param[in] a vector1 * @param[in] b vector2 @@ -272,16 +273,16 @@ glm_vec3_subs(vec3 v, float s, vec3 dest) { /*! * @brief multiply two vector (component-wise multiplication) * - * @param a v1 - * @param b v2 - * @param d v3 = (a[0] * b[0], a[1] * b[1], a[2] * b[2]) + * @param a vector1 + * @param b vector2 + * @param dest v3 = (a[0] * b[0], a[1] * b[1], a[2] * b[2]) */ CGLM_INLINE void -glm_vec3_mul(vec3 a, vec3 b, vec3 d) { - d[0] = a[0] * b[0]; - d[1] = a[1] * b[1]; - d[2] = a[2] * b[2]; +glm_vec3_mul(vec3 a, vec3 b, vec3 dest) { + dest[0] = a[0] * b[0]; + dest[1] = a[1] * b[1]; + dest[2] = a[2] * b[2]; } /*! @@ -466,40 +467,40 @@ glm_vec3_normalize(vec3 v) { /*! * @brief normalize vec3 to dest * - * @param[in] vec source + * @param[in] v source * @param[out] dest destination */ CGLM_INLINE void -glm_vec3_normalize_to(vec3 vec, vec3 dest) { +glm_vec3_normalize_to(vec3 v, vec3 dest) { float norm; - norm = glm_vec3_norm(vec); + norm = glm_vec3_norm(v); if (norm == 0.0f) { glm_vec3_zero(dest); return; } - glm_vec3_scale(vec, 1.0f / norm, dest); + glm_vec3_scale(v, 1.0f / norm, dest); } /*! * @brief angle betwen two vector * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] a vector1 + * @param[in] b vector2 * * @return angle as radians */ CGLM_INLINE float -glm_vec3_angle(vec3 v1, vec3 v2) { +glm_vec3_angle(vec3 a, vec3 b) { float norm, dot; /* maybe compiler generate approximation instruction (rcp) */ - norm = 1.0f / (glm_vec3_norm(v1) * glm_vec3_norm(v2)); - dot = glm_vec3_dot(v1, v2) * norm; + norm = 1.0f / (glm_vec3_norm(a) * glm_vec3_norm(b)); + dot = glm_vec3_dot(a, b) * norm; if (dot > 1.0f) return 0.0f; @@ -600,8 +601,8 @@ glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest) { /*! * @brief project a vector onto b vector * - * @param[in] a vector1 - * @param[in] b vector2 + * @param[in] a vector1 + * @param[in] b vector2 * @param[out] dest projected vector */ CGLM_INLINE @@ -615,73 +616,73 @@ glm_vec3_proj(vec3 a, vec3 b, vec3 dest) { /** * @brief find center point of two vector * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] a vector1 + * @param[in] b vector2 * @param[out] dest center point */ CGLM_INLINE void -glm_vec3_center(vec3 v1, vec3 v2, vec3 dest) { - glm_vec3_add(v1, v2, dest); +glm_vec3_center(vec3 a, vec3 b, vec3 dest) { + glm_vec3_add(a, b, dest); glm_vec3_scale(dest, 0.5f, dest); } /** * @brief squared distance between two vectors * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] a vector1 + * @param[in] b vector2 * @return returns squared distance (distance * distance) */ CGLM_INLINE float -glm_vec3_distance2(vec3 v1, vec3 v2) { - return glm_pow2(v2[0] - v1[0]) - + glm_pow2(v2[1] - v1[1]) - + glm_pow2(v2[2] - v1[2]); +glm_vec3_distance2(vec3 a, vec3 b) { + return glm_pow2(b[0] - a[0]) + + glm_pow2(b[1] - a[1]) + + glm_pow2(b[2] - a[2]); } /** * @brief distance between two vectors * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] a vector1 + * @param[in] b vector2 * @return returns distance */ CGLM_INLINE float -glm_vec3_distance(vec3 v1, vec3 v2) { - return sqrtf(glm_vec3_distance2(v1, v2)); +glm_vec3_distance(vec3 a, vec3 b) { + return sqrtf(glm_vec3_distance2(a, b)); } /*! * @brief max values of vectors * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] a vector1 + * @param[in] b vector2 * @param[out] dest destination */ CGLM_INLINE void -glm_vec3_maxv(vec3 v1, vec3 v2, vec3 dest) { - dest[0] = glm_max(v1[0], v2[0]); - dest[1] = glm_max(v1[1], v2[1]); - dest[2] = glm_max(v1[2], v2[2]); +glm_vec3_maxv(vec3 a, vec3 b, vec3 dest) { + dest[0] = glm_max(a[0], b[0]); + dest[1] = glm_max(a[1], b[1]); + dest[2] = glm_max(a[2], b[2]); } /*! * @brief min values of vectors * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] a vector1 + * @param[in] b vector2 * @param[out] dest destination */ CGLM_INLINE void -glm_vec3_minv(vec3 v1, vec3 v2, vec3 dest) { - dest[0] = glm_min(v1[0], v2[0]); - dest[1] = glm_min(v1[1], v2[1]); - dest[2] = glm_min(v1[2], v2[2]); +glm_vec3_minv(vec3 a, vec3 b, vec3 dest) { + dest[0] = glm_min(a[0], b[0]); + dest[1] = glm_min(a[1], b[1]); + dest[2] = glm_min(a[2], b[2]); } /*! diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index 3e41c30..07821ac 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -11,13 +11,12 @@ /* Functions: - CGLM_INLINE void glm_vec4_mulv(vec4 a, vec4 b, vec4 d); CGLM_INLINE void glm_vec4_broadcast(float val, vec4 d); CGLM_INLINE bool glm_vec4_eq(vec4 v, float val); CGLM_INLINE bool glm_vec4_eq_eps(vec4 v, float val); CGLM_INLINE bool glm_vec4_eq_all(vec4 v); - CGLM_INLINE bool glm_vec4_eqv(vec4 v1, vec4 v2); - CGLM_INLINE bool glm_vec4_eqv_eps(vec4 v1, vec4 v2); + CGLM_INLINE bool glm_vec4_eqv(vec4 a, vec4 b); + CGLM_INLINE bool glm_vec4_eqv_eps(vec4 a, vec4 b); CGLM_INLINE float glm_vec4_max(vec4 v); CGLM_INLINE float glm_vec4_min(vec4 v); CGLM_INLINE bool glm_vec4_isnan(vec4 v); @@ -36,26 +35,6 @@ #include #include -/*! - * @brief DEPRECATED! use glm_vec4_mul - * - * @param a v1 - * @param b v2 - * @param d v3 = (v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2], v1[3] * v2[3]) - */ -CGLM_INLINE -void -glm_vec4_mulv(vec4 a, vec4 b, vec4 d) { -#if defined( __SSE__ ) || defined( __SSE2__ ) - glmm_store(d, _mm_mul_ps(glmm_load(a), glmm_load(b))); -#else - d[0] = a[0] * b[0]; - d[1] = a[1] * b[1]; - d[2] = a[2] * b[2]; - d[3] = a[3] * b[3]; -#endif -} - /*! * @brief fill a vector with specified value * @@ -118,31 +97,31 @@ glm_vec4_eq_all(vec4 v) { /*! * @brief check if vector is equal to another (without epsilon) * - * @param v1 vector - * @param v2 vector + * @param a vector + * @param b vector */ CGLM_INLINE bool -glm_vec4_eqv(vec4 v1, vec4 v2) { - return v1[0] == v2[0] - && v1[1] == v2[1] - && v1[2] == v2[2] - && v1[3] == v2[3]; +glm_vec4_eqv(vec4 a, vec4 b) { + return a[0] == b[0] + && a[1] == b[1] + && a[2] == b[2] + && a[3] == b[3]; } /*! * @brief check if vector is equal to another (with epsilon) * - * @param v1 vector - * @param v2 vector + * @param a vector + * @param b vector */ CGLM_INLINE bool -glm_vec4_eqv_eps(vec4 v1, vec4 v2) { - return fabsf(v1[0] - v2[0]) <= FLT_EPSILON - && fabsf(v1[1] - v2[1]) <= FLT_EPSILON - && fabsf(v1[2] - v2[2]) <= FLT_EPSILON - && fabsf(v1[3] - v2[3]) <= FLT_EPSILON; +glm_vec4_eqv_eps(vec4 a, vec4 b) { + return fabsf(a[0] - b[0]) <= FLT_EPSILON + && fabsf(a[1] - b[1]) <= FLT_EPSILON + && fabsf(a[2] - b[2]) <= FLT_EPSILON + && fabsf(a[3] - b[3]) <= FLT_EPSILON; } /*! diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index b170530..2e3f6cf 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -7,8 +7,6 @@ /* Macros: - glm_vec4_dup3(v, dest) - glm_vec4_dup(v, dest) GLM_VEC4_ONE_INIT GLM_VEC4_BLACK_INIT GLM_VEC4_ZERO_INIT @@ -23,7 +21,7 @@ CGLM_INLINE void glm_vec4_ucopy(vec4 v, vec4 dest); CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b); CGLM_INLINE float glm_vec4_norm2(vec4 v); - CGLM_INLINE float glm_vec4_norm(vec4 vec); + CGLM_INLINE float glm_vec4_norm(vec4 v); CGLM_INLINE void glm_vec4_add(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_adds(vec4 v, float s, vec4 dest); CGLM_INLINE void glm_vec4_sub(vec4 a, vec4 b, vec4 dest); @@ -41,9 +39,9 @@ CGLM_INLINE void glm_vec4_inv_to(vec4 v, vec4 dest); CGLM_INLINE void glm_vec4_normalize(vec4 v); CGLM_INLINE void glm_vec4_normalize_to(vec4 vec, vec4 dest); - CGLM_INLINE float glm_vec4_distance(vec4 v1, vec4 v2); - CGLM_INLINE void glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest); - CGLM_INLINE void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest); + CGLM_INLINE float glm_vec4_distance(vec4 a, vec4 b); + CGLM_INLINE void glm_vec4_maxv(vec4 a, vec4 b, vec4 dest); + CGLM_INLINE void glm_vec4_minv(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_clamp(vec4 v, float minVal, float maxVal); CGLM_INLINE void glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) @@ -54,6 +52,7 @@ glm_vec4_flipsign_to glm_vec4_inv glm_vec4_inv_to + glm_vec4_mulv */ #ifndef cglm_vec4_h @@ -70,6 +69,7 @@ #define glm_vec4_flipsign_to(v, dest) glm_vec4_negate_to(v, dest) #define glm_vec4_inv(v) glm_vec4_negate(v) #define glm_vec4_inv_to(v, dest) glm_vec4_negate_to(v, dest) +#define glm_vec4_mulv(a, b, d) glm_vec4_mul(a, b, d) #define GLM_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f} #define GLM_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f} @@ -230,24 +230,24 @@ glm_vec4_norm2(vec4 v) { /*! * @brief norm (magnitude) of vec4 * - * @param[in] vec vector + * @param[in] v vector * * @return norm */ CGLM_INLINE float -glm_vec4_norm(vec4 vec) { +glm_vec4_norm(vec4 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) __m128 x0; - x0 = glmm_load(vec); + x0 = glmm_load(v); return _mm_cvtss_f32(_mm_sqrt_ss(glmm_dot(x0, x0))); #else - return sqrtf(glm_vec4_norm2(vec)); + return sqrtf(glm_vec4_norm2(v)); #endif } /*! - * @brief add v2 vector to v1 vector store result in dest + * @brief add b vector to a vector store result in dest * * @param[in] a vector1 * @param[in] b vector2 @@ -287,7 +287,7 @@ glm_vec4_adds(vec4 v, float s, vec4 dest) { } /*! - * @brief subtract b vector from a vector store result in dest (d = v1 - v2) + * @brief subtract b vector from a vector store result in dest (d = a - b) * * @param[in] a vector1 * @param[in] b vector2 @@ -329,20 +329,20 @@ glm_vec4_subs(vec4 v, float s, vec4 dest) { /*! * @brief multiply two vector (component-wise multiplication) * - * @param a v1 - * @param b v2 - * @param d v3 = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]) + * @param a vector1 + * @param b vector2 + * @param d dest = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]) */ CGLM_INLINE void -glm_vec4_mul(vec4 a, vec4 b, vec4 d) { +glm_vec4_mul(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - glmm_store(d, _mm_mul_ps(glmm_load(a), glmm_load(b))); + glmm_store(dest, _mm_mul_ps(glmm_load(a), glmm_load(b))); #else - d[0] = a[0] * b[0]; - d[1] = a[1] * b[1]; - d[2] = a[2] * b[2]; - d[3] = a[3] * b[3]; + dest[0] = a[0] * b[0]; + dest[1] = a[1] * b[1]; + dest[2] = a[2] * b[2]; + dest[3] = a[3] * b[3]; #endif } @@ -388,7 +388,7 @@ glm_vec4_scale_as(vec4 v, float s, vec4 dest) { } /*! - * @brief div vector with another component-wise division: d = v1 / v2 + * @brief div vector with another component-wise division: d = a / b * * @param[in] a vector 1 * @param[in] b vector 2 @@ -554,17 +554,17 @@ glm_vec4_negate(vec4 v) { /*! * @brief normalize vec4 to dest * - * @param[in] vec source + * @param[in] v source * @param[out] dest destination */ CGLM_INLINE void -glm_vec4_normalize_to(vec4 vec, vec4 dest) { +glm_vec4_normalize_to(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) __m128 xdot, x0; float dot; - x0 = glmm_load(vec); + x0 = glmm_load(v); xdot = glmm_dot(x0, x0); dot = _mm_cvtss_f32(xdot); @@ -577,14 +577,14 @@ glm_vec4_normalize_to(vec4 vec, vec4 dest) { #else float norm; - norm = glm_vec4_norm(vec); + norm = glm_vec4_norm(v); if (norm == 0.0f) { glm_vec4_zero(dest); return; } - glm_vec4_scale(vec, 1.0f / norm, dest); + glm_vec4_scale(v, 1.0f / norm, dest); #endif } @@ -602,56 +602,56 @@ glm_vec4_normalize(vec4 v) { /** * @brief distance between two vectors * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] a vector1 + * @param[in] b vector2 * @return returns distance */ CGLM_INLINE float -glm_vec4_distance(vec4 v1, vec4 v2) { - return sqrtf(glm_pow2(v2[0] - v1[0]) - + glm_pow2(v2[1] - v1[1]) - + glm_pow2(v2[2] - v1[2]) - + glm_pow2(v2[3] - v1[3])); +glm_vec4_distance(vec4 a, vec4 b) { + return sqrtf(glm_pow2(b[0] - a[0]) + + glm_pow2(b[1] - a[1]) + + glm_pow2(b[2] - a[2]) + + glm_pow2(b[3] - a[3])); } /*! * @brief max values of vectors * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] a vector1 + * @param[in] b vector2 * @param[out] dest destination */ CGLM_INLINE void -glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest) { +glm_vec4_maxv(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - glmm_store(dest, _mm_max_ps(glmm_load(v1), glmm_load(v2))); + glmm_store(dest, _mm_max_ps(glmm_load(a), glmm_load(b))); #else - dest[0] = glm_max(v1[0], v2[0]); - dest[1] = glm_max(v1[1], v2[1]); - dest[2] = glm_max(v1[2], v2[2]); - dest[3] = glm_max(v1[3], v2[3]); + dest[0] = glm_max(a[0], b[0]); + dest[1] = glm_max(a[1], b[1]); + dest[2] = glm_max(a[2], b[2]); + dest[3] = glm_max(a[3], b[3]); #endif } /*! * @brief min values of vectors * - * @param[in] v1 vector1 - * @param[in] v2 vector2 + * @param[in] a vector1 + * @param[in] b vector2 * @param[out] dest destination */ CGLM_INLINE void -glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { +glm_vec4_minv(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) - glmm_store(dest, _mm_min_ps(glmm_load(v1), glmm_load(v2))); + glmm_store(dest, _mm_min_ps(glmm_load(a), glmm_load(b))); #else - dest[0] = glm_min(v1[0], v2[0]); - dest[1] = glm_min(v1[1], v2[1]); - dest[2] = glm_min(v1[2], v2[2]); - dest[3] = glm_min(v1[3], v2[3]); + dest[0] = glm_min(a[0], b[0]); + dest[1] = glm_min(a[1], b[1]); + dest[2] = glm_min(a[2], b[2]); + dest[3] = glm_min(a[3], b[3]); #endif } diff --git a/src/vec3.c b/src/vec3.c index 9e26cc4..1b6ef3c 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -46,14 +46,14 @@ glmc_vec3_cross(vec3 a, vec3 b, vec3 d) { CGLM_EXPORT float -glmc_vec3_norm(vec3 vec) { - return glm_vec3_norm(vec); +glmc_vec3_norm(vec3 v) { + return glm_vec3_norm(v); } CGLM_EXPORT void -glmc_vec3_normalize_to(vec3 vec, vec3 dest) { - glm_vec3_normalize_to(vec, dest); +glmc_vec3_normalize_to(vec3 v, vec3 dest) { + glm_vec3_normalize_to(v, dest); } CGLM_EXPORT @@ -64,14 +64,14 @@ glmc_vec3_normalize(vec3 v) { CGLM_EXPORT float -glmc_vec3_norm2(vec3 vec) { - return glm_vec3_norm2(vec); +glmc_vec3_norm2(vec3 v) { + return glm_vec3_norm2(v); } CGLM_EXPORT void -glmc_vec3_add(vec3 v1, vec3 v2, vec3 dest) { - glm_vec3_add(v1, v2, dest); +glmc_vec3_add(vec3 a, vec3 b, vec3 dest) { + glm_vec3_add(a, b, dest); } CGLM_EXPORT @@ -160,8 +160,8 @@ glmc_vec3_negate_to(vec3 v, vec3 dest) { CGLM_EXPORT float -glmc_vec3_angle(vec3 v1, vec3 v2) { - return glm_vec3_angle(v1, v2); +glmc_vec3_angle(vec3 a, vec3 b) { + return glm_vec3_angle(a, b); } CGLM_EXPORT @@ -190,32 +190,32 @@ glmc_vec3_proj(vec3 a, vec3 b, vec3 dest) { CGLM_EXPORT void -glmc_vec3_center(vec3 v1, vec3 v2, vec3 dest) { - glm_vec3_center(v1, v2, dest); +glmc_vec3_center(vec3 a, vec3 b, vec3 dest) { + glm_vec3_center(a, b, dest); } CGLM_EXPORT float -glmc_vec3_distance2(vec3 v1, vec3 v2) { - return glm_vec3_distance2(v1, v2); +glmc_vec3_distance2(vec3 a, vec3 b) { + return glm_vec3_distance2(a, b); } CGLM_EXPORT float -glmc_vec3_distance(vec3 v1, vec3 v2) { - return glm_vec3_distance(v1, v2); +glmc_vec3_distance(vec3 a, vec3 b) { + return glm_vec3_distance(a, b); } CGLM_EXPORT void -glmc_vec3_maxv(vec3 v1, vec3 v2, vec3 dest) { - glm_vec3_minv(v1, v2, dest); +glmc_vec3_maxv(vec3 a, vec3 b, vec3 dest) { + glm_vec3_minv(a, b, dest); } CGLM_EXPORT void -glmc_vec3_minv(vec3 v1, vec3 v2, vec3 dest) { - glm_vec3_maxv(v1, v2, dest); +glmc_vec3_minv(vec3 a, vec3 b, vec3 dest) { + glm_vec3_maxv(a, b, dest); } CGLM_EXPORT @@ -270,14 +270,14 @@ glmc_vec3_eq_all(vec3 v) { CGLM_EXPORT bool -glmc_vec3_eqv(vec3 v1, vec3 v2) { - return glm_vec3_eqv(v1, v2); +glmc_vec3_eqv(vec3 a, vec3 b) { + return glm_vec3_eqv(a, b); } CGLM_EXPORT bool -glmc_vec3_eqv_eps(vec3 v1, vec3 v2) { - return glm_vec3_eqv_eps(v1, v2); +glmc_vec3_eqv_eps(vec3 a, vec3 b) { + return glm_vec3_eqv_eps(a, b); } CGLM_EXPORT diff --git a/src/vec4.c b/src/vec4.c index a559b12..97b0da4 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -28,8 +28,8 @@ glmc_vec4_one(vec4 v) { CGLM_EXPORT void -glmc_vec4_copy3(vec4 a, vec3 dest) { - glm_vec4_copy3(a, dest); +glmc_vec4_copy3(vec4 v, vec3 dest) { + glm_vec4_copy3(v, dest); } CGLM_EXPORT @@ -52,14 +52,14 @@ glmc_vec4_dot(vec4 a, vec4 b) { CGLM_EXPORT float -glmc_vec4_norm(vec4 vec) { - return glm_vec4_norm(vec); +glmc_vec4_norm(vec4 v) { + return glm_vec4_norm(v); } CGLM_EXPORT void -glmc_vec4_normalize_to(vec4 vec, vec4 dest) { - glm_vec4_normalize_to(vec, dest); +glmc_vec4_normalize_to(vec4 v, vec4 dest) { + glm_vec4_normalize_to(v, dest); } CGLM_EXPORT @@ -70,8 +70,8 @@ glmc_vec4_normalize(vec4 v) { CGLM_EXPORT float -glmc_vec4_norm2(vec4 vec) { - return glm_vec4_norm2(vec); +glmc_vec4_norm2(vec4 v) { + return glm_vec4_norm2(v); } CGLM_EXPORT @@ -166,20 +166,20 @@ glmc_vec4_negate_to(vec4 v, vec4 dest) { CGLM_EXPORT float -glmc_vec4_distance(vec4 v1, vec4 v2) { - return glm_vec4_distance(v1, v2); +glmc_vec4_distance(vec4 a, vec4 b) { + return glm_vec4_distance(a, b); } CGLM_EXPORT void -glmc_vec4_maxv(vec4 v1, vec4 v2, vec4 dest) { - glm_vec4_minv(v1, v2, dest); +glmc_vec4_maxv(vec4 a, vec4 b, vec4 dest) { + glm_vec4_minv(a, b, dest); } CGLM_EXPORT void -glmc_vec4_minv(vec4 v1, vec4 v2, vec4 dest) { - glm_vec4_maxv(v1, v2, dest); +glmc_vec4_minv(vec4 a, vec4 b, vec4 dest) { + glm_vec4_maxv(a, b, dest); } CGLM_EXPORT @@ -228,14 +228,14 @@ glmc_vec4_eq_all(vec4 v) { CGLM_EXPORT bool -glmc_vec4_eqv(vec4 v1, vec4 v2) { - return glm_vec4_eqv(v1, v2); +glmc_vec4_eqv(vec4 a, vec4 b) { + return glm_vec4_eqv(a, b); } CGLM_EXPORT bool -glmc_vec4_eqv_eps(vec4 v1, vec4 v2) { - return glm_vec4_eqv_eps(v1, v2); +glmc_vec4_eqv_eps(vec4 a, vec4 b) { + return glm_vec4_eqv_eps(a, b); } CGLM_EXPORT From 6d6954b208f9e93787b22da5c83ca05d1697a503 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 29 Nov 2018 10:50:24 +0300 Subject: [PATCH 213/292] vec: `minnadd` and `maxadd` helpers --- docs/source/vec3.rst | 22 ++++++++++++++++ docs/source/vec4.rst | 22 ++++++++++++++++ include/cglm/box.h | 26 ++++++++----------- include/cglm/call/vec3.h | 8 ++++++ include/cglm/call/vec4.h | 8 ++++++ include/cglm/vec3.h | 38 +++++++++++++++++++++++++++- include/cglm/vec4.h | 54 ++++++++++++++++++++++++++++++++++++++-- src/vec3.c | 12 +++++++++ src/vec4.c | 12 +++++++++ 9 files changed, 184 insertions(+), 18 deletions(-) diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index d8f7ced..a625f5c 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -55,6 +55,8 @@ Functions: #. :c:func:`glm_vec3_subadd` #. :c:func:`glm_vec3_muladd` #. :c:func:`glm_vec3_muladds` +#. :c:func:`glm_vec3_maxadd` +#. :c:func:`glm_vec3_minadd` #. :c:func:`glm_vec3_flipsign` #. :c:func:`glm_vec3_flipsign_to` #. :c:func:`glm_vec3_inv` @@ -273,6 +275,26 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** dest += (a * b) +.. c:function:: void glm_vec3_maxadd(vec3 a, vec3 b, vec3 dest) + + | add max of two vector to result/dest + | it applies += operator so dest must be initialized + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** dest += (a * b) + +.. c:function:: void glm_vec3_minadd(vec3 a, vec3 b, vec3 dest) + + | add min of two vector to result/dest + | it applies += operator so dest must be initialized + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** dest += (a * b) + .. c:function:: void glm_vec3_flipsign(vec3 v) **DEPRACATED!** diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index 99f65cc..5bb1ac7 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -43,6 +43,8 @@ Functions: #. :c:func:`glm_vec4_subadd` #. :c:func:`glm_vec4_muladd` #. :c:func:`glm_vec4_muladds` +#. :c:func:`glm_vec4_maxadd` +#. :c:func:`glm_vec4_minadd` #. :c:func:`glm_vec4_flipsign` #. :c:func:`glm_vec4_flipsign_to` #. :c:func:`glm_vec4_inv` @@ -262,6 +264,26 @@ Functions documentation | *[in]* **s** scalar | *[out]* **dest** dest += (a * b) +.. c:function:: void glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest) + + | add max of two vector to result/dest + | it applies += operator so dest must be initialized + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** dest += (a * b) + +.. c:function:: void glm_vec4_minadd(vec4 a, vec4 b, vec4 dest) + + | add min of two vector to result/dest + | it applies += operator so dest must be initialized + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** dest += (a * b) + .. c:function:: void glm_vec4_flipsign(vec4 v) **DEPRACATED!** diff --git a/include/cglm/box.h b/include/cglm/box.h index 0fec3ee..2250c2a 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -23,7 +23,7 @@ CGLM_INLINE void glm_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]) { - vec3 v[2], xa, xb, ya, yb, za, zb, tmp; + vec3 v[2], xa, xb, ya, yb, za, zb; glm_vec3_scale(m[0], box[0][0], xa); glm_vec3_scale(m[0], box[1][0], xb); @@ -34,21 +34,17 @@ glm_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]) { glm_vec3_scale(m[2], box[0][2], za); glm_vec3_scale(m[2], box[1][2], zb); - /* min(xa, xb) + min(ya, yb) + min(za, zb) + translation */ - glm_vec3_minv(xa, xb, v[0]); - glm_vec3_minv(ya, yb, tmp); - glm_vec3_add(v[0], tmp, v[0]); - glm_vec3_minv(za, zb, tmp); - glm_vec3_add(v[0], tmp, v[0]); - glm_vec3_add(v[0], m[3], v[0]); + /* translation + min(xa, xb) + min(ya, yb) + min(za, zb) */ + glm_vec3(m[3], v[0]); + glm_vec3_minadd(xa, xb, v[0]); + glm_vec3_minadd(ya, yb, v[0]); + glm_vec3_minadd(za, zb, v[0]); - /* max(xa, xb) + max(ya, yb) + max(za, zb) + translation */ - glm_vec3_maxv(xa, xb, v[1]); - glm_vec3_maxv(ya, yb, tmp); - glm_vec3_add(v[1], tmp, v[1]); - glm_vec3_maxv(za, zb, tmp); - glm_vec3_add(v[1], tmp, v[1]); - glm_vec3_add(v[1], m[3], v[1]); + /* translation + max(xa, xb) + max(ya, yb) + max(za, zb) */ + glm_vec3(m[3], v[1]); + glm_vec3_maxadd(xa, xb, v[1]); + glm_vec3_maxadd(ya, yb, v[1]); + glm_vec3_maxadd(za, zb, v[1]); glm_vec3_copy(v[0], dest[0]); glm_vec3_copy(v[1], dest[1]); diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 106257e..5b77170 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -112,6 +112,14 @@ CGLM_EXPORT void glmc_vec3_muladds(vec3 a, float s, vec3 dest); +CGLM_EXPORT +void +glmc_vec3_maxadd(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_minadd(vec3 a, vec3 b, vec3 dest); + CGLM_EXPORT void glmc_vec3_negate(vec3 v); diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index 1923da6..9a72510 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -117,6 +117,14 @@ CGLM_EXPORT void glmc_vec4_muladds(vec4 a, float s, vec4 dest); +CGLM_EXPORT +void +glmc_vec4_maxadd(vec4 a, vec4 b, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_minadd(vec4 a, vec4 b, vec4 dest); + CGLM_EXPORT void glmc_vec4_negate(vec4 v); diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index d311c27..04d697b 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -37,6 +37,8 @@ CGLM_INLINE void glm_vec3_subadd(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_muladd(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_muladds(vec3 a, float s, vec3 dest); + CGLM_INLINE void glm_vec3_maxadd(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec3_minadd(vec3 a, vec3 b, vec3 dest); CGLM_INLINE void glm_vec3_flipsign(vec3 v); CGLM_INLINE void glm_vec3_flipsign_to(vec3 v, vec3 dest); CGLM_INLINE void glm_vec3_negate_to(vec3 v, vec3 dest); @@ -419,6 +421,40 @@ glm_vec3_muladds(vec3 a, float s, vec3 dest) { dest[2] += a[2] * s; } +/*! + * @brief add max of two vector 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_vec3_maxadd(vec3 a, vec3 b, vec3 dest) { + dest[0] += glm_max(a[0], b[0]); + dest[1] += glm_max(a[1], b[1]); + dest[2] += glm_max(a[2], b[2]); +} + +/*! + * @brief add min of two vector to result/dest + * + * it applies += operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest += min(a, b) + */ +CGLM_INLINE +void +glm_vec3_minadd(vec3 a, vec3 b, vec3 dest) { + dest[0] += glm_min(a[0], b[0]); + dest[1] += glm_min(a[1], b[1]); + dest[2] += glm_min(a[2], b[2]); +} + /*! * @brief negate vector components and store result in dest * @@ -732,7 +768,7 @@ glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) { /* from + s * (to - from) */ glm_vec3_broadcast(glm_clamp_zo(t), s); glm_vec3_sub(to, from, v); - glm_vec3_mulv(s, v, v); + glm_vec3_mul(s, v, v); glm_vec3_add(from, v, dest); } diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 2e3f6cf..5391047 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -34,6 +34,9 @@ CGLM_INLINE void glm_vec4_addadd(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_subadd(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_muladd(vec4 a, vec4 b, vec4 dest); + CGLM_INLINE void glm_vec4_muladds(vec4 a, float s, vec4 dest); + CGLM_INLINE void glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest); + CGLM_INLINE void glm_vec4_minadd(vec4 a, vec4 b, vec4 dest); CGLM_INLINE void glm_vec4_negate(vec4 v); CGLM_INLINE void glm_vec4_inv(vec4 v); CGLM_INLINE void glm_vec4_inv_to(vec4 v, vec4 dest); @@ -45,7 +48,6 @@ CGLM_INLINE void glm_vec4_clamp(vec4 v, float minVal, float maxVal); CGLM_INLINE void glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) - DEPRECATED: glm_vec4_dup glm_vec4_flipsign @@ -521,6 +523,54 @@ glm_vec4_muladds(vec4 a, float s, vec4 dest) { #endif } +/*! + * @brief add max of two vector 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_vec4_maxadd(vec4 a, vec4 b, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glmm_store(dest, _mm_add_ps(glmm_load(dest), + _mm_max_ps(glmm_load(a), + glmm_load(b)))); +#else + dest[0] += glm_max(a[0], b[0]); + dest[1] += glm_max(a[1], b[1]); + dest[2] += glm_max(a[2], b[2]); + dest[3] += glm_max(a[3], b[3]); +#endif +} + +/*! + * @brief add min of two vector to result/dest + * + * it applies += operator so dest must be initialized + * + * @param[in] a vector + * @param[in] s scalar + * @param[out] dest dest += min(a, b) + */ +CGLM_INLINE +void +glm_vec4_minadd(vec4 a, vec4 b, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glmm_store(dest, _mm_add_ps(glmm_load(dest), + _mm_min_ps(glmm_load(a), + glmm_load(b)))); +#else + dest[0] += glm_min(a[0], b[0]); + dest[1] += glm_min(a[1], b[1]); + dest[2] += glm_min(a[2], b[2]); + dest[3] += glm_min(a[3], b[3]); +#endif +} + /*! * @brief negate vector components and store result in dest * @@ -694,7 +744,7 @@ glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) { /* from + s * (to - from) */ glm_vec4_broadcast(glm_clamp_zo(t), s); glm_vec4_sub(to, from, v); - glm_vec4_mulv(s, v, v); + glm_vec4_mul(s, v, v); glm_vec4_add(from, v, dest); } diff --git a/src/vec3.c b/src/vec3.c index 1b6ef3c..7b20888 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -146,6 +146,18 @@ glmc_vec3_muladds(vec3 a, float s, vec3 dest) { glm_vec3_muladds(a, s, dest); } +CGLM_EXPORT +void +glmc_vec3_maxadd(vec3 a, vec3 b, vec3 dest) { + glm_vec3_maxadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec3_minadd(vec3 a, vec3 b, vec3 dest) { + glm_vec3_minadd(a, b, dest); +} + CGLM_EXPORT void glmc_vec3_negate(vec3 v) { diff --git a/src/vec4.c b/src/vec4.c index 97b0da4..1a49710 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -152,6 +152,18 @@ glmc_vec4_muladds(vec4 a, float s, vec4 dest) { glm_vec4_muladds(a, s, dest); } +CGLM_EXPORT +void +glmc_vec4_maxadd(vec4 a, vec4 b, vec4 dest) { + glm_vec4_maxadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec4_minadd(vec4 a, vec4 b, vec4 dest) { + glm_vec4_minadd(a, b, dest); +} + CGLM_EXPORT void glmc_vec4_negate(vec4 v) { From b47d148b8125c33d4da7a990931226fc85f099c2 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 2 Dec 2018 21:35:31 +0300 Subject: [PATCH 214/292] Update README.md --- README.md | 67 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index c9d92c0..bebbcbe 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ you have the latest version - **[major change]** by starting v0.4.0, quaternions are stored as [x, y, z, w], it was [w, x, y, z] in v0.3.5 and earlier versions - **[api rename]** by starting v0.4.5, **glm_simd** functions are renamed to **glmm_** - **[new option]** by starting v0.4.5, you can disable alignment requirement, check options in docs. +- **[major change]** by starting v0.5.0, vec3 functions uses **glm_vec3_** namespace, it was **glm_vec_** until v0.5.0 #### Note for C++ developers: If you don't aware about original GLM library yet, you may also want to look at: @@ -81,6 +82,7 @@ Currently *cglm* uses default clip space configuration (-1, 1) for camera functi - frustum (extract view frustum planes, corners...) - bounding box (AABB in Frustum (culling), crop, merge...) - project, unproject +- and other...
@@ -122,39 +124,6 @@ glm_mul(T, R, modelMat); glm_inv_tr(modelMat); ``` -## Contributors - -This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. - - - -## Backers - -Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/cglm#backer)] - - - - -## Sponsors - -Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/cglm#sponsor)] - - - - - - - - - - - - - - -## License -MIT. check the LICENSE file - ## Build ### Unix (Autotools) @@ -284,3 +253,35 @@ You can pass same way to another APIs e.g. Vulkan, DX... - [ ] Unaligned operations (e.g. `glm_umat4_mul`) - [x] Extra documentation - [ ] ARM Neon Arch (In Progress) + + +## Contributors + +This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. + + + +## Backers + +Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/cglm#backer)] + + + + +## Sponsors + +Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/cglm#sponsor)] + + + + + + + + + + + + +## License +MIT. check the LICENSE file From 2f632c6311f606c3110e501240360fbfaffc5c6b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 2 Dec 2018 21:35:50 +0300 Subject: [PATCH 215/292] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bebbcbe..e72c70a 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ you have the latest version - **[major change]** by starting v0.4.0, quaternions are stored as [x, y, z, w], it was [w, x, y, z] in v0.3.5 and earlier versions - **[api rename]** by starting v0.4.5, **glm_simd** functions are renamed to **glmm_** - **[new option]** by starting v0.4.5, you can disable alignment requirement, check options in docs. -- **[major change]** by starting v0.5.0, vec3 functions uses **glm_vec3_** namespace, it was **glm_vec_** until v0.5.0 +- **[major change]** by starting v0.5.0, vec3 functions use **glm_vec3_** namespace, it was **glm_vec_** until v0.5.0 #### Note for C++ developers: If you don't aware about original GLM library yet, you may also want to look at: From b23d65bef59b3cc788d6f6d926c4f596bf637b8f Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 5 Dec 2018 16:32:13 +0300 Subject: [PATCH 216/292] now working on v0.5.1 --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 6d878d7..382dcd7 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.5.0], [info@recp.me]) +AC_INIT([cglm], [0.5.1], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index 5ce0313..aed901e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.5.0' +version = u'0.5.1' # The full version, including alpha/beta/rc tags. -release = u'0.5.0' +release = u'0.5.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index d76d84f..f0b9c2e 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 5 -#define CGLM_VERSION_PATCH 0 +#define CGLM_VERSION_PATCH 1 #endif /* cglm_version_h */ From 92605f845abaa7707f2e7666caefdc57f14923d6 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 5 Dec 2018 16:34:22 +0300 Subject: [PATCH 217/292] test: fix comparing two float values in tests --- include/cglm/vec3.h | 2 +- include/cglm/vec4.h | 8 ++++---- test/src/test_mat3.c | 4 ++-- test/src/test_mat4.c | 4 ++-- test/src/test_quat.c | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 04d697b..e5994ba 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -444,7 +444,7 @@ glm_vec3_maxadd(vec3 a, vec3 b, vec3 dest) { * it applies += operator so dest must be initialized * * @param[in] a vector - * @param[in] s scalar + * @param[in] b scalar * @param[out] dest dest += min(a, b) */ CGLM_INLINE diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 5391047..97a915b 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -331,9 +331,9 @@ glm_vec4_subs(vec4 v, float s, vec4 dest) { /*! * @brief multiply two vector (component-wise multiplication) * - * @param a vector1 - * @param b vector2 - * @param d dest = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]) + * @param a vector1 + * @param b vector2 + * @param dest dest = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]) */ CGLM_INLINE void @@ -553,7 +553,7 @@ glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest) { * it applies += operator so dest must be initialized * * @param[in] a vector - * @param[in] s scalar + * @param[in] b scalar * @param[out] dest dest += min(a, b) */ CGLM_INLINE diff --git a/test/src/test_mat3.c b/test/src/test_mat3.c index d97d1f5..e0de7c6 100644 --- a/test/src/test_mat3.c +++ b/test/src/test_mat3.c @@ -24,9 +24,9 @@ test_mat3(void **state) { for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { if (i == j) - assert_true(m3[i][j] == 1.0f); + assert_true(glm_eq(m3[i][j], 1.0f)); else - assert_true(m3[i][j] == 0.0f); + assert_true(glm_eq(m3[i][j], 0.0f)); } } diff --git a/test/src/test_mat4.c b/test/src/test_mat4.c index 7e4c488..f369829 100644 --- a/test/src/test_mat4.c +++ b/test/src/test_mat4.c @@ -24,9 +24,9 @@ test_mat4(void **state) { for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { if (i == j) - assert_true(m3[i][j] == 1.0f); + assert_true(glm_eq(m3[i][j], 1.0f)); else - assert_true(m3[i][j] == 0.0f); + assert_true(glm_eq(m3[i][j], 0.0f)); } } diff --git a/test/src/test_quat.c b/test/src/test_quat.c index 62e2306..0d64367 100644 --- a/test/src/test_quat.c +++ b/test/src/test_quat.c @@ -25,7 +25,7 @@ test_quat(void **state) { /* 0. test identiy quat */ glm_quat_identity(q4); - assert_true(glm_quat_real(q4) == cosf(glm_rad(0.0f) * 0.5f)); + assert_true(glm_eq(glm_quat_real(q4), cosf(glm_rad(0.0f) * 0.5f))); glm_quat_mat4(q4, rot1); test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009); @@ -118,7 +118,7 @@ test_quat(void **state) { /* 9. test imag, real */ /* 9.1 real */ - assert_true(glm_quat_real(q4) == cosf(glm_rad(-90.0f) * 0.5f)); + assert_true(glm_eq(glm_quat_real(q4), cosf(glm_rad(-90.0f) * 0.5f))); /* 9.1 imag */ glm_quat_imag(q4, imag); From 2ef9c23a6c9a8bd2f96f7310f0a3397b32af4d59 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 6 Dec 2018 18:01:52 +0300 Subject: [PATCH 218/292] vec: normalize cross product helper --- docs/source/vec3.rst | 20 ++++++++++++---- include/cglm/call/vec3.h | 6 ++++- include/cglm/cam.h | 4 +--- include/cglm/vec3.h | 49 ++++++++++++++++++++++++++-------------- include/cglm/vec4.h | 1 - src/vec3.c | 10 ++++++-- 6 files changed, 61 insertions(+), 29 deletions(-) diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index a625f5c..b431528 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -39,7 +39,6 @@ Functions: #. :c:func:`glm_vec3_zero` #. :c:func:`glm_vec3_one` #. :c:func:`glm_vec3_dot` -#. :c:func:`glm_vec3_cross` #. :c:func:`glm_vec3_norm2` #. :c:func:`glm_vec3_norm` #. :c:func:`glm_vec3_add` @@ -65,6 +64,8 @@ Functions: #. :c:func:`glm_vec3_negate_to` #. :c:func:`glm_vec3_normalize` #. :c:func:`glm_vec3_normalize_to` +#. :c:func:`glm_vec3_cross` +#. :c:func:`glm_vec3_crossn` #. :c:func:`glm_vec3_distance2` #. :c:func:`glm_vec3_distance` #. :c:func:`glm_vec3_angle` @@ -125,12 +126,21 @@ Functions documentation .. c:function:: void glm_vec3_cross(vec3 a, vec3 b, vec3 d) - cross product + cross product of two vector (RH) Parameters: - | *[in]* **a** source 1 - | *[in]* **b** source 2 - | *[out]* **d** destination + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** destination + +.. c:function:: void glm_vec3_crossn(vec3 a, vec3 b, vec3 dest) + + cross product of two vector (RH) and normalize the result + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** destination .. c:function:: float glm_vec3_norm2(vec3 v) diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 5b77170..9763403 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -42,7 +42,11 @@ glmc_vec3_dot(vec3 a, vec3 b); CGLM_EXPORT void -glmc_vec3_cross(vec3 a, vec3 b, vec3 d); +glmc_vec3_cross(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_crossn(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT float diff --git a/include/cglm/cam.h b/include/cglm/cam.h index acfa970..9bb3cdf 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -323,9 +323,7 @@ glm_lookat(vec3 eye, glm_vec3_sub(center, eye, f); glm_vec3_normalize(f); - glm_vec3_cross(f, up, s); - glm_vec3_normalize(s); - + glm_vec3_crossn(f, up, s); glm_vec3_cross(s, f, u); dest[0][0] = s[0]; diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index e5994ba..c53c8ab 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -21,7 +21,6 @@ CGLM_INLINE void glm_vec3_zero(vec3 v); CGLM_INLINE void glm_vec3_one(vec3 v); CGLM_INLINE float glm_vec3_dot(vec3 a, vec3 b); - CGLM_INLINE void glm_vec3_cross(vec3 a, vec3 b, vec3 d); CGLM_INLINE float glm_vec3_norm2(vec3 v); CGLM_INLINE float glm_vec3_norm(vec3 v); CGLM_INLINE void glm_vec3_add(vec3 a, vec3 b, vec3 dest); @@ -47,6 +46,8 @@ CGLM_INLINE void glm_vec3_inv_to(vec3 v, vec3 dest); CGLM_INLINE void glm_vec3_normalize(vec3 v); CGLM_INLINE void glm_vec3_normalize_to(vec3 v, vec3 dest); + CGLM_INLINE void glm_vec3_cross(vec3 a, vec3 b, vec3 d); + CGLM_INLINE void glm_vec3_crossn(vec3 a, vec3 b, vec3 dest); CGLM_INLINE float glm_vec3_distance(vec3 a, vec3 b); CGLM_INLINE float glm_vec3_angle(vec3 a, vec3 b); CGLM_INLINE void glm_vec3_rotate(vec3 v, float angle, vec3 axis); @@ -166,22 +167,6 @@ glm_vec3_dot(vec3 a, vec3 b) { return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; } -/*! - * @brief vec3 cross product - * - * @param[in] a source 1 - * @param[in] b source 2 - * @param[out] d destination - */ -CGLM_INLINE -void -glm_vec3_cross(vec3 a, vec3 b, vec3 d) { - /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ - d[0] = a[1] * b[2] - a[2] * b[1]; - d[1] = a[2] * b[0] - a[0] * b[2]; - d[2] = a[0] * b[1] - a[1] * b[0]; -} - /*! * @brief norm * norm (magnitude) of vec * @@ -521,6 +506,36 @@ glm_vec3_normalize_to(vec3 v, vec3 dest) { glm_vec3_scale(v, 1.0f / norm, dest); } +/*! + * @brief cross product of two vector (RH) + * + * @param[in] a vector 1 + * @param[in] b vector 2 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_cross(vec3 a, vec3 b, vec3 dest) { + /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ + dest[0] = a[1] * b[2] - a[2] * b[1]; + dest[1] = a[2] * b[0] - a[0] * b[2]; + dest[2] = a[0] * b[1] - a[1] * b[0]; +} + +/*! + * @brief cross product of two vector (RH) and normalize the result + * + * @param[in] a vector 1 + * @param[in] b vector 2 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_crossn(vec3 a, vec3 b, vec3 dest) { + glm_vec3_cross(a, b, dest); + glm_vec3_normalize(dest); +} + /*! * @brief angle betwen two vector * diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 97a915b..0c4f613 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -426,7 +426,6 @@ glm_vec4_divs(vec4 v, float s, vec4 dest) { #endif } - /*! * @brief add two vectors and add result to sum * diff --git a/src/vec3.c b/src/vec3.c index 7b20888..14edaf6 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -40,8 +40,14 @@ glmc_vec3_dot(vec3 a, vec3 b) { CGLM_EXPORT void -glmc_vec3_cross(vec3 a, vec3 b, vec3 d) { - glm_vec3_cross(a, b, d); +glmc_vec3_cross(vec3 a, vec3 b, vec3 dest) { + glm_vec3_cross(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec3_crossn(vec3 a, vec3 b, vec3 dest) { + glm_vec3_crossn(a, b, dest); } CGLM_EXPORT From 21834b4ffb3fe5b09fa5bfc00833af3f10c435f7 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 6 Dec 2018 18:17:02 +0300 Subject: [PATCH 219/292] matrix: trace of matrix --- docs/source/mat3.rst | 11 +++++++++++ docs/source/mat4.rst | 23 +++++++++++++++++++++++ include/cglm/call/mat3.h | 4 ++++ include/cglm/call/mat4.h | 8 ++++++++ include/cglm/mat3.h | 13 +++++++++++++ include/cglm/mat4.h | 28 ++++++++++++++++++++++++++++ src/mat3.c | 6 ++++++ src/mat4.c | 12 ++++++++++++ 8 files changed, 105 insertions(+) diff --git a/docs/source/mat3.rst b/docs/source/mat3.rst index 5d590d9..8592c4e 100644 --- a/docs/source/mat3.rst +++ b/docs/source/mat3.rst @@ -29,6 +29,7 @@ Functions: #. :c:func:`glm_mat3_scale` #. :c:func:`glm_mat3_det` #. :c:func:`glm_mat3_inv` +#. :c:func:`glm_mat3_trace` #. :c:func:`glm_mat3_swap_col` #. :c:func:`glm_mat3_swap_row` @@ -133,6 +134,16 @@ Functions documentation | *[in]* **mat** matrix | *[out]* **dest** destination (inverse matrix) +.. c:function:: void glm_mat3_trace(mat3 m) + + | sum of the elements on the main diagonal from upper left to the lower right + + Parameters: + | *[in]* **m** matrix + + Returns: + trace of matrix + .. c:function:: void glm_mat3_swap_col(mat3 mat, int col1, int col2) swap two matrix columns diff --git a/docs/source/mat4.rst b/docs/source/mat4.rst index ae37147..30f48fe 100644 --- a/docs/source/mat4.rst +++ b/docs/source/mat4.rst @@ -33,6 +33,8 @@ Functions: #. :c:func:`glm_mat4_mulN` #. :c:func:`glm_mat4_mulv` #. :c:func:`glm_mat4_mulv3` +#. :c:func:`glm_mat3_trace` +#. :c:func:`glm_mat3_trace3` #. :c:func:`glm_mat4_quat` #. :c:func:`glm_mat4_transpose_to` #. :c:func:`glm_mat4_transpose` @@ -156,6 +158,27 @@ Functions documentation | *[in]* **v** vec3 (right, column vector) | *[out]* **dest** vec3 (result, column vector) +.. c:function:: void glm_mat4_trace(mat4 m) + + | sum of the elements on the main diagonal from upper left to the lower right + + Parameters: + | *[in]* **m** matrix + + Returns: + trace of matrix + +.. c:function:: void glm_mat4_trace3(mat4 m) + + | trace of matrix (rotation part) + | sum of the elements on the main diagonal from upper left to the lower right + + Parameters: + | *[in]* **m** matrix + + Returns: + trace of matrix + .. c:function:: void glm_mat4_quat(mat4 m, versor dest) convert mat4's rotation part to quaternion diff --git a/include/cglm/call/mat3.h b/include/cglm/call/mat3.h index 9270113..f27e187 100644 --- a/include/cglm/call/mat3.h +++ b/include/cglm/call/mat3.h @@ -44,6 +44,10 @@ CGLM_EXPORT void glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest); +CGLM_EXPORT +float +glmc_mat3_trace(mat3 m); + CGLM_EXPORT void glmc_mat3_quat(mat3 m, versor dest); diff --git a/include/cglm/call/mat4.h b/include/cglm/call/mat4.h index daa7b7e..7e76f73 100644 --- a/include/cglm/call/mat4.h +++ b/include/cglm/call/mat4.h @@ -61,6 +61,14 @@ CGLM_EXPORT void glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest); +CGLM_EXPORT +float +glmc_mat4_trace(mat4 m); + +CGLM_EXPORT +float +glmc_mat4_trace3(mat4 m); + CGLM_EXPORT void glmc_mat4_quat(mat4 m, versor dest); diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 2d6523c..05bcf11 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -21,6 +21,7 @@ CGLM_INLINE void glm_mat3_transpose_to(mat3 m, mat3 dest); CGLM_INLINE void glm_mat3_transpose(mat3 m); CGLM_INLINE void glm_mat3_mulv(mat3 m, vec3 v, vec3 dest); + CGLM_INLINE float glm_mat3_trace(mat3 m); CGLM_INLINE void glm_mat3_scale(mat3 m, float s); CGLM_INLINE float glm_mat3_det(mat3 mat); CGLM_INLINE void glm_mat3_inv(mat3 mat, mat3 dest); @@ -207,6 +208,18 @@ glm_mat3_mulv(mat3 m, vec3 v, vec3 dest) { dest[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2]; } +/*! + * @brief trace of matrix + * + * sum of the elements on the main diagonal from upper left to the lower right + * + * @param[in] m matrix + */ +CGLM_INLINE +float +glm_mat3_trace(mat3 m) { + return m[0][0] + m[1][1] + m[2][2]; +} /*! * @brief convert mat3 to quaternion diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 8ce027d..ea3b34e 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -29,6 +29,8 @@ CGLM_INLINE void glm_mat4_mulN(mat4 *matrices[], int len, mat4 dest); CGLM_INLINE void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); CGLM_INLINE void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest); + CGLM_INLINE float glm_mat4_trace(mat4 m); + CGLM_INLINE float glm_mat4_trace3(mat4 m); CGLM_INLINE void glm_mat4_transpose_to(mat4 m, mat4 dest); CGLM_INLINE void glm_mat4_transpose(mat4 m); CGLM_INLINE void glm_mat4_scale_p(mat4 m, float s); @@ -338,6 +340,32 @@ glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) { #endif } +/*! + * @brief trace of matrix + * + * sum of the elements on the main diagonal from upper left to the lower right + * + * @param[in] m matrix + */ +CGLM_INLINE +float +glm_mat4_trace(mat4 m) { + return m[0][0] + m[1][1] + m[2][2] + m[3][3]; +} + +/*! + * @brief trace of matrix (rotation part) + * + * sum of the elements on the main diagonal from upper left to the lower right + * + * @param[in] m matrix + */ +CGLM_INLINE +float +glm_mat4_trace3(mat4 m) { + return m[0][0] + m[1][1] + m[2][2]; +} + /*! * @brief convert mat4's rotation part to quaternion * diff --git a/src/mat3.c b/src/mat3.c index be603e8..acb981b 100644 --- a/src/mat3.c +++ b/src/mat3.c @@ -50,6 +50,12 @@ glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest) { glm_mat3_mulv(m, v, dest); } +CGLM_EXPORT +float +glmc_mat3_trace(mat3 m) { + return glm_mat3_trace(m); +} + CGLM_EXPORT void glmc_mat3_quat(mat3 m, versor dest) { diff --git a/src/mat4.c b/src/mat4.c index 7bb99e2..b62420e 100644 --- a/src/mat4.c +++ b/src/mat4.c @@ -74,6 +74,18 @@ glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest) { glm_mat4_mulv3(m, v, last, dest); } +CGLM_EXPORT +float +glmc_mat4_trace(mat4 m) { + return glm_mat4_trace(m); +} + +CGLM_EXPORT +float +glmc_mat4_trace3(mat4 m) { + return glm_mat4_trace3(m); +} + CGLM_EXPORT void glmc_mat4_quat(mat4 m, versor dest) { From 7219b02d2350f9a936192d477504adb14294606a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 25 Dec 2018 10:08:36 +0300 Subject: [PATCH 220/292] remove alignment from vec3 and mat3 --- include/cglm/types.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/include/cglm/types.h b/include/cglm/types.h index cad1042..1190b73 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -10,12 +10,12 @@ #if defined(_MSC_VER) /* do not use alignment for older visual studio versions */ -#if _MSC_VER < 1913 /* Visual Studio 2017 version 15.6 */ -# define CGLM_ALL_UNALIGNED -# define CGLM_ALIGN(X) /* no alignment */ -#else -# define CGLM_ALIGN(X) __declspec(align(X)) -#endif +# if _MSC_VER < 1913 /* Visual Studio 2017 version 15.6 */ +# define CGLM_ALL_UNALIGNED +# define CGLM_ALIGN(X) /* no alignment */ +# else +# define CGLM_ALIGN(X) __declspec(align(X)) +# endif #else # define CGLM_ALIGN(X) __attribute((aligned(X))) #endif @@ -33,20 +33,18 @@ #endif typedef float vec2[2]; -typedef CGLM_ALIGN_IF(8) float vec3[3]; +typedef float vec3[3]; typedef int ivec3[3]; typedef CGLM_ALIGN_IF(16) float vec4[4]; +typedef vec4 versor; +typedef vec3 mat3[3]; #ifdef __AVX__ -typedef CGLM_ALIGN_IF(32) vec3 mat3[3]; typedef CGLM_ALIGN_IF(32) vec4 mat4[4]; #else -typedef vec3 mat3[3]; typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; #endif -typedef vec4 versor; - #define GLM_E 2.71828182845904523536028747135266250 /* e */ #define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */ #define GLM_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */ From d17c99215dfe9d9cda7b75cf1c91e251c00516f2 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 26 Dec 2018 09:57:52 +0300 Subject: [PATCH 221/292] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e72c70a..dffa54c 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ you have the latest version - **[api rename]** by starting v0.4.5, **glm_simd** functions are renamed to **glmm_** - **[new option]** by starting v0.4.5, you can disable alignment requirement, check options in docs. - **[major change]** by starting v0.5.0, vec3 functions use **glm_vec3_** namespace, it was **glm_vec_** until v0.5.0 +- **[major change]** by starting v0.5.1, built-in alignment is removed from **vec3** and **mat3** types #### Note for C++ developers: If you don't aware about original GLM library yet, you may also want to look at: From e3d3cd8ab8fd1c21db6c84b8b940e81ab6caab31 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 15 Jan 2019 12:08:54 +0300 Subject: [PATCH 222/292] now working on v0.5.2 --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 382dcd7..1349b90 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.5.1], [info@recp.me]) +AC_INIT([cglm], [0.5.2], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index aed901e..33ea83b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.5.1' +version = u'0.5.2' # The full version, including alpha/beta/rc tags. -release = u'0.5.1' +release = u'0.5.2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index f0b9c2e..5066576 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 5 -#define CGLM_VERSION_PATCH 1 +#define CGLM_VERSION_PATCH 2 #endif /* cglm_version_h */ From 07e60bd0981840ec183d6e2ed23415ba63168107 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 16 Jan 2019 14:59:58 +0300 Subject: [PATCH 223/292] cam: extend frustum's far distance helper (#71) * this will help to implement zoom easily --- docs/source/cam.rst | 11 +++++++++++ include/cglm/call/cam.h | 4 ++++ include/cglm/cam.h | 24 ++++++++++++++++++++++++ src/cam.c | 6 ++++++ 4 files changed, 45 insertions(+) diff --git a/docs/source/cam.rst b/docs/source/cam.rst index 6e4cc94..7d47fbc 100644 --- a/docs/source/cam.rst +++ b/docs/source/cam.rst @@ -36,6 +36,7 @@ Functions: #. :c:func:`glm_ortho_default` #. :c:func:`glm_ortho_default_s` #. :c:func:`glm_perspective` +#. :c:func:`glm_persp_move_far` #. :c:func:`glm_perspective_default` #. :c:func:`glm_perspective_resize` #. :c:func:`glm_lookat` @@ -145,6 +146,16 @@ Functions documentation | *[in]* **farVal** far clipping planes | *[out]* **dest** result matrix +.. c:function:: void glm_persp_move_far(mat4 proj, float deltaFar) + + | extend perspective projection matrix's far distance + + | this function does not guarantee far >= near, be aware of that! + + Parameters: + | *[in, out]* **proj** projection matrix to extend + | *[in]* **deltaFar** distance from existing far (negative to shink) + .. c:function:: void glm_perspective_default(float aspect, mat4 dest) | set up perspective projection matrix with default near/far diff --git a/include/cglm/call/cam.h b/include/cglm/call/cam.h index befc9b4..017b6fc 100644 --- a/include/cglm/call/cam.h +++ b/include/cglm/call/cam.h @@ -61,6 +61,10 @@ glmc_perspective(float fovy, float farVal, mat4 dest); +CGLM_EXPORT +void +glmc_persp_move_far(mat4 proj, float deltaFar); + CGLM_EXPORT void glmc_perspective_default(float aspect, mat4 dest); diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 9bb3cdf..314b065 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -271,6 +271,30 @@ glm_perspective(float fovy, dest[3][2] = 2.0f * nearVal * farVal * fn; } +/*! + * @brief extend perspective projection matrix's far distance + * + * this function does not guarantee far >= near, be aware of that! + * + * @param[in, out] proj projection matrix to extend + * @param[in] deltaFar distance from existing far (negative to shink) + */ +CGLM_INLINE +void +glm_persp_move_far(mat4 proj, float deltaFar) { + float fn, farVal, nearVal, p22, p32; + + p22 = proj[2][2]; + p32 = proj[3][2]; + + nearVal = p32 / (p22 - 1.0f); + farVal = p32 / (p22 + 1.0f) + deltaFar; + fn = 1.0f / (nearVal - farVal); + + proj[2][2] = (nearVal + farVal) * fn; + proj[3][2] = 2.0f * nearVal * farVal * fn; +} + /*! * @brief set up perspective projection matrix with default near/far * and angle values diff --git a/src/cam.c b/src/cam.c index 4a8567f..39ac210 100644 --- a/src/cam.c +++ b/src/cam.c @@ -88,6 +88,12 @@ glmc_perspective(float fovy, dest); } +CGLM_EXPORT +void +glmc_persp_move_far(mat4 proj, float deltaFar) { + glm_persp_move_far(proj, deltaFar); +} + CGLM_EXPORT void glmc_perspective_default(float aspect, mat4 dest) { From b117f3bf80b8333245b56b5ec152aff90dfdabd0 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 21 Jan 2019 23:14:04 +0300 Subject: [PATCH 224/292] neon: add neon support for most vec4 operations --- include/cglm/simd/intrin.h | 18 ++++++++-- include/cglm/vec4.h | 71 ++++++++++++++++++++++++++++++++------ 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index f4854bd..fb577ea 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -105,10 +105,24 @@ glmm_store3(__m128 vx, float v[3]) { #endif +#if defined(__SSE3__) +# include +#endif + +#if defined(__SSE4_1__) +# include +#endif + +#if defined(__SSE4_2__) +# include +#endif + /* ARM Neon */ -#if defined(__ARM_NEON) && defined(__ARM_NEON_FP) +#if defined(__ARM_NEON) # include -# define CGLM_NEON_FP 1 +# if defined(__ARM_NEON_FP) +# define CGLM_NEON_FP 1 +# endif #else # undef CGLM_NEON_FP #endif diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 0c4f613..ad2fb45 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -122,6 +122,8 @@ void glm_vec4_copy(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, glmm_load(v)); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vld1q_f32(v)); #else dest[0] = v[0]; dest[1] = v[1]; @@ -157,6 +159,8 @@ void glm_vec4_zero(vec4 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(v, _mm_setzero_ps()); +#elif defined(CGLM_NEON_FP) + vst1q_f32(v, vdupq_n_f32(0.0f)); #else v[0] = 0.0f; v[1] = 0.0f; @@ -175,6 +179,8 @@ void glm_vec4_one(vec4 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(v, _mm_set1_ps(1.0f)); +#elif defined(CGLM_NEON_FP) + vst1q_f32(v, vdupq_n_f32(1.0f)); #else v[0] = 1.0f; v[1] = 1.0f; @@ -194,11 +200,24 @@ glm_vec4_one(vec4 v) { CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b) { -#if defined( __SSE__ ) || defined( __SSE2__ ) +#if (defined(__SSE4_1__) || defined(__SSE4_2__)) && defined(CGLM_SSE4_DOT) + return _mm_cvtss_f32(_mm_dp_ps(glmm_load(a), glmm_load(b), 0xFF)); +#elif defined(__SSE3__) && defined(CGLM_SSE3_DOT) + __m128 x0, x1; + x0 = _mm_mul_ps(glmm_load(a), glmm_load(b)); + x1 = _mm_hadd_ps(x0, x0); + return _mm_cvtss_f32(_mm_hadd_ps(x1, x1)); +#elif defined(__SSE__) || defined(__SSE2__) __m128 x0; x0 = _mm_mul_ps(glmm_load(a), glmm_load(b)); x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 3, 2)); return _mm_cvtss_f32(_mm_add_ss(x0, glmm_shuff1(x0, 0, 1, 0, 1))); +#elif defined(CGLM_NEON_FP) + float32x4_t v0, v1, v2; + v0 = vmulq_f32(vld1q_f32(a), vld1q_f32(b)); + v1 = vaddq_f32(v0, vrev64q_f32(v0)); + v2 = vaddq_f32(v1, vcombine_f32(vget_high_f32(v1), vget_low_f32(v1))); + return vgetq_lane_f32(v2, 0); #else return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; #endif @@ -218,15 +237,7 @@ glm_vec4_dot(vec4 a, vec4 b) { CGLM_INLINE float glm_vec4_norm2(vec4 v) { -#if defined( __SSE__ ) || defined( __SSE2__ ) - __m128 x0; - x0 = glmm_load(v); - x0 = _mm_mul_ps(x0, x0); - x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 3, 2)); - return _mm_cvtss_f32(_mm_add_ss(x0, glmm_shuff1(x0, 0, 1, 0, 1))); -#else - return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]; -#endif + return glm_vec4_dot(v, v); } /*! @@ -244,7 +255,7 @@ glm_vec4_norm(vec4 v) { x0 = glmm_load(v); return _mm_cvtss_f32(_mm_sqrt_ss(glmm_dot(x0, x0))); #else - return sqrtf(glm_vec4_norm2(v)); + return sqrtf(glm_vec4_dot(v, v)); #endif } @@ -260,6 +271,8 @@ void glm_vec4_add(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(a), glmm_load(b))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vaddq_f32(vld1q_f32(a), vld1q_f32(b))); #else dest[0] = a[0] + b[0]; dest[1] = a[1] + b[1]; @@ -280,6 +293,8 @@ void glm_vec4_adds(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(v), _mm_set1_ps(s))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vaddq_f32(vld1q_f32(v), vdupq_n_f32(s))); #else dest[0] = v[0] + s; dest[1] = v[1] + s; @@ -300,6 +315,8 @@ void glm_vec4_sub(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_sub_ps(glmm_load(a), glmm_load(b))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vsubq_f32(vld1q_f32(a), vld1q_f32(b))); #else dest[0] = a[0] - b[0]; dest[1] = a[1] - b[1]; @@ -320,6 +337,8 @@ void glm_vec4_subs(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_sub_ps(glmm_load(v), _mm_set1_ps(s))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vsubq_f32(vld1q_f32(v), vdupq_n_f32(s))); #else dest[0] = v[0] - s; dest[1] = v[1] - s; @@ -340,6 +359,8 @@ void glm_vec4_mul(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_mul_ps(glmm_load(a), glmm_load(b))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vmulq_f32(vld1q_f32(a), vld1q_f32(b))); #else dest[0] = a[0] * b[0]; dest[1] = a[1] * b[1]; @@ -360,6 +381,8 @@ void glm_vec4_scale(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_mul_ps(glmm_load(v), _mm_set1_ps(s))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vmulq_f32(vld1q_f32(v), vdupq_n_f32(s))); #else dest[0] = v[0] * s; dest[1] = v[1] * s; @@ -442,6 +465,10 @@ glm_vec4_addadd(vec4 a, vec4 b, vec4 dest) { glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_add_ps(glmm_load(a), glmm_load(b)))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vaddq_f32(vld1q_f32(dest), + vaddq_f32(vld1q_f32(a), + vld1q_f32(b)))); #else dest[0] += a[0] + b[0]; dest[1] += a[1] + b[1]; @@ -466,6 +493,10 @@ glm_vec4_subadd(vec4 a, vec4 b, vec4 dest) { glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_sub_ps(glmm_load(a), glmm_load(b)))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vaddq_f32(vld1q_f32(dest), + vsubq_f32(vld1q_f32(a), + vld1q_f32(b)))); #else dest[0] += a[0] - b[0]; dest[1] += a[1] - b[1]; @@ -490,6 +521,10 @@ glm_vec4_muladd(vec4 a, vec4 b, vec4 dest) { glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_mul_ps(glmm_load(a), glmm_load(b)))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vaddq_f32(vld1q_f32(dest), + vmulq_f32(vld1q_f32(a), + vld1q_f32(b)))); #else dest[0] += a[0] * b[0]; dest[1] += a[1] * b[1]; @@ -514,6 +549,10 @@ glm_vec4_muladds(vec4 a, float s, vec4 dest) { glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_mul_ps(glmm_load(a), _mm_set1_ps(s)))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vaddq_f32(vld1q_f32(dest), + vsubq_f32(vld1q_f32(a), + vdupq_n_f32(s)))); #else dest[0] += a[0] * s; dest[1] += a[1] * s; @@ -538,6 +577,10 @@ glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest) { glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_max_ps(glmm_load(a), glmm_load(b)))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vaddq_f32(vld1q_f32(dest), + vmaxq_f32(vld1q_f32(a), + vld1q_f32(b)))); #else dest[0] += glm_max(a[0], b[0]); dest[1] += glm_max(a[1], b[1]); @@ -562,6 +605,10 @@ glm_vec4_minadd(vec4 a, vec4 b, vec4 dest) { glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_min_ps(glmm_load(a), glmm_load(b)))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vaddq_f32(vld1q_f32(dest), + vminq_f32(vld1q_f32(a), + vld1q_f32(b)))); #else dest[0] += glm_min(a[0], b[0]); dest[1] += glm_min(a[1], b[1]); @@ -581,6 +628,8 @@ void glm_vec4_negate_to(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, veorq_s32(vld1q_f32(v), vdupq_n_f32(-0.0f))); #else dest[0] = -v[0]; dest[1] = -v[1]; From f0c2a2984e7a8243bb18c6d7f1070c462a1708a0 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 22 Jan 2019 09:05:38 +0300 Subject: [PATCH 225/292] simd, neon: add missing neon support for vec4 --- include/cglm/vec4.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index ad2fb45..5d0e466 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -725,6 +725,8 @@ void glm_vec4_maxv(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_max_ps(glmm_load(a), glmm_load(b))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vmaxq_f32(vld1q_f32(a), vld1q_f32(b))); #else dest[0] = glm_max(a[0], b[0]); dest[1] = glm_max(a[1], b[1]); @@ -745,6 +747,8 @@ void glm_vec4_minv(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_min_ps(glmm_load(a), glmm_load(b))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vminq_f32(vld1q_f32(a), vld1q_f32(b))); #else dest[0] = glm_min(a[0], b[0]); dest[1] = glm_min(a[1], b[1]); @@ -766,6 +770,9 @@ glm_vec4_clamp(vec4 v, float minVal, float maxVal) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(v, _mm_min_ps(_mm_max_ps(glmm_load(v), _mm_set1_ps(minVal)), _mm_set1_ps(maxVal))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(v, vminq_f32(vmaxq_f32(vld1q_f32(v), vdupq_n_f32(minVal)), + vdupq_n_f32(maxVal))); #else v[0] = glm_clamp(v[0], minVal, maxVal); v[1] = glm_clamp(v[1], minVal, maxVal); From f65f1d491bec03b6de58fb12918e7083f7f5a1ce Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 22 Jan 2019 09:23:51 +0300 Subject: [PATCH 226/292] simd: optimize vec4_distance with sse and neon --- include/cglm/vec4.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 5d0e466..03dc405 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -707,10 +707,25 @@ glm_vec4_normalize(vec4 v) { CGLM_INLINE float glm_vec4_distance(vec4 a, vec4 b) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + __m128 x0; + x0 = _mm_sub_ps(glmm_load(b), glmm_load(a)); + x0 = _mm_mul_ps(x0, x0); + x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 3, 2)); + return _mm_cvtss_f32(_mm_sqrt_ss(_mm_add_ss(x0, + glmm_shuff1(x0, 0, 1, 0, 1)))); +#elif defined(CGLM_NEON_FP) + float32x4_t v0; + float32_t r; + v0 = vsubq_f32(vld1q_f32(a), vld1q_f32(b)); + r = vaddvq_f32(vmulq_f32(v0, v0)); + return sqrtf(r); +#else return sqrtf(glm_pow2(b[0] - a[0]) + glm_pow2(b[1] - a[1]) + glm_pow2(b[2] - a[2]) + glm_pow2(b[3] - a[3])); +#endif } /*! From be6aa9a89a1a5132fc0defa7ae44c83c636c5937 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 22 Jan 2019 09:39:57 +0300 Subject: [PATCH 227/292] simd: optimize some mat4 operations with neon --- include/cglm/mat4.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index ea3b34e..56c6de3 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -118,6 +118,11 @@ glm_mat4_copy(mat4 mat, mat4 dest) { glmm_store(dest[1], glmm_load(mat[1])); glmm_store(dest[2], glmm_load(mat[2])); glmm_store(dest[3], glmm_load(mat[3])); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest[0], vld1q_f32(mat[0])); + vst1q_f32(dest[1], vld1q_f32(mat[1])); + vst1q_f32(dest[2], vld1q_f32(mat[2])); + vst1q_f32(dest[3], vld1q_f32(mat[3])); #else glm_mat4_ucopy(mat, dest); #endif @@ -252,7 +257,7 @@ glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest) { glm_mat4_mul_avx(m1, m2, dest); #elif defined( __SSE__ ) || defined( __SSE2__ ) glm_mat4_mul_sse2(m1, m2, dest); -#elif defined( __ARM_NEON_FP ) +#elif defined(CGLM_NEON_FP) glm_mat4_mul_neon(m1, m2, dest); #else float a00 = m1[0][0], a01 = m1[0][1], a02 = m1[0][2], a03 = m1[0][3], @@ -506,6 +511,13 @@ void glm_mat4_scale(mat4 m, float s) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mat4_scale_sse2(m, s); +#elif defined(CGLM_NEON_FP) + float32x4_t v0; + v0 = vdupq_n_f32(s); + vst1q_f32(m[0], vmulq_f32(vld1q_f32(m[0]), v0)); + vst1q_f32(m[1], vmulq_f32(vld1q_f32(m[1]), v0)); + vst1q_f32(m[2], vmulq_f32(vld1q_f32(m[2]), v0)); + vst1q_f32(m[3], vmulq_f32(vld1q_f32(m[3]), v0)); #else glm_mat4_scale_p(m, s); #endif From 31bb303c55fde6d93aa52c9083e64fd1b2b7be54 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 24 Jan 2019 10:17:49 +0300 Subject: [PATCH 228/292] simd: organise SIMD-functions * optimize dot product --- .gitignore | 1 + CREDITS | 3 + include/cglm/quat.h | 2 +- include/cglm/simd/arm.h | 41 +++++++++++ include/cglm/simd/intrin.h | 114 ++++++++++--------------------- include/cglm/simd/x86.h | 136 +++++++++++++++++++++++++++++++++++++ include/cglm/vec4.h | 28 ++------ makefile.am | 52 +++++++------- win/cglm.vcxproj | 2 + win/cglm.vcxproj.filters | 6 ++ 10 files changed, 259 insertions(+), 126 deletions(-) create mode 100644 include/cglm/simd/arm.h create mode 100644 include/cglm/simd/x86.h diff --git a/.gitignore b/.gitignore index d500b97..195a82c 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,4 @@ win/cglm_test_* win/x64 win/x85 win/Debug +cglm-test-ios* diff --git a/CREDITS b/CREDITS index 0488bad..263dd2d 100644 --- a/CREDITS +++ b/CREDITS @@ -52,3 +52,6 @@ https://gamedev.stackexchange.com/questions/28395/rotating-vector3-by-a-quaterni 9. Sphere AABB intersect https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c + +10. Horizontal add +https://stackoverflow.com/questions/6996764/fastest-way-to-do-horizontal-float-vector-sum-on-x86 diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 1db0161..f5f29af 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -218,7 +218,7 @@ glm_quat_normalize_to(versor q, versor dest) { float dot; x0 = glmm_load(q); - xdot = glmm_dot(x0, x0); + xdot = glmm_vdot(x0, x0); dot = _mm_cvtss_f32(xdot); if (dot <= 0.0f) { diff --git a/include/cglm/simd/arm.h b/include/cglm/simd/arm.h new file mode 100644 index 0000000..5412461 --- /dev/null +++ b/include/cglm/simd/arm.h @@ -0,0 +1,41 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_simd_arm_h +#define cglm_simd_arm_h +#include "intrin.h" +#ifdef CGLM_SIMD_ARM + +#define glmm_load(p) vld1q_f32(p) +#define glmm_store(p, a) vst1q_f32(p, a) + +static inline +float +glmm_hadd(float32x4_t v) { +#if defined(__aarch64__) + return vaddvq_f32(v); +#else + v = vaddq_f32(v, vrev64q_f32(v)); + v = vaddq_f32(v, vcombine_f32(vget_high_f32(v), vget_low_f32(v))); + return vgetq_lane_f32(v, 0); +#endif +} + +static inline +float +glmm_dot(float32x4_t a, float32x4_t b) { + return glmm_hadd(vmulq_f32(a, b)); +} + +static inline +float +glmm_norm(float32x4_t a) { + return sqrtf(glmm_dot(a, a)); +} + +#endif +#endif /* cglm_simd_arm_h */ diff --git a/include/cglm/simd/intrin.h b/include/cglm/simd/intrin.h index fb577ea..a44b905 100644 --- a/include/cglm/simd/intrin.h +++ b/include/cglm/simd/intrin.h @@ -27,94 +27,39 @@ #if defined( __SSE__ ) || defined( __SSE2__ ) # include # include - -/* OPTIONAL: You may save some instructions but latency (not sure) */ -#ifdef CGLM_USE_INT_DOMAIN -# define glmm_shuff1(xmm, z, y, x, w) \ - _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(xmm), \ - _MM_SHUFFLE(z, y, x, w))) -#else -# define glmm_shuff1(xmm, z, y, x, w) \ - _mm_shuffle_ps(xmm, xmm, _MM_SHUFFLE(z, y, x, w)) -#endif - -#define glmm_shuff1x(xmm, x) glmm_shuff1(xmm, x, x, x, x) -#define glmm_shuff2(a, b, z0, y0, x0, w0, z1, y1, x1, w1) \ - glmm_shuff1(_mm_shuffle_ps(a, b, _MM_SHUFFLE(z0, y0, x0, w0)), \ - z1, y1, x1, w1) - -static inline -__m128 -glmm_dot(__m128 a, __m128 b) { - __m128 x0; - x0 = _mm_mul_ps(a, b); - x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 3, 2)); - return _mm_add_ps(x0, glmm_shuff1(x0, 0, 1, 0, 1)); -} - -static inline -__m128 -glmm_norm(__m128 a) { - return _mm_sqrt_ps(glmm_dot(a, a)); -} - -static inline -__m128 -glmm_load3(float v[3]) { - __m128i xy; - __m128 z; - - xy = _mm_loadl_epi64((const __m128i *)v); - z = _mm_load_ss(&v[2]); - - return _mm_movelh_ps(_mm_castsi128_ps(xy), z); -} - -static inline -void -glmm_store3(__m128 vx, float v[3]) { - _mm_storel_pi((__m64 *)&v[0], vx); - _mm_store_ss(&v[2], glmm_shuff1(vx, 2, 2, 2, 2)); -} - -#ifdef CGLM_ALL_UNALIGNED -# define glmm_load(p) _mm_loadu_ps(p) -# define glmm_store(p, a) _mm_storeu_ps(p, a) -#else -# define glmm_load(p) _mm_load_ps(p) -# define glmm_store(p, a) _mm_store_ps(p, a) -#endif - -#endif - -/* x86, x64 */ -#if defined( __SSE__ ) || defined( __SSE2__ ) # define CGLM_SSE_FP 1 -#endif - -#ifdef __AVX__ -# define CGLM_AVX_FP 1 - -#ifdef CGLM_ALL_UNALIGNED -# define glmm_load256(p) _mm256_loadu_ps(p) -# define glmm_store256(p, a) _mm256_storeu_ps(p, a) -#else -# define glmm_load256(p) _mm256_load_ps(p) -# define glmm_store256(p, a) _mm256_store_ps(p, a) -#endif - +# ifndef CGLM_SIMD_x86 +# define CGLM_SIMD_x86 +# endif #endif #if defined(__SSE3__) # include +# ifndef CGLM_SIMD_x86 +# define CGLM_SIMD_x86 +# endif #endif #if defined(__SSE4_1__) # include +# ifndef CGLM_SIMD_x86 +# define CGLM_SIMD_x86 +# endif #endif #if defined(__SSE4_2__) # include +# ifndef CGLM_SIMD_x86 +# define CGLM_SIMD_x86 +# endif +#endif + +#ifdef __AVX__ +# include +# define CGLM_AVX_FP 1 +# ifndef CGLM_SIMD_x86 +# define CGLM_SIMD_x86 +# endif #endif /* ARM Neon */ @@ -122,9 +67,24 @@ glmm_store3(__m128 vx, float v[3]) { # include # if defined(__ARM_NEON_FP) # define CGLM_NEON_FP 1 +# ifndef CGLM_SIMD_ARM +# define CGLM_SIMD_ARM +# endif # endif -#else -# undef CGLM_NEON_FP +#endif + +#if defined(CGLM_SIMD_x86) || defined(CGLM_NEON_FP) +# ifndef CGLM_SIMD +# define CGLM_SIMD +# endif +#endif + +#if defined(CGLM_SIMD_x86) +# include "x86.h" +#endif + +#if defined(CGLM_SIMD_ARM) +# include "arm.h" #endif #endif /* cglm_intrin_h */ diff --git a/include/cglm/simd/x86.h b/include/cglm/simd/x86.h new file mode 100644 index 0000000..520a834 --- /dev/null +++ b/include/cglm/simd/x86.h @@ -0,0 +1,136 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_simd_x86_h +#define cglm_simd_x86_h +#include "intrin.h" +#ifdef CGLM_SIMD_x86 + +#ifdef CGLM_ALL_UNALIGNED +# define glmm_load(p) _mm_loadu_ps(p) +# define glmm_store(p, a) _mm_storeu_ps(p, a) +#else +# define glmm_load(p) _mm_load_ps(p) +# define glmm_store(p, a) _mm_store_ps(p, a) +#endif + +#ifdef CGLM_USE_INT_DOMAIN +# define glmm_shuff1(xmm, z, y, x, w) \ + _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(xmm), \ + _MM_SHUFFLE(z, y, x, w))) +#else +# define glmm_shuff1(xmm, z, y, x, w) \ + _mm_shuffle_ps(xmm, xmm, _MM_SHUFFLE(z, y, x, w)) +#endif + +#define glmm_shuff1x(xmm, x) glmm_shuff1(xmm, x, x, x, x) +#define glmm_shuff2(a, b, z0, y0, x0, w0, z1, y1, x1, w1) \ + glmm_shuff1(_mm_shuffle_ps(a, b, _MM_SHUFFLE(z0, y0, x0, w0)), \ + z1, y1, x1, w1) + +#ifdef __AVX__ +# ifdef CGLM_ALL_UNALIGNED +# define glmm_load256(p) _mm256_loadu_ps(p) +# define glmm_store256(p, a) _mm256_storeu_ps(p, a) +# else +# define glmm_load256(p) _mm256_load_ps(p) +# define glmm_store256(p, a) _mm256_store_ps(p, a) +# endif +#endif + +static inline +__m128 +glmm_vhadds(__m128 v) { +#if defined(__SSE3__) + __m128 shuf, sums; + shuf = _mm_movehdup_ps(v); + sums = _mm_add_ps(v, shuf); + shuf = _mm_movehl_ps(shuf, sums); + sums = _mm_add_ss(sums, shuf); + return sums; +#else + __m128 shuf, sums; + shuf = glmm_shuff1(v, 2, 3, 0, 1); + sums = _mm_add_ps(v, shuf); + shuf = _mm_movehl_ps(shuf, sums); + sums = _mm_add_ss(sums, shuf); + return sums; +#endif +} + +static inline +float +glmm_hadd(__m128 v) { + return _mm_cvtss_f32(glmm_vhadds(v)); +} + +static inline +__m128 +glmm_vdots(__m128 a, __m128 b) { +#if (defined(__SSE4_1__) || defined(__SSE4_2__)) && defined(CGLM_SSE4_DOT) + return _mm_dp_ps(glmm_load(a), glmm_load(b), 0xFF); +#elif defined(__SSE3__) && defined(CGLM_SSE3_DOT) + __m128 x0, x1; + x0 = _mm_mul_ps(glmm_load(a), glmm_load(b)); + x1 = _mm_hadd_ps(x0, x0); + return _mm_hadd_ps(x1, x1); +#else + return glmm_vhadds(_mm_mul_ps(a, b)); +#endif +} + +static inline +__m128 +glmm_vdot(__m128 a, __m128 b) { +#if (defined(__SSE4_1__) || defined(__SSE4_2__)) && defined(CGLM_SSE4_DOT) + return _mm_dp_ps(glmm_load(a), glmm_load(b), 0xFF); +#elif defined(__SSE3__) && defined(CGLM_SSE3_DOT) + __m128 x0, x1; + x0 = _mm_mul_ps(glmm_load(a), glmm_load(b)); + x1 = _mm_hadd_ps(x0, x0); + return _mm_hadd_ps(x1, x1); +#else + __m128 x0; + x0 = _mm_mul_ps(a, b); + x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 3, 2)); + return _mm_add_ps(x0, glmm_shuff1(x0, 0, 1, 0, 1)); +#endif +} + +static inline +float +glmm_dot(__m128 a, __m128 b) { + return _mm_cvtss_f32(glmm_vdots(a, b)); +} + +static inline +float +glmm_norm(__m128 a) { + return _mm_cvtss_f32(_mm_sqrt_ss(glmm_vhadds(_mm_mul_ps(a, a)))); +} + +static inline +__m128 +glmm_load3(float v[3]) { + __m128i xy; + __m128 z; + + xy = _mm_loadl_epi64((const __m128i *)v); + z = _mm_load_ss(&v[2]); + + return _mm_movelh_ps(_mm_castsi128_ps(xy), z); +} + +static inline +void +glmm_store3(__m128 vx, float v[3]) { + _mm_storel_pi((__m64 *)&v[0], vx); + _mm_store_ss(&v[2], glmm_shuff1(vx, 2, 2, 2, 2)); +} + +#endif +#endif /* cglm_simd_x86_h */ diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 03dc405..9da0d96 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -200,24 +200,8 @@ glm_vec4_one(vec4 v) { CGLM_INLINE float glm_vec4_dot(vec4 a, vec4 b) { -#if (defined(__SSE4_1__) || defined(__SSE4_2__)) && defined(CGLM_SSE4_DOT) - return _mm_cvtss_f32(_mm_dp_ps(glmm_load(a), glmm_load(b), 0xFF)); -#elif defined(__SSE3__) && defined(CGLM_SSE3_DOT) - __m128 x0, x1; - x0 = _mm_mul_ps(glmm_load(a), glmm_load(b)); - x1 = _mm_hadd_ps(x0, x0); - return _mm_cvtss_f32(_mm_hadd_ps(x1, x1)); -#elif defined(__SSE__) || defined(__SSE2__) - __m128 x0; - x0 = _mm_mul_ps(glmm_load(a), glmm_load(b)); - x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 3, 2)); - return _mm_cvtss_f32(_mm_add_ss(x0, glmm_shuff1(x0, 0, 1, 0, 1))); -#elif defined(CGLM_NEON_FP) - float32x4_t v0, v1, v2; - v0 = vmulq_f32(vld1q_f32(a), vld1q_f32(b)); - v1 = vaddq_f32(v0, vrev64q_f32(v0)); - v2 = vaddq_f32(v1, vcombine_f32(vget_high_f32(v1), vget_low_f32(v1))); - return vgetq_lane_f32(v2, 0); +#if defined(CGLM_SIMD) + return glmm_dot(glmm_load(a), glmm_load(b)); #else return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; #endif @@ -250,10 +234,8 @@ glm_vec4_norm2(vec4 v) { CGLM_INLINE float glm_vec4_norm(vec4 v) { -#if defined( __SSE__ ) || defined( __SSE2__ ) - __m128 x0; - x0 = glmm_load(v); - return _mm_cvtss_f32(_mm_sqrt_ss(glmm_dot(x0, x0))); +#if defined(CGLM_SIMD) + return glmm_norm(glmm_load(v)); #else return sqrtf(glm_vec4_dot(v, v)); #endif @@ -663,7 +645,7 @@ glm_vec4_normalize_to(vec4 v, vec4 dest) { float dot; x0 = glmm_load(v); - xdot = glmm_dot(x0, x0); + xdot = glmm_vdot(x0, x0); dot = _mm_cvtss_f32(xdot); if (dot == 0.0f) { diff --git a/makefile.am b/makefile.am index 2e9336c..63fa285 100644 --- a/makefile.am +++ b/makefile.am @@ -34,30 +34,30 @@ test_tests_CFLAGS = $(checkCFLAGS) cglmdir=$(includedir)/cglm cglm_HEADERS = include/cglm/version.h \ - include/cglm/cglm.h \ - include/cglm/call.h \ - include/cglm/cam.h \ - include/cglm/io.h \ - include/cglm/mat4.h \ - include/cglm/mat3.h \ - include/cglm/types.h \ - include/cglm/common.h \ - include/cglm/affine.h \ - include/cglm/vec3.h \ - include/cglm/vec3-ext.h \ - include/cglm/vec4.h \ - include/cglm/vec4-ext.h \ - include/cglm/euler.h \ - include/cglm/util.h \ - include/cglm/quat.h \ - include/cglm/affine-mat.h \ - include/cglm/plane.h \ - include/cglm/frustum.h \ - include/cglm/box.h \ - include/cglm/color.h \ - include/cglm/project.h \ - include/cglm/sphere.h \ - include/cglm/ease.h + include/cglm/cglm.h \ + include/cglm/call.h \ + include/cglm/cam.h \ + include/cglm/io.h \ + include/cglm/mat4.h \ + include/cglm/mat3.h \ + include/cglm/types.h \ + include/cglm/common.h \ + include/cglm/affine.h \ + include/cglm/vec3.h \ + include/cglm/vec3-ext.h \ + include/cglm/vec4.h \ + include/cglm/vec4-ext.h \ + include/cglm/euler.h \ + include/cglm/util.h \ + include/cglm/quat.h \ + include/cglm/affine-mat.h \ + include/cglm/plane.h \ + include/cglm/frustum.h \ + include/cglm/box.h \ + include/cglm/color.h \ + include/cglm/project.h \ + include/cglm/sphere.h \ + include/cglm/ease.h cglm_calldir=$(includedir)/cglm/call cglm_call_HEADERS = include/cglm/call/mat4.h \ @@ -77,7 +77,9 @@ cglm_call_HEADERS = include/cglm/call/mat4.h \ include/cglm/call/ease.h cglm_simddir=$(includedir)/cglm/simd -cglm_simd_HEADERS = include/cglm/simd/intrin.h +cglm_simd_HEADERS = include/cglm/simd/intrin.h \ + include/cglm/simd/x86.h \ + include/cglm/simd/arm.h cglm_simd_sse2dir=$(includedir)/cglm/simd/sse2 cglm_simd_sse2_HEADERS = include/cglm/simd/sse2/affine.h \ diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj index 5678688..97d9d08 100644 --- a/win/cglm.vcxproj +++ b/win/cglm.vcxproj @@ -69,6 +69,7 @@ + @@ -77,6 +78,7 @@ + diff --git a/win/cglm.vcxproj.filters b/win/cglm.vcxproj.filters index 5e65853..a668242 100644 --- a/win/cglm.vcxproj.filters +++ b/win/cglm.vcxproj.filters @@ -233,5 +233,11 @@ include\cglm + + include\cglm\simd + + + include\cglm\simd + \ No newline at end of file From fc7f958167944c2a568a0748b0ab3c159ec9629d Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 25 Jan 2019 21:56:17 +0300 Subject: [PATCH 229/292] simd: remove re-load in SSE4 and SSE3 --- include/cglm/simd/x86.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/cglm/simd/x86.h b/include/cglm/simd/x86.h index 520a834..99d2b8a 100644 --- a/include/cglm/simd/x86.h +++ b/include/cglm/simd/x86.h @@ -72,10 +72,10 @@ static inline __m128 glmm_vdots(__m128 a, __m128 b) { #if (defined(__SSE4_1__) || defined(__SSE4_2__)) && defined(CGLM_SSE4_DOT) - return _mm_dp_ps(glmm_load(a), glmm_load(b), 0xFF); + return _mm_dp_ps(a, b, 0xFF); #elif defined(__SSE3__) && defined(CGLM_SSE3_DOT) __m128 x0, x1; - x0 = _mm_mul_ps(glmm_load(a), glmm_load(b)); + x0 = _mm_mul_ps(a, b); x1 = _mm_hadd_ps(x0, x0); return _mm_hadd_ps(x1, x1); #else @@ -87,10 +87,10 @@ static inline __m128 glmm_vdot(__m128 a, __m128 b) { #if (defined(__SSE4_1__) || defined(__SSE4_2__)) && defined(CGLM_SSE4_DOT) - return _mm_dp_ps(glmm_load(a), glmm_load(b), 0xFF); + return _mm_dp_ps(a, b, 0xFF); #elif defined(__SSE3__) && defined(CGLM_SSE3_DOT) __m128 x0, x1; - x0 = _mm_mul_ps(glmm_load(a), glmm_load(b)); + x0 = _mm_mul_ps(a, b); x1 = _mm_hadd_ps(x0, x0); return _mm_hadd_ps(x1, x1); #else From 59b9e54879c30f380c15d9799b6976bb72fadfb6 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 26 Jan 2019 15:54:10 +0300 Subject: [PATCH 230/292] vec4: helper to fill vec4 as [S^3, S^2, S, 1] --- include/cglm/call/vec4.h | 4 ++++ include/cglm/vec4.h | 19 +++++++++++++++++++ src/vec4.c | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index 9a72510..936bb52 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -153,6 +153,10 @@ CGLM_EXPORT void glmc_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest); +CGLM_EXPORT +void +glmc_vec4_cubic(float s, vec4 dest); + /* ext */ CGLM_EXPORT diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 9da0d96..1d68841 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -800,4 +800,23 @@ glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) { glm_vec4_add(from, v, dest); } +/*! + * @brief helper to fill vec4 as [S^3, S^2, S, 1] + * + * @param[in] s parameter + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_cubic(float s, vec4 dest) { + float ss; + + ss = s * s; + + dest[0] = s; + dest[1] = ss; + dest[2] = ss * s; + dest[3] = 1.0f; +} + #endif /* cglm_vec4_h */ diff --git a/src/vec4.c b/src/vec4.c index 1a49710..0bb6a6e 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -206,6 +206,12 @@ glmc_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) { glm_vec4_lerp(from, to, t, dest); } +CGLM_EXPORT +void +glmc_vec4_cubic(float s, vec4 dest) { + glm_vec4_cubic(s, dest); +} + /* ext */ CGLM_EXPORT From 807d5589b4b6c8a775fda77a9e4159ed55f39d06 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 26 Jan 2019 16:05:11 +0300 Subject: [PATCH 231/292] call: add missing end guard to call headers --- include/cglm/call/ease.h | 3 +++ include/cglm/call/sphere.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/cglm/call/ease.h b/include/cglm/call/ease.h index 9f1757e..87e39ca 100644 --- a/include/cglm/call/ease.h +++ b/include/cglm/call/ease.h @@ -137,4 +137,7 @@ CGLM_EXPORT float glmc_ease_bounce_inout(float t); +#ifdef __cplusplus +} +#endif #endif /* cglmc_ease_h */ diff --git a/include/cglm/call/sphere.h b/include/cglm/call/sphere.h index 02c3d55..9b96546 100644 --- a/include/cglm/call/sphere.h +++ b/include/cglm/call/sphere.h @@ -33,4 +33,7 @@ CGLM_EXPORT bool glmc_sphere_point(vec4 s, vec3 point); +#ifdef __cplusplus +} +#endif #endif /* cglmc_sphere_h */ From 32ddf49756461300fce6ee6e24be34a968066c7b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 26 Jan 2019 18:05:05 +0300 Subject: [PATCH 232/292] mat4: helper for row * matrix * column --- docs/source/mat4.rst | 18 ++++++++++++++++++ docs/source/vec4.rst | 14 +++++++++----- include/cglm/call/mat4.h | 4 ++++ include/cglm/mat4.h | 22 ++++++++++++++++++++++ src/mat4.c | 6 ++++++ 5 files changed, 59 insertions(+), 5 deletions(-) diff --git a/docs/source/mat4.rst b/docs/source/mat4.rst index 30f48fe..294f8f4 100644 --- a/docs/source/mat4.rst +++ b/docs/source/mat4.rst @@ -45,6 +45,7 @@ Functions: #. :c:func:`glm_mat4_inv_fast` #. :c:func:`glm_mat4_swap_col` #. :c:func:`glm_mat4_swap_row` +#. :c:func:`glm_mat4_rmc` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -270,3 +271,20 @@ Functions documentation | *[in, out]* **mat** matrix | *[in]* **row1** row1 | *[in]* **row2** row2 + +.. c:function:: float glm_mat4_rmc(vec4 r, mat4 m, vec4 c) + + | **rmc** stands for **Row** * **Matrix** * **Column** + + | helper for R (row vector) * M (matrix) * C (column vector) + + | the result is scalar because S * M = Matrix1x4 (row vector), + | then Matrix1x4 * Vec4 (column vector) = Matrix1x1 (Scalar) + + Parameters: + | *[in]* **r** row vector or matrix1x4 + | *[in]* **m** matrix4x4 + | *[in]* **c** column vector or matrix4x1 + + Returns: + scalar value e.g. Matrix1x1 diff --git a/docs/source/vec4.rst b/docs/source/vec4.rst index 5bb1ac7..f497868 100644 --- a/docs/source/vec4.rst +++ b/docs/source/vec4.rst @@ -58,11 +58,7 @@ Functions: #. :c:func:`glm_vec4_minv` #. :c:func:`glm_vec4_clamp` #. :c:func:`glm_vec4_lerp` -#. :c:func:`glm_vec4_isnan` -#. :c:func:`glm_vec4_isinf` -#. :c:func:`glm_vec4_isvalid` -#. :c:func:`glm_vec4_sign` -#. :c:func:`glm_vec4_sqrt` +#. :c:func:`glm_vec4_cubic` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -401,3 +397,11 @@ Functions documentation | *[in]* **to** to value | *[in]* **t** interpolant (amount) clamped between 0 and 1 | *[out]* **dest** destination + +.. c:function:: void glm_vec4_cubic(float s, vec4 dest) + + helper to fill vec4 as [S^3, S^2, S, 1] + + Parameters: + | *[in]* **s** parameter + | *[out]* **dest** destination diff --git a/include/cglm/call/mat4.h b/include/cglm/call/mat4.h index 7e76f73..54fbcbe 100644 --- a/include/cglm/call/mat4.h +++ b/include/cglm/call/mat4.h @@ -113,6 +113,10 @@ CGLM_EXPORT void glmc_mat4_swap_row(mat4 mat, int row1, int row2); +CGLM_EXPORT +float +glmc_mat4_rmc(vec4 r, mat4 m, vec4 c); + #ifdef __cplusplus } #endif diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 56c6de3..35d4117 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -677,4 +677,26 @@ glm_mat4_swap_row(mat4 mat, int row1, int row2) { mat[3][row2] = tmp[3]; } +/*! + * @brief helper for R (row vector) * M (matrix) * C (column vector) + * + * rmc stands for Row * Matrix * Column + * + * the result is scalar because S * M = Matrix1x4 (row vector), + * then Matrix1x4 * Vec4 (column vector) = Matrix1x1 (Scalar) + * + * @param[in] r row vector or matrix1x4 + * @param[in] m matrix4x4 + * @param[in] c column vector or matrix4x1 + * + * @return scalar value e.g. B(s) + */ +CGLM_INLINE +float +glm_mat4_rmc(vec4 r, mat4 m, vec4 c) { + vec4 tmp; + glm_mat4_mulv(m, r, tmp); + return glm_vec4_dot(c, tmp); +} + #endif /* cglm_mat_h */ diff --git a/src/mat4.c b/src/mat4.c index b62420e..c648a6e 100644 --- a/src/mat4.c +++ b/src/mat4.c @@ -151,3 +151,9 @@ void glmc_mat4_swap_row(mat4 mat, int row1, int row2) { glm_mat4_swap_row(mat, row1, row2); } + +CGLM_EXPORT +float +glmc_mat4_rmc(vec4 r, mat4 m, vec4 c) { + return glm_mat4_rmc(r, m, c); +} From 60cb4beb0a7adc8073f559c6ff16df618604a074 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 26 Jan 2019 18:06:26 +0300 Subject: [PATCH 233/292] curve: helper for calculate result of SMC multiplication --- docs/source/api.rst | 1 + docs/source/curve.rst | 41 +++++++++++++++++++++++++++++++++++++++ include/cglm/call.h | 1 + include/cglm/call/curve.h | 23 ++++++++++++++++++++++ include/cglm/cglm.h | 1 + include/cglm/curve.h | 40 ++++++++++++++++++++++++++++++++++++++ makefile.am | 9 ++++++--- src/curve.c | 15 ++++++++++++++ win/cglm.vcxproj | 3 +++ win/cglm.vcxproj.filters | 9 +++++++++ 10 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 docs/source/curve.rst create mode 100644 include/cglm/call/curve.h create mode 100644 include/cglm/curve.h create mode 100644 src/curve.c diff --git a/docs/source/api.rst b/docs/source/api.rst index e88b426..c7f74a5 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -46,3 +46,4 @@ Follow the :doc:`build` documentation for this io call sphere + curve diff --git a/docs/source/curve.rst b/docs/source/curve.rst new file mode 100644 index 0000000..26c9b75 --- /dev/null +++ b/docs/source/curve.rst @@ -0,0 +1,41 @@ +.. default-domain:: C + +Curve +================================================================================ + +Header: cglm/curve.h + +Common helpers for common curves. For specific curve see its header/doc +e.g bezier + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_smc` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: float glm_smc(float s, mat4 m, vec4 c) + + | helper function to calculate **S** * **M** * **C** multiplication for curves + + | this function does not encourage you to use SMC, instead it is a helper if you use SMC. + + | if you want to specify S as vector then use more generic glm_mat4_rmc() func. + + | Example usage: + + .. code-block:: c + + Bs = glm_smc(s, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}) + + Parameters: + | *[in]* **s** parameter between 0 and 1 (this will be [s3, s2, s, 1]) + | *[in]* **m** basis matrix + | *[out]* **c** position/control vector + + Returns: + scalar value e.g. Bs diff --git a/include/cglm/call.h b/include/cglm/call.h index b7fa6e1..7c1c8d7 100644 --- a/include/cglm/call.h +++ b/include/cglm/call.h @@ -27,6 +27,7 @@ extern "C" { #include "call/project.h" #include "call/sphere.h" #include "call/ease.h" +#include "call/curve.h" #ifdef __cplusplus } diff --git a/include/cglm/call/curve.h b/include/cglm/call/curve.h new file mode 100644 index 0000000..061fdb9 --- /dev/null +++ b/include/cglm/call/curve.h @@ -0,0 +1,23 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_curve_h +#define cglmc_curve_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +float +glmc_smc(float s, mat4 m, vec4 c); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_curve_h */ diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index 8b37162..d79a88e 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -26,5 +26,6 @@ #include "project.h" #include "sphere.h" #include "ease.h" +#include "curve.h" #endif /* cglm_h */ diff --git a/include/cglm/curve.h b/include/cglm/curve.h new file mode 100644 index 0000000..5033be5 --- /dev/null +++ b/include/cglm/curve.h @@ -0,0 +1,40 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_curve_h +#define cglm_curve_h + +#include "common.h" +#include "vec4.h" +#include "mat4.h" + +/*! + * @brief helper function to calculate S*M*C multiplication for curves + * + * This function does not encourage you to use SMC, + * instead it is a helper if you use SMC. + * + * if you want to specify S as vector then use more generic glm_mat4_rmc() func. + * + * Example usage: + * B(s) = glm_smc(s, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}) + * + * @param[in] s parameter between 0 and 1 (this will be [s3, s2, s, 1]) + * @param[in] m basis matrix + * @param[in] c position/control vector + * + * @return B(s) + */ +CGLM_INLINE +float +glm_smc(float s, mat4 m, vec4 c) { + vec4 vs; + glm_vec4_cubic(s, vs); + return glm_mat4_rmc(vs, m, c); +} + +#endif /* cglm_curve_h */ diff --git a/makefile.am b/makefile.am index 63fa285..d6498c6 100644 --- a/makefile.am +++ b/makefile.am @@ -57,7 +57,8 @@ cglm_HEADERS = include/cglm/version.h \ include/cglm/color.h \ include/cglm/project.h \ include/cglm/sphere.h \ - include/cglm/ease.h + include/cglm/ease.h \ + include/cglm/curve.h cglm_calldir=$(includedir)/cglm/call cglm_call_HEADERS = include/cglm/call/mat4.h \ @@ -74,7 +75,8 @@ cglm_call_HEADERS = include/cglm/call/mat4.h \ include/cglm/call/box.h \ include/cglm/call/project.h \ include/cglm/call/sphere.h \ - include/cglm/call/ease.h + include/cglm/call/ease.h \ + include/cglm/call/curve.h cglm_simddir=$(includedir)/cglm/simd cglm_simd_HEADERS = include/cglm/simd/intrin.h \ @@ -109,7 +111,8 @@ libcglm_la_SOURCES=\ src/box.c \ src/project.c \ src/sphere.c \ - src/ease.c + src/ease.c \ + src/curve.c test_tests_SOURCES=\ test/src/test_common.c \ diff --git a/src/curve.c b/src/curve.c new file mode 100644 index 0000000..74d4702 --- /dev/null +++ b/src/curve.c @@ -0,0 +1,15 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +float +glmc_smc(float s, mat4 m, vec4 c) { + return glm_smc(s, m, c); +} diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj index 97d9d08..82293f0 100644 --- a/win/cglm.vcxproj +++ b/win/cglm.vcxproj @@ -22,6 +22,7 @@ + @@ -44,6 +45,7 @@ + @@ -60,6 +62,7 @@ + diff --git a/win/cglm.vcxproj.filters b/win/cglm.vcxproj.filters index a668242..7f9735b 100644 --- a/win/cglm.vcxproj.filters +++ b/win/cglm.vcxproj.filters @@ -84,6 +84,9 @@ src + + src + @@ -239,5 +242,11 @@ include\cglm\simd + + include\cglm\call + + + include\cglm + \ No newline at end of file From 11a6e4471e6ffc4868c6cc1ac712671698ba54db Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 28 Jan 2019 14:26:02 +0300 Subject: [PATCH 234/292] fix vec4_cubic function --- include/cglm/vec4.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 1d68841..bbd1c31 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -813,9 +813,9 @@ glm_vec4_cubic(float s, vec4 dest) { ss = s * s; - dest[0] = s; + dest[0] = ss * s; dest[1] = ss; - dest[2] = ss * s; + dest[2] = s; dest[3] = 1.0f; } From b0e48a56ca4380c80d30f2faf0a896b7a9306554 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 28 Jan 2019 15:31:03 +0300 Subject: [PATCH 235/292] test: rename test_rand_angle() to test_rand() --- test/src/test_common.c | 2 +- test/src/test_common.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/src/test_common.c b/test/src/test_common.c index 405000d..d41d3cb 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -58,7 +58,7 @@ test_rand_vec4(vec4 dest) { } float -test_rand_angle(void) { +test_rand(void) { srand((unsigned int)time(NULL)); return drand48(); } diff --git a/test/src/test_common.h b/test/src/test_common.h index 7881e7a..8a16b0f 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -59,7 +59,7 @@ void test_rand_vec4(vec4 dest) ; float -test_rand_angle(void); +test_rand(void); void test_rand_quat(versor q); From 730cb1e9f782e0d9fc4ebece06be20f6ecf976e2 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 28 Jan 2019 15:32:24 +0300 Subject: [PATCH 236/292] add bezier helpers --- include/cglm/bezier.h | 56 ++++++++++++++++++++++++++++++++++++++ include/cglm/call/bezier.h | 23 ++++++++++++++++ include/cglm/cglm.h | 1 + src/bezier.c | 15 ++++++++++ test/src/test_bezier.c | 41 ++++++++++++++++++++++++++++ test/src/test_main.c | 5 +++- test/src/test_tests.h | 3 ++ 7 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 include/cglm/bezier.h create mode 100644 include/cglm/call/bezier.h create mode 100644 src/bezier.c create mode 100644 test/src/test_bezier.c diff --git a/include/cglm/bezier.h b/include/cglm/bezier.h new file mode 100644 index 0000000..f36ac1d --- /dev/null +++ b/include/cglm/bezier.h @@ -0,0 +1,56 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_bezier_h +#define cglm_bezier_h + +#define GLM_BEZIER_MAT_INIT {{-1.0f, 3.0f, -3.0f, 1.0f}, \ + { 3.0f, -6.0f, 3.0f, 0.0f}, \ + {-3.0f, 3.0f, 0.0f, 0.0f}, \ + { 1.0f, 0.0f, 0.0f, 0.0f}} + +/* for C only */ +#define GLM_BEZIER_MAT ((mat4)GLM_BEZIER_MAT_INIT) + +#define CGLM_DECASTEL_EPS 1e-9 +#define CGLM_DECASTEL_MAX 1000 +#define CGLM_DECASTEL_SMALL 1e-20 + +/*! + * @brief cubic bezier interpolation + * + * Formula: + * B(s) = P0*(1-s)^3 + 3*C0*s*(1-s)^2 + 3*C1*s^2*(1-s) + P1*s^3 + * + * similar result using matrix: + * B(s) = glm_smc(t, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}) + * + * glm_eq(glm_smc(...), glm_bezier(...)) should return TRUE + * + * @param[in] s parameter between 0 and 1 + * @param[in] p0 begin point + * @param[in] c0 control point 1 + * @param[in] c1 control point 2 + * @param[in] p1 end point + * + * @return B(s) + */ +CGLM_INLINE +float +glm_bezier(float s, float p0, float c0, float c1, float p1) { + float x, xx, ss, xs3, a; + + x = 1.0f - s; + xx = x * x; + ss = s * s; + xs3 = (s - ss) * 3.0f; + a = p0 * xx + c0 * xs3; + + return a + s * (c1 * xs3 + p1 * ss - a); +} + +#endif /* cglm_bezier_h */ diff --git a/include/cglm/call/bezier.h b/include/cglm/call/bezier.h new file mode 100644 index 0000000..531c15d --- /dev/null +++ b/include/cglm/call/bezier.h @@ -0,0 +1,23 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_curve_h +#define cglmc_curve_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +float +glmc_bezier(float s, float p0, float c0, float c1, float p1); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_curve_h */ diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index d79a88e..7c301bf 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -27,5 +27,6 @@ #include "sphere.h" #include "ease.h" #include "curve.h" +#include "bezier.h" #endif /* cglm_h */ diff --git a/src/bezier.c b/src/bezier.c new file mode 100644 index 0000000..244e580 --- /dev/null +++ b/src/bezier.c @@ -0,0 +1,15 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +float +glmc_bezier(float s, float p0, float c0, float c1, float p1) { + return glm_bezier(s, p0, c0, c1, p1); +} diff --git a/test/src/test_bezier.c b/test/src/test_bezier.c new file mode 100644 index 0000000..32d8c35 --- /dev/null +++ b/test/src/test_bezier.c @@ -0,0 +1,41 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +CGLM_INLINE +float +test_bezier_plain(float s, float p0, float c0, float c1, float p1) { + float x, xx, xxx, ss, sss; + + x = 1.0f - s; + xx = x * x; + xxx = xx * x; + ss = s * s; + sss = ss * s; + + return p0 * xxx + 3.0f * (c0 * s * xx + c1 * ss * x) + p1 * sss; +} + +void +test_bezier(void **state) { + float s, p0, p1, c0, c1, smc, Bs, Bs_plain; + + s = test_rand(); + p0 = test_rand(); + p1 = test_rand(); + c0 = test_rand(); + c1 = test_rand(); + + smc = glm_smc(s, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}); + Bs = glm_bezier(s, p0, c0, c1, p1); + Bs_plain = test_bezier_plain(s, p0, c0, c1, p1); + + assert_true(glm_eq(Bs, Bs_plain)); + assert_true(glm_eq(smc, Bs_plain)); + assert_true(glm_eq(Bs, smc)); +} diff --git a/test/src/test_main.c b/test/src/test_main.c index ff77b02..8ce1673 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -38,7 +38,10 @@ main(int argc, const char * argv[]) { cmocka_unit_test(test_vec3), /* affine */ - cmocka_unit_test(test_affine) + cmocka_unit_test(test_affine), + + /* bezier */ + cmocka_unit_test(test_bezier) }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/test/src/test_tests.h b/test/src/test_tests.h index 7b9cf0a..618cc9f 100644 --- a/test/src/test_tests.h +++ b/test/src/test_tests.h @@ -40,4 +40,7 @@ test_vec3(void **state); void test_affine(void **state); +void +test_bezier(void **state); + #endif /* test_tests_h */ From c22231f29621ad13e2638450cfe1bce56c4bca99 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 28 Jan 2019 15:52:42 +0300 Subject: [PATCH 237/292] curve: de casteljau implementation for solving cubic bezier --- CREDITS | 6 ++++ include/cglm/bezier.h | 73 ++++++++++++++++++++++++++++++++++++++ include/cglm/call.h | 1 + include/cglm/call/bezier.h | 14 ++++++-- src/bezier.c | 12 +++++++ 5 files changed, 103 insertions(+), 3 deletions(-) diff --git a/CREDITS b/CREDITS index 263dd2d..7272ddc 100644 --- a/CREDITS +++ b/CREDITS @@ -55,3 +55,9 @@ https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c 10. Horizontal add https://stackoverflow.com/questions/6996764/fastest-way-to-do-horizontal-float-vector-sum-on-x86 + +11. de casteljau implementation and comments +https://forums.khronos.org/showthread.php/10264-Animations-in-1-4-1-release-notes-revision-A/page2?highlight=bezier +https://forums.khronos.org/showthread.php/10644-Animation-Bezier-interpolation +https://forums.khronos.org/showthread.php/10387-2D-Tangents-in-Bezier-Splines?p=34164&viewfull=1#post34164 +https://forums.khronos.org/showthread.php/10651-Animation-TCB-Spline-Interpolation-in-COLLADA?highlight=bezier diff --git a/include/cglm/bezier.h b/include/cglm/bezier.h index f36ac1d..594da86 100644 --- a/include/cglm/bezier.h +++ b/include/cglm/bezier.h @@ -53,4 +53,77 @@ glm_bezier(float s, float p0, float c0, float c1, float p1) { return a + s * (c1 * xs3 + p1 * ss - a); } +/*! + * @brief iterative way to solve cubic equation + * + * @param[in] s parameter between 0 and 1 + * @param[in] p0 begin point + * @param[in] c0 control point 1 + * @param[in] c1 control point 2 + * @param[in] p1 end point + * + * @return parameter to use in cubic equation + */ +CGLM_INLINE +float +glm_decasteljau(float prm, float p0, float c0, float c1, float p1) { + float u, v, a, b, c, d, e, f; + int i; + + if (prm - p0 < CGLM_DECASTEL_SMALL) + return 0.0f; + + if (p1 - prm < CGLM_DECASTEL_SMALL) + return 1.0f; + + u = 0.0f; + v = 1.0f; + + for (i = 0; i < CGLM_DECASTEL_MAX; i++) { + /* de Casteljau Subdivision */ + a = (p0 + c0) * 0.5f; + b = (c0 + c1) * 0.5f; + c = (c1 + p1) * 0.5f; + d = (a + b) * 0.5f; + e = (b + c) * 0.5f; + f = (d + e) * 0.5f; /* this one is on the curve! */ + + /* The curve point is close enough to our wanted t */ + if (fabsf(f - prm) < CGLM_DECASTEL_EPS) + return glm_clamp_zo((u + v) * 0.5f); + + /* dichotomy */ + if (f < prm) { + p0 = f; + c0 = e; + c1 = c; + u = (u + v) * 0.5f; + } else { + c0 = a; + c1 = d; + p1 = f; + v = (u + v) * 0.5f; + } + } + + return glm_clamp_zo((u + v) * 0.5f); +} + +/*! + * @brief solve cubic bezier equation + * + * @param[in] s parameter between 0 and 1 + * @param[in] p0 begin point + * @param[in] c0 control point 1 + * @param[in] c1 control point 2 + * @param[in] p1 end point + * + * @return parameter to use in cubic equation + */ +CGLM_INLINE +float +glm_bezier_solve(float prm, float p0, float c0, float c1, float p1) { + return glm_decasteljau(prm, p0, c0, c1, p1); +} + #endif /* cglm_bezier_h */ diff --git a/include/cglm/call.h b/include/cglm/call.h index 7c1c8d7..7cbd501 100644 --- a/include/cglm/call.h +++ b/include/cglm/call.h @@ -28,6 +28,7 @@ extern "C" { #include "call/sphere.h" #include "call/ease.h" #include "call/curve.h" +#include "call/bezier.h" #ifdef __cplusplus } diff --git a/include/cglm/call/bezier.h b/include/cglm/call/bezier.h index 531c15d..c90a178 100644 --- a/include/cglm/call/bezier.h +++ b/include/cglm/call/bezier.h @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#ifndef cglmc_curve_h -#define cglmc_curve_h +#ifndef cglmc_bezier_h +#define cglmc_bezier_h #ifdef __cplusplus extern "C" { #endif @@ -17,7 +17,15 @@ CGLM_EXPORT float glmc_bezier(float s, float p0, float c0, float c1, float p1); +CGLM_EXPORT +float +glmc_decasteljau(float prm, float p0, float c0, float c1, float p1); + +CGLM_EXPORT +float +glmc_bezier_solve(float prm, float p0, float c0, float c1, float p1); + #ifdef __cplusplus } #endif -#endif /* cglmc_curve_h */ +#endif /* cglmc_bezier_h */ diff --git a/src/bezier.c b/src/bezier.c index 244e580..36d2776 100644 --- a/src/bezier.c +++ b/src/bezier.c @@ -13,3 +13,15 @@ float glmc_bezier(float s, float p0, float c0, float c1, float p1) { return glm_bezier(s, p0, c0, c1, p1); } + +CGLM_EXPORT +float +glmc_decasteljau(float prm, float p0, float c0, float c1, float p1) { + return glm_decasteljau(prm, p0, c0, c1, p1); +} + +CGLM_EXPORT +float +glmc_bezier_solve(float prm, float p0, float c0, float c1, float p1) { + return glm_bezier_solve(prm, p0, c0, c1, p1); +} From a4e2c39c1d6e6021e9aad7e8085ee30ed78c29d4 Mon Sep 17 00:00:00 2001 From: CC Date: Tue, 29 Jan 2019 16:54:02 +0800 Subject: [PATCH 238/292] Update cglm.podspec update pod version --- cglm.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cglm.podspec b/cglm.podspec index 00d1df9..f49c294 100644 --- a/cglm.podspec +++ b/cglm.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| # Description s.name = "cglm" - s.version = "0.4.6" + s.version = "0.5.1" s.summary = "📽 Optimized OpenGL/Graphics Math (glm) for C" s.description = <<-DESC cglm is math library for graphics programming for C. It is similar to original glm but it is written for C instead of C++ (you can use here too). See the documentation or README for all features. From 1e121a485511ddf6e5d249f34d880d3dbb658005 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 29 Jan 2019 22:11:04 +0300 Subject: [PATCH 239/292] mat4: fix rmc multiplication --- include/cglm/mat4.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 35d4117..74e876a 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -695,8 +695,8 @@ CGLM_INLINE float glm_mat4_rmc(vec4 r, mat4 m, vec4 c) { vec4 tmp; - glm_mat4_mulv(m, r, tmp); - return glm_vec4_dot(c, tmp); + glm_mat4_mulv(m, c, tmp); + return glm_vec4_dot(r, tmp); } #endif /* cglm_mat_h */ From 7848dda1dd9c577a1d107fba34ffcfea03ada05a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 29 Jan 2019 22:17:44 +0300 Subject: [PATCH 240/292] curve: cubic hermite intrpolation --- include/cglm/bezier.h | 56 ++++++++++++++++++++++++++++++++------ include/cglm/call/bezier.h | 4 +++ makefile.am | 12 +++++--- src/bezier.c | 6 ++++ test/src/test_bezier.c | 24 ++++++++++++++++ win/cglm.vcxproj | 3 ++ win/cglm.vcxproj.filters | 9 ++++++ 7 files changed, 102 insertions(+), 12 deletions(-) diff --git a/include/cglm/bezier.h b/include/cglm/bezier.h index 594da86..8b1ee6e 100644 --- a/include/cglm/bezier.h +++ b/include/cglm/bezier.h @@ -8,13 +8,17 @@ #ifndef cglm_bezier_h #define cglm_bezier_h -#define GLM_BEZIER_MAT_INIT {{-1.0f, 3.0f, -3.0f, 1.0f}, \ - { 3.0f, -6.0f, 3.0f, 0.0f}, \ - {-3.0f, 3.0f, 0.0f, 0.0f}, \ - { 1.0f, 0.0f, 0.0f, 0.0f}} - +#define GLM_BEZIER_MAT_INIT {{-1.0f, 3.0f, -3.0f, 1.0f}, \ + { 3.0f, -6.0f, 3.0f, 0.0f}, \ + {-3.0f, 3.0f, 0.0f, 0.0f}, \ + { 1.0f, 0.0f, 0.0f, 0.0f}} +#define GLM_HERMITE_MAT_INIT {{ 2.0f, -3.0f, 0.0f, 1.0f}, \ + {-2.0f, 3.0f, 0.0f, 0.0f}, \ + { 1.0f, -2.0f, 1.0f, 0.0f}, \ + { 1.0f, -1.0f, 0.0f, 0.0f}} /* for C only */ -#define GLM_BEZIER_MAT ((mat4)GLM_BEZIER_MAT_INIT) +#define GLM_BEZIER_MAT ((mat4)GLM_BEZIER_MAT_INIT) +#define GLM_HERMITE_MAT ((mat4)GLM_HERMITE_MAT_INIT) #define CGLM_DECASTEL_EPS 1e-9 #define CGLM_DECASTEL_MAX 1000 @@ -54,10 +58,46 @@ glm_bezier(float s, float p0, float c0, float c1, float p1) { } /*! - * @brief iterative way to solve cubic equation + * @brief cubic hermite interpolation + * + * Formula: + * H(s) = P0*(2*s^3 - 3*s^2 + 1) + T0*(s^3 - 2*s^2 + s) + * + P1*(-2*s^3 + 3*s^2) + T1*(s^3 - s^2) + * + * similar result using matrix: + * H(s) = glm_smc(t, GLM_HERMITE_MAT, (vec4){p0, p1, c0, c1}) + * + * glm_eq(glm_smc(...), glm_hermite(...)) should return TRUE * * @param[in] s parameter between 0 and 1 * @param[in] p0 begin point + * @param[in] t0 tangent 1 + * @param[in] t1 tangent 2 + * @param[in] p1 end point + * + * @return B(s) + */ +CGLM_INLINE +float +glm_hermite(float s, float p0, float t0, float t1, float p1) { + float ss, d, a, b, c, e, f; + + ss = s * s; + a = ss + ss; + c = a + ss; + b = a * s; + d = s * ss; + f = d - ss; + e = b - c; + + return p0 * (e + 1.0f) + t0 * (f - ss + s) + t1 * f - p1 * e; +} + +/*! + * @brief iterative way to solve cubic equation + * + * @param[in] prm parameter between 0 and 1 + * @param[in] p0 begin point * @param[in] c0 control point 1 * @param[in] c1 control point 2 * @param[in] p1 end point @@ -112,7 +152,7 @@ glm_decasteljau(float prm, float p0, float c0, float c1, float p1) { /*! * @brief solve cubic bezier equation * - * @param[in] s parameter between 0 and 1 + * @param[in] prm parameter between 0 and 1 * @param[in] p0 begin point * @param[in] c0 control point 1 * @param[in] c1 control point 2 diff --git a/include/cglm/call/bezier.h b/include/cglm/call/bezier.h index c90a178..b37f349 100644 --- a/include/cglm/call/bezier.h +++ b/include/cglm/call/bezier.h @@ -17,6 +17,10 @@ CGLM_EXPORT float glmc_bezier(float s, float p0, float c0, float c1, float p1); +CGLM_EXPORT +float +glmc_hermite(float s, float p0, float t0, float t1, float p1); + CGLM_EXPORT float glmc_decasteljau(float prm, float p0, float c0, float c1, float p1); diff --git a/makefile.am b/makefile.am index d6498c6..d6cdc70 100644 --- a/makefile.am +++ b/makefile.am @@ -58,7 +58,8 @@ cglm_HEADERS = include/cglm/version.h \ include/cglm/project.h \ include/cglm/sphere.h \ include/cglm/ease.h \ - include/cglm/curve.h + include/cglm/curve.h \ + include/cglm/bezier.h cglm_calldir=$(includedir)/cglm/call cglm_call_HEADERS = include/cglm/call/mat4.h \ @@ -76,7 +77,8 @@ cglm_call_HEADERS = include/cglm/call/mat4.h \ include/cglm/call/project.h \ include/cglm/call/sphere.h \ include/cglm/call/ease.h \ - include/cglm/call/curve.h + include/cglm/call/curve.h \ + include/cglm/call/bezier.h cglm_simddir=$(includedir)/cglm/simd cglm_simd_HEADERS = include/cglm/simd/intrin.h \ @@ -112,7 +114,8 @@ libcglm_la_SOURCES=\ src/project.c \ src/sphere.c \ src/ease.c \ - src/curve.c + src/curve.c \ + src/bezier.c test_tests_SOURCES=\ test/src/test_common.c \ @@ -126,7 +129,8 @@ test_tests_SOURCES=\ test/src/test_vec4.c \ test/src/test_vec3.c \ test/src/test_mat3.c \ - test/src/test_affine.c + test/src/test_affine.c \ + test/src/test_bezier.c all-local: sh ./post-build.sh diff --git a/src/bezier.c b/src/bezier.c index 36d2776..0bb16fe 100644 --- a/src/bezier.c +++ b/src/bezier.c @@ -14,6 +14,12 @@ glmc_bezier(float s, float p0, float c0, float c1, float p1) { return glm_bezier(s, p0, c0, c1, p1); } +CGLM_EXPORT +float +glmc_hermite(float s, float p0, float t0, float t1, float p1) { + return glm_hermite(s, p0, t0, t1, p1); +} + CGLM_EXPORT float glmc_decasteljau(float prm, float p0, float c0, float c1, float p1) { diff --git a/test/src/test_bezier.c b/test/src/test_bezier.c index 32d8c35..bd7c796 100644 --- a/test/src/test_bezier.c +++ b/test/src/test_bezier.c @@ -21,6 +21,20 @@ test_bezier_plain(float s, float p0, float c0, float c1, float p1) { return p0 * xxx + 3.0f * (c0 * s * xx + c1 * ss * x) + p1 * sss; } +CGLM_INLINE +float +test_hermite_plain(float s, float p0, float t0, float t1, float p1) { + float ss, sss; + + ss = s * s; + sss = ss * s; + + return p0 * (2.0f * sss - 3.0f * ss + 1.0f) + + t0 * (sss - 2.0f * ss + s) + + p1 * (-2.0f * sss + 3.0f * ss) + + t1 * (sss - ss); +} + void test_bezier(void **state) { float s, p0, p1, c0, c1, smc, Bs, Bs_plain; @@ -31,6 +45,7 @@ test_bezier(void **state) { c0 = test_rand(); c1 = test_rand(); + /* test cubic bezier */ smc = glm_smc(s, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}); Bs = glm_bezier(s, p0, c0, c1, p1); Bs_plain = test_bezier_plain(s, p0, c0, c1, p1); @@ -38,4 +53,13 @@ test_bezier(void **state) { assert_true(glm_eq(Bs, Bs_plain)); assert_true(glm_eq(smc, Bs_plain)); assert_true(glm_eq(Bs, smc)); + + /* test cubic hermite */ + smc = glm_smc(s, GLM_HERMITE_MAT, (vec4){p0, p1, c0, c1}); + Bs = glm_hermite(s, p0, c0, c1, p1); + Bs_plain = test_hermite_plain(s, p0, c0, c1, p1); + + assert_true(glm_eq(Bs, Bs_plain)); + assert_true(glm_eq(smc, Bs_plain)); + assert_true(glm_eq(Bs, smc)); } diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj index 82293f0..90e58a6 100644 --- a/win/cglm.vcxproj +++ b/win/cglm.vcxproj @@ -20,6 +20,7 @@ + @@ -40,9 +41,11 @@ + + diff --git a/win/cglm.vcxproj.filters b/win/cglm.vcxproj.filters index 7f9735b..dd66ee1 100644 --- a/win/cglm.vcxproj.filters +++ b/win/cglm.vcxproj.filters @@ -87,6 +87,9 @@ src + + src + @@ -248,5 +251,11 @@ include\cglm + + include\cglm + + + include\cglm\call + \ No newline at end of file From 4e5879497e28e8932ff527985436fcd5950aca59 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 2 Feb 2019 15:29:48 +0300 Subject: [PATCH 241/292] update docs --- README.md | 4 ++ docs/source/api.rst | 1 + docs/source/bezier.rst | 89 ++++++++++++++++++++++++++++++++++++++++++ include/cglm/bezier.h | 2 +- 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 docs/source/bezier.rst diff --git a/README.md b/README.md index dffa54c..d03a03f 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,11 @@ Currently *cglm* uses default clip space configuration (-1, 1) for camera functi - inline or pre-compiled function call - frustum (extract view frustum planes, corners...) - bounding box (AABB in Frustum (culling), crop, merge...) +- bounding sphere - project, unproject +- easing functions +- curves +- curve interpolation helpers (S*M*C, deCasteljau...) - and other...
diff --git a/docs/source/api.rst b/docs/source/api.rst index c7f74a5..408eae7 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -47,3 +47,4 @@ Follow the :doc:`build` documentation for this call sphere curve + bezier diff --git a/docs/source/bezier.rst b/docs/source/bezier.rst new file mode 100644 index 0000000..8b29751 --- /dev/null +++ b/docs/source/bezier.rst @@ -0,0 +1,89 @@ +.. default-domain:: C + +Bezier +================================================================================ + +Header: cglm/bezier.h + +Common helpers for cubic bezier and similar curves. + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_bezier` +2. :c:func:`glm_hermite` +3. :c:func:`glm_decasteljau` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: float glm_bezier(float s, float p0, float c0, float c1, float p1) + + | cubic bezier interpolation + | formula: + + .. code-block:: text + + B(s) = P0*(1-s)^3 + 3*C0*s*(1-s)^2 + 3*C1*s^2*(1-s) + P1*s^3 + + | similar result using matrix: + + .. code-block:: text + + B(s) = glm_smc(t, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}) + + | glm_eq(glm_smc(...), glm_bezier(...)) should return TRUE + + Parameters: + | *[in]* **s** parameter between 0 and 1 + | *[in]* **p0** begin point + | *[in]* **c0** control point 1 + | *[in]* **c1** control point 2 + | *[in]* **p1** end point + + Returns: + B(s) + +.. c:function:: float glm_hermite(float s, float p0, float t0, float t1, float p1) + + | cubic hermite interpolation + | formula: + + .. code-block:: text + + H(s) = P0*(2*s^3 - 3*s^2 + 1) + T0*(s^3 - 2*s^2 + s) + P1*(-2*s^3 + 3*s^2) + T1*(s^3 - s^2) + + | similar result using matrix: + + .. code-block:: text + + H(s) = glm_smc(t, GLM_HERMITE_MAT, (vec4){p0, p1, c0, c1}) + + | glm_eq(glm_smc(...), glm_hermite(...)) should return TRUE + + + Parameters: + | *[in]* **s** parameter between 0 and 1 + | *[in]* **p0** begin point + | *[in]* **t0** tangent 1 + | *[in]* **t1** tangent 2 + | *[in]* **p1** end point + + Returns: + B(s) + +.. c:function:: float glm_decasteljau(float prm, float p0, float c0, float c1, float p1) + + | iterative way to solve cubic equation + + Parameters: + | *[in]* **prm** parameter between 0 and 1 + | *[in]* **p0** begin point + | *[in]* **c0** control point 1 + | *[in]* **c1** control point 2 + | *[in]* **p1** end point + + Returns: + parameter to use in cubic equation diff --git a/include/cglm/bezier.h b/include/cglm/bezier.h index 8b1ee6e..1d194f5 100644 --- a/include/cglm/bezier.h +++ b/include/cglm/bezier.h @@ -75,7 +75,7 @@ glm_bezier(float s, float p0, float c0, float c1, float p1) { * @param[in] t1 tangent 2 * @param[in] p1 end point * - * @return B(s) + * @return H(s) */ CGLM_INLINE float From 60cfc870094b57f81e0589106396cd1cb298aae5 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 2 Feb 2019 15:30:05 +0300 Subject: [PATCH 242/292] remove bezier_solve for now --- include/cglm/bezier.h | 17 ----------------- include/cglm/call/bezier.h | 4 ---- src/bezier.c | 6 ------ 3 files changed, 27 deletions(-) diff --git a/include/cglm/bezier.h b/include/cglm/bezier.h index 1d194f5..2560594 100644 --- a/include/cglm/bezier.h +++ b/include/cglm/bezier.h @@ -149,21 +149,4 @@ glm_decasteljau(float prm, float p0, float c0, float c1, float p1) { return glm_clamp_zo((u + v) * 0.5f); } -/*! - * @brief solve cubic bezier equation - * - * @param[in] prm parameter between 0 and 1 - * @param[in] p0 begin point - * @param[in] c0 control point 1 - * @param[in] c1 control point 2 - * @param[in] p1 end point - * - * @return parameter to use in cubic equation - */ -CGLM_INLINE -float -glm_bezier_solve(float prm, float p0, float c0, float c1, float p1) { - return glm_decasteljau(prm, p0, c0, c1, p1); -} - #endif /* cglm_bezier_h */ diff --git a/include/cglm/call/bezier.h b/include/cglm/call/bezier.h index b37f349..a6a0eb4 100644 --- a/include/cglm/call/bezier.h +++ b/include/cglm/call/bezier.h @@ -25,10 +25,6 @@ CGLM_EXPORT float glmc_decasteljau(float prm, float p0, float c0, float c1, float p1); -CGLM_EXPORT -float -glmc_bezier_solve(float prm, float p0, float c0, float c1, float p1); - #ifdef __cplusplus } #endif diff --git a/src/bezier.c b/src/bezier.c index 0bb16fe..21e6495 100644 --- a/src/bezier.c +++ b/src/bezier.c @@ -25,9 +25,3 @@ float glmc_decasteljau(float prm, float p0, float c0, float c1, float p1) { return glm_decasteljau(prm, p0, c0, c1, p1); } - -CGLM_EXPORT -float -glmc_bezier_solve(float prm, float p0, float c0, float c1, float p1) { - return glm_bezier_solve(prm, p0, c0, c1, p1); -} From 18f06743ed40755910000a76653c26a6d28a9376 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 2 Feb 2019 15:54:09 +0300 Subject: [PATCH 243/292] build: make automake build slient (less-verbose) --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 1349b90..d29b9bb 100644 --- a/configure.ac +++ b/configure.ac @@ -29,6 +29,7 @@ LT_INIT # Checks for libraries. AC_CHECK_LIB([m], [floor]) +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) AC_SYS_LARGEFILE # Checks for header files. From c8b8f4f6f0e60dd57f157a93ba1fe5110526281a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 13 Feb 2019 10:00:57 +0300 Subject: [PATCH 244/292] now working on v0.5.3 --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index d29b9bb..e2fabfe 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.5.2], [info@recp.me]) +AC_INIT([cglm], [0.5.3], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index 33ea83b..9a15689 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.5.2' +version = u'0.5.3' # The full version, including alpha/beta/rc tags. -release = u'0.5.2' +release = u'0.5.3' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index 5066576..47b8463 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 5 -#define CGLM_VERSION_PATCH 2 +#define CGLM_VERSION_PATCH 3 #endif /* cglm_version_h */ From 2b1eece9ac6f061dbb53add79af63758bcfe5aeb Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 13 Feb 2019 10:12:49 +0300 Subject: [PATCH 245/292] mat3: add rmc for mat3 --- docs/source/mat3.rst | 18 ++++++++++++++++++ docs/source/mat4.rst | 2 +- include/cglm/call/mat3.h | 4 ++++ include/cglm/mat3.h | 24 ++++++++++++++++++++++++ src/mat3.c | 6 ++++++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/docs/source/mat3.rst b/docs/source/mat3.rst index 8592c4e..9b0bec4 100644 --- a/docs/source/mat3.rst +++ b/docs/source/mat3.rst @@ -32,6 +32,7 @@ Functions: #. :c:func:`glm_mat3_trace` #. :c:func:`glm_mat3_swap_col` #. :c:func:`glm_mat3_swap_row` +#. :c:func:`glm_mat3_rmc` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -161,3 +162,20 @@ Functions documentation | *[in, out]* **mat** matrix | *[in]* **row1** row1 | *[in]* **row2** row2 + +.. c:function:: float glm_mat3_rmc(vec3 r, mat3 m, vec3 c) + + | **rmc** stands for **Row** * **Matrix** * **Column** + + | helper for R (row vector) * M (matrix) * C (column vector) + + | the result is scalar because R * M = Matrix1x3 (row vector), + | then Matrix1x3 * Vec3 (column vector) = Matrix1x1 (Scalar) + + Parameters: + | *[in]* **r** row vector or matrix1x3 + | *[in]* **m** matrix3x3 + | *[in]* **c** column vector or matrix3x1 + + Returns: + scalar value e.g. Matrix1x1 diff --git a/docs/source/mat4.rst b/docs/source/mat4.rst index 294f8f4..f9a1c18 100644 --- a/docs/source/mat4.rst +++ b/docs/source/mat4.rst @@ -278,7 +278,7 @@ Functions documentation | helper for R (row vector) * M (matrix) * C (column vector) - | the result is scalar because S * M = Matrix1x4 (row vector), + | the result is scalar because R * M = Matrix1x4 (row vector), | then Matrix1x4 * Vec4 (column vector) = Matrix1x1 (Scalar) Parameters: diff --git a/include/cglm/call/mat3.h b/include/cglm/call/mat3.h index f27e187..fbd8270 100644 --- a/include/cglm/call/mat3.h +++ b/include/cglm/call/mat3.h @@ -72,6 +72,10 @@ CGLM_EXPORT void glmc_mat3_swap_row(mat3 mat, int row1, int row2); +CGLM_EXPORT +float +glmc_mat3_rmc(vec3 r, mat3 m, vec3 c); + #ifdef __cplusplus } #endif diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 05bcf11..0ecd755 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -22,11 +22,13 @@ CGLM_INLINE void glm_mat3_transpose(mat3 m); CGLM_INLINE void glm_mat3_mulv(mat3 m, vec3 v, vec3 dest); CGLM_INLINE float glm_mat3_trace(mat3 m); + CGLM_INLINE void glm_mat3_quat(mat3 m, versor dest); CGLM_INLINE void glm_mat3_scale(mat3 m, float s); CGLM_INLINE float glm_mat3_det(mat3 mat); CGLM_INLINE void glm_mat3_inv(mat3 mat, mat3 dest); CGLM_INLINE void glm_mat3_swap_col(mat3 mat, int col1, int col2); CGLM_INLINE void glm_mat3_swap_row(mat3 mat, int row1, int row2); + CGLM_INLINE float glm_mat3_rmc(vec3 r, mat3 m, vec3 c); */ #ifndef cglm_mat3_h @@ -372,4 +374,26 @@ glm_mat3_swap_row(mat3 mat, int row1, int row2) { mat[2][row2] = tmp[2]; } +/*! + * @brief helper for R (row vector) * M (matrix) * C (column vector) + * + * rmc stands for Row * Matrix * Column + * + * the result is scalar because R * M = Matrix1x3 (row vector), + * then Matrix1x3 * Vec3 (column vector) = Matrix1x1 (Scalar) + * + * @param[in] r row vector or matrix1x3 + * @param[in] m matrix3x3 + * @param[in] c column vector or matrix3x1 + * + * @return scalar value e.g. Matrix1x1 + */ +CGLM_INLINE +float +glm_mat3_rmc(vec3 r, mat3 m, vec3 c) { + vec3 tmp; + glm_mat3_mulv(m, c, tmp); + return glm_vec3_dot(r, tmp); +} + #endif /* cglm_mat3_h */ diff --git a/src/mat3.c b/src/mat3.c index acb981b..337f1f1 100644 --- a/src/mat3.c +++ b/src/mat3.c @@ -91,3 +91,9 @@ void glmc_mat3_swap_row(mat3 mat, int row1, int row2) { glm_mat3_swap_row(mat, row1, row2); } + +CGLM_EXPORT +float +glmc_mat3_rmc(vec3 r, mat3 m, vec3 c) { + return glm_mat3_rmc(r, m, c); +} From 0d2e5a996aaeaf5d8cd550893912524873c9b523 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 13 Feb 2019 10:13:06 +0300 Subject: [PATCH 246/292] docs: add SSE3 and SSE4 dot product options --- docs/source/opt.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/source/opt.rst b/docs/source/opt.rst index 4acb972..6deca67 100644 --- a/docs/source/opt.rst +++ b/docs/source/opt.rst @@ -40,3 +40,13 @@ SSE and SSE2 Shuffle Option **_mm_shuffle_ps** generates **shufps** instruction even if registers are same. You can force it to generate **pshufd** instruction by defining **CGLM_USE_INT_DOMAIN** macro. As default it is not defined. + +SSE3 and SSE4 Dot Product Options +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You have to extra options for dot product: **CGLM_SSE4_DOT** and **CGLM_SSE3_DOT**. + +- If **SSE4** is enabled then you can define **CGLM_SSE4_DOT** to force cglm to use **_mm_dp_ps** instruction. +- If **SSE3** is enabled then you can define **CGLM_SSE3_DOT** to force cglm to use **_mm_hadd_ps** instructions. + +otherwise cglm will use custom cglm's hadd functions which are optimized too. From b4efcefe7f176b04cf82bcb415b7fbc1e2cb7c58 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 13 Feb 2019 10:14:53 +0300 Subject: [PATCH 247/292] drop glm__memcpy, glm__memset and glm__memzero * implement mat3_zero and mat4_zero functions * copy matrix items manually in ucopy functions --- docs/source/mat3.rst | 8 ++++++++ docs/source/mat4.rst | 8 ++++++++ include/cglm/cam.h | 6 +++--- include/cglm/common.h | 28 ---------------------------- include/cglm/mat3.h | 25 ++++++++++++++++++++++++- include/cglm/mat4.h | 31 ++++++++++++++++++++++++++----- 6 files changed, 69 insertions(+), 37 deletions(-) diff --git a/docs/source/mat3.rst b/docs/source/mat3.rst index 9b0bec4..e577ce4 100644 --- a/docs/source/mat3.rst +++ b/docs/source/mat3.rst @@ -21,6 +21,7 @@ Functions: 1. :c:func:`glm_mat3_copy` #. :c:func:`glm_mat3_identity` #. :c:func:`glm_mat3_identity_array` +#. :c:func:`glm_mat3_zero` #. :c:func:`glm_mat3_mul` #. :c:func:`glm_mat3_transpose_to` #. :c:func:`glm_mat3_transpose` @@ -60,6 +61,13 @@ Functions documentation | *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled) | *[in]* **count** count of matrices +.. c:function:: void glm_mat3_zero(mat3 mat) + + make given matrix zero + + Parameters: + | *[in,out]* **mat** matrix to + .. c:function:: void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest) multiply m1 and m2 to dest diff --git a/docs/source/mat4.rst b/docs/source/mat4.rst index f9a1c18..a74d6e2 100644 --- a/docs/source/mat4.rst +++ b/docs/source/mat4.rst @@ -26,6 +26,7 @@ Functions: #. :c:func:`glm_mat4_copy` #. :c:func:`glm_mat4_identity` #. :c:func:`glm_mat4_identity_array` +#. :c:func:`glm_mat4_zero` #. :c:func:`glm_mat4_pick3` #. :c:func:`glm_mat4_pick3t` #. :c:func:`glm_mat4_ins3` @@ -81,6 +82,13 @@ Functions documentation | *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled) | *[in]* **count** count of matrices +.. c:function:: void glm_mat4_zero(mat4 mat) + + make given matrix zero + + Parameters: + | *[in,out]* **mat** matrix to + .. c:function:: void glm_mat4_pick3(mat4 mat, mat3 dest) copy upper-left of mat4 to mat3 diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 314b065..e77b989 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -84,7 +84,7 @@ glm_frustum(float left, mat4 dest) { float rl, tb, fn, nv; - glm__memzero(float, dest, sizeof(mat4)); + glm_mat4_zero(dest); rl = 1.0f / (right - left); tb = 1.0f / (top - bottom); @@ -122,7 +122,7 @@ glm_ortho(float left, mat4 dest) { float rl, tb, fn; - glm__memzero(float, dest, sizeof(mat4)); + glm_mat4_zero(dest); rl = 1.0f / (right - left); tb = 1.0f / (top - bottom); @@ -259,7 +259,7 @@ glm_perspective(float fovy, mat4 dest) { float f, fn; - glm__memzero(float, dest, sizeof(mat4)); + glm_mat4_zero(dest); f = 1.0f / tanf(fovy * 0.5f); fn = 1.0f / (nearVal - farVal); diff --git a/include/cglm/common.h b/include/cglm/common.h index 199bfda..422716a 100644 --- a/include/cglm/common.h +++ b/include/cglm/common.h @@ -26,34 +26,6 @@ # define CGLM_INLINE static inline __attribute((always_inline)) #endif -#define glm__memcpy(type, dest, src, size) \ - do { \ - type *srci; \ - type *srci_end; \ - type *desti; \ - \ - srci = (type *)src; \ - srci_end = (type *)((char *)srci + size); \ - desti = (type *)dest; \ - \ - while (srci != srci_end) \ - *desti++ = *srci++; \ - } while (0) - -#define glm__memset(type, dest, size, val) \ - do { \ - type *desti; \ - type *desti_end; \ - \ - desti = (type *)dest; \ - desti_end = (type *)((char *)desti + size); \ - \ - while (desti != desti_end) \ - *desti++ = val; \ - } while (0) - -#define glm__memzero(type, dest, size) glm__memset(type, dest, size, 0) - #include "types.h" #include "simd/intrin.h" diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 0ecd755..3126064 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -17,6 +17,7 @@ CGLM_INLINE void glm_mat3_copy(mat3 mat, mat3 dest); CGLM_INLINE void glm_mat3_identity(mat3 mat); CGLM_INLINE void glm_mat3_identity_array(mat3 * restrict mat, size_t count); + CGLM_INLINE void glm_mat3_zero(mat3 mat); CGLM_INLINE void glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest); CGLM_INLINE void glm_mat3_transpose_to(mat3 m, mat3 dest); CGLM_INLINE void glm_mat3_transpose(mat3 m); @@ -65,7 +66,17 @@ CGLM_INLINE void glm_mat3_copy(mat3 mat, mat3 dest) { - glm__memcpy(float, dest, mat, sizeof(mat3)); + 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]; } /*! @@ -108,6 +119,18 @@ glm_mat3_identity_array(mat3 * __restrict mat, size_t count) { } } +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +void +glm_mat3_zero(mat3 mat) { + CGLM_ALIGN_MAT mat3 t = GLM_MAT3_ZERO_INIT; + glm_mat3_copy(t, mat); +} + /*! * @brief multiply m1 and m2 to dest * diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 74e876a..e6b916b 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -22,6 +22,7 @@ CGLM_INLINE void glm_mat4_copy(mat4 mat, mat4 dest); CGLM_INLINE void glm_mat4_identity(mat4 mat); CGLM_INLINE void glm_mat4_identity_array(mat4 * restrict mat, size_t count); + CGLM_INLINE void glm_mat4_zero(mat4 mat); CGLM_INLINE void glm_mat4_pick3(mat4 mat, mat3 dest); CGLM_INLINE void glm_mat4_pick3t(mat4 mat, mat3 dest); CGLM_INLINE void glm_mat4_ins3(mat3 mat, mat4 dest); @@ -31,6 +32,7 @@ CGLM_INLINE void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest); CGLM_INLINE float glm_mat4_trace(mat4 m); CGLM_INLINE float glm_mat4_trace3(mat4 m); + CGLM_INLINE void glm_mat4_quat(mat4 m, versor dest) ; CGLM_INLINE void glm_mat4_transpose_to(mat4 m, mat4 dest); CGLM_INLINE void glm_mat4_transpose(mat4 m); CGLM_INLINE void glm_mat4_scale_p(mat4 m, float s); @@ -40,6 +42,7 @@ CGLM_INLINE void glm_mat4_inv_fast(mat4 mat, mat4 dest); CGLM_INLINE void glm_mat4_swap_col(mat4 mat, int col1, int col2); CGLM_INLINE void glm_mat4_swap_row(mat4 mat, int row1, int row2); + CGLM_INLINE float glm_mat4_rmc(vec4 r, mat4 m, vec4 c); */ #ifndef cglm_mat_h @@ -98,7 +101,15 @@ CGLM_INLINE void glm_mat4_ucopy(mat4 mat, mat4 dest) { - glm__memcpy(float, dest, mat, sizeof(mat4)); + dest[0][0] = mat[0][0]; dest[1][0] = mat[1][0]; + dest[0][1] = mat[0][1]; dest[1][1] = mat[1][1]; + dest[0][2] = mat[0][2]; dest[1][2] = mat[1][2]; + dest[0][3] = mat[0][3]; dest[1][3] = mat[1][3]; + + dest[2][0] = mat[2][0]; dest[3][0] = mat[3][0]; + dest[2][1] = mat[2][1]; dest[3][1] = mat[3][1]; + dest[2][2] = mat[2][2]; dest[3][2] = mat[3][2]; + dest[2][3] = mat[2][3]; dest[3][3] = mat[3][3]; } /*! @@ -168,6 +179,18 @@ glm_mat4_identity_array(mat4 * __restrict mat, size_t count) { } } +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +void +glm_mat4_zero(mat4 mat) { + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_ZERO_INIT; + glm_mat4_copy(t, mat); +} + /*! * @brief copy upper-left of mat4 to mat3 * @@ -474,10 +497,8 @@ glm_mat4_transpose(mat4 m) { glm_mat4_transp_sse2(m, m); #else mat4 d; - glm_mat4_transpose_to(m, d); - - glm__memcpy(float, m, d, sizeof(mat4)); + glm_mat4_ucopy(d, m); #endif } @@ -682,7 +703,7 @@ glm_mat4_swap_row(mat4 mat, int row1, int row2) { * * rmc stands for Row * Matrix * Column * - * the result is scalar because S * M = Matrix1x4 (row vector), + * the result is scalar because R * M = Matrix1x4 (row vector), * then Matrix1x4 * Vec4 (column vector) = Matrix1x1 (Scalar) * * @param[in] r row vector or matrix1x4 From ee1937f28d709a1b5b5fb0f9e2dc7271bd202660 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 17 Mar 2019 09:29:36 +0300 Subject: [PATCH 248/292] now working on v0.5.4 --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index e2fabfe..2c9329f 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.5.3], [info@recp.me]) +AC_INIT([cglm], [0.5.4], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index 9a15689..9fd800a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.5.3' +version = u'0.5.4' # The full version, including alpha/beta/rc tags. -release = u'0.5.3' +release = u'0.5.4' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index 47b8463..3664323 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 5 -#define CGLM_VERSION_PATCH 3 +#define CGLM_VERSION_PATCH 4 #endif /* cglm_version_h */ From 8fa21a1837783154589fbef2fc2a515aa5360946 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 17 Mar 2019 09:33:38 +0300 Subject: [PATCH 249/292] docs: use sphinx_rtd_theme theme dor documentation --- docs/source/build.rst | 32 +++++++++++++++++------ docs/source/conf.py | 16 ++++++------ docs/source/features.rst | 23 +++++++++++++++++ docs/source/getting_started.rst | 28 ++++++++++---------- docs/source/index.rst | 45 ++++++++++++++++++--------------- docs/source/opengl.rst | 4 +-- 6 files changed, 96 insertions(+), 52 deletions(-) create mode 100644 docs/source/features.rst diff --git a/docs/source/build.rst b/docs/source/build.rst index 842c761..c725ab4 100644 --- a/docs/source/build.rst +++ b/docs/source/build.rst @@ -1,9 +1,7 @@ -Building cglm +Build cglm ================================ -| **cglm** does not have external dependencies except for unit testing. -| When you pulled cglm repo with submodules all dependencies will be pulled too. -| `build-deps.sh` will pull all dependencies/submodules and build for you. +| **cglm** does not have external dependencies except for unit testing. When you pulled **cglm** repo with submodules all dependencies will be pulled too. `build-deps.sh` will pull all dependencies/submodules and build for you. External dependencies: * cmocka - for unit testing @@ -12,7 +10,8 @@ External dependencies: If you only need to inline versions, you don't need to build **cglm**, you don't need to link it to your program. Just import cglm to your project as dependency / external lib by copy-paste then use it as usual -**Unix (Autotools):** +Unix (Autotools): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: bash :linenos: @@ -26,11 +25,12 @@ Just import cglm to your project as dependency / external lib by copy-paste then $ [sudo] make install # install to system (optional) **make** will build cglm to **.libs** sub folder in project folder. -If you don't want to install cglm to your system's folder you can get static and dynamic libs in this folder. +If you don't want to install **cglm** to your system's folder you can get static and dynamic libs in this folder. -**Build dependencies (windows):** +Windows (MSBuild): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Windows related build files, project files are located in win folder, +Windows related build files, project files are located in `win` folder, make sure you are inside in cglm/win folder. Code Analysis are enabled, it may take awhile to build. @@ -50,3 +50,19 @@ then try to build with *devenv*: $ devenv cglm.sln /Build Release Currently tests are not available on Windows. + +Documentation (Sphinx): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**cglm** uses sphinx framework for documentation, it allows lot of formats for documentation. To see all options see sphinx build page: + +https://www.sphinx-doc.org/en/master/man/sphinx-build.html + +Example build: + +.. code-block:: bash + :linenos: + + $ cd cglm/docs + $ sphinx-build source build + diff --git a/docs/source/conf.py b/docs/source/conf.py index 9fd800a..c2b6ba0 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -90,7 +90,7 @@ todo_include_todos = False # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'alabaster' +html_theme = 'sphinx_rtd_theme' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -99,13 +99,13 @@ html_theme = 'alabaster' # html_theme_options = {} html_theme_options = { - 'github_banner': 'true', - 'github_button': 'true', - 'github_user': 'recp', - 'github_repo': 'cglm', - 'travis_button': 'true', - 'show_related': 'true', - 'fixed_sidebar': 'true' + # 'github_banner': 'true', + # 'github_button': 'true', + # 'github_user': 'recp', + # 'github_repo': 'cglm', + # 'travis_button': 'true', + # 'show_related': 'true', + # 'fixed_sidebar': 'true' } # Add any paths that contain custom static files (such as style sheets) here, diff --git a/docs/source/features.rst b/docs/source/features.rst new file mode 100644 index 0000000..69e8cd1 --- /dev/null +++ b/docs/source/features.rst @@ -0,0 +1,23 @@ +Features +================================================================================ + +* general purpose matrix operations (mat4, mat3) +* chain matrix multiplication (square only) +* general purpose vector operations (cross, dot, rotate, proj, angle...) +* affine transforms +* matrix decomposition (extract rotation, scaling factor) +* optimized affine transform matrices (mul, rigid-body inverse) +* camera (lookat) +* projections (ortho, perspective) +* quaternions +* euler angles / yaw-pitch-roll to matrix +* extract euler angles +* inline or pre-compiled function call +* frustum (extract view frustum planes, corners...) +* bounding box (AABB in Frustum (culling), crop, merge...) +* bounding sphere +* project, unproject +* easing functions +* curves +* curve interpolation helpers (SMC, deCasteljau...) +* and other... diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 2f8511c..bf2b8f3 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -9,23 +9,26 @@ Types: .. code-block:: c :linenos: - typedef float vec3[3]; - typedef int ivec3[3]; - typedef CGLM_ALIGN(16) float vec4[4]; + typedef float vec2[2]; + typedef float vec3[3]; + typedef int ivec3[3]; + typedef CGLM_ALIGN_IF(16) float vec4[4]; + typedef vec4 versor; + typedef vec3 mat3[3]; - typedef vec3 mat3[3]; - typedef vec4 mat4[4]; - - typedef vec4 versor; + #ifdef __AVX__ + typedef CGLM_ALIGN_IF(32) vec4 mat4[4]; + #else + typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; + #endif As you can see types don't store extra informations in favor of space. You can send these values e.g. matrix to OpenGL directly without casting or calling a function like *value_ptr* -Alignment is Required: +Alignment Is Required: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -**vec4** and **mat4** requires 16 byte alignment because vec4 and mat4 operations are -vectorized by SIMD instructions (SSE/AVX). +**vec4** and **mat4** requires 16 (32 for **mat4** if AVX is enabled) byte alignment because **vec4** and **mat4** operations are vectorized by SIMD instructions (SSE/AVX/NEON). **UPDATE:** By starting v0.4.5 cglm provides an option to disable alignment requirement, it is enabled as default @@ -37,10 +40,9 @@ vectorized by SIMD instructions (SSE/AVX). Allocations: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *cglm* doesn't alloc any memory on heap. So it doesn't provide any allocator. -You must allocate memory yourself. You should alloc memory for out parameters too if you pass pointer of memory location. -When allocating memory don't forget that **vec4** and **mat4** requires alignment. +You must allocate memory yourself. You should alloc memory for out parameters too if you pass pointer of memory location. When allocating memory, don't forget that **vec4** and **mat4** require alignment. -**NOTE:** Unaligned vec4 and unaligned mat4 operations will be supported in the future. Check todo list. +**NOTE:** Unaligned **vec4** and unaligned **mat4** operations will be supported in the future. Check todo list. Because you may want to multiply a CGLM matrix with external matrix. There is no guarantee that non-CGLM matrix is aligned. Unaligned types will have *u* prefix e.g. **umat4** diff --git a/docs/source/index.rst b/docs/source/index.rst index cfdf220..38c9e37 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -3,7 +3,7 @@ You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. -Welcome to cglm's documentation! +cglm Documentation ================================ **cglm** is optimized 3D math library written in C99 (compatible with C89). @@ -14,33 +14,36 @@ is considered to be supported as optional. Also currently only **float** type is supported for most operations. -**Features** - -* general purpose matrix operations (mat4, mat3) -* chain matrix multiplication (square only) -* general purpose vector operations (cross, dot, rotate, proj, angle...) -* affine transforms -* matrix decomposition (extract rotation, scaling factor) -* optimized affine transform matrices (mul, rigid-body inverse) -* camera (lookat) -* projections (ortho, perspective) -* quaternions -* euler angles / yaw-pitch-roll to matrix -* extract euler angles -* inline or pre-compiled function call -* frustum (extract view frustum planes, corners...) -* bounding box (AABB in Frustum (culling), crop, merge...) - - .. toctree:: - :maxdepth: 1 - :caption: Table Of Contents: + :maxdepth: 2 + :caption: Getting Started: + features build getting_started + +.. toctree:: + :maxdepth: 2 + :caption: How To: + opengl + +.. toctree:: + :maxdepth: 2 + :caption: API: + api + +.. toctree:: + :maxdepth: 2 + :caption: Options: + opt + +.. toctree:: + :maxdepth: 2 + :caption: Troubleshooting: + troubleshooting Indices and tables diff --git a/docs/source/opengl.rst b/docs/source/opengl.rst index e6b37e0..a38d572 100644 --- a/docs/source/opengl.rst +++ b/docs/source/opengl.rst @@ -43,9 +43,9 @@ array of matrices: /* ... */ glUniformMatrix4fv(location, count, GL_FALSE, (float *)matrix); -in this way, passing aray of matrices is same +in this way, passing aray of matrices is same -Passing / Uniforming Vectors to OpenGL:¶ +Passing / Uniforming Vectors to OpenGL: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You don't need to do extra thing when passing cglm vectors to OpengL or other APIs. From 73226bd2fd6574c31da668d69a34e88a0cdc1374 Mon Sep 17 00:00:00 2001 From: Wasin Thonkaew Date: Wed, 20 Mar 2019 14:32:31 +0800 Subject: [PATCH 250/292] Fulfill #76 (#77) * Fulfill #76 --- include/cglm/affine-mat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/affine-mat.h b/include/cglm/affine-mat.h index 0dcb447..f58749b 100644 --- a/include/cglm/affine-mat.h +++ b/include/cglm/affine-mat.h @@ -152,7 +152,7 @@ glm_inv_tr(mat4 mat) { glm_inv_tr_sse2(mat); #else CGLM_ALIGN_MAT mat3 r; - CGLM_ALIGN(16) vec3 t; + CGLM_ALIGN(8) vec3 t; /* rotate */ glm_mat4_pick3t(mat, r); From f848e4451afe6666c83b9488e4bc70d9c950c8f0 Mon Sep 17 00:00:00 2001 From: acoto87 Date: Thu, 28 Mar 2019 20:56:37 -0600 Subject: [PATCH 251/292] Include `stddef.h` to ensure `size_t` and other dependent types --- include/cglm/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/cglm/common.h b/include/cglm/common.h index 422716a..42d5e67 100644 --- a/include/cglm/common.h +++ b/include/cglm/common.h @@ -11,6 +11,7 @@ #define _USE_MATH_DEFINES /* for windows */ #include +#include #include #include From 674e05213a58e3289319616ed38fab4be4adc64a Mon Sep 17 00:00:00 2001 From: acoto87 Date: Thu, 28 Mar 2019 23:41:19 -0600 Subject: [PATCH 252/292] - Add struct types to types.h. - Add structs/vec4.h file. --- include/cglm/structs/vec4.h | 282 ++++++++++++++++++++++++++++++++++++ include/cglm/types.h | 46 ++++++ 2 files changed, 328 insertions(+) create mode 100644 include/cglm/structs/vec4.h diff --git a/include/cglm/structs/vec4.h b/include/cglm/structs/vec4.h new file mode 100644 index 0000000..7290c35 --- /dev/null +++ b/include/cglm/structs/vec4.h @@ -0,0 +1,282 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_vec4s_h +#define cglm_vec4s_h + +#include "common.h" +#include "vec4-ext.h" +#include "util.h" + +#define GLMS_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f} +#define GLMS_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f} +#define GLMS_VEC4_ZERO_INIT {0.0f, 0.0f, 0.0f, 0.0f} + +#define GLMS_VEC4_ONE ((vec4s)GLM_VEC4_ONE_INIT) +#define GLMS_VEC4_BLACK ((vec4s)GLM_VEC4_BLACK_INIT) +#define GLMS_VEC4_ZERO ((vec4s)GLM_VEC4_ZERO_INIT) + +CGLM_INLINE +vec4s +glms_vec4(vec3s v3, float last) +{ + vec4s r; + glm_vec4(v3.raw, last, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec4_copy3(vec4s v) +{ + vec3s r; + glm_vec4_copy3(v.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_copy(vec4s v) +{ + vec4s r; + glm_vec4_copy(v.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_ucopy(vec4s v) +{ + vec4s r; + glm_vec4_ucopy(v.raw, r.raw); + return r; +} + + +CGLM_INLINE +float +glms_vec4_dot(vec4s a, vec4s b) +{ + return glm_vec4_dot(a.raw, b.raw); +} + +CGLM_INLINE +float +glms_vec4_norm2(vec4s v) +{ + return glm_vec4_norm2(v.raw); +} + +CGLM_INLINE +float +glms_vec4_norm(vec4s v) +{ + return glm_vec4_norm(v.raw); +} + +CGLM_INLINE +vec4s +glms_vec4_add(vec4s a, vec4s b) +{ + vec4s r; + glm_vec4_add(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_adds(vec4s v, float s) +{ + vec4s r; + glm_vec4_adds(v.raw s, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_sub(vec4s a, vec4s b) +{ + vec4s r; + glm_vec4_sub(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_subs(vec4s v, float s) +{ + vec4s r; + glm_vec4_subs(v.raw, s, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_mul(vec4s a, vec4s b) +{ + vec4s r; + glm_vec4_mul(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_scale(vec4s v, float s) +{ + vec4s r; + glm_vec4_scale(v.raw, s, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_scale_as(vec4s v, float s) +{ + vec4s r; + glm_vec4_scale_as(v.raw, s, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_div(vec4s a, vec4s b) +{ + vec4s r; + glm_vec4_div(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_divs(vec4s v, float s) +{ + vec4s r; + glm_vec4_divs(v.raw, s, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_addadd(vec4s a, vec4s b) +{ + vec4s r; + glm_vec4_addadd(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_subadd(vec4s a, vec4s b) +{ + vec4s r; + glm_vec4_subadd(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_muladd(vec4s a, vec4s b) +{ + vec4s r; + glm_vec4_muladd(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_muladds(vec4s a, float s) +{ + vec4s r; + glm_vec4_muladds(a.raw, s, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_maxadd(vec4s a, vec4s b) +{ + vec4s r; + glm_vec4_maxadd(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_minadd(vec4s a, vec4s b) +{ + vec4s r; + glm_vec4_minadd(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_negate(vec4s v) +{ + glm_vec4_negate(v.raw); + return v; +} + +CGLM_INLINE +vec4s +glms_vec4_inv(vec4s v) +{ + glm_vec4_inv(v.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_normalize(vec4s v) +{ + glm_vec4_normalize(v.raw); + return v; +} + +CGLM_INLINE +float +glms_vec4_distance(vec4s a, vec4s b) +{ + return glm_vec4_distance(a.raw, b.raw); +} + +CGLM_INLINE +vec4s +glms_vec4_maxv(vec4s a, vec4s b) +{ + vec4s r; + glm_vec4_maxv(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_minv(vec4s a, vec4s b) +{ + vec4s r; + glm_vec4_minv(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_clamp(vec4s v, float minVal, float maxVal) +{ + glm_vec4_clamp(v.raw, minVal, maxVal); + return v; +} + +CGLM_INLINE +vec4s +glms_vec4_lerp(vec4s from, vec4s to, float t) +{ + vec4s r; + glm_vec4_lerp(from.raw, to.raw, t, r.raw); + return r; +} + +#endif /* cglm_vec4s_h */ diff --git a/include/cglm/types.h b/include/cglm/types.h index 1190b73..29703df 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -32,6 +32,7 @@ # define CGLM_ALIGN_MAT CGLM_ALIGN(16) #endif +// array types typedef float vec2[2]; typedef float vec3[3]; typedef int ivec3[3]; @@ -45,6 +46,51 @@ typedef CGLM_ALIGN_IF(32) vec4 mat4[4]; typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; #endif +// struct types +typedef union CGLM_ALIGN_IF(8) vec2s { +#ifndef CGLM_NO_ANONYMOUS_STRUCT + struct { + float x; + float y; + }; +#endif + vec2 raw; +} vec2s; + +typedef union CGLM_ALIGN_IF(8) vec3s { +#ifndef CGLM_NO_ANONYMOUS_STRUCT + struct { + float x; + float y; + float z; + }; +#endif + vec3 raw; +} vec3s; + +typedef union CGLM_ALIGN_IF(8) ivec3s { +#ifndef CGLM_NO_ANONYMOUS_STRUCT + struct { + int x; + int y; + int z; + }; +#endif + ivec3 raw; +} ivec3s; + +typedef union CGLM_ALIGN_IF(16) vec4s { +#ifndef CGLM_NO_ANONYMOUS_STRUCT + struct { + float x; + float y; + float z; + float w; + }; +#endif + vec4 raw; +} vec4s; + #define GLM_E 2.71828182845904523536028747135266250 /* e */ #define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */ #define GLM_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */ From 4c5451994f38328cc0a94457e57c192d2ee31950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Coto=20Guti=C3=A9rrez?= Date: Thu, 28 Mar 2019 23:54:09 -0600 Subject: [PATCH 253/292] Include `stddef.h` to ensure `size_t` and other dependent types (#79) --- include/cglm/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/cglm/common.h b/include/cglm/common.h index 422716a..42d5e67 100644 --- a/include/cglm/common.h +++ b/include/cglm/common.h @@ -11,6 +11,7 @@ #define _USE_MATH_DEFINES /* for windows */ #include +#include #include #include From 6c0c5167b05f6a1c1fa29f89783c151650d85409 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 31 Mar 2019 18:53:31 +0300 Subject: [PATCH 254/292] docs: fix some parameter docs --- include/cglm/vec3.h | 4 ++-- include/cglm/vec4.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index c53c8ab..e67cc2f 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -428,8 +428,8 @@ glm_vec3_maxadd(vec3 a, vec3 b, vec3 dest) { * * it applies += operator so dest must be initialized * - * @param[in] a vector - * @param[in] b scalar + * @param[in] a vector 1 + * @param[in] b vector 2 * @param[out] dest dest += min(a, b) */ CGLM_INLINE diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index bbd1c31..b94cf61 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -576,8 +576,8 @@ glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest) { * * it applies += operator so dest must be initialized * - * @param[in] a vector - * @param[in] b scalar + * @param[in] a vector 1 + * @param[in] b vector 2 * @param[out] dest dest += min(a, b) */ CGLM_INLINE From 81a74ba2255dd4c60f19126aab9d78609e74a5c8 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 31 Mar 2019 18:58:20 +0300 Subject: [PATCH 255/292] move 'stdbool.h' to common header, add missing common.h header to public headers --- include/cglm/bezier.h | 2 ++ include/cglm/common.h | 1 + include/cglm/project.h | 1 + include/cglm/util.h | 1 - include/cglm/vec3-ext.h | 3 --- include/cglm/vec4-ext.h | 3 --- 6 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/cglm/bezier.h b/include/cglm/bezier.h index 2560594..5dac859 100644 --- a/include/cglm/bezier.h +++ b/include/cglm/bezier.h @@ -8,6 +8,8 @@ #ifndef cglm_bezier_h #define cglm_bezier_h +#include "common.h" + #define GLM_BEZIER_MAT_INIT {{-1.0f, 3.0f, -3.0f, 1.0f}, \ { 3.0f, -6.0f, 3.0f, 0.0f}, \ {-3.0f, 3.0f, 0.0f, 0.0f}, \ diff --git a/include/cglm/common.h b/include/cglm/common.h index 42d5e67..c7c5eb8 100644 --- a/include/cglm/common.h +++ b/include/cglm/common.h @@ -14,6 +14,7 @@ #include #include #include +#include #if defined(_MSC_VER) # ifdef CGLM_DLL diff --git a/include/cglm/project.h b/include/cglm/project.h index d4295d3..1336222 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -8,6 +8,7 @@ #ifndef cglm_project_h #define cglm_project_h +#include "common.h" #include "vec3.h" #include "vec4.h" #include "mat4.h" diff --git a/include/cglm/util.h b/include/cglm/util.h index af73eb8..d1ef21b 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -19,7 +19,6 @@ #define cglm_util_h #include "common.h" -#include #define GLM_MIN(X, Y) (((X) < (Y)) ? (X) : (Y)) #define GLM_MAX(X, Y) (((X) > (Y)) ? (X) : (Y)) diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index 0e64325..f1cc462 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -31,9 +31,6 @@ #include "common.h" #include "util.h" -#include -#include -#include /*! * @brief fill a vector with specified value diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index 07821ac..c545a14 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -31,9 +31,6 @@ #include "common.h" #include "vec3-ext.h" -#include -#include -#include /*! * @brief fill a vector with specified value From c25469829a000a397fc164d93896a5505899e859 Mon Sep 17 00:00:00 2001 From: acoto87 Date: Wed, 3 Apr 2019 22:25:49 -0600 Subject: [PATCH 256/292] Initial implementation of struct type `vec4s` --- include/cglm/cglms.h | 20 ++++++ include/cglm/structs/vec4-ext.h | 114 ++++++++++++++++++++++++++++++++ include/cglm/structs/vec4.h | 15 +++-- include/cglm/types.h | 23 +------ test/src/test_common.c | 14 ++++ test/src/test_common.h | 9 ++- test/src/test_quat.c | 2 + test/src/test_vec4.c | 10 ++- 8 files changed, 178 insertions(+), 29 deletions(-) create mode 100644 include/cglm/cglms.h create mode 100644 include/cglm/structs/vec4-ext.h diff --git a/include/cglm/cglms.h b/include/cglm/cglms.h new file mode 100644 index 0000000..4dd471f --- /dev/null +++ b/include/cglm/cglms.h @@ -0,0 +1,20 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_structs_h +#define cglm_structs_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "cglm.h" +#include "structs/vec4.h" + +#ifdef __cplusplus +} +#endif +#endif /* cglm_structs_h */ diff --git a/include/cglm/structs/vec4-ext.h b/include/cglm/structs/vec4-ext.h new file mode 100644 index 0000000..ea84e82 --- /dev/null +++ b/include/cglm/structs/vec4-ext.h @@ -0,0 +1,114 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_vec4s_ext_h +#define cglm_vec4s_ext_h + +#include "common.h" +#include "vec3-ext.h" +#include +#include +#include + +CGLM_INLINE +vec4s +glms_vec4_broadcast(float val, vec4 d) +{ + vec4s r; + glm_vec4_broadcast(val, r.raw); + return r; +} + +CGLM_INLINE +bool +glms_vec4_eq(vec4s v, float val) +{ + return glm_vec4_eq(v.raw, val); +} + +CGLM_INLINE +bool +glms_vec4_eq_eps(vec4 v, float val) +{ + return glm_vec4_eq_eps(v.raw, val); +} + +CGLM_INLINE +bool +glms_vec4_eq_all(vec4s v) +{ + return glm_vec4_eq_all(v.raw); +} + +CGLM_INLINE +bool +glms_vec4_eqv(vec4s a, vec4s b) +{ + return glm_vec4_eqv(a.raw, b.raw); +} + +CGLM_INLINE +bool +glms_vec4_eqv_eps(vec4s a, vec4s b) +{ + return glm_vec4_eqv_eps(a.raw, b.raw); +} + +CGLM_INLINE +float +glms_vec4_max(vec4s v) +{ + return glm_vec4_max(v.raw); +} + +CGLM_INLINE +float +glms_vec4_min(vec4s v) +{ + return glm_vec4_min(v.raw); +} + +CGLM_INLINE +bool +glms_vec4_isnan(vec4s v) +{ + return glm_vec4_isnan(v.raw); +} + +CGLM_INLINE +bool +glms_vec4_isinf(vec4s v) +{ + return glm_vec4_isinf(v.raw); +} + +CGLM_INLINE +bool +glms_vec4_isvalid(vec4s v) +{ + return glm_vec4_isvalid(v.raw); +} + +CGLM_INLINE +vec4s +glms_vec4_sign(vec4s v) +{ + vec4s r; + glm_vec4_sign(v.raw, r.raw); + return r; +} + +CGLM_INLINE +vec4s +glms_vec4_sqrt(vec4s v) +{ + vec4s r; + glm_vec4_sqrt(v.raw, r.raw); + return r; +} + +#endif /* cglm_vec4s_ext_h */ diff --git a/include/cglm/structs/vec4.h b/include/cglm/structs/vec4.h index 7290c35..b68bb33 100644 --- a/include/cglm/structs/vec4.h +++ b/include/cglm/structs/vec4.h @@ -8,9 +8,11 @@ #ifndef cglm_vec4s_h #define cglm_vec4s_h -#include "common.h" -#include "vec4-ext.h" -#include "util.h" +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" #define GLMS_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f} #define GLMS_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f} @@ -92,7 +94,7 @@ vec4s glms_vec4_adds(vec4s v, float s) { vec4s r; - glm_vec4_adds(v.raw s, r.raw); + glm_vec4_adds(v.raw, s, r.raw); return r; } @@ -226,7 +228,7 @@ vec4s glms_vec4_inv(vec4s v) { glm_vec4_inv(v.raw); - return r; + return v; } CGLM_INLINE @@ -279,4 +281,7 @@ glms_vec4_lerp(vec4s from, vec4s to, float t) return r; } +#ifdef __cplusplus +} +#endif #endif /* cglm_vec4s_h */ diff --git a/include/cglm/types.h b/include/cglm/types.h index 29703df..69c2885 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -47,17 +47,7 @@ typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; #endif // struct types -typedef union CGLM_ALIGN_IF(8) vec2s { -#ifndef CGLM_NO_ANONYMOUS_STRUCT - struct { - float x; - float y; - }; -#endif - vec2 raw; -} vec2s; - -typedef union CGLM_ALIGN_IF(8) vec3s { +typedef union CGLM_ALIGN_IF(16) vec3s { #ifndef CGLM_NO_ANONYMOUS_STRUCT struct { float x; @@ -68,17 +58,6 @@ typedef union CGLM_ALIGN_IF(8) vec3s { vec3 raw; } vec3s; -typedef union CGLM_ALIGN_IF(8) ivec3s { -#ifndef CGLM_NO_ANONYMOUS_STRUCT - struct { - int x; - int y; - int z; - }; -#endif - ivec3 raw; -} ivec3s; - typedef union CGLM_ALIGN_IF(16) vec4s { #ifndef CGLM_NO_ANONYMOUS_STRUCT struct { diff --git a/test/src/test_common.c b/test/src/test_common.c index d41d3cb..94331f4 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -57,6 +57,14 @@ test_rand_vec4(vec4 dest) { dest[3] = drand48(); } +vec4s +test_rand_vec4s() +{ + vec4s r; + test_rand_vec4(r.raw); + return r; +} + float test_rand(void) { srand((unsigned int)time(NULL)); @@ -127,6 +135,12 @@ test_assert_vec4_eq(vec4 v1, vec4 v2) { assert_true(fabsf(v1[3] - v2[3]) <= 0.000009); } +void +test_assert_vec4s_eq(vec4s v1, vec4s v2) +{ + test_assert_vec4_eq(v1.raw, v2.raw); +} + void test_assert_quat_eq_abs(versor v1, versor v2) { assert_true(fabsf(fabsf(v1[0]) - fabsf(v2[0])) <= 0.0009); /* rounding errors */ diff --git a/test/src/test_common.h b/test/src/test_common.h index 8a16b0f..c6a2dc4 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -20,6 +20,7 @@ #include #include +#include #include void @@ -46,6 +47,9 @@ test_assert_vec3_eq(vec3 v1, vec3 v2); void test_assert_vec4_eq(vec4 v1, vec4 v2); +void +test_assert_vec4s_eq(vec4s v1, vec4s v2); + void test_assert_quat_eq(versor v1, versor v2); @@ -56,7 +60,10 @@ void test_rand_vec3(vec3 dest); void -test_rand_vec4(vec4 dest) ; +test_rand_vec4(vec4 dest); + +vec4s +test_rand_vec4s(); float test_rand(void); diff --git a/test/src/test_quat.c b/test/src/test_quat.c index 0d64367..d0cc27c 100644 --- a/test/src/test_quat.c +++ b/test/src/test_quat.c @@ -44,9 +44,11 @@ test_quat(void **state) { test_assert_mat4_eq2(inRot, outRot, 0.000009); /* almost equal */ /* 4. test SSE mul and raw mul */ +#if defined( __SSE__ ) || defined( __SSE2__ ) test_quat_mul_raw(inQuat, outQuat, q3); glm_quat_mul_sse2(inQuat, outQuat, q4); test_assert_quat_eq(q3, q4); +#endif } /* 5. test lookat */ diff --git a/test/src/test_vec4.c b/test/src/test_vec4.c index 8e4fda5..5fe3be8 100644 --- a/test/src/test_vec4.c +++ b/test/src/test_vec4.c @@ -65,10 +65,10 @@ test_vec4_clamp(vec4 v, float minVal, float maxVal) { void test_vec4(void **state) { vec4 v, v1, v2, v3, v4; + vec4s vs1, vs2, vs3, vs4; int i; float d1, d2; - for (i = 0; i < 1000; i++) { /* 1. test SSE/SIMD dot product */ test_rand_vec4(v); @@ -175,4 +175,12 @@ test_vec4(void **state) { assert_true(v3[1] >= 0.0999 && v3[1] <= 0.80001); assert_true(v3[2] >= 0.0999 && v3[2] <= 0.80001); assert_true(v3[3] >= 0.0999 && v3[3] <= 0.80001); + + /* structs */ + vs1 = test_rand_vec4s(); + vs2 = test_rand_vec4s(); + + vs3 = glms_vec4_add(vs1, vs2); + vs4 = glms_vec4_maxv(vs1, vs3); + test_assert_vec4s_eq(vs3, vs4); } From 1aa54dc1109ea663b95984417baa0f4a3b851c9d Mon Sep 17 00:00:00 2001 From: acoto87 Date: Mon, 8 Apr 2019 21:06:01 -0500 Subject: [PATCH 257/292] - separating struct types into `types-struct.h` - vec3s implementation - fix style issues --- include/cglm/cglms.h | 2 + include/cglm/structs/vec3-ext.h | 100 ++++++++ include/cglm/structs/vec3.h | 398 ++++++++++++++++++++++++++++++++ include/cglm/structs/vec4-ext.h | 48 ++-- include/cglm/structs/vec4.h | 96 +++----- include/cglm/types-struct.h | 36 +++ include/cglm/types.h | 25 -- test/src/test_common.c | 14 ++ test/src/test_common.h | 6 + test/src/test_vec3.c | 9 + 10 files changed, 617 insertions(+), 117 deletions(-) create mode 100644 include/cglm/structs/vec3-ext.h create mode 100644 include/cglm/structs/vec3.h create mode 100644 include/cglm/types-struct.h diff --git a/include/cglm/cglms.h b/include/cglm/cglms.h index 4dd471f..9f00dc8 100644 --- a/include/cglm/cglms.h +++ b/include/cglm/cglms.h @@ -12,6 +12,8 @@ extern "C" { #endif #include "cglm.h" +#include "types-struct.h" +#include "structs/vec3.h" #include "structs/vec4.h" #ifdef __cplusplus diff --git a/include/cglm/structs/vec3-ext.h b/include/cglm/structs/vec3-ext.h new file mode 100644 index 0000000..0449b3d --- /dev/null +++ b/include/cglm/structs/vec3-ext.h @@ -0,0 +1,100 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_vec3s_ext_h +#define cglm_vec3s_ext_h + +#include "../common.h" +#include "../types-struct.h" +#include "../util.h" +#include "../vec3-ext.h" + +CGLM_INLINE +vec3s +glms_vec3_broadcast(float val) { + vec3s r; + glm_vec3_broadcast(val, r.raw); + return r; +} + +CGLM_INLINE +bool +glms_vec3_eq(vec3s v, float val) { + return glm_vec3_eq(v.raw, val); +} + +CGLM_INLINE +bool +glms_vec3_eq_eps(vec3s v, float val) { + return glm_vec3_eq_eps(v.raw, val); +} + +CGLM_INLINE +bool +glms_vec3_eq_all(vec3s v) { + return glm_vec3_eq_all(v.raw); +} + +CGLM_INLINE +bool +glms_vec3_eqv(vec3s a, vec3s b) { + return glm_vec3_eqv(a.raw, b.raw); +} + +CGLM_INLINE +bool +glms_vec3_eqv_eps(vec3s a, vec3s b) { + return glm_vec3_eqv_eps(a.raw, b.raw); +} + +CGLM_INLINE +float +glms_vec3_max(vec3s v) { + return glm_vec3_max(v.raw); +} + +CGLM_INLINE +float +glms_vec3_min(vec3s v) { + return glm_vec3_min(v.raw); +} + +CGLM_INLINE +bool +glms_vec3_isnan(vec3s v) { + return glm_vec3_isnan(v.raw); +} + +CGLM_INLINE +bool +glms_vec3_isinf(vec3s v) { + return glm_vec3_isinf(v.raw); +} + +CGLM_INLINE +bool +glms_vec3_isvalid(vec3s v) { + return glm_vec3_isvalid(v.raw); +} + +CGLM_INLINE +vec3s +glms_vec3_sign(vec3s v) { + vec3s r; + glm_vec3_sign(v.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_sqrt(vec3s v) { + vec3s r; + glm_vec3_sqrt(v.raw, r.raw); + return r; +} + +#endif /* cglm_vec3s_ext_h */ diff --git a/include/cglm/structs/vec3.h b/include/cglm/structs/vec3.h new file mode 100644 index 0000000..ed77c4a --- /dev/null +++ b/include/cglm/structs/vec3.h @@ -0,0 +1,398 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_vec3s_h +#define cglm_vec3s_h + +#include "../common.h" +#include "../types-struct.h" +#include "../util.h" +#include "../vec3.h" +#include "vec3-ext.h" + +#define GLMS_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f} +#define GLMS_VEC3_ZERO_INIT {0.0f, 0.0f, 0.0f} + +#define GLMS_VEC3_ONE ((vec3s)GLMS_VEC3_ONE_INIT) +#define GLMS_VEC3_ZERO ((vec3s)GLMS_VEC3_ZERO_INIT) + +#define GLMS_YUP ((vec3s){0.0f, 1.0f, 0.0f}) +#define GLMS_ZUP ((vec3s){0.0f, 0.0f, 1.0f}) +#define GLMS_XUP ((vec3s){1.0f, 0.0f, 0.0f}) + +CGLM_INLINE +vec3s +glms_vec3(vec4s v4) { + vec3s r; + glm_vec3(v4.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_copy(vec3s v) { + vec3s r; + glm_vec3_copy(v.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_zero() { + vec3s r; + glm_vec3_zero(r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_one() { + vec3s r; + glm_vec3_one(r.raw); + return r; +} + +CGLM_INLINE +float +glms_vec3_dot(vec3s a, vec3s b) { + return glm_vec3_dot(a.raw, b.raw); +} + +CGLM_INLINE +float +glms_vec3_norm2(vec3s v) { + glm_vec3_norm2(v.raw); +} + +CGLM_INLINE +float +glms_vec3_norm(vec3s v) { + glm_vec3_norm(v.raw); +} + +CGLM_INLINE +vec3s +glms_vec3_add(vec3s a, vec3s b) { + vec3s r; + glm_vec3_add(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_adds(vec3s a, float s) { + vec3s r; + glm_vec3_adds(a.raw, s, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_sub(vec3s a, vec3s b) { + vec3s r; + glm_vec3_sub(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_subs(vec3s a, float s) { + vec3s r; + glm_vec3_subs(a.raw, s, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_mul(vec3s a, vec3s b) { + vec3s r; + glm_vec3_mul(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_scale(vec3s v, float s) { + vec3s r; + glm_vec3_scale(v.raw, s, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_scale_as(vec3s v, float s) { + vec3s r; + glm_vec3_scale_as(v.raw, s, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_div(vec3s a, vec3s b) { + vec3s r; + glm_vec3_div(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_divs(vec3s a, float s) { + vec3s r; + glm_vec3_divs(a.raw, s, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_addadd(vec3s a, vec3s b) { + vec3s r; + glm_vec3_addadd(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_subadd(vec3s a, vec3s b) { + vec3s r; + glm_vec3_subadd(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_muladd(vec3s a, vec3s b) { + vec3s r; + glm_vec3_muladd(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_muladds(vec3s a, float s) { + vec3s r; + glm_vec3_muladds(a.raw, s, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_maxadd(vec3s a, vec3s b) { + vec3s r; + glm_vec3_maxadd(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_minadd(vec3s a, vec3s b) { + vec3s r; + glm_vec3_minadd(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_flipsign(vec3s v) { + glm_vec3_flipsign(v.raw); + return v; +} + +CGLM_INLINE +vec3s +glms_vec3_flipsign_to(vec3s v) { + vec3s r; + glm_vec3_flipsign_to(v.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_negate_to(vec3s v) { + vec3s r; + glm_vec3_negate_to(v.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_negate(vec3s v) { + glm_vec3_negate(v.raw); + return v; +} + +CGLM_INLINE +vec3s +glms_vec3_inv(vec3s v) { + glm_vec3_inv(v.raw); + return v; +} + +CGLM_INLINE +vec3s +glms_vec3_inv_to(vec3s v) { + vec3s r; + glm_vec3_inv_to(v.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_normalize(vec3s v) { + glm_vec3_normalize(v.raw); + return v; +} + +CGLM_INLINE +vec3s +glms_vec3_normalize_to(vec3s v) { + vec3s r; + glm_vec3_normalize_to(v.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_cross(vec3s a, vec3s b) { + vec3s r; + glm_vec3_cross(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_crossn(vec3s a, vec3s b) { + vec3s r; + glm_vec3_crossn(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +float +glms_vec3_distance(vec3s a, vec3s b) { + return glm_vec3_distance(a.raw, b.raw); +} + +CGLM_INLINE +float +glms_vec3_angle(vec3s a, vec3s b) { + return glm_vec3_angle(a.raw, b.raw); +} + +CGLM_INLINE +vec3s +glms_vec3_rotate(vec3s v, float angle, vec3s axis) { + glm_vec3_rotate(v.raw, angle, axis.raw); + return v; +} + +CGLM_INLINE +vec3s +glms_vec3_rotate_m4(mat4 m, vec3s v) { + vec3s r; + glm_vec3_rotate_m4(m, v.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_rotate_m3(mat3 m, vec3s v) { + vec3s r; + glm_vec3_rotate_m3(m, v.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_proj(vec3s a, vec3s b) { + vec3s r; + glm_vec3_proj(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_center(vec3s a, vec3s b) { + vec3s r; + glm_vec3_center(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +float +glms_vec3_distance2(vec3s a, vec3s b) { + return glm_vec3_distance2(a.raw, b.raw); +} + +CGLM_INLINE +vec3s +glms_vec3_maxv(vec3s a, vec3s b) { + vec3s r; + glm_vec3_maxv(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_minv(vec3s a, vec3s b) { + vec3s r; + glm_vec3_minv(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_ortho(vec3s v) { + vec3s r; + glm_vec3_ortho(v.raw, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_vec3_clamp(vec3s v, float minVal, float maxVal) { + glm_vec3_clamp(v.raw, minVal, maxVal); + return v; +} + +CGLM_INLINE +vec3s +glms_vec3_lerp(vec3s from, vec3s to, float t) { + vec3s r; + glm_vec3_lerp(from.raw, to.raw, t, r.raw); + return r; +} + +CGLM_INLINE +vec3s +glms_cross(vec3s a, vec3s b) { + vec3s r; + glm_cross(a.raw, b.raw, r.raw); + return r; +} + +CGLM_INLINE +float +glms_dot(vec3s a, vec3s b) { + return glm_dot(a.raw, b.raw); +} + +CGLM_INLINE +vec3s +glms_normalize(vec3s v) { + glm_normalize(v.raw); + return v; +} + +CGLM_INLINE +vec3s +glms_normalize_to(vec3s v) { + vec3s r; + glm_normalize_to(v.raw, r.raw); + return r; +} + +#endif /* cglm_vec3s_h */ diff --git a/include/cglm/structs/vec4-ext.h b/include/cglm/structs/vec4-ext.h index ea84e82..4fbb2d3 100644 --- a/include/cglm/structs/vec4-ext.h +++ b/include/cglm/structs/vec4-ext.h @@ -8,16 +8,14 @@ #ifndef cglm_vec4s_ext_h #define cglm_vec4s_ext_h -#include "common.h" -#include "vec3-ext.h" -#include -#include -#include +#include "../common.h" +#include "../types-struct.h" +#include "../util.h" +#include "../vec4-ext.h" CGLM_INLINE vec4s -glms_vec4_broadcast(float val, vec4 d) -{ +glms_vec4_broadcast(float val) { vec4s r; glm_vec4_broadcast(val, r.raw); return r; @@ -25,78 +23,67 @@ glms_vec4_broadcast(float val, vec4 d) CGLM_INLINE bool -glms_vec4_eq(vec4s v, float val) -{ +glms_vec4_eq(vec4s v, float val) { return glm_vec4_eq(v.raw, val); } CGLM_INLINE bool -glms_vec4_eq_eps(vec4 v, float val) -{ +glms_vec4_eq_eps(vec4s v, float val) { return glm_vec4_eq_eps(v.raw, val); } CGLM_INLINE bool -glms_vec4_eq_all(vec4s v) -{ +glms_vec4_eq_all(vec4s v) { return glm_vec4_eq_all(v.raw); } CGLM_INLINE bool -glms_vec4_eqv(vec4s a, vec4s b) -{ +glms_vec4_eqv(vec4s a, vec4s b) { return glm_vec4_eqv(a.raw, b.raw); } CGLM_INLINE bool -glms_vec4_eqv_eps(vec4s a, vec4s b) -{ +glms_vec4_eqv_eps(vec4s a, vec4s b) { return glm_vec4_eqv_eps(a.raw, b.raw); } CGLM_INLINE float -glms_vec4_max(vec4s v) -{ +glms_vec4_max(vec4s v) { return glm_vec4_max(v.raw); } CGLM_INLINE float -glms_vec4_min(vec4s v) -{ +glms_vec4_min(vec4s v) { return glm_vec4_min(v.raw); } CGLM_INLINE bool -glms_vec4_isnan(vec4s v) -{ +glms_vec4_isnan(vec4s v) { return glm_vec4_isnan(v.raw); } CGLM_INLINE bool -glms_vec4_isinf(vec4s v) -{ +glms_vec4_isinf(vec4s v) { return glm_vec4_isinf(v.raw); } CGLM_INLINE bool -glms_vec4_isvalid(vec4s v) -{ +glms_vec4_isvalid(vec4s v) { return glm_vec4_isvalid(v.raw); } CGLM_INLINE vec4s -glms_vec4_sign(vec4s v) -{ +glms_vec4_sign(vec4s v) { vec4s r; glm_vec4_sign(v.raw, r.raw); return r; @@ -104,8 +91,7 @@ glms_vec4_sign(vec4s v) CGLM_INLINE vec4s -glms_vec4_sqrt(vec4s v) -{ +glms_vec4_sqrt(vec4s v) { vec4s r; glm_vec4_sqrt(v.raw, r.raw); return r; diff --git a/include/cglm/structs/vec4.h b/include/cglm/structs/vec4.h index b68bb33..c0a79c3 100644 --- a/include/cglm/structs/vec4.h +++ b/include/cglm/structs/vec4.h @@ -12,7 +12,11 @@ extern "C" { #endif -#include "../cglm.h" +#include "../common.h" +#include "../types-struct.h" +#include "../util.h" +#include "../vec4.h" +#include "vec4-ext.h" #define GLMS_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f} #define GLMS_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f} @@ -24,8 +28,7 @@ extern "C" { CGLM_INLINE vec4s -glms_vec4(vec3s v3, float last) -{ +glms_vec4(vec3s v3, float last) { vec4s r; glm_vec4(v3.raw, last, r.raw); return r; @@ -33,8 +36,7 @@ glms_vec4(vec3s v3, float last) CGLM_INLINE vec3s -glms_vec4_copy3(vec4s v) -{ +glms_vec4_copy3(vec4s v) { vec3s r; glm_vec4_copy3(v.raw, r.raw); return r; @@ -42,8 +44,7 @@ glms_vec4_copy3(vec4s v) CGLM_INLINE vec4s -glms_vec4_copy(vec4s v) -{ +glms_vec4_copy(vec4s v) { vec4s r; glm_vec4_copy(v.raw, r.raw); return r; @@ -51,8 +52,7 @@ glms_vec4_copy(vec4s v) CGLM_INLINE vec4s -glms_vec4_ucopy(vec4s v) -{ +glms_vec4_ucopy(vec4s v) { vec4s r; glm_vec4_ucopy(v.raw, r.raw); return r; @@ -61,29 +61,25 @@ glms_vec4_ucopy(vec4s v) CGLM_INLINE float -glms_vec4_dot(vec4s a, vec4s b) -{ +glms_vec4_dot(vec4s a, vec4s b) { return glm_vec4_dot(a.raw, b.raw); } CGLM_INLINE float -glms_vec4_norm2(vec4s v) -{ +glms_vec4_norm2(vec4s v) { return glm_vec4_norm2(v.raw); } CGLM_INLINE float -glms_vec4_norm(vec4s v) -{ +glms_vec4_norm(vec4s v) { return glm_vec4_norm(v.raw); } CGLM_INLINE vec4s -glms_vec4_add(vec4s a, vec4s b) -{ +glms_vec4_add(vec4s a, vec4s b) { vec4s r; glm_vec4_add(a.raw, b.raw, r.raw); return r; @@ -91,8 +87,7 @@ glms_vec4_add(vec4s a, vec4s b) CGLM_INLINE vec4s -glms_vec4_adds(vec4s v, float s) -{ +glms_vec4_adds(vec4s v, float s) { vec4s r; glm_vec4_adds(v.raw, s, r.raw); return r; @@ -100,8 +95,7 @@ glms_vec4_adds(vec4s v, float s) CGLM_INLINE vec4s -glms_vec4_sub(vec4s a, vec4s b) -{ +glms_vec4_sub(vec4s a, vec4s b) { vec4s r; glm_vec4_sub(a.raw, b.raw, r.raw); return r; @@ -109,8 +103,7 @@ glms_vec4_sub(vec4s a, vec4s b) CGLM_INLINE vec4s -glms_vec4_subs(vec4s v, float s) -{ +glms_vec4_subs(vec4s v, float s) { vec4s r; glm_vec4_subs(v.raw, s, r.raw); return r; @@ -118,8 +111,7 @@ glms_vec4_subs(vec4s v, float s) CGLM_INLINE vec4s -glms_vec4_mul(vec4s a, vec4s b) -{ +glms_vec4_mul(vec4s a, vec4s b) { vec4s r; glm_vec4_mul(a.raw, b.raw, r.raw); return r; @@ -127,8 +119,7 @@ glms_vec4_mul(vec4s a, vec4s b) CGLM_INLINE vec4s -glms_vec4_scale(vec4s v, float s) -{ +glms_vec4_scale(vec4s v, float s) { vec4s r; glm_vec4_scale(v.raw, s, r.raw); return r; @@ -136,8 +127,7 @@ glms_vec4_scale(vec4s v, float s) CGLM_INLINE vec4s -glms_vec4_scale_as(vec4s v, float s) -{ +glms_vec4_scale_as(vec4s v, float s) { vec4s r; glm_vec4_scale_as(v.raw, s, r.raw); return r; @@ -145,8 +135,7 @@ glms_vec4_scale_as(vec4s v, float s) CGLM_INLINE vec4s -glms_vec4_div(vec4s a, vec4s b) -{ +glms_vec4_div(vec4s a, vec4s b) { vec4s r; glm_vec4_div(a.raw, b.raw, r.raw); return r; @@ -154,8 +143,7 @@ glms_vec4_div(vec4s a, vec4s b) CGLM_INLINE vec4s -glms_vec4_divs(vec4s v, float s) -{ +glms_vec4_divs(vec4s v, float s) { vec4s r; glm_vec4_divs(v.raw, s, r.raw); return r; @@ -163,8 +151,7 @@ glms_vec4_divs(vec4s v, float s) CGLM_INLINE vec4s -glms_vec4_addadd(vec4s a, vec4s b) -{ +glms_vec4_addadd(vec4s a, vec4s b) { vec4s r; glm_vec4_addadd(a.raw, b.raw, r.raw); return r; @@ -172,8 +159,7 @@ glms_vec4_addadd(vec4s a, vec4s b) CGLM_INLINE vec4s -glms_vec4_subadd(vec4s a, vec4s b) -{ +glms_vec4_subadd(vec4s a, vec4s b) { vec4s r; glm_vec4_subadd(a.raw, b.raw, r.raw); return r; @@ -181,8 +167,7 @@ glms_vec4_subadd(vec4s a, vec4s b) CGLM_INLINE vec4s -glms_vec4_muladd(vec4s a, vec4s b) -{ +glms_vec4_muladd(vec4s a, vec4s b) { vec4s r; glm_vec4_muladd(a.raw, b.raw, r.raw); return r; @@ -190,8 +175,7 @@ glms_vec4_muladd(vec4s a, vec4s b) CGLM_INLINE vec4s -glms_vec4_muladds(vec4s a, float s) -{ +glms_vec4_muladds(vec4s a, float s) { vec4s r; glm_vec4_muladds(a.raw, s, r.raw); return r; @@ -199,8 +183,7 @@ glms_vec4_muladds(vec4s a, float s) CGLM_INLINE vec4s -glms_vec4_maxadd(vec4s a, vec4s b) -{ +glms_vec4_maxadd(vec4s a, vec4s b) { vec4s r; glm_vec4_maxadd(a.raw, b.raw, r.raw); return r; @@ -208,8 +191,7 @@ glms_vec4_maxadd(vec4s a, vec4s b) CGLM_INLINE vec4s -glms_vec4_minadd(vec4s a, vec4s b) -{ +glms_vec4_minadd(vec4s a, vec4s b) { vec4s r; glm_vec4_minadd(a.raw, b.raw, r.raw); return r; @@ -217,39 +199,34 @@ glms_vec4_minadd(vec4s a, vec4s b) CGLM_INLINE vec4s -glms_vec4_negate(vec4s v) -{ +glms_vec4_negate(vec4s v) { glm_vec4_negate(v.raw); return v; } CGLM_INLINE vec4s -glms_vec4_inv(vec4s v) -{ +glms_vec4_inv(vec4s v) { glm_vec4_inv(v.raw); return v; } CGLM_INLINE vec4s -glms_vec4_normalize(vec4s v) -{ +glms_vec4_normalize(vec4s v) { glm_vec4_normalize(v.raw); return v; } CGLM_INLINE float -glms_vec4_distance(vec4s a, vec4s b) -{ +glms_vec4_distance(vec4s a, vec4s b) { return glm_vec4_distance(a.raw, b.raw); } CGLM_INLINE vec4s -glms_vec4_maxv(vec4s a, vec4s b) -{ +glms_vec4_maxv(vec4s a, vec4s b) { vec4s r; glm_vec4_maxv(a.raw, b.raw, r.raw); return r; @@ -257,8 +234,7 @@ glms_vec4_maxv(vec4s a, vec4s b) CGLM_INLINE vec4s -glms_vec4_minv(vec4s a, vec4s b) -{ +glms_vec4_minv(vec4s a, vec4s b) { vec4s r; glm_vec4_minv(a.raw, b.raw, r.raw); return r; @@ -266,16 +242,14 @@ glms_vec4_minv(vec4s a, vec4s b) CGLM_INLINE vec4s -glms_vec4_clamp(vec4s v, float minVal, float maxVal) -{ +glms_vec4_clamp(vec4s v, float minVal, float maxVal) { glm_vec4_clamp(v.raw, minVal, maxVal); return v; } CGLM_INLINE vec4s -glms_vec4_lerp(vec4s from, vec4s to, float t) -{ +glms_vec4_lerp(vec4s from, vec4s to, float t) { vec4s r; glm_vec4_lerp(from.raw, to.raw, t, r.raw); return r; diff --git a/include/cglm/types-struct.h b/include/cglm/types-struct.h new file mode 100644 index 0000000..27e04fe --- /dev/null +++ b/include/cglm/types-struct.h @@ -0,0 +1,36 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_types_struct_h +#define cglm_types_struct_h + +#include "types.h" + +typedef union CGLM_ALIGN_IF(16) vec3s { +#ifndef CGLM_NO_ANONYMOUS_STRUCT + struct { + float x; + float y; + float z; + }; +#endif + vec3 raw; +} vec3s; + +typedef union CGLM_ALIGN_IF(16) vec4s { +#ifndef CGLM_NO_ANONYMOUS_STRUCT + struct { + float x; + float y; + float z; + float w; + }; +#endif + vec4 raw; +} vec4s; + +#endif /* cglm_types_struct_h */ diff --git a/include/cglm/types.h b/include/cglm/types.h index 69c2885..1190b73 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -32,7 +32,6 @@ # define CGLM_ALIGN_MAT CGLM_ALIGN(16) #endif -// array types typedef float vec2[2]; typedef float vec3[3]; typedef int ivec3[3]; @@ -46,30 +45,6 @@ typedef CGLM_ALIGN_IF(32) vec4 mat4[4]; typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; #endif -// struct types -typedef union CGLM_ALIGN_IF(16) vec3s { -#ifndef CGLM_NO_ANONYMOUS_STRUCT - struct { - float x; - float y; - float z; - }; -#endif - vec3 raw; -} vec3s; - -typedef union CGLM_ALIGN_IF(16) vec4s { -#ifndef CGLM_NO_ANONYMOUS_STRUCT - struct { - float x; - float y; - float z; - float w; - }; -#endif - vec4 raw; -} vec4s; - #define GLM_E 2.71828182845904523536028747135266250 /* e */ #define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */ #define GLM_LOG10E 0.434294481903251827651128918916605082 /* log10(e) */ diff --git a/test/src/test_common.c b/test/src/test_common.c index 94331f4..f835235 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -47,6 +47,14 @@ test_rand_vec3(vec3 dest) { dest[2] = drand48(); } +vec3s +test_rand_vec3s() +{ + vec3s r; + test_rand_vec3(r.raw); + return r; +} + void test_rand_vec4(vec4 dest) { srand((unsigned int)time(NULL)); @@ -127,6 +135,12 @@ test_assert_vec3_eq(vec3 v1, vec3 v2) { assert_true(fabsf(v1[2] - v2[2]) <= 0.000009); } +void +test_assert_vec3s_eq(vec3s v1, vec3s v2) +{ + test_assert_vec3_eq(v1.raw, v2.raw); +} + void test_assert_vec4_eq(vec4 v1, vec4 v2) { assert_true(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ diff --git a/test/src/test_common.h b/test/src/test_common.h index c6a2dc4..51d1826 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -44,6 +44,9 @@ test_assert_mat3_eq(mat3 m1, mat3 m2); void test_assert_vec3_eq(vec3 v1, vec3 v2); +void +test_assert_vec3s_eq(vec3s v1, vec3s v2); + void test_assert_vec4_eq(vec4 v1, vec4 v2); @@ -59,6 +62,9 @@ test_assert_quat_eq_abs(versor v1, versor v2); void test_rand_vec3(vec3 dest); +vec3s +test_rand_vec3s(); + void test_rand_vec4(vec4 dest); diff --git a/test/src/test_vec3.c b/test/src/test_vec3.c index 6cfc593..4f1f2d1 100644 --- a/test/src/test_vec3.c +++ b/test/src/test_vec3.c @@ -12,6 +12,7 @@ test_vec3(void **state) { mat3 rot1m3; mat4 rot1; vec3 v, v1, v2; + vec3s vs1, vs2, vs3, vs4; /* test zero */ glm_vec3_zero(v); @@ -75,4 +76,12 @@ test_vec3(void **state) { test_assert_vec3_eq(v1, v2); test_assert_vec3_eq(v1, GLM_ZUP); + + /* structs */ + vs1 = test_rand_vec3s(); + vs2 = test_rand_vec3s(); + + vs3 = glms_vec3_add(vs1, vs2); + vs4 = glms_vec3_maxv(vs1, vs3); + test_assert_vec3s_eq(vs3, vs4); } From 8f2f2c55728ef8cf657eb62ac976d64275e3d7ca Mon Sep 17 00:00:00 2001 From: Wasin Thonkaew Date: Fri, 19 Apr 2019 01:47:50 +0800 Subject: [PATCH 258/292] Fix to use armv7 compatible function for glm_vec4_distance Before it used armv8 only function thus it leads to build failed for Android with target of armv7 i.e. armeabi-v7a. This fixed that issue. --- include/cglm/vec4.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index b94cf61..2b62c1b 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -697,11 +697,7 @@ glm_vec4_distance(vec4 a, vec4 b) { return _mm_cvtss_f32(_mm_sqrt_ss(_mm_add_ss(x0, glmm_shuff1(x0, 0, 1, 0, 1)))); #elif defined(CGLM_NEON_FP) - float32x4_t v0; - float32_t r; - v0 = vsubq_f32(vld1q_f32(a), vld1q_f32(b)); - r = vaddvq_f32(vmulq_f32(v0, v0)); - return sqrtf(r); + return glmm_norm(vsubq_f32(glmm_load(a), glmm_load(b))); #else return sqrtf(glm_pow2(b[0] - a[0]) + glm_pow2(b[1] - a[1]) From 461a4009badb0afff795c5e693c0887d5c69b5c5 Mon Sep 17 00:00:00 2001 From: Wasin Thonkaew Date: Fri, 19 Apr 2019 02:07:57 +0800 Subject: [PATCH 259/292] refactor vec4 : glm_vec4_distance for SSE/SSE2 According to suggestion by recp at https://github.com/recp/cglm/issues/82#issuecomment-483051704. --- include/cglm/vec4.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 2b62c1b..d053ed5 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -690,12 +690,7 @@ CGLM_INLINE float glm_vec4_distance(vec4 a, vec4 b) { #if defined( __SSE__ ) || defined( __SSE2__ ) - __m128 x0; - x0 = _mm_sub_ps(glmm_load(b), glmm_load(a)); - x0 = _mm_mul_ps(x0, x0); - x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 3, 2)); - return _mm_cvtss_f32(_mm_sqrt_ss(_mm_add_ss(x0, - glmm_shuff1(x0, 0, 1, 0, 1)))); + return glmm_norm(_mm_sub_ps(glmm_load(b), glmm_load(a))); #elif defined(CGLM_NEON_FP) return glmm_norm(vsubq_f32(glmm_load(a), glmm_load(b))); #else From 5b80e0e3c22af24c19c44c403b4476d2909c12e0 Mon Sep 17 00:00:00 2001 From: Wasin Thonkaew Date: Fri, 19 Apr 2019 03:04:00 +0800 Subject: [PATCH 260/292] test cases for glm_vec4_distance --- test/src/test_common.c | 1 + test/src/test_vec4.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/test/src/test_common.c b/test/src/test_common.c index d41d3cb..0afc235 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -5,6 +5,7 @@ #include "test_common.h" #include +#include #define m 4 #define n 4 diff --git a/test/src/test_vec4.c b/test/src/test_vec4.c index 8e4fda5..daf4e00 100644 --- a/test/src/test_vec4.c +++ b/test/src/test_vec4.c @@ -93,6 +93,13 @@ test_vec4(void **state) { /* 3. test SIMD norm2 */ test_rand_vec4(v); test_assert_eqf(test_vec4_norm2(v), glm_vec4_norm2(v)); + + /* 4. test SSE/SIMD distance */ + test_rand_vec4(v1); + test_rand_vec4(v2); + d1 = glm_vec4_distance(v1, v2); + d2 = sqrtf(powf(v1[0]-v2[0], 2.0f) + pow(v1[1]-v2[1], 2.0f) + pow(v1[2]-v2[2], 2.0f) + pow(v1[3]-v2[3], 2.0f)); + assert_true(fabsf(d1 - d2) <= 0.000009); } /* test zero */ From d85b5234a9703c81b823348fb44fddd21fafa13c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 21 Apr 2019 00:19:17 +0300 Subject: [PATCH 261/292] ci: print test logs after failure --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index c2c0c84..9f2a546 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,3 +57,6 @@ after_success: --gcov-options '\-lp' --verbose; fi + +after_failure: + - cat ./test-suite.log From 73e6b65da08b210401e9e24f923f7627e7c94ceb Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 27 Apr 2019 09:36:15 +0300 Subject: [PATCH 262/292] test: fix comparing floats in bezier tests --- test/src/test_bezier.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/src/test_bezier.c b/test/src/test_bezier.c index bd7c796..1c7bb11 100644 --- a/test/src/test_bezier.c +++ b/test/src/test_bezier.c @@ -51,8 +51,8 @@ test_bezier(void **state) { Bs_plain = test_bezier_plain(s, p0, c0, c1, p1); assert_true(glm_eq(Bs, Bs_plain)); - assert_true(glm_eq(smc, Bs_plain)); - assert_true(glm_eq(Bs, smc)); + test_assert_eqf(smc, Bs_plain); + test_assert_eqf(Bs, smc); /* test cubic hermite */ smc = glm_smc(s, GLM_HERMITE_MAT, (vec4){p0, p1, c0, c1}); From 6ed275734b4c6a6de595c6eccc2cc9c6fa4c70c6 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 28 Apr 2019 12:15:43 +0300 Subject: [PATCH 263/292] mark readonly parameters as const --- include/cglm/affine-mat.h | 4 +- include/cglm/affine.h | 36 +++++++-------- include/cglm/box.h | 37 ++++++++-------- include/cglm/cam.h | 18 ++++---- include/cglm/color.h | 2 +- include/cglm/curve.h | 2 +- include/cglm/euler.h | 20 ++++----- include/cglm/frustum.h | 16 +++---- include/cglm/mat4.h | 38 ++++++++-------- include/cglm/project.h | 6 +-- include/cglm/quat.h | 70 +++++++++++++++-------------- include/cglm/simd/avx/affine.h | 2 +- include/cglm/simd/avx/mat4.h | 2 +- include/cglm/simd/neon/mat4.h | 2 +- include/cglm/simd/sse2/affine.h | 4 +- include/cglm/simd/sse2/mat3.h | 2 +- include/cglm/simd/sse2/mat4.h | 12 ++--- include/cglm/simd/sse2/quat.h | 2 +- include/cglm/simd/x86.h | 4 +- include/cglm/sphere.h | 10 ++--- include/cglm/vec3-ext.h | 24 +++++----- include/cglm/vec3.h | 78 ++++++++++++++++----------------- include/cglm/vec4-ext.h | 24 +++++----- include/cglm/vec4.h | 56 +++++++++++------------ 24 files changed, 237 insertions(+), 234 deletions(-) diff --git a/include/cglm/affine-mat.h b/include/cglm/affine-mat.h index f58749b..9d78633 100644 --- a/include/cglm/affine-mat.h +++ b/include/cglm/affine-mat.h @@ -44,7 +44,7 @@ */ CGLM_INLINE void -glm_mul(mat4 m1, mat4 m2, mat4 dest) { +glm_mul(const mat4 m1, const mat4 m2, mat4 dest) { #ifdef __AVX__ glm_mul_avx(m1, m2, dest); #elif defined( __SSE__ ) || defined( __SSE2__ ) @@ -100,7 +100,7 @@ glm_mul(mat4 m1, mat4 m2, mat4 dest) { */ CGLM_INLINE void -glm_mul_rot(mat4 m1, mat4 m2, mat4 dest) { +glm_mul_rot(const mat4 m1, const mat4 m2, mat4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mul_rot_sse2(m1, m2, dest); #else diff --git a/include/cglm/affine.h b/include/cglm/affine.h index 84ead4b..af567b6 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -42,7 +42,7 @@ CGLM_INLINE void -glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest); +glm_mat4_mul(const mat4 m1, const mat4 m2, mat4 dest); /*! * @brief translate existing transform matrix by v vector @@ -53,7 +53,7 @@ glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest); */ CGLM_INLINE void -glm_translate(mat4 m, vec3 v) { +glm_translate(mat4 m, const vec3 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(m[3], _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_load(m[0]), @@ -89,7 +89,7 @@ glm_translate(mat4 m, vec3 v) { */ CGLM_INLINE void -glm_translate_to(mat4 m, vec3 v, mat4 dest) { +glm_translate_to(const mat4 m, const vec3 v, mat4 dest) { glm_mat4_copy(m, dest); glm_translate(dest, v); } @@ -168,7 +168,7 @@ glm_translate_z(mat4 m, float z) { */ CGLM_INLINE void -glm_translate_make(mat4 m, vec3 v) { +glm_translate_make(mat4 m, const vec3 v) { glm_mat4_identity(m); glm_vec3_copy(v, m[3]); } @@ -183,7 +183,7 @@ glm_translate_make(mat4 m, vec3 v) { */ CGLM_INLINE void -glm_scale_to(mat4 m, vec3 v, mat4 dest) { +glm_scale_to(const mat4 m, const vec3 v, mat4 dest) { glm_vec4_scale(m[0], v[0], dest[0]); glm_vec4_scale(m[1], v[1], dest[1]); glm_vec4_scale(m[2], v[2], dest[2]); @@ -199,7 +199,7 @@ glm_scale_to(mat4 m, vec3 v, mat4 dest) { */ CGLM_INLINE void -glm_scale_make(mat4 m, vec3 v) { +glm_scale_make(mat4 m, const vec3 v) { glm_mat4_identity(m); m[0][0] = v[0]; m[1][1] = v[1]; @@ -215,7 +215,7 @@ glm_scale_make(mat4 m, vec3 v) { */ CGLM_INLINE void -glm_scale(mat4 m, vec3 v) { +glm_scale(mat4 m, const vec3 v) { glm_scale_to(m, v, m); } @@ -243,7 +243,7 @@ glm_scale_uni(mat4 m, float s) { */ CGLM_INLINE void -glm_rotate_x(mat4 m, float angle, mat4 dest) { +glm_rotate_x(const mat4 m, float angle, mat4 dest) { CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; @@ -268,7 +268,7 @@ glm_rotate_x(mat4 m, float angle, mat4 dest) { */ CGLM_INLINE void -glm_rotate_y(mat4 m, float angle, mat4 dest) { +glm_rotate_y(const mat4 m, float angle, mat4 dest) { CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; @@ -293,7 +293,7 @@ glm_rotate_y(mat4 m, float angle, mat4 dest) { */ CGLM_INLINE void -glm_rotate_z(mat4 m, float angle, mat4 dest) { +glm_rotate_z(const mat4 m, float angle, mat4 dest) { CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; @@ -319,7 +319,7 @@ glm_rotate_z(mat4 m, float angle, mat4 dest) { */ CGLM_INLINE void -glm_rotate_make(mat4 m, float angle, vec3 axis) { +glm_rotate_make(mat4 m, float angle, const vec3 axis) { CGLM_ALIGN(8) vec3 axisn, v, vs; float c; @@ -350,7 +350,7 @@ glm_rotate_make(mat4 m, float angle, vec3 axis) { */ CGLM_INLINE void -glm_rotate(mat4 m, float angle, vec3 axis) { +glm_rotate(mat4 m, float angle, const vec3 axis) { CGLM_ALIGN_MAT mat4 rot; glm_rotate_make(rot, angle, axis); glm_mul_rot(m, rot, m); @@ -367,7 +367,7 @@ glm_rotate(mat4 m, float angle, vec3 axis) { */ CGLM_INLINE void -glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) { +glm_rotate_at(mat4 m, const vec3 pivot, float angle, const vec3 axis) { CGLM_ALIGN(8) vec3 pivotInv; glm_vec3_negate_to(pivot, pivotInv); @@ -392,7 +392,7 @@ glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) { */ CGLM_INLINE void -glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) { +glm_rotate_atm(mat4 m, const vec3 pivot, float angle, const vec3 axis) { CGLM_ALIGN(8) vec3 pivotInv; glm_vec3_negate_to(pivot, pivotInv); @@ -410,7 +410,7 @@ glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) { */ CGLM_INLINE void -glm_decompose_scalev(mat4 m, vec3 s) { +glm_decompose_scalev(const mat4 m, vec3 s) { s[0] = glm_vec3_norm(m[0]); s[1] = glm_vec3_norm(m[1]); s[2] = glm_vec3_norm(m[2]); @@ -426,7 +426,7 @@ glm_decompose_scalev(mat4 m, vec3 s) { */ CGLM_INLINE bool -glm_uniscaled(mat4 m) { +glm_uniscaled(const mat4 m) { CGLM_ALIGN(8) vec3 s; glm_decompose_scalev(m, s); return glm_vec3_eq_all(s); @@ -442,7 +442,7 @@ glm_uniscaled(mat4 m) { */ CGLM_INLINE void -glm_decompose_rs(mat4 m, mat4 r, vec3 s) { +glm_decompose_rs(const mat4 m, mat4 r, vec3 s) { CGLM_ALIGN(16) vec4 t = {0.0f, 0.0f, 0.0f, 1.0f}; CGLM_ALIGN(8) vec3 v; @@ -482,7 +482,7 @@ glm_decompose_rs(mat4 m, mat4 r, vec3 s) { */ CGLM_INLINE void -glm_decompose(mat4 m, vec4 t, mat4 r, vec3 s) { +glm_decompose(const mat4 m, vec4 t, mat4 r, vec3 s) { glm_vec4_copy(m[3], t); glm_decompose_rs(m, r, s); } diff --git a/include/cglm/box.h b/include/cglm/box.h index 2250c2a..c218602 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -22,7 +22,7 @@ */ CGLM_INLINE void -glm_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]) { +glm_aabb_transform(const vec3 box[2], const mat4 m, vec3 dest[2]) { vec3 v[2], xa, xb, ya, yb, za, zb; glm_vec3_scale(m[0], box[0][0], xa); @@ -62,7 +62,7 @@ glm_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]) { */ CGLM_INLINE void -glm_aabb_merge(vec3 box1[2], vec3 box2[2], vec3 dest[2]) { +glm_aabb_merge(const vec3 box1[2], const vec3 box2[2], vec3 dest[2]) { dest[0][0] = glm_min(box1[0][0], box2[0][0]); dest[0][1] = glm_min(box1[0][1], box2[0][1]); dest[0][2] = glm_min(box1[0][2], box2[0][2]); @@ -85,7 +85,7 @@ glm_aabb_merge(vec3 box1[2], vec3 box2[2], vec3 dest[2]) { */ CGLM_INLINE void -glm_aabb_crop(vec3 box[2], vec3 cropBox[2], vec3 dest[2]) { +glm_aabb_crop(const vec3 box[2], const vec3 cropBox[2], vec3 dest[2]) { dest[0][0] = glm_max(box[0][0], cropBox[0][0]); dest[0][1] = glm_max(box[0][1], cropBox[0][1]); dest[0][2] = glm_max(box[0][2], cropBox[0][2]); @@ -109,10 +109,10 @@ glm_aabb_crop(vec3 box[2], vec3 cropBox[2], vec3 dest[2]) { */ CGLM_INLINE void -glm_aabb_crop_until(vec3 box[2], - vec3 cropBox[2], - vec3 clampBox[2], - vec3 dest[2]) { +glm_aabb_crop_until(const vec3 box[2], + const vec3 cropBox[2], + const vec3 clampBox[2], + vec3 dest[2]) { glm_aabb_crop(box, cropBox, dest); glm_aabb_merge(clampBox, dest, dest); } @@ -133,9 +133,10 @@ glm_aabb_crop_until(vec3 box[2], */ CGLM_INLINE bool -glm_aabb_frustum(vec3 box[2], vec4 planes[6]) { - float *p, dp; - int i; +glm_aabb_frustum(const vec3 box[2], const vec4 planes[6]) { + const float *p; + float dp; + int i; for (i = 0; i < 6; i++) { p = planes[i]; @@ -169,7 +170,7 @@ glm_aabb_invalidate(vec3 box[2]) { */ CGLM_INLINE bool -glm_aabb_isvalid(vec3 box[2]) { +glm_aabb_isvalid(const vec3 box[2]) { return glm_vec3_max(box[0]) != FLT_MAX && glm_vec3_min(box[1]) != -FLT_MAX; } @@ -181,7 +182,7 @@ glm_aabb_isvalid(vec3 box[2]) { */ CGLM_INLINE float -glm_aabb_size(vec3 box[2]) { +glm_aabb_size(const vec3 box[2]) { return glm_vec3_distance(box[0], box[1]); } @@ -192,7 +193,7 @@ glm_aabb_size(vec3 box[2]) { */ CGLM_INLINE float -glm_aabb_radius(vec3 box[2]) { +glm_aabb_radius(const vec3 box[2]) { return glm_aabb_size(box) * 0.5f; } @@ -204,7 +205,7 @@ glm_aabb_radius(vec3 box[2]) { */ CGLM_INLINE void -glm_aabb_center(vec3 box[2], vec3 dest) { +glm_aabb_center(const vec3 box[2], vec3 dest) { glm_vec3_center(box[0], box[1], dest); } @@ -216,7 +217,7 @@ glm_aabb_center(vec3 box[2], vec3 dest) { */ CGLM_INLINE bool -glm_aabb_aabb(vec3 box[2], vec3 other[2]) { +glm_aabb_aabb(const vec3 box[2], const vec3 other[2]) { return (box[0][0] <= other[1][0] && box[1][0] >= other[0][0]) && (box[0][1] <= other[1][1] && box[1][1] >= other[0][1]) && (box[0][2] <= other[1][2] && box[1][2] >= other[0][2]); @@ -233,7 +234,7 @@ glm_aabb_aabb(vec3 box[2], vec3 other[2]) { */ CGLM_INLINE bool -glm_aabb_sphere(vec3 box[2], vec4 s) { +glm_aabb_sphere(const vec3 box[2], const vec4 s) { float dmin; int a, b, c; @@ -256,7 +257,7 @@ glm_aabb_sphere(vec3 box[2], vec4 s) { */ CGLM_INLINE bool -glm_aabb_point(vec3 box[2], vec3 point) { +glm_aabb_point(const vec3 box[2], const vec3 point) { return (point[0] >= box[0][0] && point[0] <= box[1][0]) && (point[1] >= box[0][1] && point[1] <= box[1][1]) && (point[2] >= box[0][2] && point[2] <= box[1][2]); @@ -270,7 +271,7 @@ glm_aabb_point(vec3 box[2], vec3 point) { */ CGLM_INLINE bool -glm_aabb_contains(vec3 box[2], vec3 other[2]) { +glm_aabb_contains(const vec3 box[2], const vec3 other[2]) { return (box[0][0] <= other[0][0] && box[1][0] >= other[1][0]) && (box[0][1] <= other[0][1] && box[1][1] >= other[1][1]) && (box[0][2] <= other[0][2] && box[1][2] >= other[1][2]); diff --git a/include/cglm/cam.h b/include/cglm/cam.h index e77b989..0e48b16 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -147,7 +147,7 @@ glm_ortho(float left, */ CGLM_INLINE void -glm_ortho_aabb(vec3 box[2], mat4 dest) { +glm_ortho_aabb(const vec3 box[2], mat4 dest) { glm_ortho(box[0][0], box[1][0], box[0][1], box[1][1], -box[1][2], -box[0][2], @@ -165,7 +165,7 @@ glm_ortho_aabb(vec3 box[2], mat4 dest) { */ CGLM_INLINE void -glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) { +glm_ortho_aabb_p(const vec3 box[2], float padding, mat4 dest) { glm_ortho(box[0][0] - padding, box[1][0] + padding, box[0][1] - padding, box[1][1] + padding, -(box[1][2] + padding), -(box[0][2] - padding), @@ -183,7 +183,7 @@ glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) { */ CGLM_INLINE void -glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) { +glm_ortho_aabb_pz(const vec3 box[2], float padding, mat4 dest) { glm_ortho(box[0][0], box[1][0], box[0][1], box[1][1], -(box[1][2] + padding), -(box[0][2] - padding), @@ -218,9 +218,7 @@ glm_ortho_default(float aspect, mat4 dest) { */ CGLM_INLINE void -glm_ortho_default_s(float aspect, - float size, - mat4 dest) { +glm_ortho_default_s(float aspect, float size, mat4 dest) { if (aspect >= 1.0f) { glm_ortho(-size * aspect, size * aspect, @@ -338,10 +336,10 @@ glm_perspective_resize(float aspect, mat4 proj) { */ CGLM_INLINE void -glm_lookat(vec3 eye, - vec3 center, - vec3 up, - mat4 dest) { +glm_lookat(const vec3 eye, + const vec3 center, + const vec3 up, + mat4 dest) { CGLM_ALIGN(8) vec3 f, u, s; glm_vec3_sub(center, eye, f); diff --git a/include/cglm/color.h b/include/cglm/color.h index 69566ad..27d77b8 100644 --- a/include/cglm/color.h +++ b/include/cglm/color.h @@ -18,7 +18,7 @@ */ CGLM_INLINE float -glm_luminance(vec3 rgb) { +glm_luminance(const vec3 rgb) { vec3 l = {0.212671f, 0.715160f, 0.072169f}; return glm_dot(rgb, l); } diff --git a/include/cglm/curve.h b/include/cglm/curve.h index 5033be5..bcc104f 100644 --- a/include/cglm/curve.h +++ b/include/cglm/curve.h @@ -31,7 +31,7 @@ */ CGLM_INLINE float -glm_smc(float s, mat4 m, vec4 c) { +glm_smc(float s, const mat4 m, const vec4 c) { vec4 vs; glm_vec4_cubic(s, vs); return glm_mat4_rmc(vs, m, c); diff --git a/include/cglm/euler.h b/include/cglm/euler.h index 1ff5f6d..df6c0bc 100644 --- a/include/cglm/euler.h +++ b/include/cglm/euler.h @@ -57,7 +57,7 @@ typedef enum glm_euler_sq { CGLM_INLINE glm_euler_sq -glm_euler_order(int ord[3]) { +glm_euler_order(const int ord[3]) { return (glm_euler_sq)(ord[0] << 0 | ord[1] << 2 | ord[2] << 4); } @@ -69,7 +69,7 @@ glm_euler_order(int ord[3]) { */ CGLM_INLINE void -glm_euler_angles(mat4 m, vec3 dest) { +glm_euler_angles(const mat4 m, vec3 dest) { float m00, m01, m10, m11, m20, m21, m22; float thetaX, thetaY, thetaZ; @@ -107,7 +107,7 @@ glm_euler_angles(mat4 m, vec3 dest) { */ CGLM_INLINE void -glm_euler_xyz(vec3 angles, mat4 dest) { +glm_euler_xyz(const vec3 angles, mat4 dest) { float cx, cy, cz, sx, sy, sz, czsx, cxcz, sysz; @@ -145,7 +145,7 @@ glm_euler_xyz(vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler(vec3 angles, mat4 dest) { +glm_euler(const vec3 angles, mat4 dest) { glm_euler_xyz(angles, dest); } @@ -157,7 +157,7 @@ glm_euler(vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler_xzy(vec3 angles, mat4 dest) { +glm_euler_xzy(const vec3 angles, mat4 dest) { float cx, cy, cz, sx, sy, sz, sxsy, cysx, cxsy, cxcy; @@ -197,7 +197,7 @@ glm_euler_xzy(vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler_yxz(vec3 angles, mat4 dest) { +glm_euler_yxz(const vec3 angles, mat4 dest) { float cx, cy, cz, sx, sy, sz, cycz, sysz, czsy, cysz; @@ -236,7 +236,7 @@ glm_euler_yxz(vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler_yzx(vec3 angles, mat4 dest) { +glm_euler_yzx(const vec3 angles, mat4 dest) { float cx, cy, cz, sx, sy, sz, sxsy, cxcy, cysx, cxsy; @@ -275,7 +275,7 @@ glm_euler_yzx(vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler_zxy(vec3 angles, mat4 dest) { +glm_euler_zxy(const vec3 angles, mat4 dest) { float cx, cy, cz, sx, sy, sz, cycz, sxsy, cysz; @@ -313,7 +313,7 @@ glm_euler_zxy(vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler_zyx(vec3 angles, mat4 dest) { +glm_euler_zyx(const vec3 angles, mat4 dest) { float cx, cy, cz, sx, sy, sz, czsx, cxcz, sysz; @@ -352,7 +352,7 @@ glm_euler_zyx(vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler_by_order(vec3 angles, glm_euler_sq ord, mat4 dest) { +glm_euler_by_order(const vec3 angles, glm_euler_sq ord, mat4 dest) { float cx, cy, cz, sx, sy, sz; diff --git a/include/cglm/frustum.h b/include/cglm/frustum.h index 78b39d2..755fecd 100644 --- a/include/cglm/frustum.h +++ b/include/cglm/frustum.h @@ -69,7 +69,7 @@ */ CGLM_INLINE void -glm_frustum_planes(mat4 m, vec4 dest[6]) { +glm_frustum_planes(const mat4 m, vec4 dest[6]) { mat4 t; glm_mat4_transpose_to(m, t); @@ -114,7 +114,7 @@ glm_frustum_planes(mat4 m, vec4 dest[6]) { */ CGLM_INLINE void -glm_frustum_corners(mat4 invMat, vec4 dest[8]) { +glm_frustum_corners(const mat4 invMat, vec4 dest[8]) { vec4 c[8]; /* indexOf(nearCoord) = indexOf(farCoord) + 4 */ @@ -157,7 +157,7 @@ glm_frustum_corners(mat4 invMat, vec4 dest[8]) { */ CGLM_INLINE void -glm_frustum_center(vec4 corners[8], vec4 dest) { +glm_frustum_center(const vec4 corners[8], vec4 dest) { vec4 center; glm_vec4_copy(corners[0], center); @@ -182,7 +182,7 @@ glm_frustum_center(vec4 corners[8], vec4 dest) { */ CGLM_INLINE void -glm_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) { +glm_frustum_box(const vec4 corners[8], const mat4 m, vec3 box[2]) { vec4 v; vec3 min, max; int i; @@ -220,10 +220,10 @@ glm_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) { */ CGLM_INLINE void -glm_frustum_corners_at(vec4 corners[8], - float splitDist, - float farDist, - vec4 planeCorners[4]) { +glm_frustum_corners_at(const vec4 corners[8], + float splitDist, + float farDist, + vec4 planeCorners[4]) { vec4 corner; float dist, sc; diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index e6b916b..2a87fba 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -100,7 +100,7 @@ */ CGLM_INLINE void -glm_mat4_ucopy(mat4 mat, mat4 dest) { +glm_mat4_ucopy(const mat4 mat, mat4 dest) { dest[0][0] = mat[0][0]; dest[1][0] = mat[1][0]; dest[0][1] = mat[0][1]; dest[1][1] = mat[1][1]; dest[0][2] = mat[0][2]; dest[1][2] = mat[1][2]; @@ -120,7 +120,7 @@ glm_mat4_ucopy(mat4 mat, mat4 dest) { */ CGLM_INLINE void -glm_mat4_copy(mat4 mat, mat4 dest) { +glm_mat4_copy(const mat4 mat, mat4 dest) { #ifdef __AVX__ glmm_store256(dest[0], glmm_load256(mat[0])); glmm_store256(dest[2], glmm_load256(mat[2])); @@ -170,7 +170,7 @@ glm_mat4_identity(mat4 mat) { */ CGLM_INLINE void -glm_mat4_identity_array(mat4 * __restrict mat, size_t count) { +glm_mat4_identity_array(mat4 * const __restrict mat, size_t count) { CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; size_t i; @@ -199,7 +199,7 @@ glm_mat4_zero(mat4 mat) { */ CGLM_INLINE void -glm_mat4_pick3(mat4 mat, mat3 dest) { +glm_mat4_pick3(const mat4 mat, mat3 dest) { dest[0][0] = mat[0][0]; dest[0][1] = mat[0][1]; dest[0][2] = mat[0][2]; @@ -223,7 +223,7 @@ glm_mat4_pick3(mat4 mat, mat3 dest) { */ CGLM_INLINE void -glm_mat4_pick3t(mat4 mat, mat3 dest) { +glm_mat4_pick3t(const mat4 mat, mat3 dest) { dest[0][0] = mat[0][0]; dest[0][1] = mat[1][0]; dest[0][2] = mat[2][0]; @@ -245,7 +245,7 @@ glm_mat4_pick3t(mat4 mat, mat3 dest) { */ CGLM_INLINE void -glm_mat4_ins3(mat3 mat, mat4 dest) { +glm_mat4_ins3(const mat3 mat, mat4 dest) { dest[0][0] = mat[0][0]; dest[0][1] = mat[0][1]; dest[0][2] = mat[0][2]; @@ -275,7 +275,7 @@ glm_mat4_ins3(mat3 mat, mat4 dest) { */ CGLM_INLINE void -glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest) { +glm_mat4_mul(const mat4 m1, const mat4 m2, mat4 dest) { #ifdef __AVX__ glm_mat4_mul_avx(m1, m2, dest); #elif defined( __SSE__ ) || defined( __SSE2__ ) @@ -333,7 +333,7 @@ glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest) { */ CGLM_INLINE void -glm_mat4_mulN(mat4 * __restrict matrices[], uint32_t len, mat4 dest) { +glm_mat4_mulN(mat4 * const __restrict matrices[], uint32_t len, mat4 dest) { uint32_t i; #ifdef DEBUG @@ -355,7 +355,7 @@ glm_mat4_mulN(mat4 * __restrict matrices[], uint32_t len, mat4 dest) { */ CGLM_INLINE void -glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) { +glm_mat4_mulv(const mat4 m, const vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mat4_mulv_sse2(m, v, dest); #else @@ -377,7 +377,7 @@ glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) { */ CGLM_INLINE float -glm_mat4_trace(mat4 m) { +glm_mat4_trace(const mat4 m) { return m[0][0] + m[1][1] + m[2][2] + m[3][3]; } @@ -390,7 +390,7 @@ glm_mat4_trace(mat4 m) { */ CGLM_INLINE float -glm_mat4_trace3(mat4 m) { +glm_mat4_trace3(const mat4 m) { return m[0][0] + m[1][1] + m[2][2]; } @@ -402,7 +402,7 @@ glm_mat4_trace3(mat4 m) { */ CGLM_INLINE void -glm_mat4_quat(mat4 m, versor dest) { +glm_mat4_quat(const mat4 m, versor dest) { float trace, r, rinv; /* it seems using like m12 instead of m[1][2] causes extra instructions */ @@ -453,7 +453,7 @@ glm_mat4_quat(mat4 m, versor dest) { */ CGLM_INLINE void -glm_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest) { +glm_mat4_mulv3(const mat4 m, const vec3 v, float last, vec3 dest) { vec4 res; glm_vec4(v, last, res); glm_mat4_mulv(m, res, res); @@ -470,7 +470,7 @@ glm_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest) { */ CGLM_INLINE void -glm_mat4_transpose_to(mat4 m, mat4 dest) { +glm_mat4_transpose_to(const mat4 m, mat4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mat4_transp_sse2(m, dest); #else @@ -553,7 +553,7 @@ glm_mat4_scale(mat4 m, float s) { */ CGLM_INLINE float -glm_mat4_det(mat4 mat) { +glm_mat4_det(const mat4 mat) { #if defined( __SSE__ ) || defined( __SSE2__ ) return glm_mat4_det_sse2(mat); #else @@ -586,7 +586,7 @@ glm_mat4_det(mat4 mat) { */ CGLM_INLINE void -glm_mat4_inv(mat4 mat, mat4 dest) { +glm_mat4_inv(const mat4 mat, mat4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mat4_inv_sse2(mat, dest); #else @@ -647,7 +647,7 @@ glm_mat4_inv(mat4 mat, mat4 dest) { */ CGLM_INLINE void -glm_mat4_inv_fast(mat4 mat, mat4 dest) { +glm_mat4_inv_fast(const mat4 mat, mat4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mat4_inv_fast_sse2(mat, dest); #else @@ -680,7 +680,7 @@ glm_mat4_swap_col(mat4 mat, int col1, int col2) { */ CGLM_INLINE void -glm_mat4_swap_row(mat4 mat, int row1, int row2) { +glm_mat4_swap_row(mat4 mat, const int row1, const int row2) { CGLM_ALIGN(16) vec4 tmp; tmp[0] = mat[0][row1]; tmp[1] = mat[1][row1]; @@ -714,7 +714,7 @@ glm_mat4_swap_row(mat4 mat, int row1, int row2) { */ CGLM_INLINE float -glm_mat4_rmc(vec4 r, mat4 m, vec4 c) { +glm_mat4_rmc(const vec4 r, const mat4 m, const vec4 c) { vec4 tmp; glm_mat4_mulv(m, c, tmp); return glm_vec4_dot(r, tmp); diff --git a/include/cglm/project.h b/include/cglm/project.h index 1336222..f62b001 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -41,7 +41,7 @@ */ CGLM_INLINE void -glm_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { +glm_unprojecti(const vec3 pos, const mat4 invMat, const vec4 vp, vec3 dest) { vec4 v; v[0] = 2.0f * (pos[0] - vp[0]) / vp[2] - 1.0f; @@ -80,7 +80,7 @@ glm_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { */ CGLM_INLINE void -glm_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) { +glm_unproject(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest) { mat4 inv; glm_mat4_inv(m, inv); glm_unprojecti(pos, inv, vp, dest); @@ -100,7 +100,7 @@ glm_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) { */ CGLM_INLINE void -glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { +glm_project(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest) { CGLM_ALIGN(16) vec4 pos4, vone = GLM_VEC4_ONE_INIT; glm_vec4(pos, 1.0f, pos4); diff --git a/include/cglm/quat.h b/include/cglm/quat.h index f5f29af..e6ef0f4 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -68,15 +68,15 @@ glm_mat4_identity(mat4 mat); CGLM_INLINE void -glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); +glm_mat4_mulv(const mat4 m, const vec4 v, vec4 dest); CGLM_INLINE void -glm_mul_rot(mat4 m1, mat4 m2, mat4 dest); +glm_mul_rot(const mat4 m1, const mat4 m2, mat4 dest); CGLM_INLINE void -glm_translate(mat4 m, vec3 v); +glm_translate(mat4 m, const vec3 v); /* * IMPORTANT: @@ -113,7 +113,7 @@ glm_quat_identity(versor q) { */ CGLM_INLINE void -glm_quat_identity_array(versor * __restrict q, size_t count) { +glm_quat_identity_array(versor * const __restrict q, size_t count) { CGLM_ALIGN(16) versor v = GLM_QUAT_IDENTITY_INIT; size_t i; @@ -149,7 +149,7 @@ glm_quat_init(versor q, float x, float y, float z, float w) { */ CGLM_INLINE void -glm_quatv(versor q, float angle, vec3 axis) { +glm_quatv(versor q, float angle, const vec3 axis) { CGLM_ALIGN(8) vec3 k; float a, c, s; @@ -189,7 +189,7 @@ glm_quat(versor q, float angle, float x, float y, float z) { */ CGLM_INLINE void -glm_quat_copy(versor q, versor dest) { +glm_quat_copy(const versor q, versor dest) { glm_vec4_copy(q, dest); } @@ -200,7 +200,7 @@ glm_quat_copy(versor q, versor dest) { */ CGLM_INLINE float -glm_quat_norm(versor q) { +glm_quat_norm(const versor q) { return glm_vec4_norm(q); } @@ -212,7 +212,7 @@ glm_quat_norm(versor q) { */ CGLM_INLINE void -glm_quat_normalize_to(versor q, versor dest) { +glm_quat_normalize_to(const versor q, versor dest) { #if defined( __SSE2__ ) || defined( __SSE2__ ) __m128 xdot, x0; float dot; @@ -260,7 +260,7 @@ glm_quat_normalize(versor q) { */ CGLM_INLINE float -glm_quat_dot(versor p, versor q) { +glm_quat_dot(const versor p, const versor q) { return glm_vec4_dot(p, q); } @@ -272,7 +272,7 @@ glm_quat_dot(versor p, versor q) { */ CGLM_INLINE void -glm_quat_conjugate(versor q, versor dest) { +glm_quat_conjugate(const versor q, versor dest) { glm_vec4_negate_to(q, dest); dest[3] = -dest[3]; } @@ -285,7 +285,7 @@ glm_quat_conjugate(versor q, versor dest) { */ CGLM_INLINE void -glm_quat_inv(versor q, versor dest) { +glm_quat_inv(const versor q, versor dest) { CGLM_ALIGN(16) versor conj; glm_quat_conjugate(q, conj); glm_vec4_scale(conj, 1.0f / glm_vec4_norm2(q), dest); @@ -300,7 +300,7 @@ glm_quat_inv(versor q, versor dest) { */ CGLM_INLINE void -glm_quat_add(versor p, versor q, versor dest) { +glm_quat_add(const versor p, const versor q, versor dest) { glm_vec4_add(p, q, dest); } @@ -313,7 +313,7 @@ glm_quat_add(versor p, versor q, versor dest) { */ CGLM_INLINE void -glm_quat_sub(versor p, versor q, versor dest) { +glm_quat_sub(const versor p, const versor q, versor dest) { glm_vec4_sub(p, q, dest); } @@ -324,7 +324,7 @@ glm_quat_sub(versor p, versor q, versor dest) { */ CGLM_INLINE float -glm_quat_real(versor q) { +glm_quat_real(const versor q) { return q[3]; } @@ -336,7 +336,7 @@ glm_quat_real(versor q) { */ CGLM_INLINE void -glm_quat_imag(versor q, vec3 dest) { +glm_quat_imag(const versor q, vec3 dest) { dest[0] = q[0]; dest[1] = q[1]; dest[2] = q[2]; @@ -349,7 +349,7 @@ glm_quat_imag(versor q, vec3 dest) { */ CGLM_INLINE void -glm_quat_imagn(versor q, vec3 dest) { +glm_quat_imagn(const versor q, vec3 dest) { glm_normalize_to(q, dest); } @@ -360,7 +360,7 @@ glm_quat_imagn(versor q, vec3 dest) { */ CGLM_INLINE float -glm_quat_imaglen(versor q) { +glm_quat_imaglen(const versor q) { return glm_vec3_norm(q); } @@ -371,7 +371,7 @@ glm_quat_imaglen(versor q) { */ CGLM_INLINE float -glm_quat_angle(versor q) { +glm_quat_angle(const versor q) { /* sin(theta / 2) = length(x*x + y*y + z*z) cos(theta / 2) = w @@ -388,7 +388,7 @@ glm_quat_angle(versor q) { */ CGLM_INLINE void -glm_quat_axis(versor q, versor dest) { +glm_quat_axis(const versor q, versor dest) { glm_quat_imagn(q, dest); } @@ -406,7 +406,7 @@ glm_quat_axis(versor q, versor dest) { */ CGLM_INLINE void -glm_quat_mul(versor p, versor q, versor dest) { +glm_quat_mul(const versor p, const versor q, versor dest) { /* + (a1 b2 + b1 a2 + c1 d2 − d1 c2)i + (a1 c2 − b1 d2 + c1 a2 + d1 b2)j @@ -431,7 +431,7 @@ glm_quat_mul(versor p, versor q, versor dest) { */ CGLM_INLINE void -glm_quat_mat4(versor q, mat4 dest) { +glm_quat_mat4(const versor q, mat4 dest) { float w, x, y, z, xx, yy, zz, xy, yz, xz, @@ -478,7 +478,7 @@ glm_quat_mat4(versor q, mat4 dest) { */ CGLM_INLINE void -glm_quat_mat4t(versor q, mat4 dest) { +glm_quat_mat4t(const versor q, mat4 dest) { float w, x, y, z, xx, yy, zz, xy, yz, xz, @@ -525,7 +525,7 @@ glm_quat_mat4t(versor q, mat4 dest) { */ CGLM_INLINE void -glm_quat_mat3(versor q, mat3 dest) { +glm_quat_mat3(const versor q, mat3 dest) { float w, x, y, z, xx, yy, zz, xy, yz, xz, @@ -564,7 +564,7 @@ glm_quat_mat3(versor q, mat3 dest) { */ CGLM_INLINE void -glm_quat_mat3t(versor q, mat3 dest) { +glm_quat_mat3t(const versor q, mat3 dest) { float w, x, y, z, xx, yy, zz, xy, yz, xz, @@ -606,7 +606,7 @@ glm_quat_mat3t(versor q, mat3 dest) { */ CGLM_INLINE void -glm_quat_lerp(versor from, versor to, float t, versor dest) { +glm_quat_lerp(const versor from, const versor to, float t, versor dest) { glm_vec4_lerp(from, to, t, dest); } @@ -621,7 +621,7 @@ glm_quat_lerp(versor from, versor to, float t, versor dest) { */ CGLM_INLINE void -glm_quat_slerp(versor from, versor to, float t, versor dest) { +glm_quat_slerp(const versor from, const versor to, float t, versor dest) { CGLM_ALIGN(16) vec4 q1, q2; float cosTheta, sinTheta, angle; @@ -664,7 +664,7 @@ glm_quat_slerp(versor from, versor to, float t, versor dest) { */ CGLM_INLINE void -glm_quat_look(vec3 eye, versor ori, mat4 dest) { +glm_quat_look(const vec3 eye, const versor ori, mat4 dest) { /* orientation */ glm_quat_mat4t(ori, dest); @@ -683,7 +683,7 @@ glm_quat_look(vec3 eye, versor ori, mat4 dest) { */ CGLM_INLINE void -glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) { +glm_quat_for(const vec3 dir, const vec3 fwd, const vec3 up, versor dest) { CGLM_ALIGN(8) vec3 axis; float dot, angle; @@ -717,7 +717,11 @@ glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) { */ CGLM_INLINE void -glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { +glm_quat_forp(const vec3 from, + const vec3 to, + const vec3 fwd, + const vec3 up, + versor dest) { CGLM_ALIGN(8) vec3 dir; glm_vec3_sub(to, from, dir); glm_quat_for(dir, fwd, up, dest); @@ -732,7 +736,7 @@ glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { */ CGLM_INLINE void -glm_quat_rotatev(versor q, vec3 v, vec3 dest) { +glm_quat_rotatev(const versor q, const vec3 v, vec3 dest) { CGLM_ALIGN(16) versor p; CGLM_ALIGN(8) vec3 u, v1, v2; float s; @@ -760,7 +764,7 @@ glm_quat_rotatev(versor q, vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_quat_rotate(mat4 m, versor q, mat4 dest) { +glm_quat_rotate(const mat4 m, const versor q, mat4 dest) { CGLM_ALIGN_MAT mat4 rot; glm_quat_mat4(q, rot); glm_mul_rot(m, rot, dest); @@ -775,7 +779,7 @@ glm_quat_rotate(mat4 m, versor q, mat4 dest) { */ CGLM_INLINE void -glm_quat_rotate_at(mat4 m, versor q, vec3 pivot) { +glm_quat_rotate_at(mat4 m, const versor q, const vec3 pivot) { CGLM_ALIGN(8) vec3 pivotInv; glm_vec3_negate_to(pivot, pivotInv); @@ -799,7 +803,7 @@ glm_quat_rotate_at(mat4 m, versor q, vec3 pivot) { */ CGLM_INLINE void -glm_quat_rotate_atm(mat4 m, versor q, vec3 pivot) { +glm_quat_rotate_atm(mat4 m, const versor q, const vec3 pivot) { CGLM_ALIGN(8) vec3 pivotInv; glm_vec3_negate_to(pivot, pivotInv); diff --git a/include/cglm/simd/avx/affine.h b/include/cglm/simd/avx/affine.h index b02ff0c..0d0454e 100644 --- a/include/cglm/simd/avx/affine.h +++ b/include/cglm/simd/avx/affine.h @@ -16,7 +16,7 @@ CGLM_INLINE void -glm_mul_avx(mat4 m1, mat4 m2, mat4 dest) { +glm_mul_avx(const mat4 m1, const mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ __m256 y0, y1, y2, y3, y4, y5, y6, y7, y8, y9; diff --git a/include/cglm/simd/avx/mat4.h b/include/cglm/simd/avx/mat4.h index 944769b..a458d4c 100644 --- a/include/cglm/simd/avx/mat4.h +++ b/include/cglm/simd/avx/mat4.h @@ -16,7 +16,7 @@ CGLM_INLINE void -glm_mat4_mul_avx(mat4 m1, mat4 m2, mat4 dest) { +glm_mat4_mul_avx(const mat4 m1, const mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ __m256 y0, y1, y2, y3, y4, y5, y6, y7, y8, y9; diff --git a/include/cglm/simd/neon/mat4.h b/include/cglm/simd/neon/mat4.h index 0623dc0..df342dc 100644 --- a/include/cglm/simd/neon/mat4.h +++ b/include/cglm/simd/neon/mat4.h @@ -14,7 +14,7 @@ CGLM_INLINE void -glm_mat4_mul_neon(mat4 m1, mat4 m2, mat4 dest) { +glm_mat4_mul_neon(const mat4 m1, const mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ float32x4_t l0, l1, l2, l3, r, d0, d1, d2, d3; diff --git a/include/cglm/simd/sse2/affine.h b/include/cglm/simd/sse2/affine.h index 87db1b8..ae187b1 100644 --- a/include/cglm/simd/sse2/affine.h +++ b/include/cglm/simd/sse2/affine.h @@ -14,7 +14,7 @@ CGLM_INLINE void -glm_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { +glm_mul_sse2(const mat4 m1, const mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ __m128 l0, l1, l2, l3, r; @@ -51,7 +51,7 @@ glm_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { CGLM_INLINE void -glm_mul_rot_sse2(mat4 m1, mat4 m2, mat4 dest) { +glm_mul_rot_sse2(const mat4 m1, const mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ __m128 l0, l1, l2, l3, r; diff --git a/include/cglm/simd/sse2/mat3.h b/include/cglm/simd/sse2/mat3.h index 9c972ff..07cb5f4 100644 --- a/include/cglm/simd/sse2/mat3.h +++ b/include/cglm/simd/sse2/mat3.h @@ -14,7 +14,7 @@ CGLM_INLINE void -glm_mat3_mul_sse2(mat3 m1, mat3 m2, mat3 dest) { +glm_mat3_mul_sse2(const mat3 m1, const mat3 m2, mat3 dest) { __m128 l0, l1, l2; __m128 r0, r1, r2; __m128 x0, x1, x2; diff --git a/include/cglm/simd/sse2/mat4.h b/include/cglm/simd/sse2/mat4.h index 7c87eb5..66fb75a 100644 --- a/include/cglm/simd/sse2/mat4.h +++ b/include/cglm/simd/sse2/mat4.h @@ -28,7 +28,7 @@ glm_mat4_scale_sse2(mat4 m, float s) { CGLM_INLINE void -glm_mat4_transp_sse2(mat4 m, mat4 dest) { +glm_mat4_transp_sse2(const mat4 m, mat4 dest) { __m128 r0, r1, r2, r3; r0 = glmm_load(m[0]); @@ -46,7 +46,7 @@ glm_mat4_transp_sse2(mat4 m, mat4 dest) { CGLM_INLINE void -glm_mat4_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { +glm_mat4_mul_sse2(const mat4 m1, const mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ __m128 l0, l1, l2, l3, r; @@ -85,7 +85,7 @@ glm_mat4_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { CGLM_INLINE void -glm_mat4_mulv_sse2(mat4 m, vec4 v, vec4 dest) { +glm_mat4_mulv_sse2(const mat4 m, const vec4 v, vec4 dest) { __m128 x0, x1, x2; x0 = glmm_load(v); @@ -100,7 +100,7 @@ glm_mat4_mulv_sse2(mat4 m, vec4 v, vec4 dest) { CGLM_INLINE float -glm_mat4_det_sse2(mat4 mat) { +glm_mat4_det_sse2(const mat4 mat) { __m128 r0, r1, r2, r3, x0, x1, x2; /* 127 <- 0, [square] det(A) = det(At) */ @@ -155,7 +155,7 @@ glm_mat4_det_sse2(mat4 mat) { CGLM_INLINE void -glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { +glm_mat4_inv_fast_sse2(const mat4 mat, mat4 dest) { __m128 r0, r1, r2, r3, v0, v1, v2, v3, t0, t1, t2, t3, t4, t5, @@ -279,7 +279,7 @@ glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { CGLM_INLINE void -glm_mat4_inv_sse2(mat4 mat, mat4 dest) { +glm_mat4_inv_sse2(const mat4 mat, mat4 dest) { __m128 r0, r1, r2, r3, v0, v1, v2, v3, t0, t1, t2, t3, t4, t5, diff --git a/include/cglm/simd/sse2/quat.h b/include/cglm/simd/sse2/quat.h index 0173f94..08ebb70 100644 --- a/include/cglm/simd/sse2/quat.h +++ b/include/cglm/simd/sse2/quat.h @@ -14,7 +14,7 @@ CGLM_INLINE void -glm_quat_mul_sse2(versor p, versor q, versor dest) { +glm_quat_mul_sse2(const versor p, const versor q, versor dest) { /* + (a1 b2 + b1 a2 + c1 d2 − d1 c2)i + (a1 c2 − b1 d2 + c1 a2 + d1 b2)j diff --git a/include/cglm/simd/x86.h b/include/cglm/simd/x86.h index 99d2b8a..b926511 100644 --- a/include/cglm/simd/x86.h +++ b/include/cglm/simd/x86.h @@ -103,7 +103,7 @@ glmm_vdot(__m128 a, __m128 b) { static inline float -glmm_dot(__m128 a, __m128 b) { +glmm_dot(const __m128 a, const __m128 b) { return _mm_cvtss_f32(glmm_vdots(a, b)); } @@ -115,7 +115,7 @@ glmm_norm(__m128 a) { static inline __m128 -glmm_load3(float v[3]) { +glmm_load3(const float v[3]) { __m128i xy; __m128 z; diff --git a/include/cglm/sphere.h b/include/cglm/sphere.h index 334b83a..7653096 100644 --- a/include/cglm/sphere.h +++ b/include/cglm/sphere.h @@ -27,7 +27,7 @@ */ CGLM_INLINE float -glm_sphere_radii(vec4 s) { +glm_sphere_radii(const vec4 s) { return s[3]; } @@ -40,7 +40,7 @@ glm_sphere_radii(vec4 s) { */ CGLM_INLINE void -glm_sphere_transform(vec4 s, mat4 m, vec4 dest) { +glm_sphere_transform(const vec4 s, const mat4 m, vec4 dest) { glm_mat4_mulv3(m, s, 1.0f, dest); dest[3] = s[3]; } @@ -57,7 +57,7 @@ glm_sphere_transform(vec4 s, mat4 m, vec4 dest) { */ CGLM_INLINE void -glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { +glm_sphere_merge(const vec4 s1, const vec4 s2, vec4 dest) { float dist, radii; dist = glm_vec3_distance(s1, s2); @@ -78,7 +78,7 @@ glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { */ CGLM_INLINE bool -glm_sphere_sphere(vec4 s1, vec4 s2) { +glm_sphere_sphere(const vec4 s1, const vec4 s2) { return glm_vec3_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]); } @@ -90,7 +90,7 @@ glm_sphere_sphere(vec4 s1, vec4 s2) { */ CGLM_INLINE bool -glm_sphere_point(vec4 s, vec3 point) { +glm_sphere_point(const vec4 s, const vec3 point) { float rr; rr = s[3] * s[3]; return glm_vec3_distance2(point, s) <= rr; diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index f1cc462..d82455f 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -52,7 +52,7 @@ glm_vec3_broadcast(float val, vec3 d) { */ CGLM_INLINE bool -glm_vec3_eq(vec3 v, float val) { +glm_vec3_eq(const vec3 v, float val) { return v[0] == val && v[0] == v[1] && v[0] == v[2]; } @@ -64,7 +64,7 @@ glm_vec3_eq(vec3 v, float val) { */ CGLM_INLINE bool -glm_vec3_eq_eps(vec3 v, float val) { +glm_vec3_eq_eps(const vec3 v, float val) { return fabsf(v[0] - val) <= FLT_EPSILON && fabsf(v[1] - val) <= FLT_EPSILON && fabsf(v[2] - val) <= FLT_EPSILON; @@ -77,7 +77,7 @@ glm_vec3_eq_eps(vec3 v, float val) { */ CGLM_INLINE bool -glm_vec3_eq_all(vec3 v) { +glm_vec3_eq_all(const vec3 v) { return v[0] == v[1] && v[0] == v[2]; } @@ -89,7 +89,7 @@ glm_vec3_eq_all(vec3 v) { */ CGLM_INLINE bool -glm_vec3_eqv(vec3 a, vec3 b) { +glm_vec3_eqv(const vec3 a, const vec3 b) { return a[0] == b[0] && a[1] == b[1] && a[2] == b[2]; @@ -103,7 +103,7 @@ glm_vec3_eqv(vec3 a, vec3 b) { */ CGLM_INLINE bool -glm_vec3_eqv_eps(vec3 a, vec3 b) { +glm_vec3_eqv_eps(const vec3 a, const vec3 b) { return fabsf(a[0] - b[0]) <= FLT_EPSILON && fabsf(a[1] - b[1]) <= FLT_EPSILON && fabsf(a[2] - b[2]) <= FLT_EPSILON; @@ -116,7 +116,7 @@ glm_vec3_eqv_eps(vec3 a, vec3 b) { */ CGLM_INLINE float -glm_vec3_max(vec3 v) { +glm_vec3_max(const vec3 v) { float max; max = v[0]; @@ -135,7 +135,7 @@ glm_vec3_max(vec3 v) { */ CGLM_INLINE float -glm_vec3_min(vec3 v) { +glm_vec3_min(const vec3 v) { float min; min = v[0]; @@ -155,7 +155,7 @@ glm_vec3_min(vec3 v) { */ CGLM_INLINE bool -glm_vec3_isnan(vec3 v) { +glm_vec3_isnan(const vec3 v) { return isnan(v[0]) || isnan(v[1]) || isnan(v[2]); } @@ -167,7 +167,7 @@ glm_vec3_isnan(vec3 v) { */ CGLM_INLINE bool -glm_vec3_isinf(vec3 v) { +glm_vec3_isinf(const vec3 v) { return isinf(v[0]) || isinf(v[1]) || isinf(v[2]); } @@ -179,7 +179,7 @@ glm_vec3_isinf(vec3 v) { */ CGLM_INLINE bool -glm_vec3_isvalid(vec3 v) { +glm_vec3_isvalid(const vec3 v) { return !glm_vec3_isnan(v) && !glm_vec3_isinf(v); } @@ -192,7 +192,7 @@ glm_vec3_isvalid(vec3 v) { */ CGLM_INLINE void -glm_vec3_sign(vec3 v, vec3 dest) { +glm_vec3_sign(const vec3 v, vec3 dest) { dest[0] = glm_signf(v[0]); dest[1] = glm_signf(v[1]); dest[2] = glm_signf(v[2]); @@ -206,7 +206,7 @@ glm_vec3_sign(vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec3_sqrt(vec3 v, vec3 dest) { +glm_vec3_sqrt(const vec3 v, vec3 dest) { dest[0] = sqrtf(v[0]); dest[1] = sqrtf(v[1]); dest[2] = sqrtf(v[2]); diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index e67cc2f..b503b6e 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -111,7 +111,7 @@ */ CGLM_INLINE void -glm_vec3(vec4 v4, vec3 dest) { +glm_vec3(const vec4 v4, vec3 dest) { dest[0] = v4[0]; dest[1] = v4[1]; dest[2] = v4[2]; @@ -125,7 +125,7 @@ glm_vec3(vec4 v4, vec3 dest) { */ CGLM_INLINE void -glm_vec3_copy(vec3 a, vec3 dest) { +glm_vec3_copy(const vec3 a, vec3 dest) { dest[0] = a[0]; dest[1] = a[1]; dest[2] = a[2]; @@ -163,7 +163,7 @@ glm_vec3_one(vec3 v) { */ CGLM_INLINE float -glm_vec3_dot(vec3 a, vec3 b) { +glm_vec3_dot(const vec3 a, const vec3 b) { return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; } @@ -180,7 +180,7 @@ glm_vec3_dot(vec3 a, vec3 b) { */ CGLM_INLINE float -glm_vec3_norm2(vec3 v) { +glm_vec3_norm2(const vec3 v) { return glm_vec3_dot(v, v); } @@ -193,7 +193,7 @@ glm_vec3_norm2(vec3 v) { */ CGLM_INLINE float -glm_vec3_norm(vec3 v) { +glm_vec3_norm(const vec3 v) { return sqrtf(glm_vec3_norm2(v)); } @@ -206,7 +206,7 @@ glm_vec3_norm(vec3 v) { */ CGLM_INLINE void -glm_vec3_add(vec3 a, vec3 b, vec3 dest) { +glm_vec3_add(const vec3 a, const vec3 b, vec3 dest) { dest[0] = a[0] + b[0]; dest[1] = a[1] + b[1]; dest[2] = a[2] + b[2]; @@ -221,7 +221,7 @@ glm_vec3_add(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_adds(vec3 v, float s, vec3 dest) { +glm_vec3_adds(const vec3 v, float s, vec3 dest) { dest[0] = v[0] + s; dest[1] = v[1] + s; dest[2] = v[2] + s; @@ -236,7 +236,7 @@ glm_vec3_adds(vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec3_sub(vec3 a, vec3 b, vec3 dest) { +glm_vec3_sub(const vec3 a, const vec3 b, vec3 dest) { dest[0] = a[0] - b[0]; dest[1] = a[1] - b[1]; dest[2] = a[2] - b[2]; @@ -251,7 +251,7 @@ glm_vec3_sub(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_subs(vec3 v, float s, vec3 dest) { +glm_vec3_subs(const vec3 v, float s, vec3 dest) { dest[0] = v[0] - s; dest[1] = v[1] - s; dest[2] = v[2] - s; @@ -266,7 +266,7 @@ glm_vec3_subs(vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec3_mul(vec3 a, vec3 b, vec3 dest) { +glm_vec3_mul(const vec3 a, const vec3 b, vec3 dest) { dest[0] = a[0] * b[0]; dest[1] = a[1] * b[1]; dest[2] = a[2] * b[2]; @@ -281,7 +281,7 @@ glm_vec3_mul(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_scale(vec3 v, float s, vec3 dest) { +glm_vec3_scale(const vec3 v, float s, vec3 dest) { dest[0] = v[0] * s; dest[1] = v[1] * s; dest[2] = v[2] * s; @@ -296,7 +296,7 @@ glm_vec3_scale(vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec3_scale_as(vec3 v, float s, vec3 dest) { +glm_vec3_scale_as(const vec3 v, float s, vec3 dest) { float norm; norm = glm_vec3_norm(v); @@ -317,7 +317,7 @@ glm_vec3_scale_as(vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec3_div(vec3 a, vec3 b, vec3 dest) { +glm_vec3_div(const vec3 a, const vec3 b, vec3 dest) { dest[0] = a[0] / b[0]; dest[1] = a[1] / b[1]; dest[2] = a[2] / b[2]; @@ -332,7 +332,7 @@ glm_vec3_div(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_divs(vec3 v, float s, vec3 dest) { +glm_vec3_divs(const vec3 v, float s, vec3 dest) { dest[0] = v[0] / s; dest[1] = v[1] / s; dest[2] = v[2] / s; @@ -349,7 +349,7 @@ glm_vec3_divs(vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec3_addadd(vec3 a, vec3 b, vec3 dest) { +glm_vec3_addadd(const vec3 a, const vec3 b, vec3 dest) { dest[0] += a[0] + b[0]; dest[1] += a[1] + b[1]; dest[2] += a[2] + b[2]; @@ -366,7 +366,7 @@ glm_vec3_addadd(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_subadd(vec3 a, vec3 b, vec3 dest) { +glm_vec3_subadd(const vec3 a, const vec3 b, vec3 dest) { dest[0] += a[0] - b[0]; dest[1] += a[1] - b[1]; dest[2] += a[2] - b[2]; @@ -383,7 +383,7 @@ glm_vec3_subadd(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_muladd(vec3 a, vec3 b, vec3 dest) { +glm_vec3_muladd(const vec3 a, const vec3 b, vec3 dest) { dest[0] += a[0] * b[0]; dest[1] += a[1] * b[1]; dest[2] += a[2] * b[2]; @@ -400,7 +400,7 @@ glm_vec3_muladd(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_muladds(vec3 a, float s, vec3 dest) { +glm_vec3_muladds(const vec3 a, float s, vec3 dest) { dest[0] += a[0] * s; dest[1] += a[1] * s; dest[2] += a[2] * s; @@ -417,7 +417,7 @@ glm_vec3_muladds(vec3 a, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec3_maxadd(vec3 a, vec3 b, vec3 dest) { +glm_vec3_maxadd(const vec3 a, const vec3 b, vec3 dest) { dest[0] += glm_max(a[0], b[0]); dest[1] += glm_max(a[1], b[1]); dest[2] += glm_max(a[2], b[2]); @@ -434,7 +434,7 @@ glm_vec3_maxadd(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_minadd(vec3 a, vec3 b, vec3 dest) { +glm_vec3_minadd(const vec3 a, const vec3 b, vec3 dest) { dest[0] += glm_min(a[0], b[0]); dest[1] += glm_min(a[1], b[1]); dest[2] += glm_min(a[2], b[2]); @@ -448,7 +448,7 @@ glm_vec3_minadd(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_negate_to(vec3 v, vec3 dest) { +glm_vec3_negate_to(const vec3 v, vec3 dest) { dest[0] = -v[0]; dest[1] = -v[1]; dest[2] = -v[2]; @@ -493,7 +493,7 @@ glm_vec3_normalize(vec3 v) { */ CGLM_INLINE void -glm_vec3_normalize_to(vec3 v, vec3 dest) { +glm_vec3_normalize_to(const vec3 v, vec3 dest) { float norm; norm = glm_vec3_norm(v); @@ -515,7 +515,7 @@ glm_vec3_normalize_to(vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec3_cross(vec3 a, vec3 b, vec3 dest) { +glm_vec3_cross(const vec3 a, const vec3 b, vec3 dest) { /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ dest[0] = a[1] * b[2] - a[2] * b[1]; dest[1] = a[2] * b[0] - a[0] * b[2]; @@ -531,7 +531,7 @@ glm_vec3_cross(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_crossn(vec3 a, vec3 b, vec3 dest) { +glm_vec3_crossn(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_cross(a, b, dest); glm_vec3_normalize(dest); } @@ -546,7 +546,7 @@ glm_vec3_crossn(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE float -glm_vec3_angle(vec3 a, vec3 b) { +glm_vec3_angle(const vec3 a, const vec3 b) { float norm, dot; /* maybe compiler generate approximation instruction (rcp) */ @@ -570,7 +570,7 @@ glm_vec3_angle(vec3 a, vec3 b) { */ CGLM_INLINE void -glm_vec3_rotate(vec3 v, float angle, vec3 axis) { +glm_vec3_rotate(vec3 v, float angle, const vec3 axis) { vec3 v1, v2, k; float c, s; @@ -608,7 +608,7 @@ glm_vec3_rotate(vec3 v, float angle, vec3 axis) { */ CGLM_INLINE void -glm_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest) { +glm_vec3_rotate_m4(const mat4 m, const vec3 v, vec3 dest) { vec4 x, y, z, res; glm_vec4_normalize_to(m[0], x); @@ -631,7 +631,7 @@ glm_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest) { +glm_vec3_rotate_m3(const mat3 m, const vec3 v, vec3 dest) { vec4 res, x, y, z; glm_vec4(m[0], 0.0f, x); @@ -658,7 +658,7 @@ glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec3_proj(vec3 a, vec3 b, vec3 dest) { +glm_vec3_proj(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_scale(b, glm_vec3_dot(a, b) / glm_vec3_norm2(b), dest); @@ -673,7 +673,7 @@ glm_vec3_proj(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_center(vec3 a, vec3 b, vec3 dest) { +glm_vec3_center(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_add(a, b, dest); glm_vec3_scale(dest, 0.5f, dest); } @@ -687,7 +687,7 @@ glm_vec3_center(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE float -glm_vec3_distance2(vec3 a, vec3 b) { +glm_vec3_distance2(const vec3 a, const vec3 b) { return glm_pow2(b[0] - a[0]) + glm_pow2(b[1] - a[1]) + glm_pow2(b[2] - a[2]); @@ -702,7 +702,7 @@ glm_vec3_distance2(vec3 a, vec3 b) { */ CGLM_INLINE float -glm_vec3_distance(vec3 a, vec3 b) { +glm_vec3_distance(const vec3 a, const vec3 b) { return sqrtf(glm_vec3_distance2(a, b)); } @@ -715,7 +715,7 @@ glm_vec3_distance(vec3 a, vec3 b) { */ CGLM_INLINE void -glm_vec3_maxv(vec3 a, vec3 b, vec3 dest) { +glm_vec3_maxv(const vec3 a, const vec3 b, vec3 dest) { dest[0] = glm_max(a[0], b[0]); dest[1] = glm_max(a[1], b[1]); dest[2] = glm_max(a[2], b[2]); @@ -730,7 +730,7 @@ glm_vec3_maxv(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_minv(vec3 a, vec3 b, vec3 dest) { +glm_vec3_minv(const vec3 a, const vec3 b, vec3 dest) { dest[0] = glm_min(a[0], b[0]); dest[1] = glm_min(a[1], b[1]); dest[2] = glm_min(a[2], b[2]); @@ -744,7 +744,7 @@ glm_vec3_minv(vec3 a, vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_ortho(vec3 v, vec3 dest) { +glm_vec3_ortho(const vec3 v, vec3 dest) { dest[0] = v[1] - v[2]; dest[1] = v[2] - v[0]; dest[2] = v[0] - v[1]; @@ -777,7 +777,7 @@ glm_vec3_clamp(vec3 v, float minVal, float maxVal) { */ CGLM_INLINE void -glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) { +glm_vec3_lerp(const vec3 from, const vec3 to, float t, vec3 dest) { vec3 s, v; /* from + s * (to - from) */ @@ -798,7 +798,7 @@ glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) { */ CGLM_INLINE void -glm_cross(vec3 a, vec3 b, vec3 d) { +glm_cross(const vec3 a, const vec3 b, vec3 d) { glm_vec3_cross(a, b, d); } @@ -814,7 +814,7 @@ glm_cross(vec3 a, vec3 b, vec3 d) { */ CGLM_INLINE float -glm_dot(vec3 a, vec3 b) { +glm_dot(const vec3 a, const vec3 b) { return glm_vec3_dot(a, b); } @@ -841,7 +841,7 @@ glm_normalize(vec3 v) { */ CGLM_INLINE void -glm_normalize_to(vec3 v, vec3 dest) { +glm_normalize_to(const vec3 v, vec3 dest) { glm_vec3_normalize_to(v, dest); } diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index c545a14..7998a7d 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -56,7 +56,7 @@ glm_vec4_broadcast(float val, vec4 d) { */ CGLM_INLINE bool -glm_vec4_eq(vec4 v, float val) { +glm_vec4_eq(const vec4 v, float val) { return v[0] == val && v[0] == v[1] && v[0] == v[2] @@ -71,7 +71,7 @@ glm_vec4_eq(vec4 v, float val) { */ CGLM_INLINE bool -glm_vec4_eq_eps(vec4 v, float val) { +glm_vec4_eq_eps(const vec4 v, float val) { return fabsf(v[0] - val) <= FLT_EPSILON && fabsf(v[1] - val) <= FLT_EPSILON && fabsf(v[2] - val) <= FLT_EPSILON @@ -85,7 +85,7 @@ glm_vec4_eq_eps(vec4 v, float val) { */ CGLM_INLINE bool -glm_vec4_eq_all(vec4 v) { +glm_vec4_eq_all(const vec4 v) { return v[0] == v[1] && v[0] == v[2] && v[0] == v[3]; @@ -99,7 +99,7 @@ glm_vec4_eq_all(vec4 v) { */ CGLM_INLINE bool -glm_vec4_eqv(vec4 a, vec4 b) { +glm_vec4_eqv(const vec4 a, const vec4 b) { return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] @@ -114,7 +114,7 @@ glm_vec4_eqv(vec4 a, vec4 b) { */ CGLM_INLINE bool -glm_vec4_eqv_eps(vec4 a, vec4 b) { +glm_vec4_eqv_eps(const vec4 a, const vec4 b) { return fabsf(a[0] - b[0]) <= FLT_EPSILON && fabsf(a[1] - b[1]) <= FLT_EPSILON && fabsf(a[2] - b[2]) <= FLT_EPSILON @@ -128,7 +128,7 @@ glm_vec4_eqv_eps(vec4 a, vec4 b) { */ CGLM_INLINE float -glm_vec4_max(vec4 v) { +glm_vec4_max(const vec4 v) { float max; max = glm_vec3_max(v); @@ -145,7 +145,7 @@ glm_vec4_max(vec4 v) { */ CGLM_INLINE float -glm_vec4_min(vec4 v) { +glm_vec4_min(const vec4 v) { float min; min = glm_vec3_min(v); @@ -163,7 +163,7 @@ glm_vec4_min(vec4 v) { */ CGLM_INLINE bool -glm_vec4_isnan(vec4 v) { +glm_vec4_isnan(const vec4 v) { return isnan(v[0]) || isnan(v[1]) || isnan(v[2]) || isnan(v[3]); } @@ -175,7 +175,7 @@ glm_vec4_isnan(vec4 v) { */ CGLM_INLINE bool -glm_vec4_isinf(vec4 v) { +glm_vec4_isinf(const vec4 v) { return isinf(v[0]) || isinf(v[1]) || isinf(v[2]) || isinf(v[3]); } @@ -187,7 +187,7 @@ glm_vec4_isinf(vec4 v) { */ CGLM_INLINE bool -glm_vec4_isvalid(vec4 v) { +glm_vec4_isvalid(const vec4 v) { return !glm_vec4_isnan(v) && !glm_vec4_isinf(v); } @@ -200,7 +200,7 @@ glm_vec4_isvalid(vec4 v) { */ CGLM_INLINE void -glm_vec4_sign(vec4 v, vec4 dest) { +glm_vec4_sign(const vec4 v, vec4 dest) { #if defined( __SSE2__ ) || defined( __SSE2__ ) __m128 x0, x1, x2, x3, x4; @@ -228,7 +228,7 @@ glm_vec4_sign(vec4 v, vec4 dest) { */ CGLM_INLINE void -glm_vec4_sqrt(vec4 v, vec4 dest) { +glm_vec4_sqrt(const vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_sqrt_ps(glmm_load(v))); #else diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index d053ed5..3ed31e4 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -90,7 +90,7 @@ */ CGLM_INLINE void -glm_vec4(vec3 v3, float last, vec4 dest) { +glm_vec4(const vec3 v3, float last, vec4 dest) { dest[0] = v3[0]; dest[1] = v3[1]; dest[2] = v3[2]; @@ -105,7 +105,7 @@ glm_vec4(vec3 v3, float last, vec4 dest) { */ CGLM_INLINE void -glm_vec4_copy3(vec4 a, vec3 dest) { +glm_vec4_copy3(const vec4 a, vec3 dest) { dest[0] = a[0]; dest[1] = a[1]; dest[2] = a[2]; @@ -119,7 +119,7 @@ glm_vec4_copy3(vec4 a, vec3 dest) { */ CGLM_INLINE void -glm_vec4_copy(vec4 v, vec4 dest) { +glm_vec4_copy(const vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, glmm_load(v)); #elif defined(CGLM_NEON_FP) @@ -142,7 +142,7 @@ glm_vec4_copy(vec4 v, vec4 dest) { */ CGLM_INLINE void -glm_vec4_ucopy(vec4 v, vec4 dest) { +glm_vec4_ucopy(const vec4 v, vec4 dest) { dest[0] = v[0]; dest[1] = v[1]; dest[2] = v[2]; @@ -199,7 +199,7 @@ glm_vec4_one(vec4 v) { */ CGLM_INLINE float -glm_vec4_dot(vec4 a, vec4 b) { +glm_vec4_dot(const vec4 a, const vec4 b) { #if defined(CGLM_SIMD) return glmm_dot(glmm_load(a), glmm_load(b)); #else @@ -220,7 +220,7 @@ glm_vec4_dot(vec4 a, vec4 b) { */ CGLM_INLINE float -glm_vec4_norm2(vec4 v) { +glm_vec4_norm2(const vec4 v) { return glm_vec4_dot(v, v); } @@ -233,7 +233,7 @@ glm_vec4_norm2(vec4 v) { */ CGLM_INLINE float -glm_vec4_norm(vec4 v) { +glm_vec4_norm(const vec4 v) { #if defined(CGLM_SIMD) return glmm_norm(glmm_load(v)); #else @@ -250,7 +250,7 @@ glm_vec4_norm(vec4 v) { */ CGLM_INLINE void -glm_vec4_add(vec4 a, vec4 b, vec4 dest) { +glm_vec4_add(const vec4 a, const vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(a), glmm_load(b))); #elif defined(CGLM_NEON_FP) @@ -272,7 +272,7 @@ glm_vec4_add(vec4 a, vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_adds(vec4 v, float s, vec4 dest) { +glm_vec4_adds(const vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(v), _mm_set1_ps(s))); #elif defined(CGLM_NEON_FP) @@ -294,7 +294,7 @@ glm_vec4_adds(vec4 v, float s, vec4 dest) { */ CGLM_INLINE void -glm_vec4_sub(vec4 a, vec4 b, vec4 dest) { +glm_vec4_sub(const vec4 a, const vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_sub_ps(glmm_load(a), glmm_load(b))); #elif defined(CGLM_NEON_FP) @@ -316,7 +316,7 @@ glm_vec4_sub(vec4 a, vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_subs(vec4 v, float s, vec4 dest) { +glm_vec4_subs(const vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_sub_ps(glmm_load(v), _mm_set1_ps(s))); #elif defined(CGLM_NEON_FP) @@ -338,7 +338,7 @@ glm_vec4_subs(vec4 v, float s, vec4 dest) { */ CGLM_INLINE void -glm_vec4_mul(vec4 a, vec4 b, vec4 dest) { +glm_vec4_mul(const vec4 a, const vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_mul_ps(glmm_load(a), glmm_load(b))); #elif defined(CGLM_NEON_FP) @@ -360,7 +360,7 @@ glm_vec4_mul(vec4 a, vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_scale(vec4 v, float s, vec4 dest) { +glm_vec4_scale(const vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_mul_ps(glmm_load(v), _mm_set1_ps(s))); #elif defined(CGLM_NEON_FP) @@ -382,7 +382,7 @@ glm_vec4_scale(vec4 v, float s, vec4 dest) { */ CGLM_INLINE void -glm_vec4_scale_as(vec4 v, float s, vec4 dest) { +glm_vec4_scale_as(const vec4 v, float s, vec4 dest) { float norm; norm = glm_vec4_norm(v); @@ -403,7 +403,7 @@ glm_vec4_scale_as(vec4 v, float s, vec4 dest) { */ CGLM_INLINE void -glm_vec4_div(vec4 a, vec4 b, vec4 dest) { +glm_vec4_div(const vec4 a, const vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_div_ps(glmm_load(a), glmm_load(b))); #else @@ -423,7 +423,7 @@ glm_vec4_div(vec4 a, vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_divs(vec4 v, float s, vec4 dest) { +glm_vec4_divs(const vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_div_ps(glmm_load(v), _mm_set1_ps(s))); #else @@ -442,7 +442,7 @@ glm_vec4_divs(vec4 v, float s, vec4 dest) { */ CGLM_INLINE void -glm_vec4_addadd(vec4 a, vec4 b, vec4 dest) { +glm_vec4_addadd(const vec4 a, const vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_add_ps(glmm_load(a), @@ -470,7 +470,7 @@ glm_vec4_addadd(vec4 a, vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_subadd(vec4 a, vec4 b, vec4 dest) { +glm_vec4_subadd(const vec4 a, const vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_sub_ps(glmm_load(a), @@ -498,7 +498,7 @@ glm_vec4_subadd(vec4 a, vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_muladd(vec4 a, vec4 b, vec4 dest) { +glm_vec4_muladd(const vec4 a, const vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_mul_ps(glmm_load(a), @@ -526,7 +526,7 @@ glm_vec4_muladd(vec4 a, vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_muladds(vec4 a, float s, vec4 dest) { +glm_vec4_muladds(const vec4 a, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_mul_ps(glmm_load(a), @@ -554,7 +554,7 @@ glm_vec4_muladds(vec4 a, float s, vec4 dest) { */ CGLM_INLINE void -glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest) { +glm_vec4_maxadd(const vec4 a, const vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_max_ps(glmm_load(a), @@ -582,7 +582,7 @@ glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_minadd(vec4 a, vec4 b, vec4 dest) { +glm_vec4_minadd(const vec4 a,const vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_min_ps(glmm_load(a), @@ -607,7 +607,7 @@ glm_vec4_minadd(vec4 a, vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_negate_to(vec4 v, vec4 dest) { +glm_vec4_negate_to(const vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); #elif defined(CGLM_NEON_FP) @@ -639,7 +639,7 @@ glm_vec4_negate(vec4 v) { */ CGLM_INLINE void -glm_vec4_normalize_to(vec4 v, vec4 dest) { +glm_vec4_normalize_to(const vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) __m128 xdot, x0; float dot; @@ -688,7 +688,7 @@ glm_vec4_normalize(vec4 v) { */ CGLM_INLINE float -glm_vec4_distance(vec4 a, vec4 b) { +glm_vec4_distance(const vec4 a, const vec4 b) { #if defined( __SSE__ ) || defined( __SSE2__ ) return glmm_norm(_mm_sub_ps(glmm_load(b), glmm_load(a))); #elif defined(CGLM_NEON_FP) @@ -710,7 +710,7 @@ glm_vec4_distance(vec4 a, vec4 b) { */ CGLM_INLINE void -glm_vec4_maxv(vec4 a, vec4 b, vec4 dest) { +glm_vec4_maxv(const vec4 a, const vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_max_ps(glmm_load(a), glmm_load(b))); #elif defined(CGLM_NEON_FP) @@ -732,7 +732,7 @@ glm_vec4_maxv(vec4 a, vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_minv(vec4 a, vec4 b, vec4 dest) { +glm_vec4_minv(const vec4 a, const vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_min_ps(glmm_load(a), glmm_load(b))); #elif defined(CGLM_NEON_FP) @@ -781,7 +781,7 @@ glm_vec4_clamp(vec4 v, float minVal, float maxVal) { */ CGLM_INLINE void -glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) { +glm_vec4_lerp(const vec4 from, const vec4 to, float t, vec4 dest) { vec4 s, v; /* from + s * (to - from) */ From 6e501ef1f66498d4f4e89de4a7d7d86491e9c41e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 28 Apr 2019 19:15:55 +0300 Subject: [PATCH 264/292] build: don't link libcmocka if not exists --- post-build.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/post-build.sh b/post-build.sh index 9861ac4..dfe92cc 100644 --- a/post-build.sh +++ b/post-build.sh @@ -10,10 +10,15 @@ cd $(dirname "$0") mkdir -p .libs +libmocka_folder=$(pwd)/test/lib/cmocka/build/src/ + if [ "$(uname)" = "Darwin" ]; then - ln -sf $(pwd)/test/lib/cmocka/build/src/libcmocka.0.dylib \ - .libs/libcmocka.0.dylib; + libcmocka=libcmocka.0.dylib else - ln -sf $(pwd)/test/lib/cmocka/build/src/libcmocka.so.0 \ - .libs/libcmocka.so.0; + libcmocka=libcmocka.so.0 +fi + +libcmocka_fullpath="$libmocka_folder$libcmocka" +if [ ! -f libcmocka ]; then + ln -sf libcmocka .libs/$libcmocka; fi From 010e887946a1e294739117a8474050626cc3821d Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 28 Apr 2019 19:21:13 +0300 Subject: [PATCH 265/292] build: don't link libcmocka if not exists --- post-build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/post-build.sh b/post-build.sh index dfe92cc..880f7aa 100644 --- a/post-build.sh +++ b/post-build.sh @@ -19,6 +19,6 @@ else fi libcmocka_fullpath="$libmocka_folder$libcmocka" -if [ ! -f libcmocka ]; then - ln -sf libcmocka .libs/$libcmocka; +if [ ! -f libcmocka_fullpath ]; then + ln -sf libcmocka_fullpath .libs/$libcmocka; fi From a5f1ed32afe55144e2cfe14cc8a1b2be3afeaa55 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 28 Apr 2019 19:24:09 +0300 Subject: [PATCH 266/292] build: don't link libcmocka if not exists --- post-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post-build.sh b/post-build.sh index 880f7aa..2374189 100644 --- a/post-build.sh +++ b/post-build.sh @@ -20,5 +20,5 @@ fi libcmocka_fullpath="$libmocka_folder$libcmocka" if [ ! -f libcmocka_fullpath ]; then - ln -sf libcmocka_fullpath .libs/$libcmocka; + ln -sf $libcmocka_fullpath .libs/$libcmocka; fi From 120ae9ae99f9e27c5956e9969b88ff2c8be6ae2c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 28 Apr 2019 19:43:58 +0300 Subject: [PATCH 267/292] buil: fix linking cmocka --- post-build.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/post-build.sh b/post-build.sh index 2374189..6fa6e7a 100644 --- a/post-build.sh +++ b/post-build.sh @@ -8,7 +8,7 @@ cd $(dirname "$0") -mkdir -p .libs +mkdir -p "$(pwd)/.libs" libmocka_folder=$(pwd)/test/lib/cmocka/build/src/ @@ -18,7 +18,7 @@ else libcmocka=libcmocka.so.0 fi -libcmocka_fullpath="$libmocka_folder$libcmocka" -if [ ! -f libcmocka_fullpath ]; then - ln -sf $libcmocka_fullpath .libs/$libcmocka; +libcmocka_path="$libmocka_folder$libcmocka" +if [ -f "$libcmocka_path" ]; then + ln -sf "$libcmocka_path" "$(pwd)/.libs/$libcmocka"; fi From 392565f9206c7b9b6ad2d452f17fe9b5bb44fafe Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sun, 28 Apr 2019 21:48:19 +0300 Subject: [PATCH 268/292] mark readonly parameters as const (continue) --- include/cglm/call/affine.h | 38 +++++++------- include/cglm/call/box.h | 32 ++++++------ include/cglm/call/cam.h | 38 +++++++------- include/cglm/call/curve.h | 2 +- include/cglm/call/euler.h | 18 +++---- include/cglm/call/frustum.h | 16 +++--- include/cglm/call/io.h | 20 ++++---- include/cglm/call/mat3.h | 20 ++++---- include/cglm/call/mat4.h | 38 +++++++------- include/cglm/call/project.h | 6 +-- include/cglm/call/quat.h | 64 ++++++++++++------------ include/cglm/call/sphere.h | 10 ++-- include/cglm/call/vec3.h | 98 ++++++++++++++++++------------------- include/cglm/call/vec4.h | 82 +++++++++++++++---------------- include/cglm/cam.h | 24 ++++----- include/cglm/io.h | 28 +++++------ include/cglm/mat3.h | 20 ++++---- src/affine.c | 38 +++++++------- src/box.c | 32 ++++++------ src/cam.c | 44 ++++++++--------- src/curve.c | 2 +- src/euler.c | 18 +++---- src/frustum.c | 16 +++--- src/io.c | 20 ++++---- src/mat3.c | 20 ++++---- src/mat4.c | 38 +++++++------- src/project.c | 6 +-- src/quat.c | 64 ++++++++++++------------ src/sphere.c | 10 ++-- src/vec3.c | 98 ++++++++++++++++++------------------- src/vec4.c | 82 +++++++++++++++---------------- 31 files changed, 525 insertions(+), 517 deletions(-) diff --git a/include/cglm/call/affine.h b/include/cglm/call/affine.h index c11405b..ec50bc4 100644 --- a/include/cglm/call/affine.h +++ b/include/cglm/call/affine.h @@ -15,15 +15,15 @@ extern "C" { CGLM_EXPORT void -glmc_translate_make(mat4 m, vec3 v); +glmc_translate_make(mat4 m, const vec3 v); CGLM_EXPORT void -glmc_translate_to(mat4 m, vec3 v, mat4 dest); +glmc_translate_to(const mat4 m, const vec3 v, mat4 dest); CGLM_EXPORT void -glmc_translate(mat4 m, vec3 v); +glmc_translate(mat4 m, const vec3 v); CGLM_EXPORT void @@ -39,15 +39,15 @@ glmc_translate_z(mat4 m, float to); CGLM_EXPORT void -glmc_scale_make(mat4 m, vec3 v); +glmc_scale_make(mat4 m, const vec3 v); CGLM_EXPORT void -glmc_scale_to(mat4 m, vec3 v, mat4 dest); +glmc_scale_to(const mat4 m, const vec3 v, mat4 dest); CGLM_EXPORT void -glmc_scale(mat4 m, vec3 v); +glmc_scale(mat4 m, const vec3 v); CGLM_EXPORT void @@ -55,57 +55,57 @@ glmc_scale_uni(mat4 m, float s); CGLM_EXPORT void -glmc_rotate_x(mat4 m, float rad, mat4 dest); +glmc_rotate_x(const mat4 m, float rad, mat4 dest); CGLM_EXPORT void -glmc_rotate_y(mat4 m, float rad, mat4 dest); +glmc_rotate_y(const mat4 m, float rad, mat4 dest); CGLM_EXPORT void -glmc_rotate_z(mat4 m, float rad, mat4 dest); +glmc_rotate_z(const mat4 m, float rad, mat4 dest); CGLM_EXPORT void -glmc_rotate_make(mat4 m, float angle, vec3 axis); +glmc_rotate_make(mat4 m, float angle, const vec3 axis); CGLM_EXPORT void -glmc_rotate(mat4 m, float angle, vec3 axis); +glmc_rotate(mat4 m, float angle, const vec3 axis); CGLM_EXPORT void -glmc_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis); +glmc_rotate_at(mat4 m, const vec3 pivot, float angle, const vec3 axis); CGLM_EXPORT void -glmc_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis); +glmc_rotate_atm(mat4 m, const vec3 pivot, float angle, const vec3 axis); CGLM_EXPORT void -glmc_decompose_scalev(mat4 m, vec3 s); +glmc_decompose_scalev(const mat4 m, vec3 s); CGLM_EXPORT bool -glmc_uniscaled(mat4 m); +glmc_uniscaled(const mat4 m); CGLM_EXPORT void -glmc_decompose_rs(mat4 m, mat4 r, vec3 s); +glmc_decompose_rs(const mat4 m, mat4 r, vec3 s); CGLM_EXPORT void -glmc_decompose(mat4 m, vec4 t, mat4 r, vec3 s); +glmc_decompose(const mat4 m, vec4 t, mat4 r, vec3 s); /* affine-mat */ CGLM_EXPORT void -glmc_mul(mat4 m1, mat4 m2, mat4 dest); +glmc_mul(const mat4 m1, const mat4 m2, mat4 dest); CGLM_EXPORT void -glmc_mul_rot(mat4 m1, mat4 m2, mat4 dest); +glmc_mul_rot(const mat4 m1, const mat4 m2, mat4 dest); CGLM_EXPORT void diff --git a/include/cglm/call/box.h b/include/cglm/call/box.h index afb7558..fe4ab90 100644 --- a/include/cglm/call/box.h +++ b/include/cglm/call/box.h @@ -15,26 +15,26 @@ extern "C" { CGLM_EXPORT void -glmc_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]); +glmc_aabb_transform(const vec3 box[2], const mat4 m, vec3 dest[2]); CGLM_EXPORT void -glmc_aabb_merge(vec3 box1[2], vec3 box2[2], vec3 dest[2]); +glmc_aabb_merge(const vec3 box1[2], const vec3 box2[2], vec3 dest[2]); CGLM_EXPORT void -glmc_aabb_crop(vec3 box[2], vec3 cropBox[2], vec3 dest[2]); +glmc_aabb_crop(const vec3 box[2], const vec3 cropBox[2], vec3 dest[2]); CGLM_EXPORT void -glmc_aabb_crop_until(vec3 box[2], - vec3 cropBox[2], - vec3 clampBox[2], - vec3 dest[2]); +glmc_aabb_crop_until(const vec3 box[2], + const vec3 cropBox[2], + const vec3 clampBox[2], + vec3 dest[2]); CGLM_EXPORT bool -glmc_aabb_frustum(vec3 box[2], vec4 planes[6]); +glmc_aabb_frustum(const vec3 box[2], vec4 planes[6]); CGLM_EXPORT void @@ -42,35 +42,35 @@ glmc_aabb_invalidate(vec3 box[2]); CGLM_EXPORT bool -glmc_aabb_isvalid(vec3 box[2]); +glmc_aabb_isvalid(const vec3 box[2]); CGLM_EXPORT float -glmc_aabb_size(vec3 box[2]); +glmc_aabb_size(const vec3 box[2]); CGLM_EXPORT float -glmc_aabb_radius(vec3 box[2]); +glmc_aabb_radius(const vec3 box[2]); CGLM_EXPORT void -glmc_aabb_center(vec3 box[2], vec3 dest); +glmc_aabb_center(const vec3 box[2], vec3 dest); CGLM_EXPORT bool -glmc_aabb_aabb(vec3 box[2], vec3 other[2]); +glmc_aabb_aabb(const vec3 box[2], const vec3 other[2]); CGLM_EXPORT bool -glmc_aabb_point(vec3 box[2], vec3 point); +glmc_aabb_point(const vec3 box[2], const vec3 point); CGLM_EXPORT bool -glmc_aabb_contains(vec3 box[2], vec3 other[2]); +glmc_aabb_contains(const vec3 box[2], const vec3 other[2]); CGLM_EXPORT bool -glmc_aabb_sphere(vec3 box[2], vec4 s); +glmc_aabb_sphere(const vec3 box[2], const vec4 s); #ifdef __cplusplus } diff --git a/include/cglm/call/cam.h b/include/cglm/call/cam.h index 017b6fc..9b42b74 100644 --- a/include/cglm/call/cam.h +++ b/include/cglm/call/cam.h @@ -21,7 +21,7 @@ glmc_frustum(float left, float top, float nearVal, float farVal, - mat4 dest); + mat4 dest); CGLM_EXPORT void @@ -31,19 +31,19 @@ glmc_ortho(float left, float top, float nearVal, float farVal, - mat4 dest); + mat4 dest); CGLM_EXPORT void -glmc_ortho_aabb(vec3 box[2], mat4 dest); +glmc_ortho_aabb(const vec3 box[2], mat4 dest); CGLM_EXPORT void -glmc_ortho_aabb_p(vec3 box[2], float padding, mat4 dest); +glmc_ortho_aabb_p(const vec3 box[2], float padding, mat4 dest); CGLM_EXPORT void -glmc_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest); +glmc_ortho_aabb_pz(const vec3 box[2], float padding, mat4 dest); CGLM_EXPORT void @@ -59,7 +59,7 @@ glmc_perspective(float fovy, float aspect, float nearVal, float farVal, - mat4 dest); + mat4 dest); CGLM_EXPORT void @@ -75,19 +75,19 @@ glmc_perspective_resize(float aspect, mat4 proj); CGLM_EXPORT void -glmc_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest); +glmc_lookat(const vec3 eye, const vec3 center, const vec3 up, mat4 dest); CGLM_EXPORT void -glmc_look(vec3 eye, vec3 dir, vec3 up, mat4 dest); +glmc_look(const vec3 eye, const vec3 dir, const vec3 up, mat4 dest); CGLM_EXPORT void -glmc_look_anyup(vec3 eye, vec3 dir, mat4 dest); +glmc_look_anyup(const vec3 eye, const vec3 dir, mat4 dest); CGLM_EXPORT void -glmc_persp_decomp(mat4 proj, +glmc_persp_decomp(const mat4 proj, float * __restrict nearVal, float * __restrict farVal, float * __restrict top, @@ -97,45 +97,45 @@ glmc_persp_decomp(mat4 proj, CGLM_EXPORT void -glmc_persp_decompv(mat4 proj, float dest[6]); +glmc_persp_decompv(const mat4 proj, float dest[6]); CGLM_EXPORT void -glmc_persp_decomp_x(mat4 proj, +glmc_persp_decomp_x(const mat4 proj, float * __restrict left, float * __restrict right); CGLM_EXPORT void -glmc_persp_decomp_y(mat4 proj, +glmc_persp_decomp_y(const mat4 proj, float * __restrict top, float * __restrict bottom); CGLM_EXPORT void -glmc_persp_decomp_z(mat4 proj, +glmc_persp_decomp_z(const mat4 proj, float * __restrict nearVal, float * __restrict farVal); CGLM_EXPORT void -glmc_persp_decomp_far(mat4 proj, float * __restrict farVal); +glmc_persp_decomp_far(const mat4 proj, float * __restrict farVal); CGLM_EXPORT void -glmc_persp_decomp_near(mat4 proj, float * __restrict nearVal); +glmc_persp_decomp_near(const mat4 proj, float * __restrict nearVal); CGLM_EXPORT float -glmc_persp_fovy(mat4 proj); +glmc_persp_fovy(const mat4 proj); CGLM_EXPORT float -glmc_persp_aspect(mat4 proj); +glmc_persp_aspect(const mat4 proj); CGLM_EXPORT void -glmc_persp_sizes(mat4 proj, float fovy, vec4 dest); +glmc_persp_sizes(const mat4 proj, float fovy, vec4 dest); #ifdef __cplusplus } diff --git a/include/cglm/call/curve.h b/include/cglm/call/curve.h index 061fdb9..07610f3 100644 --- a/include/cglm/call/curve.h +++ b/include/cglm/call/curve.h @@ -15,7 +15,7 @@ extern "C" { CGLM_EXPORT float -glmc_smc(float s, mat4 m, vec4 c); +glmc_smc(float s, const mat4 m, const vec4 c); #ifdef __cplusplus } diff --git a/include/cglm/call/euler.h b/include/cglm/call/euler.h index 9b85485..71746bf 100644 --- a/include/cglm/call/euler.h +++ b/include/cglm/call/euler.h @@ -15,39 +15,39 @@ extern "C" { CGLM_EXPORT void -glmc_euler_angles(mat4 m, vec3 dest); +glmc_euler_angles(const mat4 m, vec3 dest); CGLM_EXPORT void -glmc_euler(vec3 angles, mat4 dest); +glmc_euler(const vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_xyz(vec3 angles, mat4 dest); +glmc_euler_xyz(const vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_zyx(vec3 angles, mat4 dest); +glmc_euler_zyx(const vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_zxy(vec3 angles, mat4 dest); +glmc_euler_zxy(const vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_xzy(vec3 angles, mat4 dest); +glmc_euler_xzy(const vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_yzx(vec3 angles, mat4 dest); +glmc_euler_yzx(const vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_yxz(vec3 angles, mat4 dest); +glmc_euler_yxz(const vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_by_order(vec3 angles, glm_euler_sq axis, mat4 dest); +glmc_euler_by_order(const vec3 angles, glm_euler_sq axis, mat4 dest); #ifdef __cplusplus } diff --git a/include/cglm/call/frustum.h b/include/cglm/call/frustum.h index 6b4facb..be97fc3 100644 --- a/include/cglm/call/frustum.h +++ b/include/cglm/call/frustum.h @@ -15,26 +15,26 @@ extern "C" { CGLM_EXPORT void -glmc_frustum_planes(mat4 m, vec4 dest[6]); +glmc_frustum_planes(const mat4 m, vec4 dest[6]); CGLM_EXPORT void -glmc_frustum_corners(mat4 invMat, vec4 dest[8]); +glmc_frustum_corners(const mat4 invMat, vec4 dest[8]); CGLM_EXPORT void -glmc_frustum_center(vec4 corners[8], vec4 dest); +glmc_frustum_center(const vec4 corners[8], vec4 dest); CGLM_EXPORT void -glmc_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]); +glmc_frustum_box(const vec4 corners[8], const mat4 m, vec3 box[2]); CGLM_EXPORT void -glmc_frustum_corners_at(vec4 corners[8], - float splitDist, - float farDist, - vec4 planeCorners[4]); +glmc_frustum_corners_at(const vec4 corners[8], + float splitDist, + float farDist, + vec4 planeCorners[4]); #ifdef __cplusplus } #endif diff --git a/include/cglm/call/io.h b/include/cglm/call/io.h index b6c50f6..421e719 100644 --- a/include/cglm/call/io.h +++ b/include/cglm/call/io.h @@ -15,28 +15,28 @@ extern "C" { CGLM_EXPORT void -glmc_mat4_print(mat4 matrix, - FILE * __restrict ostream); +glmc_mat4_print(const mat4 matrix, + FILE * const __restrict ostream); CGLM_EXPORT void -glmc_mat3_print(mat3 matrix, - FILE * __restrict ostream); +glmc_mat3_print(const mat3 matrix, + FILE * const __restrict ostream); CGLM_EXPORT void -glmc_vec4_print(vec4 vec, - FILE * __restrict ostream); +glmc_vec4_print(const vec4 vec, + FILE * const __restrict ostream); CGLM_EXPORT void -glmc_vec3_print(vec3 vec, - FILE * __restrict ostream); +glmc_vec3_print(const vec3 vec, + FILE * const __restrict ostream); CGLM_EXPORT void -glmc_versor_print(versor vec, - FILE * __restrict ostream); +glmc_versor_print(const versor vec, + FILE * const __restrict ostream); #ifdef __cplusplus } diff --git a/include/cglm/call/mat3.h b/include/cglm/call/mat3.h index fbd8270..68d5535 100644 --- a/include/cglm/call/mat3.h +++ b/include/cglm/call/mat3.h @@ -18,7 +18,7 @@ extern "C" { CGLM_EXPORT void -glmc_mat3_copy(mat3 mat, mat3 dest); +glmc_mat3_copy(const mat3 mat, mat3 dest); CGLM_EXPORT void @@ -26,15 +26,15 @@ glmc_mat3_identity(mat3 mat); CGLM_EXPORT void -glmc_mat3_identity_array(mat3 * __restrict mat, size_t count); +glmc_mat3_identity_array(mat3 * const __restrict mat, size_t count); CGLM_EXPORT void -glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest); +glmc_mat3_mul(const mat3 m1, const mat3 m2, mat3 dest); CGLM_EXPORT void -glmc_mat3_transpose_to(mat3 m, mat3 dest); +glmc_mat3_transpose_to(const mat3 m, mat3 dest); CGLM_EXPORT void @@ -42,15 +42,15 @@ glmc_mat3_transpose(mat3 m); CGLM_EXPORT void -glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest); +glmc_mat3_mulv(const mat3 m, const vec3 v, vec3 dest); CGLM_EXPORT float -glmc_mat3_trace(mat3 m); +glmc_mat3_trace(const mat3 m); CGLM_EXPORT void -glmc_mat3_quat(mat3 m, versor dest); +glmc_mat3_quat(const mat3 m, versor dest); CGLM_EXPORT void @@ -58,11 +58,11 @@ glmc_mat3_scale(mat3 m, float s); CGLM_EXPORT float -glmc_mat3_det(mat3 mat); +glmc_mat3_det(const mat3 mat); CGLM_EXPORT void -glmc_mat3_inv(mat3 mat, mat3 dest); +glmc_mat3_inv(const mat3 mat, mat3 dest); CGLM_EXPORT void @@ -74,7 +74,7 @@ glmc_mat3_swap_row(mat3 mat, int row1, int row2); CGLM_EXPORT float -glmc_mat3_rmc(vec3 r, mat3 m, vec3 c); +glmc_mat3_rmc(const vec3 r, const mat3 m, const vec3 c); #ifdef __cplusplus } diff --git a/include/cglm/call/mat4.h b/include/cglm/call/mat4.h index 54fbcbe..43e4cec 100644 --- a/include/cglm/call/mat4.h +++ b/include/cglm/call/mat4.h @@ -19,11 +19,11 @@ extern "C" { CGLM_EXPORT void -glmc_mat4_ucopy(mat4 mat, mat4 dest); +glmc_mat4_ucopy(const mat4 mat, mat4 dest); CGLM_EXPORT void -glmc_mat4_copy(mat4 mat, mat4 dest); +glmc_mat4_copy(const mat4 mat, mat4 dest); CGLM_EXPORT void @@ -31,51 +31,51 @@ glmc_mat4_identity(mat4 mat); CGLM_EXPORT void -glmc_mat4_identity_array(mat4 * __restrict mat, size_t count); +glmc_mat4_identity_array(mat4 * const __restrict mat, size_t count); CGLM_EXPORT void -glmc_mat4_pick3(mat4 mat, mat3 dest); +glmc_mat4_pick3(const mat4 mat, mat3 dest); CGLM_EXPORT void -glmc_mat4_pick3t(mat4 mat, mat3 dest); +glmc_mat4_pick3t(const mat4 mat, mat3 dest); CGLM_EXPORT void -glmc_mat4_ins3(mat3 mat, mat4 dest); +glmc_mat4_ins3(const mat3 mat, mat4 dest); CGLM_EXPORT void -glmc_mat4_mul(mat4 m1, mat4 m2, mat4 dest); +glmc_mat4_mul(const mat4 m1, const mat4 m2, mat4 dest); CGLM_EXPORT void -glmc_mat4_mulN(mat4 * __restrict matrices[], uint32_t len, mat4 dest); +glmc_mat4_mulN(mat4 * const __restrict matrices[], uint32_t len, mat4 dest); CGLM_EXPORT void -glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest); +glmc_mat4_mulv(const mat4 m, const vec4 v, vec4 dest); CGLM_EXPORT void -glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest); +glmc_mat4_mulv3(const mat4 m, const vec3 v, float last, vec3 dest); CGLM_EXPORT float -glmc_mat4_trace(mat4 m); +glmc_mat4_trace(const mat4 m); CGLM_EXPORT float -glmc_mat4_trace3(mat4 m); +glmc_mat4_trace3(const mat4 m); CGLM_EXPORT void -glmc_mat4_quat(mat4 m, versor dest); +glmc_mat4_quat(const mat4 m, versor dest); CGLM_EXPORT void -glmc_mat4_transpose_to(mat4 m, mat4 dest); +glmc_mat4_transpose_to(const mat4 m, mat4 dest); CGLM_EXPORT void @@ -91,19 +91,19 @@ glmc_mat4_scale(mat4 m, float s); CGLM_EXPORT float -glmc_mat4_det(mat4 mat); +glmc_mat4_det(const mat4 mat); CGLM_EXPORT void -glmc_mat4_inv(mat4 mat, mat4 dest); +glmc_mat4_inv(const mat4 mat, mat4 dest); CGLM_EXPORT void -glmc_mat4_inv_precise(mat4 mat, mat4 dest); +glmc_mat4_inv_precise(const mat4 mat, mat4 dest); CGLM_EXPORT void -glmc_mat4_inv_fast(mat4 mat, mat4 dest); +glmc_mat4_inv_fast(const mat4 mat, mat4 dest); CGLM_EXPORT void @@ -115,7 +115,7 @@ glmc_mat4_swap_row(mat4 mat, int row1, int row2); CGLM_EXPORT float -glmc_mat4_rmc(vec4 r, mat4 m, vec4 c); +glmc_mat4_rmc(const vec4 r, const mat4 m, const vec4 c); #ifdef __cplusplus } diff --git a/include/cglm/call/project.h b/include/cglm/call/project.h index 35ac087..92c25e1 100644 --- a/include/cglm/call/project.h +++ b/include/cglm/call/project.h @@ -15,15 +15,15 @@ extern "C" { CGLM_EXPORT void -glmc_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest); +glmc_unprojecti(const vec3 pos, const mat4 invMat, const vec4 vp, vec3 dest); CGLM_EXPORT void -glmc_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest); +glmc_unproject(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest); CGLM_EXPORT void -glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest); +glmc_project(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest); #ifdef __cplusplus } diff --git a/include/cglm/call/quat.h b/include/cglm/call/quat.h index 2778a58..03d8381 100644 --- a/include/cglm/call/quat.h +++ b/include/cglm/call/quat.h @@ -19,7 +19,7 @@ glmc_quat_identity(versor q); CGLM_EXPORT void -glmc_quat_identity_array(versor * __restrict q, size_t count); +glmc_quat_identity_array(versor * const __restrict q, size_t count); CGLM_EXPORT void @@ -31,19 +31,19 @@ glmc_quat(versor q, float angle, float x, float y, float z); CGLM_EXPORT void -glmc_quatv(versor q, float angle, vec3 axis); +glmc_quatv(versor q, float angle, const vec3 axis); CGLM_EXPORT void -glmc_quat_copy(versor q, versor dest); +glmc_quat_copy(const versor q, versor dest); CGLM_EXPORT float -glmc_quat_norm(versor q); +glmc_quat_norm(const versor q); CGLM_EXPORT void -glmc_quat_normalize_to(versor q, versor dest); +glmc_quat_normalize_to(const versor q, versor dest); CGLM_EXPORT void @@ -51,103 +51,107 @@ glmc_quat_normalize(versor q); CGLM_EXPORT float -glmc_quat_dot(versor p, versor q); +glmc_quat_dot(const versor p, const versor q); CGLM_EXPORT void -glmc_quat_conjugate(versor q, versor dest); +glmc_quat_conjugate(const versor q, versor dest); CGLM_EXPORT void -glmc_quat_inv(versor q, versor dest); +glmc_quat_inv(const versor q, versor dest); CGLM_EXPORT void -glmc_quat_add(versor p, versor q, versor dest); +glmc_quat_add(const versor p, const versor q, versor dest); CGLM_EXPORT void -glmc_quat_sub(versor p, versor q, versor dest); +glmc_quat_sub(const versor p, const versor q, versor dest); CGLM_EXPORT float -glmc_quat_real(versor q); +glmc_quat_real(const versor q); CGLM_EXPORT void -glmc_quat_imag(versor q, vec3 dest); +glmc_quat_imag(const versor q, vec3 dest); CGLM_EXPORT void -glmc_quat_imagn(versor q, vec3 dest); +glmc_quat_imagn(const versor q, vec3 dest); CGLM_EXPORT float -glmc_quat_imaglen(versor q); +glmc_quat_imaglen(const versor q); CGLM_EXPORT float -glmc_quat_angle(versor q); +glmc_quat_angle(const versor q); CGLM_EXPORT void -glmc_quat_axis(versor q, versor dest); +glmc_quat_axis(const versor q, versor dest); CGLM_EXPORT void -glmc_quat_mul(versor p, versor q, versor dest); +glmc_quat_mul(const versor p, const versor q, versor dest); CGLM_EXPORT void -glmc_quat_mat4(versor q, mat4 dest); +glmc_quat_mat4(const versor q, mat4 dest); CGLM_EXPORT void -glmc_quat_mat4t(versor q, mat4 dest); +glmc_quat_mat4t(const versor q, mat4 dest); CGLM_EXPORT void -glmc_quat_mat3(versor q, mat3 dest); +glmc_quat_mat3(const versor q, mat3 dest); CGLM_EXPORT void -glmc_quat_mat3t(versor q, mat3 dest); +glmc_quat_mat3t(const versor q, mat3 dest); CGLM_EXPORT void -glmc_quat_lerp(versor from, versor to, float t, versor dest); +glmc_quat_lerp(const versor from, const versor to, float t, versor dest); CGLM_EXPORT void -glmc_quat_slerp(versor q, versor r, float t, versor dest); +glmc_quat_slerp(const versor q, const versor r, float t, versor dest); CGLM_EXPORT void -glmc_quat_look(vec3 eye, versor ori, mat4 dest); +glmc_quat_look(const vec3 eye, const versor ori, mat4 dest); CGLM_EXPORT void -glmc_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest); +glmc_quat_for(const vec3 dir, const vec3 fwd, const vec3 up, versor dest); CGLM_EXPORT void -glmc_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest); +glmc_quat_forp(const vec3 from, + const vec3 to, + const vec3 fwd, + const vec3 up, + versor dest); CGLM_EXPORT void -glmc_quat_rotatev(versor from, vec3 to, vec3 dest); +glmc_quat_rotatev(const versor from, const vec3 to, vec3 dest); CGLM_EXPORT void -glmc_quat_rotate(mat4 m, versor q, mat4 dest); +glmc_quat_rotate(const mat4 m, const versor q, mat4 dest); CGLM_EXPORT void -glmc_quat_rotate_at(mat4 model, versor q, vec3 pivot); +glmc_quat_rotate_at(mat4 model, const versor q, const vec3 pivot); CGLM_EXPORT void -glmc_quat_rotate_atm(mat4 m, versor q, vec3 pivot); +glmc_quat_rotate_atm(mat4 m, const versor q, const vec3 pivot); #ifdef __cplusplus } diff --git a/include/cglm/call/sphere.h b/include/cglm/call/sphere.h index 9b96546..7b4d0d7 100644 --- a/include/cglm/call/sphere.h +++ b/include/cglm/call/sphere.h @@ -15,23 +15,23 @@ extern "C" { CGLM_EXPORT float -glmc_sphere_radii(vec4 s); +glmc_sphere_radii(const vec4 s); CGLM_EXPORT void -glmc_sphere_transform(vec4 s, mat4 m, vec4 dest); +glmc_sphere_transform(const vec4 s, const mat4 m, vec4 dest); CGLM_EXPORT void -glmc_sphere_merge(vec4 s1, vec4 s2, vec4 dest); +glmc_sphere_merge(const vec4 s1, const vec4 s2, vec4 dest); CGLM_EXPORT bool -glmc_sphere_sphere(vec4 s1, vec4 s2); +glmc_sphere_sphere(const vec4 s1, const vec4 s2); CGLM_EXPORT bool -glmc_sphere_point(vec4 s, vec3 point); +glmc_sphere_point(const vec4 s, const vec3 point); #ifdef __cplusplus } diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 9763403..cc7c78e 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -22,11 +22,11 @@ extern "C" { CGLM_EXPORT void -glmc_vec3(vec4 v4, vec3 dest); +glmc_vec3(const vec4 v4, vec3 dest); CGLM_EXPORT void -glmc_vec3_copy(vec3 a, vec3 dest); +glmc_vec3_copy(const vec3 a, vec3 dest); CGLM_EXPORT void @@ -38,27 +38,27 @@ glmc_vec3_one(vec3 v); CGLM_EXPORT float -glmc_vec3_dot(vec3 a, vec3 b); +glmc_vec3_dot(const vec3 a, const vec3 b); CGLM_EXPORT void -glmc_vec3_cross(vec3 a, vec3 b, vec3 dest); +glmc_vec3_cross(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_crossn(vec3 a, vec3 b, vec3 dest); +glmc_vec3_crossn(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT float -glmc_vec3_norm(vec3 v); +glmc_vec3_norm(const vec3 v); CGLM_EXPORT float -glmc_vec3_norm2(vec3 v); +glmc_vec3_norm2(const vec3 v); CGLM_EXPORT void -glmc_vec3_normalize_to(vec3 v, vec3 dest); +glmc_vec3_normalize_to(const vec3 v, vec3 dest); CGLM_EXPORT void @@ -66,63 +66,63 @@ glmc_vec3_normalize(vec3 v); CGLM_EXPORT void -glmc_vec3_add(vec3 a, vec3 b, vec3 dest); +glmc_vec3_add(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_adds(vec3 v, float s, vec3 dest); +glmc_vec3_adds(const vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec3_sub(vec3 a, vec3 b, vec3 dest); +glmc_vec3_sub(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_subs(vec3 v, float s, vec3 dest); +glmc_vec3_subs(const vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec3_mul(vec3 a, vec3 b, vec3 d); +glmc_vec3_mul(const vec3 a, const vec3 b, vec3 d); CGLM_EXPORT void -glmc_vec3_scale(vec3 v, float s, vec3 dest); +glmc_vec3_scale(const vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec3_scale_as(vec3 v, float s, vec3 dest); +glmc_vec3_scale_as(const vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec3_div(vec3 a, vec3 b, vec3 dest); +glmc_vec3_div(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_divs(vec3 a, float s, vec3 dest); +glmc_vec3_divs(const vec3 a, float s, vec3 dest); CGLM_EXPORT void -glmc_vec3_addadd(vec3 a, vec3 b, vec3 dest); +glmc_vec3_addadd(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_subadd(vec3 a, vec3 b, vec3 dest); +glmc_vec3_subadd(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_muladd(vec3 a, vec3 b, vec3 dest); +glmc_vec3_muladd(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_muladds(vec3 a, float s, vec3 dest); +glmc_vec3_muladds(const vec3 a, float s, vec3 dest); CGLM_EXPORT void -glmc_vec3_maxadd(vec3 a, vec3 b, vec3 dest); +glmc_vec3_maxadd(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_minadd(vec3 a, vec3 b, vec3 dest); +glmc_vec3_minadd(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT void @@ -130,47 +130,47 @@ glmc_vec3_negate(vec3 v); CGLM_EXPORT void -glmc_vec3_negate_to(vec3 v, vec3 dest); +glmc_vec3_negate_to(const vec3 v, vec3 dest); CGLM_EXPORT float -glmc_vec3_angle(vec3 a, vec3 b); +glmc_vec3_angle(const vec3 a, const vec3 b); CGLM_EXPORT void -glmc_vec3_rotate(vec3 v, float angle, vec3 axis); +glmc_vec3_rotate(vec3 v, float angle, const vec3 axis); CGLM_EXPORT void -glmc_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest); +glmc_vec3_rotate_m4(const mat4 m, const vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest); +glmc_vec3_rotate_m3(const mat3 m, const vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec3_proj(vec3 a, vec3 b, vec3 dest); +glmc_vec3_proj(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_center(vec3 a, vec3 b, vec3 dest); +glmc_vec3_center(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT float -glmc_vec3_distance2(vec3 a, vec3 b); +glmc_vec3_distance2(const vec3 a, const vec3 b); CGLM_EXPORT float -glmc_vec3_distance(vec3 a, vec3 b); +glmc_vec3_distance(const vec3 a, const vec3 b); CGLM_EXPORT void -glmc_vec3_maxv(vec3 a, vec3 b, vec3 dest); +glmc_vec3_maxv(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_minv(vec3 a, vec3 b, vec3 dest); +glmc_vec3_minv(const vec3 a, const vec3 b, vec3 dest); CGLM_EXPORT void @@ -178,17 +178,17 @@ glmc_vec3_clamp(vec3 v, float minVal, float maxVal); CGLM_EXPORT void -glmc_vec3_ortho(vec3 v, vec3 dest); +glmc_vec3_ortho(const vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest); +glmc_vec3_lerp(const vec3 from, const vec3 to, float t, vec3 dest); /* ext */ CGLM_EXPORT void -glmc_vec3_mulv(vec3 a, vec3 b, vec3 d); +glmc_vec3_mulv(const vec3 a, const vec3 b, vec3 d); CGLM_EXPORT void @@ -196,51 +196,51 @@ glmc_vec3_broadcast(float val, vec3 d); CGLM_EXPORT bool -glmc_vec3_eq(vec3 v, float val); +glmc_vec3_eq(const vec3 v, float val); CGLM_EXPORT bool -glmc_vec3_eq_eps(vec3 v, float val); +glmc_vec3_eq_eps(const vec3 v, float val); CGLM_EXPORT bool -glmc_vec3_eq_all(vec3 v); +glmc_vec3_eq_all(const vec3 v); CGLM_EXPORT bool -glmc_vec3_eqv(vec3 a, vec3 b); +glmc_vec3_eqv(const vec3 a, const vec3 b); CGLM_EXPORT bool -glmc_vec3_eqv_eps(vec3 a, vec3 b); +glmc_vec3_eqv_eps(const vec3 a, const vec3 b); CGLM_EXPORT float -glmc_vec3_max(vec3 v); +glmc_vec3_max(const vec3 v); CGLM_EXPORT float -glmc_vec3_min(vec3 v); +glmc_vec3_min(const vec3 v); CGLM_EXPORT bool -glmc_vec3_isnan(vec3 v); +glmc_vec3_isnan(const vec3 v); CGLM_EXPORT bool -glmc_vec3_isinf(vec3 v); +glmc_vec3_isinf(const vec3 v); CGLM_EXPORT bool -glmc_vec3_isvalid(vec3 v); +glmc_vec3_isvalid(const vec3 v); CGLM_EXPORT void -glmc_vec3_sign(vec3 v, vec3 dest); +glmc_vec3_sign(const vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec3_sqrt(vec3 v, vec3 dest); +glmc_vec3_sqrt(const vec3 v, vec3 dest); #ifdef __cplusplus } diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index 936bb52..c862ce6 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -23,7 +23,7 @@ extern "C" { CGLM_EXPORT void -glmc_vec4(vec3 v3, float last, vec4 dest); +glmc_vec4(const vec3 v3, float last, vec4 dest); CGLM_EXPORT void @@ -35,31 +35,31 @@ glmc_vec4_one(vec4 v); CGLM_EXPORT void -glmc_vec4_copy3(vec4 v, vec3 dest); +glmc_vec4_copy3(const vec4 v, vec3 dest); CGLM_EXPORT void -glmc_vec4_copy(vec4 v, vec4 dest); +glmc_vec4_copy(const vec4 v, vec4 dest); CGLM_EXPORT void -glmc_vec4_ucopy(vec4 v, vec4 dest); +glmc_vec4_ucopy(const vec4 v, vec4 dest); CGLM_EXPORT float -glmc_vec4_dot(vec4 a, vec4 b); +glmc_vec4_dot(const vec4 a, const vec4 b); CGLM_EXPORT float -glmc_vec4_norm(vec4 v); +glmc_vec4_norm(const vec4 v); CGLM_EXPORT float -glmc_vec4_norm2(vec4 v); +glmc_vec4_norm2(const vec4 v); CGLM_EXPORT void -glmc_vec4_normalize_to(vec4 v, vec4 dest); +glmc_vec4_normalize_to(const vec4 v, vec4 dest); CGLM_EXPORT void @@ -67,63 +67,63 @@ glmc_vec4_normalize(vec4 v); CGLM_EXPORT void -glmc_vec4_add(vec4 a, vec4 b, vec4 dest); +glmc_vec4_add(const vec4 a, const vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_adds(vec4 v, float s, vec4 dest); +glmc_vec4_adds(const vec4 v, float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_sub(vec4 a, vec4 b, vec4 dest); +glmc_vec4_sub(const vec4 a, const vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_subs(vec4 v, float s, vec4 dest); +glmc_vec4_subs(const vec4 v, float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_mul(vec4 a, vec4 b, vec4 d); +glmc_vec4_mul(const vec4 a, const vec4 b, vec4 d); CGLM_EXPORT void -glmc_vec4_scale(vec4 v, float s, vec4 dest); +glmc_vec4_scale(const vec4 v, float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_scale_as(vec3 v, float s, vec3 dest); +glmc_vec4_scale_as(const vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec4_div(vec4 a, vec4 b, vec4 dest); +glmc_vec4_div(const vec4 a, const vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_divs(vec4 v, float s, vec4 dest); +glmc_vec4_divs(const vec4 v, float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_addadd(vec4 a, vec4 b, vec4 dest); +glmc_vec4_addadd(const vec4 a, const vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_subadd(vec4 a, vec4 b, vec4 dest); +glmc_vec4_subadd(const vec4 a, const vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_muladd(vec4 a, vec4 b, vec4 dest); +glmc_vec4_muladd(const vec4 a, const vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_muladds(vec4 a, float s, vec4 dest); +glmc_vec4_muladds(const vec4 a, float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_maxadd(vec4 a, vec4 b, vec4 dest); +glmc_vec4_maxadd(const vec4 a, const vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_minadd(vec4 a, vec4 b, vec4 dest); +glmc_vec4_minadd(const vec4 a, const vec4 b, vec4 dest); CGLM_EXPORT void @@ -131,19 +131,19 @@ glmc_vec4_negate(vec4 v); CGLM_EXPORT void -glmc_vec4_negate_to(vec4 v, vec4 dest); +glmc_vec4_negate_to(const vec4 v, vec4 dest); CGLM_EXPORT float -glmc_vec4_distance(vec4 a, vec4 b); +glmc_vec4_distance(const vec4 a, const vec4 b); CGLM_EXPORT void -glmc_vec4_maxv(vec4 a, vec4 b, vec4 dest); +glmc_vec4_maxv(const vec4 a, const vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_minv(vec4 a, vec4 b, vec4 dest); +glmc_vec4_minv(const vec4 a, const vec4 b, vec4 dest); CGLM_EXPORT void @@ -151,7 +151,7 @@ glmc_vec4_clamp(vec4 v, float minVal, float maxVal); CGLM_EXPORT void -glmc_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest); +glmc_vec4_lerp(const vec4 from, const vec4 to, float t, vec4 dest); CGLM_EXPORT void @@ -161,7 +161,7 @@ glmc_vec4_cubic(float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_mulv(vec4 a, vec4 b, vec4 d); +glmc_vec4_mulv(const vec4 a, const vec4 b, vec4 d); CGLM_EXPORT void @@ -169,51 +169,51 @@ glmc_vec4_broadcast(float val, vec4 d); CGLM_EXPORT bool -glmc_vec4_eq(vec4 v, float val); +glmc_vec4_eq(const vec4 v, float val); CGLM_EXPORT bool -glmc_vec4_eq_eps(vec4 v, float val); +glmc_vec4_eq_eps(const vec4 v, float val); CGLM_EXPORT bool -glmc_vec4_eq_all(vec4 v); +glmc_vec4_eq_all(const vec4 v); CGLM_EXPORT bool -glmc_vec4_eqv(vec4 a, vec4 b); +glmc_vec4_eqv(const vec4 a, const vec4 b); CGLM_EXPORT bool -glmc_vec4_eqv_eps(vec4 a, vec4 b); +glmc_vec4_eqv_eps(const vec4 a, const vec4 b); CGLM_EXPORT float -glmc_vec4_max(vec4 v); +glmc_vec4_max(const vec4 v); CGLM_EXPORT float -glmc_vec4_min(vec4 v); +glmc_vec4_min(const vec4 v); CGLM_EXPORT bool -glmc_vec4_isnan(vec4 v); +glmc_vec4_isnan(const vec4 v); CGLM_EXPORT bool -glmc_vec4_isinf(vec4 v); +glmc_vec4_isinf(const vec4 v); CGLM_EXPORT bool -glmc_vec4_isvalid(vec4 v); +glmc_vec4_isvalid(const vec4 v); CGLM_EXPORT void -glmc_vec4_sign(vec4 v, vec4 dest); +glmc_vec4_sign(const vec4 v, vec4 dest); CGLM_EXPORT void -glmc_vec4_sqrt(vec4 v, vec4 dest); +glmc_vec4_sqrt(const vec4 v, vec4 dest); #ifdef __cplusplus } diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 0e48b16..2255cf6 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -380,7 +380,7 @@ glm_lookat(const vec3 eye, */ CGLM_INLINE void -glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { +glm_look(const vec3 eye, const vec3 dir, const vec3 up, mat4 dest) { CGLM_ALIGN(8) vec3 target; glm_vec3_add(eye, dir, target); glm_lookat(eye, target, up, dest); @@ -398,7 +398,7 @@ glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { */ CGLM_INLINE void -glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) { +glm_look_anyup(const vec3 eye, const vec3 dir, mat4 dest) { CGLM_ALIGN(8) vec3 up; glm_vec3_ortho(dir, up); glm_look(eye, dir, up, dest); @@ -417,7 +417,7 @@ glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) { */ CGLM_INLINE void -glm_persp_decomp(mat4 proj, +glm_persp_decomp(const mat4 proj, float * __restrict nearVal, float * __restrict farVal, float * __restrict top, @@ -457,7 +457,7 @@ glm_persp_decomp(mat4 proj, */ CGLM_INLINE void -glm_persp_decompv(mat4 proj, float dest[6]) { +glm_persp_decompv(const mat4 proj, float dest[6]) { glm_persp_decomp(proj, &dest[0], &dest[1], &dest[2], &dest[3], &dest[4], &dest[5]); } @@ -472,7 +472,7 @@ glm_persp_decompv(mat4 proj, float dest[6]) { */ CGLM_INLINE void -glm_persp_decomp_x(mat4 proj, +glm_persp_decomp_x(const mat4 proj, float * __restrict left, float * __restrict right) { float nearVal, m20, m00; @@ -495,7 +495,7 @@ glm_persp_decomp_x(mat4 proj, */ CGLM_INLINE void -glm_persp_decomp_y(mat4 proj, +glm_persp_decomp_y(const mat4 proj, float * __restrict top, float * __restrict bottom) { float nearVal, m21, m11; @@ -518,7 +518,7 @@ glm_persp_decomp_y(mat4 proj, */ CGLM_INLINE void -glm_persp_decomp_z(mat4 proj, +glm_persp_decomp_z(const mat4 proj, float * __restrict nearVal, float * __restrict farVal) { float m32, m22; @@ -538,7 +538,7 @@ glm_persp_decomp_z(mat4 proj, */ CGLM_INLINE void -glm_persp_decomp_far(mat4 proj, float * __restrict farVal) { +glm_persp_decomp_far(const mat4 proj, float * __restrict farVal) { *farVal = proj[3][2] / (proj[2][2] + 1.0f); } @@ -550,7 +550,7 @@ glm_persp_decomp_far(mat4 proj, float * __restrict farVal) { */ CGLM_INLINE void -glm_persp_decomp_near(mat4 proj, float * __restrict nearVal) { +glm_persp_decomp_near(const mat4 proj, float * __restrict nearVal) { *nearVal = proj[3][2] / (proj[2][2] - 1.0f); } @@ -564,7 +564,7 @@ glm_persp_decomp_near(mat4 proj, float * __restrict nearVal) { */ CGLM_INLINE float -glm_persp_fovy(mat4 proj) { +glm_persp_fovy(const mat4 proj) { return 2.0f * atanf(1.0f / proj[1][1]); } @@ -575,7 +575,7 @@ glm_persp_fovy(mat4 proj) { */ CGLM_INLINE float -glm_persp_aspect(mat4 proj) { +glm_persp_aspect(const mat4 proj) { return proj[1][1] / proj[0][0]; } @@ -588,7 +588,7 @@ glm_persp_aspect(mat4 proj) { */ CGLM_INLINE void -glm_persp_sizes(mat4 proj, float fovy, vec4 dest) { +glm_persp_sizes(const mat4 proj, float fovy, vec4 dest) { float t, a, nearVal, farVal; t = 2.0f * tanf(fovy * 0.5f); diff --git a/include/cglm/io.h b/include/cglm/io.h index ac0bfeb..e51f03c 100644 --- a/include/cglm/io.h +++ b/include/cglm/io.h @@ -25,8 +25,8 @@ CGLM_INLINE void -glm_mat4_print(mat4 matrix, - FILE * __restrict ostream) { +glm_mat4_print(const mat4 matrix, + FILE * const __restrict ostream) { int i; int j; @@ -55,8 +55,8 @@ glm_mat4_print(mat4 matrix, CGLM_INLINE void -glm_mat3_print(mat3 matrix, - FILE * __restrict ostream) { +glm_mat3_print(const mat3 matrix, + FILE * const __restrict ostream) { int i; int j; @@ -85,8 +85,8 @@ glm_mat3_print(mat3 matrix, CGLM_INLINE void -glm_vec4_print(vec4 vec, - FILE * __restrict ostream) { +glm_vec4_print(const vec4 vec, + FILE * const __restrict ostream) { int i; #define m 4 @@ -107,8 +107,8 @@ glm_vec4_print(vec4 vec, CGLM_INLINE void -glm_vec3_print(vec3 vec, - FILE * __restrict ostream) { +glm_vec3_print(const vec3 vec, + FILE * const __restrict ostream) { int i; #define m 3 @@ -129,8 +129,8 @@ glm_vec3_print(vec3 vec, CGLM_INLINE void -glm_ivec3_print(ivec3 vec, - FILE * __restrict ostream) { +glm_ivec3_print(const ivec3 vec, + FILE * const __restrict ostream) { int i; #define m 3 @@ -151,8 +151,8 @@ glm_ivec3_print(ivec3 vec, CGLM_INLINE void -glm_versor_print(versor vec, - FILE * __restrict ostream) { +glm_versor_print(const versor vec, + FILE * const __restrict ostream) { int i; #define m 4 @@ -173,9 +173,9 @@ glm_versor_print(versor vec, CGLM_INLINE void -glm_aabb_print(vec3 bbox[2], +glm_aabb_print(const vec3 bbox[2], const char * __restrict tag, - FILE * __restrict ostream) { + FILE * const __restrict ostream) { int i, j; #define m 3 diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index 3126064..f1597fd 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -65,7 +65,7 @@ */ CGLM_INLINE void -glm_mat3_copy(mat3 mat, mat3 dest) { +glm_mat3_copy(const mat3 mat, mat3 dest) { dest[0][0] = mat[0][0]; dest[0][1] = mat[0][1]; dest[0][2] = mat[0][2]; @@ -110,7 +110,7 @@ glm_mat3_identity(mat3 mat) { */ CGLM_INLINE void -glm_mat3_identity_array(mat3 * __restrict mat, size_t count) { +glm_mat3_identity_array(mat3 * const __restrict mat, size_t count) { CGLM_ALIGN_MAT mat3 t = GLM_MAT3_IDENTITY_INIT; size_t i; @@ -147,7 +147,7 @@ glm_mat3_zero(mat3 mat) { */ CGLM_INLINE void -glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest) { +glm_mat3_mul(const mat3 m1, const mat3 m2, mat3 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mat3_mul_sse2(m1, m2, dest); #else @@ -181,7 +181,7 @@ glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest) { */ CGLM_INLINE void -glm_mat3_transpose_to(mat3 m, mat3 dest) { +glm_mat3_transpose_to(const mat3 m, mat3 dest) { dest[0][0] = m[0][0]; dest[0][1] = m[1][0]; dest[0][2] = m[2][0]; @@ -227,7 +227,7 @@ glm_mat3_transpose(mat3 m) { */ CGLM_INLINE void -glm_mat3_mulv(mat3 m, vec3 v, vec3 dest) { +glm_mat3_mulv(const mat3 m, const vec3 v, vec3 dest) { dest[0] = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0] * v[2]; dest[1] = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1] * v[2]; dest[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2]; @@ -242,7 +242,7 @@ glm_mat3_mulv(mat3 m, vec3 v, vec3 dest) { */ CGLM_INLINE float -glm_mat3_trace(mat3 m) { +glm_mat3_trace(const mat3 m) { return m[0][0] + m[1][1] + m[2][2]; } @@ -254,7 +254,7 @@ glm_mat3_trace(mat3 m) { */ CGLM_INLINE void -glm_mat3_quat(mat3 m, versor dest) { +glm_mat3_quat(const mat3 m, versor dest) { float trace, r, rinv; /* it seems using like m12 instead of m[1][2] causes extra instructions */ @@ -320,7 +320,7 @@ glm_mat3_scale(mat3 m, float s) { */ CGLM_INLINE float -glm_mat3_det(mat3 mat) { +glm_mat3_det(const mat3 mat) { float a = mat[0][0], b = mat[0][1], c = mat[0][2], d = mat[1][0], e = mat[1][1], f = mat[1][2], g = mat[2][0], h = mat[2][1], i = mat[2][2]; @@ -336,7 +336,7 @@ glm_mat3_det(mat3 mat) { */ CGLM_INLINE void -glm_mat3_inv(mat3 mat, mat3 dest) { +glm_mat3_inv(const mat3 mat, mat3 dest) { float det; float a = mat[0][0], b = mat[0][1], c = mat[0][2], d = mat[1][0], e = mat[1][1], f = mat[1][2], @@ -413,7 +413,7 @@ glm_mat3_swap_row(mat3 mat, int row1, int row2) { */ CGLM_INLINE float -glm_mat3_rmc(vec3 r, mat3 m, vec3 c) { +glm_mat3_rmc(const vec3 r, const mat3 m, const vec3 c) { vec3 tmp; glm_mat3_mulv(m, c, tmp); return glm_vec3_dot(r, tmp); diff --git a/src/affine.c b/src/affine.c index a818bd1..6388c19 100644 --- a/src/affine.c +++ b/src/affine.c @@ -10,19 +10,19 @@ CGLM_EXPORT void -glmc_translate_make(mat4 m, vec3 v) { +glmc_translate_make(mat4 m, const vec3 v) { glm_translate_make(m, v); } CGLM_EXPORT void -glmc_translate_to(mat4 m, vec3 v, mat4 dest) { +glmc_translate_to(const mat4 m, const vec3 v, mat4 dest) { glm_translate_to(m, v, dest); } CGLM_EXPORT void -glmc_translate(mat4 m, vec3 v) { +glmc_translate(mat4 m, const vec3 v) { glm_translate(m, v); } @@ -46,19 +46,19 @@ glmc_translate_z(mat4 m, float to) { CGLM_EXPORT void -glmc_scale_make(mat4 m, vec3 v) { +glmc_scale_make(mat4 m, const vec3 v) { glm_scale_make(m, v); } CGLM_EXPORT void -glmc_scale_to(mat4 m, vec3 v, mat4 dest) { +glmc_scale_to(const mat4 m, const vec3 v, mat4 dest) { glm_scale_to(m, v, dest); } CGLM_EXPORT void -glmc_scale(mat4 m, vec3 v) { +glmc_scale(mat4 m, const vec3 v) { glm_scale(m, v); } @@ -70,79 +70,79 @@ glmc_scale_uni(mat4 m, float s) { CGLM_EXPORT void -glmc_rotate_x(mat4 m, float rad, mat4 dest) { +glmc_rotate_x(const mat4 m, float rad, mat4 dest) { glm_rotate_x(m, rad, dest); } CGLM_EXPORT void -glmc_rotate_y(mat4 m, float rad, mat4 dest) { +glmc_rotate_y(const mat4 m, float rad, mat4 dest) { glm_rotate_y(m, rad, dest); } CGLM_EXPORT void -glmc_rotate_z(mat4 m, float rad, mat4 dest) { +glmc_rotate_z(const mat4 m, float rad, mat4 dest) { glm_rotate_z(m, rad, dest); } CGLM_EXPORT void -glmc_rotate_make(mat4 m, float angle, vec3 axis) { +glmc_rotate_make(mat4 m, float angle, const vec3 axis) { glm_rotate_make(m, angle, axis); } CGLM_EXPORT void -glmc_rotate(mat4 m, float angle, vec3 axis) { +glmc_rotate(mat4 m, float angle, const vec3 axis) { glm_rotate(m, angle, axis); } CGLM_EXPORT void -glmc_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) { +glmc_rotate_at(mat4 m, const vec3 pivot, float angle, const vec3 axis) { glm_rotate_at(m, pivot, angle, axis); } CGLM_EXPORT void -glmc_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) { +glmc_rotate_atm(mat4 m, const vec3 pivot, float angle, const vec3 axis) { glm_rotate_atm(m, pivot, angle, axis); } CGLM_EXPORT void -glmc_decompose_scalev(mat4 m, vec3 s) { +glmc_decompose_scalev(const mat4 m, vec3 s) { glm_decompose_scalev(m, s); } CGLM_EXPORT bool -glmc_uniscaled(mat4 m) { +glmc_uniscaled(const mat4 m) { return glm_uniscaled(m); } CGLM_EXPORT void -glmc_decompose_rs(mat4 m, mat4 r, vec3 s) { +glmc_decompose_rs(const mat4 m, mat4 r, vec3 s) { glm_decompose_rs(m, r, s); } CGLM_EXPORT void -glmc_decompose(mat4 m, vec4 t, mat4 r, vec3 s) { +glmc_decompose(const mat4 m, vec4 t, mat4 r, vec3 s) { glm_decompose(m, t, r, s); } CGLM_EXPORT void -glmc_mul(mat4 m1, mat4 m2, mat4 dest) { +glmc_mul(const mat4 m1, const mat4 m2, mat4 dest) { glm_mul(m1, m2, dest); } CGLM_EXPORT void -glmc_mul_rot(mat4 m1, mat4 m2, mat4 dest) { +glmc_mul_rot(const mat4 m1, const mat4 m2, mat4 dest) { glm_mul_rot(m1, m2, dest); } diff --git a/src/box.c b/src/box.c index fd639ea..4c7022b 100644 --- a/src/box.c +++ b/src/box.c @@ -10,34 +10,34 @@ CGLM_EXPORT void -glmc_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]) { +glmc_aabb_transform(const vec3 box[2], const mat4 m, vec3 dest[2]) { glm_aabb_transform(box, m, dest); } CGLM_EXPORT void -glmc_aabb_merge(vec3 box1[2], vec3 box2[2], vec3 dest[2]) { +glmc_aabb_merge(const vec3 box1[2], const vec3 box2[2], vec3 dest[2]) { glm_aabb_merge(box1, box2, dest); } CGLM_EXPORT void -glmc_aabb_crop(vec3 box[2], vec3 cropBox[2], vec3 dest[2]) { +glmc_aabb_crop(const vec3 box[2], const vec3 cropBox[2], vec3 dest[2]) { glm_aabb_crop(box, cropBox, dest); } CGLM_EXPORT void -glmc_aabb_crop_until(vec3 box[2], - vec3 cropBox[2], - vec3 clampBox[2], - vec3 dest[2]) { +glmc_aabb_crop_until(const vec3 box[2], + const vec3 cropBox[2], + const vec3 clampBox[2], + vec3 dest[2]) { glm_aabb_crop_until(box, cropBox, clampBox, dest); } CGLM_EXPORT bool -glmc_aabb_frustum(vec3 box[2], vec4 planes[6]) { +glmc_aabb_frustum(const vec3 box[2], vec4 planes[6]) { return glm_aabb_frustum(box, planes); } @@ -49,48 +49,48 @@ glmc_aabb_invalidate(vec3 box[2]) { CGLM_EXPORT bool -glmc_aabb_isvalid(vec3 box[2]) { +glmc_aabb_isvalid(const vec3 box[2]) { return glm_aabb_isvalid(box); } CGLM_EXPORT float -glmc_aabb_size(vec3 box[2]) { +glmc_aabb_size(const vec3 box[2]) { return glm_aabb_size(box); } CGLM_EXPORT float -glmc_aabb_radius(vec3 box[2]) { +glmc_aabb_radius(const vec3 box[2]) { return glm_aabb_radius(box); } CGLM_EXPORT void -glmc_aabb_center(vec3 box[2], vec3 dest) { +glmc_aabb_center(const vec3 box[2], vec3 dest) { glm_aabb_center(box, dest); } CGLM_EXPORT bool -glmc_aabb_aabb(vec3 box[2], vec3 other[2]) { +glmc_aabb_aabb(const vec3 box[2], const vec3 other[2]) { return glm_aabb_aabb(box, other); } CGLM_EXPORT bool -glmc_aabb_point(vec3 box[2], vec3 point) { +glmc_aabb_point(const vec3 box[2], const vec3 point) { return glm_aabb_point(box, point); } CGLM_EXPORT bool -glmc_aabb_contains(vec3 box[2], vec3 other[2]) { +glmc_aabb_contains(const vec3 box[2], const vec3 other[2]) { return glm_aabb_contains(box, other); } CGLM_EXPORT bool -glmc_aabb_sphere(vec3 box[2], vec4 s) { +glmc_aabb_sphere(const vec3 box[2], const vec4 s) { return glm_aabb_sphere(box, s); } diff --git a/src/cam.c b/src/cam.c index 39ac210..2ad4cdd 100644 --- a/src/cam.c +++ b/src/cam.c @@ -16,7 +16,7 @@ glmc_frustum(float left, float top, float nearVal, float farVal, - mat4 dest) { + mat4 dest) { glm_frustum(left, right, bottom, @@ -34,7 +34,7 @@ glmc_ortho(float left, float top, float nearVal, float farVal, - mat4 dest) { + mat4 dest) { glm_ortho(left, right, bottom, @@ -46,19 +46,19 @@ glmc_ortho(float left, CGLM_EXPORT void -glmc_ortho_aabb(vec3 box[2], mat4 dest) { +glmc_ortho_aabb(const vec3 box[2], mat4 dest) { glm_ortho_aabb(box, dest); } CGLM_EXPORT void -glmc_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) { +glmc_ortho_aabb_p(const vec3 box[2], float padding, mat4 dest) { glm_ortho_aabb_p(box, padding, dest); } CGLM_EXPORT void -glmc_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) { +glmc_ortho_aabb_pz(const vec3 box[2], float padding, mat4 dest) { glm_ortho_aabb_pz(box, padding, dest); } @@ -80,7 +80,7 @@ glmc_perspective(float fovy, float aspect, float nearVal, float farVal, - mat4 dest) { + mat4 dest) { glm_perspective(fovy, aspect, nearVal, @@ -108,28 +108,28 @@ glmc_perspective_resize(float aspect, mat4 proj) { CGLM_EXPORT void -glmc_lookat(vec3 eye, - vec3 center, - vec3 up, - mat4 dest) { +glmc_lookat(const vec3 eye, + const vec3 center, + const vec3 up, + mat4 dest) { glm_lookat(eye, center, up, dest); } CGLM_EXPORT void -glmc_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { +glmc_look(const vec3 eye, const vec3 dir, const vec3 up, mat4 dest) { glm_look(eye, dir, up, dest); } CGLM_EXPORT void -glmc_look_anyup(vec3 eye, vec3 dir, mat4 dest) { +glmc_look_anyup(const vec3 eye, const vec3 dir, mat4 dest) { glm_look_anyup(eye, dir, dest); } CGLM_EXPORT void -glmc_persp_decomp(mat4 proj, +glmc_persp_decomp(const mat4 proj, float * __restrict nearVal, float * __restrict farVal, float * __restrict top, @@ -141,13 +141,13 @@ glmc_persp_decomp(mat4 proj, CGLM_EXPORT void -glmc_persp_decompv(mat4 proj, float dest[6]) { +glmc_persp_decompv(const mat4 proj, float dest[6]) { glm_persp_decompv(proj, dest); } CGLM_EXPORT void -glmc_persp_decomp_x(mat4 proj, +glmc_persp_decomp_x(const mat4 proj, float * __restrict left, float * __restrict right) { glm_persp_decomp_x(proj, left, right); @@ -155,7 +155,7 @@ glmc_persp_decomp_x(mat4 proj, CGLM_EXPORT void -glmc_persp_decomp_y(mat4 proj, +glmc_persp_decomp_y(const mat4 proj, float * __restrict top, float * __restrict bottom) { glm_persp_decomp_y(proj, top, bottom); @@ -163,7 +163,7 @@ glmc_persp_decomp_y(mat4 proj, CGLM_EXPORT void -glmc_persp_decomp_z(mat4 proj, +glmc_persp_decomp_z(const mat4 proj, float * __restrict nearVal, float * __restrict farVal) { glm_persp_decomp_z(proj, nearVal, farVal); @@ -171,30 +171,30 @@ glmc_persp_decomp_z(mat4 proj, CGLM_EXPORT void -glmc_persp_decomp_far(mat4 proj, float * __restrict farVal) { +glmc_persp_decomp_far(const mat4 proj, float * __restrict farVal) { glm_persp_decomp_far(proj, farVal); } CGLM_EXPORT void -glmc_persp_decomp_near(mat4 proj, float * __restrict nearVal) { +glmc_persp_decomp_near(const mat4 proj, float * __restrict nearVal) { glm_persp_decomp_near(proj, nearVal); } CGLM_EXPORT float -glmc_persp_fovy(mat4 proj) { +glmc_persp_fovy(const mat4 proj) { return glm_persp_fovy(proj); } CGLM_EXPORT float -glmc_persp_aspect(mat4 proj) { +glmc_persp_aspect(const mat4 proj) { return glm_persp_aspect(proj); } CGLM_EXPORT void -glmc_persp_sizes(mat4 proj, float fovy, vec4 dest) { +glmc_persp_sizes(const mat4 proj, float fovy, vec4 dest) { glm_persp_sizes(proj, fovy, dest); } diff --git a/src/curve.c b/src/curve.c index 74d4702..88d735e 100644 --- a/src/curve.c +++ b/src/curve.c @@ -10,6 +10,6 @@ CGLM_EXPORT float -glmc_smc(float s, mat4 m, vec4 c) { +glmc_smc(float s, const mat4 m, const vec4 c) { return glm_smc(s, m, c); } diff --git a/src/euler.c b/src/euler.c index 44d6edb..92126ca 100644 --- a/src/euler.c +++ b/src/euler.c @@ -10,54 +10,54 @@ CGLM_EXPORT void -glmc_euler_angles(mat4 m, vec3 dest) { +glmc_euler_angles(const mat4 m, vec3 dest) { glm_euler_angles(m, dest); } CGLM_EXPORT void -glmc_euler(vec3 angles, mat4 dest) { +glmc_euler(const vec3 angles, mat4 dest) { glm_euler(angles, dest); } CGLM_EXPORT void -glmc_euler_xyz(vec3 angles, mat4 dest) { +glmc_euler_xyz(const vec3 angles, mat4 dest) { glm_euler_xyz(angles, dest); } CGLM_EXPORT void -glmc_euler_zyx(vec3 angles, mat4 dest) { +glmc_euler_zyx(const vec3 angles, mat4 dest) { glm_euler_zyx(angles, dest); } CGLM_EXPORT void -glmc_euler_zxy(vec3 angles, mat4 dest) { +glmc_euler_zxy(const vec3 angles, mat4 dest) { glm_euler_zxy(angles, dest); } CGLM_EXPORT void -glmc_euler_xzy(vec3 angles, mat4 dest) { +glmc_euler_xzy(const vec3 angles, mat4 dest) { glm_euler_xzy(angles, dest); } CGLM_EXPORT void -glmc_euler_yzx(vec3 angles, mat4 dest) { +glmc_euler_yzx(const vec3 angles, mat4 dest) { glm_euler_yzx(angles, dest); } CGLM_EXPORT void -glmc_euler_yxz(vec3 angles, mat4 dest) { +glmc_euler_yxz(const vec3 angles, mat4 dest) { glm_euler_yxz(angles, dest); } CGLM_EXPORT void -glmc_euler_by_order(vec3 angles, glm_euler_sq axis, mat4 dest) { +glmc_euler_by_order(const vec3 angles, glm_euler_sq axis, mat4 dest) { glm_euler_by_order(angles, axis, dest); } diff --git a/src/frustum.c b/src/frustum.c index 312c3d3..5e896f4 100644 --- a/src/frustum.c +++ b/src/frustum.c @@ -10,33 +10,33 @@ CGLM_EXPORT void -glmc_frustum_planes(mat4 m, vec4 dest[6]) { +glmc_frustum_planes(const mat4 m, vec4 dest[6]) { glm_frustum_planes(m, dest); } CGLM_EXPORT void -glmc_frustum_corners(mat4 invMat, vec4 dest[8]) { +glmc_frustum_corners(const mat4 invMat, vec4 dest[8]) { glm_frustum_corners(invMat, dest); } CGLM_EXPORT void -glmc_frustum_center(vec4 corners[8], vec4 dest) { +glmc_frustum_center(const vec4 corners[8], vec4 dest) { glm_frustum_center(corners, dest); } CGLM_EXPORT void -glmc_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) { +glmc_frustum_box(const vec4 corners[8], const mat4 m, vec3 box[2]) { glm_frustum_box(corners, m, box); } CGLM_EXPORT void -glmc_frustum_corners_at(vec4 corners[8], - float splitDist, - float farDist, - vec4 planeCorners[4]) { +glmc_frustum_corners_at(const vec4 corners[8], + float splitDist, + float farDist, + vec4 planeCorners[4]) { glm_frustum_corners_at(corners, splitDist, farDist, planeCorners); } diff --git a/src/io.c b/src/io.c index fb2b5a9..9e1c15f 100644 --- a/src/io.c +++ b/src/io.c @@ -10,35 +10,35 @@ CGLM_EXPORT void -glmc_mat4_print(mat4 matrix, - FILE * __restrict ostream) { +glmc_mat4_print(const mat4 matrix, + FILE * const __restrict ostream) { glm_mat4_print(matrix, ostream); } CGLM_EXPORT void -glmc_mat3_print(mat3 matrix, - FILE * __restrict ostream) { +glmc_mat3_print(const mat3 matrix, + FILE * const __restrict ostream) { glm_mat3_print(matrix, ostream); } CGLM_EXPORT void -glmc_vec4_print(vec4 vec, - FILE * __restrict ostream) { +glmc_vec4_print(const vec4 vec, + FILE * const __restrict ostream) { glm_vec4_print(vec, ostream); } CGLM_EXPORT void -glmc_vec3_print(vec3 vec, - FILE * __restrict ostream) { +glmc_vec3_print(const vec3 vec, + FILE * const __restrict ostream) { glm_vec3_print(vec, ostream); } CGLM_EXPORT void -glmc_versor_print(versor vec, - FILE * __restrict ostream) { +glmc_versor_print(const versor vec, + FILE * const __restrict ostream) { glm_versor_print(vec, ostream); } diff --git a/src/mat3.c b/src/mat3.c index 337f1f1..a99f583 100644 --- a/src/mat3.c +++ b/src/mat3.c @@ -10,7 +10,7 @@ CGLM_EXPORT void -glmc_mat3_copy(mat3 mat, mat3 dest) { +glmc_mat3_copy(const mat3 mat, mat3 dest) { glm_mat3_copy(mat, dest); } @@ -22,19 +22,19 @@ glmc_mat3_identity(mat3 mat) { CGLM_EXPORT void -glmc_mat3_identity_array(mat3 * __restrict mat, size_t count) { +glmc_mat3_identity_array(mat3 * const __restrict mat, size_t count) { glm_mat3_identity_array(mat, count); } CGLM_EXPORT void -glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest) { +glmc_mat3_mul(const mat3 m1, const mat3 m2, mat3 dest) { glm_mat3_mul(m1, m2, dest); } CGLM_EXPORT void -glmc_mat3_transpose_to(mat3 m, mat3 dest) { +glmc_mat3_transpose_to(const mat3 m, mat3 dest) { glm_mat3_transpose_to(m, dest); } @@ -46,19 +46,19 @@ glmc_mat3_transpose(mat3 m) { CGLM_EXPORT void -glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest) { +glmc_mat3_mulv(const mat3 m, const vec3 v, vec3 dest) { glm_mat3_mulv(m, v, dest); } CGLM_EXPORT float -glmc_mat3_trace(mat3 m) { +glmc_mat3_trace(const mat3 m) { return glm_mat3_trace(m); } CGLM_EXPORT void -glmc_mat3_quat(mat3 m, versor dest) { +glmc_mat3_quat(const mat3 m, versor dest) { glm_mat3_quat(m, dest); } @@ -70,13 +70,13 @@ glmc_mat3_scale(mat3 m, float s) { CGLM_EXPORT float -glmc_mat3_det(mat3 mat) { +glmc_mat3_det(const mat3 mat) { return glm_mat3_det(mat); } CGLM_EXPORT void -glmc_mat3_inv(mat3 mat, mat3 dest) { +glmc_mat3_inv(const mat3 mat, mat3 dest) { glm_mat3_inv(mat, dest); } @@ -94,6 +94,6 @@ glmc_mat3_swap_row(mat3 mat, int row1, int row2) { CGLM_EXPORT float -glmc_mat3_rmc(vec3 r, mat3 m, vec3 c) { +glmc_mat3_rmc(const vec3 r, const mat3 m, const vec3 c) { return glm_mat3_rmc(r, m, c); } diff --git a/src/mat4.c b/src/mat4.c index c648a6e..08c1257 100644 --- a/src/mat4.c +++ b/src/mat4.c @@ -10,13 +10,13 @@ CGLM_EXPORT void -glmc_mat4_ucopy(mat4 mat, mat4 dest) { +glmc_mat4_ucopy(const mat4 mat, mat4 dest) { glm_mat4_copy(mat, dest); } CGLM_EXPORT void -glmc_mat4_copy(mat4 mat, mat4 dest) { +glmc_mat4_copy(const mat4 mat, mat4 dest) { glm_mat4_copy(mat, dest); } @@ -28,73 +28,73 @@ glmc_mat4_identity(mat4 mat) { CGLM_EXPORT void -glmc_mat4_identity_array(mat4 * __restrict mat, size_t count) { +glmc_mat4_identity_array(mat4 * const __restrict mat, size_t count) { glm_mat4_identity_array(mat, count); } CGLM_EXPORT void -glmc_mat4_pick3(mat4 mat, mat3 dest) { +glmc_mat4_pick3(const mat4 mat, mat3 dest) { glm_mat4_pick3(mat, dest); } CGLM_EXPORT void -glmc_mat4_pick3t(mat4 mat, mat3 dest) { +glmc_mat4_pick3t(const mat4 mat, mat3 dest) { glm_mat4_pick3t(mat, dest); } CGLM_EXPORT void -glmc_mat4_ins3(mat3 mat, mat4 dest) { +glmc_mat4_ins3(const mat3 mat, mat4 dest) { glm_mat4_ins3(mat, dest); } CGLM_EXPORT void -glmc_mat4_mul(mat4 m1, mat4 m2, mat4 dest) { +glmc_mat4_mul(const mat4 m1, const mat4 m2, mat4 dest) { glm_mat4_mul(m1, m2, dest); } CGLM_EXPORT void -glmc_mat4_mulN(mat4 * __restrict matrices[], uint32_t len, mat4 dest) { +glmc_mat4_mulN(mat4 * const __restrict matrices[], uint32_t len, mat4 dest) { glm_mat4_mulN(matrices, len, dest); } CGLM_EXPORT void -glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest) { +glmc_mat4_mulv(const mat4 m, const vec4 v, vec4 dest) { glm_mat4_mulv(m, v, dest); } CGLM_EXPORT void -glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest) { +glmc_mat4_mulv3(const mat4 m, const vec3 v, float last, vec3 dest) { glm_mat4_mulv3(m, v, last, dest); } CGLM_EXPORT float -glmc_mat4_trace(mat4 m) { +glmc_mat4_trace(const mat4 m) { return glm_mat4_trace(m); } CGLM_EXPORT float -glmc_mat4_trace3(mat4 m) { +glmc_mat4_trace3(const mat4 m) { return glm_mat4_trace3(m); } CGLM_EXPORT void -glmc_mat4_quat(mat4 m, versor dest) { +glmc_mat4_quat(const mat4 m, versor dest) { glm_mat4_quat(m, dest); } CGLM_EXPORT void -glmc_mat4_transpose_to(mat4 m, mat4 dest) { +glmc_mat4_transpose_to(const mat4 m, mat4 dest) { glm_mat4_transpose_to(m, dest); } @@ -118,25 +118,25 @@ glmc_mat4_scale(mat4 m, float s) { CGLM_EXPORT float -glmc_mat4_det(mat4 mat) { +glmc_mat4_det(const mat4 mat) { return glm_mat4_det(mat); } CGLM_EXPORT void -glmc_mat4_inv(mat4 mat, mat4 dest) { +glmc_mat4_inv(const mat4 mat, mat4 dest) { glm_mat4_inv(mat, dest); } CGLM_EXPORT void -glmc_mat4_inv_precise(mat4 mat, mat4 dest) { +glmc_mat4_inv_precise(const mat4 mat, mat4 dest) { glm_mat4_inv_precise(mat, dest); } CGLM_EXPORT void -glmc_mat4_inv_fast(mat4 mat, mat4 dest) { +glmc_mat4_inv_fast(const mat4 mat, mat4 dest) { glm_mat4_inv_fast(mat, dest); } @@ -154,6 +154,6 @@ glmc_mat4_swap_row(mat4 mat, int row1, int row2) { CGLM_EXPORT float -glmc_mat4_rmc(vec4 r, mat4 m, vec4 c) { +glmc_mat4_rmc(const vec4 r, const mat4 m, const vec4 c) { return glm_mat4_rmc(r, m, c); } diff --git a/src/project.c b/src/project.c index 91c7128..ec7f33d 100644 --- a/src/project.c +++ b/src/project.c @@ -10,18 +10,18 @@ CGLM_EXPORT void -glmc_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { +glmc_unprojecti(const vec3 pos, const mat4 invMat, const vec4 vp, vec3 dest) { glm_unprojecti(pos, invMat, vp, dest); } CGLM_EXPORT void -glmc_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) { +glmc_unproject(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest) { glm_unproject(pos, m, vp, dest); } CGLM_EXPORT void -glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { +glmc_project(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest) { glm_project(pos, m, vp, dest); } diff --git a/src/quat.c b/src/quat.c index 32674a7..7a642a8 100644 --- a/src/quat.c +++ b/src/quat.c @@ -16,7 +16,7 @@ glmc_quat_identity(versor q) { CGLM_EXPORT void -glmc_quat_identity_array(versor * __restrict q, size_t count) { +glmc_quat_identity_array(versor * const __restrict q, size_t count) { glm_quat_identity_array(q, count); } @@ -34,25 +34,25 @@ glmc_quat(versor q, float angle, float x, float y, float z) { CGLM_EXPORT void -glmc_quatv(versor q, float angle, vec3 axis) { +glmc_quatv(versor q, float angle, const vec3 axis) { glm_quatv(q, angle, axis); } CGLM_EXPORT void -glmc_quat_copy(versor q, versor dest) { +glmc_quat_copy(const versor q, versor dest) { glm_quat_copy(q, dest); } CGLM_EXPORT float -glmc_quat_norm(versor q) { +glmc_quat_norm(const versor q) { return glm_quat_norm(q); } CGLM_EXPORT void -glmc_quat_normalize_to(versor q, versor dest) { +glmc_quat_normalize_to(const versor q, versor dest) { glm_quat_normalize_to(q, dest); } @@ -64,150 +64,154 @@ glmc_quat_normalize(versor q) { CGLM_EXPORT float -glmc_quat_dot(versor p, versor q) { +glmc_quat_dot(const versor p, const versor q) { return glm_quat_dot(p, q); } CGLM_EXPORT void -glmc_quat_conjugate(versor q, versor dest) { +glmc_quat_conjugate(const versor q, versor dest) { glm_quat_conjugate(q, dest); } CGLM_EXPORT void -glmc_quat_inv(versor q, versor dest) { +glmc_quat_inv(const versor q, versor dest) { glm_quat_inv(q, dest); } CGLM_EXPORT void -glmc_quat_add(versor p, versor q, versor dest) { +glmc_quat_add(const versor p, const versor q, versor dest) { glm_quat_add(p, q, dest); } CGLM_EXPORT void -glmc_quat_sub(versor p, versor q, versor dest) { +glmc_quat_sub(const versor p, const versor q, versor dest) { glm_quat_sub(p, q, dest); } CGLM_EXPORT float -glmc_quat_real(versor q) { +glmc_quat_real(const versor q) { return glm_quat_real(q); } CGLM_EXPORT void -glmc_quat_imag(versor q, vec3 dest) { +glmc_quat_imag(const versor q, vec3 dest) { glm_quat_imag(q, dest); } CGLM_EXPORT void -glmc_quat_imagn(versor q, vec3 dest) { +glmc_quat_imagn(const versor q, vec3 dest) { glm_quat_imagn(q, dest); } CGLM_EXPORT float -glmc_quat_imaglen(versor q) { +glmc_quat_imaglen(const versor q) { return glm_quat_imaglen(q); } CGLM_EXPORT float -glmc_quat_angle(versor q) { +glmc_quat_angle(const versor q) { return glm_quat_angle(q); } CGLM_EXPORT void -glmc_quat_axis(versor q, versor dest) { +glmc_quat_axis(const versor q, versor dest) { glm_quat_axis(q, dest); } CGLM_EXPORT void -glmc_quat_mul(versor p, versor q, versor dest) { +glmc_quat_mul(const versor p, const versor q, versor dest) { glm_quat_mul(p, q, dest); } CGLM_EXPORT void -glmc_quat_mat4(versor q, mat4 dest) { +glmc_quat_mat4(const versor q, mat4 dest) { glm_quat_mat4(q, dest); } CGLM_EXPORT void -glmc_quat_mat4t(versor q, mat4 dest) { +glmc_quat_mat4t(const versor q, mat4 dest) { glm_quat_mat4t(q, dest); } CGLM_EXPORT void -glmc_quat_mat3(versor q, mat3 dest) { +glmc_quat_mat3(const versor q, mat3 dest) { glm_quat_mat3(q, dest); } CGLM_EXPORT void -glmc_quat_mat3t(versor q, mat3 dest) { +glmc_quat_mat3t(const versor q, mat3 dest) { glm_quat_mat3t(q, dest); } CGLM_EXPORT void -glmc_quat_lerp(versor from, versor to, float t, versor dest) { +glmc_quat_lerp(const versor from, const versor to, float t, versor dest) { glm_quat_lerp(from, to, t, dest); } CGLM_EXPORT void -glmc_quat_slerp(versor from, versor to, float t, versor dest) { +glmc_quat_slerp(const versor from, const versor to, float t, versor dest) { glm_quat_slerp(from, to, t, dest); } CGLM_EXPORT void -glmc_quat_look(vec3 eye, versor ori, mat4 dest) { +glmc_quat_look(const vec3 eye, const versor ori, mat4 dest) { glm_quat_look(eye, ori, dest); } CGLM_EXPORT void -glmc_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) { +glmc_quat_for(const vec3 dir, const vec3 fwd, const vec3 up, versor dest) { glm_quat_for(dir, fwd, up, dest); } CGLM_EXPORT void -glmc_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { +glmc_quat_forp(const vec3 from, + const vec3 to, + const vec3 fwd, + const vec3 up, + versor dest) { glm_quat_forp(from, to, fwd, up, dest); } CGLM_EXPORT void -glmc_quat_rotatev(versor q, vec3 v, vec3 dest) { +glmc_quat_rotatev(const versor q, const vec3 v, vec3 dest) { glm_quat_rotatev(q, v, dest); } CGLM_EXPORT void -glmc_quat_rotate(mat4 m, versor q, mat4 dest) { +glmc_quat_rotate(const mat4 m, const versor q, mat4 dest) { glm_quat_rotate(m, q, dest); } CGLM_EXPORT void -glmc_quat_rotate_at(mat4 model, versor q, vec3 pivot) { +glmc_quat_rotate_at(mat4 model, const versor q, const vec3 pivot) { glm_quat_rotate_at(model, q, pivot); } CGLM_EXPORT void -glmc_quat_rotate_atm(mat4 m, versor q, vec3 pivot) { +glmc_quat_rotate_atm(mat4 m, const versor q, const vec3 pivot) { glm_quat_rotate_atm(m, q, pivot); } diff --git a/src/sphere.c b/src/sphere.c index 003ef87..1026ed4 100644 --- a/src/sphere.c +++ b/src/sphere.c @@ -10,30 +10,30 @@ CGLM_EXPORT float -glmc_sphere_radii(vec4 s) { +glmc_sphere_radii(const vec4 s) { return glm_sphere_radii(s); } CGLM_EXPORT void -glmc_sphere_transform(vec4 s, mat4 m, vec4 dest) { +glmc_sphere_transform(const vec4 s, const mat4 m, vec4 dest) { glm_sphere_transform(s, m, dest); } CGLM_EXPORT void -glmc_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { +glmc_sphere_merge(const vec4 s1, const vec4 s2, vec4 dest) { glm_sphere_merge(s1, s2, dest); } CGLM_EXPORT bool -glmc_sphere_sphere(vec4 s1, vec4 s2) { +glmc_sphere_sphere(const vec4 s1, const vec4 s2) { return glm_sphere_sphere(s1, s2); } CGLM_EXPORT bool -glmc_sphere_point(vec4 s, vec3 point) { +glmc_sphere_point(const vec4 s, const vec3 point) { return glm_sphere_point(s, point); } diff --git a/src/vec3.c b/src/vec3.c index 14edaf6..afc5bbe 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -10,13 +10,13 @@ CGLM_EXPORT void -glmc_vec3(vec4 v4, vec3 dest) { +glmc_vec3(const vec4 v4, vec3 dest) { glm_vec3(v4, dest); } CGLM_EXPORT void -glmc_vec3_copy(vec3 a, vec3 dest) { +glmc_vec3_copy(const vec3 a, vec3 dest) { glm_vec3_copy(a, dest); } @@ -34,31 +34,31 @@ glmc_vec3_one(vec3 v) { CGLM_EXPORT float -glmc_vec3_dot(vec3 a, vec3 b) { +glmc_vec3_dot(const vec3 a, const vec3 b) { return glm_vec3_dot(a, b); } CGLM_EXPORT void -glmc_vec3_cross(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_cross(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_cross(a, b, dest); } CGLM_EXPORT void -glmc_vec3_crossn(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_crossn(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_crossn(a, b, dest); } CGLM_EXPORT float -glmc_vec3_norm(vec3 v) { +glmc_vec3_norm(const vec3 v) { return glm_vec3_norm(v); } CGLM_EXPORT void -glmc_vec3_normalize_to(vec3 v, vec3 dest) { +glmc_vec3_normalize_to(const vec3 v, vec3 dest) { glm_vec3_normalize_to(v, dest); } @@ -70,97 +70,97 @@ glmc_vec3_normalize(vec3 v) { CGLM_EXPORT float -glmc_vec3_norm2(vec3 v) { +glmc_vec3_norm2(const vec3 v) { return glm_vec3_norm2(v); } CGLM_EXPORT void -glmc_vec3_add(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_add(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_add(a, b, dest); } CGLM_EXPORT void -glmc_vec3_adds(vec3 v, float s, vec3 dest) { +glmc_vec3_adds(const vec3 v, float s, vec3 dest) { glm_vec3_adds(v, s, dest); } CGLM_EXPORT void -glmc_vec3_sub(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_sub(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_sub(a, b, dest); } CGLM_EXPORT void -glmc_vec3_subs(vec3 v, float s, vec3 dest) { +glmc_vec3_subs(const vec3 v, float s, vec3 dest) { glm_vec3_subs(v, s, dest); } CGLM_EXPORT void -glmc_vec3_mul(vec3 a, vec3 b, vec3 d) { +glmc_vec3_mul(const vec3 a, const vec3 b, vec3 d) { glm_vec3_mul(a, b, d); } CGLM_EXPORT void -glmc_vec3_scale(vec3 v, float s, vec3 dest) { +glmc_vec3_scale(const vec3 v, float s, vec3 dest) { glm_vec3_scale(v, s, dest); } CGLM_EXPORT void -glmc_vec3_scale_as(vec3 v, float s, vec3 dest) { +glmc_vec3_scale_as(const vec3 v, float s, vec3 dest) { glm_vec3_scale_as(v, s, dest); } CGLM_EXPORT void -glmc_vec3_div(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_div(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_div(a, b, dest); } CGLM_EXPORT void -glmc_vec3_divs(vec3 a, float s, vec3 dest) { +glmc_vec3_divs(const vec3 a, float s, vec3 dest) { glm_vec3_divs(a, s, dest); } CGLM_EXPORT void -glmc_vec3_addadd(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_addadd(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_addadd(a, b, dest); } CGLM_EXPORT void -glmc_vec3_subadd(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_subadd(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_subadd(a, b, dest); } CGLM_EXPORT void -glmc_vec3_muladd(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_muladd(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_muladd(a, b, dest); } CGLM_EXPORT void -glmc_vec3_muladds(vec3 a, float s, vec3 dest) { +glmc_vec3_muladds(const vec3 a, float s, vec3 dest) { glm_vec3_muladds(a, s, dest); } CGLM_EXPORT void -glmc_vec3_maxadd(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_maxadd(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_maxadd(a, b, dest); } CGLM_EXPORT void -glmc_vec3_minadd(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_minadd(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_minadd(a, b, dest); } @@ -172,67 +172,67 @@ glmc_vec3_negate(vec3 v) { CGLM_EXPORT void -glmc_vec3_negate_to(vec3 v, vec3 dest) { +glmc_vec3_negate_to(const vec3 v, vec3 dest) { glm_vec3_negate_to(v, dest); } CGLM_EXPORT float -glmc_vec3_angle(vec3 a, vec3 b) { +glmc_vec3_angle(const vec3 a, const vec3 b) { return glm_vec3_angle(a, b); } CGLM_EXPORT void -glmc_vec3_rotate(vec3 v, float angle, vec3 axis) { +glmc_vec3_rotate(vec3 v, float angle, const vec3 axis) { glm_vec3_rotate(v, angle, axis); } CGLM_EXPORT void -glmc_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest) { +glmc_vec3_rotate_m4(const mat4 m, const vec3 v, vec3 dest) { glm_vec3_rotate_m4(m, v, dest); } CGLM_EXPORT void -glmc_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest) { +glmc_vec3_rotate_m3(const mat3 m, const vec3 v, vec3 dest) { glm_vec3_rotate_m3(m, v, dest); } CGLM_EXPORT void -glmc_vec3_proj(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_proj(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_proj(a, b, dest); } CGLM_EXPORT void -glmc_vec3_center(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_center(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_center(a, b, dest); } CGLM_EXPORT float -glmc_vec3_distance2(vec3 a, vec3 b) { +glmc_vec3_distance2(const vec3 a, const vec3 b) { return glm_vec3_distance2(a, b); } CGLM_EXPORT float -glmc_vec3_distance(vec3 a, vec3 b) { +glmc_vec3_distance(const vec3 a, const vec3 b) { return glm_vec3_distance(a, b); } CGLM_EXPORT void -glmc_vec3_maxv(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_maxv(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_minv(a, b, dest); } CGLM_EXPORT void -glmc_vec3_minv(vec3 a, vec3 b, vec3 dest) { +glmc_vec3_minv(const vec3 a, const vec3 b, vec3 dest) { glm_vec3_maxv(a, b, dest); } @@ -244,13 +244,13 @@ glmc_vec3_clamp(vec3 v, float minVal, float maxVal) { CGLM_EXPORT void -glmc_vec3_ortho(vec3 v, vec3 dest) { +glmc_vec3_ortho(const vec3 v, vec3 dest) { glm_vec3_ortho(v, dest); } CGLM_EXPORT void -glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) { +glmc_vec3_lerp(const vec3 from, const vec3 to, float t, vec3 dest) { glm_vec3_lerp(from, to, t, dest); } @@ -258,7 +258,7 @@ glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) { CGLM_EXPORT void -glmc_vec3_mulv(vec3 a, vec3 b, vec3 d) { +glmc_vec3_mulv(const vec3 a, const vec3 b, vec3 d) { glm_vec3_mulv(a, b, d); } @@ -270,72 +270,72 @@ glmc_vec3_broadcast(float val, vec3 d) { CGLM_EXPORT bool -glmc_vec3_eq(vec3 v, float val) { +glmc_vec3_eq(const vec3 v, float val) { return glm_vec3_eq(v, val); } CGLM_EXPORT bool -glmc_vec3_eq_eps(vec3 v, float val) { +glmc_vec3_eq_eps(const vec3 v, float val) { return glm_vec3_eq_eps(v, val); } CGLM_EXPORT bool -glmc_vec3_eq_all(vec3 v) { +glmc_vec3_eq_all(const vec3 v) { return glm_vec3_eq_all(v); } CGLM_EXPORT bool -glmc_vec3_eqv(vec3 a, vec3 b) { +glmc_vec3_eqv(const vec3 a, const vec3 b) { return glm_vec3_eqv(a, b); } CGLM_EXPORT bool -glmc_vec3_eqv_eps(vec3 a, vec3 b) { +glmc_vec3_eqv_eps(const vec3 a, const vec3 b) { return glm_vec3_eqv_eps(a, b); } CGLM_EXPORT float -glmc_vec3_max(vec3 v) { +glmc_vec3_max(const vec3 v) { return glm_vec3_max(v); } CGLM_EXPORT float -glmc_vec3_min(vec3 v) { +glmc_vec3_min(const vec3 v) { return glm_vec3_min(v); } CGLM_EXPORT bool -glmc_vec3_isnan(vec3 v) { +glmc_vec3_isnan(const vec3 v) { return glm_vec3_isnan(v); } CGLM_EXPORT bool -glmc_vec3_isinf(vec3 v) { +glmc_vec3_isinf(const vec3 v) { return glm_vec3_isinf(v); } CGLM_EXPORT bool -glmc_vec3_isvalid(vec3 v) { +glmc_vec3_isvalid(const vec3 v) { return glm_vec3_isvalid(v); } CGLM_EXPORT void -glmc_vec3_sign(vec3 v, vec3 dest) { +glmc_vec3_sign(const vec3 v, vec3 dest) { glm_vec3_sign(v, dest); } CGLM_EXPORT void -glmc_vec3_sqrt(vec3 v, vec3 dest) { +glmc_vec3_sqrt(const vec3 v, vec3 dest) { glm_vec3_sqrt(v, dest); } diff --git a/src/vec4.c b/src/vec4.c index 0bb6a6e..932f4ff 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -10,7 +10,7 @@ CGLM_EXPORT void -glmc_vec4(vec3 v3, float last, vec4 dest) { +glmc_vec4(const vec3 v3, float last, vec4 dest) { glm_vec4(v3, last, dest); } @@ -28,37 +28,37 @@ glmc_vec4_one(vec4 v) { CGLM_EXPORT void -glmc_vec4_copy3(vec4 v, vec3 dest) { +glmc_vec4_copy3(const vec4 v, vec3 dest) { glm_vec4_copy3(v, dest); } CGLM_EXPORT void -glmc_vec4_copy(vec4 v, vec4 dest) { +glmc_vec4_copy(const vec4 v, vec4 dest) { glm_vec4_copy(v, dest); } CGLM_EXPORT void -glmc_vec4_ucopy(vec4 v, vec4 dest) { +glmc_vec4_ucopy(const vec4 v, vec4 dest) { glm_vec4_ucopy(v, dest); } CGLM_EXPORT float -glmc_vec4_dot(vec4 a, vec4 b) { +glmc_vec4_dot(const vec4 a, const vec4 b) { return glm_vec4_dot(a, b); } CGLM_EXPORT float -glmc_vec4_norm(vec4 v) { +glmc_vec4_norm(const vec4 v) { return glm_vec4_norm(v); } CGLM_EXPORT void -glmc_vec4_normalize_to(vec4 v, vec4 dest) { +glmc_vec4_normalize_to(const vec4 v, vec4 dest) { glm_vec4_normalize_to(v, dest); } @@ -70,97 +70,97 @@ glmc_vec4_normalize(vec4 v) { CGLM_EXPORT float -glmc_vec4_norm2(vec4 v) { +glmc_vec4_norm2(const vec4 v) { return glm_vec4_norm2(v); } CGLM_EXPORT void -glmc_vec4_add(vec4 a, vec4 b, vec4 dest) { +glmc_vec4_add(const vec4 a, const vec4 b, vec4 dest) { glm_vec4_add(a, b, dest); } CGLM_EXPORT void -glmc_vec4_adds(vec4 v, float s, vec4 dest) { +glmc_vec4_adds(const vec4 v, float s, vec4 dest) { glm_vec4_adds(v, s, dest); } CGLM_EXPORT void -glmc_vec4_sub(vec4 a, vec4 b, vec4 dest) { +glmc_vec4_sub(const vec4 a, const vec4 b, vec4 dest) { glm_vec4_sub(a, b, dest); } CGLM_EXPORT void -glmc_vec4_subs(vec4 v, float s, vec4 dest) { +glmc_vec4_subs(const vec4 v, float s, vec4 dest) { glm_vec4_subs(v, s, dest); } CGLM_EXPORT void -glmc_vec4_mul(vec4 a, vec4 b, vec4 d) { +glmc_vec4_mul(const vec4 a, const vec4 b, vec4 d) { glm_vec4_mul(a, b, d); } CGLM_EXPORT void -glmc_vec4_scale(vec4 v, float s, vec4 dest) { +glmc_vec4_scale(const vec4 v, float s, vec4 dest) { glm_vec4_scale(v, s, dest); } CGLM_EXPORT void -glmc_vec4_scale_as(vec4 v, float s, vec4 dest) { +glmc_vec4_scale_as(const vec4 v, float s, vec4 dest) { glm_vec4_scale_as(v, s, dest); } CGLM_EXPORT void -glmc_vec4_div(vec4 a, vec4 b, vec4 dest) { +glmc_vec4_div(const vec4 a, const vec4 b, vec4 dest) { glm_vec4_div(a, b, dest); } CGLM_EXPORT void -glmc_vec4_divs(vec4 v, float s, vec4 dest) { +glmc_vec4_divs(const vec4 v, float s, vec4 dest) { glm_vec4_divs(v, s, dest); } CGLM_EXPORT void -glmc_vec4_addadd(vec4 a, vec4 b, vec4 dest) { +glmc_vec4_addadd(const vec4 a, const vec4 b, vec4 dest) { glm_vec4_addadd(a, b, dest); } CGLM_EXPORT void -glmc_vec4_subadd(vec4 a, vec4 b, vec4 dest) { +glmc_vec4_subadd(const vec4 a, const vec4 b, vec4 dest) { glm_vec4_subadd(a, b, dest); } CGLM_EXPORT void -glmc_vec4_muladd(vec4 a, vec4 b, vec4 dest) { +glmc_vec4_muladd(const vec4 a, const vec4 b, vec4 dest) { glm_vec4_muladd(a, b, dest); } CGLM_EXPORT void -glmc_vec4_muladds(vec4 a, float s, vec4 dest) { +glmc_vec4_muladds(const vec4 a, float s, vec4 dest) { glm_vec4_muladds(a, s, dest); } CGLM_EXPORT void -glmc_vec4_maxadd(vec4 a, vec4 b, vec4 dest) { +glmc_vec4_maxadd(const vec4 a, const vec4 b, vec4 dest) { glm_vec4_maxadd(a, b, dest); } CGLM_EXPORT void -glmc_vec4_minadd(vec4 a, vec4 b, vec4 dest) { +glmc_vec4_minadd(const vec4 a, const vec4 b, vec4 dest) { glm_vec4_minadd(a, b, dest); } @@ -172,25 +172,25 @@ glmc_vec4_negate(vec4 v) { CGLM_EXPORT void -glmc_vec4_negate_to(vec4 v, vec4 dest) { +glmc_vec4_negate_to(const vec4 v, vec4 dest) { glm_vec4_negate_to(v, dest); } CGLM_EXPORT float -glmc_vec4_distance(vec4 a, vec4 b) { +glmc_vec4_distance(const vec4 a, const vec4 b) { return glm_vec4_distance(a, b); } CGLM_EXPORT void -glmc_vec4_maxv(vec4 a, vec4 b, vec4 dest) { +glmc_vec4_maxv(const vec4 a, const vec4 b, vec4 dest) { glm_vec4_minv(a, b, dest); } CGLM_EXPORT void -glmc_vec4_minv(vec4 a, vec4 b, vec4 dest) { +glmc_vec4_minv(const vec4 a, const vec4 b, vec4 dest) { glm_vec4_maxv(a, b, dest); } @@ -202,7 +202,7 @@ glmc_vec4_clamp(vec4 v, float minVal, float maxVal) { CGLM_EXPORT void -glmc_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) { +glmc_vec4_lerp(const vec4 from, const vec4 to, float t, vec4 dest) { glm_vec4_lerp(from, to, t, dest); } @@ -216,7 +216,7 @@ glmc_vec4_cubic(float s, vec4 dest) { CGLM_EXPORT void -glmc_vec4_mulv(vec4 a, vec4 b, vec4 d) { +glmc_vec4_mulv(const vec4 a, const vec4 b, vec4 d) { glm_vec4_mulv(a, b, d); } @@ -228,72 +228,72 @@ glmc_vec4_broadcast(float val, vec4 d) { CGLM_EXPORT bool -glmc_vec4_eq(vec4 v, float val) { +glmc_vec4_eq(const vec4 v, float val) { return glm_vec4_eq(v, val); } CGLM_EXPORT bool -glmc_vec4_eq_eps(vec4 v, float val) { +glmc_vec4_eq_eps(const vec4 v, float val) { return glm_vec4_eq_eps(v, val); } CGLM_EXPORT bool -glmc_vec4_eq_all(vec4 v) { +glmc_vec4_eq_all(const vec4 v) { return glm_vec4_eq_all(v); } CGLM_EXPORT bool -glmc_vec4_eqv(vec4 a, vec4 b) { +glmc_vec4_eqv(const vec4 a, const vec4 b) { return glm_vec4_eqv(a, b); } CGLM_EXPORT bool -glmc_vec4_eqv_eps(vec4 a, vec4 b) { +glmc_vec4_eqv_eps(const vec4 a, const vec4 b) { return glm_vec4_eqv_eps(a, b); } CGLM_EXPORT float -glmc_vec4_max(vec4 v) { +glmc_vec4_max(const vec4 v) { return glm_vec4_max(v); } CGLM_EXPORT float -glmc_vec4_min(vec4 v) { +glmc_vec4_min(const vec4 v) { return glm_vec4_min(v); } CGLM_EXPORT bool -glmc_vec4_isnan(vec4 v) { +glmc_vec4_isnan(const vec4 v) { return glm_vec4_isnan(v); } CGLM_EXPORT bool -glmc_vec4_isinf(vec4 v) { +glmc_vec4_isinf(const vec4 v) { return glm_vec4_isinf(v); } CGLM_EXPORT bool -glmc_vec4_isvalid(vec4 v) { +glmc_vec4_isvalid(const vec4 v) { return glm_vec4_isvalid(v); } CGLM_EXPORT void -glmc_vec4_sign(vec4 v, vec4 dest) { +glmc_vec4_sign(const vec4 v, vec4 dest) { glm_vec4_sign(v, dest); } CGLM_EXPORT void -glmc_vec4_sqrt(vec4 v, vec4 dest) { +glmc_vec4_sqrt(const vec4 v, vec4 dest) { glm_vec4_sqrt(v, dest); } From bb8ff257521f7169645458df3891164e77bdddc8 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 30 Apr 2019 08:19:07 +0300 Subject: [PATCH 269/292] Revert "mark readonly parameters as const" --- include/cglm/affine-mat.h | 4 +- include/cglm/affine.h | 36 ++++++------ include/cglm/box.h | 37 ++++++------- include/cglm/call/affine.h | 38 ++++++------- include/cglm/call/box.h | 32 +++++------ include/cglm/call/cam.h | 38 ++++++------- include/cglm/call/curve.h | 2 +- include/cglm/call/euler.h | 18 +++--- include/cglm/call/frustum.h | 16 +++--- include/cglm/call/io.h | 20 +++---- include/cglm/call/mat3.h | 20 +++---- include/cglm/call/mat4.h | 38 ++++++------- include/cglm/call/project.h | 6 +- include/cglm/call/quat.h | 64 ++++++++++----------- include/cglm/call/sphere.h | 10 ++-- include/cglm/call/vec3.h | 98 ++++++++++++++++----------------- include/cglm/call/vec4.h | 82 +++++++++++++-------------- include/cglm/cam.h | 42 +++++++------- include/cglm/color.h | 2 +- include/cglm/curve.h | 2 +- include/cglm/euler.h | 20 +++---- include/cglm/frustum.h | 16 +++--- include/cglm/io.h | 28 +++++----- include/cglm/mat3.h | 20 +++---- include/cglm/mat4.h | 38 ++++++------- include/cglm/project.h | 6 +- include/cglm/quat.h | 70 +++++++++++------------ include/cglm/simd/avx/affine.h | 2 +- include/cglm/simd/avx/mat4.h | 2 +- include/cglm/simd/neon/mat4.h | 2 +- include/cglm/simd/sse2/affine.h | 4 +- include/cglm/simd/sse2/mat3.h | 2 +- include/cglm/simd/sse2/mat4.h | 12 ++-- include/cglm/simd/sse2/quat.h | 2 +- include/cglm/simd/x86.h | 4 +- include/cglm/sphere.h | 10 ++-- include/cglm/vec3-ext.h | 24 ++++---- include/cglm/vec3.h | 78 +++++++++++++------------- include/cglm/vec4-ext.h | 24 ++++---- include/cglm/vec4.h | 56 +++++++++---------- src/affine.c | 38 ++++++------- src/box.c | 32 +++++------ src/cam.c | 44 +++++++-------- src/curve.c | 2 +- src/euler.c | 18 +++--- src/frustum.c | 16 +++--- src/io.c | 20 +++---- src/mat3.c | 20 +++---- src/mat4.c | 38 ++++++------- src/project.c | 6 +- src/quat.c | 64 ++++++++++----------- src/sphere.c | 10 ++-- src/vec3.c | 98 ++++++++++++++++----------------- src/vec4.c | 82 +++++++++++++-------------- 54 files changed, 751 insertions(+), 762 deletions(-) diff --git a/include/cglm/affine-mat.h b/include/cglm/affine-mat.h index 9d78633..f58749b 100644 --- a/include/cglm/affine-mat.h +++ b/include/cglm/affine-mat.h @@ -44,7 +44,7 @@ */ CGLM_INLINE void -glm_mul(const mat4 m1, const mat4 m2, mat4 dest) { +glm_mul(mat4 m1, mat4 m2, mat4 dest) { #ifdef __AVX__ glm_mul_avx(m1, m2, dest); #elif defined( __SSE__ ) || defined( __SSE2__ ) @@ -100,7 +100,7 @@ glm_mul(const mat4 m1, const mat4 m2, mat4 dest) { */ CGLM_INLINE void -glm_mul_rot(const mat4 m1, const mat4 m2, mat4 dest) { +glm_mul_rot(mat4 m1, mat4 m2, mat4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mul_rot_sse2(m1, m2, dest); #else diff --git a/include/cglm/affine.h b/include/cglm/affine.h index af567b6..84ead4b 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -42,7 +42,7 @@ CGLM_INLINE void -glm_mat4_mul(const mat4 m1, const mat4 m2, mat4 dest); +glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest); /*! * @brief translate existing transform matrix by v vector @@ -53,7 +53,7 @@ glm_mat4_mul(const mat4 m1, const mat4 m2, mat4 dest); */ CGLM_INLINE void -glm_translate(mat4 m, const vec3 v) { +glm_translate(mat4 m, vec3 v) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(m[3], _mm_add_ps(_mm_add_ps(_mm_mul_ps(glmm_load(m[0]), @@ -89,7 +89,7 @@ glm_translate(mat4 m, const vec3 v) { */ CGLM_INLINE void -glm_translate_to(const mat4 m, const vec3 v, mat4 dest) { +glm_translate_to(mat4 m, vec3 v, mat4 dest) { glm_mat4_copy(m, dest); glm_translate(dest, v); } @@ -168,7 +168,7 @@ glm_translate_z(mat4 m, float z) { */ CGLM_INLINE void -glm_translate_make(mat4 m, const vec3 v) { +glm_translate_make(mat4 m, vec3 v) { glm_mat4_identity(m); glm_vec3_copy(v, m[3]); } @@ -183,7 +183,7 @@ glm_translate_make(mat4 m, const vec3 v) { */ CGLM_INLINE void -glm_scale_to(const mat4 m, const vec3 v, mat4 dest) { +glm_scale_to(mat4 m, vec3 v, mat4 dest) { glm_vec4_scale(m[0], v[0], dest[0]); glm_vec4_scale(m[1], v[1], dest[1]); glm_vec4_scale(m[2], v[2], dest[2]); @@ -199,7 +199,7 @@ glm_scale_to(const mat4 m, const vec3 v, mat4 dest) { */ CGLM_INLINE void -glm_scale_make(mat4 m, const vec3 v) { +glm_scale_make(mat4 m, vec3 v) { glm_mat4_identity(m); m[0][0] = v[0]; m[1][1] = v[1]; @@ -215,7 +215,7 @@ glm_scale_make(mat4 m, const vec3 v) { */ CGLM_INLINE void -glm_scale(mat4 m, const vec3 v) { +glm_scale(mat4 m, vec3 v) { glm_scale_to(m, v, m); } @@ -243,7 +243,7 @@ glm_scale_uni(mat4 m, float s) { */ CGLM_INLINE void -glm_rotate_x(const mat4 m, float angle, mat4 dest) { +glm_rotate_x(mat4 m, float angle, mat4 dest) { CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; @@ -268,7 +268,7 @@ glm_rotate_x(const mat4 m, float angle, mat4 dest) { */ CGLM_INLINE void -glm_rotate_y(const mat4 m, float angle, mat4 dest) { +glm_rotate_y(mat4 m, float angle, mat4 dest) { CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; @@ -293,7 +293,7 @@ glm_rotate_y(const mat4 m, float angle, mat4 dest) { */ CGLM_INLINE void -glm_rotate_z(const mat4 m, float angle, mat4 dest) { +glm_rotate_z(mat4 m, float angle, mat4 dest) { CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; float c, s; @@ -319,7 +319,7 @@ glm_rotate_z(const mat4 m, float angle, mat4 dest) { */ CGLM_INLINE void -glm_rotate_make(mat4 m, float angle, const vec3 axis) { +glm_rotate_make(mat4 m, float angle, vec3 axis) { CGLM_ALIGN(8) vec3 axisn, v, vs; float c; @@ -350,7 +350,7 @@ glm_rotate_make(mat4 m, float angle, const vec3 axis) { */ CGLM_INLINE void -glm_rotate(mat4 m, float angle, const vec3 axis) { +glm_rotate(mat4 m, float angle, vec3 axis) { CGLM_ALIGN_MAT mat4 rot; glm_rotate_make(rot, angle, axis); glm_mul_rot(m, rot, m); @@ -367,7 +367,7 @@ glm_rotate(mat4 m, float angle, const vec3 axis) { */ CGLM_INLINE void -glm_rotate_at(mat4 m, const vec3 pivot, float angle, const vec3 axis) { +glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) { CGLM_ALIGN(8) vec3 pivotInv; glm_vec3_negate_to(pivot, pivotInv); @@ -392,7 +392,7 @@ glm_rotate_at(mat4 m, const vec3 pivot, float angle, const vec3 axis) { */ CGLM_INLINE void -glm_rotate_atm(mat4 m, const vec3 pivot, float angle, const vec3 axis) { +glm_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) { CGLM_ALIGN(8) vec3 pivotInv; glm_vec3_negate_to(pivot, pivotInv); @@ -410,7 +410,7 @@ glm_rotate_atm(mat4 m, const vec3 pivot, float angle, const vec3 axis) { */ CGLM_INLINE void -glm_decompose_scalev(const mat4 m, vec3 s) { +glm_decompose_scalev(mat4 m, vec3 s) { s[0] = glm_vec3_norm(m[0]); s[1] = glm_vec3_norm(m[1]); s[2] = glm_vec3_norm(m[2]); @@ -426,7 +426,7 @@ glm_decompose_scalev(const mat4 m, vec3 s) { */ CGLM_INLINE bool -glm_uniscaled(const mat4 m) { +glm_uniscaled(mat4 m) { CGLM_ALIGN(8) vec3 s; glm_decompose_scalev(m, s); return glm_vec3_eq_all(s); @@ -442,7 +442,7 @@ glm_uniscaled(const mat4 m) { */ CGLM_INLINE void -glm_decompose_rs(const mat4 m, mat4 r, vec3 s) { +glm_decompose_rs(mat4 m, mat4 r, vec3 s) { CGLM_ALIGN(16) vec4 t = {0.0f, 0.0f, 0.0f, 1.0f}; CGLM_ALIGN(8) vec3 v; @@ -482,7 +482,7 @@ glm_decompose_rs(const mat4 m, mat4 r, vec3 s) { */ CGLM_INLINE void -glm_decompose(const mat4 m, vec4 t, mat4 r, vec3 s) { +glm_decompose(mat4 m, vec4 t, mat4 r, vec3 s) { glm_vec4_copy(m[3], t); glm_decompose_rs(m, r, s); } diff --git a/include/cglm/box.h b/include/cglm/box.h index c218602..2250c2a 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -22,7 +22,7 @@ */ CGLM_INLINE void -glm_aabb_transform(const vec3 box[2], const mat4 m, vec3 dest[2]) { +glm_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]) { vec3 v[2], xa, xb, ya, yb, za, zb; glm_vec3_scale(m[0], box[0][0], xa); @@ -62,7 +62,7 @@ glm_aabb_transform(const vec3 box[2], const mat4 m, vec3 dest[2]) { */ CGLM_INLINE void -glm_aabb_merge(const vec3 box1[2], const vec3 box2[2], vec3 dest[2]) { +glm_aabb_merge(vec3 box1[2], vec3 box2[2], vec3 dest[2]) { dest[0][0] = glm_min(box1[0][0], box2[0][0]); dest[0][1] = glm_min(box1[0][1], box2[0][1]); dest[0][2] = glm_min(box1[0][2], box2[0][2]); @@ -85,7 +85,7 @@ glm_aabb_merge(const vec3 box1[2], const vec3 box2[2], vec3 dest[2]) { */ CGLM_INLINE void -glm_aabb_crop(const vec3 box[2], const vec3 cropBox[2], vec3 dest[2]) { +glm_aabb_crop(vec3 box[2], vec3 cropBox[2], vec3 dest[2]) { dest[0][0] = glm_max(box[0][0], cropBox[0][0]); dest[0][1] = glm_max(box[0][1], cropBox[0][1]); dest[0][2] = glm_max(box[0][2], cropBox[0][2]); @@ -109,10 +109,10 @@ glm_aabb_crop(const vec3 box[2], const vec3 cropBox[2], vec3 dest[2]) { */ CGLM_INLINE void -glm_aabb_crop_until(const vec3 box[2], - const vec3 cropBox[2], - const vec3 clampBox[2], - vec3 dest[2]) { +glm_aabb_crop_until(vec3 box[2], + vec3 cropBox[2], + vec3 clampBox[2], + vec3 dest[2]) { glm_aabb_crop(box, cropBox, dest); glm_aabb_merge(clampBox, dest, dest); } @@ -133,10 +133,9 @@ glm_aabb_crop_until(const vec3 box[2], */ CGLM_INLINE bool -glm_aabb_frustum(const vec3 box[2], const vec4 planes[6]) { - const float *p; - float dp; - int i; +glm_aabb_frustum(vec3 box[2], vec4 planes[6]) { + float *p, dp; + int i; for (i = 0; i < 6; i++) { p = planes[i]; @@ -170,7 +169,7 @@ glm_aabb_invalidate(vec3 box[2]) { */ CGLM_INLINE bool -glm_aabb_isvalid(const vec3 box[2]) { +glm_aabb_isvalid(vec3 box[2]) { return glm_vec3_max(box[0]) != FLT_MAX && glm_vec3_min(box[1]) != -FLT_MAX; } @@ -182,7 +181,7 @@ glm_aabb_isvalid(const vec3 box[2]) { */ CGLM_INLINE float -glm_aabb_size(const vec3 box[2]) { +glm_aabb_size(vec3 box[2]) { return glm_vec3_distance(box[0], box[1]); } @@ -193,7 +192,7 @@ glm_aabb_size(const vec3 box[2]) { */ CGLM_INLINE float -glm_aabb_radius(const vec3 box[2]) { +glm_aabb_radius(vec3 box[2]) { return glm_aabb_size(box) * 0.5f; } @@ -205,7 +204,7 @@ glm_aabb_radius(const vec3 box[2]) { */ CGLM_INLINE void -glm_aabb_center(const vec3 box[2], vec3 dest) { +glm_aabb_center(vec3 box[2], vec3 dest) { glm_vec3_center(box[0], box[1], dest); } @@ -217,7 +216,7 @@ glm_aabb_center(const vec3 box[2], vec3 dest) { */ CGLM_INLINE bool -glm_aabb_aabb(const vec3 box[2], const vec3 other[2]) { +glm_aabb_aabb(vec3 box[2], vec3 other[2]) { return (box[0][0] <= other[1][0] && box[1][0] >= other[0][0]) && (box[0][1] <= other[1][1] && box[1][1] >= other[0][1]) && (box[0][2] <= other[1][2] && box[1][2] >= other[0][2]); @@ -234,7 +233,7 @@ glm_aabb_aabb(const vec3 box[2], const vec3 other[2]) { */ CGLM_INLINE bool -glm_aabb_sphere(const vec3 box[2], const vec4 s) { +glm_aabb_sphere(vec3 box[2], vec4 s) { float dmin; int a, b, c; @@ -257,7 +256,7 @@ glm_aabb_sphere(const vec3 box[2], const vec4 s) { */ CGLM_INLINE bool -glm_aabb_point(const vec3 box[2], const vec3 point) { +glm_aabb_point(vec3 box[2], vec3 point) { return (point[0] >= box[0][0] && point[0] <= box[1][0]) && (point[1] >= box[0][1] && point[1] <= box[1][1]) && (point[2] >= box[0][2] && point[2] <= box[1][2]); @@ -271,7 +270,7 @@ glm_aabb_point(const vec3 box[2], const vec3 point) { */ CGLM_INLINE bool -glm_aabb_contains(const vec3 box[2], const vec3 other[2]) { +glm_aabb_contains(vec3 box[2], vec3 other[2]) { return (box[0][0] <= other[0][0] && box[1][0] >= other[1][0]) && (box[0][1] <= other[0][1] && box[1][1] >= other[1][1]) && (box[0][2] <= other[0][2] && box[1][2] >= other[1][2]); diff --git a/include/cglm/call/affine.h b/include/cglm/call/affine.h index ec50bc4..c11405b 100644 --- a/include/cglm/call/affine.h +++ b/include/cglm/call/affine.h @@ -15,15 +15,15 @@ extern "C" { CGLM_EXPORT void -glmc_translate_make(mat4 m, const vec3 v); +glmc_translate_make(mat4 m, vec3 v); CGLM_EXPORT void -glmc_translate_to(const mat4 m, const vec3 v, mat4 dest); +glmc_translate_to(mat4 m, vec3 v, mat4 dest); CGLM_EXPORT void -glmc_translate(mat4 m, const vec3 v); +glmc_translate(mat4 m, vec3 v); CGLM_EXPORT void @@ -39,15 +39,15 @@ glmc_translate_z(mat4 m, float to); CGLM_EXPORT void -glmc_scale_make(mat4 m, const vec3 v); +glmc_scale_make(mat4 m, vec3 v); CGLM_EXPORT void -glmc_scale_to(const mat4 m, const vec3 v, mat4 dest); +glmc_scale_to(mat4 m, vec3 v, mat4 dest); CGLM_EXPORT void -glmc_scale(mat4 m, const vec3 v); +glmc_scale(mat4 m, vec3 v); CGLM_EXPORT void @@ -55,57 +55,57 @@ glmc_scale_uni(mat4 m, float s); CGLM_EXPORT void -glmc_rotate_x(const mat4 m, float rad, mat4 dest); +glmc_rotate_x(mat4 m, float rad, mat4 dest); CGLM_EXPORT void -glmc_rotate_y(const mat4 m, float rad, mat4 dest); +glmc_rotate_y(mat4 m, float rad, mat4 dest); CGLM_EXPORT void -glmc_rotate_z(const mat4 m, float rad, mat4 dest); +glmc_rotate_z(mat4 m, float rad, mat4 dest); CGLM_EXPORT void -glmc_rotate_make(mat4 m, float angle, const vec3 axis); +glmc_rotate_make(mat4 m, float angle, vec3 axis); CGLM_EXPORT void -glmc_rotate(mat4 m, float angle, const vec3 axis); +glmc_rotate(mat4 m, float angle, vec3 axis); CGLM_EXPORT void -glmc_rotate_at(mat4 m, const vec3 pivot, float angle, const vec3 axis); +glmc_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis); CGLM_EXPORT void -glmc_rotate_atm(mat4 m, const vec3 pivot, float angle, const vec3 axis); +glmc_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis); CGLM_EXPORT void -glmc_decompose_scalev(const mat4 m, vec3 s); +glmc_decompose_scalev(mat4 m, vec3 s); CGLM_EXPORT bool -glmc_uniscaled(const mat4 m); +glmc_uniscaled(mat4 m); CGLM_EXPORT void -glmc_decompose_rs(const mat4 m, mat4 r, vec3 s); +glmc_decompose_rs(mat4 m, mat4 r, vec3 s); CGLM_EXPORT void -glmc_decompose(const mat4 m, vec4 t, mat4 r, vec3 s); +glmc_decompose(mat4 m, vec4 t, mat4 r, vec3 s); /* affine-mat */ CGLM_EXPORT void -glmc_mul(const mat4 m1, const mat4 m2, mat4 dest); +glmc_mul(mat4 m1, mat4 m2, mat4 dest); CGLM_EXPORT void -glmc_mul_rot(const mat4 m1, const mat4 m2, mat4 dest); +glmc_mul_rot(mat4 m1, mat4 m2, mat4 dest); CGLM_EXPORT void diff --git a/include/cglm/call/box.h b/include/cglm/call/box.h index fe4ab90..afb7558 100644 --- a/include/cglm/call/box.h +++ b/include/cglm/call/box.h @@ -15,26 +15,26 @@ extern "C" { CGLM_EXPORT void -glmc_aabb_transform(const vec3 box[2], const mat4 m, vec3 dest[2]); +glmc_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]); CGLM_EXPORT void -glmc_aabb_merge(const vec3 box1[2], const vec3 box2[2], vec3 dest[2]); +glmc_aabb_merge(vec3 box1[2], vec3 box2[2], vec3 dest[2]); CGLM_EXPORT void -glmc_aabb_crop(const vec3 box[2], const vec3 cropBox[2], vec3 dest[2]); +glmc_aabb_crop(vec3 box[2], vec3 cropBox[2], vec3 dest[2]); CGLM_EXPORT void -glmc_aabb_crop_until(const vec3 box[2], - const vec3 cropBox[2], - const vec3 clampBox[2], - vec3 dest[2]); +glmc_aabb_crop_until(vec3 box[2], + vec3 cropBox[2], + vec3 clampBox[2], + vec3 dest[2]); CGLM_EXPORT bool -glmc_aabb_frustum(const vec3 box[2], vec4 planes[6]); +glmc_aabb_frustum(vec3 box[2], vec4 planes[6]); CGLM_EXPORT void @@ -42,35 +42,35 @@ glmc_aabb_invalidate(vec3 box[2]); CGLM_EXPORT bool -glmc_aabb_isvalid(const vec3 box[2]); +glmc_aabb_isvalid(vec3 box[2]); CGLM_EXPORT float -glmc_aabb_size(const vec3 box[2]); +glmc_aabb_size(vec3 box[2]); CGLM_EXPORT float -glmc_aabb_radius(const vec3 box[2]); +glmc_aabb_radius(vec3 box[2]); CGLM_EXPORT void -glmc_aabb_center(const vec3 box[2], vec3 dest); +glmc_aabb_center(vec3 box[2], vec3 dest); CGLM_EXPORT bool -glmc_aabb_aabb(const vec3 box[2], const vec3 other[2]); +glmc_aabb_aabb(vec3 box[2], vec3 other[2]); CGLM_EXPORT bool -glmc_aabb_point(const vec3 box[2], const vec3 point); +glmc_aabb_point(vec3 box[2], vec3 point); CGLM_EXPORT bool -glmc_aabb_contains(const vec3 box[2], const vec3 other[2]); +glmc_aabb_contains(vec3 box[2], vec3 other[2]); CGLM_EXPORT bool -glmc_aabb_sphere(const vec3 box[2], const vec4 s); +glmc_aabb_sphere(vec3 box[2], vec4 s); #ifdef __cplusplus } diff --git a/include/cglm/call/cam.h b/include/cglm/call/cam.h index 9b42b74..017b6fc 100644 --- a/include/cglm/call/cam.h +++ b/include/cglm/call/cam.h @@ -21,7 +21,7 @@ glmc_frustum(float left, float top, float nearVal, float farVal, - mat4 dest); + mat4 dest); CGLM_EXPORT void @@ -31,19 +31,19 @@ glmc_ortho(float left, float top, float nearVal, float farVal, - mat4 dest); + mat4 dest); CGLM_EXPORT void -glmc_ortho_aabb(const vec3 box[2], mat4 dest); +glmc_ortho_aabb(vec3 box[2], mat4 dest); CGLM_EXPORT void -glmc_ortho_aabb_p(const vec3 box[2], float padding, mat4 dest); +glmc_ortho_aabb_p(vec3 box[2], float padding, mat4 dest); CGLM_EXPORT void -glmc_ortho_aabb_pz(const vec3 box[2], float padding, mat4 dest); +glmc_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest); CGLM_EXPORT void @@ -59,7 +59,7 @@ glmc_perspective(float fovy, float aspect, float nearVal, float farVal, - mat4 dest); + mat4 dest); CGLM_EXPORT void @@ -75,19 +75,19 @@ glmc_perspective_resize(float aspect, mat4 proj); CGLM_EXPORT void -glmc_lookat(const vec3 eye, const vec3 center, const vec3 up, mat4 dest); +glmc_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest); CGLM_EXPORT void -glmc_look(const vec3 eye, const vec3 dir, const vec3 up, mat4 dest); +glmc_look(vec3 eye, vec3 dir, vec3 up, mat4 dest); CGLM_EXPORT void -glmc_look_anyup(const vec3 eye, const vec3 dir, mat4 dest); +glmc_look_anyup(vec3 eye, vec3 dir, mat4 dest); CGLM_EXPORT void -glmc_persp_decomp(const mat4 proj, +glmc_persp_decomp(mat4 proj, float * __restrict nearVal, float * __restrict farVal, float * __restrict top, @@ -97,45 +97,45 @@ glmc_persp_decomp(const mat4 proj, CGLM_EXPORT void -glmc_persp_decompv(const mat4 proj, float dest[6]); +glmc_persp_decompv(mat4 proj, float dest[6]); CGLM_EXPORT void -glmc_persp_decomp_x(const mat4 proj, +glmc_persp_decomp_x(mat4 proj, float * __restrict left, float * __restrict right); CGLM_EXPORT void -glmc_persp_decomp_y(const mat4 proj, +glmc_persp_decomp_y(mat4 proj, float * __restrict top, float * __restrict bottom); CGLM_EXPORT void -glmc_persp_decomp_z(const mat4 proj, +glmc_persp_decomp_z(mat4 proj, float * __restrict nearVal, float * __restrict farVal); CGLM_EXPORT void -glmc_persp_decomp_far(const mat4 proj, float * __restrict farVal); +glmc_persp_decomp_far(mat4 proj, float * __restrict farVal); CGLM_EXPORT void -glmc_persp_decomp_near(const mat4 proj, float * __restrict nearVal); +glmc_persp_decomp_near(mat4 proj, float * __restrict nearVal); CGLM_EXPORT float -glmc_persp_fovy(const mat4 proj); +glmc_persp_fovy(mat4 proj); CGLM_EXPORT float -glmc_persp_aspect(const mat4 proj); +glmc_persp_aspect(mat4 proj); CGLM_EXPORT void -glmc_persp_sizes(const mat4 proj, float fovy, vec4 dest); +glmc_persp_sizes(mat4 proj, float fovy, vec4 dest); #ifdef __cplusplus } diff --git a/include/cglm/call/curve.h b/include/cglm/call/curve.h index 07610f3..061fdb9 100644 --- a/include/cglm/call/curve.h +++ b/include/cglm/call/curve.h @@ -15,7 +15,7 @@ extern "C" { CGLM_EXPORT float -glmc_smc(float s, const mat4 m, const vec4 c); +glmc_smc(float s, mat4 m, vec4 c); #ifdef __cplusplus } diff --git a/include/cglm/call/euler.h b/include/cglm/call/euler.h index 71746bf..9b85485 100644 --- a/include/cglm/call/euler.h +++ b/include/cglm/call/euler.h @@ -15,39 +15,39 @@ extern "C" { CGLM_EXPORT void -glmc_euler_angles(const mat4 m, vec3 dest); +glmc_euler_angles(mat4 m, vec3 dest); CGLM_EXPORT void -glmc_euler(const vec3 angles, mat4 dest); +glmc_euler(vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_xyz(const vec3 angles, mat4 dest); +glmc_euler_xyz(vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_zyx(const vec3 angles, mat4 dest); +glmc_euler_zyx(vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_zxy(const vec3 angles, mat4 dest); +glmc_euler_zxy(vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_xzy(const vec3 angles, mat4 dest); +glmc_euler_xzy(vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_yzx(const vec3 angles, mat4 dest); +glmc_euler_yzx(vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_yxz(const vec3 angles, mat4 dest); +glmc_euler_yxz(vec3 angles, mat4 dest); CGLM_EXPORT void -glmc_euler_by_order(const vec3 angles, glm_euler_sq axis, mat4 dest); +glmc_euler_by_order(vec3 angles, glm_euler_sq axis, mat4 dest); #ifdef __cplusplus } diff --git a/include/cglm/call/frustum.h b/include/cglm/call/frustum.h index be97fc3..6b4facb 100644 --- a/include/cglm/call/frustum.h +++ b/include/cglm/call/frustum.h @@ -15,26 +15,26 @@ extern "C" { CGLM_EXPORT void -glmc_frustum_planes(const mat4 m, vec4 dest[6]); +glmc_frustum_planes(mat4 m, vec4 dest[6]); CGLM_EXPORT void -glmc_frustum_corners(const mat4 invMat, vec4 dest[8]); +glmc_frustum_corners(mat4 invMat, vec4 dest[8]); CGLM_EXPORT void -glmc_frustum_center(const vec4 corners[8], vec4 dest); +glmc_frustum_center(vec4 corners[8], vec4 dest); CGLM_EXPORT void -glmc_frustum_box(const vec4 corners[8], const mat4 m, vec3 box[2]); +glmc_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]); CGLM_EXPORT void -glmc_frustum_corners_at(const vec4 corners[8], - float splitDist, - float farDist, - vec4 planeCorners[4]); +glmc_frustum_corners_at(vec4 corners[8], + float splitDist, + float farDist, + vec4 planeCorners[4]); #ifdef __cplusplus } #endif diff --git a/include/cglm/call/io.h b/include/cglm/call/io.h index 421e719..b6c50f6 100644 --- a/include/cglm/call/io.h +++ b/include/cglm/call/io.h @@ -15,28 +15,28 @@ extern "C" { CGLM_EXPORT void -glmc_mat4_print(const mat4 matrix, - FILE * const __restrict ostream); +glmc_mat4_print(mat4 matrix, + FILE * __restrict ostream); CGLM_EXPORT void -glmc_mat3_print(const mat3 matrix, - FILE * const __restrict ostream); +glmc_mat3_print(mat3 matrix, + FILE * __restrict ostream); CGLM_EXPORT void -glmc_vec4_print(const vec4 vec, - FILE * const __restrict ostream); +glmc_vec4_print(vec4 vec, + FILE * __restrict ostream); CGLM_EXPORT void -glmc_vec3_print(const vec3 vec, - FILE * const __restrict ostream); +glmc_vec3_print(vec3 vec, + FILE * __restrict ostream); CGLM_EXPORT void -glmc_versor_print(const versor vec, - FILE * const __restrict ostream); +glmc_versor_print(versor vec, + FILE * __restrict ostream); #ifdef __cplusplus } diff --git a/include/cglm/call/mat3.h b/include/cglm/call/mat3.h index 68d5535..fbd8270 100644 --- a/include/cglm/call/mat3.h +++ b/include/cglm/call/mat3.h @@ -18,7 +18,7 @@ extern "C" { CGLM_EXPORT void -glmc_mat3_copy(const mat3 mat, mat3 dest); +glmc_mat3_copy(mat3 mat, mat3 dest); CGLM_EXPORT void @@ -26,15 +26,15 @@ glmc_mat3_identity(mat3 mat); CGLM_EXPORT void -glmc_mat3_identity_array(mat3 * const __restrict mat, size_t count); +glmc_mat3_identity_array(mat3 * __restrict mat, size_t count); CGLM_EXPORT void -glmc_mat3_mul(const mat3 m1, const mat3 m2, mat3 dest); +glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest); CGLM_EXPORT void -glmc_mat3_transpose_to(const mat3 m, mat3 dest); +glmc_mat3_transpose_to(mat3 m, mat3 dest); CGLM_EXPORT void @@ -42,15 +42,15 @@ glmc_mat3_transpose(mat3 m); CGLM_EXPORT void -glmc_mat3_mulv(const mat3 m, const vec3 v, vec3 dest); +glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest); CGLM_EXPORT float -glmc_mat3_trace(const mat3 m); +glmc_mat3_trace(mat3 m); CGLM_EXPORT void -glmc_mat3_quat(const mat3 m, versor dest); +glmc_mat3_quat(mat3 m, versor dest); CGLM_EXPORT void @@ -58,11 +58,11 @@ glmc_mat3_scale(mat3 m, float s); CGLM_EXPORT float -glmc_mat3_det(const mat3 mat); +glmc_mat3_det(mat3 mat); CGLM_EXPORT void -glmc_mat3_inv(const mat3 mat, mat3 dest); +glmc_mat3_inv(mat3 mat, mat3 dest); CGLM_EXPORT void @@ -74,7 +74,7 @@ glmc_mat3_swap_row(mat3 mat, int row1, int row2); CGLM_EXPORT float -glmc_mat3_rmc(const vec3 r, const mat3 m, const vec3 c); +glmc_mat3_rmc(vec3 r, mat3 m, vec3 c); #ifdef __cplusplus } diff --git a/include/cglm/call/mat4.h b/include/cglm/call/mat4.h index 43e4cec..54fbcbe 100644 --- a/include/cglm/call/mat4.h +++ b/include/cglm/call/mat4.h @@ -19,11 +19,11 @@ extern "C" { CGLM_EXPORT void -glmc_mat4_ucopy(const mat4 mat, mat4 dest); +glmc_mat4_ucopy(mat4 mat, mat4 dest); CGLM_EXPORT void -glmc_mat4_copy(const mat4 mat, mat4 dest); +glmc_mat4_copy(mat4 mat, mat4 dest); CGLM_EXPORT void @@ -31,51 +31,51 @@ glmc_mat4_identity(mat4 mat); CGLM_EXPORT void -glmc_mat4_identity_array(mat4 * const __restrict mat, size_t count); +glmc_mat4_identity_array(mat4 * __restrict mat, size_t count); CGLM_EXPORT void -glmc_mat4_pick3(const mat4 mat, mat3 dest); +glmc_mat4_pick3(mat4 mat, mat3 dest); CGLM_EXPORT void -glmc_mat4_pick3t(const mat4 mat, mat3 dest); +glmc_mat4_pick3t(mat4 mat, mat3 dest); CGLM_EXPORT void -glmc_mat4_ins3(const mat3 mat, mat4 dest); +glmc_mat4_ins3(mat3 mat, mat4 dest); CGLM_EXPORT void -glmc_mat4_mul(const mat4 m1, const mat4 m2, mat4 dest); +glmc_mat4_mul(mat4 m1, mat4 m2, mat4 dest); CGLM_EXPORT void -glmc_mat4_mulN(mat4 * const __restrict matrices[], uint32_t len, mat4 dest); +glmc_mat4_mulN(mat4 * __restrict matrices[], uint32_t len, mat4 dest); CGLM_EXPORT void -glmc_mat4_mulv(const mat4 m, const vec4 v, vec4 dest); +glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest); CGLM_EXPORT void -glmc_mat4_mulv3(const mat4 m, const vec3 v, float last, vec3 dest); +glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest); CGLM_EXPORT float -glmc_mat4_trace(const mat4 m); +glmc_mat4_trace(mat4 m); CGLM_EXPORT float -glmc_mat4_trace3(const mat4 m); +glmc_mat4_trace3(mat4 m); CGLM_EXPORT void -glmc_mat4_quat(const mat4 m, versor dest); +glmc_mat4_quat(mat4 m, versor dest); CGLM_EXPORT void -glmc_mat4_transpose_to(const mat4 m, mat4 dest); +glmc_mat4_transpose_to(mat4 m, mat4 dest); CGLM_EXPORT void @@ -91,19 +91,19 @@ glmc_mat4_scale(mat4 m, float s); CGLM_EXPORT float -glmc_mat4_det(const mat4 mat); +glmc_mat4_det(mat4 mat); CGLM_EXPORT void -glmc_mat4_inv(const mat4 mat, mat4 dest); +glmc_mat4_inv(mat4 mat, mat4 dest); CGLM_EXPORT void -glmc_mat4_inv_precise(const mat4 mat, mat4 dest); +glmc_mat4_inv_precise(mat4 mat, mat4 dest); CGLM_EXPORT void -glmc_mat4_inv_fast(const mat4 mat, mat4 dest); +glmc_mat4_inv_fast(mat4 mat, mat4 dest); CGLM_EXPORT void @@ -115,7 +115,7 @@ glmc_mat4_swap_row(mat4 mat, int row1, int row2); CGLM_EXPORT float -glmc_mat4_rmc(const vec4 r, const mat4 m, const vec4 c); +glmc_mat4_rmc(vec4 r, mat4 m, vec4 c); #ifdef __cplusplus } diff --git a/include/cglm/call/project.h b/include/cglm/call/project.h index 92c25e1..35ac087 100644 --- a/include/cglm/call/project.h +++ b/include/cglm/call/project.h @@ -15,15 +15,15 @@ extern "C" { CGLM_EXPORT void -glmc_unprojecti(const vec3 pos, const mat4 invMat, const vec4 vp, vec3 dest); +glmc_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest); CGLM_EXPORT void -glmc_unproject(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest); +glmc_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest); CGLM_EXPORT void -glmc_project(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest); +glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest); #ifdef __cplusplus } diff --git a/include/cglm/call/quat.h b/include/cglm/call/quat.h index 03d8381..2778a58 100644 --- a/include/cglm/call/quat.h +++ b/include/cglm/call/quat.h @@ -19,7 +19,7 @@ glmc_quat_identity(versor q); CGLM_EXPORT void -glmc_quat_identity_array(versor * const __restrict q, size_t count); +glmc_quat_identity_array(versor * __restrict q, size_t count); CGLM_EXPORT void @@ -31,19 +31,19 @@ glmc_quat(versor q, float angle, float x, float y, float z); CGLM_EXPORT void -glmc_quatv(versor q, float angle, const vec3 axis); +glmc_quatv(versor q, float angle, vec3 axis); CGLM_EXPORT void -glmc_quat_copy(const versor q, versor dest); +glmc_quat_copy(versor q, versor dest); CGLM_EXPORT float -glmc_quat_norm(const versor q); +glmc_quat_norm(versor q); CGLM_EXPORT void -glmc_quat_normalize_to(const versor q, versor dest); +glmc_quat_normalize_to(versor q, versor dest); CGLM_EXPORT void @@ -51,107 +51,103 @@ glmc_quat_normalize(versor q); CGLM_EXPORT float -glmc_quat_dot(const versor p, const versor q); +glmc_quat_dot(versor p, versor q); CGLM_EXPORT void -glmc_quat_conjugate(const versor q, versor dest); +glmc_quat_conjugate(versor q, versor dest); CGLM_EXPORT void -glmc_quat_inv(const versor q, versor dest); +glmc_quat_inv(versor q, versor dest); CGLM_EXPORT void -glmc_quat_add(const versor p, const versor q, versor dest); +glmc_quat_add(versor p, versor q, versor dest); CGLM_EXPORT void -glmc_quat_sub(const versor p, const versor q, versor dest); +glmc_quat_sub(versor p, versor q, versor dest); CGLM_EXPORT float -glmc_quat_real(const versor q); +glmc_quat_real(versor q); CGLM_EXPORT void -glmc_quat_imag(const versor q, vec3 dest); +glmc_quat_imag(versor q, vec3 dest); CGLM_EXPORT void -glmc_quat_imagn(const versor q, vec3 dest); +glmc_quat_imagn(versor q, vec3 dest); CGLM_EXPORT float -glmc_quat_imaglen(const versor q); +glmc_quat_imaglen(versor q); CGLM_EXPORT float -glmc_quat_angle(const versor q); +glmc_quat_angle(versor q); CGLM_EXPORT void -glmc_quat_axis(const versor q, versor dest); +glmc_quat_axis(versor q, versor dest); CGLM_EXPORT void -glmc_quat_mul(const versor p, const versor q, versor dest); +glmc_quat_mul(versor p, versor q, versor dest); CGLM_EXPORT void -glmc_quat_mat4(const versor q, mat4 dest); +glmc_quat_mat4(versor q, mat4 dest); CGLM_EXPORT void -glmc_quat_mat4t(const versor q, mat4 dest); +glmc_quat_mat4t(versor q, mat4 dest); CGLM_EXPORT void -glmc_quat_mat3(const versor q, mat3 dest); +glmc_quat_mat3(versor q, mat3 dest); CGLM_EXPORT void -glmc_quat_mat3t(const versor q, mat3 dest); +glmc_quat_mat3t(versor q, mat3 dest); CGLM_EXPORT void -glmc_quat_lerp(const versor from, const versor to, float t, versor dest); +glmc_quat_lerp(versor from, versor to, float t, versor dest); CGLM_EXPORT void -glmc_quat_slerp(const versor q, const versor r, float t, versor dest); +glmc_quat_slerp(versor q, versor r, float t, versor dest); CGLM_EXPORT void -glmc_quat_look(const vec3 eye, const versor ori, mat4 dest); +glmc_quat_look(vec3 eye, versor ori, mat4 dest); CGLM_EXPORT void -glmc_quat_for(const vec3 dir, const vec3 fwd, const vec3 up, versor dest); +glmc_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest); CGLM_EXPORT void -glmc_quat_forp(const vec3 from, - const vec3 to, - const vec3 fwd, - const vec3 up, - versor dest); +glmc_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest); CGLM_EXPORT void -glmc_quat_rotatev(const versor from, const vec3 to, vec3 dest); +glmc_quat_rotatev(versor from, vec3 to, vec3 dest); CGLM_EXPORT void -glmc_quat_rotate(const mat4 m, const versor q, mat4 dest); +glmc_quat_rotate(mat4 m, versor q, mat4 dest); CGLM_EXPORT void -glmc_quat_rotate_at(mat4 model, const versor q, const vec3 pivot); +glmc_quat_rotate_at(mat4 model, versor q, vec3 pivot); CGLM_EXPORT void -glmc_quat_rotate_atm(mat4 m, const versor q, const vec3 pivot); +glmc_quat_rotate_atm(mat4 m, versor q, vec3 pivot); #ifdef __cplusplus } diff --git a/include/cglm/call/sphere.h b/include/cglm/call/sphere.h index 7b4d0d7..9b96546 100644 --- a/include/cglm/call/sphere.h +++ b/include/cglm/call/sphere.h @@ -15,23 +15,23 @@ extern "C" { CGLM_EXPORT float -glmc_sphere_radii(const vec4 s); +glmc_sphere_radii(vec4 s); CGLM_EXPORT void -glmc_sphere_transform(const vec4 s, const mat4 m, vec4 dest); +glmc_sphere_transform(vec4 s, mat4 m, vec4 dest); CGLM_EXPORT void -glmc_sphere_merge(const vec4 s1, const vec4 s2, vec4 dest); +glmc_sphere_merge(vec4 s1, vec4 s2, vec4 dest); CGLM_EXPORT bool -glmc_sphere_sphere(const vec4 s1, const vec4 s2); +glmc_sphere_sphere(vec4 s1, vec4 s2); CGLM_EXPORT bool -glmc_sphere_point(const vec4 s, const vec3 point); +glmc_sphere_point(vec4 s, vec3 point); #ifdef __cplusplus } diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index cc7c78e..9763403 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -22,11 +22,11 @@ extern "C" { CGLM_EXPORT void -glmc_vec3(const vec4 v4, vec3 dest); +glmc_vec3(vec4 v4, vec3 dest); CGLM_EXPORT void -glmc_vec3_copy(const vec3 a, vec3 dest); +glmc_vec3_copy(vec3 a, vec3 dest); CGLM_EXPORT void @@ -38,27 +38,27 @@ glmc_vec3_one(vec3 v); CGLM_EXPORT float -glmc_vec3_dot(const vec3 a, const vec3 b); +glmc_vec3_dot(vec3 a, vec3 b); CGLM_EXPORT void -glmc_vec3_cross(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_cross(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_crossn(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_crossn(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT float -glmc_vec3_norm(const vec3 v); +glmc_vec3_norm(vec3 v); CGLM_EXPORT float -glmc_vec3_norm2(const vec3 v); +glmc_vec3_norm2(vec3 v); CGLM_EXPORT void -glmc_vec3_normalize_to(const vec3 v, vec3 dest); +glmc_vec3_normalize_to(vec3 v, vec3 dest); CGLM_EXPORT void @@ -66,63 +66,63 @@ glmc_vec3_normalize(vec3 v); CGLM_EXPORT void -glmc_vec3_add(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_add(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_adds(const vec3 v, float s, vec3 dest); +glmc_vec3_adds(vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec3_sub(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_sub(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_subs(const vec3 v, float s, vec3 dest); +glmc_vec3_subs(vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec3_mul(const vec3 a, const vec3 b, vec3 d); +glmc_vec3_mul(vec3 a, vec3 b, vec3 d); CGLM_EXPORT void -glmc_vec3_scale(const vec3 v, float s, vec3 dest); +glmc_vec3_scale(vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec3_scale_as(const vec3 v, float s, vec3 dest); +glmc_vec3_scale_as(vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec3_div(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_div(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_divs(const vec3 a, float s, vec3 dest); +glmc_vec3_divs(vec3 a, float s, vec3 dest); CGLM_EXPORT void -glmc_vec3_addadd(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_addadd(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_subadd(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_subadd(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_muladd(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_muladd(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_muladds(const vec3 a, float s, vec3 dest); +glmc_vec3_muladds(vec3 a, float s, vec3 dest); CGLM_EXPORT void -glmc_vec3_maxadd(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_maxadd(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_minadd(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_minadd(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void @@ -130,47 +130,47 @@ glmc_vec3_negate(vec3 v); CGLM_EXPORT void -glmc_vec3_negate_to(const vec3 v, vec3 dest); +glmc_vec3_negate_to(vec3 v, vec3 dest); CGLM_EXPORT float -glmc_vec3_angle(const vec3 a, const vec3 b); +glmc_vec3_angle(vec3 a, vec3 b); CGLM_EXPORT void -glmc_vec3_rotate(vec3 v, float angle, const vec3 axis); +glmc_vec3_rotate(vec3 v, float angle, vec3 axis); CGLM_EXPORT void -glmc_vec3_rotate_m4(const mat4 m, const vec3 v, vec3 dest); +glmc_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec3_rotate_m3(const mat3 m, const vec3 v, vec3 dest); +glmc_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec3_proj(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_proj(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_center(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_center(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT float -glmc_vec3_distance2(const vec3 a, const vec3 b); +glmc_vec3_distance2(vec3 a, vec3 b); CGLM_EXPORT float -glmc_vec3_distance(const vec3 a, const vec3 b); +glmc_vec3_distance(vec3 a, vec3 b); CGLM_EXPORT void -glmc_vec3_maxv(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_maxv(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void -glmc_vec3_minv(const vec3 a, const vec3 b, vec3 dest); +glmc_vec3_minv(vec3 a, vec3 b, vec3 dest); CGLM_EXPORT void @@ -178,17 +178,17 @@ glmc_vec3_clamp(vec3 v, float minVal, float maxVal); CGLM_EXPORT void -glmc_vec3_ortho(const vec3 v, vec3 dest); +glmc_vec3_ortho(vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec3_lerp(const vec3 from, const vec3 to, float t, vec3 dest); +glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest); /* ext */ CGLM_EXPORT void -glmc_vec3_mulv(const vec3 a, const vec3 b, vec3 d); +glmc_vec3_mulv(vec3 a, vec3 b, vec3 d); CGLM_EXPORT void @@ -196,51 +196,51 @@ glmc_vec3_broadcast(float val, vec3 d); CGLM_EXPORT bool -glmc_vec3_eq(const vec3 v, float val); +glmc_vec3_eq(vec3 v, float val); CGLM_EXPORT bool -glmc_vec3_eq_eps(const vec3 v, float val); +glmc_vec3_eq_eps(vec3 v, float val); CGLM_EXPORT bool -glmc_vec3_eq_all(const vec3 v); +glmc_vec3_eq_all(vec3 v); CGLM_EXPORT bool -glmc_vec3_eqv(const vec3 a, const vec3 b); +glmc_vec3_eqv(vec3 a, vec3 b); CGLM_EXPORT bool -glmc_vec3_eqv_eps(const vec3 a, const vec3 b); +glmc_vec3_eqv_eps(vec3 a, vec3 b); CGLM_EXPORT float -glmc_vec3_max(const vec3 v); +glmc_vec3_max(vec3 v); CGLM_EXPORT float -glmc_vec3_min(const vec3 v); +glmc_vec3_min(vec3 v); CGLM_EXPORT bool -glmc_vec3_isnan(const vec3 v); +glmc_vec3_isnan(vec3 v); CGLM_EXPORT bool -glmc_vec3_isinf(const vec3 v); +glmc_vec3_isinf(vec3 v); CGLM_EXPORT bool -glmc_vec3_isvalid(const vec3 v); +glmc_vec3_isvalid(vec3 v); CGLM_EXPORT void -glmc_vec3_sign(const vec3 v, vec3 dest); +glmc_vec3_sign(vec3 v, vec3 dest); CGLM_EXPORT void -glmc_vec3_sqrt(const vec3 v, vec3 dest); +glmc_vec3_sqrt(vec3 v, vec3 dest); #ifdef __cplusplus } diff --git a/include/cglm/call/vec4.h b/include/cglm/call/vec4.h index c862ce6..936bb52 100644 --- a/include/cglm/call/vec4.h +++ b/include/cglm/call/vec4.h @@ -23,7 +23,7 @@ extern "C" { CGLM_EXPORT void -glmc_vec4(const vec3 v3, float last, vec4 dest); +glmc_vec4(vec3 v3, float last, vec4 dest); CGLM_EXPORT void @@ -35,31 +35,31 @@ glmc_vec4_one(vec4 v); CGLM_EXPORT void -glmc_vec4_copy3(const vec4 v, vec3 dest); +glmc_vec4_copy3(vec4 v, vec3 dest); CGLM_EXPORT void -glmc_vec4_copy(const vec4 v, vec4 dest); +glmc_vec4_copy(vec4 v, vec4 dest); CGLM_EXPORT void -glmc_vec4_ucopy(const vec4 v, vec4 dest); +glmc_vec4_ucopy(vec4 v, vec4 dest); CGLM_EXPORT float -glmc_vec4_dot(const vec4 a, const vec4 b); +glmc_vec4_dot(vec4 a, vec4 b); CGLM_EXPORT float -glmc_vec4_norm(const vec4 v); +glmc_vec4_norm(vec4 v); CGLM_EXPORT float -glmc_vec4_norm2(const vec4 v); +glmc_vec4_norm2(vec4 v); CGLM_EXPORT void -glmc_vec4_normalize_to(const vec4 v, vec4 dest); +glmc_vec4_normalize_to(vec4 v, vec4 dest); CGLM_EXPORT void @@ -67,63 +67,63 @@ glmc_vec4_normalize(vec4 v); CGLM_EXPORT void -glmc_vec4_add(const vec4 a, const vec4 b, vec4 dest); +glmc_vec4_add(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_adds(const vec4 v, float s, vec4 dest); +glmc_vec4_adds(vec4 v, float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_sub(const vec4 a, const vec4 b, vec4 dest); +glmc_vec4_sub(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_subs(const vec4 v, float s, vec4 dest); +glmc_vec4_subs(vec4 v, float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_mul(const vec4 a, const vec4 b, vec4 d); +glmc_vec4_mul(vec4 a, vec4 b, vec4 d); CGLM_EXPORT void -glmc_vec4_scale(const vec4 v, float s, vec4 dest); +glmc_vec4_scale(vec4 v, float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_scale_as(const vec3 v, float s, vec3 dest); +glmc_vec4_scale_as(vec3 v, float s, vec3 dest); CGLM_EXPORT void -glmc_vec4_div(const vec4 a, const vec4 b, vec4 dest); +glmc_vec4_div(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_divs(const vec4 v, float s, vec4 dest); +glmc_vec4_divs(vec4 v, float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_addadd(const vec4 a, const vec4 b, vec4 dest); +glmc_vec4_addadd(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_subadd(const vec4 a, const vec4 b, vec4 dest); +glmc_vec4_subadd(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_muladd(const vec4 a, const vec4 b, vec4 dest); +glmc_vec4_muladd(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_muladds(const vec4 a, float s, vec4 dest); +glmc_vec4_muladds(vec4 a, float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_maxadd(const vec4 a, const vec4 b, vec4 dest); +glmc_vec4_maxadd(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_minadd(const vec4 a, const vec4 b, vec4 dest); +glmc_vec4_minadd(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void @@ -131,19 +131,19 @@ glmc_vec4_negate(vec4 v); CGLM_EXPORT void -glmc_vec4_negate_to(const vec4 v, vec4 dest); +glmc_vec4_negate_to(vec4 v, vec4 dest); CGLM_EXPORT float -glmc_vec4_distance(const vec4 a, const vec4 b); +glmc_vec4_distance(vec4 a, vec4 b); CGLM_EXPORT void -glmc_vec4_maxv(const vec4 a, const vec4 b, vec4 dest); +glmc_vec4_maxv(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void -glmc_vec4_minv(const vec4 a, const vec4 b, vec4 dest); +glmc_vec4_minv(vec4 a, vec4 b, vec4 dest); CGLM_EXPORT void @@ -151,7 +151,7 @@ glmc_vec4_clamp(vec4 v, float minVal, float maxVal); CGLM_EXPORT void -glmc_vec4_lerp(const vec4 from, const vec4 to, float t, vec4 dest); +glmc_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest); CGLM_EXPORT void @@ -161,7 +161,7 @@ glmc_vec4_cubic(float s, vec4 dest); CGLM_EXPORT void -glmc_vec4_mulv(const vec4 a, const vec4 b, vec4 d); +glmc_vec4_mulv(vec4 a, vec4 b, vec4 d); CGLM_EXPORT void @@ -169,51 +169,51 @@ glmc_vec4_broadcast(float val, vec4 d); CGLM_EXPORT bool -glmc_vec4_eq(const vec4 v, float val); +glmc_vec4_eq(vec4 v, float val); CGLM_EXPORT bool -glmc_vec4_eq_eps(const vec4 v, float val); +glmc_vec4_eq_eps(vec4 v, float val); CGLM_EXPORT bool -glmc_vec4_eq_all(const vec4 v); +glmc_vec4_eq_all(vec4 v); CGLM_EXPORT bool -glmc_vec4_eqv(const vec4 a, const vec4 b); +glmc_vec4_eqv(vec4 a, vec4 b); CGLM_EXPORT bool -glmc_vec4_eqv_eps(const vec4 a, const vec4 b); +glmc_vec4_eqv_eps(vec4 a, vec4 b); CGLM_EXPORT float -glmc_vec4_max(const vec4 v); +glmc_vec4_max(vec4 v); CGLM_EXPORT float -glmc_vec4_min(const vec4 v); +glmc_vec4_min(vec4 v); CGLM_EXPORT bool -glmc_vec4_isnan(const vec4 v); +glmc_vec4_isnan(vec4 v); CGLM_EXPORT bool -glmc_vec4_isinf(const vec4 v); +glmc_vec4_isinf(vec4 v); CGLM_EXPORT bool -glmc_vec4_isvalid(const vec4 v); +glmc_vec4_isvalid(vec4 v); CGLM_EXPORT void -glmc_vec4_sign(const vec4 v, vec4 dest); +glmc_vec4_sign(vec4 v, vec4 dest); CGLM_EXPORT void -glmc_vec4_sqrt(const vec4 v, vec4 dest); +glmc_vec4_sqrt(vec4 v, vec4 dest); #ifdef __cplusplus } diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 2255cf6..e77b989 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -147,7 +147,7 @@ glm_ortho(float left, */ CGLM_INLINE void -glm_ortho_aabb(const vec3 box[2], mat4 dest) { +glm_ortho_aabb(vec3 box[2], mat4 dest) { glm_ortho(box[0][0], box[1][0], box[0][1], box[1][1], -box[1][2], -box[0][2], @@ -165,7 +165,7 @@ glm_ortho_aabb(const vec3 box[2], mat4 dest) { */ CGLM_INLINE void -glm_ortho_aabb_p(const vec3 box[2], float padding, mat4 dest) { +glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) { glm_ortho(box[0][0] - padding, box[1][0] + padding, box[0][1] - padding, box[1][1] + padding, -(box[1][2] + padding), -(box[0][2] - padding), @@ -183,7 +183,7 @@ glm_ortho_aabb_p(const vec3 box[2], float padding, mat4 dest) { */ CGLM_INLINE void -glm_ortho_aabb_pz(const vec3 box[2], float padding, mat4 dest) { +glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) { glm_ortho(box[0][0], box[1][0], box[0][1], box[1][1], -(box[1][2] + padding), -(box[0][2] - padding), @@ -218,7 +218,9 @@ glm_ortho_default(float aspect, mat4 dest) { */ CGLM_INLINE void -glm_ortho_default_s(float aspect, float size, mat4 dest) { +glm_ortho_default_s(float aspect, + float size, + mat4 dest) { if (aspect >= 1.0f) { glm_ortho(-size * aspect, size * aspect, @@ -336,10 +338,10 @@ glm_perspective_resize(float aspect, mat4 proj) { */ CGLM_INLINE void -glm_lookat(const vec3 eye, - const vec3 center, - const vec3 up, - mat4 dest) { +glm_lookat(vec3 eye, + vec3 center, + vec3 up, + mat4 dest) { CGLM_ALIGN(8) vec3 f, u, s; glm_vec3_sub(center, eye, f); @@ -380,7 +382,7 @@ glm_lookat(const vec3 eye, */ CGLM_INLINE void -glm_look(const vec3 eye, const vec3 dir, const vec3 up, mat4 dest) { +glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { CGLM_ALIGN(8) vec3 target; glm_vec3_add(eye, dir, target); glm_lookat(eye, target, up, dest); @@ -398,7 +400,7 @@ glm_look(const vec3 eye, const vec3 dir, const vec3 up, mat4 dest) { */ CGLM_INLINE void -glm_look_anyup(const vec3 eye, const vec3 dir, mat4 dest) { +glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) { CGLM_ALIGN(8) vec3 up; glm_vec3_ortho(dir, up); glm_look(eye, dir, up, dest); @@ -417,7 +419,7 @@ glm_look_anyup(const vec3 eye, const vec3 dir, mat4 dest) { */ CGLM_INLINE void -glm_persp_decomp(const mat4 proj, +glm_persp_decomp(mat4 proj, float * __restrict nearVal, float * __restrict farVal, float * __restrict top, @@ -457,7 +459,7 @@ glm_persp_decomp(const mat4 proj, */ CGLM_INLINE void -glm_persp_decompv(const mat4 proj, float dest[6]) { +glm_persp_decompv(mat4 proj, float dest[6]) { glm_persp_decomp(proj, &dest[0], &dest[1], &dest[2], &dest[3], &dest[4], &dest[5]); } @@ -472,7 +474,7 @@ glm_persp_decompv(const mat4 proj, float dest[6]) { */ CGLM_INLINE void -glm_persp_decomp_x(const mat4 proj, +glm_persp_decomp_x(mat4 proj, float * __restrict left, float * __restrict right) { float nearVal, m20, m00; @@ -495,7 +497,7 @@ glm_persp_decomp_x(const mat4 proj, */ CGLM_INLINE void -glm_persp_decomp_y(const mat4 proj, +glm_persp_decomp_y(mat4 proj, float * __restrict top, float * __restrict bottom) { float nearVal, m21, m11; @@ -518,7 +520,7 @@ glm_persp_decomp_y(const mat4 proj, */ CGLM_INLINE void -glm_persp_decomp_z(const mat4 proj, +glm_persp_decomp_z(mat4 proj, float * __restrict nearVal, float * __restrict farVal) { float m32, m22; @@ -538,7 +540,7 @@ glm_persp_decomp_z(const mat4 proj, */ CGLM_INLINE void -glm_persp_decomp_far(const mat4 proj, float * __restrict farVal) { +glm_persp_decomp_far(mat4 proj, float * __restrict farVal) { *farVal = proj[3][2] / (proj[2][2] + 1.0f); } @@ -550,7 +552,7 @@ glm_persp_decomp_far(const mat4 proj, float * __restrict farVal) { */ CGLM_INLINE void -glm_persp_decomp_near(const mat4 proj, float * __restrict nearVal) { +glm_persp_decomp_near(mat4 proj, float * __restrict nearVal) { *nearVal = proj[3][2] / (proj[2][2] - 1.0f); } @@ -564,7 +566,7 @@ glm_persp_decomp_near(const mat4 proj, float * __restrict nearVal) { */ CGLM_INLINE float -glm_persp_fovy(const mat4 proj) { +glm_persp_fovy(mat4 proj) { return 2.0f * atanf(1.0f / proj[1][1]); } @@ -575,7 +577,7 @@ glm_persp_fovy(const mat4 proj) { */ CGLM_INLINE float -glm_persp_aspect(const mat4 proj) { +glm_persp_aspect(mat4 proj) { return proj[1][1] / proj[0][0]; } @@ -588,7 +590,7 @@ glm_persp_aspect(const mat4 proj) { */ CGLM_INLINE void -glm_persp_sizes(const mat4 proj, float fovy, vec4 dest) { +glm_persp_sizes(mat4 proj, float fovy, vec4 dest) { float t, a, nearVal, farVal; t = 2.0f * tanf(fovy * 0.5f); diff --git a/include/cglm/color.h b/include/cglm/color.h index 27d77b8..69566ad 100644 --- a/include/cglm/color.h +++ b/include/cglm/color.h @@ -18,7 +18,7 @@ */ CGLM_INLINE float -glm_luminance(const vec3 rgb) { +glm_luminance(vec3 rgb) { vec3 l = {0.212671f, 0.715160f, 0.072169f}; return glm_dot(rgb, l); } diff --git a/include/cglm/curve.h b/include/cglm/curve.h index bcc104f..5033be5 100644 --- a/include/cglm/curve.h +++ b/include/cglm/curve.h @@ -31,7 +31,7 @@ */ CGLM_INLINE float -glm_smc(float s, const mat4 m, const vec4 c) { +glm_smc(float s, mat4 m, vec4 c) { vec4 vs; glm_vec4_cubic(s, vs); return glm_mat4_rmc(vs, m, c); diff --git a/include/cglm/euler.h b/include/cglm/euler.h index df6c0bc..1ff5f6d 100644 --- a/include/cglm/euler.h +++ b/include/cglm/euler.h @@ -57,7 +57,7 @@ typedef enum glm_euler_sq { CGLM_INLINE glm_euler_sq -glm_euler_order(const int ord[3]) { +glm_euler_order(int ord[3]) { return (glm_euler_sq)(ord[0] << 0 | ord[1] << 2 | ord[2] << 4); } @@ -69,7 +69,7 @@ glm_euler_order(const int ord[3]) { */ CGLM_INLINE void -glm_euler_angles(const mat4 m, vec3 dest) { +glm_euler_angles(mat4 m, vec3 dest) { float m00, m01, m10, m11, m20, m21, m22; float thetaX, thetaY, thetaZ; @@ -107,7 +107,7 @@ glm_euler_angles(const mat4 m, vec3 dest) { */ CGLM_INLINE void -glm_euler_xyz(const vec3 angles, mat4 dest) { +glm_euler_xyz(vec3 angles, mat4 dest) { float cx, cy, cz, sx, sy, sz, czsx, cxcz, sysz; @@ -145,7 +145,7 @@ glm_euler_xyz(const vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler(const vec3 angles, mat4 dest) { +glm_euler(vec3 angles, mat4 dest) { glm_euler_xyz(angles, dest); } @@ -157,7 +157,7 @@ glm_euler(const vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler_xzy(const vec3 angles, mat4 dest) { +glm_euler_xzy(vec3 angles, mat4 dest) { float cx, cy, cz, sx, sy, sz, sxsy, cysx, cxsy, cxcy; @@ -197,7 +197,7 @@ glm_euler_xzy(const vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler_yxz(const vec3 angles, mat4 dest) { +glm_euler_yxz(vec3 angles, mat4 dest) { float cx, cy, cz, sx, sy, sz, cycz, sysz, czsy, cysz; @@ -236,7 +236,7 @@ glm_euler_yxz(const vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler_yzx(const vec3 angles, mat4 dest) { +glm_euler_yzx(vec3 angles, mat4 dest) { float cx, cy, cz, sx, sy, sz, sxsy, cxcy, cysx, cxsy; @@ -275,7 +275,7 @@ glm_euler_yzx(const vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler_zxy(const vec3 angles, mat4 dest) { +glm_euler_zxy(vec3 angles, mat4 dest) { float cx, cy, cz, sx, sy, sz, cycz, sxsy, cysz; @@ -313,7 +313,7 @@ glm_euler_zxy(const vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler_zyx(const vec3 angles, mat4 dest) { +glm_euler_zyx(vec3 angles, mat4 dest) { float cx, cy, cz, sx, sy, sz, czsx, cxcz, sysz; @@ -352,7 +352,7 @@ glm_euler_zyx(const vec3 angles, mat4 dest) { */ CGLM_INLINE void -glm_euler_by_order(const vec3 angles, glm_euler_sq ord, mat4 dest) { +glm_euler_by_order(vec3 angles, glm_euler_sq ord, mat4 dest) { float cx, cy, cz, sx, sy, sz; diff --git a/include/cglm/frustum.h b/include/cglm/frustum.h index 755fecd..78b39d2 100644 --- a/include/cglm/frustum.h +++ b/include/cglm/frustum.h @@ -69,7 +69,7 @@ */ CGLM_INLINE void -glm_frustum_planes(const mat4 m, vec4 dest[6]) { +glm_frustum_planes(mat4 m, vec4 dest[6]) { mat4 t; glm_mat4_transpose_to(m, t); @@ -114,7 +114,7 @@ glm_frustum_planes(const mat4 m, vec4 dest[6]) { */ CGLM_INLINE void -glm_frustum_corners(const mat4 invMat, vec4 dest[8]) { +glm_frustum_corners(mat4 invMat, vec4 dest[8]) { vec4 c[8]; /* indexOf(nearCoord) = indexOf(farCoord) + 4 */ @@ -157,7 +157,7 @@ glm_frustum_corners(const mat4 invMat, vec4 dest[8]) { */ CGLM_INLINE void -glm_frustum_center(const vec4 corners[8], vec4 dest) { +glm_frustum_center(vec4 corners[8], vec4 dest) { vec4 center; glm_vec4_copy(corners[0], center); @@ -182,7 +182,7 @@ glm_frustum_center(const vec4 corners[8], vec4 dest) { */ CGLM_INLINE void -glm_frustum_box(const vec4 corners[8], const mat4 m, vec3 box[2]) { +glm_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) { vec4 v; vec3 min, max; int i; @@ -220,10 +220,10 @@ glm_frustum_box(const vec4 corners[8], const mat4 m, vec3 box[2]) { */ CGLM_INLINE void -glm_frustum_corners_at(const vec4 corners[8], - float splitDist, - float farDist, - vec4 planeCorners[4]) { +glm_frustum_corners_at(vec4 corners[8], + float splitDist, + float farDist, + vec4 planeCorners[4]) { vec4 corner; float dist, sc; diff --git a/include/cglm/io.h b/include/cglm/io.h index e51f03c..ac0bfeb 100644 --- a/include/cglm/io.h +++ b/include/cglm/io.h @@ -25,8 +25,8 @@ CGLM_INLINE void -glm_mat4_print(const mat4 matrix, - FILE * const __restrict ostream) { +glm_mat4_print(mat4 matrix, + FILE * __restrict ostream) { int i; int j; @@ -55,8 +55,8 @@ glm_mat4_print(const mat4 matrix, CGLM_INLINE void -glm_mat3_print(const mat3 matrix, - FILE * const __restrict ostream) { +glm_mat3_print(mat3 matrix, + FILE * __restrict ostream) { int i; int j; @@ -85,8 +85,8 @@ glm_mat3_print(const mat3 matrix, CGLM_INLINE void -glm_vec4_print(const vec4 vec, - FILE * const __restrict ostream) { +glm_vec4_print(vec4 vec, + FILE * __restrict ostream) { int i; #define m 4 @@ -107,8 +107,8 @@ glm_vec4_print(const vec4 vec, CGLM_INLINE void -glm_vec3_print(const vec3 vec, - FILE * const __restrict ostream) { +glm_vec3_print(vec3 vec, + FILE * __restrict ostream) { int i; #define m 3 @@ -129,8 +129,8 @@ glm_vec3_print(const vec3 vec, CGLM_INLINE void -glm_ivec3_print(const ivec3 vec, - FILE * const __restrict ostream) { +glm_ivec3_print(ivec3 vec, + FILE * __restrict ostream) { int i; #define m 3 @@ -151,8 +151,8 @@ glm_ivec3_print(const ivec3 vec, CGLM_INLINE void -glm_versor_print(const versor vec, - FILE * const __restrict ostream) { +glm_versor_print(versor vec, + FILE * __restrict ostream) { int i; #define m 4 @@ -173,9 +173,9 @@ glm_versor_print(const versor vec, CGLM_INLINE void -glm_aabb_print(const vec3 bbox[2], +glm_aabb_print(vec3 bbox[2], const char * __restrict tag, - FILE * const __restrict ostream) { + FILE * __restrict ostream) { int i, j; #define m 3 diff --git a/include/cglm/mat3.h b/include/cglm/mat3.h index f1597fd..3126064 100644 --- a/include/cglm/mat3.h +++ b/include/cglm/mat3.h @@ -65,7 +65,7 @@ */ CGLM_INLINE void -glm_mat3_copy(const mat3 mat, mat3 dest) { +glm_mat3_copy(mat3 mat, mat3 dest) { dest[0][0] = mat[0][0]; dest[0][1] = mat[0][1]; dest[0][2] = mat[0][2]; @@ -110,7 +110,7 @@ glm_mat3_identity(mat3 mat) { */ CGLM_INLINE void -glm_mat3_identity_array(mat3 * const __restrict mat, size_t count) { +glm_mat3_identity_array(mat3 * __restrict mat, size_t count) { CGLM_ALIGN_MAT mat3 t = GLM_MAT3_IDENTITY_INIT; size_t i; @@ -147,7 +147,7 @@ glm_mat3_zero(mat3 mat) { */ CGLM_INLINE void -glm_mat3_mul(const mat3 m1, const mat3 m2, mat3 dest) { +glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mat3_mul_sse2(m1, m2, dest); #else @@ -181,7 +181,7 @@ glm_mat3_mul(const mat3 m1, const mat3 m2, mat3 dest) { */ CGLM_INLINE void -glm_mat3_transpose_to(const mat3 m, mat3 dest) { +glm_mat3_transpose_to(mat3 m, mat3 dest) { dest[0][0] = m[0][0]; dest[0][1] = m[1][0]; dest[0][2] = m[2][0]; @@ -227,7 +227,7 @@ glm_mat3_transpose(mat3 m) { */ CGLM_INLINE void -glm_mat3_mulv(const mat3 m, const vec3 v, vec3 dest) { +glm_mat3_mulv(mat3 m, vec3 v, vec3 dest) { dest[0] = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0] * v[2]; dest[1] = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1] * v[2]; dest[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2]; @@ -242,7 +242,7 @@ glm_mat3_mulv(const mat3 m, const vec3 v, vec3 dest) { */ CGLM_INLINE float -glm_mat3_trace(const mat3 m) { +glm_mat3_trace(mat3 m) { return m[0][0] + m[1][1] + m[2][2]; } @@ -254,7 +254,7 @@ glm_mat3_trace(const mat3 m) { */ CGLM_INLINE void -glm_mat3_quat(const mat3 m, versor dest) { +glm_mat3_quat(mat3 m, versor dest) { float trace, r, rinv; /* it seems using like m12 instead of m[1][2] causes extra instructions */ @@ -320,7 +320,7 @@ glm_mat3_scale(mat3 m, float s) { */ CGLM_INLINE float -glm_mat3_det(const mat3 mat) { +glm_mat3_det(mat3 mat) { float a = mat[0][0], b = mat[0][1], c = mat[0][2], d = mat[1][0], e = mat[1][1], f = mat[1][2], g = mat[2][0], h = mat[2][1], i = mat[2][2]; @@ -336,7 +336,7 @@ glm_mat3_det(const mat3 mat) { */ CGLM_INLINE void -glm_mat3_inv(const mat3 mat, mat3 dest) { +glm_mat3_inv(mat3 mat, mat3 dest) { float det; float a = mat[0][0], b = mat[0][1], c = mat[0][2], d = mat[1][0], e = mat[1][1], f = mat[1][2], @@ -413,7 +413,7 @@ glm_mat3_swap_row(mat3 mat, int row1, int row2) { */ CGLM_INLINE float -glm_mat3_rmc(const vec3 r, const mat3 m, const vec3 c) { +glm_mat3_rmc(vec3 r, mat3 m, vec3 c) { vec3 tmp; glm_mat3_mulv(m, c, tmp); return glm_vec3_dot(r, tmp); diff --git a/include/cglm/mat4.h b/include/cglm/mat4.h index 2a87fba..e6b916b 100644 --- a/include/cglm/mat4.h +++ b/include/cglm/mat4.h @@ -100,7 +100,7 @@ */ CGLM_INLINE void -glm_mat4_ucopy(const mat4 mat, mat4 dest) { +glm_mat4_ucopy(mat4 mat, mat4 dest) { dest[0][0] = mat[0][0]; dest[1][0] = mat[1][0]; dest[0][1] = mat[0][1]; dest[1][1] = mat[1][1]; dest[0][2] = mat[0][2]; dest[1][2] = mat[1][2]; @@ -120,7 +120,7 @@ glm_mat4_ucopy(const mat4 mat, mat4 dest) { */ CGLM_INLINE void -glm_mat4_copy(const mat4 mat, mat4 dest) { +glm_mat4_copy(mat4 mat, mat4 dest) { #ifdef __AVX__ glmm_store256(dest[0], glmm_load256(mat[0])); glmm_store256(dest[2], glmm_load256(mat[2])); @@ -170,7 +170,7 @@ glm_mat4_identity(mat4 mat) { */ CGLM_INLINE void -glm_mat4_identity_array(mat4 * const __restrict mat, size_t count) { +glm_mat4_identity_array(mat4 * __restrict mat, size_t count) { CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; size_t i; @@ -199,7 +199,7 @@ glm_mat4_zero(mat4 mat) { */ CGLM_INLINE void -glm_mat4_pick3(const mat4 mat, mat3 dest) { +glm_mat4_pick3(mat4 mat, mat3 dest) { dest[0][0] = mat[0][0]; dest[0][1] = mat[0][1]; dest[0][2] = mat[0][2]; @@ -223,7 +223,7 @@ glm_mat4_pick3(const mat4 mat, mat3 dest) { */ CGLM_INLINE void -glm_mat4_pick3t(const mat4 mat, mat3 dest) { +glm_mat4_pick3t(mat4 mat, mat3 dest) { dest[0][0] = mat[0][0]; dest[0][1] = mat[1][0]; dest[0][2] = mat[2][0]; @@ -245,7 +245,7 @@ glm_mat4_pick3t(const mat4 mat, mat3 dest) { */ CGLM_INLINE void -glm_mat4_ins3(const mat3 mat, mat4 dest) { +glm_mat4_ins3(mat3 mat, mat4 dest) { dest[0][0] = mat[0][0]; dest[0][1] = mat[0][1]; dest[0][2] = mat[0][2]; @@ -275,7 +275,7 @@ glm_mat4_ins3(const mat3 mat, mat4 dest) { */ CGLM_INLINE void -glm_mat4_mul(const mat4 m1, const mat4 m2, mat4 dest) { +glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest) { #ifdef __AVX__ glm_mat4_mul_avx(m1, m2, dest); #elif defined( __SSE__ ) || defined( __SSE2__ ) @@ -333,7 +333,7 @@ glm_mat4_mul(const mat4 m1, const mat4 m2, mat4 dest) { */ CGLM_INLINE void -glm_mat4_mulN(mat4 * const __restrict matrices[], uint32_t len, mat4 dest) { +glm_mat4_mulN(mat4 * __restrict matrices[], uint32_t len, mat4 dest) { uint32_t i; #ifdef DEBUG @@ -355,7 +355,7 @@ glm_mat4_mulN(mat4 * const __restrict matrices[], uint32_t len, mat4 dest) { */ CGLM_INLINE void -glm_mat4_mulv(const mat4 m, const vec4 v, vec4 dest) { +glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mat4_mulv_sse2(m, v, dest); #else @@ -377,7 +377,7 @@ glm_mat4_mulv(const mat4 m, const vec4 v, vec4 dest) { */ CGLM_INLINE float -glm_mat4_trace(const mat4 m) { +glm_mat4_trace(mat4 m) { return m[0][0] + m[1][1] + m[2][2] + m[3][3]; } @@ -390,7 +390,7 @@ glm_mat4_trace(const mat4 m) { */ CGLM_INLINE float -glm_mat4_trace3(const mat4 m) { +glm_mat4_trace3(mat4 m) { return m[0][0] + m[1][1] + m[2][2]; } @@ -402,7 +402,7 @@ glm_mat4_trace3(const mat4 m) { */ CGLM_INLINE void -glm_mat4_quat(const mat4 m, versor dest) { +glm_mat4_quat(mat4 m, versor dest) { float trace, r, rinv; /* it seems using like m12 instead of m[1][2] causes extra instructions */ @@ -453,7 +453,7 @@ glm_mat4_quat(const mat4 m, versor dest) { */ CGLM_INLINE void -glm_mat4_mulv3(const mat4 m, const vec3 v, float last, vec3 dest) { +glm_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest) { vec4 res; glm_vec4(v, last, res); glm_mat4_mulv(m, res, res); @@ -470,7 +470,7 @@ glm_mat4_mulv3(const mat4 m, const vec3 v, float last, vec3 dest) { */ CGLM_INLINE void -glm_mat4_transpose_to(const mat4 m, mat4 dest) { +glm_mat4_transpose_to(mat4 m, mat4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mat4_transp_sse2(m, dest); #else @@ -553,7 +553,7 @@ glm_mat4_scale(mat4 m, float s) { */ CGLM_INLINE float -glm_mat4_det(const mat4 mat) { +glm_mat4_det(mat4 mat) { #if defined( __SSE__ ) || defined( __SSE2__ ) return glm_mat4_det_sse2(mat); #else @@ -586,7 +586,7 @@ glm_mat4_det(const mat4 mat) { */ CGLM_INLINE void -glm_mat4_inv(const mat4 mat, mat4 dest) { +glm_mat4_inv(mat4 mat, mat4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mat4_inv_sse2(mat, dest); #else @@ -647,7 +647,7 @@ glm_mat4_inv(const mat4 mat, mat4 dest) { */ CGLM_INLINE void -glm_mat4_inv_fast(const mat4 mat, mat4 dest) { +glm_mat4_inv_fast(mat4 mat, mat4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glm_mat4_inv_fast_sse2(mat, dest); #else @@ -680,7 +680,7 @@ glm_mat4_swap_col(mat4 mat, int col1, int col2) { */ CGLM_INLINE void -glm_mat4_swap_row(mat4 mat, const int row1, const int row2) { +glm_mat4_swap_row(mat4 mat, int row1, int row2) { CGLM_ALIGN(16) vec4 tmp; tmp[0] = mat[0][row1]; tmp[1] = mat[1][row1]; @@ -714,7 +714,7 @@ glm_mat4_swap_row(mat4 mat, const int row1, const int row2) { */ CGLM_INLINE float -glm_mat4_rmc(const vec4 r, const mat4 m, const vec4 c) { +glm_mat4_rmc(vec4 r, mat4 m, vec4 c) { vec4 tmp; glm_mat4_mulv(m, c, tmp); return glm_vec4_dot(r, tmp); diff --git a/include/cglm/project.h b/include/cglm/project.h index f62b001..1336222 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -41,7 +41,7 @@ */ CGLM_INLINE void -glm_unprojecti(const vec3 pos, const mat4 invMat, const vec4 vp, vec3 dest) { +glm_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { vec4 v; v[0] = 2.0f * (pos[0] - vp[0]) / vp[2] - 1.0f; @@ -80,7 +80,7 @@ glm_unprojecti(const vec3 pos, const mat4 invMat, const vec4 vp, vec3 dest) { */ CGLM_INLINE void -glm_unproject(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest) { +glm_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) { mat4 inv; glm_mat4_inv(m, inv); glm_unprojecti(pos, inv, vp, dest); @@ -100,7 +100,7 @@ glm_unproject(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest) { */ CGLM_INLINE void -glm_project(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest) { +glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { CGLM_ALIGN(16) vec4 pos4, vone = GLM_VEC4_ONE_INIT; glm_vec4(pos, 1.0f, pos4); diff --git a/include/cglm/quat.h b/include/cglm/quat.h index e6ef0f4..f5f29af 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -68,15 +68,15 @@ glm_mat4_identity(mat4 mat); CGLM_INLINE void -glm_mat4_mulv(const mat4 m, const vec4 v, vec4 dest); +glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); CGLM_INLINE void -glm_mul_rot(const mat4 m1, const mat4 m2, mat4 dest); +glm_mul_rot(mat4 m1, mat4 m2, mat4 dest); CGLM_INLINE void -glm_translate(mat4 m, const vec3 v); +glm_translate(mat4 m, vec3 v); /* * IMPORTANT: @@ -113,7 +113,7 @@ glm_quat_identity(versor q) { */ CGLM_INLINE void -glm_quat_identity_array(versor * const __restrict q, size_t count) { +glm_quat_identity_array(versor * __restrict q, size_t count) { CGLM_ALIGN(16) versor v = GLM_QUAT_IDENTITY_INIT; size_t i; @@ -149,7 +149,7 @@ glm_quat_init(versor q, float x, float y, float z, float w) { */ CGLM_INLINE void -glm_quatv(versor q, float angle, const vec3 axis) { +glm_quatv(versor q, float angle, vec3 axis) { CGLM_ALIGN(8) vec3 k; float a, c, s; @@ -189,7 +189,7 @@ glm_quat(versor q, float angle, float x, float y, float z) { */ CGLM_INLINE void -glm_quat_copy(const versor q, versor dest) { +glm_quat_copy(versor q, versor dest) { glm_vec4_copy(q, dest); } @@ -200,7 +200,7 @@ glm_quat_copy(const versor q, versor dest) { */ CGLM_INLINE float -glm_quat_norm(const versor q) { +glm_quat_norm(versor q) { return glm_vec4_norm(q); } @@ -212,7 +212,7 @@ glm_quat_norm(const versor q) { */ CGLM_INLINE void -glm_quat_normalize_to(const versor q, versor dest) { +glm_quat_normalize_to(versor q, versor dest) { #if defined( __SSE2__ ) || defined( __SSE2__ ) __m128 xdot, x0; float dot; @@ -260,7 +260,7 @@ glm_quat_normalize(versor q) { */ CGLM_INLINE float -glm_quat_dot(const versor p, const versor q) { +glm_quat_dot(versor p, versor q) { return glm_vec4_dot(p, q); } @@ -272,7 +272,7 @@ glm_quat_dot(const versor p, const versor q) { */ CGLM_INLINE void -glm_quat_conjugate(const versor q, versor dest) { +glm_quat_conjugate(versor q, versor dest) { glm_vec4_negate_to(q, dest); dest[3] = -dest[3]; } @@ -285,7 +285,7 @@ glm_quat_conjugate(const versor q, versor dest) { */ CGLM_INLINE void -glm_quat_inv(const versor q, versor dest) { +glm_quat_inv(versor q, versor dest) { CGLM_ALIGN(16) versor conj; glm_quat_conjugate(q, conj); glm_vec4_scale(conj, 1.0f / glm_vec4_norm2(q), dest); @@ -300,7 +300,7 @@ glm_quat_inv(const versor q, versor dest) { */ CGLM_INLINE void -glm_quat_add(const versor p, const versor q, versor dest) { +glm_quat_add(versor p, versor q, versor dest) { glm_vec4_add(p, q, dest); } @@ -313,7 +313,7 @@ glm_quat_add(const versor p, const versor q, versor dest) { */ CGLM_INLINE void -glm_quat_sub(const versor p, const versor q, versor dest) { +glm_quat_sub(versor p, versor q, versor dest) { glm_vec4_sub(p, q, dest); } @@ -324,7 +324,7 @@ glm_quat_sub(const versor p, const versor q, versor dest) { */ CGLM_INLINE float -glm_quat_real(const versor q) { +glm_quat_real(versor q) { return q[3]; } @@ -336,7 +336,7 @@ glm_quat_real(const versor q) { */ CGLM_INLINE void -glm_quat_imag(const versor q, vec3 dest) { +glm_quat_imag(versor q, vec3 dest) { dest[0] = q[0]; dest[1] = q[1]; dest[2] = q[2]; @@ -349,7 +349,7 @@ glm_quat_imag(const versor q, vec3 dest) { */ CGLM_INLINE void -glm_quat_imagn(const versor q, vec3 dest) { +glm_quat_imagn(versor q, vec3 dest) { glm_normalize_to(q, dest); } @@ -360,7 +360,7 @@ glm_quat_imagn(const versor q, vec3 dest) { */ CGLM_INLINE float -glm_quat_imaglen(const versor q) { +glm_quat_imaglen(versor q) { return glm_vec3_norm(q); } @@ -371,7 +371,7 @@ glm_quat_imaglen(const versor q) { */ CGLM_INLINE float -glm_quat_angle(const versor q) { +glm_quat_angle(versor q) { /* sin(theta / 2) = length(x*x + y*y + z*z) cos(theta / 2) = w @@ -388,7 +388,7 @@ glm_quat_angle(const versor q) { */ CGLM_INLINE void -glm_quat_axis(const versor q, versor dest) { +glm_quat_axis(versor q, versor dest) { glm_quat_imagn(q, dest); } @@ -406,7 +406,7 @@ glm_quat_axis(const versor q, versor dest) { */ CGLM_INLINE void -glm_quat_mul(const versor p, const versor q, versor dest) { +glm_quat_mul(versor p, versor q, versor dest) { /* + (a1 b2 + b1 a2 + c1 d2 − d1 c2)i + (a1 c2 − b1 d2 + c1 a2 + d1 b2)j @@ -431,7 +431,7 @@ glm_quat_mul(const versor p, const versor q, versor dest) { */ CGLM_INLINE void -glm_quat_mat4(const versor q, mat4 dest) { +glm_quat_mat4(versor q, mat4 dest) { float w, x, y, z, xx, yy, zz, xy, yz, xz, @@ -478,7 +478,7 @@ glm_quat_mat4(const versor q, mat4 dest) { */ CGLM_INLINE void -glm_quat_mat4t(const versor q, mat4 dest) { +glm_quat_mat4t(versor q, mat4 dest) { float w, x, y, z, xx, yy, zz, xy, yz, xz, @@ -525,7 +525,7 @@ glm_quat_mat4t(const versor q, mat4 dest) { */ CGLM_INLINE void -glm_quat_mat3(const versor q, mat3 dest) { +glm_quat_mat3(versor q, mat3 dest) { float w, x, y, z, xx, yy, zz, xy, yz, xz, @@ -564,7 +564,7 @@ glm_quat_mat3(const versor q, mat3 dest) { */ CGLM_INLINE void -glm_quat_mat3t(const versor q, mat3 dest) { +glm_quat_mat3t(versor q, mat3 dest) { float w, x, y, z, xx, yy, zz, xy, yz, xz, @@ -606,7 +606,7 @@ glm_quat_mat3t(const versor q, mat3 dest) { */ CGLM_INLINE void -glm_quat_lerp(const versor from, const versor to, float t, versor dest) { +glm_quat_lerp(versor from, versor to, float t, versor dest) { glm_vec4_lerp(from, to, t, dest); } @@ -621,7 +621,7 @@ glm_quat_lerp(const versor from, const versor to, float t, versor dest) { */ CGLM_INLINE void -glm_quat_slerp(const versor from, const versor to, float t, versor dest) { +glm_quat_slerp(versor from, versor to, float t, versor dest) { CGLM_ALIGN(16) vec4 q1, q2; float cosTheta, sinTheta, angle; @@ -664,7 +664,7 @@ glm_quat_slerp(const versor from, const versor to, float t, versor dest) { */ CGLM_INLINE void -glm_quat_look(const vec3 eye, const versor ori, mat4 dest) { +glm_quat_look(vec3 eye, versor ori, mat4 dest) { /* orientation */ glm_quat_mat4t(ori, dest); @@ -683,7 +683,7 @@ glm_quat_look(const vec3 eye, const versor ori, mat4 dest) { */ CGLM_INLINE void -glm_quat_for(const vec3 dir, const vec3 fwd, const vec3 up, versor dest) { +glm_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) { CGLM_ALIGN(8) vec3 axis; float dot, angle; @@ -717,11 +717,7 @@ glm_quat_for(const vec3 dir, const vec3 fwd, const vec3 up, versor dest) { */ CGLM_INLINE void -glm_quat_forp(const vec3 from, - const vec3 to, - const vec3 fwd, - const vec3 up, - versor dest) { +glm_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { CGLM_ALIGN(8) vec3 dir; glm_vec3_sub(to, from, dir); glm_quat_for(dir, fwd, up, dest); @@ -736,7 +732,7 @@ glm_quat_forp(const vec3 from, */ CGLM_INLINE void -glm_quat_rotatev(const versor q, const vec3 v, vec3 dest) { +glm_quat_rotatev(versor q, vec3 v, vec3 dest) { CGLM_ALIGN(16) versor p; CGLM_ALIGN(8) vec3 u, v1, v2; float s; @@ -764,7 +760,7 @@ glm_quat_rotatev(const versor q, const vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_quat_rotate(const mat4 m, const versor q, mat4 dest) { +glm_quat_rotate(mat4 m, versor q, mat4 dest) { CGLM_ALIGN_MAT mat4 rot; glm_quat_mat4(q, rot); glm_mul_rot(m, rot, dest); @@ -779,7 +775,7 @@ glm_quat_rotate(const mat4 m, const versor q, mat4 dest) { */ CGLM_INLINE void -glm_quat_rotate_at(mat4 m, const versor q, const vec3 pivot) { +glm_quat_rotate_at(mat4 m, versor q, vec3 pivot) { CGLM_ALIGN(8) vec3 pivotInv; glm_vec3_negate_to(pivot, pivotInv); @@ -803,7 +799,7 @@ glm_quat_rotate_at(mat4 m, const versor q, const vec3 pivot) { */ CGLM_INLINE void -glm_quat_rotate_atm(mat4 m, const versor q, const vec3 pivot) { +glm_quat_rotate_atm(mat4 m, versor q, vec3 pivot) { CGLM_ALIGN(8) vec3 pivotInv; glm_vec3_negate_to(pivot, pivotInv); diff --git a/include/cglm/simd/avx/affine.h b/include/cglm/simd/avx/affine.h index 0d0454e..b02ff0c 100644 --- a/include/cglm/simd/avx/affine.h +++ b/include/cglm/simd/avx/affine.h @@ -16,7 +16,7 @@ CGLM_INLINE void -glm_mul_avx(const mat4 m1, const mat4 m2, mat4 dest) { +glm_mul_avx(mat4 m1, mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ __m256 y0, y1, y2, y3, y4, y5, y6, y7, y8, y9; diff --git a/include/cglm/simd/avx/mat4.h b/include/cglm/simd/avx/mat4.h index a458d4c..944769b 100644 --- a/include/cglm/simd/avx/mat4.h +++ b/include/cglm/simd/avx/mat4.h @@ -16,7 +16,7 @@ CGLM_INLINE void -glm_mat4_mul_avx(const mat4 m1, const mat4 m2, mat4 dest) { +glm_mat4_mul_avx(mat4 m1, mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ __m256 y0, y1, y2, y3, y4, y5, y6, y7, y8, y9; diff --git a/include/cglm/simd/neon/mat4.h b/include/cglm/simd/neon/mat4.h index df342dc..0623dc0 100644 --- a/include/cglm/simd/neon/mat4.h +++ b/include/cglm/simd/neon/mat4.h @@ -14,7 +14,7 @@ CGLM_INLINE void -glm_mat4_mul_neon(const mat4 m1, const mat4 m2, mat4 dest) { +glm_mat4_mul_neon(mat4 m1, mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ float32x4_t l0, l1, l2, l3, r, d0, d1, d2, d3; diff --git a/include/cglm/simd/sse2/affine.h b/include/cglm/simd/sse2/affine.h index ae187b1..87db1b8 100644 --- a/include/cglm/simd/sse2/affine.h +++ b/include/cglm/simd/sse2/affine.h @@ -14,7 +14,7 @@ CGLM_INLINE void -glm_mul_sse2(const mat4 m1, const mat4 m2, mat4 dest) { +glm_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ __m128 l0, l1, l2, l3, r; @@ -51,7 +51,7 @@ glm_mul_sse2(const mat4 m1, const mat4 m2, mat4 dest) { CGLM_INLINE void -glm_mul_rot_sse2(const mat4 m1, const mat4 m2, mat4 dest) { +glm_mul_rot_sse2(mat4 m1, mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ __m128 l0, l1, l2, l3, r; diff --git a/include/cglm/simd/sse2/mat3.h b/include/cglm/simd/sse2/mat3.h index 07cb5f4..9c972ff 100644 --- a/include/cglm/simd/sse2/mat3.h +++ b/include/cglm/simd/sse2/mat3.h @@ -14,7 +14,7 @@ CGLM_INLINE void -glm_mat3_mul_sse2(const mat3 m1, const mat3 m2, mat3 dest) { +glm_mat3_mul_sse2(mat3 m1, mat3 m2, mat3 dest) { __m128 l0, l1, l2; __m128 r0, r1, r2; __m128 x0, x1, x2; diff --git a/include/cglm/simd/sse2/mat4.h b/include/cglm/simd/sse2/mat4.h index 66fb75a..7c87eb5 100644 --- a/include/cglm/simd/sse2/mat4.h +++ b/include/cglm/simd/sse2/mat4.h @@ -28,7 +28,7 @@ glm_mat4_scale_sse2(mat4 m, float s) { CGLM_INLINE void -glm_mat4_transp_sse2(const mat4 m, mat4 dest) { +glm_mat4_transp_sse2(mat4 m, mat4 dest) { __m128 r0, r1, r2, r3; r0 = glmm_load(m[0]); @@ -46,7 +46,7 @@ glm_mat4_transp_sse2(const mat4 m, mat4 dest) { CGLM_INLINE void -glm_mat4_mul_sse2(const mat4 m1, const mat4 m2, mat4 dest) { +glm_mat4_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { /* D = R * L (Column-Major) */ __m128 l0, l1, l2, l3, r; @@ -85,7 +85,7 @@ glm_mat4_mul_sse2(const mat4 m1, const mat4 m2, mat4 dest) { CGLM_INLINE void -glm_mat4_mulv_sse2(const mat4 m, const vec4 v, vec4 dest) { +glm_mat4_mulv_sse2(mat4 m, vec4 v, vec4 dest) { __m128 x0, x1, x2; x0 = glmm_load(v); @@ -100,7 +100,7 @@ glm_mat4_mulv_sse2(const mat4 m, const vec4 v, vec4 dest) { CGLM_INLINE float -glm_mat4_det_sse2(const mat4 mat) { +glm_mat4_det_sse2(mat4 mat) { __m128 r0, r1, r2, r3, x0, x1, x2; /* 127 <- 0, [square] det(A) = det(At) */ @@ -155,7 +155,7 @@ glm_mat4_det_sse2(const mat4 mat) { CGLM_INLINE void -glm_mat4_inv_fast_sse2(const mat4 mat, mat4 dest) { +glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { __m128 r0, r1, r2, r3, v0, v1, v2, v3, t0, t1, t2, t3, t4, t5, @@ -279,7 +279,7 @@ glm_mat4_inv_fast_sse2(const mat4 mat, mat4 dest) { CGLM_INLINE void -glm_mat4_inv_sse2(const mat4 mat, mat4 dest) { +glm_mat4_inv_sse2(mat4 mat, mat4 dest) { __m128 r0, r1, r2, r3, v0, v1, v2, v3, t0, t1, t2, t3, t4, t5, diff --git a/include/cglm/simd/sse2/quat.h b/include/cglm/simd/sse2/quat.h index 08ebb70..0173f94 100644 --- a/include/cglm/simd/sse2/quat.h +++ b/include/cglm/simd/sse2/quat.h @@ -14,7 +14,7 @@ CGLM_INLINE void -glm_quat_mul_sse2(const versor p, const versor q, versor dest) { +glm_quat_mul_sse2(versor p, versor q, versor dest) { /* + (a1 b2 + b1 a2 + c1 d2 − d1 c2)i + (a1 c2 − b1 d2 + c1 a2 + d1 b2)j diff --git a/include/cglm/simd/x86.h b/include/cglm/simd/x86.h index b926511..99d2b8a 100644 --- a/include/cglm/simd/x86.h +++ b/include/cglm/simd/x86.h @@ -103,7 +103,7 @@ glmm_vdot(__m128 a, __m128 b) { static inline float -glmm_dot(const __m128 a, const __m128 b) { +glmm_dot(__m128 a, __m128 b) { return _mm_cvtss_f32(glmm_vdots(a, b)); } @@ -115,7 +115,7 @@ glmm_norm(__m128 a) { static inline __m128 -glmm_load3(const float v[3]) { +glmm_load3(float v[3]) { __m128i xy; __m128 z; diff --git a/include/cglm/sphere.h b/include/cglm/sphere.h index 7653096..334b83a 100644 --- a/include/cglm/sphere.h +++ b/include/cglm/sphere.h @@ -27,7 +27,7 @@ */ CGLM_INLINE float -glm_sphere_radii(const vec4 s) { +glm_sphere_radii(vec4 s) { return s[3]; } @@ -40,7 +40,7 @@ glm_sphere_radii(const vec4 s) { */ CGLM_INLINE void -glm_sphere_transform(const vec4 s, const mat4 m, vec4 dest) { +glm_sphere_transform(vec4 s, mat4 m, vec4 dest) { glm_mat4_mulv3(m, s, 1.0f, dest); dest[3] = s[3]; } @@ -57,7 +57,7 @@ glm_sphere_transform(const vec4 s, const mat4 m, vec4 dest) { */ CGLM_INLINE void -glm_sphere_merge(const vec4 s1, const vec4 s2, vec4 dest) { +glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { float dist, radii; dist = glm_vec3_distance(s1, s2); @@ -78,7 +78,7 @@ glm_sphere_merge(const vec4 s1, const vec4 s2, vec4 dest) { */ CGLM_INLINE bool -glm_sphere_sphere(const vec4 s1, const vec4 s2) { +glm_sphere_sphere(vec4 s1, vec4 s2) { return glm_vec3_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]); } @@ -90,7 +90,7 @@ glm_sphere_sphere(const vec4 s1, const vec4 s2) { */ CGLM_INLINE bool -glm_sphere_point(const vec4 s, const vec3 point) { +glm_sphere_point(vec4 s, vec3 point) { float rr; rr = s[3] * s[3]; return glm_vec3_distance2(point, s) <= rr; diff --git a/include/cglm/vec3-ext.h b/include/cglm/vec3-ext.h index d82455f..f1cc462 100644 --- a/include/cglm/vec3-ext.h +++ b/include/cglm/vec3-ext.h @@ -52,7 +52,7 @@ glm_vec3_broadcast(float val, vec3 d) { */ CGLM_INLINE bool -glm_vec3_eq(const vec3 v, float val) { +glm_vec3_eq(vec3 v, float val) { return v[0] == val && v[0] == v[1] && v[0] == v[2]; } @@ -64,7 +64,7 @@ glm_vec3_eq(const vec3 v, float val) { */ CGLM_INLINE bool -glm_vec3_eq_eps(const vec3 v, float val) { +glm_vec3_eq_eps(vec3 v, float val) { return fabsf(v[0] - val) <= FLT_EPSILON && fabsf(v[1] - val) <= FLT_EPSILON && fabsf(v[2] - val) <= FLT_EPSILON; @@ -77,7 +77,7 @@ glm_vec3_eq_eps(const vec3 v, float val) { */ CGLM_INLINE bool -glm_vec3_eq_all(const vec3 v) { +glm_vec3_eq_all(vec3 v) { return v[0] == v[1] && v[0] == v[2]; } @@ -89,7 +89,7 @@ glm_vec3_eq_all(const vec3 v) { */ CGLM_INLINE bool -glm_vec3_eqv(const vec3 a, const vec3 b) { +glm_vec3_eqv(vec3 a, vec3 b) { return a[0] == b[0] && a[1] == b[1] && a[2] == b[2]; @@ -103,7 +103,7 @@ glm_vec3_eqv(const vec3 a, const vec3 b) { */ CGLM_INLINE bool -glm_vec3_eqv_eps(const vec3 a, const vec3 b) { +glm_vec3_eqv_eps(vec3 a, vec3 b) { return fabsf(a[0] - b[0]) <= FLT_EPSILON && fabsf(a[1] - b[1]) <= FLT_EPSILON && fabsf(a[2] - b[2]) <= FLT_EPSILON; @@ -116,7 +116,7 @@ glm_vec3_eqv_eps(const vec3 a, const vec3 b) { */ CGLM_INLINE float -glm_vec3_max(const vec3 v) { +glm_vec3_max(vec3 v) { float max; max = v[0]; @@ -135,7 +135,7 @@ glm_vec3_max(const vec3 v) { */ CGLM_INLINE float -glm_vec3_min(const vec3 v) { +glm_vec3_min(vec3 v) { float min; min = v[0]; @@ -155,7 +155,7 @@ glm_vec3_min(const vec3 v) { */ CGLM_INLINE bool -glm_vec3_isnan(const vec3 v) { +glm_vec3_isnan(vec3 v) { return isnan(v[0]) || isnan(v[1]) || isnan(v[2]); } @@ -167,7 +167,7 @@ glm_vec3_isnan(const vec3 v) { */ CGLM_INLINE bool -glm_vec3_isinf(const vec3 v) { +glm_vec3_isinf(vec3 v) { return isinf(v[0]) || isinf(v[1]) || isinf(v[2]); } @@ -179,7 +179,7 @@ glm_vec3_isinf(const vec3 v) { */ CGLM_INLINE bool -glm_vec3_isvalid(const vec3 v) { +glm_vec3_isvalid(vec3 v) { return !glm_vec3_isnan(v) && !glm_vec3_isinf(v); } @@ -192,7 +192,7 @@ glm_vec3_isvalid(const vec3 v) { */ CGLM_INLINE void -glm_vec3_sign(const vec3 v, vec3 dest) { +glm_vec3_sign(vec3 v, vec3 dest) { dest[0] = glm_signf(v[0]); dest[1] = glm_signf(v[1]); dest[2] = glm_signf(v[2]); @@ -206,7 +206,7 @@ glm_vec3_sign(const vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec3_sqrt(const vec3 v, vec3 dest) { +glm_vec3_sqrt(vec3 v, vec3 dest) { dest[0] = sqrtf(v[0]); dest[1] = sqrtf(v[1]); dest[2] = sqrtf(v[2]); diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index b503b6e..e67cc2f 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -111,7 +111,7 @@ */ CGLM_INLINE void -glm_vec3(const vec4 v4, vec3 dest) { +glm_vec3(vec4 v4, vec3 dest) { dest[0] = v4[0]; dest[1] = v4[1]; dest[2] = v4[2]; @@ -125,7 +125,7 @@ glm_vec3(const vec4 v4, vec3 dest) { */ CGLM_INLINE void -glm_vec3_copy(const vec3 a, vec3 dest) { +glm_vec3_copy(vec3 a, vec3 dest) { dest[0] = a[0]; dest[1] = a[1]; dest[2] = a[2]; @@ -163,7 +163,7 @@ glm_vec3_one(vec3 v) { */ CGLM_INLINE float -glm_vec3_dot(const vec3 a, const vec3 b) { +glm_vec3_dot(vec3 a, vec3 b) { return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; } @@ -180,7 +180,7 @@ glm_vec3_dot(const vec3 a, const vec3 b) { */ CGLM_INLINE float -glm_vec3_norm2(const vec3 v) { +glm_vec3_norm2(vec3 v) { return glm_vec3_dot(v, v); } @@ -193,7 +193,7 @@ glm_vec3_norm2(const vec3 v) { */ CGLM_INLINE float -glm_vec3_norm(const vec3 v) { +glm_vec3_norm(vec3 v) { return sqrtf(glm_vec3_norm2(v)); } @@ -206,7 +206,7 @@ glm_vec3_norm(const vec3 v) { */ CGLM_INLINE void -glm_vec3_add(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_add(vec3 a, vec3 b, vec3 dest) { dest[0] = a[0] + b[0]; dest[1] = a[1] + b[1]; dest[2] = a[2] + b[2]; @@ -221,7 +221,7 @@ glm_vec3_add(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_adds(const vec3 v, float s, vec3 dest) { +glm_vec3_adds(vec3 v, float s, vec3 dest) { dest[0] = v[0] + s; dest[1] = v[1] + s; dest[2] = v[2] + s; @@ -236,7 +236,7 @@ glm_vec3_adds(const vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec3_sub(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_sub(vec3 a, vec3 b, vec3 dest) { dest[0] = a[0] - b[0]; dest[1] = a[1] - b[1]; dest[2] = a[2] - b[2]; @@ -251,7 +251,7 @@ glm_vec3_sub(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_subs(const vec3 v, float s, vec3 dest) { +glm_vec3_subs(vec3 v, float s, vec3 dest) { dest[0] = v[0] - s; dest[1] = v[1] - s; dest[2] = v[2] - s; @@ -266,7 +266,7 @@ glm_vec3_subs(const vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec3_mul(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_mul(vec3 a, vec3 b, vec3 dest) { dest[0] = a[0] * b[0]; dest[1] = a[1] * b[1]; dest[2] = a[2] * b[2]; @@ -281,7 +281,7 @@ glm_vec3_mul(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_scale(const vec3 v, float s, vec3 dest) { +glm_vec3_scale(vec3 v, float s, vec3 dest) { dest[0] = v[0] * s; dest[1] = v[1] * s; dest[2] = v[2] * s; @@ -296,7 +296,7 @@ glm_vec3_scale(const vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec3_scale_as(const vec3 v, float s, vec3 dest) { +glm_vec3_scale_as(vec3 v, float s, vec3 dest) { float norm; norm = glm_vec3_norm(v); @@ -317,7 +317,7 @@ glm_vec3_scale_as(const vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec3_div(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_div(vec3 a, vec3 b, vec3 dest) { dest[0] = a[0] / b[0]; dest[1] = a[1] / b[1]; dest[2] = a[2] / b[2]; @@ -332,7 +332,7 @@ glm_vec3_div(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_divs(const vec3 v, float s, vec3 dest) { +glm_vec3_divs(vec3 v, float s, vec3 dest) { dest[0] = v[0] / s; dest[1] = v[1] / s; dest[2] = v[2] / s; @@ -349,7 +349,7 @@ glm_vec3_divs(const vec3 v, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec3_addadd(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_addadd(vec3 a, vec3 b, vec3 dest) { dest[0] += a[0] + b[0]; dest[1] += a[1] + b[1]; dest[2] += a[2] + b[2]; @@ -366,7 +366,7 @@ glm_vec3_addadd(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_subadd(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_subadd(vec3 a, vec3 b, vec3 dest) { dest[0] += a[0] - b[0]; dest[1] += a[1] - b[1]; dest[2] += a[2] - b[2]; @@ -383,7 +383,7 @@ glm_vec3_subadd(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_muladd(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_muladd(vec3 a, vec3 b, vec3 dest) { dest[0] += a[0] * b[0]; dest[1] += a[1] * b[1]; dest[2] += a[2] * b[2]; @@ -400,7 +400,7 @@ glm_vec3_muladd(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_muladds(const vec3 a, float s, vec3 dest) { +glm_vec3_muladds(vec3 a, float s, vec3 dest) { dest[0] += a[0] * s; dest[1] += a[1] * s; dest[2] += a[2] * s; @@ -417,7 +417,7 @@ glm_vec3_muladds(const vec3 a, float s, vec3 dest) { */ CGLM_INLINE void -glm_vec3_maxadd(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_maxadd(vec3 a, vec3 b, vec3 dest) { dest[0] += glm_max(a[0], b[0]); dest[1] += glm_max(a[1], b[1]); dest[2] += glm_max(a[2], b[2]); @@ -434,7 +434,7 @@ glm_vec3_maxadd(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_minadd(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_minadd(vec3 a, vec3 b, vec3 dest) { dest[0] += glm_min(a[0], b[0]); dest[1] += glm_min(a[1], b[1]); dest[2] += glm_min(a[2], b[2]); @@ -448,7 +448,7 @@ glm_vec3_minadd(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_negate_to(const vec3 v, vec3 dest) { +glm_vec3_negate_to(vec3 v, vec3 dest) { dest[0] = -v[0]; dest[1] = -v[1]; dest[2] = -v[2]; @@ -493,7 +493,7 @@ glm_vec3_normalize(vec3 v) { */ CGLM_INLINE void -glm_vec3_normalize_to(const vec3 v, vec3 dest) { +glm_vec3_normalize_to(vec3 v, vec3 dest) { float norm; norm = glm_vec3_norm(v); @@ -515,7 +515,7 @@ glm_vec3_normalize_to(const vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec3_cross(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_cross(vec3 a, vec3 b, vec3 dest) { /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ dest[0] = a[1] * b[2] - a[2] * b[1]; dest[1] = a[2] * b[0] - a[0] * b[2]; @@ -531,7 +531,7 @@ glm_vec3_cross(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_crossn(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_crossn(vec3 a, vec3 b, vec3 dest) { glm_vec3_cross(a, b, dest); glm_vec3_normalize(dest); } @@ -546,7 +546,7 @@ glm_vec3_crossn(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE float -glm_vec3_angle(const vec3 a, const vec3 b) { +glm_vec3_angle(vec3 a, vec3 b) { float norm, dot; /* maybe compiler generate approximation instruction (rcp) */ @@ -570,7 +570,7 @@ glm_vec3_angle(const vec3 a, const vec3 b) { */ CGLM_INLINE void -glm_vec3_rotate(vec3 v, float angle, const vec3 axis) { +glm_vec3_rotate(vec3 v, float angle, vec3 axis) { vec3 v1, v2, k; float c, s; @@ -608,7 +608,7 @@ glm_vec3_rotate(vec3 v, float angle, const vec3 axis) { */ CGLM_INLINE void -glm_vec3_rotate_m4(const mat4 m, const vec3 v, vec3 dest) { +glm_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest) { vec4 x, y, z, res; glm_vec4_normalize_to(m[0], x); @@ -631,7 +631,7 @@ glm_vec3_rotate_m4(const mat4 m, const vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec3_rotate_m3(const mat3 m, const vec3 v, vec3 dest) { +glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest) { vec4 res, x, y, z; glm_vec4(m[0], 0.0f, x); @@ -658,7 +658,7 @@ glm_vec3_rotate_m3(const mat3 m, const vec3 v, vec3 dest) { */ CGLM_INLINE void -glm_vec3_proj(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_proj(vec3 a, vec3 b, vec3 dest) { glm_vec3_scale(b, glm_vec3_dot(a, b) / glm_vec3_norm2(b), dest); @@ -673,7 +673,7 @@ glm_vec3_proj(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_center(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_center(vec3 a, vec3 b, vec3 dest) { glm_vec3_add(a, b, dest); glm_vec3_scale(dest, 0.5f, dest); } @@ -687,7 +687,7 @@ glm_vec3_center(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE float -glm_vec3_distance2(const vec3 a, const vec3 b) { +glm_vec3_distance2(vec3 a, vec3 b) { return glm_pow2(b[0] - a[0]) + glm_pow2(b[1] - a[1]) + glm_pow2(b[2] - a[2]); @@ -702,7 +702,7 @@ glm_vec3_distance2(const vec3 a, const vec3 b) { */ CGLM_INLINE float -glm_vec3_distance(const vec3 a, const vec3 b) { +glm_vec3_distance(vec3 a, vec3 b) { return sqrtf(glm_vec3_distance2(a, b)); } @@ -715,7 +715,7 @@ glm_vec3_distance(const vec3 a, const vec3 b) { */ CGLM_INLINE void -glm_vec3_maxv(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_maxv(vec3 a, vec3 b, vec3 dest) { dest[0] = glm_max(a[0], b[0]); dest[1] = glm_max(a[1], b[1]); dest[2] = glm_max(a[2], b[2]); @@ -730,7 +730,7 @@ glm_vec3_maxv(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_minv(const vec3 a, const vec3 b, vec3 dest) { +glm_vec3_minv(vec3 a, vec3 b, vec3 dest) { dest[0] = glm_min(a[0], b[0]); dest[1] = glm_min(a[1], b[1]); dest[2] = glm_min(a[2], b[2]); @@ -744,7 +744,7 @@ glm_vec3_minv(const vec3 a, const vec3 b, vec3 dest) { */ CGLM_INLINE void -glm_vec3_ortho(const vec3 v, vec3 dest) { +glm_vec3_ortho(vec3 v, vec3 dest) { dest[0] = v[1] - v[2]; dest[1] = v[2] - v[0]; dest[2] = v[0] - v[1]; @@ -777,7 +777,7 @@ glm_vec3_clamp(vec3 v, float minVal, float maxVal) { */ CGLM_INLINE void -glm_vec3_lerp(const vec3 from, const vec3 to, float t, vec3 dest) { +glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) { vec3 s, v; /* from + s * (to - from) */ @@ -798,7 +798,7 @@ glm_vec3_lerp(const vec3 from, const vec3 to, float t, vec3 dest) { */ CGLM_INLINE void -glm_cross(const vec3 a, const vec3 b, vec3 d) { +glm_cross(vec3 a, vec3 b, vec3 d) { glm_vec3_cross(a, b, d); } @@ -814,7 +814,7 @@ glm_cross(const vec3 a, const vec3 b, vec3 d) { */ CGLM_INLINE float -glm_dot(const vec3 a, const vec3 b) { +glm_dot(vec3 a, vec3 b) { return glm_vec3_dot(a, b); } @@ -841,7 +841,7 @@ glm_normalize(vec3 v) { */ CGLM_INLINE void -glm_normalize_to(const vec3 v, vec3 dest) { +glm_normalize_to(vec3 v, vec3 dest) { glm_vec3_normalize_to(v, dest); } diff --git a/include/cglm/vec4-ext.h b/include/cglm/vec4-ext.h index 7998a7d..c545a14 100644 --- a/include/cglm/vec4-ext.h +++ b/include/cglm/vec4-ext.h @@ -56,7 +56,7 @@ glm_vec4_broadcast(float val, vec4 d) { */ CGLM_INLINE bool -glm_vec4_eq(const vec4 v, float val) { +glm_vec4_eq(vec4 v, float val) { return v[0] == val && v[0] == v[1] && v[0] == v[2] @@ -71,7 +71,7 @@ glm_vec4_eq(const vec4 v, float val) { */ CGLM_INLINE bool -glm_vec4_eq_eps(const vec4 v, float val) { +glm_vec4_eq_eps(vec4 v, float val) { return fabsf(v[0] - val) <= FLT_EPSILON && fabsf(v[1] - val) <= FLT_EPSILON && fabsf(v[2] - val) <= FLT_EPSILON @@ -85,7 +85,7 @@ glm_vec4_eq_eps(const vec4 v, float val) { */ CGLM_INLINE bool -glm_vec4_eq_all(const vec4 v) { +glm_vec4_eq_all(vec4 v) { return v[0] == v[1] && v[0] == v[2] && v[0] == v[3]; @@ -99,7 +99,7 @@ glm_vec4_eq_all(const vec4 v) { */ CGLM_INLINE bool -glm_vec4_eqv(const vec4 a, const vec4 b) { +glm_vec4_eqv(vec4 a, vec4 b) { return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] @@ -114,7 +114,7 @@ glm_vec4_eqv(const vec4 a, const vec4 b) { */ CGLM_INLINE bool -glm_vec4_eqv_eps(const vec4 a, const vec4 b) { +glm_vec4_eqv_eps(vec4 a, vec4 b) { return fabsf(a[0] - b[0]) <= FLT_EPSILON && fabsf(a[1] - b[1]) <= FLT_EPSILON && fabsf(a[2] - b[2]) <= FLT_EPSILON @@ -128,7 +128,7 @@ glm_vec4_eqv_eps(const vec4 a, const vec4 b) { */ CGLM_INLINE float -glm_vec4_max(const vec4 v) { +glm_vec4_max(vec4 v) { float max; max = glm_vec3_max(v); @@ -145,7 +145,7 @@ glm_vec4_max(const vec4 v) { */ CGLM_INLINE float -glm_vec4_min(const vec4 v) { +glm_vec4_min(vec4 v) { float min; min = glm_vec3_min(v); @@ -163,7 +163,7 @@ glm_vec4_min(const vec4 v) { */ CGLM_INLINE bool -glm_vec4_isnan(const vec4 v) { +glm_vec4_isnan(vec4 v) { return isnan(v[0]) || isnan(v[1]) || isnan(v[2]) || isnan(v[3]); } @@ -175,7 +175,7 @@ glm_vec4_isnan(const vec4 v) { */ CGLM_INLINE bool -glm_vec4_isinf(const vec4 v) { +glm_vec4_isinf(vec4 v) { return isinf(v[0]) || isinf(v[1]) || isinf(v[2]) || isinf(v[3]); } @@ -187,7 +187,7 @@ glm_vec4_isinf(const vec4 v) { */ CGLM_INLINE bool -glm_vec4_isvalid(const vec4 v) { +glm_vec4_isvalid(vec4 v) { return !glm_vec4_isnan(v) && !glm_vec4_isinf(v); } @@ -200,7 +200,7 @@ glm_vec4_isvalid(const vec4 v) { */ CGLM_INLINE void -glm_vec4_sign(const vec4 v, vec4 dest) { +glm_vec4_sign(vec4 v, vec4 dest) { #if defined( __SSE2__ ) || defined( __SSE2__ ) __m128 x0, x1, x2, x3, x4; @@ -228,7 +228,7 @@ glm_vec4_sign(const vec4 v, vec4 dest) { */ CGLM_INLINE void -glm_vec4_sqrt(const vec4 v, vec4 dest) { +glm_vec4_sqrt(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_sqrt_ps(glmm_load(v))); #else diff --git a/include/cglm/vec4.h b/include/cglm/vec4.h index 3ed31e4..d053ed5 100644 --- a/include/cglm/vec4.h +++ b/include/cglm/vec4.h @@ -90,7 +90,7 @@ */ CGLM_INLINE void -glm_vec4(const vec3 v3, float last, vec4 dest) { +glm_vec4(vec3 v3, float last, vec4 dest) { dest[0] = v3[0]; dest[1] = v3[1]; dest[2] = v3[2]; @@ -105,7 +105,7 @@ glm_vec4(const vec3 v3, float last, vec4 dest) { */ CGLM_INLINE void -glm_vec4_copy3(const vec4 a, vec3 dest) { +glm_vec4_copy3(vec4 a, vec3 dest) { dest[0] = a[0]; dest[1] = a[1]; dest[2] = a[2]; @@ -119,7 +119,7 @@ glm_vec4_copy3(const vec4 a, vec3 dest) { */ CGLM_INLINE void -glm_vec4_copy(const vec4 v, vec4 dest) { +glm_vec4_copy(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, glmm_load(v)); #elif defined(CGLM_NEON_FP) @@ -142,7 +142,7 @@ glm_vec4_copy(const vec4 v, vec4 dest) { */ CGLM_INLINE void -glm_vec4_ucopy(const vec4 v, vec4 dest) { +glm_vec4_ucopy(vec4 v, vec4 dest) { dest[0] = v[0]; dest[1] = v[1]; dest[2] = v[2]; @@ -199,7 +199,7 @@ glm_vec4_one(vec4 v) { */ CGLM_INLINE float -glm_vec4_dot(const vec4 a, const vec4 b) { +glm_vec4_dot(vec4 a, vec4 b) { #if defined(CGLM_SIMD) return glmm_dot(glmm_load(a), glmm_load(b)); #else @@ -220,7 +220,7 @@ glm_vec4_dot(const vec4 a, const vec4 b) { */ CGLM_INLINE float -glm_vec4_norm2(const vec4 v) { +glm_vec4_norm2(vec4 v) { return glm_vec4_dot(v, v); } @@ -233,7 +233,7 @@ glm_vec4_norm2(const vec4 v) { */ CGLM_INLINE float -glm_vec4_norm(const vec4 v) { +glm_vec4_norm(vec4 v) { #if defined(CGLM_SIMD) return glmm_norm(glmm_load(v)); #else @@ -250,7 +250,7 @@ glm_vec4_norm(const vec4 v) { */ CGLM_INLINE void -glm_vec4_add(const vec4 a, const vec4 b, vec4 dest) { +glm_vec4_add(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(a), glmm_load(b))); #elif defined(CGLM_NEON_FP) @@ -272,7 +272,7 @@ glm_vec4_add(const vec4 a, const vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_adds(const vec4 v, float s, vec4 dest) { +glm_vec4_adds(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(v), _mm_set1_ps(s))); #elif defined(CGLM_NEON_FP) @@ -294,7 +294,7 @@ glm_vec4_adds(const vec4 v, float s, vec4 dest) { */ CGLM_INLINE void -glm_vec4_sub(const vec4 a, const vec4 b, vec4 dest) { +glm_vec4_sub(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_sub_ps(glmm_load(a), glmm_load(b))); #elif defined(CGLM_NEON_FP) @@ -316,7 +316,7 @@ glm_vec4_sub(const vec4 a, const vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_subs(const vec4 v, float s, vec4 dest) { +glm_vec4_subs(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_sub_ps(glmm_load(v), _mm_set1_ps(s))); #elif defined(CGLM_NEON_FP) @@ -338,7 +338,7 @@ glm_vec4_subs(const vec4 v, float s, vec4 dest) { */ CGLM_INLINE void -glm_vec4_mul(const vec4 a, const vec4 b, vec4 dest) { +glm_vec4_mul(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_mul_ps(glmm_load(a), glmm_load(b))); #elif defined(CGLM_NEON_FP) @@ -360,7 +360,7 @@ glm_vec4_mul(const vec4 a, const vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_scale(const vec4 v, float s, vec4 dest) { +glm_vec4_scale(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_mul_ps(glmm_load(v), _mm_set1_ps(s))); #elif defined(CGLM_NEON_FP) @@ -382,7 +382,7 @@ glm_vec4_scale(const vec4 v, float s, vec4 dest) { */ CGLM_INLINE void -glm_vec4_scale_as(const vec4 v, float s, vec4 dest) { +glm_vec4_scale_as(vec4 v, float s, vec4 dest) { float norm; norm = glm_vec4_norm(v); @@ -403,7 +403,7 @@ glm_vec4_scale_as(const vec4 v, float s, vec4 dest) { */ CGLM_INLINE void -glm_vec4_div(const vec4 a, const vec4 b, vec4 dest) { +glm_vec4_div(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_div_ps(glmm_load(a), glmm_load(b))); #else @@ -423,7 +423,7 @@ glm_vec4_div(const vec4 a, const vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_divs(const vec4 v, float s, vec4 dest) { +glm_vec4_divs(vec4 v, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_div_ps(glmm_load(v), _mm_set1_ps(s))); #else @@ -442,7 +442,7 @@ glm_vec4_divs(const vec4 v, float s, vec4 dest) { */ CGLM_INLINE void -glm_vec4_addadd(const vec4 a, const vec4 b, vec4 dest) { +glm_vec4_addadd(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_add_ps(glmm_load(a), @@ -470,7 +470,7 @@ glm_vec4_addadd(const vec4 a, const vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_subadd(const vec4 a, const vec4 b, vec4 dest) { +glm_vec4_subadd(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_sub_ps(glmm_load(a), @@ -498,7 +498,7 @@ glm_vec4_subadd(const vec4 a, const vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_muladd(const vec4 a, const vec4 b, vec4 dest) { +glm_vec4_muladd(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_mul_ps(glmm_load(a), @@ -526,7 +526,7 @@ glm_vec4_muladd(const vec4 a, const vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_muladds(const vec4 a, float s, vec4 dest) { +glm_vec4_muladds(vec4 a, float s, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_mul_ps(glmm_load(a), @@ -554,7 +554,7 @@ glm_vec4_muladds(const vec4 a, float s, vec4 dest) { */ CGLM_INLINE void -glm_vec4_maxadd(const vec4 a, const vec4 b, vec4 dest) { +glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_max_ps(glmm_load(a), @@ -582,7 +582,7 @@ glm_vec4_maxadd(const vec4 a, const vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_minadd(const vec4 a,const vec4 b, vec4 dest) { +glm_vec4_minadd(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_add_ps(glmm_load(dest), _mm_min_ps(glmm_load(a), @@ -607,7 +607,7 @@ glm_vec4_minadd(const vec4 a,const vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_negate_to(const vec4 v, vec4 dest) { +glm_vec4_negate_to(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); #elif defined(CGLM_NEON_FP) @@ -639,7 +639,7 @@ glm_vec4_negate(vec4 v) { */ CGLM_INLINE void -glm_vec4_normalize_to(const vec4 v, vec4 dest) { +glm_vec4_normalize_to(vec4 v, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) __m128 xdot, x0; float dot; @@ -688,7 +688,7 @@ glm_vec4_normalize(vec4 v) { */ CGLM_INLINE float -glm_vec4_distance(const vec4 a, const vec4 b) { +glm_vec4_distance(vec4 a, vec4 b) { #if defined( __SSE__ ) || defined( __SSE2__ ) return glmm_norm(_mm_sub_ps(glmm_load(b), glmm_load(a))); #elif defined(CGLM_NEON_FP) @@ -710,7 +710,7 @@ glm_vec4_distance(const vec4 a, const vec4 b) { */ CGLM_INLINE void -glm_vec4_maxv(const vec4 a, const vec4 b, vec4 dest) { +glm_vec4_maxv(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_max_ps(glmm_load(a), glmm_load(b))); #elif defined(CGLM_NEON_FP) @@ -732,7 +732,7 @@ glm_vec4_maxv(const vec4 a, const vec4 b, vec4 dest) { */ CGLM_INLINE void -glm_vec4_minv(const vec4 a, const vec4 b, vec4 dest) { +glm_vec4_minv(vec4 a, vec4 b, vec4 dest) { #if defined( __SSE__ ) || defined( __SSE2__ ) glmm_store(dest, _mm_min_ps(glmm_load(a), glmm_load(b))); #elif defined(CGLM_NEON_FP) @@ -781,7 +781,7 @@ glm_vec4_clamp(vec4 v, float minVal, float maxVal) { */ CGLM_INLINE void -glm_vec4_lerp(const vec4 from, const vec4 to, float t, vec4 dest) { +glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) { vec4 s, v; /* from + s * (to - from) */ diff --git a/src/affine.c b/src/affine.c index 6388c19..a818bd1 100644 --- a/src/affine.c +++ b/src/affine.c @@ -10,19 +10,19 @@ CGLM_EXPORT void -glmc_translate_make(mat4 m, const vec3 v) { +glmc_translate_make(mat4 m, vec3 v) { glm_translate_make(m, v); } CGLM_EXPORT void -glmc_translate_to(const mat4 m, const vec3 v, mat4 dest) { +glmc_translate_to(mat4 m, vec3 v, mat4 dest) { glm_translate_to(m, v, dest); } CGLM_EXPORT void -glmc_translate(mat4 m, const vec3 v) { +glmc_translate(mat4 m, vec3 v) { glm_translate(m, v); } @@ -46,19 +46,19 @@ glmc_translate_z(mat4 m, float to) { CGLM_EXPORT void -glmc_scale_make(mat4 m, const vec3 v) { +glmc_scale_make(mat4 m, vec3 v) { glm_scale_make(m, v); } CGLM_EXPORT void -glmc_scale_to(const mat4 m, const vec3 v, mat4 dest) { +glmc_scale_to(mat4 m, vec3 v, mat4 dest) { glm_scale_to(m, v, dest); } CGLM_EXPORT void -glmc_scale(mat4 m, const vec3 v) { +glmc_scale(mat4 m, vec3 v) { glm_scale(m, v); } @@ -70,79 +70,79 @@ glmc_scale_uni(mat4 m, float s) { CGLM_EXPORT void -glmc_rotate_x(const mat4 m, float rad, mat4 dest) { +glmc_rotate_x(mat4 m, float rad, mat4 dest) { glm_rotate_x(m, rad, dest); } CGLM_EXPORT void -glmc_rotate_y(const mat4 m, float rad, mat4 dest) { +glmc_rotate_y(mat4 m, float rad, mat4 dest) { glm_rotate_y(m, rad, dest); } CGLM_EXPORT void -glmc_rotate_z(const mat4 m, float rad, mat4 dest) { +glmc_rotate_z(mat4 m, float rad, mat4 dest) { glm_rotate_z(m, rad, dest); } CGLM_EXPORT void -glmc_rotate_make(mat4 m, float angle, const vec3 axis) { +glmc_rotate_make(mat4 m, float angle, vec3 axis) { glm_rotate_make(m, angle, axis); } CGLM_EXPORT void -glmc_rotate(mat4 m, float angle, const vec3 axis) { +glmc_rotate(mat4 m, float angle, vec3 axis) { glm_rotate(m, angle, axis); } CGLM_EXPORT void -glmc_rotate_at(mat4 m, const vec3 pivot, float angle, const vec3 axis) { +glmc_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis) { glm_rotate_at(m, pivot, angle, axis); } CGLM_EXPORT void -glmc_rotate_atm(mat4 m, const vec3 pivot, float angle, const vec3 axis) { +glmc_rotate_atm(mat4 m, vec3 pivot, float angle, vec3 axis) { glm_rotate_atm(m, pivot, angle, axis); } CGLM_EXPORT void -glmc_decompose_scalev(const mat4 m, vec3 s) { +glmc_decompose_scalev(mat4 m, vec3 s) { glm_decompose_scalev(m, s); } CGLM_EXPORT bool -glmc_uniscaled(const mat4 m) { +glmc_uniscaled(mat4 m) { return glm_uniscaled(m); } CGLM_EXPORT void -glmc_decompose_rs(const mat4 m, mat4 r, vec3 s) { +glmc_decompose_rs(mat4 m, mat4 r, vec3 s) { glm_decompose_rs(m, r, s); } CGLM_EXPORT void -glmc_decompose(const mat4 m, vec4 t, mat4 r, vec3 s) { +glmc_decompose(mat4 m, vec4 t, mat4 r, vec3 s) { glm_decompose(m, t, r, s); } CGLM_EXPORT void -glmc_mul(const mat4 m1, const mat4 m2, mat4 dest) { +glmc_mul(mat4 m1, mat4 m2, mat4 dest) { glm_mul(m1, m2, dest); } CGLM_EXPORT void -glmc_mul_rot(const mat4 m1, const mat4 m2, mat4 dest) { +glmc_mul_rot(mat4 m1, mat4 m2, mat4 dest) { glm_mul_rot(m1, m2, dest); } diff --git a/src/box.c b/src/box.c index 4c7022b..fd639ea 100644 --- a/src/box.c +++ b/src/box.c @@ -10,34 +10,34 @@ CGLM_EXPORT void -glmc_aabb_transform(const vec3 box[2], const mat4 m, vec3 dest[2]) { +glmc_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]) { glm_aabb_transform(box, m, dest); } CGLM_EXPORT void -glmc_aabb_merge(const vec3 box1[2], const vec3 box2[2], vec3 dest[2]) { +glmc_aabb_merge(vec3 box1[2], vec3 box2[2], vec3 dest[2]) { glm_aabb_merge(box1, box2, dest); } CGLM_EXPORT void -glmc_aabb_crop(const vec3 box[2], const vec3 cropBox[2], vec3 dest[2]) { +glmc_aabb_crop(vec3 box[2], vec3 cropBox[2], vec3 dest[2]) { glm_aabb_crop(box, cropBox, dest); } CGLM_EXPORT void -glmc_aabb_crop_until(const vec3 box[2], - const vec3 cropBox[2], - const vec3 clampBox[2], - vec3 dest[2]) { +glmc_aabb_crop_until(vec3 box[2], + vec3 cropBox[2], + vec3 clampBox[2], + vec3 dest[2]) { glm_aabb_crop_until(box, cropBox, clampBox, dest); } CGLM_EXPORT bool -glmc_aabb_frustum(const vec3 box[2], vec4 planes[6]) { +glmc_aabb_frustum(vec3 box[2], vec4 planes[6]) { return glm_aabb_frustum(box, planes); } @@ -49,48 +49,48 @@ glmc_aabb_invalidate(vec3 box[2]) { CGLM_EXPORT bool -glmc_aabb_isvalid(const vec3 box[2]) { +glmc_aabb_isvalid(vec3 box[2]) { return glm_aabb_isvalid(box); } CGLM_EXPORT float -glmc_aabb_size(const vec3 box[2]) { +glmc_aabb_size(vec3 box[2]) { return glm_aabb_size(box); } CGLM_EXPORT float -glmc_aabb_radius(const vec3 box[2]) { +glmc_aabb_radius(vec3 box[2]) { return glm_aabb_radius(box); } CGLM_EXPORT void -glmc_aabb_center(const vec3 box[2], vec3 dest) { +glmc_aabb_center(vec3 box[2], vec3 dest) { glm_aabb_center(box, dest); } CGLM_EXPORT bool -glmc_aabb_aabb(const vec3 box[2], const vec3 other[2]) { +glmc_aabb_aabb(vec3 box[2], vec3 other[2]) { return glm_aabb_aabb(box, other); } CGLM_EXPORT bool -glmc_aabb_point(const vec3 box[2], const vec3 point) { +glmc_aabb_point(vec3 box[2], vec3 point) { return glm_aabb_point(box, point); } CGLM_EXPORT bool -glmc_aabb_contains(const vec3 box[2], const vec3 other[2]) { +glmc_aabb_contains(vec3 box[2], vec3 other[2]) { return glm_aabb_contains(box, other); } CGLM_EXPORT bool -glmc_aabb_sphere(const vec3 box[2], const vec4 s) { +glmc_aabb_sphere(vec3 box[2], vec4 s) { return glm_aabb_sphere(box, s); } diff --git a/src/cam.c b/src/cam.c index 2ad4cdd..39ac210 100644 --- a/src/cam.c +++ b/src/cam.c @@ -16,7 +16,7 @@ glmc_frustum(float left, float top, float nearVal, float farVal, - mat4 dest) { + mat4 dest) { glm_frustum(left, right, bottom, @@ -34,7 +34,7 @@ glmc_ortho(float left, float top, float nearVal, float farVal, - mat4 dest) { + mat4 dest) { glm_ortho(left, right, bottom, @@ -46,19 +46,19 @@ glmc_ortho(float left, CGLM_EXPORT void -glmc_ortho_aabb(const vec3 box[2], mat4 dest) { +glmc_ortho_aabb(vec3 box[2], mat4 dest) { glm_ortho_aabb(box, dest); } CGLM_EXPORT void -glmc_ortho_aabb_p(const vec3 box[2], float padding, mat4 dest) { +glmc_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) { glm_ortho_aabb_p(box, padding, dest); } CGLM_EXPORT void -glmc_ortho_aabb_pz(const vec3 box[2], float padding, mat4 dest) { +glmc_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) { glm_ortho_aabb_pz(box, padding, dest); } @@ -80,7 +80,7 @@ glmc_perspective(float fovy, float aspect, float nearVal, float farVal, - mat4 dest) { + mat4 dest) { glm_perspective(fovy, aspect, nearVal, @@ -108,28 +108,28 @@ glmc_perspective_resize(float aspect, mat4 proj) { CGLM_EXPORT void -glmc_lookat(const vec3 eye, - const vec3 center, - const vec3 up, - mat4 dest) { +glmc_lookat(vec3 eye, + vec3 center, + vec3 up, + mat4 dest) { glm_lookat(eye, center, up, dest); } CGLM_EXPORT void -glmc_look(const vec3 eye, const vec3 dir, const vec3 up, mat4 dest) { +glmc_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { glm_look(eye, dir, up, dest); } CGLM_EXPORT void -glmc_look_anyup(const vec3 eye, const vec3 dir, mat4 dest) { +glmc_look_anyup(vec3 eye, vec3 dir, mat4 dest) { glm_look_anyup(eye, dir, dest); } CGLM_EXPORT void -glmc_persp_decomp(const mat4 proj, +glmc_persp_decomp(mat4 proj, float * __restrict nearVal, float * __restrict farVal, float * __restrict top, @@ -141,13 +141,13 @@ glmc_persp_decomp(const mat4 proj, CGLM_EXPORT void -glmc_persp_decompv(const mat4 proj, float dest[6]) { +glmc_persp_decompv(mat4 proj, float dest[6]) { glm_persp_decompv(proj, dest); } CGLM_EXPORT void -glmc_persp_decomp_x(const mat4 proj, +glmc_persp_decomp_x(mat4 proj, float * __restrict left, float * __restrict right) { glm_persp_decomp_x(proj, left, right); @@ -155,7 +155,7 @@ glmc_persp_decomp_x(const mat4 proj, CGLM_EXPORT void -glmc_persp_decomp_y(const mat4 proj, +glmc_persp_decomp_y(mat4 proj, float * __restrict top, float * __restrict bottom) { glm_persp_decomp_y(proj, top, bottom); @@ -163,7 +163,7 @@ glmc_persp_decomp_y(const mat4 proj, CGLM_EXPORT void -glmc_persp_decomp_z(const mat4 proj, +glmc_persp_decomp_z(mat4 proj, float * __restrict nearVal, float * __restrict farVal) { glm_persp_decomp_z(proj, nearVal, farVal); @@ -171,30 +171,30 @@ glmc_persp_decomp_z(const mat4 proj, CGLM_EXPORT void -glmc_persp_decomp_far(const mat4 proj, float * __restrict farVal) { +glmc_persp_decomp_far(mat4 proj, float * __restrict farVal) { glm_persp_decomp_far(proj, farVal); } CGLM_EXPORT void -glmc_persp_decomp_near(const mat4 proj, float * __restrict nearVal) { +glmc_persp_decomp_near(mat4 proj, float * __restrict nearVal) { glm_persp_decomp_near(proj, nearVal); } CGLM_EXPORT float -glmc_persp_fovy(const mat4 proj) { +glmc_persp_fovy(mat4 proj) { return glm_persp_fovy(proj); } CGLM_EXPORT float -glmc_persp_aspect(const mat4 proj) { +glmc_persp_aspect(mat4 proj) { return glm_persp_aspect(proj); } CGLM_EXPORT void -glmc_persp_sizes(const mat4 proj, float fovy, vec4 dest) { +glmc_persp_sizes(mat4 proj, float fovy, vec4 dest) { glm_persp_sizes(proj, fovy, dest); } diff --git a/src/curve.c b/src/curve.c index 88d735e..74d4702 100644 --- a/src/curve.c +++ b/src/curve.c @@ -10,6 +10,6 @@ CGLM_EXPORT float -glmc_smc(float s, const mat4 m, const vec4 c) { +glmc_smc(float s, mat4 m, vec4 c) { return glm_smc(s, m, c); } diff --git a/src/euler.c b/src/euler.c index 92126ca..44d6edb 100644 --- a/src/euler.c +++ b/src/euler.c @@ -10,54 +10,54 @@ CGLM_EXPORT void -glmc_euler_angles(const mat4 m, vec3 dest) { +glmc_euler_angles(mat4 m, vec3 dest) { glm_euler_angles(m, dest); } CGLM_EXPORT void -glmc_euler(const vec3 angles, mat4 dest) { +glmc_euler(vec3 angles, mat4 dest) { glm_euler(angles, dest); } CGLM_EXPORT void -glmc_euler_xyz(const vec3 angles, mat4 dest) { +glmc_euler_xyz(vec3 angles, mat4 dest) { glm_euler_xyz(angles, dest); } CGLM_EXPORT void -glmc_euler_zyx(const vec3 angles, mat4 dest) { +glmc_euler_zyx(vec3 angles, mat4 dest) { glm_euler_zyx(angles, dest); } CGLM_EXPORT void -glmc_euler_zxy(const vec3 angles, mat4 dest) { +glmc_euler_zxy(vec3 angles, mat4 dest) { glm_euler_zxy(angles, dest); } CGLM_EXPORT void -glmc_euler_xzy(const vec3 angles, mat4 dest) { +glmc_euler_xzy(vec3 angles, mat4 dest) { glm_euler_xzy(angles, dest); } CGLM_EXPORT void -glmc_euler_yzx(const vec3 angles, mat4 dest) { +glmc_euler_yzx(vec3 angles, mat4 dest) { glm_euler_yzx(angles, dest); } CGLM_EXPORT void -glmc_euler_yxz(const vec3 angles, mat4 dest) { +glmc_euler_yxz(vec3 angles, mat4 dest) { glm_euler_yxz(angles, dest); } CGLM_EXPORT void -glmc_euler_by_order(const vec3 angles, glm_euler_sq axis, mat4 dest) { +glmc_euler_by_order(vec3 angles, glm_euler_sq axis, mat4 dest) { glm_euler_by_order(angles, axis, dest); } diff --git a/src/frustum.c b/src/frustum.c index 5e896f4..312c3d3 100644 --- a/src/frustum.c +++ b/src/frustum.c @@ -10,33 +10,33 @@ CGLM_EXPORT void -glmc_frustum_planes(const mat4 m, vec4 dest[6]) { +glmc_frustum_planes(mat4 m, vec4 dest[6]) { glm_frustum_planes(m, dest); } CGLM_EXPORT void -glmc_frustum_corners(const mat4 invMat, vec4 dest[8]) { +glmc_frustum_corners(mat4 invMat, vec4 dest[8]) { glm_frustum_corners(invMat, dest); } CGLM_EXPORT void -glmc_frustum_center(const vec4 corners[8], vec4 dest) { +glmc_frustum_center(vec4 corners[8], vec4 dest) { glm_frustum_center(corners, dest); } CGLM_EXPORT void -glmc_frustum_box(const vec4 corners[8], const mat4 m, vec3 box[2]) { +glmc_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) { glm_frustum_box(corners, m, box); } CGLM_EXPORT void -glmc_frustum_corners_at(const vec4 corners[8], - float splitDist, - float farDist, - vec4 planeCorners[4]) { +glmc_frustum_corners_at(vec4 corners[8], + float splitDist, + float farDist, + vec4 planeCorners[4]) { glm_frustum_corners_at(corners, splitDist, farDist, planeCorners); } diff --git a/src/io.c b/src/io.c index 9e1c15f..fb2b5a9 100644 --- a/src/io.c +++ b/src/io.c @@ -10,35 +10,35 @@ CGLM_EXPORT void -glmc_mat4_print(const mat4 matrix, - FILE * const __restrict ostream) { +glmc_mat4_print(mat4 matrix, + FILE * __restrict ostream) { glm_mat4_print(matrix, ostream); } CGLM_EXPORT void -glmc_mat3_print(const mat3 matrix, - FILE * const __restrict ostream) { +glmc_mat3_print(mat3 matrix, + FILE * __restrict ostream) { glm_mat3_print(matrix, ostream); } CGLM_EXPORT void -glmc_vec4_print(const vec4 vec, - FILE * const __restrict ostream) { +glmc_vec4_print(vec4 vec, + FILE * __restrict ostream) { glm_vec4_print(vec, ostream); } CGLM_EXPORT void -glmc_vec3_print(const vec3 vec, - FILE * const __restrict ostream) { +glmc_vec3_print(vec3 vec, + FILE * __restrict ostream) { glm_vec3_print(vec, ostream); } CGLM_EXPORT void -glmc_versor_print(const versor vec, - FILE * const __restrict ostream) { +glmc_versor_print(versor vec, + FILE * __restrict ostream) { glm_versor_print(vec, ostream); } diff --git a/src/mat3.c b/src/mat3.c index a99f583..337f1f1 100644 --- a/src/mat3.c +++ b/src/mat3.c @@ -10,7 +10,7 @@ CGLM_EXPORT void -glmc_mat3_copy(const mat3 mat, mat3 dest) { +glmc_mat3_copy(mat3 mat, mat3 dest) { glm_mat3_copy(mat, dest); } @@ -22,19 +22,19 @@ glmc_mat3_identity(mat3 mat) { CGLM_EXPORT void -glmc_mat3_identity_array(mat3 * const __restrict mat, size_t count) { +glmc_mat3_identity_array(mat3 * __restrict mat, size_t count) { glm_mat3_identity_array(mat, count); } CGLM_EXPORT void -glmc_mat3_mul(const mat3 m1, const mat3 m2, mat3 dest) { +glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest) { glm_mat3_mul(m1, m2, dest); } CGLM_EXPORT void -glmc_mat3_transpose_to(const mat3 m, mat3 dest) { +glmc_mat3_transpose_to(mat3 m, mat3 dest) { glm_mat3_transpose_to(m, dest); } @@ -46,19 +46,19 @@ glmc_mat3_transpose(mat3 m) { CGLM_EXPORT void -glmc_mat3_mulv(const mat3 m, const vec3 v, vec3 dest) { +glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest) { glm_mat3_mulv(m, v, dest); } CGLM_EXPORT float -glmc_mat3_trace(const mat3 m) { +glmc_mat3_trace(mat3 m) { return glm_mat3_trace(m); } CGLM_EXPORT void -glmc_mat3_quat(const mat3 m, versor dest) { +glmc_mat3_quat(mat3 m, versor dest) { glm_mat3_quat(m, dest); } @@ -70,13 +70,13 @@ glmc_mat3_scale(mat3 m, float s) { CGLM_EXPORT float -glmc_mat3_det(const mat3 mat) { +glmc_mat3_det(mat3 mat) { return glm_mat3_det(mat); } CGLM_EXPORT void -glmc_mat3_inv(const mat3 mat, mat3 dest) { +glmc_mat3_inv(mat3 mat, mat3 dest) { glm_mat3_inv(mat, dest); } @@ -94,6 +94,6 @@ glmc_mat3_swap_row(mat3 mat, int row1, int row2) { CGLM_EXPORT float -glmc_mat3_rmc(const vec3 r, const mat3 m, const vec3 c) { +glmc_mat3_rmc(vec3 r, mat3 m, vec3 c) { return glm_mat3_rmc(r, m, c); } diff --git a/src/mat4.c b/src/mat4.c index 08c1257..c648a6e 100644 --- a/src/mat4.c +++ b/src/mat4.c @@ -10,13 +10,13 @@ CGLM_EXPORT void -glmc_mat4_ucopy(const mat4 mat, mat4 dest) { +glmc_mat4_ucopy(mat4 mat, mat4 dest) { glm_mat4_copy(mat, dest); } CGLM_EXPORT void -glmc_mat4_copy(const mat4 mat, mat4 dest) { +glmc_mat4_copy(mat4 mat, mat4 dest) { glm_mat4_copy(mat, dest); } @@ -28,73 +28,73 @@ glmc_mat4_identity(mat4 mat) { CGLM_EXPORT void -glmc_mat4_identity_array(mat4 * const __restrict mat, size_t count) { +glmc_mat4_identity_array(mat4 * __restrict mat, size_t count) { glm_mat4_identity_array(mat, count); } CGLM_EXPORT void -glmc_mat4_pick3(const mat4 mat, mat3 dest) { +glmc_mat4_pick3(mat4 mat, mat3 dest) { glm_mat4_pick3(mat, dest); } CGLM_EXPORT void -glmc_mat4_pick3t(const mat4 mat, mat3 dest) { +glmc_mat4_pick3t(mat4 mat, mat3 dest) { glm_mat4_pick3t(mat, dest); } CGLM_EXPORT void -glmc_mat4_ins3(const mat3 mat, mat4 dest) { +glmc_mat4_ins3(mat3 mat, mat4 dest) { glm_mat4_ins3(mat, dest); } CGLM_EXPORT void -glmc_mat4_mul(const mat4 m1, const mat4 m2, mat4 dest) { +glmc_mat4_mul(mat4 m1, mat4 m2, mat4 dest) { glm_mat4_mul(m1, m2, dest); } CGLM_EXPORT void -glmc_mat4_mulN(mat4 * const __restrict matrices[], uint32_t len, mat4 dest) { +glmc_mat4_mulN(mat4 * __restrict matrices[], uint32_t len, mat4 dest) { glm_mat4_mulN(matrices, len, dest); } CGLM_EXPORT void -glmc_mat4_mulv(const mat4 m, const vec4 v, vec4 dest) { +glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest) { glm_mat4_mulv(m, v, dest); } CGLM_EXPORT void -glmc_mat4_mulv3(const mat4 m, const vec3 v, float last, vec3 dest) { +glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest) { glm_mat4_mulv3(m, v, last, dest); } CGLM_EXPORT float -glmc_mat4_trace(const mat4 m) { +glmc_mat4_trace(mat4 m) { return glm_mat4_trace(m); } CGLM_EXPORT float -glmc_mat4_trace3(const mat4 m) { +glmc_mat4_trace3(mat4 m) { return glm_mat4_trace3(m); } CGLM_EXPORT void -glmc_mat4_quat(const mat4 m, versor dest) { +glmc_mat4_quat(mat4 m, versor dest) { glm_mat4_quat(m, dest); } CGLM_EXPORT void -glmc_mat4_transpose_to(const mat4 m, mat4 dest) { +glmc_mat4_transpose_to(mat4 m, mat4 dest) { glm_mat4_transpose_to(m, dest); } @@ -118,25 +118,25 @@ glmc_mat4_scale(mat4 m, float s) { CGLM_EXPORT float -glmc_mat4_det(const mat4 mat) { +glmc_mat4_det(mat4 mat) { return glm_mat4_det(mat); } CGLM_EXPORT void -glmc_mat4_inv(const mat4 mat, mat4 dest) { +glmc_mat4_inv(mat4 mat, mat4 dest) { glm_mat4_inv(mat, dest); } CGLM_EXPORT void -glmc_mat4_inv_precise(const mat4 mat, mat4 dest) { +glmc_mat4_inv_precise(mat4 mat, mat4 dest) { glm_mat4_inv_precise(mat, dest); } CGLM_EXPORT void -glmc_mat4_inv_fast(const mat4 mat, mat4 dest) { +glmc_mat4_inv_fast(mat4 mat, mat4 dest) { glm_mat4_inv_fast(mat, dest); } @@ -154,6 +154,6 @@ glmc_mat4_swap_row(mat4 mat, int row1, int row2) { CGLM_EXPORT float -glmc_mat4_rmc(const vec4 r, const mat4 m, const vec4 c) { +glmc_mat4_rmc(vec4 r, mat4 m, vec4 c) { return glm_mat4_rmc(r, m, c); } diff --git a/src/project.c b/src/project.c index ec7f33d..91c7128 100644 --- a/src/project.c +++ b/src/project.c @@ -10,18 +10,18 @@ CGLM_EXPORT void -glmc_unprojecti(const vec3 pos, const mat4 invMat, const vec4 vp, vec3 dest) { +glmc_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { glm_unprojecti(pos, invMat, vp, dest); } CGLM_EXPORT void -glmc_unproject(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest) { +glmc_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) { glm_unproject(pos, m, vp, dest); } CGLM_EXPORT void -glmc_project(const vec3 pos, const mat4 m, const vec4 vp, vec3 dest) { +glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { glm_project(pos, m, vp, dest); } diff --git a/src/quat.c b/src/quat.c index 7a642a8..32674a7 100644 --- a/src/quat.c +++ b/src/quat.c @@ -16,7 +16,7 @@ glmc_quat_identity(versor q) { CGLM_EXPORT void -glmc_quat_identity_array(versor * const __restrict q, size_t count) { +glmc_quat_identity_array(versor * __restrict q, size_t count) { glm_quat_identity_array(q, count); } @@ -34,25 +34,25 @@ glmc_quat(versor q, float angle, float x, float y, float z) { CGLM_EXPORT void -glmc_quatv(versor q, float angle, const vec3 axis) { +glmc_quatv(versor q, float angle, vec3 axis) { glm_quatv(q, angle, axis); } CGLM_EXPORT void -glmc_quat_copy(const versor q, versor dest) { +glmc_quat_copy(versor q, versor dest) { glm_quat_copy(q, dest); } CGLM_EXPORT float -glmc_quat_norm(const versor q) { +glmc_quat_norm(versor q) { return glm_quat_norm(q); } CGLM_EXPORT void -glmc_quat_normalize_to(const versor q, versor dest) { +glmc_quat_normalize_to(versor q, versor dest) { glm_quat_normalize_to(q, dest); } @@ -64,154 +64,150 @@ glmc_quat_normalize(versor q) { CGLM_EXPORT float -glmc_quat_dot(const versor p, const versor q) { +glmc_quat_dot(versor p, versor q) { return glm_quat_dot(p, q); } CGLM_EXPORT void -glmc_quat_conjugate(const versor q, versor dest) { +glmc_quat_conjugate(versor q, versor dest) { glm_quat_conjugate(q, dest); } CGLM_EXPORT void -glmc_quat_inv(const versor q, versor dest) { +glmc_quat_inv(versor q, versor dest) { glm_quat_inv(q, dest); } CGLM_EXPORT void -glmc_quat_add(const versor p, const versor q, versor dest) { +glmc_quat_add(versor p, versor q, versor dest) { glm_quat_add(p, q, dest); } CGLM_EXPORT void -glmc_quat_sub(const versor p, const versor q, versor dest) { +glmc_quat_sub(versor p, versor q, versor dest) { glm_quat_sub(p, q, dest); } CGLM_EXPORT float -glmc_quat_real(const versor q) { +glmc_quat_real(versor q) { return glm_quat_real(q); } CGLM_EXPORT void -glmc_quat_imag(const versor q, vec3 dest) { +glmc_quat_imag(versor q, vec3 dest) { glm_quat_imag(q, dest); } CGLM_EXPORT void -glmc_quat_imagn(const versor q, vec3 dest) { +glmc_quat_imagn(versor q, vec3 dest) { glm_quat_imagn(q, dest); } CGLM_EXPORT float -glmc_quat_imaglen(const versor q) { +glmc_quat_imaglen(versor q) { return glm_quat_imaglen(q); } CGLM_EXPORT float -glmc_quat_angle(const versor q) { +glmc_quat_angle(versor q) { return glm_quat_angle(q); } CGLM_EXPORT void -glmc_quat_axis(const versor q, versor dest) { +glmc_quat_axis(versor q, versor dest) { glm_quat_axis(q, dest); } CGLM_EXPORT void -glmc_quat_mul(const versor p, const versor q, versor dest) { +glmc_quat_mul(versor p, versor q, versor dest) { glm_quat_mul(p, q, dest); } CGLM_EXPORT void -glmc_quat_mat4(const versor q, mat4 dest) { +glmc_quat_mat4(versor q, mat4 dest) { glm_quat_mat4(q, dest); } CGLM_EXPORT void -glmc_quat_mat4t(const versor q, mat4 dest) { +glmc_quat_mat4t(versor q, mat4 dest) { glm_quat_mat4t(q, dest); } CGLM_EXPORT void -glmc_quat_mat3(const versor q, mat3 dest) { +glmc_quat_mat3(versor q, mat3 dest) { glm_quat_mat3(q, dest); } CGLM_EXPORT void -glmc_quat_mat3t(const versor q, mat3 dest) { +glmc_quat_mat3t(versor q, mat3 dest) { glm_quat_mat3t(q, dest); } CGLM_EXPORT void -glmc_quat_lerp(const versor from, const versor to, float t, versor dest) { +glmc_quat_lerp(versor from, versor to, float t, versor dest) { glm_quat_lerp(from, to, t, dest); } CGLM_EXPORT void -glmc_quat_slerp(const versor from, const versor to, float t, versor dest) { +glmc_quat_slerp(versor from, versor to, float t, versor dest) { glm_quat_slerp(from, to, t, dest); } CGLM_EXPORT void -glmc_quat_look(const vec3 eye, const versor ori, mat4 dest) { +glmc_quat_look(vec3 eye, versor ori, mat4 dest) { glm_quat_look(eye, ori, dest); } CGLM_EXPORT void -glmc_quat_for(const vec3 dir, const vec3 fwd, const vec3 up, versor dest) { +glmc_quat_for(vec3 dir, vec3 fwd, vec3 up, versor dest) { glm_quat_for(dir, fwd, up, dest); } CGLM_EXPORT void -glmc_quat_forp(const vec3 from, - const vec3 to, - const vec3 fwd, - const vec3 up, - versor dest) { +glmc_quat_forp(vec3 from, vec3 to, vec3 fwd, vec3 up, versor dest) { glm_quat_forp(from, to, fwd, up, dest); } CGLM_EXPORT void -glmc_quat_rotatev(const versor q, const vec3 v, vec3 dest) { +glmc_quat_rotatev(versor q, vec3 v, vec3 dest) { glm_quat_rotatev(q, v, dest); } CGLM_EXPORT void -glmc_quat_rotate(const mat4 m, const versor q, mat4 dest) { +glmc_quat_rotate(mat4 m, versor q, mat4 dest) { glm_quat_rotate(m, q, dest); } CGLM_EXPORT void -glmc_quat_rotate_at(mat4 model, const versor q, const vec3 pivot) { +glmc_quat_rotate_at(mat4 model, versor q, vec3 pivot) { glm_quat_rotate_at(model, q, pivot); } CGLM_EXPORT void -glmc_quat_rotate_atm(mat4 m, const versor q, const vec3 pivot) { +glmc_quat_rotate_atm(mat4 m, versor q, vec3 pivot) { glm_quat_rotate_atm(m, q, pivot); } diff --git a/src/sphere.c b/src/sphere.c index 1026ed4..003ef87 100644 --- a/src/sphere.c +++ b/src/sphere.c @@ -10,30 +10,30 @@ CGLM_EXPORT float -glmc_sphere_radii(const vec4 s) { +glmc_sphere_radii(vec4 s) { return glm_sphere_radii(s); } CGLM_EXPORT void -glmc_sphere_transform(const vec4 s, const mat4 m, vec4 dest) { +glmc_sphere_transform(vec4 s, mat4 m, vec4 dest) { glm_sphere_transform(s, m, dest); } CGLM_EXPORT void -glmc_sphere_merge(const vec4 s1, const vec4 s2, vec4 dest) { +glmc_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { glm_sphere_merge(s1, s2, dest); } CGLM_EXPORT bool -glmc_sphere_sphere(const vec4 s1, const vec4 s2) { +glmc_sphere_sphere(vec4 s1, vec4 s2) { return glm_sphere_sphere(s1, s2); } CGLM_EXPORT bool -glmc_sphere_point(const vec4 s, const vec3 point) { +glmc_sphere_point(vec4 s, vec3 point) { return glm_sphere_point(s, point); } diff --git a/src/vec3.c b/src/vec3.c index afc5bbe..14edaf6 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -10,13 +10,13 @@ CGLM_EXPORT void -glmc_vec3(const vec4 v4, vec3 dest) { +glmc_vec3(vec4 v4, vec3 dest) { glm_vec3(v4, dest); } CGLM_EXPORT void -glmc_vec3_copy(const vec3 a, vec3 dest) { +glmc_vec3_copy(vec3 a, vec3 dest) { glm_vec3_copy(a, dest); } @@ -34,31 +34,31 @@ glmc_vec3_one(vec3 v) { CGLM_EXPORT float -glmc_vec3_dot(const vec3 a, const vec3 b) { +glmc_vec3_dot(vec3 a, vec3 b) { return glm_vec3_dot(a, b); } CGLM_EXPORT void -glmc_vec3_cross(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_cross(vec3 a, vec3 b, vec3 dest) { glm_vec3_cross(a, b, dest); } CGLM_EXPORT void -glmc_vec3_crossn(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_crossn(vec3 a, vec3 b, vec3 dest) { glm_vec3_crossn(a, b, dest); } CGLM_EXPORT float -glmc_vec3_norm(const vec3 v) { +glmc_vec3_norm(vec3 v) { return glm_vec3_norm(v); } CGLM_EXPORT void -glmc_vec3_normalize_to(const vec3 v, vec3 dest) { +glmc_vec3_normalize_to(vec3 v, vec3 dest) { glm_vec3_normalize_to(v, dest); } @@ -70,97 +70,97 @@ glmc_vec3_normalize(vec3 v) { CGLM_EXPORT float -glmc_vec3_norm2(const vec3 v) { +glmc_vec3_norm2(vec3 v) { return glm_vec3_norm2(v); } CGLM_EXPORT void -glmc_vec3_add(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_add(vec3 a, vec3 b, vec3 dest) { glm_vec3_add(a, b, dest); } CGLM_EXPORT void -glmc_vec3_adds(const vec3 v, float s, vec3 dest) { +glmc_vec3_adds(vec3 v, float s, vec3 dest) { glm_vec3_adds(v, s, dest); } CGLM_EXPORT void -glmc_vec3_sub(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_sub(vec3 a, vec3 b, vec3 dest) { glm_vec3_sub(a, b, dest); } CGLM_EXPORT void -glmc_vec3_subs(const vec3 v, float s, vec3 dest) { +glmc_vec3_subs(vec3 v, float s, vec3 dest) { glm_vec3_subs(v, s, dest); } CGLM_EXPORT void -glmc_vec3_mul(const vec3 a, const vec3 b, vec3 d) { +glmc_vec3_mul(vec3 a, vec3 b, vec3 d) { glm_vec3_mul(a, b, d); } CGLM_EXPORT void -glmc_vec3_scale(const vec3 v, float s, vec3 dest) { +glmc_vec3_scale(vec3 v, float s, vec3 dest) { glm_vec3_scale(v, s, dest); } CGLM_EXPORT void -glmc_vec3_scale_as(const vec3 v, float s, vec3 dest) { +glmc_vec3_scale_as(vec3 v, float s, vec3 dest) { glm_vec3_scale_as(v, s, dest); } CGLM_EXPORT void -glmc_vec3_div(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_div(vec3 a, vec3 b, vec3 dest) { glm_vec3_div(a, b, dest); } CGLM_EXPORT void -glmc_vec3_divs(const vec3 a, float s, vec3 dest) { +glmc_vec3_divs(vec3 a, float s, vec3 dest) { glm_vec3_divs(a, s, dest); } CGLM_EXPORT void -glmc_vec3_addadd(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_addadd(vec3 a, vec3 b, vec3 dest) { glm_vec3_addadd(a, b, dest); } CGLM_EXPORT void -glmc_vec3_subadd(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_subadd(vec3 a, vec3 b, vec3 dest) { glm_vec3_subadd(a, b, dest); } CGLM_EXPORT void -glmc_vec3_muladd(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_muladd(vec3 a, vec3 b, vec3 dest) { glm_vec3_muladd(a, b, dest); } CGLM_EXPORT void -glmc_vec3_muladds(const vec3 a, float s, vec3 dest) { +glmc_vec3_muladds(vec3 a, float s, vec3 dest) { glm_vec3_muladds(a, s, dest); } CGLM_EXPORT void -glmc_vec3_maxadd(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_maxadd(vec3 a, vec3 b, vec3 dest) { glm_vec3_maxadd(a, b, dest); } CGLM_EXPORT void -glmc_vec3_minadd(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_minadd(vec3 a, vec3 b, vec3 dest) { glm_vec3_minadd(a, b, dest); } @@ -172,67 +172,67 @@ glmc_vec3_negate(vec3 v) { CGLM_EXPORT void -glmc_vec3_negate_to(const vec3 v, vec3 dest) { +glmc_vec3_negate_to(vec3 v, vec3 dest) { glm_vec3_negate_to(v, dest); } CGLM_EXPORT float -glmc_vec3_angle(const vec3 a, const vec3 b) { +glmc_vec3_angle(vec3 a, vec3 b) { return glm_vec3_angle(a, b); } CGLM_EXPORT void -glmc_vec3_rotate(vec3 v, float angle, const vec3 axis) { +glmc_vec3_rotate(vec3 v, float angle, vec3 axis) { glm_vec3_rotate(v, angle, axis); } CGLM_EXPORT void -glmc_vec3_rotate_m4(const mat4 m, const vec3 v, vec3 dest) { +glmc_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest) { glm_vec3_rotate_m4(m, v, dest); } CGLM_EXPORT void -glmc_vec3_rotate_m3(const mat3 m, const vec3 v, vec3 dest) { +glmc_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest) { glm_vec3_rotate_m3(m, v, dest); } CGLM_EXPORT void -glmc_vec3_proj(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_proj(vec3 a, vec3 b, vec3 dest) { glm_vec3_proj(a, b, dest); } CGLM_EXPORT void -glmc_vec3_center(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_center(vec3 a, vec3 b, vec3 dest) { glm_vec3_center(a, b, dest); } CGLM_EXPORT float -glmc_vec3_distance2(const vec3 a, const vec3 b) { +glmc_vec3_distance2(vec3 a, vec3 b) { return glm_vec3_distance2(a, b); } CGLM_EXPORT float -glmc_vec3_distance(const vec3 a, const vec3 b) { +glmc_vec3_distance(vec3 a, vec3 b) { return glm_vec3_distance(a, b); } CGLM_EXPORT void -glmc_vec3_maxv(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_maxv(vec3 a, vec3 b, vec3 dest) { glm_vec3_minv(a, b, dest); } CGLM_EXPORT void -glmc_vec3_minv(const vec3 a, const vec3 b, vec3 dest) { +glmc_vec3_minv(vec3 a, vec3 b, vec3 dest) { glm_vec3_maxv(a, b, dest); } @@ -244,13 +244,13 @@ glmc_vec3_clamp(vec3 v, float minVal, float maxVal) { CGLM_EXPORT void -glmc_vec3_ortho(const vec3 v, vec3 dest) { +glmc_vec3_ortho(vec3 v, vec3 dest) { glm_vec3_ortho(v, dest); } CGLM_EXPORT void -glmc_vec3_lerp(const vec3 from, const vec3 to, float t, vec3 dest) { +glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) { glm_vec3_lerp(from, to, t, dest); } @@ -258,7 +258,7 @@ glmc_vec3_lerp(const vec3 from, const vec3 to, float t, vec3 dest) { CGLM_EXPORT void -glmc_vec3_mulv(const vec3 a, const vec3 b, vec3 d) { +glmc_vec3_mulv(vec3 a, vec3 b, vec3 d) { glm_vec3_mulv(a, b, d); } @@ -270,72 +270,72 @@ glmc_vec3_broadcast(float val, vec3 d) { CGLM_EXPORT bool -glmc_vec3_eq(const vec3 v, float val) { +glmc_vec3_eq(vec3 v, float val) { return glm_vec3_eq(v, val); } CGLM_EXPORT bool -glmc_vec3_eq_eps(const vec3 v, float val) { +glmc_vec3_eq_eps(vec3 v, float val) { return glm_vec3_eq_eps(v, val); } CGLM_EXPORT bool -glmc_vec3_eq_all(const vec3 v) { +glmc_vec3_eq_all(vec3 v) { return glm_vec3_eq_all(v); } CGLM_EXPORT bool -glmc_vec3_eqv(const vec3 a, const vec3 b) { +glmc_vec3_eqv(vec3 a, vec3 b) { return glm_vec3_eqv(a, b); } CGLM_EXPORT bool -glmc_vec3_eqv_eps(const vec3 a, const vec3 b) { +glmc_vec3_eqv_eps(vec3 a, vec3 b) { return glm_vec3_eqv_eps(a, b); } CGLM_EXPORT float -glmc_vec3_max(const vec3 v) { +glmc_vec3_max(vec3 v) { return glm_vec3_max(v); } CGLM_EXPORT float -glmc_vec3_min(const vec3 v) { +glmc_vec3_min(vec3 v) { return glm_vec3_min(v); } CGLM_EXPORT bool -glmc_vec3_isnan(const vec3 v) { +glmc_vec3_isnan(vec3 v) { return glm_vec3_isnan(v); } CGLM_EXPORT bool -glmc_vec3_isinf(const vec3 v) { +glmc_vec3_isinf(vec3 v) { return glm_vec3_isinf(v); } CGLM_EXPORT bool -glmc_vec3_isvalid(const vec3 v) { +glmc_vec3_isvalid(vec3 v) { return glm_vec3_isvalid(v); } CGLM_EXPORT void -glmc_vec3_sign(const vec3 v, vec3 dest) { +glmc_vec3_sign(vec3 v, vec3 dest) { glm_vec3_sign(v, dest); } CGLM_EXPORT void -glmc_vec3_sqrt(const vec3 v, vec3 dest) { +glmc_vec3_sqrt(vec3 v, vec3 dest) { glm_vec3_sqrt(v, dest); } diff --git a/src/vec4.c b/src/vec4.c index 932f4ff..0bb6a6e 100644 --- a/src/vec4.c +++ b/src/vec4.c @@ -10,7 +10,7 @@ CGLM_EXPORT void -glmc_vec4(const vec3 v3, float last, vec4 dest) { +glmc_vec4(vec3 v3, float last, vec4 dest) { glm_vec4(v3, last, dest); } @@ -28,37 +28,37 @@ glmc_vec4_one(vec4 v) { CGLM_EXPORT void -glmc_vec4_copy3(const vec4 v, vec3 dest) { +glmc_vec4_copy3(vec4 v, vec3 dest) { glm_vec4_copy3(v, dest); } CGLM_EXPORT void -glmc_vec4_copy(const vec4 v, vec4 dest) { +glmc_vec4_copy(vec4 v, vec4 dest) { glm_vec4_copy(v, dest); } CGLM_EXPORT void -glmc_vec4_ucopy(const vec4 v, vec4 dest) { +glmc_vec4_ucopy(vec4 v, vec4 dest) { glm_vec4_ucopy(v, dest); } CGLM_EXPORT float -glmc_vec4_dot(const vec4 a, const vec4 b) { +glmc_vec4_dot(vec4 a, vec4 b) { return glm_vec4_dot(a, b); } CGLM_EXPORT float -glmc_vec4_norm(const vec4 v) { +glmc_vec4_norm(vec4 v) { return glm_vec4_norm(v); } CGLM_EXPORT void -glmc_vec4_normalize_to(const vec4 v, vec4 dest) { +glmc_vec4_normalize_to(vec4 v, vec4 dest) { glm_vec4_normalize_to(v, dest); } @@ -70,97 +70,97 @@ glmc_vec4_normalize(vec4 v) { CGLM_EXPORT float -glmc_vec4_norm2(const vec4 v) { +glmc_vec4_norm2(vec4 v) { return glm_vec4_norm2(v); } CGLM_EXPORT void -glmc_vec4_add(const vec4 a, const vec4 b, vec4 dest) { +glmc_vec4_add(vec4 a, vec4 b, vec4 dest) { glm_vec4_add(a, b, dest); } CGLM_EXPORT void -glmc_vec4_adds(const vec4 v, float s, vec4 dest) { +glmc_vec4_adds(vec4 v, float s, vec4 dest) { glm_vec4_adds(v, s, dest); } CGLM_EXPORT void -glmc_vec4_sub(const vec4 a, const vec4 b, vec4 dest) { +glmc_vec4_sub(vec4 a, vec4 b, vec4 dest) { glm_vec4_sub(a, b, dest); } CGLM_EXPORT void -glmc_vec4_subs(const vec4 v, float s, vec4 dest) { +glmc_vec4_subs(vec4 v, float s, vec4 dest) { glm_vec4_subs(v, s, dest); } CGLM_EXPORT void -glmc_vec4_mul(const vec4 a, const vec4 b, vec4 d) { +glmc_vec4_mul(vec4 a, vec4 b, vec4 d) { glm_vec4_mul(a, b, d); } CGLM_EXPORT void -glmc_vec4_scale(const vec4 v, float s, vec4 dest) { +glmc_vec4_scale(vec4 v, float s, vec4 dest) { glm_vec4_scale(v, s, dest); } CGLM_EXPORT void -glmc_vec4_scale_as(const vec4 v, float s, vec4 dest) { +glmc_vec4_scale_as(vec4 v, float s, vec4 dest) { glm_vec4_scale_as(v, s, dest); } CGLM_EXPORT void -glmc_vec4_div(const vec4 a, const vec4 b, vec4 dest) { +glmc_vec4_div(vec4 a, vec4 b, vec4 dest) { glm_vec4_div(a, b, dest); } CGLM_EXPORT void -glmc_vec4_divs(const vec4 v, float s, vec4 dest) { +glmc_vec4_divs(vec4 v, float s, vec4 dest) { glm_vec4_divs(v, s, dest); } CGLM_EXPORT void -glmc_vec4_addadd(const vec4 a, const vec4 b, vec4 dest) { +glmc_vec4_addadd(vec4 a, vec4 b, vec4 dest) { glm_vec4_addadd(a, b, dest); } CGLM_EXPORT void -glmc_vec4_subadd(const vec4 a, const vec4 b, vec4 dest) { +glmc_vec4_subadd(vec4 a, vec4 b, vec4 dest) { glm_vec4_subadd(a, b, dest); } CGLM_EXPORT void -glmc_vec4_muladd(const vec4 a, const vec4 b, vec4 dest) { +glmc_vec4_muladd(vec4 a, vec4 b, vec4 dest) { glm_vec4_muladd(a, b, dest); } CGLM_EXPORT void -glmc_vec4_muladds(const vec4 a, float s, vec4 dest) { +glmc_vec4_muladds(vec4 a, float s, vec4 dest) { glm_vec4_muladds(a, s, dest); } CGLM_EXPORT void -glmc_vec4_maxadd(const vec4 a, const vec4 b, vec4 dest) { +glmc_vec4_maxadd(vec4 a, vec4 b, vec4 dest) { glm_vec4_maxadd(a, b, dest); } CGLM_EXPORT void -glmc_vec4_minadd(const vec4 a, const vec4 b, vec4 dest) { +glmc_vec4_minadd(vec4 a, vec4 b, vec4 dest) { glm_vec4_minadd(a, b, dest); } @@ -172,25 +172,25 @@ glmc_vec4_negate(vec4 v) { CGLM_EXPORT void -glmc_vec4_negate_to(const vec4 v, vec4 dest) { +glmc_vec4_negate_to(vec4 v, vec4 dest) { glm_vec4_negate_to(v, dest); } CGLM_EXPORT float -glmc_vec4_distance(const vec4 a, const vec4 b) { +glmc_vec4_distance(vec4 a, vec4 b) { return glm_vec4_distance(a, b); } CGLM_EXPORT void -glmc_vec4_maxv(const vec4 a, const vec4 b, vec4 dest) { +glmc_vec4_maxv(vec4 a, vec4 b, vec4 dest) { glm_vec4_minv(a, b, dest); } CGLM_EXPORT void -glmc_vec4_minv(const vec4 a, const vec4 b, vec4 dest) { +glmc_vec4_minv(vec4 a, vec4 b, vec4 dest) { glm_vec4_maxv(a, b, dest); } @@ -202,7 +202,7 @@ glmc_vec4_clamp(vec4 v, float minVal, float maxVal) { CGLM_EXPORT void -glmc_vec4_lerp(const vec4 from, const vec4 to, float t, vec4 dest) { +glmc_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest) { glm_vec4_lerp(from, to, t, dest); } @@ -216,7 +216,7 @@ glmc_vec4_cubic(float s, vec4 dest) { CGLM_EXPORT void -glmc_vec4_mulv(const vec4 a, const vec4 b, vec4 d) { +glmc_vec4_mulv(vec4 a, vec4 b, vec4 d) { glm_vec4_mulv(a, b, d); } @@ -228,72 +228,72 @@ glmc_vec4_broadcast(float val, vec4 d) { CGLM_EXPORT bool -glmc_vec4_eq(const vec4 v, float val) { +glmc_vec4_eq(vec4 v, float val) { return glm_vec4_eq(v, val); } CGLM_EXPORT bool -glmc_vec4_eq_eps(const vec4 v, float val) { +glmc_vec4_eq_eps(vec4 v, float val) { return glm_vec4_eq_eps(v, val); } CGLM_EXPORT bool -glmc_vec4_eq_all(const vec4 v) { +glmc_vec4_eq_all(vec4 v) { return glm_vec4_eq_all(v); } CGLM_EXPORT bool -glmc_vec4_eqv(const vec4 a, const vec4 b) { +glmc_vec4_eqv(vec4 a, vec4 b) { return glm_vec4_eqv(a, b); } CGLM_EXPORT bool -glmc_vec4_eqv_eps(const vec4 a, const vec4 b) { +glmc_vec4_eqv_eps(vec4 a, vec4 b) { return glm_vec4_eqv_eps(a, b); } CGLM_EXPORT float -glmc_vec4_max(const vec4 v) { +glmc_vec4_max(vec4 v) { return glm_vec4_max(v); } CGLM_EXPORT float -glmc_vec4_min(const vec4 v) { +glmc_vec4_min(vec4 v) { return glm_vec4_min(v); } CGLM_EXPORT bool -glmc_vec4_isnan(const vec4 v) { +glmc_vec4_isnan(vec4 v) { return glm_vec4_isnan(v); } CGLM_EXPORT bool -glmc_vec4_isinf(const vec4 v) { +glmc_vec4_isinf(vec4 v) { return glm_vec4_isinf(v); } CGLM_EXPORT bool -glmc_vec4_isvalid(const vec4 v) { +glmc_vec4_isvalid(vec4 v) { return glm_vec4_isvalid(v); } CGLM_EXPORT void -glmc_vec4_sign(const vec4 v, vec4 dest) { +glmc_vec4_sign(vec4 v, vec4 dest) { glm_vec4_sign(v, dest); } CGLM_EXPORT void -glmc_vec4_sqrt(const vec4 v, vec4 dest) { +glmc_vec4_sqrt(vec4 v, vec4 dest) { glm_vec4_sqrt(v, dest); } From d232ab786576d0a6ccb0ab101f312eab8533027c Mon Sep 17 00:00:00 2001 From: yushli Date: Tue, 30 Apr 2019 14:47:20 +0800 Subject: [PATCH 270/292] Update quat.h fix typo --- include/cglm/quat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index e6ef0f4..55d1f53 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -233,7 +233,7 @@ glm_quat_normalize_to(const versor q, versor dest) { dot = glm_vec4_norm2(q); if (dot <= 0.0f) { - glm_quat_identity(q); + glm_quat_identity(dest); return; } From 892a7c7dcea88fa3e36f0929376f8b03caa43f7b Mon Sep 17 00:00:00 2001 From: acoto87 Date: Tue, 30 Apr 2019 22:08:17 -0500 Subject: [PATCH 271/292] - add mat3, mat4, sphere.h --- include/cglm/cglms.h | 3 ++ include/cglm/structs/mat3.h | 57 +++++++++++++++++++++ include/cglm/structs/mat4.h | 80 ++++++++++++++++++++++++++++++ include/cglm/structs/sphere.h | 93 +++++++++++++++++++++++++++++++++++ include/cglm/structs/vec4.h | 7 --- 5 files changed, 233 insertions(+), 7 deletions(-) create mode 100644 include/cglm/structs/mat3.h create mode 100644 include/cglm/structs/mat4.h create mode 100644 include/cglm/structs/sphere.h diff --git a/include/cglm/cglms.h b/include/cglm/cglms.h index 9f00dc8..67dbfa4 100644 --- a/include/cglm/cglms.h +++ b/include/cglm/cglms.h @@ -15,6 +15,9 @@ extern "C" { #include "types-struct.h" #include "structs/vec3.h" #include "structs/vec4.h" +#include "structs/mat3.h" +#include "structs/mat4.h" +#include "structs/sphere.h" #ifdef __cplusplus } diff --git a/include/cglm/structs/mat3.h b/include/cglm/structs/mat3.h new file mode 100644 index 0000000..c1d8e48 --- /dev/null +++ b/include/cglm/structs/mat3.h @@ -0,0 +1,57 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE vec3s glm_mat3_mulv(mat3 m, vec3s v); + CGLM_INLINE float glm_mat3_rmc(vec3s r, mat3 m, vec3s c); + */ + +#ifndef cglm_mat3s_h +#define cglm_mat3s_h + +#include "../common.h" +#include "../types-struct.h" +#include "../mat3.h" +#include "vec3.h" + +/*! + * @brief multiply mat3 with vec3 (column vector) and store in dest vector + * + * @param[in] m mat3 (left) + * @param[in] v vec3 (right, column vector) + * returns vec3 (result, column vector) + */ +CGLM_INLINE +vec3s +glms_mat3_mulv(mat3 m, vec3s v) { + vec3s r; + glm_mat3_mulv(m, v.raw, r.raw); + return r; +} + +/*! + * @brief helper for R (row vector) * M (matrix) * C (column vector) + * + * rmc stands for Row * Matrix * Column + * + * the result is scalar because R * M = Matrix1x3 (row vector), + * then Matrix1x3 * Vec3 (column vector) = Matrix1x1 (Scalar) + * + * @param[in] r row vector or matrix1x3 + * @param[in] m matrix3x3 + * @param[in] c column vector or matrix3x1 + * + * @return scalar value e.g. Matrix1x1 + */ +CGLM_INLINE +float +glms_mat3_rmc(vec3s r, mat3 m, vec3s c) { + return glm_mat3_rmc(r.raw, m, c.raw); +} + +#endif /* cglm_mat3s_h */ diff --git a/include/cglm/structs/mat4.h b/include/cglm/structs/mat4.h new file mode 100644 index 0000000..fc785d7 --- /dev/null +++ b/include/cglm/structs/mat4.h @@ -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 + */ + +/*! + * Most of functions in this header are optimized manually with SIMD + * if available. You dont need to call/incude SIMD headers manually + */ + +/* + Functions: + CGLM_INLINE void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); + CGLM_INLINE void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest); + CGLM_INLINE float glm_mat4_rmc(vec4 r, mat4 m, vec4 c); + */ + +#ifndef cglm_mats_h +#define cglm_mats_h + +#include "../common.h" +#include "../types-struct.h" +#include "../mat4.h" +#include "vec4.h" +#include "vec3.h" + +/*! + * @brief multiply mat4 with vec4 (column vector) and store in dest vector + * + * @param[in] m mat4 (left) + * @param[in] v vec4 (right, column vector) + * returns vec4 (result, column vector) + */ +CGLM_INLINE +vec4s +glms_mat4_mulv(mat4 m, vec4s v) { + vec4s r; + glm_mat4_mulv(m, v.raw, r.raw); + return r; +} + +/*! + * @brief multiply vector with mat4 + * + * @param[in] m mat4(affine transform) + * @param[in] v vec3 + * @param[in] last 4th item to make it vec4 + * returns result vector (vec3) + */ +CGLM_INLINE +vec3s +glms_mat4_mulv3(mat4 m, vec3s v, float last) { + vec3s r; + glm_mat4_mulv3(m, v.raw, last, r.raw); + return r; +} + +/*! + * @brief helper for R (row vector) * M (matrix) * C (column vector) + * + * rmc stands for Row * Matrix * Column + * + * the result is scalar because R * M = Matrix1x4 (row vector), + * then Matrix1x4 * Vec4 (column vector) = Matrix1x1 (Scalar) + * + * @param[in] r row vector or matrix1x4 + * @param[in] m matrix4x4 + * @param[in] c column vector or matrix4x1 + * + * @return scalar value e.g. B(s) + */ +CGLM_INLINE +float +glms_mat4_rmc(vec4s r, mat4 m, vec4s c) { + return glm_mat4_rmc(r.raw, m, c.raw); +} + +#endif /* cglm_mats_h */ diff --git a/include/cglm/structs/sphere.h b/include/cglm/structs/sphere.h new file mode 100644 index 0000000..b336c3b --- /dev/null +++ b/include/cglm/structs/sphere.h @@ -0,0 +1,93 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_spheres_h +#define cglm_spheres_h + +#include "../common.h" +#include "../types-struct.h" +#include "../mat4.h" +#include "../sphere.h" + +/* + Sphere Representation in cglm: [center.x, center.y, center.z, radii] + + You could use this representation or you can convert it to vec4 before call + any function + */ + +/*! + * @brief helper for getting sphere radius + * + * @param[in] s sphere + * + * @return returns radii + */ +CGLM_INLINE +float +glms_sphere_radii(vec4s s) { + return glm_sphere_radii(s.raw); +} + +/*! + * @brief apply transform to sphere, it is just wrapper for glm_mat4_mulv3 + * + * @param[in] s sphere + * @param[in] m transform matrix + * @returns transformed sphere + */ +CGLM_INLINE +vec4s +glms_sphere_transform(vec4s s, mat4 m) { + vec4s r; + glm_sphere_transform(s.raw, m, r.raw); + return r; +} + +/*! + * @brief merges two spheres and creates a new one + * + * two sphere must be in same space, for instance if one in world space then + * the other must be in world space too, not in local space. + * + * @param[in] s1 sphere 1 + * @param[in] s2 sphere 2 + * returns merged/extended sphere + */ +CGLM_INLINE +vec4s +glms_sphere_merge(vec4s s1, vec4s s2) { + vec4s r; + glm_sphere_merge(s1.raw, s2.raw, r.raw); + return r; +} + +/*! + * @brief check if two sphere intersects + * + * @param[in] s1 sphere + * @param[in] s2 other sphere + */ +CGLM_INLINE +bool +glms_sphere_sphere(vec4s s1, vec4s s2) { + return glm_sphere_sphere(s1.raw, s2.raw); +} + +/*! + * @brief check if sphere intersects with point + * + * @param[in] s sphere + * @param[in] point point + */ +CGLM_INLINE +bool +glms_sphere_point(vec4s s, vec3s point) { + return glm_sphere_point(s.raw, point.raw); +} + +#endif /* cglm_spheres_h */ diff --git a/include/cglm/structs/vec4.h b/include/cglm/structs/vec4.h index c0a79c3..c8ec509 100644 --- a/include/cglm/structs/vec4.h +++ b/include/cglm/structs/vec4.h @@ -8,10 +8,6 @@ #ifndef cglm_vec4s_h #define cglm_vec4s_h -#ifdef __cplusplus -extern "C" { -#endif - #include "../common.h" #include "../types-struct.h" #include "../util.h" @@ -255,7 +251,4 @@ glms_vec4_lerp(vec4s from, vec4s to, float t) { return r; } -#ifdef __cplusplus -} -#endif #endif /* cglm_vec4s_h */ From 3ff902de9ccaff2a6d8660ff2a5a8254bf9bb3c3 Mon Sep 17 00:00:00 2001 From: acoto87 Date: Fri, 3 May 2019 22:48:13 -0500 Subject: [PATCH 272/292] add mat3 and mat4 implementation --- include/cglm/structs/mat3.h | 263 +++++++++++++++++++++- include/cglm/structs/mat4.h | 427 ++++++++++++++++++++++++++++++++++-- include/cglm/types-struct.h | 60 ++++- 3 files changed, 728 insertions(+), 22 deletions(-) diff --git a/include/cglm/structs/mat3.h b/include/cglm/structs/mat3.h index c1d8e48..63fe7c6 100644 --- a/include/cglm/structs/mat3.h +++ b/include/cglm/structs/mat3.h @@ -6,9 +6,29 @@ */ /* + Macros: + GLMS_MAT3_IDENTITY_INIT + GLMS_MAT3_ZERO_INIT + GLMS_MAT3_IDENTITY + GLMS_MAT3_ZERO + Functions: - CGLM_INLINE vec3s glm_mat3_mulv(mat3 m, vec3s v); - CGLM_INLINE float glm_mat3_rmc(vec3s r, mat3 m, vec3s c); + CGLM_INLINE mat3s glms_mat3_copy(mat3s mat); + CGLM_INLINE mat3s glms_mat3_identity(); + CGLM_INLINE void glms_mat3_identity_array(mat3s * __restrict mat, size_t count); + CGLM_INLINE mat3s glms_mat3_zero(); + CGLM_INLINE mat3s glms_mat3_mul(mat3s m1, mat3s m2); + CGLM_INLINE mat3s glms_mat3_transpose_to(mat3s m); + CGLM_INLINE ma3s glms_mat3_transpose(mat3s m); + CGLM_INLINE vec3s glms_mat3_mulv(mat3s m, vec3s v); + CGLM_INLINE float glms_mat3_trace(mat3s m); + CGLM_INLINE versor glms_mat3_quat(mat3s m); + CGLM_INLINE mat3s glms_mat3_scale(mat3s m, float s); + CGLM_INLINE float glms_mat3_det(mat3s mat); + CGLM_INLINE mat3s glms_mat3_inv(mat3s mat); + 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); */ #ifndef cglm_mat3s_h @@ -19,21 +39,250 @@ #include "../mat3.h" #include "vec3.h" +#define GLMS_MAT3_IDENTITY_INIT {1.0f, 0.0f, 0.0f, \ + 0.0f, 1.0f, 0.0f, \ + 0.0f, 0.0f, 1.0f} +#define GLMS_MAT3_ZERO_INIT {0.0f, 0.0f, 0.0f, \ + 0.0f, 0.0f, 0.0f, \ + 0.0f, 0.0f, 0.0f} + +/* for C only */ +#define GLMS_MAT3_IDENTITY ((mat3s)GLMS_MAT3_IDENTITY_INIT) +#define GLMS_MAT3_ZERO ((mat3s)GLMS_MAT3_ZERO_INIT) + +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @returns destination + */ +CGLM_INLINE +mat3s +glms_mat3_copy(mat3s mat) { + mat3s r; + glm_mat3_copy(mat.raw, r.raw); + return r; +} + +/*! + * @brief make given matrix identity. It is identical with below, + * but it is more easy to do that with this func especially for members + * e.g. glm_mat3_identity(aStruct->aMatrix); + * + * @code + * glm_mat3_copy(GLM_MAT3_IDENTITY, mat); // C only + * + * // or + * mat3 mat = GLM_MAT3_IDENTITY_INIT; + * @endcode + * + * @returns destination + */ +CGLM_INLINE +mat3s +glms_mat3_identity() { + mat3s r; + glm_mat3_identity(r.raw); + return r; +} + +/*! + * @brief make given matrix array's each element identity matrix + * + * @param[in, out] mat matrix array (must be aligned (16/32) + * if alignment is not disabled) + * + * @param[in] count count of matrices + */ +CGLM_INLINE +void +glms_mat3_identity_array(mat3s * __restrict mat, size_t count) { + CGLM_ALIGN_MAT mat3s t = GLMS_MAT3_IDENTITY_INIT; + size_t i; + + for (i = 0; i < count; i++) { + glm_mat3_copy(t.raw, mat[i].raw); + } +} + +/*! + * @brief make given matrix zero. + * + * @returns matrix + */ +CGLM_INLINE +mat3s +glms_mat3_zero() { + mat3s r; + glm_mat3_zero(r.raw); + return r; +} + +/*! + * @brief multiply m1 and m2 to dest + * + * m1, m2 and dest matrices can be same matrix, it is possible to write this: + * + * @code + * mat3 m = GLM_MAT3_IDENTITY_INIT; + * glm_mat3_mul(m, m, m); + * @endcode + * + * @param[in] m1 left matrix + * @param[in] m2 right matrix + * @returns destination matrix + */ +CGLM_INLINE +mat3s +glms_mat3_mul(mat3s m1, mat3s m2) { + mat3s r; + glm_mat3_mul(m1.raw, m2.raw, r.raw); + return r; +} + +/*! + * @brief transpose mat3 and store in dest + * + * source matrix will not be transposed unless dest is m + * + * @param[in] m matrix + * @param[out] dest result + */ +CGLM_INLINE +mat3s +glms_mat3_transpose_to(mat3s m) { + mat3s r; + glm_mat3_transpose_to(m.raw, r.raw); + return r; +} + +/*! + * @brief tranpose mat3 and store result in same matrix + * + * @param[in, out] m source and dest + */ +CGLM_INLINE +mat3s +glms_mat3_transpose(mat3s m) { + glm_mat3_transpose(m.raw); + return m; +} + /*! * @brief multiply mat3 with vec3 (column vector) and store in dest vector * * @param[in] m mat3 (left) * @param[in] v vec3 (right, column vector) - * returns vec3 (result, column vector) + * @returns vec3 (result, column vector) */ CGLM_INLINE vec3s -glms_mat3_mulv(mat3 m, vec3s v) { +glms_mat3_mulv(mat3s m, vec3s v) { vec3s r; - glm_mat3_mulv(m, v.raw, r.raw); + glm_mat3_mulv(m.raw, v.raw, r.raw); return r; } +/*! + * @brief trace of matrix + * + * sum of the elements on the main diagonal from upper left to the lower right + * + * @param[in] m matrix + */ +CGLM_INLINE +float +glms_mat3_trace(mat3s m) { + return glm_mat3_trace(m.raw); +} + +/*! + * @brief convert mat3 to quaternion + * + * @param[in] m rotation matrix + * @returns destination quaternion + */ +CGLM_INLINE +versors +glms_mat3_quat(mat3s m) { + versors r; + glm_mat3_quat(m.raw, r.raw); + return r; +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in] m matrix + * @param[in] s scalar + * @returns scaled matrix + */ +CGLM_INLINE +mat3s +glms_mat3_scale(mat3s m, float s) { + glm_mat3_scale(m.raw, s); + return m; +} + +/*! + * @brief mat3 determinant + * + * @param[in] mat matrix + * + * @return determinant + */ +CGLM_INLINE +float +glms_mat3_det(mat3s mat) { + return glm_mat3_det(mat.raw); +} + +/*! + * @brief inverse mat3 and store in dest + * + * @param[in] mat matrix + * @returns inverse matrix + */ +CGLM_INLINE +mat3s +glms_mat3_inv(mat3s mat) { + mat3s r; + glm_mat3_inv(mat.raw, r.raw); + return r; +} + +/*! + * @brief swap two matrix columns + * + * @param[in] mat matrix + * @param[in] col1 col1 + * @param[in] col2 col2 + * @returns matrix + */ +CGLM_INLINE +mat3s +glms_mat3_swap_col(mat3s mat, int col1, int col2) { + glm_mat3_swap_col(mat.raw, col1, col2); + return mat; +} + +/*! + * @brief swap two matrix rows + * + * @param[in] mat matrix + * @param[in] row1 row1 + * @param[in] row2 row2 + * @returns matrix + */ +CGLM_INLINE +mat3s +glms_mat3_swap_row(mat3s mat, int row1, int row2) { + glm_mat3_swap_row(mat.raw, row1, row2); + return mat; +} + /*! * @brief helper for R (row vector) * M (matrix) * C (column vector) * @@ -50,8 +299,8 @@ glms_mat3_mulv(mat3 m, vec3s v) { */ CGLM_INLINE float -glms_mat3_rmc(vec3s r, mat3 m, vec3s c) { - return glm_mat3_rmc(r.raw, m, c.raw); +glms_mat3_rmc(vec3s r, mat3s m, vec3s c) { + return glm_mat3_rmc(r.raw, m.raw, c.raw); } #endif /* cglm_mat3s_h */ diff --git a/include/cglm/structs/mat4.h b/include/cglm/structs/mat4.h index fc785d7..a61f18d 100644 --- a/include/cglm/structs/mat4.h +++ b/include/cglm/structs/mat4.h @@ -11,14 +11,42 @@ */ /* + Macros: + GLMS_MAT4_IDENTITY_INIT + GLMS_MAT4_ZERO_INIT + GLMS_MAT4_IDENTITY + GLMS_MAT4_ZERO + Functions: - CGLM_INLINE void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); - CGLM_INLINE void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest); - CGLM_INLINE float glm_mat4_rmc(vec4 r, mat4 m, vec4 c); + CGLM_INLINE mat4s glms_mat4_ucopy(mat4s mat); + CGLM_INLINE mat4s glms_mat4_copy(mat4s mat); + CGLM_INLINE mat4s glms_mat4_identity(); + CGLM_INLINE void glms_mat4_identity_array(mat4s * __restrict mat, size_t count); + CGLM_INLINE mat4s glms_mat4_zero(); + 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_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); + CGLM_INLINE float glms_mat4_trace(mat4s m); + CGLM_INLINE float glms_mat4_trace3(mat4s m); + CGLM_INLINE versors glms_mat4_quat(mat4s m); + CGLM_INLINE vec3s glms_mat4_mulv3(mat4s m, vec3s v, float last); + CGLM_INLINE mat4s glms_mat4_transpose_to(mat4s m); + CGLM_INLINE mat4s glms_mat4_transpose(mat4s m); + CGLM_INLINE mat4s glms_mat4_scale_p(mat4s m, float s); + CGLM_INLINE mat4s glms_mat4_scale(mat4s m, float s); + CGLM_INLINE float glms_mat4_det(mat4s mat); + CGLM_INLINE mat4s glms_mat4_inv(mat4s mat); + CGLM_INLINE mat4s glms_mat4_inv_fast(mat4s mat); + 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); */ -#ifndef cglm_mats_h -#define cglm_mats_h +#ifndef cglm_mat4s_h +#define cglm_mat4s_h #include "../common.h" #include "../types-struct.h" @@ -26,18 +54,250 @@ #include "vec4.h" #include "vec3.h" +#define GLMS_MAT4_IDENTITY_INIT {{1.0f, 0.0f, 0.0f, 0.0f}, \ + {0.0f, 1.0f, 0.0f, 0.0f}, \ + {0.0f, 0.0f, 1.0f, 0.0f}, \ + {0.0f, 0.0f, 0.0f, 1.0f}} + +#define GLMS_MAT4_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}, \ + {0.0f, 0.0f, 0.0f, 0.0f}} + +/* for C only */ +#define GLMS_MAT4_IDENTITY ((mat4)GLMS_MAT4_IDENTITY_INIT) +#define GLMS_MAT4_ZERO ((mat4)GLMS_MAT4_ZERO_INIT) + +/*! + * @brief copy all members of [mat] to [dest] + * + * matrix may not be aligned, u stands for unaligned, this may be useful when + * copying a matrix from external source e.g. asset importer... + * + * @param[in] mat source + * @returns destination + */ +CGLM_INLINE +mat4s +glms_mat4_ucopy(mat4s mat) { + mat4s r; + glm_mat4_ucopy(mat.raw, r.raw); + return r; +} + +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @returns destination + */ +CGLM_INLINE +mat4s +glms_mat4_copy(mat4s mat) { + mat4s r; + glm_mat4_copy(mat.raw, r.raw); + return r; +} + +/*! + * @brief make given matrix identity. It is identical with below, + * but it is more easy to do that with this func especially for members + * e.g. glm_mat4_identity(aStruct->aMatrix); + * + * @code + * glm_mat4_copy(GLM_MAT4_IDENTITY, mat); // C only + * + * // or + * mat4 mat = GLM_MAT4_IDENTITY_INIT; + * @endcode + * + * @retuns destination + */ +CGLM_INLINE +mat4s +glms_mat4_identity() { + mat4s r; + glm_mat4_identity(r.raw); + return r; +} + +/*! + * @brief make given matrix array's each element identity matrix + * + * @param[in, out] mat matrix array (must be aligned (16/32) + * if alignment is not disabled) + * + * @param[in] count count of matrices + */ +CGLM_INLINE +void +glms_mat4_identity_array(mat4s * __restrict mat, size_t count) { + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; + size_t i; + + for (i = 0; i < count; i++) { + glm_mat4_copy(t.raw, mat[i].raw); + } +} + +/*! + * @brief make given matrix zero. + * + * @returns matrix + */ +CGLM_INLINE +mat4s +glms_mat4_zero() { + mat4s r; + glm_mat4_zero(r.raw); + return r; +} + +/*! + * @brief copy upper-left of mat4 to mat3 + * + * @param[in] mat source + * @returns destination + */ +CGLM_INLINE +mat3s +glms_mat4_pick3(mat4s mat) { + mat3s r; + glm_mat4_pick3(mat.raw, r.raw); + return r; +} + +/*! + * @brief copy upper-left of mat4 to mat3 (transposed) + * + * the postfix t stands for transpose + * + * @param[in] mat source + * @returns destination + */ +CGLM_INLINE +mat3s +glms_mat4_pick3t(mat4s mat) { + mat3s r; + glm_mat4_pick3t(mat.raw, r.raw); + return r; +} + +/*! + * @brief copy mat3 to mat4's upper-left + * + * @param[in] mat source + * @returns destination + */ +CGLM_INLINE +mat4s +glms_mat4_ins3(mat3s mat) { + mat4s r; + glm_mat4_ins3(mat.raw, r.raw); + return r; +} + +/*! + * @brief multiply m1 and m2 to dest + * + * m1, m2 and dest matrices can be same matrix, it is possible to write this: + * + * @code + * mat4 m = GLM_MAT4_IDENTITY_INIT; + * glm_mat4_mul(m, m, m); + * @endcode + * + * @param[in] m1 left matrix + * @param[in] m2 right matrix + * @returns destination matrix + */ +CGLM_INLINE +mat4s +glms_mat4_mul(mat4s m1, mat4s m2) { + mat4s r; + glm_mat4_mul(m1.raw, m2.raw, r.raw); + return r; +} + +/*! + * @brief mupliply N mat4 matrices and store result in dest + * + * this function lets you multiply multiple (more than two or more...) matrices + *

multiplication will be done in loop, this may reduce instructions + * size but if len is too small then compiler may unroll whole loop, + * usage: + * @code + * mat m1, m2, m3, m4, res; + * + * glm_mat4_mulN((mat4 *[]){&m1, &m2, &m3, &m4}, 4, res); + * @endcode + * + * @warning matrices parameter is pointer array not mat4 array! + * + * @param[in] matrices mat4 * array + * @param[in] len matrices count + * @returns result + */ +CGLM_INLINE +mat4s +glms_mat4_mulN(mat4s * __restrict matrices[], uint32_t len) { + mat4s r; + glm_mat4_mulN(matrices, len, r.raw); + return r; +} + /*! * @brief multiply mat4 with vec4 (column vector) and store in dest vector * * @param[in] m mat4 (left) * @param[in] v vec4 (right, column vector) - * returns vec4 (result, column vector) + * @returns vec4 (result, column vector) */ CGLM_INLINE vec4s -glms_mat4_mulv(mat4 m, vec4s v) { +glms_mat4_mulv(mat4s m, vec4s v) { vec4s r; - glm_mat4_mulv(m, v.raw, r.raw); + glm_mat4_mulv(m.raw, v.raw, r.raw); + return r; +} + +/*! + * @brief trace of matrix + * + * sum of the elements on the main diagonal from upper left to the lower right + * + * @param[in] m matrix + */ +CGLM_INLINE +float +glms_mat4_trace(mat4s m) { + return glm_mat4_trace(m.raw); +} + +/*! + * @brief trace of matrix (rotation part) + * + * sum of the elements on the main diagonal from upper left to the lower right + * + * @param[in] m matrix + */ +CGLM_INLINE +float +glms_mat4_trace3(mat4s m) { + return glm_mat4_trace3(m.raw); +} + +/*! + * @brief convert mat4's rotation part to quaternion + * + * @param[in] m affine matrix + * @returns destination quaternion + */ +CGLM_INLINE +versors +glms_mat4_quat(mat4s m) { + versors r; + glm_mat4_quat(m.raw, r.raw); return r; } @@ -47,16 +307,154 @@ glms_mat4_mulv(mat4 m, vec4s v) { * @param[in] m mat4(affine transform) * @param[in] v vec3 * @param[in] last 4th item to make it vec4 - * returns result vector (vec3) + * @returns result vector (vec3) */ CGLM_INLINE vec3s -glms_mat4_mulv3(mat4 m, vec3s v, float last) { +glms_mat4_mulv3(mat4s m, vec3s v, float last) { vec3s r; - glm_mat4_mulv3(m, v.raw, last, r.raw); + glm_mat4_mulv3(m.raw, v.raw, last, r.raw); return r; } +/*! + * @brief transpose mat4 and store in dest + * + * source matrix will not be transposed unless dest is m + * + * @param[in] m matrix + * @returns result + */ +CGLM_INLINE +mat4s +glms_mat4_transpose_to(mat4s m) { + mat4s r; + glm_mat4_transpose_to(m.raw, r.raw); + return r; +} + +/*! + * @brief tranpose mat4 and store result in same matrix + * + * @param[in] m source + * @returns result + */ +CGLM_INLINE +mat4s +glms_mat4_transpose(mat4s m) { + glm_mat4_transpose(m.raw); + return m; +} + +/*! + * @brief scale (multiply with scalar) matrix without simd optimization + * + * multiply matrix with scalar + * + * @param[in] m matrix + * @param[in] s scalar + * @returns matrix + */ +CGLM_INLINE +mat4s +glms_mat4_scale_p(mat4s m, float s) { + glm_mat4_scale_p(m.raw, s); + return m; +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in] m matrix + * @param[in] s scalar + * @returns matrix + */ +CGLM_INLINE +mat4s +glms_mat4_scale(mat4s m, float s) { + glm_mat4_scale(m.raw, s); + return m; +} + +/*! + * @brief mat4 determinant + * + * @param[in] mat matrix + * + * @return determinant + */ +CGLM_INLINE +float +glms_mat4_det(mat4s mat) { + return glm_mat4_det(mat.raw); +} + +/*! + * @brief inverse mat4 and store in dest + * + * @param[in] mat matrix + * @returns inverse matrix + */ +CGLM_INLINE +mat4s +glms_mat4_inv(mat4s mat) { + mat4s r; + glm_mat4_inv(mat.raw, r.raw); + return r; +} + +/*! + * @brief inverse mat4 and store in dest + * + * this func uses reciprocal approximation without extra corrections + * e.g Newton-Raphson. this should work faster than normal, + * to get more precise use glm_mat4_inv version. + * + * NOTE: You will lose precision, glm_mat4_inv is more accurate + * + * @param[in] mat matrix + * @returns inverse matrix + */ +CGLM_INLINE +mat4s +glms_mat4_inv_fast(mat4s mat) { + mat4s r; + glm_mat4_inv_fast(mat.raw, r.raw); + return r; +} + +/*! + * @brief swap two matrix columns + * + * @param[in] mat matrix + * @param[in] col1 col1 + * @param[in] col2 col2 + * @returns matrix + */ +CGLM_INLINE +mat4s +glms_mat4_swap_col(mat4s mat, int col1, int col2) { + glm_mat4_swap_col(mat.raw, col1, col2); + return mat; +} + +/*! + * @brief swap two matrix rows + * + * @param[in] mat matrix + * @param[in] row1 row1 + * @param[in] row2 row2 + * @returns matrix + */ +CGLM_INLINE +mat4s +glms_mat4_swap_row(mat4s mat, int row1, int row2) { + glm_mat4_swap_row(mat.raw, row1, row2); + return mat; +} + /*! * @brief helper for R (row vector) * M (matrix) * C (column vector) * @@ -73,8 +471,9 @@ glms_mat4_mulv3(mat4 m, vec3s v, float last) { */ CGLM_INLINE float -glms_mat4_rmc(vec4s r, mat4 m, vec4s c) { - return glm_mat4_rmc(r.raw, m, c.raw); +glms_mat4_rmc(vec4s r, mat4s m, vec4s c) { + return glm_mat4_rmc(r.raw, m.raw, c.raw); } -#endif /* cglm_mats_h */ +#endif /* cglm_mat4s_h */ + \ No newline at end of file diff --git a/include/cglm/types-struct.h b/include/cglm/types-struct.h index 27e04fe..13431aa 100644 --- a/include/cglm/types-struct.h +++ b/include/cglm/types-struct.h @@ -10,7 +10,7 @@ #include "types.h" -typedef union CGLM_ALIGN_IF(16) vec3s { +typedef union vec3s { #ifndef CGLM_NO_ANONYMOUS_STRUCT struct { float x; @@ -33,4 +33,62 @@ typedef union CGLM_ALIGN_IF(16) vec4s { vec4 raw; } vec4s; +typedef vec4s versors; + +typedef union mat3s { +#ifndef CGLM_NO_ANONYMOUS_STRUCT + struct { + float m00; + float m01; + float m02; + float m10; + float m11; + float m12; + float m20; + float m21; + float m22; + }; + struct { + vec3s col0; + vec3s col1; + vec3s col2; + }; +#endif + mat3 raw; +} mat3s; + +#ifdef __AVX__ +typedef union CGLM_ALIGN_IF(32) mat4s { +#else +typedef union CGLM_ALIGN_IF(16) mat4s { +#endif +#ifndef CGLM_NO_ANONYMOUS_STRUCT + struct { + float m00; + float m01; + float m02; + float m03; + float m10; + float m11; + float m12; + float m13; + float m20; + float m21; + float m22; + float m23; + float m30; + float m31; + float m32; + float m33; + }; + struct { + vec4s col0; + vec4s col1; + vec4s col2; + vec4s col3; + }; +#endif + mat4 raw; +} mat4s; + #endif /* cglm_types_struct_h */ From bc1969ab75b47d7dac9e11f387a195b6fcaa41e1 Mon Sep 17 00:00:00 2001 From: acoto87 Date: Tue, 7 May 2019 16:16:00 -0500 Subject: [PATCH 273/292] - Changes in `mat3s` and `mat4s` types. - Added `ivec3s` type - Struct implementation of: affine.h, box.h, color.h, curve.h, frutum.h, io.h, plane.h, project.h - Deleted `glms_mat3_transpose_to` and `glms_mat4_transpose_to` - Bug fixes in mat4.h --- include/cglm/frustum.h | 2 +- include/cglm/plane.h | 2 +- include/cglm/structs/affine.h | 343 +++++++++++++++++++++++++++++++++ include/cglm/structs/box.h | 285 +++++++++++++++++++++++++++ include/cglm/structs/color.h | 27 +++ include/cglm/structs/curve.h | 40 ++++ include/cglm/structs/frustum.h | 240 +++++++++++++++++++++++ include/cglm/structs/io.h | 100 ++++++++++ include/cglm/structs/mat3.h | 17 -- include/cglm/structs/mat4.h | 52 ++--- include/cglm/structs/plane.h | 40 ++++ include/cglm/structs/project.h | 104 ++++++++++ include/cglm/structs/sphere.h | 2 +- include/cglm/types-struct.h | 51 ++--- 14 files changed, 1223 insertions(+), 82 deletions(-) create mode 100644 include/cglm/structs/affine.h create mode 100644 include/cglm/structs/box.h create mode 100644 include/cglm/structs/color.h create mode 100644 include/cglm/structs/curve.h create mode 100644 include/cglm/structs/frustum.h create mode 100644 include/cglm/structs/io.h create mode 100644 include/cglm/structs/plane.h create mode 100644 include/cglm/structs/project.h diff --git a/include/cglm/frustum.h b/include/cglm/frustum.h index 78b39d2..5aa3c17 100644 --- a/include/cglm/frustum.h +++ b/include/cglm/frustum.h @@ -65,7 +65,7 @@ * Exracted planes order: [left, right, bottom, top, near, far] * * @param[in] m matrix (see brief) - * @param[out] dest exracted view frustum planes (see brief) + * @param[out] dest extracted view frustum planes (see brief) */ CGLM_INLINE void diff --git a/include/cglm/plane.h b/include/cglm/plane.h index 48fe879..7a5291d 100644 --- a/include/cglm/plane.h +++ b/include/cglm/plane.h @@ -25,7 +25,7 @@ /*! * @brief normalizes a plane * - * @param[in, out] plane pnale to normalize + * @param[in, out] plane plane to normalize */ CGLM_INLINE void diff --git a/include/cglm/structs/affine.h b/include/cglm/structs/affine.h new file mode 100644 index 0000000..6f8be48 --- /dev/null +++ b/include/cglm/structs/affine.h @@ -0,0 +1,343 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_translate(mat4s m, vec3s v); + CGLM_INLINE mat4s glms_translate_x(mat4s m, float x); + CGLM_INLINE mat4s glms_translate_y(mat4s m, float y); + CGLM_INLINE mat4s glms_translate_z(mat4s m, float z); + CGLM_INLINE mat4s glms_translate_make(vec3s v); + CGLM_INLINE mat4s glms_scale_to(mat4s m, vec3s v); + CGLM_INLINE mat4s glms_scale_make(vec3s v); + CGLM_INLINE mat4s glms_scale(mat4s m, vec3s v); + CGLM_INLINE mat4s glms_scale_uni(mat4s m, float s); + CGLM_INLINE mat4s glmx_rotate_x(mat4s m, float angle); + CGLM_INLINE mat4s glms_rotate_y(mat4s m, float angle); + CGLM_INLINE mat4s glms_rotate_z(mat4s m, float angle); + 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 vec3s glms_decompose_scalev(mat4s m); + CGLM_INLINE bool glms_uniscaled(mat4s m); + CGLM_INLINE void glms_decompose_rs(mat4s m, mat4s r, vec3s s); + CGLM_INLINE void glms_decompose(mat4s m, vec4s t, mat4s r, vec3s s); + */ + +#ifndef cglm_affines_h +#define cglm_affines_h + +#include "../common.h" +#include "../types-struct.h" +#include "../affine.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" + +CGLM_INLINE +mat4s +glms_mat4_mul(mat4s m1, mat4s m2); + +/*! + * @brief translate existing transform matrix by v vector + * and stores result in same matrix + * + * @param[in] m affine transfrom + * @param[in] v translate vector [x, y, z] + * @returns affine transfrom + */ +CGLM_INLINE +mat4s +glms_translate(mat4s m, vec3s v) { + glm_translate(m.raw, v.raw); + return m; +} + +/*! + * @brief translate existing transform matrix by x factor + * + * @param[in] m affine transfrom + * @param[in] x x factor + * @returns affine transfrom + */ +CGLM_INLINE +mat4s +glms_translate_x(mat4s m, float x) { + glm_translate_x(m.raw, x); + return m; +} + +/*! + * @brief translate existing transform matrix by y factor + * + * @param[in] m affine transfrom + * @param[in] y y factor + * @returns affine transfrom + */ +CGLM_INLINE +mat4s +glms_translate_y(mat4s m, float y) { + glm_translate_y(m.raw, y); + return m; +} + +/*! + * @brief translate existing transform matrix by z factor + * + * @param[in] m affine transfrom + * @param[in] z z factor + * @returns affine transfrom + */ +CGLM_INLINE +mat4s +glms_translate_z(mat4s m, float z) { + glm_translate_z(m.raw, z); + return m; +} + +/*! + * @brief creates NEW translate transform matrix by v vector + * + * @param[in] v translate vector [x, y, z] + * @returns affine transfrom + */ +CGLM_INLINE +mat4s +glms_translate_make(vec3s v) { + mat4s m; + glm_translate_make(m.raw, v.raw); + return m; +} + +/*! + * @brief creates NEW scale matrix by v vector + * + * @param[out] m affine transfrom + * @param[in] v scale vector [x, y, z] + */ +CGLM_INLINE +mat4s +glms_scale_make(vec3s v) { + mat4s m; + glm_scale_make(m.raw, v.raw); + return m; +} + +/*! + * @brief scales existing transform matrix by v vector + * and stores result in same matrix + * + * @param[in] m affine transfrom + * @param[in] v scale vector [x, y, z] + * @returns affine transfrom + */ +CGLM_INLINE +mat4s +glms_scale(mat4s m, vec3s v) { + mat4s r; + glm_scale_to(m.raw, v.raw, r.raw); + return r; +} + +/*! + * @brief applies uniform scale to existing transform matrix v = [s, s, s] + * and stores result in same matrix + * + * @param[in] m affine transfrom + * @param[in] s scale factor + * @returns affine transfrom + */ +CGLM_INLINE +mat4s +glms_scale_uni(mat4s m, float s) { + glm_scale_uni(m.raw, s); + return m; +} + +/*! + * @brief rotate existing transform matrix around X axis by angle + * and store result in dest + * + * @param[in] m affine transfrom + * @param[in] angle angle (radians) + * @returns rotated matrix + */ +CGLM_INLINE +mat4s +glmx_rotate_x(mat4s m, float angle) { + mat4s r; + glm_rotate_x(m.raw, angle, r.raw); + return r; +} + +/*! + * @brief rotate existing transform matrix around Y axis by angle + * and store result in dest + * + * @param[in] m affine transfrom + * @param[in] angle angle (radians) + * @returns rotated matrix + */ +CGLM_INLINE +mat4s +glms_rotate_y(mat4s m, float angle) { + mat4s r; + glm_rotate_y(m.raw, angle, r.raw); + return r; +} + +/*! + * @brief rotate existing transform matrix around Z axis by angle + * and store result in dest + * + * @param[in] m affine transfrom + * @param[in] angle angle (radians) + * @returns rotated matrix + */ +CGLM_INLINE +mat4s +glms_rotate_z(mat4s m, float angle) { + mat4s r; + glm_rotate_z(m.raw, angle, r.raw); + return r; +} + +/*! + * @brief creates NEW rotation matrix by angle and axis + * + * axis will be normalized so you don't need to normalize it + * + * @param[in] angle angle (radians) + * @param[in] axis axis + * @returns affine transfrom + */ +CGLM_INLINE +mat4s +glms_rotate_make(float angle, vec3s axis) { + mat4s m; + glm_rotate_make(m.raw, angle, axis.raw); + return m; +} + +/*! + * @brief rotate existing transform matrix around given axis by angle + * + * @param[in] m affine transfrom + * @param[in] angle angle (radians) + * @param[in] axis axis + * @returns affine transfrom + */ +CGLM_INLINE +mat4s +glms_rotate(mat4s m, float angle, vec3s axis) { + glm_rotate(m.raw, angle, axis.raw); + return m; +} + +/*! + * @brief rotate existing transform + * around given axis by angle at given pivot point (rotation center) + * + * @param[in] m affine transfrom + * @param[in] pivot rotation center + * @param[in] angle angle (radians) + * @param[in] axis axis + * @returns affine transfrom + */ +CGLM_INLINE +mat4s +glms_rotate_at(mat4s m, vec3s pivot, float angle, vec3s axis) { + glm_rotate_at(m.raw, pivot.raw, angle, axis.raw); + return m; +} + +/*! + * @brief creates NEW rotation matrix by angle and axis at given point + * + * this creates rotation matrix, it assumes you don't have a matrix + * + * 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 + * @returns affine transfrom + */ +CGLM_INLINE +mat4s +glms_rotate_atm(mat4s m, vec3s pivot, float angle, vec3s axis) { + glm_rotate_atm(m.raw, pivot.raw, angle, axis.raw); + return m; +} + +/*! + * @brief decompose scale vector + * + * @param[in] m affine transform + * @returns scale vector (Sx, Sy, Sz) + */ +CGLM_INLINE +vec3s +glms_decompose_scalev(mat4s m) { + mat3s m3x3; + vec3s s; + + m3x3 = glms_mat4_pick3(m); + + s.x = glms_vec3_norm(m3x3.col[0]); + s.y = glms_vec3_norm(m3x3.col[1]); + s.z = glms_vec3_norm(m3x3.col[2]); + return s; +} + +/*! + * @brief returns true if matrix is uniform scaled. This is helpful for + * creating normal matrix. + * + * @param[in] m m + * + * @return boolean + */ +CGLM_INLINE +bool +glms_uniscaled(mat4s m) { + return glm_uniscaled(m.raw); +} + +/*! + * @brief decompose rotation matrix (mat4) and scale vector [Sx, Sy, Sz] + * DON'T pass projected matrix here + * + * @param[in] m affine transform + * @param[out] r rotation matrix + * @param[out] s scale matrix + */ +CGLM_INLINE +void +glms_decompose_rs(mat4s m, mat4s r, vec3s s) { + glm_decompose_rs(m.raw, r.raw, s.raw); +} + +/*! + * @brief decompose affine transform, TODO: extract shear factors. + * DON'T pass projected matrix here + * + * @param[in] m affine transfrom + * @param[out] t translation vector + * @param[out] r rotation matrix (mat4) + * @param[out] s scaling vector [X, Y, Z] + */ +CGLM_INLINE +void +glms_decompose(mat4s m, vec4s t, mat4s r, vec3s s) { + glm_decompose(m.raw, t.raw, r.raw, s.raw); +} + +#endif /* cglm_affines_h */ diff --git a/include/cglm/structs/box.h b/include/cglm/structs/box.h new file mode 100644 index 0000000..e9c813f --- /dev/null +++ b/include/cglm/structs/box.h @@ -0,0 +1,285 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_boxs_h +#define cglm_boxs_h + +#include "../common.h" +#include "../types-struct.h" +#include "../box.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" + +/*! + * @brief apply transform to Axis-Aligned Bounding Box + * + * @param[in] box bounding box + * @param[in] m transform matrix + * @param[out] dest transformed bounding box + */ +CGLM_INLINE +void +glms_aabb_transform(vec3s box[2], mat4s m, vec3s dest[2]) { + vec3s v[2], xa, xb, ya, yb, za, zb; + mat3s m3x3; + + m3x3 = glms_mat4_pick3(m); + + xa = glms_vec3_scale(m3x3.col[0], box[0].x); + xb = glms_vec3_scale(m3x3.col[0], box[1].x); + + ya = glms_vec3_scale(m3x3.col[1], box[0].y); + yb = glms_vec3_scale(m3x3.col[1], box[1].y); + + za = glms_vec3_scale(m3x3.col[2], box[0].z); + zb = glms_vec3_scale(m3x3.col[2], box[1].z); + + /* translation + min(xa, xb) + min(ya, yb) + min(za, zb) */ + v[0] = m3x3.col[3]; + v[0] = glms_vec3_minadd(xa, xb); + v[0] = glms_vec3_minadd(ya, yb); + v[0] = glms_vec3_minadd(za, zb); + + /* translation + max(xa, xb) + max(ya, yb) + max(za, zb) */ + v[1] = m3x3.col[3]; + v[1] = glms_vec3_maxadd(xa, xb); + v[1] = glms_vec3_maxadd(ya, yb); + v[1] = glms_vec3_maxadd(za, zb); + + dest[0] = glms_vec3_copy(v[0]); + dest[1] = glms_vec3_copy(v[1]); +} + +/*! + * @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] box1 bounding box 1 + * @param[in] box2 bounding box 2 + * @param[out] dest merged bounding box + */ +CGLM_INLINE +void +glms_aabb_merge(vec3s box1[2], vec3s box2[2], vec3s dest[2]) { + dest[0].x = glm_min(box1[0].x, box2[0].x); + dest[0].y = glm_min(box1[0].y, box2[0].y); + dest[0].z = glm_min(box1[0].z, box2[0].z); + + dest[1].x = glm_max(box1[1].x, box2[1].x); + dest[1].y = glm_max(box1[1].y, box2[1].y); + dest[1].z = glm_max(box1[1].z, box2[1].z); +} + +/*! + * @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] box bounding box 1 + * @param[in] cropBox crop box + * @param[out] dest cropped bounding box + */ +CGLM_INLINE +void +glms_aabb_crop(vec3s box[2], vec3s cropBox[2], vec3s dest[2]) { + dest[0].x = glm_max(box[0].x, cropBox[0].x); + dest[0].y = glm_max(box[0].y, cropBox[0].y); + dest[0].z = glm_max(box[0].z, cropBox[0].z); + + dest[1].x = glm_min(box[1].x, cropBox[1].x); + dest[1].y = glm_min(box[1].y, cropBox[1].y); + dest[1].z = glm_min(box[1].z, cropBox[1].z); +} + +/*! + * @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] box bounding box + * @param[in] cropBox crop box + * @param[in] clampBox miniumum box + * @param[out] dest cropped bounding box + */ +CGLM_INLINE +void +glms_aabb_crop_until(vec3s box[2], + vec3s cropBox[2], + vec3s clampBox[2], + vec3s dest[2]) { + glms_aabb_crop(box, cropBox, dest); + glms_aabb_merge(clampBox, dest, dest); +} + +/*! + * @brief check if AABB intersects with frustum planes + * + * this could be useful for frustum culling using AABB. + * + * OPTIMIZATION HINT: + * if planes order is similar to LEFT, RIGHT, BOTTOM, TOP, NEAR, FAR + * then this method should run even faster because it would only use two + * planes if object is not inside the two planes + * fortunately cglm extracts planes as this order! just pass what you got! + * + * @param[in] box bounding box + * @param[in] planes frustum planes + */ +CGLM_INLINE +bool +glms_aabb_frustum(vec3s box[2], vec4s planes[6]) { + vec4s p; + float dp; + int i; + + for (i = 0; i < 6; i++) { + p = planes[i]; + dp = p.x * box[p.x > 0.0f].x + + p.y * box[p.y > 0.0f].y + + p.z * box[p.z > 0.0f].z; + + if (dp < -p.w) + return false; + } + + return true; +} + +/*! + * @brief invalidate AABB min and max values + * + * @param[in, out] box bounding box + */ +CGLM_INLINE +void +glms_aabb_invalidate(vec3s box[2]) { + box[0] = glms_vec3_broadcast(FLT_MAX); + box[1] = glms_vec3_broadcast(-FLT_MAX); +} + +/*! + * @brief check if AABB is valid or not + * + * @param[in] box bounding box + */ +CGLM_INLINE +bool +glms_aabb_isvalid(vec3s box[2]) { + return glms_vec3_max(box[0]) != FLT_MAX && + glms_vec3_min(box[1]) != -FLT_MAX; +} + +/*! + * @brief distance between of min and max + * + * @param[in] box bounding box + */ +CGLM_INLINE +float +glms_aabb_size(vec3s box[2]) { + return glms_vec3_distance(box[0], box[1]); +} + +/*! + * @brief radius of sphere which surrounds AABB + * + * @param[in] box bounding box + */ +CGLM_INLINE +float +glms_aabb_radius(vec3s box[2]) { + return glms_aabb_size(box) * 0.5f; +} + +/*! + * @brief computes center point of AABB + * + * @param[in] box bounding box + * @param[out] dest center of bounding box + */ +CGLM_INLINE +vec3s +glms_aabb_center(vec3s box[2]) { + return glms_vec3_center(box[0], box[1]); +} + +/*! + * @brief check if two AABB intersects + * + * @param[in] box bounding box + * @param[in] other other bounding box + */ +CGLM_INLINE +bool +glms_aabb_aabb(vec3s box[2], vec3s other[2]) { + return (box[0].x <= other[1].x && box[1].x >= other[0].x) + && (box[0].y <= other[1].y && box[1].y >= other[0].y) + && (box[0].z <= other[1].z && box[1].z >= other[0].z); +} + +/*! + * @brief check if AABB intersects with sphere + * + * https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c + * Solid Box - Solid Sphere test. + * + * @param[in] box solid bounding box + * @param[in] s solid sphere + */ +CGLM_INLINE +bool +glms_aabb_sphere(vec3s box[2], vec4 s) { + float dmin; + int a, b, c; + + a = s[0] >= box[0].x; + b = s[1] >= box[0].y; + c = s[2] >= box[0].z; + + dmin = glm_pow2(s[0] - box[a].x) + + glm_pow2(s[1] - box[b].y) + + glm_pow2(s[2] - box[c].z); + + return dmin <= glm_pow2(s[3]); +} + +/*! + * @brief check if point is inside of AABB + * + * @param[in] box bounding box + * @param[in] point point + */ +CGLM_INLINE +bool +glms_aabb_point(vec3s box[2], vec3s point) { + return (point.x >= box[0].x && point.x <= box[1].x) + && (point.y >= box[0].y && point.y <= box[1].y) + && (point.z >= box[0].z && point.z <= box[1].z); +} + +/*! + * @brief check if AABB contains other AABB + * + * @param[in] box bounding box + * @param[in] other other bounding box + */ +CGLM_INLINE +bool +glms_aabb_contains(vec3s box[2], vec3s other[2]) { + return (box[0].x <= other[0].x && box[1].x >= other[1].x) + && (box[0].y <= other[0].y && box[1].y >= other[1].y) + && (box[0].z <= other[0].z && box[1].z >= other[1].z); +} + +#endif /* cglm_boxs_h */ diff --git a/include/cglm/structs/color.h b/include/cglm/structs/color.h new file mode 100644 index 0000000..62cf5a8 --- /dev/null +++ b/include/cglm/structs/color.h @@ -0,0 +1,27 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_colors_h +#define cglm_colors_h + +#include "../common.h" +#include "../types-struct.h" +#include "../color.h" +#include "vec3.h" + +/*! + * @brief averages the color channels into one value + * + * @param[in] rgb RGB color + */ +CGLM_INLINE +float +glms_luminance(vec3s rgb) { + return glm_luminance(rgb.raw); +} + +#endif /* cglm_colors_h */ diff --git a/include/cglm/structs/curve.h b/include/cglm/structs/curve.h new file mode 100644 index 0000000..724b0be --- /dev/null +++ b/include/cglm/structs/curve.h @@ -0,0 +1,40 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_curves_h +#define cglm_curves_h + +#include "../common.h" +#include "../types-struct.h" +#include "../curve.h" +#include "vec4.h" +#include "mat4.h" + +/*! + * @brief helper function to calculate S*M*C multiplication for curves + * + * This function does not encourage you to use SMC, + * instead it is a helper if you use SMC. + * + * if you want to specify S as vector then use more generic glm_mat4_rmc() func. + * + * Example usage: + * B(s) = glm_smc(s, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}) + * + * @param[in] s parameter between 0 and 1 (this will be [s3, s2, s, 1]) + * @param[in] m basis matrix + * @param[in] c position/control vector + * + * @return B(s) + */ +CGLM_INLINE +float +glms_smc(float s, mat4s m, vec4s c) { + return glm_smc(s, m.raw, c.raw); +} + +#endif /* cglm_curves_h */ diff --git a/include/cglm/structs/frustum.h b/include/cglm/structs/frustum.h new file mode 100644 index 0000000..07340c8 --- /dev/null +++ b/include/cglm/structs/frustum.h @@ -0,0 +1,240 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_frustums_h +#define cglm_frustums_h + +#include "../common.h" +#include "../types-struct.h" +#include "../frustum.h" +#include "plane.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" + +/* you can override clip space coords + but you have to provide all with same name + e.g.: define GLM_CSCOORD_LBN {0.0f, 0.0f, 1.0f, 1.0f} */ +#ifndef GLM_CUSTOM_CLIPSPACE + +/* near */ +#define GLMS_CSCOORD_LBN {-1.0f, -1.0f, -1.0f, 1.0f} +#define GLMS_CSCOORD_LTN {-1.0f, 1.0f, -1.0f, 1.0f} +#define GLMS_CSCOORD_RTN { 1.0f, 1.0f, -1.0f, 1.0f} +#define GLMS_CSCOORD_RBN { 1.0f, -1.0f, -1.0f, 1.0f} + +/* far */ +#define GLMS_CSCOORD_LBF {-1.0f, -1.0f, 1.0f, 1.0f} +#define GLMS_CSCOORD_LTF {-1.0f, 1.0f, 1.0f, 1.0f} +#define GLMS_CSCOORD_RTF { 1.0f, 1.0f, 1.0f, 1.0f} +#define GLMS_CSCOORD_RBF { 1.0f, -1.0f, 1.0f, 1.0f} + +#endif + +/*! + * @brief extracts view frustum planes + * + * planes' space: + * 1- if m = proj: View Space + * 2- if m = viewProj: World Space + * 3- if m = MVP: Object Space + * + * You probably want to extract planes in world space so use viewProj as m + * Computing viewProj: + * glm_mat4_mul(proj, view, viewProj); + * + * Exracted planes order: [left, right, bottom, top, near, far] + * + * @param[in] m matrix (see brief) + * @param[out] dest extracted view frustum planes (see brief) + */ +CGLM_INLINE +void +glms_frustum_planes(mat4s m, vec4s dest[6]) { + mat4s t; + + t = glms_mat4_transpose(m); + + dest[0] = glms_vec4_add(t.col[3], t.col[0]); /* left */ + dest[1] = glms_vec4_sub(t.col[3], t.col[0]); /* right */ + dest[2] = glms_vec4_add(t.col[3], t.col[1]); /* bottom */ + dest[3] = glms_vec4_sub(t.col[3], t.col[1]); /* top */ + dest[4] = glms_vec4_add(t.col[3], t.col[2]); /* near */ + dest[5] = glms_vec4_sub(t.col[3], t.col[2]); /* far */ + + dest[0] = glms_plane_normalize(dest[0]); + dest[1] = glms_plane_normalize(dest[1]); + dest[2] = glms_plane_normalize(dest[2]); + dest[3] = glms_plane_normalize(dest[3]); + dest[4] = glms_plane_normalize(dest[4]); + dest[5] = glms_plane_normalize(dest[5]); +} + +/*! + * @brief extracts view frustum corners using clip-space coordinates + * + * corners' space: + * 1- if m = invViewProj: World Space + * 2- if m = invMVP: Object Space + * + * You probably want to extract corners in world space so use invViewProj + * Computing invViewProj: + * glm_mat4_mul(proj, view, viewProj); + * ... + * glm_mat4_inv(viewProj, invViewProj); + * + * if you have a near coord at i index, you can get it's far coord by i + 4 + * + * Find center coordinates: + * for (j = 0; j < 4; j++) { + * glm_vec3_center(corners[i], corners[i + 4], centerCorners[i]); + * } + * + * @param[in] invMat matrix (see brief) + * @param[out] dest exracted view frustum corners (see brief) + */ +CGLM_INLINE +void +glms_frustum_corners(mat4s invMat, vec4s dest[8]) { + vec4s c[8]; + + /* indexOf(nearCoord) = indexOf(farCoord) + 4 */ + vec4s csCoords[8] = { + GLMS_CSCOORD_LBN, + GLMS_CSCOORD_LTN, + GLMS_CSCOORD_RTN, + GLMS_CSCOORD_RBN, + + GLMS_CSCOORD_LBF, + GLMS_CSCOORD_LTF, + GLMS_CSCOORD_RTF, + GLMS_CSCOORD_RBF + }; + + c[0] = glms_mat4_mulv(invMat, csCoords[0]); + c[1] = glms_mat4_mulv(invMat, csCoords[1]); + c[2] = glms_mat4_mulv(invMat, csCoords[2]); + c[3] = glms_mat4_mulv(invMat, csCoords[3]); + c[4] = glms_mat4_mulv(invMat, csCoords[4]); + c[5] = glms_mat4_mulv(invMat, csCoords[5]); + c[6] = glms_mat4_mulv(invMat, csCoords[6]); + c[7] = glms_mat4_mulv(invMat, csCoords[7]); + + dest[0] = glms_vec4_scale(c[0], 1.0f / c[0].z); + dest[1] = glms_vec4_scale(c[1], 1.0f / c[1].z); + dest[2] = glms_vec4_scale(c[2], 1.0f / c[2].z); + dest[3] = glms_vec4_scale(c[3], 1.0f / c[3].z); + dest[4] = glms_vec4_scale(c[4], 1.0f / c[4].z); + dest[5] = glms_vec4_scale(c[5], 1.0f / c[5].z); + dest[6] = glms_vec4_scale(c[6], 1.0f / c[6].z); + dest[7] = glms_vec4_scale(c[7], 1.0f / c[7].z); +} + +/*! + * @brief finds center of view frustum + * + * @param[in] corners view frustum corners + * @returns view frustum center + */ +CGLM_INLINE +vec4s +glms_frustum_center(vec4s corners[8]) { + vec4s center; + + center = glms_vec4_copy(corners[0]); + + center = glms_vec4_add(corners[1], center); + center = glms_vec4_add(corners[2], center); + center = glms_vec4_add(corners[3], center); + center = glms_vec4_add(corners[4], center); + center = glms_vec4_add(corners[5], center); + center = glms_vec4_add(corners[6], center); + center = glms_vec4_add(corners[7], center); + + return glms_vec4_scale(center, 0.125f); +} + +/*! + * @brief finds bounding box of frustum relative to given matrix e.g. view mat + * + * @param[in] corners view frustum corners + * @param[in] m matrix to convert existing conners + * @param[out] box bounding box as array [min, max] + */ +CGLM_INLINE +void +glms_frustum_box(vec4s corners[8], mat4s m, vec3s box[2]) { + vec4s v; + vec3s min, max; + int i; + + min = glms_vec3_broadcast(FLT_MAX); + max = glms_vec3_broadcast(-FLT_MAX); + + for (i = 0; i < 8; i++) { + v = glms_mat4_mulv(m, corners[i]); + + min.x = glm_min(min.x, v.x); + min.y = glm_min(min.y, v.y); + min.z = glm_min(min.z, v.z); + + max.x = glm_max(max.x, v.x); + max.y = glm_max(max.y, v.y); + max.z = glm_max(max.z, v.z); + } + + box[0] = glms_vec3_copy(min); + box[1] = glms_vec3_copy(max); +} + +/*! + * @brief finds planes corners which is between near and far planes (parallel) + * + * this will be helpful if you want to split a frustum e.g. CSM/PSSM. This will + * find planes' corners but you will need to one more plane. + * Actually you have it, it is near, far or created previously with this func ;) + * + * @param[in] corners view frustum corners + * @param[in] splitDist split distance + * @param[in] farDist far distance (zFar) + * @param[out] planeCorners plane corners [LB, LT, RT, RB] + */ +CGLM_INLINE +void +glms_frustum_corners_at(vec4s corners[8], + float splitDist, + float farDist, + vec4s planeCorners[4]) { + vec4s corner; + float dist, sc; + + /* because distance and scale is same for all */ + dist = glms_vec4_distance(corners[GLM_RTF], corners[GLM_RTN]); + sc = dist * (splitDist / farDist); + + /* left bottom */ + corner = glms_vec4_sub(corners[GLM_LBF], corners[GLM_LBN]); + corner = glms_vec4_scale_as(corner, sc); + planeCorners[0] = glms_vec4_add(corners[GLM_LBN], corner); + + /* left top */ + corner = glms_vec4_sub(corners[GLM_LTF], corners[GLM_LTN]); + corner = glms_vec4_scale_as(corner, sc); + planeCorners[1] = glms_vec4_add(corners[GLM_LTN], corner); + + /* right top */ + corner = glms_vec4_sub(corners[GLM_RTF], corners[GLM_RTN]); + corner = glms_vec4_scale_as(corner, sc); + planeCorners[2] = glms_vec4_add(corners[GLM_RTN], corner); + + /* right bottom */ + corner = glms_vec4_sub(corners[GLM_RBF], corners[GLM_RBN]); + corner = glms_vec4_scale_as(corner, sc); + planeCorners[3] = glms_vec4_add(corners[GLM_RBN], corner); +} + +#endif /* cglm_frustums_h */ diff --git a/include/cglm/structs/io.h b/include/cglm/structs/io.h new file mode 100644 index 0000000..c209a47 --- /dev/null +++ b/include/cglm/structs/io.h @@ -0,0 +1,100 @@ +/* + * 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_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_vec3_print(vec3 vec, FILE *ostream); + CGLM_INLINE void glm_ivec3_print(ivec3 vec, FILE *ostream); + CGLM_INLINE void glm_versor_print(versor vec, FILE *ostream); + */ + +#ifndef cglm_ios_h +#define cglm_ios_h + +#include "../common.h" +#include "../io.h" +#include "mat4.h" + +#include +#include + +CGLM_INLINE +void +glms_mat4_print(mat4s matrix, + FILE * __restrict ostream) { + + glm_mat4_print(matrix.raw, ostream); +} + +CGLM_INLINE +void +glms_mat3_print(mat3s matrix, + FILE * __restrict ostream) { + glm_mat3_print(matrix.raw, ostream); +} + +CGLM_INLINE +void +glms_vec4_print(vec4s vec, + FILE * __restrict ostream) { + glm_vec4_print(vec.raw, ostream); +} + +CGLM_INLINE +void +glms_vec3_print(vec3s vec, + FILE * __restrict ostream) { + glm_vec3_print(vec.raw, ostream); +} + +CGLM_INLINE +void +glms_ivec3_print(ivec3s vec, + FILE * __restrict ostream) { + glm_ivec3_print(vec.raw, ostream); +} + +CGLM_INLINE +void +glms_versor_print(versors vec, + FILE * __restrict ostream) { + glm_versor_print(vec.raw, ostream); +} + +CGLM_INLINE +void +glms_aabb_print(vec3s bbox[2], + const char * __restrict tag, + FILE * __restrict ostream) { + int i, j; + +#define m 3 + + fprintf(ostream, "AABB (%s):\n", tag ? tag : "float"); + + for (i = 0; i < 2; i++) { + fprintf(ostream, "\t|"); + + for (j = 0; j < m; j++) { + fprintf(ostream, "%0.4f", bbox[i].raw[j]); + + if (j != m - 1) + fprintf(ostream, "\t"); + } + + fprintf(ostream, "|\n"); + } + + fprintf(ostream, "\n"); + +#undef m +} + +#endif /* cglm_ios_h */ diff --git a/include/cglm/structs/mat3.h b/include/cglm/structs/mat3.h index 63fe7c6..8072746 100644 --- a/include/cglm/structs/mat3.h +++ b/include/cglm/structs/mat3.h @@ -18,7 +18,6 @@ CGLM_INLINE void glms_mat3_identity_array(mat3s * __restrict mat, size_t count); CGLM_INLINE mat3s glms_mat3_zero(); CGLM_INLINE mat3s glms_mat3_mul(mat3s m1, mat3s m2); - CGLM_INLINE mat3s glms_mat3_transpose_to(mat3s m); CGLM_INLINE ma3s glms_mat3_transpose(mat3s m); CGLM_INLINE vec3s glms_mat3_mulv(mat3s m, vec3s v); CGLM_INLINE float glms_mat3_trace(mat3s m); @@ -140,22 +139,6 @@ glms_mat3_mul(mat3s m1, mat3s m2) { return r; } -/*! - * @brief transpose mat3 and store in dest - * - * source matrix will not be transposed unless dest is m - * - * @param[in] m matrix - * @param[out] dest result - */ -CGLM_INLINE -mat3s -glms_mat3_transpose_to(mat3s m) { - mat3s r; - glm_mat3_transpose_to(m.raw, r.raw); - return r; -} - /*! * @brief tranpose mat3 and store result in same matrix * diff --git a/include/cglm/structs/mat4.h b/include/cglm/structs/mat4.h index a61f18d..72686cd 100644 --- a/include/cglm/structs/mat4.h +++ b/include/cglm/structs/mat4.h @@ -33,7 +33,6 @@ CGLM_INLINE float glms_mat4_trace3(mat4s m); CGLM_INLINE versors glms_mat4_quat(mat4s m); CGLM_INLINE vec3s glms_mat4_mulv3(mat4s m, vec3s v, float last); - CGLM_INLINE mat4s glms_mat4_transpose_to(mat4s m); CGLM_INLINE mat4s glms_mat4_transpose(mat4s m); CGLM_INLINE mat4s glms_mat4_scale_p(mat4s m, float s); CGLM_INLINE mat4s glms_mat4_scale(mat4s m, float s); @@ -54,19 +53,19 @@ #include "vec4.h" #include "vec3.h" -#define GLMS_MAT4_IDENTITY_INIT {{1.0f, 0.0f, 0.0f, 0.0f}, \ - {0.0f, 1.0f, 0.0f, 0.0f}, \ - {0.0f, 0.0f, 1.0f, 0.0f}, \ - {0.0f, 0.0f, 0.0f, 1.0f}} +#define GLMS_MAT4_IDENTITY_INIT {1.0f, 0.0f, 0.0f, 0.0f, \ + 0.0f, 1.0f, 0.0f, 0.0f, \ + 0.0f, 0.0f, 1.0f, 0.0f, \ + 0.0f, 0.0f, 0.0f, 1.0f} -#define GLMS_MAT4_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}, \ - {0.0f, 0.0f, 0.0f, 0.0f}} +#define GLMS_MAT4_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, \ + 0.0f, 0.0f, 0.0f, 0.0f} /* for C only */ -#define GLMS_MAT4_IDENTITY ((mat4)GLMS_MAT4_IDENTITY_INIT) -#define GLMS_MAT4_ZERO ((mat4)GLMS_MAT4_ZERO_INIT) +#define GLMS_MAT4_IDENTITY ((mat4s)GLMS_MAT4_IDENTITY_INIT) +#define GLMS_MAT4_ZERO ((mat4s)GLMS_MAT4_ZERO_INIT) /*! * @brief copy all members of [mat] to [dest] @@ -132,7 +131,7 @@ glms_mat4_identity() { CGLM_INLINE void glms_mat4_identity_array(mat4s * __restrict mat, size_t count) { - CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; + CGLM_ALIGN_MAT mat4s t = GLMS_MAT4_IDENTITY_INIT; size_t i; for (i = 0; i < count; i++) { @@ -229,20 +228,25 @@ glms_mat4_mul(mat4s m1, mat4s m2) { * @code * mat m1, m2, m3, m4, res; * - * glm_mat4_mulN((mat4 *[]){&m1, &m2, &m3, &m4}, 4, res); + * res = glm_mat4_mulN((mat4 *[]){&m1, &m2, &m3, &m4}, 4); * @endcode * * @warning matrices parameter is pointer array not mat4 array! * * @param[in] matrices mat4 * array * @param[in] len matrices count - * @returns result + * @returns result matrix */ CGLM_INLINE mat4s glms_mat4_mulN(mat4s * __restrict matrices[], uint32_t len) { - mat4s r; - glm_mat4_mulN(matrices, len, r.raw); + CGLM_ALIGN_MAT mat4s r = GLMS_MAT4_IDENTITY_INIT; + uint32_t i; + + for (i = 0; i < len; i++) { + r = glms_mat4_mul(r, *matrices[i]); + } + return r; } @@ -317,22 +321,6 @@ glms_mat4_mulv3(mat4s m, vec3s v, float last) { return r; } -/*! - * @brief transpose mat4 and store in dest - * - * source matrix will not be transposed unless dest is m - * - * @param[in] m matrix - * @returns result - */ -CGLM_INLINE -mat4s -glms_mat4_transpose_to(mat4s m) { - mat4s r; - glm_mat4_transpose_to(m.raw, r.raw); - return r; -} - /*! * @brief tranpose mat4 and store result in same matrix * diff --git a/include/cglm/structs/plane.h b/include/cglm/structs/plane.h new file mode 100644 index 0000000..6e23482 --- /dev/null +++ b/include/cglm/structs/plane.h @@ -0,0 +1,40 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_planes_h +#define cglm_planes_h + +#include "../common.h" +#include "../types-struct.h" +#include "../plane.h" +#include "vec4.h" + +/* + Plane equation: Ax + By + Cz + D = 0; + + It stored in vec4 as [A, B, C, D]. (A, B, C) is normal and D is distance +*/ + +/* + Functions: + CGLM_INLINE vec4s glms_plane_normalize(vec4s plane); + */ + +/*! + * @brief normalizes a plane + * + * @param[in] plane plane to normalize + * @returns normalized plane + */ +CGLM_INLINE +vec4s +glms_plane_normalize(vec4s plane) { + glm_plane_normalize(plane.raw); + return plane; +} + +#endif /* cglm_planes_h */ diff --git a/include/cglm/structs/project.h b/include/cglm/structs/project.h new file mode 100644 index 0000000..1cbb137 --- /dev/null +++ b/include/cglm/structs/project.h @@ -0,0 +1,104 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_projects_h +#define cglm_projects_h + +#include "../common.h" +#include "../types-struct.h" +#include "../project.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" + +/*! + * @brief maps the specified viewport coordinates into specified space [1] + * the matrix should contain projection matrix. + * + * if you don't have ( and don't want to have ) an inverse matrix then use + * glm_unproject version. You may use existing inverse of matrix in somewhere + * else, this is why glm_unprojecti exists to save save inversion cost + * + * [1] space: + * 1- if m = invProj: View Space + * 2- if m = invViewProj: World Space + * 3- if m = invMVP: Object Space + * + * You probably want to map the coordinates into object space + * so use invMVP as m + * + * Computing viewProj: + * glm_mat4_mul(proj, view, viewProj); + * glm_mat4_mul(viewProj, model, MVP); + * glm_mat4_inv(viewProj, invMVP); + * + * @param[in] pos point/position in viewport coordinates + * @param[in] invMat matrix (see brief) + * @param[in] vp viewport as [x, y, width, height] + * @returns unprojected coordinates + */ +CGLM_INLINE +vec3s +glms_unprojecti(vec3s pos, mat4s invMat, vec4s vp) { + vec3s r; + glm_unprojecti(pos.raw, invMat.raw, vp.raw, r.raw); + return r; +} + +/*! + * @brief maps the specified viewport coordinates into specified space [1] + * the matrix should contain projection matrix. + * + * this is same as glm_unprojecti except this function get inverse matrix for + * you. + * + * [1] space: + * 1- if m = proj: View Space + * 2- if m = viewProj: World Space + * 3- if m = MVP: Object Space + * + * You probably want to map the coordinates into object space + * so use MVP as m + * + * Computing viewProj and MVP: + * glm_mat4_mul(proj, view, viewProj); + * glm_mat4_mul(viewProj, model, MVP); + * + * @param[in] pos point/position in viewport coordinates + * @param[in] m matrix (see brief) + * @param[in] vp viewport as [x, y, width, height] + * @returns unprojected coordinates + */ +CGLM_INLINE +vec3s +glms_unproject(vec3s pos, mat4s m, vec4s vp) { + vec3s r; + glm_unproject(pos.raw, m.raw, vp.raw, r.raw); + return r; +} + +/*! + * @brief map object coordinates to window coordinates + * + * Computing MVP: + * glm_mat4_mul(proj, view, viewProj); + * glm_mat4_mul(viewProj, model, MVP); + * + * @param[in] pos object coordinates + * @param[in] m MVP matrix + * @param[in] vp viewport as [x, y, width, height] + * @param[out] dest projected coordinates + */ +CGLM_INLINE +vec3s +glms_project(vec3s pos, mat4s m, vec4s vp) { + vec3s r; + glm_project(pos.raw, m.raw, vp.raw, r.raw); + return r; +} + +#endif /* cglm_projects_h */ diff --git a/include/cglm/structs/sphere.h b/include/cglm/structs/sphere.h index b336c3b..164e8bc 100644 --- a/include/cglm/structs/sphere.h +++ b/include/cglm/structs/sphere.h @@ -10,8 +10,8 @@ #include "../common.h" #include "../types-struct.h" -#include "../mat4.h" #include "../sphere.h" +#include "mat4.h" /* Sphere Representation in cglm: [center.x, center.y, center.z, radii] diff --git a/include/cglm/types-struct.h b/include/cglm/types-struct.h index 13431aa..2d54aa4 100644 --- a/include/cglm/types-struct.h +++ b/include/cglm/types-struct.h @@ -21,6 +21,17 @@ typedef union vec3s { vec3 raw; } vec3s; +typedef union ivec3s { +#ifndef CGLM_NO_ANONYMOUS_STRUCT + struct { + int x; + int y; + int z; + }; +#endif + ivec3 raw; +} ivec3s; + typedef union CGLM_ALIGN_IF(16) vec4s { #ifndef CGLM_NO_ANONYMOUS_STRUCT struct { @@ -38,15 +49,9 @@ typedef vec4s versors; typedef union mat3s { #ifndef CGLM_NO_ANONYMOUS_STRUCT struct { - float m00; - float m01; - float m02; - float m10; - float m11; - float m12; - float m20; - float m21; - float m22; + float m00, m01, m02; + float m10, m11, m12; + float m20, m21, m22; }; struct { vec3s col0; @@ -54,32 +59,17 @@ typedef union mat3s { vec3s col2; }; #endif + vec3s col[3]; mat3 raw; } mat3s; -#ifdef __AVX__ -typedef union CGLM_ALIGN_IF(32) mat4s { -#else -typedef union CGLM_ALIGN_IF(16) mat4s { -#endif +typedef union CGLM_ALIGN_MAT mat4s { #ifndef CGLM_NO_ANONYMOUS_STRUCT struct { - float m00; - float m01; - float m02; - float m03; - float m10; - float m11; - float m12; - float m13; - float m20; - float m21; - float m22; - float m23; - float m30; - float m31; - float m32; - float m33; + float m00, m01, m02, m03; + float m10, m11, m12, m13; + float m20, m21, m22, m23; + float m30, m31, m32, m33; }; struct { vec4s col0; @@ -88,6 +78,7 @@ typedef union CGLM_ALIGN_IF(16) mat4s { vec4s col3; }; #endif + vec4s col[4]; mat4 raw; } mat4s; From 6fa5173cfd08e1f459f8a4b9ee44f8e7632e6793 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 8 May 2019 09:18:05 +0300 Subject: [PATCH 274/292] now working on v0.5.5 --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 2c9329f..7bd3c58 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.5.4], [info@recp.me]) +AC_INIT([cglm], [0.5.5], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index c2b6ba0..33fda4e 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.5.4' +version = u'0.5.5' # The full version, including alpha/beta/rc tags. -release = u'0.5.4' +release = u'0.5.5' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index 3664323..d406e2c 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 5 -#define CGLM_VERSION_PATCH 4 +#define CGLM_VERSION_PATCH 5 #endif /* cglm_version_h */ From 2adb4c55938ab69aeef4791dc7867f900d9a1f61 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 8 May 2019 09:18:11 +0300 Subject: [PATCH 275/292] use CGLM_ALIGN_MAT on mat4 typedef --- include/cglm/types.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/include/cglm/types.h b/include/cglm/types.h index 1190b73..169d70b 100644 --- a/include/cglm/types.h +++ b/include/cglm/types.h @@ -38,12 +38,7 @@ typedef int ivec3[3]; typedef CGLM_ALIGN_IF(16) float vec4[4]; typedef vec4 versor; typedef vec3 mat3[3]; - -#ifdef __AVX__ -typedef CGLM_ALIGN_IF(32) vec4 mat4[4]; -#else -typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; -#endif +typedef CGLM_ALIGN_MAT vec4 mat4[4]; #define GLM_E 2.71828182845904523536028747135266250 /* e */ #define GLM_LOG2E 1.44269504088896340735992468100189214 /* log2(e) */ From 1d1bf8e91a63d8d4c6d269f4ad7526e80df366dc Mon Sep 17 00:00:00 2001 From: acoto87 Date: Thu, 16 May 2019 17:03:55 -0500 Subject: [PATCH 276/292] - Change the approach implementation of several functions - Added `glms_vec4_pack` and `glms_vec4_unpack` to pack and unpack arrays of `vec4s`. - Added `glms_vec3_pack` and `glms_vec3_unpack` to pack and unpack arrays of `vec3s`. - Fixes in functions that accumulates in one parameter - --- include/cglm/structs/affine.h | 16 ++-- include/cglm/structs/box.h | 84 ++++++++------------- include/cglm/structs/frustum.h | 131 ++++++--------------------------- include/cglm/structs/io.h | 24 +----- include/cglm/structs/mat4.h | 2 +- include/cglm/structs/vec3.h | 118 ++++++++++++----------------- include/cglm/structs/vec4.h | 73 ++++++++++++------ 7 files changed, 160 insertions(+), 288 deletions(-) diff --git a/include/cglm/structs/affine.h b/include/cglm/structs/affine.h index 6f8be48..72cab13 100644 --- a/include/cglm/structs/affine.h +++ b/include/cglm/structs/affine.h @@ -286,15 +286,9 @@ glms_rotate_atm(mat4s m, vec3s pivot, float angle, vec3s axis) { CGLM_INLINE vec3s glms_decompose_scalev(mat4s m) { - mat3s m3x3; - vec3s s; - - m3x3 = glms_mat4_pick3(m); - - s.x = glms_vec3_norm(m3x3.col[0]); - s.y = glms_vec3_norm(m3x3.col[1]); - s.z = glms_vec3_norm(m3x3.col[2]); - return s; + vec3s r; + glm_decompose_scalev(m.raw, r.raw); + return r; } /*! @@ -322,6 +316,8 @@ glms_uniscaled(mat4s m) { CGLM_INLINE void glms_decompose_rs(mat4s m, mat4s r, vec3s s) { + // FIX: Modify param + // glm_decompose_rs(m.raw, r.raw, s.raw); } @@ -337,6 +333,8 @@ glms_decompose_rs(mat4s m, mat4s r, vec3s s) { CGLM_INLINE void glms_decompose(mat4s m, vec4s t, mat4s r, vec3s s) { + // FIX: Modify param + // glm_decompose(m.raw, t.raw, r.raw, s.raw); } diff --git a/include/cglm/structs/box.h b/include/cglm/structs/box.h index e9c813f..ca7c3a6 100644 --- a/include/cglm/structs/box.h +++ b/include/cglm/structs/box.h @@ -25,34 +25,12 @@ CGLM_INLINE void glms_aabb_transform(vec3s box[2], mat4s m, vec3s dest[2]) { - vec3s v[2], xa, xb, ya, yb, za, zb; - mat3s m3x3; + vec3 rawBox[2]; + vec3 rawDest[2]; - m3x3 = glms_mat4_pick3(m); - - xa = glms_vec3_scale(m3x3.col[0], box[0].x); - xb = glms_vec3_scale(m3x3.col[0], box[1].x); - - ya = glms_vec3_scale(m3x3.col[1], box[0].y); - yb = glms_vec3_scale(m3x3.col[1], box[1].y); - - za = glms_vec3_scale(m3x3.col[2], box[0].z); - zb = glms_vec3_scale(m3x3.col[2], box[1].z); - - /* translation + min(xa, xb) + min(ya, yb) + min(za, zb) */ - v[0] = m3x3.col[3]; - v[0] = glms_vec3_minadd(xa, xb); - v[0] = glms_vec3_minadd(ya, yb); - v[0] = glms_vec3_minadd(za, zb); - - /* translation + max(xa, xb) + max(ya, yb) + max(za, zb) */ - v[1] = m3x3.col[3]; - v[1] = glms_vec3_maxadd(xa, xb); - v[1] = glms_vec3_maxadd(ya, yb); - v[1] = glms_vec3_maxadd(za, zb); - - dest[0] = glms_vec3_copy(v[0]); - dest[1] = glms_vec3_copy(v[1]); + glms_vec3_unpack(rawBox, box, 2); + glm_aabb_transform(rawBox, m.raw, rawDest); + glms_vec3_pack(dest, rawDest, 2); } /*! @@ -68,13 +46,14 @@ glms_aabb_transform(vec3s box[2], mat4s m, vec3s dest[2]) { CGLM_INLINE void glms_aabb_merge(vec3s box1[2], vec3s box2[2], vec3s dest[2]) { - dest[0].x = glm_min(box1[0].x, box2[0].x); - dest[0].y = glm_min(box1[0].y, box2[0].y); - dest[0].z = glm_min(box1[0].z, box2[0].z); + vec3 rawBox1[2]; + vec3 rawBox2[2]; + vec3 rawDest[2]; - dest[1].x = glm_max(box1[1].x, box2[1].x); - dest[1].y = glm_max(box1[1].y, box2[1].y); - dest[1].z = glm_max(box1[1].z, box2[1].z); + glms_vec3_unpack(rawBox1, box1, 2); + glms_vec3_unpack(rawBox2, box2, 2); + glm_aabb_merge(rawBox1, rawBox2, rawDest); + glms_vec3_pack(dest, rawDest, 2); } /*! @@ -91,13 +70,14 @@ glms_aabb_merge(vec3s box1[2], vec3s box2[2], vec3s dest[2]) { CGLM_INLINE void glms_aabb_crop(vec3s box[2], vec3s cropBox[2], vec3s dest[2]) { - dest[0].x = glm_max(box[0].x, cropBox[0].x); - dest[0].y = glm_max(box[0].y, cropBox[0].y); - dest[0].z = glm_max(box[0].z, cropBox[0].z); + vec3 rawBox[2]; + vec3 rawCropBox[2]; + vec3 rawDest[2]; - dest[1].x = glm_min(box[1].x, cropBox[1].x); - dest[1].y = glm_min(box[1].y, cropBox[1].y); - dest[1].z = glm_min(box[1].z, cropBox[1].z); + glms_vec3_unpack(rawBox, box, 2); + glms_vec3_unpack(rawCropBox, cropBox, 2); + glm_aabb_crop(rawBox, rawCropBox, rawDest); + glms_vec3_pack(dest, rawDest, 2); } /*! @@ -139,21 +119,12 @@ glms_aabb_crop_until(vec3s box[2], CGLM_INLINE bool glms_aabb_frustum(vec3s box[2], vec4s planes[6]) { - vec4s p; - float dp; - int i; + vec3 rawBox[2]; + vec4 rawPlanes[6]; - for (i = 0; i < 6; i++) { - p = planes[i]; - dp = p.x * box[p.x > 0.0f].x - + p.y * box[p.y > 0.0f].y - + p.z * box[p.z > 0.0f].z; - - if (dp < -p.w) - return false; - } - - return true; + glms_vec3_unpack(rawBox, box, 2); + glms_vec4_unpack(rawPlanes, planes, 6); + return glm_aabb_frustum(rawBox, rawPlanes); } /*! @@ -164,6 +135,8 @@ glms_aabb_frustum(vec3s box[2], vec4s planes[6]) { CGLM_INLINE void glms_aabb_invalidate(vec3s box[2]) { + // FIX: Modify param + // box[0] = glms_vec3_broadcast(FLT_MAX); box[1] = glms_vec3_broadcast(-FLT_MAX); } @@ -176,8 +149,9 @@ glms_aabb_invalidate(vec3s box[2]) { CGLM_INLINE bool glms_aabb_isvalid(vec3s box[2]) { - return glms_vec3_max(box[0]) != FLT_MAX && - glms_vec3_min(box[1]) != -FLT_MAX; + vec3 rawBox[2]; + glms_vec3_unpack(rawBox, box, 2); + return glm_aabb_isvalid(rawBox); } /*! diff --git a/include/cglm/structs/frustum.h b/include/cglm/structs/frustum.h index 07340c8..56bd165 100644 --- a/include/cglm/structs/frustum.h +++ b/include/cglm/structs/frustum.h @@ -55,23 +55,9 @@ CGLM_INLINE void glms_frustum_planes(mat4s m, vec4s dest[6]) { - mat4s t; - - t = glms_mat4_transpose(m); - - dest[0] = glms_vec4_add(t.col[3], t.col[0]); /* left */ - dest[1] = glms_vec4_sub(t.col[3], t.col[0]); /* right */ - dest[2] = glms_vec4_add(t.col[3], t.col[1]); /* bottom */ - dest[3] = glms_vec4_sub(t.col[3], t.col[1]); /* top */ - dest[4] = glms_vec4_add(t.col[3], t.col[2]); /* near */ - dest[5] = glms_vec4_sub(t.col[3], t.col[2]); /* far */ - - dest[0] = glms_plane_normalize(dest[0]); - dest[1] = glms_plane_normalize(dest[1]); - dest[2] = glms_plane_normalize(dest[2]); - dest[3] = glms_plane_normalize(dest[3]); - dest[4] = glms_plane_normalize(dest[4]); - dest[5] = glms_plane_normalize(dest[5]); + vec4 rawDest[6]; + glm_frustum_planes(m.raw, rawDest); + glms_vec4_pack(dest, rawDest, 6); } /*! @@ -100,38 +86,9 @@ glms_frustum_planes(mat4s m, vec4s dest[6]) { CGLM_INLINE void glms_frustum_corners(mat4s invMat, vec4s dest[8]) { - vec4s c[8]; - - /* indexOf(nearCoord) = indexOf(farCoord) + 4 */ - vec4s csCoords[8] = { - GLMS_CSCOORD_LBN, - GLMS_CSCOORD_LTN, - GLMS_CSCOORD_RTN, - GLMS_CSCOORD_RBN, - - GLMS_CSCOORD_LBF, - GLMS_CSCOORD_LTF, - GLMS_CSCOORD_RTF, - GLMS_CSCOORD_RBF - }; - - c[0] = glms_mat4_mulv(invMat, csCoords[0]); - c[1] = glms_mat4_mulv(invMat, csCoords[1]); - c[2] = glms_mat4_mulv(invMat, csCoords[2]); - c[3] = glms_mat4_mulv(invMat, csCoords[3]); - c[4] = glms_mat4_mulv(invMat, csCoords[4]); - c[5] = glms_mat4_mulv(invMat, csCoords[5]); - c[6] = glms_mat4_mulv(invMat, csCoords[6]); - c[7] = glms_mat4_mulv(invMat, csCoords[7]); - - dest[0] = glms_vec4_scale(c[0], 1.0f / c[0].z); - dest[1] = glms_vec4_scale(c[1], 1.0f / c[1].z); - dest[2] = glms_vec4_scale(c[2], 1.0f / c[2].z); - dest[3] = glms_vec4_scale(c[3], 1.0f / c[3].z); - dest[4] = glms_vec4_scale(c[4], 1.0f / c[4].z); - dest[5] = glms_vec4_scale(c[5], 1.0f / c[5].z); - dest[6] = glms_vec4_scale(c[6], 1.0f / c[6].z); - dest[7] = glms_vec4_scale(c[7], 1.0f / c[7].z); + vec4 rawDest[8]; + glm_frustum_corners(invMat.raw, rawDest); + glms_vec4_pack(dest, rawDest, 8); } /*! @@ -143,19 +100,12 @@ glms_frustum_corners(mat4s invMat, vec4s dest[8]) { CGLM_INLINE vec4s glms_frustum_center(vec4s corners[8]) { - vec4s center; + vec4 rawCorners[8]; + vec4s r; - center = glms_vec4_copy(corners[0]); - - center = glms_vec4_add(corners[1], center); - center = glms_vec4_add(corners[2], center); - center = glms_vec4_add(corners[3], center); - center = glms_vec4_add(corners[4], center); - center = glms_vec4_add(corners[5], center); - center = glms_vec4_add(corners[6], center); - center = glms_vec4_add(corners[7], center); - - return glms_vec4_scale(center, 0.125f); + glms_vec4_unpack(rawCorners, corners, 8); + glm_frustum_center(rawCorners, r.raw); + return r; } /*! @@ -168,27 +118,12 @@ glms_frustum_center(vec4s corners[8]) { CGLM_INLINE void glms_frustum_box(vec4s corners[8], mat4s m, vec3s box[2]) { - vec4s v; - vec3s min, max; - int i; + vec4 rawCorners[8]; + vec3 rawBox[2]; - min = glms_vec3_broadcast(FLT_MAX); - max = glms_vec3_broadcast(-FLT_MAX); - - for (i = 0; i < 8; i++) { - v = glms_mat4_mulv(m, corners[i]); - - min.x = glm_min(min.x, v.x); - min.y = glm_min(min.y, v.y); - min.z = glm_min(min.z, v.z); - - max.x = glm_max(max.x, v.x); - max.y = glm_max(max.y, v.y); - max.z = glm_max(max.z, v.z); - } - - box[0] = glms_vec3_copy(min); - box[1] = glms_vec3_copy(max); + glms_vec4_unpack(rawCorners, corners, 8); + glm_frustum_box(rawCorners, m.raw, rawBox); + glms_vec3_pack(box, rawBox, 2); } /*! @@ -205,36 +140,16 @@ glms_frustum_box(vec4s corners[8], mat4s m, vec3s box[2]) { */ CGLM_INLINE void -glms_frustum_corners_at(vec4s corners[8], +glms_frustum_corners_at(vec4s corners[8], float splitDist, float farDist, - vec4s planeCorners[4]) { - vec4s corner; - float dist, sc; + vec4s planeCorners[4]) { + vec4 rawCorners[8]; + vec4 rawPlaneCorners[4]; - /* because distance and scale is same for all */ - dist = glms_vec4_distance(corners[GLM_RTF], corners[GLM_RTN]); - sc = dist * (splitDist / farDist); - - /* left bottom */ - corner = glms_vec4_sub(corners[GLM_LBF], corners[GLM_LBN]); - corner = glms_vec4_scale_as(corner, sc); - planeCorners[0] = glms_vec4_add(corners[GLM_LBN], corner); - - /* left top */ - corner = glms_vec4_sub(corners[GLM_LTF], corners[GLM_LTN]); - corner = glms_vec4_scale_as(corner, sc); - planeCorners[1] = glms_vec4_add(corners[GLM_LTN], corner); - - /* right top */ - corner = glms_vec4_sub(corners[GLM_RTF], corners[GLM_RTN]); - corner = glms_vec4_scale_as(corner, sc); - planeCorners[2] = glms_vec4_add(corners[GLM_RTN], corner); - - /* right bottom */ - corner = glms_vec4_sub(corners[GLM_RBF], corners[GLM_RBN]); - corner = glms_vec4_scale_as(corner, sc); - planeCorners[3] = glms_vec4_add(corners[GLM_RBN], corner); + glms_vec4_unpack(rawCorners, corners, 8); + glm_frustum_corners_at(rawCorners, splitDist, farDist, rawPlaneCorners); + glms_vec4_pack(planeCorners, rawPlaneCorners, 8); } #endif /* cglm_frustums_h */ diff --git a/include/cglm/structs/io.h b/include/cglm/structs/io.h index c209a47..2467d20 100644 --- a/include/cglm/structs/io.h +++ b/include/cglm/structs/io.h @@ -73,28 +73,10 @@ void glms_aabb_print(vec3s bbox[2], const char * __restrict tag, FILE * __restrict ostream) { - int i, j; + vec3 rawBbox[2]; -#define m 3 - - fprintf(ostream, "AABB (%s):\n", tag ? tag : "float"); - - for (i = 0; i < 2; i++) { - fprintf(ostream, "\t|"); - - for (j = 0; j < m; j++) { - fprintf(ostream, "%0.4f", bbox[i].raw[j]); - - if (j != m - 1) - fprintf(ostream, "\t"); - } - - fprintf(ostream, "|\n"); - } - - fprintf(ostream, "\n"); - -#undef m + glms_vec3_unpack(rawBbox, bbox, 2); + glm_aabb_print(rawBbox, tag, ostream); } #endif /* cglm_ios_h */ diff --git a/include/cglm/structs/mat4.h b/include/cglm/structs/mat4.h index 72686cd..40c7291 100644 --- a/include/cglm/structs/mat4.h +++ b/include/cglm/structs/mat4.h @@ -241,7 +241,7 @@ CGLM_INLINE mat4s glms_mat4_mulN(mat4s * __restrict matrices[], uint32_t len) { CGLM_ALIGN_MAT mat4s r = GLMS_MAT4_IDENTITY_INIT; - uint32_t i; + size_t i; for (i = 0; i < len; i++) { r = glms_mat4_mul(r, *matrices[i]); diff --git a/include/cglm/structs/vec3.h b/include/cglm/structs/vec3.h index ed77c4a..312d59a 100644 --- a/include/cglm/structs/vec3.h +++ b/include/cglm/structs/vec3.h @@ -40,6 +40,30 @@ glms_vec3_copy(vec3s v) { return r; } +CGLM_INLINE +void +glms_vec3_pack(vec3s dst[], vec3 src[], size_t len) { + size_t i; + + for (i = 0; i < len; i++) { + dst[i].x = src[i][0]; + dst[i].y = src[i][1]; + dst[i].z = src[i][2]; + } +} + +CGLM_INLINE +void +glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len) { + size_t i; + + for (i = 0; i < len; i++) { + dst[i][0] = src[i].x; + dst[i][1] = src[i].y; + dst[i][2] = src[i].z; + } +} + CGLM_INLINE vec3s glms_vec3_zero() { @@ -65,13 +89,13 @@ glms_vec3_dot(vec3s a, vec3s b) { CGLM_INLINE float glms_vec3_norm2(vec3s v) { - glm_vec3_norm2(v.raw); + return glm_vec3_norm2(v.raw); } CGLM_INLINE float glms_vec3_norm(vec3s v) { - glm_vec3_norm(v.raw); + return glm_vec3_norm(v.raw); } CGLM_INLINE @@ -148,50 +172,44 @@ glms_vec3_divs(vec3s a, float s) { CGLM_INLINE vec3s -glms_vec3_addadd(vec3s a, vec3s b) { - vec3s r; - glm_vec3_addadd(a.raw, b.raw, r.raw); - return r; +glms_vec3_addadd(vec3s a, vec3s b, vec3s dest) { + glm_vec3_addadd(a.raw, b.raw, dest.raw); + return dest; } CGLM_INLINE vec3s -glms_vec3_subadd(vec3s a, vec3s b) { - vec3s r; - glm_vec3_subadd(a.raw, b.raw, r.raw); - return r; +glms_vec3_subadd(vec3s a, vec3s b, vec3s dest) { + glm_vec3_subadd(a.raw, b.raw, dest.raw); + return dest; } CGLM_INLINE vec3s -glms_vec3_muladd(vec3s a, vec3s b) { - vec3s r; - glm_vec3_muladd(a.raw, b.raw, r.raw); - return r; +glms_vec3_muladd(vec3s a, vec3s b, vec3s dest) { + glm_vec3_muladd(a.raw, b.raw, dest.raw); + return dest; } CGLM_INLINE vec3s -glms_vec3_muladds(vec3s a, float s) { - vec3s r; - glm_vec3_muladds(a.raw, s, r.raw); - return r; +glms_vec3_muladds(vec3s a, float s, vec3s dest) { + glm_vec3_muladds(a.raw, s, dest.raw); + return dest; } CGLM_INLINE vec3s -glms_vec3_maxadd(vec3s a, vec3s b) { - vec3s r; - glm_vec3_maxadd(a.raw, b.raw, r.raw); - return r; +glms_vec3_maxadd(vec3s a, vec3s b, vec3s dest) { + glm_vec3_maxadd(a.raw, b.raw, dest.raw); + return dest; } CGLM_INLINE vec3s -glms_vec3_minadd(vec3s a, vec3s b) { - vec3s r; - glm_vec3_minadd(a.raw, b.raw, r.raw); - return r; +glms_vec3_minadd(vec3s a, vec3s b, vec3s dest) { + glm_vec3_minadd(a.raw, b.raw, dest.raw); + return dest; } CGLM_INLINE @@ -201,22 +219,6 @@ glms_vec3_flipsign(vec3s v) { return v; } -CGLM_INLINE -vec3s -glms_vec3_flipsign_to(vec3s v) { - vec3s r; - glm_vec3_flipsign_to(v.raw, r.raw); - return r; -} - -CGLM_INLINE -vec3s -glms_vec3_negate_to(vec3s v) { - vec3s r; - glm_vec3_negate_to(v.raw, r.raw); - return r; -} - CGLM_INLINE vec3s glms_vec3_negate(vec3s v) { @@ -231,14 +233,6 @@ glms_vec3_inv(vec3s v) { return v; } -CGLM_INLINE -vec3s -glms_vec3_inv_to(vec3s v) { - vec3s r; - glm_vec3_inv_to(v.raw, r.raw); - return r; -} - CGLM_INLINE vec3s glms_vec3_normalize(vec3s v) { @@ -246,14 +240,6 @@ glms_vec3_normalize(vec3s v) { return v; } -CGLM_INLINE -vec3s -glms_vec3_normalize_to(vec3s v) { - vec3s r; - glm_vec3_normalize_to(v.raw, r.raw); - return r; -} - CGLM_INLINE vec3s glms_vec3_cross(vec3s a, vec3s b) { @@ -291,17 +277,17 @@ glms_vec3_rotate(vec3s v, float angle, vec3s axis) { CGLM_INLINE vec3s -glms_vec3_rotate_m4(mat4 m, vec3s v) { +glms_vec3_rotate_m4(mat4s m, vec3s v) { vec3s r; - glm_vec3_rotate_m4(m, v.raw, r.raw); + glm_vec3_rotate_m4(m.raw, v.raw, r.raw); return r; } CGLM_INLINE vec3s -glms_vec3_rotate_m3(mat3 m, vec3s v) { +glms_vec3_rotate_m3(mat3s m, vec3s v) { vec3s r; - glm_vec3_rotate_m3(m, v.raw, r.raw); + glm_vec3_rotate_m3(m.raw, v.raw, r.raw); return r; } @@ -387,12 +373,4 @@ glms_normalize(vec3s v) { return v; } -CGLM_INLINE -vec3s -glms_normalize_to(vec3s v) { - vec3s r; - glm_normalize_to(v.raw, r.raw); - return r; -} - #endif /* cglm_vec3s_h */ diff --git a/include/cglm/structs/vec4.h b/include/cglm/structs/vec4.h index c8ec509..956fee1 100644 --- a/include/cglm/structs/vec4.h +++ b/include/cglm/structs/vec4.h @@ -54,6 +54,29 @@ glms_vec4_ucopy(vec4s v) { return r; } +CGLM_INLINE +void +glms_vec4_pack(vec4s dst[], vec4 src[], size_t len) { + size_t i; + + for (i = 0; i < len; i++) { + dst[i].x = src[i][0]; + dst[i].y = src[i][1]; + dst[i].z = src[i][2]; + } +} + +CGLM_INLINE +void +glms_vec4_unpack(vec4 dst[], vec4s src[], size_t len) { + size_t i; + + for (i = 0; i < len; i++) { + dst[i][0] = src[i].x; + dst[i][1] = src[i].y; + dst[i][2] = src[i].z; + } +} CGLM_INLINE float @@ -147,50 +170,44 @@ glms_vec4_divs(vec4s v, float s) { CGLM_INLINE vec4s -glms_vec4_addadd(vec4s a, vec4s b) { - vec4s r; - glm_vec4_addadd(a.raw, b.raw, r.raw); - return r; +glms_vec4_addadd(vec4s a, vec4s b, vec4s dest) { + glm_vec4_addadd(a.raw, b.raw, dest.raw); + return dest; } CGLM_INLINE vec4s -glms_vec4_subadd(vec4s a, vec4s b) { - vec4s r; - glm_vec4_subadd(a.raw, b.raw, r.raw); - return r; +glms_vec4_subadd(vec4s a, vec4s b, vec4s dest) { + glm_vec4_subadd(a.raw, b.raw, dest.raw); + return dest; } CGLM_INLINE vec4s -glms_vec4_muladd(vec4s a, vec4s b) { - vec4s r; - glm_vec4_muladd(a.raw, b.raw, r.raw); - return r; +glms_vec4_muladd(vec4s a, vec4s b, vec4s dest) { + glm_vec4_muladd(a.raw, b.raw, dest.raw); + return dest; } CGLM_INLINE vec4s -glms_vec4_muladds(vec4s a, float s) { - vec4s r; - glm_vec4_muladds(a.raw, s, r.raw); - return r; +glms_vec4_muladds(vec4s a, float s, vec4s dest) { + glm_vec4_muladds(a.raw, s, dest.raw); + return dest; } CGLM_INLINE vec4s -glms_vec4_maxadd(vec4s a, vec4s b) { - vec4s r; - glm_vec4_maxadd(a.raw, b.raw, r.raw); - return r; +glms_vec4_maxadd(vec4s a, vec4s b, vec4s dest) { + glm_vec4_maxadd(a.raw, b.raw, dest.raw); + return dest; } CGLM_INLINE vec4s -glms_vec4_minadd(vec4s a, vec4s b) { - vec4s r; - glm_vec4_minadd(a.raw, b.raw, r.raw); - return r; +glms_vec4_minadd(vec4s a, vec4s b, vec4s dest) { + glm_vec4_minadd(a.raw, b.raw, dest.raw); + return dest; } CGLM_INLINE @@ -251,4 +268,12 @@ glms_vec4_lerp(vec4s from, vec4s to, float t) { return r; } +CGLM_INLINE +vec4s +glms_vec4_cubic(float s) { + vec4s r; + glm_vec4_cubic(s, r.raw); + return r; +} + #endif /* cglm_vec4s_h */ From fd3b0634d273929dc4dc64ad4f7617e9f3910708 Mon Sep 17 00:00:00 2001 From: acoto87 Date: Mon, 20 May 2019 17:11:10 -0500 Subject: [PATCH 277/292] Change for function that output multiple values - Now the functions that output mutliple values, such as glms_decompose_rs and glms_decompose receive pointers. - Added missing comments to struct/vec3 and struct/vec4 files. --- include/cglm/structs/affine.h | 16 +- include/cglm/structs/box.h | 45 ++-- include/cglm/structs/vec3-ext.h | 98 ++++++++ include/cglm/structs/vec3.h | 422 +++++++++++++++++++++++++++++++- include/cglm/structs/vec4-ext.h | 98 ++++++++ include/cglm/structs/vec4.h | 321 +++++++++++++++++++++++- 6 files changed, 947 insertions(+), 53 deletions(-) diff --git a/include/cglm/structs/affine.h b/include/cglm/structs/affine.h index 72cab13..481aaa3 100644 --- a/include/cglm/structs/affine.h +++ b/include/cglm/structs/affine.h @@ -25,8 +25,8 @@ CGLM_INLINE mat4s glms_rotate_atm(mat4s m, vec3s pivot, float angle, vec3s axis); CGLM_INLINE vec3s glms_decompose_scalev(mat4s m); CGLM_INLINE bool glms_uniscaled(mat4s m); - CGLM_INLINE void glms_decompose_rs(mat4s m, mat4s r, vec3s s); - CGLM_INLINE void glms_decompose(mat4s m, vec4s t, mat4s r, vec3s s); + CGLM_INLINE void glms_decompose_rs(mat4s m, mat4s * r, vec3s * s); + CGLM_INLINE void glms_decompose(mat4s m, vec4s t, mat4s * r, vec3s * s); */ #ifndef cglm_affines_h @@ -315,10 +315,8 @@ glms_uniscaled(mat4s m) { */ CGLM_INLINE void -glms_decompose_rs(mat4s m, mat4s r, vec3s s) { - // FIX: Modify param - // - glm_decompose_rs(m.raw, r.raw, s.raw); +glms_decompose_rs(mat4s m, mat4s * __restrict r, vec3s * __restrict s) { + glm_decompose_rs(m.raw, r->raw, s->raw); } /*! @@ -332,10 +330,8 @@ glms_decompose_rs(mat4s m, mat4s r, vec3s s) { */ CGLM_INLINE void -glms_decompose(mat4s m, vec4s t, mat4s r, vec3s s) { - // FIX: Modify param - // - glm_decompose(m.raw, t.raw, r.raw, s.raw); +glms_decompose(mat4s m, vec4s * __restrict t, mat4s * __restrict r, vec3s * __restrict s) { + glm_decompose(m.raw, t->raw, r->raw, s->raw); } #endif /* cglm_affines_h */ diff --git a/include/cglm/structs/box.h b/include/cglm/structs/box.h index ca7c3a6..4251bd7 100644 --- a/include/cglm/structs/box.h +++ b/include/cglm/structs/box.h @@ -162,7 +162,7 @@ glms_aabb_isvalid(vec3s box[2]) { CGLM_INLINE float glms_aabb_size(vec3s box[2]) { - return glms_vec3_distance(box[0], box[1]); + return glm_vec3_distance(box[0].raw, box[1].raw); } /*! @@ -197,9 +197,12 @@ glms_aabb_center(vec3s box[2]) { CGLM_INLINE bool glms_aabb_aabb(vec3s box[2], vec3s other[2]) { - return (box[0].x <= other[1].x && box[1].x >= other[0].x) - && (box[0].y <= other[1].y && box[1].y >= other[0].y) - && (box[0].z <= other[1].z && box[1].z >= other[0].z); + vec3 rawBox[2]; + vec3 rawOther[2]; + + glms_vec3_unpack(rawBox, box, 2); + glms_vec3_unpack(rawOther, other, 2); + return glm_aabb_aabb(rawBox, rawOther); } /*! @@ -213,19 +216,11 @@ glms_aabb_aabb(vec3s box[2], vec3s other[2]) { */ CGLM_INLINE bool -glms_aabb_sphere(vec3s box[2], vec4 s) { - float dmin; - int a, b, c; - - a = s[0] >= box[0].x; - b = s[1] >= box[0].y; - c = s[2] >= box[0].z; - - dmin = glm_pow2(s[0] - box[a].x) - + glm_pow2(s[1] - box[b].y) - + glm_pow2(s[2] - box[c].z); - - return dmin <= glm_pow2(s[3]); +glms_aabb_sphere(vec3s box[2], vec4s s) { + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + return glm_aabb_sphere(rawBox, s.raw); } /*! @@ -237,9 +232,10 @@ glms_aabb_sphere(vec3s box[2], vec4 s) { CGLM_INLINE bool glms_aabb_point(vec3s box[2], vec3s point) { - return (point.x >= box[0].x && point.x <= box[1].x) - && (point.y >= box[0].y && point.y <= box[1].y) - && (point.z >= box[0].z && point.z <= box[1].z); + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + return glm_aabb_point(rawBox, point.raw); } /*! @@ -251,9 +247,12 @@ glms_aabb_point(vec3s box[2], vec3s point) { CGLM_INLINE bool glms_aabb_contains(vec3s box[2], vec3s other[2]) { - return (box[0].x <= other[0].x && box[1].x >= other[1].x) - && (box[0].y <= other[0].y && box[1].y >= other[1].y) - && (box[0].z <= other[0].z && box[1].z >= other[1].z); + vec3 rawBox[2]; + vec3 rawOther[2]; + + glms_vec3_unpack(rawBox, box, 2); + glms_vec3_unpack(rawOther, other, 2); + return glm_aabb_contains(rawBox, rawOther); } #endif /* cglm_boxs_h */ diff --git a/include/cglm/structs/vec3-ext.h b/include/cglm/structs/vec3-ext.h index 0449b3d..2e5e729 100644 --- a/include/cglm/structs/vec3-ext.h +++ b/include/cglm/structs/vec3-ext.h @@ -5,6 +5,27 @@ * Full license can be found in the LICENSE file */ +/*! + * @brief SIMD like functions + */ + +/* + Functions: + CGLM_INLINE vec3s glms_vec3_broadcast(float val); + CGLM_INLINE bool glms_vec3_eq(vec3s v, float val); + CGLM_INLINE bool glms_vec3_eq_eps(vec3s v, float val); + CGLM_INLINE bool glms_vec3_eq_all(vec3s v); + CGLM_INLINE bool glms_vec3_eqv(vec3s a, vec3s b); + CGLM_INLINE bool glms_vec3_eqv_eps(vec3s a, vec3s b); + CGLM_INLINE float glms_vec3_max(vec3s v); + CGLM_INLINE float glms_vec3_min(vec3s v); + CGLM_INLINE bool glms_vec3_isnan(vec3s v); + CGLM_INLINE bool glms_vec3_isinf(vec3s v); + CGLM_INLINE bool glms_vec3_isvalid(vec3s v); + CGLM_INLINE vec3s glms_vec3_sign(vec3s v); + CGLM_INLINE vec3s glms_vec3_sqrt(vec3s v); + */ + #ifndef cglm_vec3s_ext_h #define cglm_vec3s_ext_h @@ -13,6 +34,12 @@ #include "../util.h" #include "../vec3-ext.h" +/*! + * @brief fill a vector with specified value + * + * @param[in] val value + * @returns dest + */ CGLM_INLINE vec3s glms_vec3_broadcast(float val) { @@ -21,66 +48,131 @@ glms_vec3_broadcast(float val) { return r; } +/*! + * @brief check if vector is equal to value (without epsilon) + * + * @param[in] v vector + * @param[in] val value + */ CGLM_INLINE bool glms_vec3_eq(vec3s v, float val) { return glm_vec3_eq(v.raw, val); } +/*! + * @brief check if vector is equal to value (with epsilon) + * + * @param[in] v vector + * @param[in] val value + */ CGLM_INLINE bool glms_vec3_eq_eps(vec3s v, float val) { return glm_vec3_eq_eps(v.raw, val); } +/*! + * @brief check if vectors members are equal (without epsilon) + * + * @param[in] v vector + */ CGLM_INLINE bool glms_vec3_eq_all(vec3s v) { return glm_vec3_eq_all(v.raw); } +/*! + * @brief check if vector is equal to another (without epsilon) + * + * @param[in] a vector + * @param[in] b vector + */ CGLM_INLINE bool glms_vec3_eqv(vec3s a, vec3s b) { return glm_vec3_eqv(a.raw, b.raw); } +/*! + * @brief check if vector is equal to another (with epsilon) + * + * @param[in] a vector + * @param[in] b vector + */ CGLM_INLINE bool glms_vec3_eqv_eps(vec3s a, vec3s b) { return glm_vec3_eqv_eps(a.raw, b.raw); } +/*! + * @brief max value of vector + * + * @param[in] v vector + */ CGLM_INLINE float glms_vec3_max(vec3s v) { return glm_vec3_max(v.raw); } +/*! + * @brief min value of vector + * + * @param[in] v vector + */ CGLM_INLINE float glms_vec3_min(vec3s v) { return glm_vec3_min(v.raw); } +/*! + * @brief check if all items are NaN (not a number) + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ CGLM_INLINE bool glms_vec3_isnan(vec3s v) { return glm_vec3_isnan(v.raw); } +/*! + * @brief check if all items are INFINITY + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ CGLM_INLINE bool glms_vec3_isinf(vec3s v) { return glm_vec3_isinf(v.raw); } +/*! + * @brief check if all items are valid number + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ CGLM_INLINE bool glms_vec3_isvalid(vec3s v) { return glm_vec3_isvalid(v.raw); } +/*! + * @brief get sign of 32 bit float as +1, -1, 0 + * + * Important: It returns 0 for zero/NaN input + * + * @param v vector + * @returns sign vector + */ CGLM_INLINE vec3s glms_vec3_sign(vec3s v) { @@ -89,6 +181,12 @@ glms_vec3_sign(vec3s v) { return r; } +/*! + * @brief square root of each vector item + * + * @param[in] v vector + * @returns destination vector + */ CGLM_INLINE vec3s glms_vec3_sqrt(vec3s v) { diff --git a/include/cglm/structs/vec3.h b/include/cglm/structs/vec3.h index 312d59a..766742b 100644 --- a/include/cglm/structs/vec3.h +++ b/include/cglm/structs/vec3.h @@ -5,6 +5,67 @@ * Full license can be found in the LICENSE file */ +/* + Macros: + GLMS_VEC3_ONE_INIT + GLMS_VEC3_ZERO_INIT + GLMS_VEC3_ONE + GLMS_VEC3_ZERO + GLMS_YUP + GLMS_ZUP + GLMS_XUP + + Functions: + CGLM_INLINE vec3s glms_vec3(vec4s v4); + CGLM_INLINE vec3s glms_vec3_copy(vec3s v); + CGLM_INLINE void glms_vec3_pack(vec3s dst[], vec3 src[], size_t len); + CGLM_INLINE void glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len); + CGLM_INLINE vec3s glms_vec3_zero(); + CGLM_INLINE vec3s glms_vec3_one(); + CGLM_INLINE float glms_vec3_dot(vec3s a, vec3s b); + CGLM_INLINE float glms_vec3_norm2(vec3s v); + CGLM_INLINE float glms_vec3_norm(vec3s v); + CGLM_INLINE vec3s glms_vec3_add(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_adds(vec3s a, float s); + CGLM_INLINE vec3s glms_vec3_sub(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_subs(vec3s a, float s); + CGLM_INLINE vec3s glms_vec3_mul(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_scale(vec3s v, float s); + CGLM_INLINE vec3s glms_vec3_scale_as(vec3s v, float s); + CGLM_INLINE vec3s glms_vec3_div(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_divs(vec3s a, float s); + CGLM_INLINE vec3s glms_vec3_addadd(vec3s a, vec3s b, vec3s dest); + CGLM_INLINE vec3s glms_vec3_subadd(vec3s a, vec3s b, vec3s dest); + CGLM_INLINE vec3s glms_vec3_muladd(vec3s a, vec3s b, vec3s dest); + 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_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); + CGLM_INLINE float glms_vec3_distance(vec3s a, vec3s b); + CGLM_INLINE float glms_vec3_angle(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_rotate(vec3s v, float angle, vec3s axis); + CGLM_INLINE vec3s glms_vec3_rotate_m4(mat4s m, vec3s v); + CGLM_INLINE vec3s glms_vec3_rotate_m3(mat3s m, vec3s v); + CGLM_INLINE vec3s glms_vec3_proj(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_center(vec3s a, vec3s b); + CGLM_INLINE float glms_vec3_distance2(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_maxv(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_minv(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_ortho(vec3s v); + CGLM_INLINE vec3s glms_vec3_clamp(vec3s v, float minVal, float maxVal); + CGLM_INLINE vec3s glms_vec3_lerp(vec3s from, vec3s to, float t); + + Convenient: + CGLM_INLINE vec3s glms_cross(vec3s a, vec3s b); + CGLM_INLINE float glms_dot(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_normalize(vec3s v); + */ + #ifndef cglm_vec3s_h #define cglm_vec3s_h @@ -24,6 +85,12 @@ #define GLMS_ZUP ((vec3s){0.0f, 0.0f, 1.0f}) #define GLMS_XUP ((vec3s){1.0f, 0.0f, 0.0f}) +/*! + * @brief init vec3 using vec4 + * + * @param[in] v4 vector4 + * @returns destination + */ CGLM_INLINE vec3s glms_vec3(vec4s v4) { @@ -32,6 +99,12 @@ glms_vec3(vec4s v4) { return r; } +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] a source + * @returns destination + */ CGLM_INLINE vec3s glms_vec3_copy(vec3s v) { @@ -40,6 +113,13 @@ glms_vec3_copy(vec3s v) { return r; } +/*! + * @brief pack an array of vec3 into an array of vec3s + * + * @param[out] dst array of vec3 + * @param[in] src array of vec3s + * @param[in] len number of elements + */ CGLM_INLINE void glms_vec3_pack(vec3s dst[], vec3 src[], size_t len) { @@ -52,6 +132,13 @@ glms_vec3_pack(vec3s dst[], vec3 src[], size_t len) { } } +/*! + * @brief unpack an array of vec3s into an array of vec3 + * + * @param[out] dst array of vec3s + * @param[in] src array of vec3 + * @param[in] len number of elements + */ CGLM_INLINE void glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len) { @@ -64,6 +151,12 @@ glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len) { } } +/*! + * @brief make vector zero + * + * @param[in] v vector + * @returns zero vector + */ CGLM_INLINE vec3s glms_vec3_zero() { @@ -72,6 +165,12 @@ glms_vec3_zero() { return r; } +/*! + * @brief make vector one + * + * @param[in] v vector + * @returns one vector + */ CGLM_INLINE vec3s glms_vec3_one() { @@ -80,24 +179,57 @@ glms_vec3_one() { return r; } +/*! + * @brief vec3 dot product + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ CGLM_INLINE float glms_vec3_dot(vec3s a, vec3s b) { return glm_vec3_dot(a.raw, b.raw); } +/*! + * @brief norm * norm (magnitude) of vec + * + * we can use this func instead of calling norm * norm, because it would call + * sqrtf fuction twice but with this func we can avoid func call, maybe this is + * not good name for this func + * + * @param[in] v vector + * + * @return norm * norm + */ CGLM_INLINE float glms_vec3_norm2(vec3s v) { return glm_vec3_norm2(v.raw); } +/*! + * @brief norm (magnitude) of vec3 + * + * @param[in] v vector + * + * @return norm + */ CGLM_INLINE float glms_vec3_norm(vec3s v) { return glm_vec3_norm(v.raw); } +/*! + * @brief add a vector to b vector store result in dest + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns destination vector + */ CGLM_INLINE vec3s glms_vec3_add(vec3s a, vec3s b) { @@ -106,6 +238,13 @@ glms_vec3_add(vec3s a, vec3s b) { return r; } +/*! + * @brief add scalar to v vector store result in dest (d = v + s) + * + * @param[in] v vector + * @param[in] s scalar + * @returns destination vector + */ CGLM_INLINE vec3s glms_vec3_adds(vec3s a, float s) { @@ -114,6 +253,13 @@ glms_vec3_adds(vec3s a, float s) { return r; } +/*! + * @brief subtract b vector from a vector store result in dest + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns destination vector + */ CGLM_INLINE vec3s glms_vec3_sub(vec3s a, vec3s b) { @@ -122,6 +268,13 @@ glms_vec3_sub(vec3s a, vec3s b) { return r; } +/*! + * @brief subtract scalar from v vector store result in dest (d = v - s) + * + * @param[in] v vector + * @param[in] s scalar + * @returns destination vector + */ CGLM_INLINE vec3s glms_vec3_subs(vec3s a, float s) { @@ -130,6 +283,13 @@ glms_vec3_subs(vec3s a, float s) { return r; } +/*! + * @brief multiply two vector (component-wise multiplication) + * + * @param a vector1 + * @param b vector2 + * @returns v3 = (a[0] * b[0], a[1] * b[1], a[2] * b[2]) + */ CGLM_INLINE vec3s glms_vec3_mul(vec3s a, vec3s b) { @@ -138,6 +298,13 @@ glms_vec3_mul(vec3s a, vec3s b) { return r; } +/*! + * @brief multiply/scale vec3 vector with scalar: result = v * s + * + * @param[in] v vector + * @param[in] s scalar + * @returns destination vector + */ CGLM_INLINE vec3s glms_vec3_scale(vec3s v, float s) { @@ -146,6 +313,13 @@ glms_vec3_scale(vec3s v, float s) { return r; } +/*! + * @brief make vec3 vector scale as specified: result = unit(v) * s + * + * @param[in] v vector + * @param[in] s scalar + * @returns destination vector + */ CGLM_INLINE vec3s glms_vec3_scale_as(vec3s v, float s) { @@ -154,6 +328,13 @@ glms_vec3_scale_as(vec3s v, float s) { return r; } +/*! + * @brief div vector with another component-wise division: d = a / b + * + * @param[in] a vector 1 + * @param[in] b vector 2 + * @returns result = (a[0]/b[0], a[1]/b[1], a[2]/b[2]) + */ CGLM_INLINE vec3s glms_vec3_div(vec3s a, vec3s b) { @@ -162,6 +343,13 @@ glms_vec3_div(vec3s a, vec3s b) { return r; } +/*! + * @brief div vector with scalar: d = v / s + * + * @param[in] v vector + * @param[in] s scalar + * @returns result = (a[0]/s, a[1]/s, a[2]/s) + */ CGLM_INLINE vec3s glms_vec3_divs(vec3s a, float s) { @@ -170,6 +358,15 @@ glms_vec3_divs(vec3s a, float s) { return r; } +/*! + * @brief add two vectors and add result to sum + * + * 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_addadd(vec3s a, vec3s b, vec3s dest) { @@ -177,6 +374,15 @@ glms_vec3_addadd(vec3s a, vec3s b, vec3s dest) { return dest; } +/*! + * @brief sub two vectors and add 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_subadd(vec3s a, vec3s b, vec3s dest) { @@ -184,6 +390,15 @@ glms_vec3_subadd(vec3s a, vec3s b, vec3s dest) { return dest; } +/*! + * @brief mul two vectors and add 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_muladd(vec3s a, vec3s b, vec3s dest) { @@ -191,6 +406,15 @@ glms_vec3_muladd(vec3s a, vec3s b, vec3s dest) { return dest; } +/*! + * @brief mul vector with scalar and add result to sum + * + * 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_muladds(vec3s a, float s, vec3s dest) { @@ -198,6 +422,15 @@ glms_vec3_muladds(vec3s a, float s, vec3s dest) { return dest; } +/*! + * @brief add max of two vector to result/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_maxadd(vec3s a, vec3s b, vec3s dest) { @@ -205,6 +438,15 @@ glms_vec3_maxadd(vec3s a, vec3s b, vec3s dest) { return dest; } +/*! + * @brief add min of two vector to result/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_minadd(vec3s a, vec3s b, vec3s dest) { @@ -212,6 +454,12 @@ glms_vec3_minadd(vec3s a, vec3s b, vec3s dest) { return dest; } +/*! + * @brief negate vector components and store result in dest + * + * @param[in] v vector + * @returns result vector + */ CGLM_INLINE vec3s glms_vec3_flipsign(vec3s v) { @@ -219,6 +467,12 @@ glms_vec3_flipsign(vec3s v) { return v; } +/*! + * @brief negate vector components + * + * @param[in] v vector + * @returns negated vector + */ CGLM_INLINE vec3s glms_vec3_negate(vec3s v) { @@ -226,13 +480,12 @@ glms_vec3_negate(vec3s v) { return v; } -CGLM_INLINE -vec3s -glms_vec3_inv(vec3s v) { - glm_vec3_inv(v.raw); - return v; -} - +/*! + * @brief normalize vec3 and store result in same vec + * + * @param[in] v vector + * @returns normalized vector + */ CGLM_INLINE vec3s glms_vec3_normalize(vec3s v) { @@ -240,6 +493,13 @@ glms_vec3_normalize(vec3s v) { return v; } +/*! + * @brief cross product of two vector (RH) + * + * @param[in] a vector 1 + * @param[in] b vector 2 + * @returns destination + */ CGLM_INLINE vec3s glms_vec3_cross(vec3s a, vec3s b) { @@ -248,6 +508,13 @@ glms_vec3_cross(vec3s a, vec3s b) { return r; } +/*! + * @brief cross product of two vector (RH) and normalize the result + * + * @param[in] a vector 1 + * @param[in] b vector 2 + * @returns destination + */ CGLM_INLINE vec3s glms_vec3_crossn(vec3s a, vec3s b) { @@ -256,18 +523,28 @@ glms_vec3_crossn(vec3s a, vec3s b) { return r; } -CGLM_INLINE -float -glms_vec3_distance(vec3s a, vec3s b) { - return glm_vec3_distance(a.raw, b.raw); -} - +/*! + * @brief angle betwen two vector + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return angle as radians + */ CGLM_INLINE float glms_vec3_angle(vec3s a, vec3s b) { return glm_vec3_angle(a.raw, b.raw); } +/*! + * @brief rotate vec3 around axis by angle using Rodrigues' rotation formula + * + * @param[in] v vector + * @param[in] axis axis vector (must be unit vector) + * @param[in] angle angle by radians + * @returns rotated vector + */ CGLM_INLINE vec3s glms_vec3_rotate(vec3s v, float angle, vec3s axis) { @@ -275,6 +552,19 @@ glms_vec3_rotate(vec3s v, float angle, vec3s axis) { return v; } +/*! + * @brief apply rotation matrix to vector + * + * matrix format should be (no perspective): + * a b c x + * e f g y + * i j k z + * 0 0 0 w + * + * @param[in] m affine matrix or rot matrix + * @param[in] v vector + * @returns rotated vector + */ CGLM_INLINE vec3s glms_vec3_rotate_m4(mat4s m, vec3s v) { @@ -283,6 +573,13 @@ glms_vec3_rotate_m4(mat4s m, vec3s v) { return r; } +/*! + * @brief apply rotation matrix to vector + * + * @param[in] m affine matrix or rot matrix + * @param[in] v vector + * @returns rotated vector + */ CGLM_INLINE vec3s glms_vec3_rotate_m3(mat3s m, vec3s v) { @@ -291,6 +588,13 @@ glms_vec3_rotate_m3(mat3s m, vec3s v) { return r; } +/*! + * @brief project a vector onto b vector + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns projected vector + */ CGLM_INLINE vec3s glms_vec3_proj(vec3s a, vec3s b) { @@ -299,6 +603,13 @@ glms_vec3_proj(vec3s a, vec3s b) { return r; } +/** + * @brief find center point of two vector + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns center point + */ CGLM_INLINE vec3s glms_vec3_center(vec3s a, vec3s b) { @@ -307,12 +618,39 @@ glms_vec3_center(vec3s a, vec3s b) { return r; } +/** + * @brief squared distance between two vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @return squared distance (distance * distance) + */ CGLM_INLINE float glms_vec3_distance2(vec3s a, vec3s b) { return glm_vec3_distance2(a.raw, b.raw); } +/** + * @brief distance between two vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @return distance + */ +CGLM_INLINE +float +glms_vec3_distance(vec3s a, vec3s b) { + return glm_vec3_distance(a.raw, b.raw); +} + +/*! + * @brief max values of vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns destination + */ CGLM_INLINE vec3s glms_vec3_maxv(vec3s a, vec3s b) { @@ -321,6 +659,13 @@ glms_vec3_maxv(vec3s a, vec3s b) { return r; } +/*! + * @brief min values of vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns destination + */ CGLM_INLINE vec3s glms_vec3_minv(vec3s a, vec3s b) { @@ -329,6 +674,12 @@ glms_vec3_minv(vec3s a, vec3s b) { return r; } +/*! + * @brief possible orthogonal/perpendicular vector + * + * @param[in] v vector + * @returns orthogonal/perpendicular vector + */ CGLM_INLINE vec3s glms_vec3_ortho(vec3s v) { @@ -337,6 +688,14 @@ glms_vec3_ortho(vec3s v) { return r; } +/*! + * @brief clamp vector's individual members between min and max values + * + * @param[in] v vector + * @param[in] minVal minimum value + * @param[in] maxVal maximum value + * @returns clamped vector + */ CGLM_INLINE vec3s glms_vec3_clamp(vec3s v, float minVal, float maxVal) { @@ -344,6 +703,16 @@ glms_vec3_clamp(vec3s v, float minVal, float maxVal) { return v; } +/*! + * @brief linear interpolation between two vector + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) clamped between 0 and 1 + * @returns destination + */ CGLM_INLINE vec3s glms_vec3_lerp(vec3s from, vec3s to, float t) { @@ -352,6 +721,15 @@ glms_vec3_lerp(vec3s from, vec3s to, float t) { return r; } +/*! + * @brief vec3 cross product + * + * this is just convenient wrapper + * + * @param[in] a source 1 + * @param[in] b source 2 + * @returns destination + */ CGLM_INLINE vec3s glms_cross(vec3s a, vec3s b) { @@ -360,12 +738,30 @@ glms_cross(vec3s a, vec3s b) { return r; } +/*! + * @brief vec3 dot product + * + * this is just convenient wrapper + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ CGLM_INLINE float glms_dot(vec3s a, vec3s b) { return glm_dot(a.raw, b.raw); } +/*! + * @brief normalize vec3 and store result in same vec + * + * this is just convenient wrapper + * + * @param[in] v vector + * @returns normalized vector + */ CGLM_INLINE vec3s glms_normalize(vec3s v) { diff --git a/include/cglm/structs/vec4-ext.h b/include/cglm/structs/vec4-ext.h index 4fbb2d3..0b81b49 100644 --- a/include/cglm/structs/vec4-ext.h +++ b/include/cglm/structs/vec4-ext.h @@ -5,6 +5,27 @@ * Full license can be found in the LICENSE file */ +/*! + * @brief SIMD like functions + */ + +/* + Functions: + CGLM_INLINE vec4s glms_vec4_broadcast(float val); + CGLM_INLINE bool glms_vec4_eq(vec4s v, float val); + CGLM_INLINE bool glms_vec4_eq_eps(vec4s v, float val); + CGLM_INLINE bool glms_vec4_eq_all(vec4s v); + CGLM_INLINE bool glms_vec4_eqv(vec4s a, vec4s b); + CGLM_INLINE bool glms_vec4_eqv_eps(vec4s a, vec4s b); + CGLM_INLINE float glms_vec4_max(vec4s v); + CGLM_INLINE float glms_vec4_min(vec4s v); + CGLM_INLINE bool glms_vec4_isnan(vec4s v); + CGLM_INLINE bool glms_vec4_isinf(vec4s v); + CGLM_INLINE bool glms_vec4_isvalid(vec4s v); + CGLM_INLINE vec4s glms_vec4_sign(vec4s v); + CGLM_INLINE vec4s glms_vec4_sqrt(vec4s v); + */ + #ifndef cglm_vec4s_ext_h #define cglm_vec4s_ext_h @@ -13,6 +34,12 @@ #include "../util.h" #include "../vec4-ext.h" +/*! + * @brief fill a vector with specified value + * + * @param val value + * @returns dest + */ CGLM_INLINE vec4s glms_vec4_broadcast(float val) { @@ -21,66 +48,131 @@ glms_vec4_broadcast(float val) { return r; } +/*! + * @brief check if vector is equal to value (without epsilon) + * + * @param v vector + * @param val value + */ CGLM_INLINE bool glms_vec4_eq(vec4s v, float val) { return glm_vec4_eq(v.raw, val); } +/*! + * @brief check if vector is equal to value (with epsilon) + * + * @param v vector + * @param val value + */ CGLM_INLINE bool glms_vec4_eq_eps(vec4s v, float val) { return glm_vec4_eq_eps(v.raw, val); } +/*! + * @brief check if vectors members are equal (without epsilon) + * + * @param v vector + */ CGLM_INLINE bool glms_vec4_eq_all(vec4s v) { return glm_vec4_eq_all(v.raw); } +/*! + * @brief check if vector is equal to another (without epsilon) + * + * @param a vector + * @param b vector + */ CGLM_INLINE bool glms_vec4_eqv(vec4s a, vec4s b) { return glm_vec4_eqv(a.raw, b.raw); } +/*! + * @brief check if vector is equal to another (with epsilon) + * + * @param a vector + * @param b vector + */ CGLM_INLINE bool glms_vec4_eqv_eps(vec4s a, vec4s b) { return glm_vec4_eqv_eps(a.raw, b.raw); } +/*! + * @brief max value of vector + * + * @param v vector + */ CGLM_INLINE float glms_vec4_max(vec4s v) { return glm_vec4_max(v.raw); } +/*! + * @brief min value of vector + * + * @param v vector + */ CGLM_INLINE float glms_vec4_min(vec4s v) { return glm_vec4_min(v.raw); } +/*! + * @brief check if one of items is NaN (not a number) + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ CGLM_INLINE bool glms_vec4_isnan(vec4s v) { return glm_vec4_isnan(v.raw); } +/*! + * @brief check if one of items is INFINITY + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ CGLM_INLINE bool glms_vec4_isinf(vec4s v) { return glm_vec4_isinf(v.raw); } +/*! + * @brief check if all items are valid number + * you should only use this in DEBUG mode or very critical asserts + * + * @param[in] v vector + */ CGLM_INLINE bool glms_vec4_isvalid(vec4s v) { return glm_vec4_isvalid(v.raw); } +/*! + * @brief get sign of 32 bit float as +1, -1, 0 + * + * Important: It returns 0 for zero/NaN input + * + * @param v vector + * @returns sign vector + */ CGLM_INLINE vec4s glms_vec4_sign(vec4s v) { @@ -89,6 +181,12 @@ glms_vec4_sign(vec4s v) { return r; } +/*! + * @brief square root of each vector item + * + * @param[in] v vector + * @returns destination vector + */ CGLM_INLINE vec4s glms_vec4_sqrt(vec4s v) { diff --git a/include/cglm/structs/vec4.h b/include/cglm/structs/vec4.h index 956fee1..2f950a7 100644 --- a/include/cglm/structs/vec4.h +++ b/include/cglm/structs/vec4.h @@ -5,6 +5,51 @@ * Full license can be found in the LICENSE file */ +/* + Macros: + GLM_VEC4_ONE_INIT + GLM_VEC4_BLACK_INIT + GLM_VEC4_ZERO_INIT + GLM_VEC4_ONE + GLM_VEC4_BLACK + GLM_VEC4_ZERO + + Functions: + CGLM_INLINE vec4s glms_vec4(vec3s v3, float last); + CGLM_INLINE vec3s glms_vec4_copy3(vec4s v); + CGLM_INLINE vec4s glms_vec4_copy(vec4s v); + CGLM_INLINE vec4s glms_vec4_ucopy(vec4s v); + CGLM_INLINE void glms_vec4_pack(vec4s dst[], vec4 src[], size_t len); + CGLM_INLINE void glms_vec4_unpack(vec4 dst[], vec4s src[], size_t len); + CGLM_INLINE float glms_vec4_dot(vec4s a, vec4s b); + CGLM_INLINE float glms_vec4_norm2(vec4s v); + CGLM_INLINE float glms_vec4_norm(vec4s v); + CGLM_INLINE vec4s glms_vec4_add(vec4s a, vec4s b); + CGLM_INLINE vec4s glms_vec4_adds(vec4s v, float s); + CGLM_INLINE vec4s glms_vec4_sub(vec4s a, vec4s b); + CGLM_INLINE vec4s glms_vec4_subs(vec4s v, float s); + CGLM_INLINE vec4s glms_vec4_mul(vec4s a, vec4s b); + CGLM_INLINE vec4s glms_vec4_scale(vec4s v, float s); + CGLM_INLINE vec4s glms_vec4_scale_as(vec4s v, float s); + CGLM_INLINE vec4s glms_vec4_div(vec4s a, vec4s b); + CGLM_INLINE vec4s glms_vec4_divs(vec4s v, float s); + CGLM_INLINE vec4s glms_vec4_addadd(vec4s a, vec4s b, vec4s dest); + CGLM_INLINE vec4s glms_vec4_subadd(vec4s a, vec4s b, vec4s dest); + CGLM_INLINE vec4s glms_vec4_muladd(vec4s a, vec4s b, vec4s dest); + 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_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 vec4s glms_vec4_maxv(vec4s a, vec4s b); + CGLM_INLINE vec4s glms_vec4_minv(vec4s a, vec4s b); + CGLM_INLINE vec4s glms_vec4_clamp(vec4s v, float minVal, float maxVal); + CGLM_INLINE vec4s glms_vec4_lerp(vec4s from, vec4s to, float t); + CGLM_INLINE vec4s glms_vec4_cubic(float s); + */ + #ifndef cglm_vec4s_h #define cglm_vec4s_h @@ -22,6 +67,13 @@ #define GLMS_VEC4_BLACK ((vec4s)GLM_VEC4_BLACK_INIT) #define GLMS_VEC4_ZERO ((vec4s)GLM_VEC4_ZERO_INIT) +/*! + * @brief init vec4 using vec3 + * + * @param[in] v3 vector3 + * @param[in] last last item + * @returns destination + */ CGLM_INLINE vec4s glms_vec4(vec3s v3, float last) { @@ -30,6 +82,12 @@ glms_vec4(vec3s v3, float last) { return r; } +/*! + * @brief copy first 3 members of [a] to [dest] + * + * @param[in] a source + * @returns destination + */ CGLM_INLINE vec3s glms_vec4_copy3(vec4s v) { @@ -38,6 +96,12 @@ glms_vec4_copy3(vec4s v) { return r; } +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] v source + * @returns destination + */ CGLM_INLINE vec4s glms_vec4_copy(vec4s v) { @@ -46,6 +110,14 @@ glms_vec4_copy(vec4s v) { return r; } +/*! + * @brief copy all members of [a] to [dest] + * + * alignment is not required + * + * @param[in] v source + * @returns destination + */ CGLM_INLINE vec4s glms_vec4_ucopy(vec4s v) { @@ -54,6 +126,13 @@ glms_vec4_ucopy(vec4s v) { return r; } +/*! + * @brief pack an array of vec4 into an array of vec4s + * + * @param[out] dst array of vec4 + * @param[in] src array of vec4s + * @param[in] len number of elements + */ CGLM_INLINE void glms_vec4_pack(vec4s dst[], vec4 src[], size_t len) { @@ -66,6 +145,13 @@ glms_vec4_pack(vec4s dst[], vec4 src[], size_t len) { } } +/*! + * @brief unpack an array of vec4s into an array of vec4 + * + * @param[out] dst array of vec4s + * @param[in] src array of vec4 + * @param[in] len number of elements + */ CGLM_INLINE void glms_vec4_unpack(vec4 dst[], vec4s src[], size_t len) { @@ -78,24 +164,85 @@ glms_vec4_unpack(vec4 dst[], vec4s src[], size_t len) { } } +/*! + * @brief make vector zero + * + * @param[in] v vector + * @returns zero vector + */ +CGLM_INLINE +vec4s +glms_vec4_zero() { + vec4s r; + glm_vec4_zero(r.raw); + return r; +} + +/*! + * @brief make vector one + * + * @param[in] v vector + * @returns one vector + */ +CGLM_INLINE +vec4s +glms_vec4_one() { + vec4s r; + glm_vec4_one(r.raw); + return r; +} + +/*! + * @brief vec4 dot product + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ CGLM_INLINE float glms_vec4_dot(vec4s a, vec4s b) { return glm_vec4_dot(a.raw, b.raw); } +/*! + * @brief norm * norm (magnitude) of vec + * + * we can use this func instead of calling norm * norm, because it would call + * sqrtf fuction twice but with this func we can avoid func call, maybe this is + * not good name for this func + * + * @param[in] v vec4 + * + * @return norm * norm + */ CGLM_INLINE float glms_vec4_norm2(vec4s v) { return glm_vec4_norm2(v.raw); } +/*! + * @brief norm (magnitude) of vec4 + * + * @param[in] v vector + * + * @return norm + */ CGLM_INLINE float glms_vec4_norm(vec4s v) { return glm_vec4_norm(v.raw); } +/*! + * @brief add b vector to a vector store result in dest + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns destination vector + */ CGLM_INLINE vec4s glms_vec4_add(vec4s a, vec4s b) { @@ -104,6 +251,13 @@ glms_vec4_add(vec4s a, vec4s b) { return r; } +/*! + * @brief add scalar to v vector store result in dest (d = v + vec(s)) + * + * @param[in] v vector + * @param[in] s scalar + * @returns destination vector + */ CGLM_INLINE vec4s glms_vec4_adds(vec4s v, float s) { @@ -112,6 +266,13 @@ glms_vec4_adds(vec4s v, float s) { return r; } +/*! + * @brief subtract b vector from a vector store result in dest (d = a - b) + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns destination vector + */ CGLM_INLINE vec4s glms_vec4_sub(vec4s a, vec4s b) { @@ -120,6 +281,13 @@ glms_vec4_sub(vec4s a, vec4s b) { return r; } +/*! + * @brief subtract scalar from v vector store result in dest (d = v - vec(s)) + * + * @param[in] v vector + * @param[in] s scalar + * @returns destination vector + */ CGLM_INLINE vec4s glms_vec4_subs(vec4s v, float s) { @@ -128,6 +296,13 @@ glms_vec4_subs(vec4s v, float s) { return r; } +/*! + * @brief multiply two vector (component-wise multiplication) + * + * @param a vector1 + * @param b vector2 + * @returns dest = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]) + */ CGLM_INLINE vec4s glms_vec4_mul(vec4s a, vec4s b) { @@ -136,6 +311,13 @@ glms_vec4_mul(vec4s a, vec4s b) { return r; } +/*! + * @brief multiply/scale vec4 vector with scalar: result = v * s + * + * @param[in] v vector + * @param[in] s scalar + * @returns destination vector + */ CGLM_INLINE vec4s glms_vec4_scale(vec4s v, float s) { @@ -144,6 +326,13 @@ glms_vec4_scale(vec4s v, float s) { return r; } +/*! + * @brief make vec4 vector scale as specified: result = unit(v) * s + * + * @param[in] v vector + * @param[in] s scalar + * @returns destination vector + */ CGLM_INLINE vec4s glms_vec4_scale_as(vec4s v, float s) { @@ -152,6 +341,13 @@ glms_vec4_scale_as(vec4s v, float s) { return r; } +/*! + * @brief div vector with another component-wise division: d = a / b + * + * @param[in] a vector 1 + * @param[in] b vector 2 + * @returns result = (a[0]/b[0], a[1]/b[1], a[2]/b[2], a[3]/b[3]) + */ CGLM_INLINE vec4s glms_vec4_div(vec4s a, vec4s b) { @@ -160,6 +356,13 @@ glms_vec4_div(vec4s a, vec4s b) { return r; } +/*! + * @brief div vec4 vector with scalar: d = v / s + * + * @param[in] v vector + * @param[in] s scalar + * @returns destination vector + */ CGLM_INLINE vec4s glms_vec4_divs(vec4s v, float s) { @@ -168,6 +371,15 @@ glms_vec4_divs(vec4s v, float s) { return r; } +/*! + * @brief add two vectors and add result to sum + * + * 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_addadd(vec4s a, vec4s b, vec4s dest) { @@ -175,6 +387,15 @@ glms_vec4_addadd(vec4s a, vec4s b, vec4s dest) { return dest; } +/*! + * @brief sub two vectors and add 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_subadd(vec4s a, vec4s b, vec4s dest) { @@ -182,6 +403,15 @@ glms_vec4_subadd(vec4s a, vec4s b, vec4s dest) { return dest; } +/*! + * @brief mul two vectors and add 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_muladd(vec4s a, vec4s b, vec4s dest) { @@ -189,6 +419,15 @@ glms_vec4_muladd(vec4s a, vec4s b, vec4s dest) { return dest; } +/*! + * @brief mul vector with scalar and add result to sum + * + * 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_muladds(vec4s a, float s, vec4s dest) { @@ -196,6 +435,15 @@ glms_vec4_muladds(vec4s a, float s, vec4s dest) { return dest; } +/*! + * @brief add max of two vector to result/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_maxadd(vec4s a, vec4s b, vec4s dest) { @@ -203,6 +451,15 @@ glms_vec4_maxadd(vec4s a, vec4s b, vec4s dest) { return dest; } +/*! + * @brief add min of two vector to result/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_minadd(vec4s a, vec4s b, vec4s dest) { @@ -210,6 +467,12 @@ glms_vec4_minadd(vec4s a, vec4s b, vec4s dest) { return dest; } +/*! + * @brief negate vector components and store result in dest + * + * @param[in] v vector + * @returns result vector + */ CGLM_INLINE vec4s glms_vec4_negate(vec4s v) { @@ -217,13 +480,12 @@ glms_vec4_negate(vec4s v) { return v; } -CGLM_INLINE -vec4s -glms_vec4_inv(vec4s v) { - glm_vec4_inv(v.raw); - return v; -} - +/*! + * @brief normalize vec4 and store result in same vec + * + * @param[in] v vector + * @returns normalized vector + */ CGLM_INLINE vec4s glms_vec4_normalize(vec4s v) { @@ -231,12 +493,26 @@ glms_vec4_normalize(vec4s v) { return v; } +/** + * @brief distance between two vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @return returns distance + */ CGLM_INLINE float glms_vec4_distance(vec4s a, vec4s b) { return glm_vec4_distance(a.raw, b.raw); } +/*! + * @brief max values of vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns destination + */ CGLM_INLINE vec4s glms_vec4_maxv(vec4s a, vec4s b) { @@ -245,6 +521,13 @@ glms_vec4_maxv(vec4s a, vec4s b) { return r; } +/*! + * @brief min values of vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns destination + */ CGLM_INLINE vec4s glms_vec4_minv(vec4s a, vec4s b) { @@ -253,6 +536,14 @@ glms_vec4_minv(vec4s a, vec4s b) { return r; } +/*! + * @brief clamp vector's individual members between min and max values + * + * @param[in] v vector + * @param[in] minVal minimum value + * @param[in] maxVal maximum value + * @returns clamped vector + */ CGLM_INLINE vec4s glms_vec4_clamp(vec4s v, float minVal, float maxVal) { @@ -260,6 +551,16 @@ glms_vec4_clamp(vec4s v, float minVal, float maxVal) { return v; } +/*! + * @brief linear interpolation between two vector + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) clamped between 0 and 1 + * @returns destination + */ CGLM_INLINE vec4s glms_vec4_lerp(vec4s from, vec4s to, float t) { @@ -268,6 +569,12 @@ glms_vec4_lerp(vec4s from, vec4s to, float t) { return r; } +/*! + * @brief helper to fill vec4 as [S^3, S^2, S, 1] + * + * @param[in] s parameter + * @returns destination + */ CGLM_INLINE vec4s glms_vec4_cubic(float s) { From ba2031d977a846786d8ef373d02c0f12e790d4dc Mon Sep 17 00:00:00 2001 From: acoto87 Date: Tue, 21 May 2019 16:45:34 -0500 Subject: [PATCH 278/292] - Rename `structs` folder to `struct` - Include files in `cglms.h` - Fix style issues (tabs to spaces, open brace without newline) --- include/cglm/cglms.h | 18 +- include/cglm/{structs => struct}/affine.h | 206 +++++++++--------- include/cglm/{structs => struct}/box.h | 86 ++++---- include/cglm/{structs => struct}/color.h | 2 +- include/cglm/{structs => struct}/curve.h | 2 +- include/cglm/{structs => struct}/frustum.h | 42 ++-- include/cglm/{structs => struct}/io.h | 10 +- include/cglm/{structs => struct}/mat3.h | 0 include/cglm/{structs => struct}/mat4.h | 6 +- include/cglm/{structs => struct}/plane.h | 4 +- include/cglm/{structs => struct}/project.h | 22 +- include/cglm/{structs => struct}/sphere.h | 0 include/cglm/{structs => struct}/vec3-ext.h | 32 +-- include/cglm/{structs => struct}/vec3.h | 225 ++++++++++---------- include/cglm/{structs => struct}/vec4-ext.h | 34 +-- include/cglm/{structs => struct}/vec4.h | 182 ++++++++-------- include/cglm/types-struct.h | 21 +- test/src/test_common.c | 12 +- 18 files changed, 447 insertions(+), 457 deletions(-) rename include/cglm/{structs => struct}/affine.h (53%) rename include/cglm/{structs => struct}/box.h (78%) rename include/cglm/{structs => struct}/color.h (93%) rename include/cglm/{structs => struct}/curve.h (96%) rename include/cglm/{structs => struct}/frustum.h (83%) rename include/cglm/{structs => struct}/io.h (90%) rename include/cglm/{structs => struct}/mat3.h (100%) rename include/cglm/{structs => struct}/mat4.h (99%) rename include/cglm/{structs => struct}/plane.h (93%) rename include/cglm/{structs => struct}/project.h (89%) rename include/cglm/{structs => struct}/sphere.h (100%) rename include/cglm/{structs => struct}/vec3-ext.h (81%) rename include/cglm/{structs => struct}/vec3.h (70%) rename include/cglm/{structs => struct}/vec4-ext.h (79%) rename include/cglm/{structs => struct}/vec4.h (70%) diff --git a/include/cglm/cglms.h b/include/cglm/cglms.h index 67dbfa4..0ecc8de 100644 --- a/include/cglm/cglms.h +++ b/include/cglm/cglms.h @@ -13,11 +13,19 @@ extern "C" { #include "cglm.h" #include "types-struct.h" -#include "structs/vec3.h" -#include "structs/vec4.h" -#include "structs/mat3.h" -#include "structs/mat4.h" -#include "structs/sphere.h" +#include "struct/vec3.h" +#include "struct/vec4.h" +#include "struct/mat3.h" +#include "struct/mat4.h" +#include "struct/affine.h" +#include "struct/frustum.h" +#include "struct/plane.h" +#include "struct/box.h" +#include "struct/color.h" +#include "struct/io.h" +#include "struct/project.h" +#include "struct/sphere.h" +#include "struct/curve.h" #ifdef __cplusplus } diff --git a/include/cglm/structs/affine.h b/include/cglm/struct/affine.h similarity index 53% rename from include/cglm/structs/affine.h rename to include/cglm/struct/affine.h index 481aaa3..0f753c5 100644 --- a/include/cglm/structs/affine.h +++ b/include/cglm/struct/affine.h @@ -8,25 +8,25 @@ /* Functions: CGLM_INLINE mat4s glms_translate(mat4s m, vec3s v); - CGLM_INLINE mat4s glms_translate_x(mat4s m, float x); - CGLM_INLINE mat4s glms_translate_y(mat4s m, float y); - CGLM_INLINE mat4s glms_translate_z(mat4s m, float z); - CGLM_INLINE mat4s glms_translate_make(vec3s v); - CGLM_INLINE mat4s glms_scale_to(mat4s m, vec3s v); - CGLM_INLINE mat4s glms_scale_make(vec3s v); - CGLM_INLINE mat4s glms_scale(mat4s m, vec3s v); - CGLM_INLINE mat4s glms_scale_uni(mat4s m, float s); - CGLM_INLINE mat4s glmx_rotate_x(mat4s m, float angle); - CGLM_INLINE mat4s glms_rotate_y(mat4s m, float angle); - CGLM_INLINE mat4s glms_rotate_z(mat4s m, float angle); - 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 vec3s glms_decompose_scalev(mat4s m); - CGLM_INLINE bool glms_uniscaled(mat4s m); - CGLM_INLINE void glms_decompose_rs(mat4s m, mat4s * r, vec3s * s); - CGLM_INLINE void glms_decompose(mat4s m, vec4s t, mat4s * r, vec3s * s); + CGLM_INLINE mat4s glms_translate_x(mat4s m, float x); + CGLM_INLINE mat4s glms_translate_y(mat4s m, float y); + CGLM_INLINE mat4s glms_translate_z(mat4s m, float z); + CGLM_INLINE mat4s glms_translate_make(vec3s v); + CGLM_INLINE mat4s glms_scale_to(mat4s m, vec3s v); + CGLM_INLINE mat4s glms_scale_make(vec3s v); + CGLM_INLINE mat4s glms_scale(mat4s m, vec3s v); + CGLM_INLINE mat4s glms_scale_uni(mat4s m, float s); + CGLM_INLINE mat4s glmx_rotate_x(mat4s m, float angle); + CGLM_INLINE mat4s glms_rotate_y(mat4s m, float angle); + CGLM_INLINE mat4s glms_rotate_z(mat4s m, float angle); + 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 vec3s glms_decompose_scalev(mat4s m); + CGLM_INLINE bool glms_uniscaled(mat4s m); + CGLM_INLINE void glms_decompose_rs(mat4s m, mat4s * r, vec3s * s); + CGLM_INLINE void glms_decompose(mat4s m, vec4s t, mat4s * r, vec3s * s); */ #ifndef cglm_affines_h @@ -47,71 +47,71 @@ glms_mat4_mul(mat4s m1, mat4s m2); * @brief translate existing transform matrix by v vector * and stores result in same matrix * - * @param[in] m affine transfrom - * @param[in] v translate vector [x, y, z] - * @returns affine transfrom + * @param[in] m affine transfrom + * @param[in] v translate vector [x, y, z] + * @returns affine transfrom */ CGLM_INLINE mat4s glms_translate(mat4s m, vec3s v) { - glm_translate(m.raw, v.raw); - return m; + glm_translate(m.raw, v.raw); + return m; } /*! * @brief translate existing transform matrix by x factor * - * @param[in] m affine transfrom - * @param[in] x x factor - * @returns affine transfrom + * @param[in] m affine transfrom + * @param[in] x x factor + * @returns affine transfrom */ CGLM_INLINE mat4s glms_translate_x(mat4s m, float x) { - glm_translate_x(m.raw, x); - return m; + glm_translate_x(m.raw, x); + return m; } /*! * @brief translate existing transform matrix by y factor * - * @param[in] m affine transfrom - * @param[in] y y factor - * @returns affine transfrom + * @param[in] m affine transfrom + * @param[in] y y factor + * @returns affine transfrom */ CGLM_INLINE mat4s glms_translate_y(mat4s m, float y) { - glm_translate_y(m.raw, y); - return m; + glm_translate_y(m.raw, y); + return m; } /*! * @brief translate existing transform matrix by z factor * - * @param[in] m affine transfrom - * @param[in] z z factor - * @returns affine transfrom + * @param[in] m affine transfrom + * @param[in] z z factor + * @returns affine transfrom */ CGLM_INLINE mat4s glms_translate_z(mat4s m, float z) { - glm_translate_z(m.raw, z); - return m; + glm_translate_z(m.raw, z); + return m; } /*! * @brief creates NEW translate transform matrix by v vector * - * @param[in] v translate vector [x, y, z] - * @returns affine transfrom + * @param[in] v translate vector [x, y, z] + * @returns affine transfrom */ CGLM_INLINE mat4s glms_translate_make(vec3s v) { - mat4s m; - glm_translate_make(m.raw, v.raw); - return m; + mat4s m; + glm_translate_make(m.raw, v.raw); + return m; } /*! @@ -123,88 +123,88 @@ glms_translate_make(vec3s v) { CGLM_INLINE mat4s glms_scale_make(vec3s v) { - mat4s m; - glm_scale_make(m.raw, v.raw); - return m; + mat4s m; + glm_scale_make(m.raw, v.raw); + return m; } /*! * @brief scales existing transform matrix by v vector * and stores result in same matrix * - * @param[in] m affine transfrom - * @param[in] v scale vector [x, y, z] - * @returns affine transfrom + * @param[in] m affine transfrom + * @param[in] v scale vector [x, y, z] + * @returns affine transfrom */ CGLM_INLINE mat4s glms_scale(mat4s m, vec3s v) { - mat4s r; + mat4s r; glm_scale_to(m.raw, v.raw, r.raw); - return r; + return r; } /*! * @brief applies uniform scale to existing transform matrix v = [s, s, s] * and stores result in same matrix * - * @param[in] m affine transfrom - * @param[in] s scale factor - * @returns affine transfrom + * @param[in] m affine transfrom + * @param[in] s scale factor + * @returns affine transfrom */ CGLM_INLINE mat4s glms_scale_uni(mat4s m, float s) { - glm_scale_uni(m.raw, s); - return m; + glm_scale_uni(m.raw, s); + return m; } /*! * @brief rotate existing transform matrix around X axis by angle * and store result in dest * - * @param[in] m affine transfrom - * @param[in] angle angle (radians) - * @returns rotated matrix + * @param[in] m affine transfrom + * @param[in] angle angle (radians) + * @returns rotated matrix */ CGLM_INLINE mat4s glmx_rotate_x(mat4s m, float angle) { - mat4s r; - glm_rotate_x(m.raw, angle, r.raw); - return r; + mat4s r; + glm_rotate_x(m.raw, angle, r.raw); + return r; } /*! * @brief rotate existing transform matrix around Y axis by angle * and store result in dest * - * @param[in] m affine transfrom - * @param[in] angle angle (radians) - * @returns rotated matrix + * @param[in] m affine transfrom + * @param[in] angle angle (radians) + * @returns rotated matrix */ CGLM_INLINE mat4s glms_rotate_y(mat4s m, float angle) { - mat4s r; - glm_rotate_y(m.raw, angle, r.raw); - return r; + mat4s r; + glm_rotate_y(m.raw, angle, r.raw); + return r; } /*! * @brief rotate existing transform matrix around Z axis by angle * and store result in dest * - * @param[in] m affine transfrom - * @param[in] angle angle (radians) - * @returns rotated matrix + * @param[in] m affine transfrom + * @param[in] angle angle (radians) + * @returns rotated matrix */ CGLM_INLINE mat4s glms_rotate_z(mat4s m, float angle) { - mat4s r; - glm_rotate_z(m.raw, angle, r.raw); - return r; + mat4s r; + glm_rotate_z(m.raw, angle, r.raw); + return r; } /*! @@ -212,48 +212,48 @@ glms_rotate_z(mat4s m, float angle) { * * axis will be normalized so you don't need to normalize it * - * @param[in] angle angle (radians) - * @param[in] axis axis - * @returns affine transfrom + * @param[in] angle angle (radians) + * @param[in] axis axis + * @returns affine transfrom */ CGLM_INLINE mat4s glms_rotate_make(float angle, vec3s axis) { - mat4s m; - glm_rotate_make(m.raw, angle, axis.raw); - return m; + mat4s m; + glm_rotate_make(m.raw, angle, axis.raw); + return m; } /*! * @brief rotate existing transform matrix around given axis by angle * - * @param[in] m affine transfrom - * @param[in] angle angle (radians) - * @param[in] axis axis - * @returns affine transfrom + * @param[in] m affine transfrom + * @param[in] angle angle (radians) + * @param[in] axis axis + * @returns affine transfrom */ CGLM_INLINE mat4s glms_rotate(mat4s m, float angle, vec3s axis) { - glm_rotate(m.raw, angle, axis.raw); - return m; + glm_rotate(m.raw, angle, axis.raw); + return m; } /*! * @brief rotate existing transform * around given axis by angle at given pivot point (rotation center) * - * @param[in] m affine transfrom - * @param[in] pivot rotation center - * @param[in] angle angle (radians) - * @param[in] axis axis - * @returns affine transfrom + * @param[in] m affine transfrom + * @param[in] pivot rotation center + * @param[in] angle angle (radians) + * @param[in] axis axis + * @returns affine transfrom */ CGLM_INLINE mat4s glms_rotate_at(mat4s m, vec3s pivot, float angle, vec3s axis) { - glm_rotate_at(m.raw, pivot.raw, angle, axis.raw); - return m; + glm_rotate_at(m.raw, pivot.raw, angle, axis.raw); + return m; } /*! @@ -268,27 +268,27 @@ glms_rotate_at(mat4s m, vec3s pivot, float angle, vec3s axis) { * @param[in] pivot rotation center * @param[in] angle angle (radians) * @param[in] axis axis - * @returns affine transfrom + * @returns affine transfrom */ CGLM_INLINE mat4s glms_rotate_atm(mat4s m, vec3s pivot, float angle, vec3s axis) { - glm_rotate_atm(m.raw, pivot.raw, angle, axis.raw); - return m; + glm_rotate_atm(m.raw, pivot.raw, angle, axis.raw); + return m; } /*! * @brief decompose scale vector * * @param[in] m affine transform - * @returns scale vector (Sx, Sy, Sz) + * @returns scale vector (Sx, Sy, Sz) */ CGLM_INLINE vec3s glms_decompose_scalev(mat4s m) { - vec3s r; - glm_decompose_scalev(m.raw, r.raw); - return r; + vec3s r; + glm_decompose_scalev(m.raw, r.raw); + return r; } /*! @@ -302,7 +302,7 @@ glms_decompose_scalev(mat4s m) { CGLM_INLINE bool glms_uniscaled(mat4s m) { - return glm_uniscaled(m.raw); + return glm_uniscaled(m.raw); } /*! @@ -316,7 +316,7 @@ glms_uniscaled(mat4s m) { CGLM_INLINE void glms_decompose_rs(mat4s m, mat4s * __restrict r, vec3s * __restrict s) { - glm_decompose_rs(m.raw, r->raw, s->raw); + glm_decompose_rs(m.raw, r->raw, s->raw); } /*! diff --git a/include/cglm/structs/box.h b/include/cglm/struct/box.h similarity index 78% rename from include/cglm/structs/box.h rename to include/cglm/struct/box.h index 4251bd7..9dc915e 100644 --- a/include/cglm/structs/box.h +++ b/include/cglm/struct/box.h @@ -25,12 +25,12 @@ CGLM_INLINE void glms_aabb_transform(vec3s box[2], mat4s m, vec3s dest[2]) { - vec3 rawBox[2]; - vec3 rawDest[2]; + vec3 rawBox[2]; + vec3 rawDest[2]; - glms_vec3_unpack(rawBox, box, 2); - glm_aabb_transform(rawBox, m.raw, rawDest); - glms_vec3_pack(dest, rawDest, 2); + glms_vec3_unpack(rawBox, box, 2); + glm_aabb_transform(rawBox, m.raw, rawDest); + glms_vec3_pack(dest, rawDest, 2); } /*! @@ -46,14 +46,14 @@ glms_aabb_transform(vec3s box[2], mat4s m, vec3s dest[2]) { CGLM_INLINE void glms_aabb_merge(vec3s box1[2], vec3s box2[2], vec3s dest[2]) { - vec3 rawBox1[2]; - vec3 rawBox2[2]; - vec3 rawDest[2]; + vec3 rawBox1[2]; + vec3 rawBox2[2]; + vec3 rawDest[2]; - glms_vec3_unpack(rawBox1, box1, 2); - glms_vec3_unpack(rawBox2, box2, 2); - glm_aabb_merge(rawBox1, rawBox2, rawDest); - glms_vec3_pack(dest, rawDest, 2); + glms_vec3_unpack(rawBox1, box1, 2); + glms_vec3_unpack(rawBox2, box2, 2); + glm_aabb_merge(rawBox1, rawBox2, rawDest); + glms_vec3_pack(dest, rawDest, 2); } /*! @@ -70,14 +70,14 @@ glms_aabb_merge(vec3s box1[2], vec3s box2[2], vec3s dest[2]) { CGLM_INLINE void glms_aabb_crop(vec3s box[2], vec3s cropBox[2], vec3s dest[2]) { - vec3 rawBox[2]; - vec3 rawCropBox[2]; - vec3 rawDest[2]; + vec3 rawBox[2]; + vec3 rawCropBox[2]; + vec3 rawDest[2]; - glms_vec3_unpack(rawBox, box, 2); - glms_vec3_unpack(rawCropBox, cropBox, 2); - glm_aabb_crop(rawBox, rawCropBox, rawDest); - glms_vec3_pack(dest, rawDest, 2); + glms_vec3_unpack(rawBox, box, 2); + glms_vec3_unpack(rawCropBox, cropBox, 2); + glm_aabb_crop(rawBox, rawCropBox, rawDest); + glms_vec3_pack(dest, rawDest, 2); } /*! @@ -119,12 +119,12 @@ glms_aabb_crop_until(vec3s box[2], CGLM_INLINE bool glms_aabb_frustum(vec3s box[2], vec4s planes[6]) { - vec3 rawBox[2]; - vec4 rawPlanes[6]; + vec3 rawBox[2]; + vec4 rawPlanes[6]; - glms_vec3_unpack(rawBox, box, 2); - glms_vec4_unpack(rawPlanes, planes, 6); - return glm_aabb_frustum(rawBox, rawPlanes); + glms_vec3_unpack(rawBox, box, 2); + glms_vec4_unpack(rawPlanes, planes, 6); + return glm_aabb_frustum(rawBox, rawPlanes); } /*! @@ -135,8 +135,6 @@ glms_aabb_frustum(vec3s box[2], vec4s planes[6]) { CGLM_INLINE void glms_aabb_invalidate(vec3s box[2]) { - // FIX: Modify param - // box[0] = glms_vec3_broadcast(FLT_MAX); box[1] = glms_vec3_broadcast(-FLT_MAX); } @@ -149,9 +147,9 @@ glms_aabb_invalidate(vec3s box[2]) { CGLM_INLINE bool glms_aabb_isvalid(vec3s box[2]) { - vec3 rawBox[2]; - glms_vec3_unpack(rawBox, box, 2); - return glm_aabb_isvalid(rawBox); + vec3 rawBox[2]; + glms_vec3_unpack(rawBox, box, 2); + return glm_aabb_isvalid(rawBox); } /*! @@ -197,11 +195,11 @@ glms_aabb_center(vec3s box[2]) { CGLM_INLINE bool glms_aabb_aabb(vec3s box[2], vec3s other[2]) { - vec3 rawBox[2]; - vec3 rawOther[2]; + vec3 rawBox[2]; + vec3 rawOther[2]; - glms_vec3_unpack(rawBox, box, 2); - glms_vec3_unpack(rawOther, other, 2); + glms_vec3_unpack(rawBox, box, 2); + glms_vec3_unpack(rawOther, other, 2); return glm_aabb_aabb(rawBox, rawOther); } @@ -217,10 +215,10 @@ glms_aabb_aabb(vec3s box[2], vec3s other[2]) { CGLM_INLINE bool glms_aabb_sphere(vec3s box[2], vec4s s) { - vec3 rawBox[2]; - - glms_vec3_unpack(rawBox, box, 2); - return glm_aabb_sphere(rawBox, s.raw); + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + return glm_aabb_sphere(rawBox, s.raw); } /*! @@ -232,9 +230,9 @@ glms_aabb_sphere(vec3s box[2], vec4s s) { CGLM_INLINE bool glms_aabb_point(vec3s box[2], vec3s point) { - vec3 rawBox[2]; + vec3 rawBox[2]; - glms_vec3_unpack(rawBox, box, 2); + glms_vec3_unpack(rawBox, box, 2); return glm_aabb_point(rawBox, point.raw); } @@ -247,12 +245,12 @@ glms_aabb_point(vec3s box[2], vec3s point) { CGLM_INLINE bool glms_aabb_contains(vec3s box[2], vec3s other[2]) { - vec3 rawBox[2]; - vec3 rawOther[2]; + vec3 rawBox[2]; + vec3 rawOther[2]; - glms_vec3_unpack(rawBox, box, 2); - glms_vec3_unpack(rawOther, other, 2); - return glm_aabb_contains(rawBox, rawOther); + glms_vec3_unpack(rawBox, box, 2); + glms_vec3_unpack(rawOther, other, 2); + return glm_aabb_contains(rawBox, rawOther); } #endif /* cglm_boxs_h */ diff --git a/include/cglm/structs/color.h b/include/cglm/struct/color.h similarity index 93% rename from include/cglm/structs/color.h rename to include/cglm/struct/color.h index 62cf5a8..e9ddc0c 100644 --- a/include/cglm/structs/color.h +++ b/include/cglm/struct/color.h @@ -21,7 +21,7 @@ CGLM_INLINE float glms_luminance(vec3s rgb) { - return glm_luminance(rgb.raw); + return glm_luminance(rgb.raw); } #endif /* cglm_colors_h */ diff --git a/include/cglm/structs/curve.h b/include/cglm/struct/curve.h similarity index 96% rename from include/cglm/structs/curve.h rename to include/cglm/struct/curve.h index 724b0be..0972f0f 100644 --- a/include/cglm/structs/curve.h +++ b/include/cglm/struct/curve.h @@ -34,7 +34,7 @@ CGLM_INLINE float glms_smc(float s, mat4s m, vec4s c) { - return glm_smc(s, m.raw, c.raw); + return glm_smc(s, m.raw, c.raw); } #endif /* cglm_curves_h */ diff --git a/include/cglm/structs/frustum.h b/include/cglm/struct/frustum.h similarity index 83% rename from include/cglm/structs/frustum.h rename to include/cglm/struct/frustum.h index 56bd165..98931f4 100644 --- a/include/cglm/structs/frustum.h +++ b/include/cglm/struct/frustum.h @@ -55,9 +55,9 @@ CGLM_INLINE void glms_frustum_planes(mat4s m, vec4s dest[6]) { - vec4 rawDest[6]; - glm_frustum_planes(m.raw, rawDest); - glms_vec4_pack(dest, rawDest, 6); + vec4 rawDest[6]; + glm_frustum_planes(m.raw, rawDest); + glms_vec4_pack(dest, rawDest, 6); } /*! @@ -86,9 +86,9 @@ glms_frustum_planes(mat4s m, vec4s dest[6]) { CGLM_INLINE void glms_frustum_corners(mat4s invMat, vec4s dest[8]) { - vec4 rawDest[8]; - glm_frustum_corners(invMat.raw, rawDest); - glms_vec4_pack(dest, rawDest, 8); + vec4 rawDest[8]; + glm_frustum_corners(invMat.raw, rawDest); + glms_vec4_pack(dest, rawDest, 8); } /*! @@ -100,12 +100,12 @@ glms_frustum_corners(mat4s invMat, vec4s dest[8]) { CGLM_INLINE vec4s glms_frustum_center(vec4s corners[8]) { - vec4 rawCorners[8]; - vec4s r; + vec4 rawCorners[8]; + vec4s r; - glms_vec4_unpack(rawCorners, corners, 8); - glm_frustum_center(rawCorners, r.raw); - return r; + glms_vec4_unpack(rawCorners, corners, 8); + glm_frustum_center(rawCorners, r.raw); + return r; } /*! @@ -118,12 +118,12 @@ glms_frustum_center(vec4s corners[8]) { CGLM_INLINE void glms_frustum_box(vec4s corners[8], mat4s m, vec3s box[2]) { - vec4 rawCorners[8]; - vec3 rawBox[2]; + vec4 rawCorners[8]; + vec3 rawBox[2]; - glms_vec4_unpack(rawCorners, corners, 8); - glm_frustum_box(rawCorners, m.raw, rawBox); - glms_vec3_pack(box, rawBox, 2); + glms_vec4_unpack(rawCorners, corners, 8); + glm_frustum_box(rawCorners, m.raw, rawBox); + glms_vec3_pack(box, rawBox, 2); } /*! @@ -144,12 +144,12 @@ glms_frustum_corners_at(vec4s corners[8], float splitDist, float farDist, vec4s planeCorners[4]) { - vec4 rawCorners[8]; - vec4 rawPlaneCorners[4]; + vec4 rawCorners[8]; + vec4 rawPlaneCorners[4]; - glms_vec4_unpack(rawCorners, corners, 8); - glm_frustum_corners_at(rawCorners, splitDist, farDist, rawPlaneCorners); - glms_vec4_pack(planeCorners, rawPlaneCorners, 8); + glms_vec4_unpack(rawCorners, corners, 8); + glm_frustum_corners_at(rawCorners, splitDist, farDist, rawPlaneCorners); + glms_vec4_pack(planeCorners, rawPlaneCorners, 8); } #endif /* cglm_frustums_h */ diff --git a/include/cglm/structs/io.h b/include/cglm/struct/io.h similarity index 90% rename from include/cglm/structs/io.h rename to include/cglm/struct/io.h index 2467d20..0a084e4 100644 --- a/include/cglm/structs/io.h +++ b/include/cglm/struct/io.h @@ -30,14 +30,14 @@ void glms_mat4_print(mat4s matrix, FILE * __restrict ostream) { - glm_mat4_print(matrix.raw, ostream); + glm_mat4_print(matrix.raw, ostream); } CGLM_INLINE void glms_mat3_print(mat3s matrix, FILE * __restrict ostream) { - glm_mat3_print(matrix.raw, ostream); + glm_mat3_print(matrix.raw, ostream); } CGLM_INLINE @@ -73,10 +73,10 @@ void glms_aabb_print(vec3s bbox[2], const char * __restrict tag, FILE * __restrict ostream) { - vec3 rawBbox[2]; + vec3 rawBbox[2]; - glms_vec3_unpack(rawBbox, bbox, 2); - glm_aabb_print(rawBbox, tag, ostream); + glms_vec3_unpack(rawBbox, bbox, 2); + glm_aabb_print(rawBbox, tag, ostream); } #endif /* cglm_ios_h */ diff --git a/include/cglm/structs/mat3.h b/include/cglm/struct/mat3.h similarity index 100% rename from include/cglm/structs/mat3.h rename to include/cglm/struct/mat3.h diff --git a/include/cglm/structs/mat4.h b/include/cglm/struct/mat4.h similarity index 99% rename from include/cglm/structs/mat4.h rename to include/cglm/struct/mat4.h index 40c7291..5947dc0 100644 --- a/include/cglm/structs/mat4.h +++ b/include/cglm/struct/mat4.h @@ -241,11 +241,11 @@ CGLM_INLINE mat4s glms_mat4_mulN(mat4s * __restrict matrices[], uint32_t len) { CGLM_ALIGN_MAT mat4s r = GLMS_MAT4_IDENTITY_INIT; - size_t i; + size_t i; for (i = 0; i < len; i++) { - r = glms_mat4_mul(r, *matrices[i]); - } + r = glms_mat4_mul(r, *matrices[i]); + } return r; } diff --git a/include/cglm/structs/plane.h b/include/cglm/struct/plane.h similarity index 93% rename from include/cglm/structs/plane.h rename to include/cglm/struct/plane.h index 6e23482..cea7e8c 100644 --- a/include/cglm/structs/plane.h +++ b/include/cglm/struct/plane.h @@ -33,8 +33,8 @@ CGLM_INLINE vec4s glms_plane_normalize(vec4s plane) { - glm_plane_normalize(plane.raw); - return plane; + glm_plane_normalize(plane.raw); + return plane; } #endif /* cglm_planes_h */ diff --git a/include/cglm/structs/project.h b/include/cglm/struct/project.h similarity index 89% rename from include/cglm/structs/project.h rename to include/cglm/struct/project.h index 1cbb137..d45ba3d 100644 --- a/include/cglm/structs/project.h +++ b/include/cglm/struct/project.h @@ -39,14 +39,14 @@ * @param[in] pos point/position in viewport coordinates * @param[in] invMat matrix (see brief) * @param[in] vp viewport as [x, y, width, height] - * @returns unprojected coordinates + * @returns unprojected coordinates */ CGLM_INLINE vec3s glms_unprojecti(vec3s pos, mat4s invMat, vec4s vp) { - vec3s r; - glm_unprojecti(pos.raw, invMat.raw, vp.raw, r.raw); - return r; + vec3s r; + glm_unprojecti(pos.raw, invMat.raw, vp.raw, r.raw); + return r; } /*! @@ -71,14 +71,14 @@ glms_unprojecti(vec3s pos, mat4s invMat, vec4s vp) { * @param[in] pos point/position in viewport coordinates * @param[in] m matrix (see brief) * @param[in] vp viewport as [x, y, width, height] - * @returns unprojected coordinates + * @returns unprojected coordinates */ CGLM_INLINE vec3s glms_unproject(vec3s pos, mat4s m, vec4s vp) { - vec3s r; - glm_unproject(pos.raw, m.raw, vp.raw, r.raw); - return r; + vec3s r; + glm_unproject(pos.raw, m.raw, vp.raw, r.raw); + return r; } /*! @@ -96,9 +96,9 @@ glms_unproject(vec3s pos, mat4s m, vec4s vp) { CGLM_INLINE vec3s glms_project(vec3s pos, mat4s m, vec4s vp) { - vec3s r; - glm_project(pos.raw, m.raw, vp.raw, r.raw); - return r; + vec3s r; + glm_project(pos.raw, m.raw, vp.raw, r.raw); + return r; } #endif /* cglm_projects_h */ diff --git a/include/cglm/structs/sphere.h b/include/cglm/struct/sphere.h similarity index 100% rename from include/cglm/structs/sphere.h rename to include/cglm/struct/sphere.h diff --git a/include/cglm/structs/vec3-ext.h b/include/cglm/struct/vec3-ext.h similarity index 81% rename from include/cglm/structs/vec3-ext.h rename to include/cglm/struct/vec3-ext.h index 2e5e729..53a1199 100644 --- a/include/cglm/structs/vec3-ext.h +++ b/include/cglm/struct/vec3-ext.h @@ -12,17 +12,17 @@ /* Functions: CGLM_INLINE vec3s glms_vec3_broadcast(float val); - CGLM_INLINE bool glms_vec3_eq(vec3s v, float val); - CGLM_INLINE bool glms_vec3_eq_eps(vec3s v, float val); - CGLM_INLINE bool glms_vec3_eq_all(vec3s v); - CGLM_INLINE bool glms_vec3_eqv(vec3s a, vec3s b); - CGLM_INLINE bool glms_vec3_eqv_eps(vec3s a, vec3s b); - CGLM_INLINE float glms_vec3_max(vec3s v); - CGLM_INLINE float glms_vec3_min(vec3s v); - CGLM_INLINE bool glms_vec3_isnan(vec3s v); - CGLM_INLINE bool glms_vec3_isinf(vec3s v); - CGLM_INLINE bool glms_vec3_isvalid(vec3s v); - CGLM_INLINE vec3s glms_vec3_sign(vec3s v); + CGLM_INLINE bool glms_vec3_eq(vec3s v, float val); + CGLM_INLINE bool glms_vec3_eq_eps(vec3s v, float val); + CGLM_INLINE bool glms_vec3_eq_all(vec3s v); + CGLM_INLINE bool glms_vec3_eqv(vec3s a, vec3s b); + CGLM_INLINE bool glms_vec3_eqv_eps(vec3s a, vec3s b); + CGLM_INLINE float glms_vec3_max(vec3s v); + CGLM_INLINE float glms_vec3_min(vec3s v); + CGLM_INLINE bool glms_vec3_isnan(vec3s v); + CGLM_INLINE bool glms_vec3_isinf(vec3s v); + CGLM_INLINE bool glms_vec3_isvalid(vec3s v); + CGLM_INLINE vec3s glms_vec3_sign(vec3s v); CGLM_INLINE vec3s glms_vec3_sqrt(vec3s v); */ @@ -37,8 +37,8 @@ /*! * @brief fill a vector with specified value * - * @param[in] val value - * @returns dest + * @param[in] val value + * @returns dest */ CGLM_INLINE vec3s @@ -170,8 +170,8 @@ glms_vec3_isvalid(vec3s v) { * * Important: It returns 0 for zero/NaN input * - * @param v vector - * @returns sign vector + * @param v vector + * @returns sign vector */ CGLM_INLINE vec3s @@ -185,7 +185,7 @@ glms_vec3_sign(vec3s v) { * @brief square root of each vector item * * @param[in] v vector - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec3s diff --git a/include/cglm/structs/vec3.h b/include/cglm/struct/vec3.h similarity index 70% rename from include/cglm/structs/vec3.h rename to include/cglm/struct/vec3.h index 766742b..06ad75f 100644 --- a/include/cglm/structs/vec3.h +++ b/include/cglm/struct/vec3.h @@ -17,53 +17,53 @@ Functions: CGLM_INLINE vec3s glms_vec3(vec4s v4); - CGLM_INLINE vec3s glms_vec3_copy(vec3s v); - CGLM_INLINE void glms_vec3_pack(vec3s dst[], vec3 src[], size_t len); - CGLM_INLINE void glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len); - CGLM_INLINE vec3s glms_vec3_zero(); - CGLM_INLINE vec3s glms_vec3_one(); - CGLM_INLINE float glms_vec3_dot(vec3s a, vec3s b); - CGLM_INLINE float glms_vec3_norm2(vec3s v); - CGLM_INLINE float glms_vec3_norm(vec3s v); - CGLM_INLINE vec3s glms_vec3_add(vec3s a, vec3s b); - CGLM_INLINE vec3s glms_vec3_adds(vec3s a, float s); - CGLM_INLINE vec3s glms_vec3_sub(vec3s a, vec3s b); - CGLM_INLINE vec3s glms_vec3_subs(vec3s a, float s); - CGLM_INLINE vec3s glms_vec3_mul(vec3s a, vec3s b); - CGLM_INLINE vec3s glms_vec3_scale(vec3s v, float s); - CGLM_INLINE vec3s glms_vec3_scale_as(vec3s v, float s); - CGLM_INLINE vec3s glms_vec3_div(vec3s a, vec3s b); - CGLM_INLINE vec3s glms_vec3_divs(vec3s a, float s); - CGLM_INLINE vec3s glms_vec3_addadd(vec3s a, vec3s b, vec3s dest); - CGLM_INLINE vec3s glms_vec3_subadd(vec3s a, vec3s b, vec3s dest); - CGLM_INLINE vec3s glms_vec3_muladd(vec3s a, vec3s b, vec3s dest); - 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_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); - CGLM_INLINE float glms_vec3_distance(vec3s a, vec3s b); - CGLM_INLINE float glms_vec3_angle(vec3s a, vec3s b); - CGLM_INLINE vec3s glms_vec3_rotate(vec3s v, float angle, vec3s axis); - CGLM_INLINE vec3s glms_vec3_rotate_m4(mat4s m, vec3s v); - CGLM_INLINE vec3s glms_vec3_rotate_m3(mat3s m, vec3s v); - CGLM_INLINE vec3s glms_vec3_proj(vec3s a, vec3s b); - CGLM_INLINE vec3s glms_vec3_center(vec3s a, vec3s b); - CGLM_INLINE float glms_vec3_distance2(vec3s a, vec3s b); - CGLM_INLINE vec3s glms_vec3_maxv(vec3s a, vec3s b); - CGLM_INLINE vec3s glms_vec3_minv(vec3s a, vec3s b); - CGLM_INLINE vec3s glms_vec3_ortho(vec3s v); - CGLM_INLINE vec3s glms_vec3_clamp(vec3s v, float minVal, float maxVal); - CGLM_INLINE vec3s glms_vec3_lerp(vec3s from, vec3s to, float t); + CGLM_INLINE vec3s glms_vec3_copy(vec3s v); + CGLM_INLINE void glms_vec3_pack(vec3s dst[], vec3 src[], size_t len); + CGLM_INLINE void glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len); + CGLM_INLINE vec3s glms_vec3_zero(); + CGLM_INLINE vec3s glms_vec3_one(); + CGLM_INLINE float glms_vec3_dot(vec3s a, vec3s b); + CGLM_INLINE float glms_vec3_norm2(vec3s v); + CGLM_INLINE float glms_vec3_norm(vec3s v); + CGLM_INLINE vec3s glms_vec3_add(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_adds(vec3s a, float s); + CGLM_INLINE vec3s glms_vec3_sub(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_subs(vec3s a, float s); + CGLM_INLINE vec3s glms_vec3_mul(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_scale(vec3s v, float s); + CGLM_INLINE vec3s glms_vec3_scale_as(vec3s v, float s); + CGLM_INLINE vec3s glms_vec3_div(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_divs(vec3s a, float s); + CGLM_INLINE vec3s glms_vec3_addadd(vec3s a, vec3s b, vec3s dest); + CGLM_INLINE vec3s glms_vec3_subadd(vec3s a, vec3s b, vec3s dest); + CGLM_INLINE vec3s glms_vec3_muladd(vec3s a, vec3s b, vec3s dest); + 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_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); + CGLM_INLINE float glms_vec3_distance(vec3s a, vec3s b); + CGLM_INLINE float glms_vec3_angle(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_rotate(vec3s v, float angle, vec3s axis); + CGLM_INLINE vec3s glms_vec3_rotate_m4(mat4s m, vec3s v); + CGLM_INLINE vec3s glms_vec3_rotate_m3(mat3s m, vec3s v); + CGLM_INLINE vec3s glms_vec3_proj(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_center(vec3s a, vec3s b); + CGLM_INLINE float glms_vec3_distance2(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_maxv(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_minv(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_vec3_ortho(vec3s v); + CGLM_INLINE vec3s glms_vec3_clamp(vec3s v, float minVal, float maxVal); + CGLM_INLINE vec3s glms_vec3_lerp(vec3s from, vec3s to, float t); Convenient: CGLM_INLINE vec3s glms_cross(vec3s a, vec3s b); - CGLM_INLINE float glms_dot(vec3s a, vec3s b); - CGLM_INLINE vec3s glms_normalize(vec3s v); + CGLM_INLINE float glms_dot(vec3s a, vec3s b); + CGLM_INLINE vec3s glms_normalize(vec3s v); */ #ifndef cglm_vec3s_h @@ -89,7 +89,7 @@ * @brief init vec3 using vec4 * * @param[in] v4 vector4 - * @returns destination + * @returns destination */ CGLM_INLINE vec3s @@ -103,7 +103,7 @@ glms_vec3(vec4s v4) { * @brief copy all members of [a] to [dest] * * @param[in] a source - * @returns destination + * @returns destination */ CGLM_INLINE vec3s @@ -123,13 +123,13 @@ glms_vec3_copy(vec3s v) { CGLM_INLINE void glms_vec3_pack(vec3s dst[], vec3 src[], size_t len) { - size_t i; - - for (i = 0; i < len; i++) { - dst[i].x = src[i][0]; - dst[i].y = src[i][1]; - dst[i].z = src[i][2]; - } + size_t i; + + for (i = 0; i < len; i++) { + dst[i].x = src[i][0]; + dst[i].y = src[i][1]; + dst[i].z = src[i][2]; + } } /*! @@ -142,20 +142,20 @@ glms_vec3_pack(vec3s dst[], vec3 src[], size_t len) { CGLM_INLINE void glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len) { - size_t i; + size_t i; - for (i = 0; i < len; i++) { - dst[i][0] = src[i].x; - dst[i][1] = src[i].y; - dst[i][2] = src[i].z; - } + for (i = 0; i < len; i++) { + dst[i][0] = src[i].x; + dst[i][1] = src[i].y; + dst[i][2] = src[i].z; + } } /*! * @brief make vector zero * - * @param[in] v vector - * @returns zero vector + * @param[in] v vector + * @returns zero vector */ CGLM_INLINE vec3s @@ -168,8 +168,8 @@ glms_vec3_zero() { /*! * @brief make vector one * - * @param[in] v vector - * @returns one vector + * @param[in] v vector + * @returns one vector */ CGLM_INLINE vec3s @@ -228,7 +228,7 @@ glms_vec3_norm(vec3s v) { * * @param[in] a vector1 * @param[in] b vector2 - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec3s @@ -243,7 +243,7 @@ glms_vec3_add(vec3s a, vec3s b) { * * @param[in] v vector * @param[in] s scalar - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec3s @@ -258,7 +258,7 @@ glms_vec3_adds(vec3s a, float s) { * * @param[in] a vector1 * @param[in] b vector2 - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec3s @@ -273,7 +273,7 @@ glms_vec3_sub(vec3s a, vec3s b) { * * @param[in] v vector * @param[in] s scalar - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec3s @@ -286,9 +286,9 @@ glms_vec3_subs(vec3s a, float s) { /*! * @brief multiply two vector (component-wise multiplication) * - * @param a vector1 - * @param b vector2 - * @returns v3 = (a[0] * b[0], a[1] * b[1], a[2] * b[2]) + * @param a vector1 + * @param b vector2 + * @returns v3 = (a[0] * b[0], a[1] * b[1], a[2] * b[2]) */ CGLM_INLINE vec3s @@ -303,7 +303,7 @@ glms_vec3_mul(vec3s a, vec3s b) { * * @param[in] v vector * @param[in] s scalar - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec3s @@ -318,7 +318,7 @@ glms_vec3_scale(vec3s v, float s) { * * @param[in] v vector * @param[in] s scalar - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec3s @@ -333,7 +333,7 @@ glms_vec3_scale_as(vec3s v, float s) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns result = (a[0]/b[0], a[1]/b[1], a[2]/b[2]) + * @returns result = (a[0]/b[0], a[1]/b[1], a[2]/b[2]) */ CGLM_INLINE vec3s @@ -348,7 +348,7 @@ glms_vec3_div(vec3s a, vec3s b) { * * @param[in] v vector * @param[in] s scalar - * @returns result = (a[0]/s, a[1]/s, a[2]/s) + * @returns result = (a[0]/s, a[1]/s, a[2]/s) */ CGLM_INLINE vec3s @@ -365,7 +365,7 @@ glms_vec3_divs(vec3s a, float s) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns dest += (a + b) + * @returns dest += (a + b) */ CGLM_INLINE vec3s @@ -381,7 +381,7 @@ glms_vec3_addadd(vec3s a, vec3s b, vec3s dest) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns dest += (a + b) + * @returns dest += (a + b) */ CGLM_INLINE vec3s @@ -397,7 +397,7 @@ glms_vec3_subadd(vec3s a, vec3s b, vec3s dest) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns dest += (a * b) + * @returns dest += (a * b) */ CGLM_INLINE vec3s @@ -413,7 +413,7 @@ glms_vec3_muladd(vec3s a, vec3s b, vec3s dest) { * * @param[in] a vector * @param[in] s scalar - * @returns dest += (a * b) + * @returns dest += (a * b) */ CGLM_INLINE vec3s @@ -429,7 +429,7 @@ glms_vec3_muladds(vec3s a, float s, vec3s dest) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns dest += max(a, b) + * @returns dest += max(a, b) */ CGLM_INLINE vec3s @@ -445,7 +445,7 @@ glms_vec3_maxadd(vec3s a, vec3s b, vec3s dest) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns dest += min(a, b) + * @returns dest += min(a, b) */ CGLM_INLINE vec3s @@ -458,7 +458,7 @@ glms_vec3_minadd(vec3s a, vec3s b, vec3s dest) { * @brief negate vector components and store result in dest * * @param[in] v vector - * @returns result vector + * @returns result vector */ CGLM_INLINE vec3s @@ -471,7 +471,7 @@ glms_vec3_flipsign(vec3s v) { * @brief negate vector components * * @param[in] v vector - * @returns negated vector + * @returns negated vector */ CGLM_INLINE vec3s @@ -484,7 +484,7 @@ glms_vec3_negate(vec3s v) { * @brief normalize vec3 and store result in same vec * * @param[in] v vector - * @returns normalized vector + * @returns normalized vector */ CGLM_INLINE vec3s @@ -498,7 +498,7 @@ glms_vec3_normalize(vec3s v) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns destination + * @returns destination */ CGLM_INLINE vec3s @@ -513,7 +513,7 @@ glms_vec3_cross(vec3s a, vec3s b) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns destination + * @returns destination */ CGLM_INLINE vec3s @@ -540,10 +540,10 @@ glms_vec3_angle(vec3s a, vec3s b) { /*! * @brief rotate vec3 around axis by angle using Rodrigues' rotation formula * - * @param[in] v vector - * @param[in] axis axis vector (must be unit vector) - * @param[in] angle angle by radians - * @returns rotated vector + * @param[in] v vector + * @param[in] axis axis vector (must be unit vector) + * @param[in] angle angle by radians + * @returns rotated vector */ CGLM_INLINE vec3s @@ -563,7 +563,7 @@ glms_vec3_rotate(vec3s v, float angle, vec3s axis) { * * @param[in] m affine matrix or rot matrix * @param[in] v vector - * @returns rotated vector + * @returns rotated vector */ CGLM_INLINE vec3s @@ -578,7 +578,7 @@ glms_vec3_rotate_m4(mat4s m, vec3s v) { * * @param[in] m affine matrix or rot matrix * @param[in] v vector - * @returns rotated vector + * @returns rotated vector */ CGLM_INLINE vec3s @@ -593,7 +593,7 @@ glms_vec3_rotate_m3(mat3s m, vec3s v) { * * @param[in] a vector1 * @param[in] b vector2 - * @returns projected vector + * @returns projected vector */ CGLM_INLINE vec3s @@ -608,7 +608,7 @@ glms_vec3_proj(vec3s a, vec3s b) { * * @param[in] a vector1 * @param[in] b vector2 - * @returns center point + * @returns center point */ CGLM_INLINE vec3s @@ -623,7 +623,7 @@ glms_vec3_center(vec3s a, vec3s b) { * * @param[in] a vector1 * @param[in] b vector2 - * @return squared distance (distance * distance) + * @return squared distance (distance * distance) */ CGLM_INLINE float @@ -636,7 +636,7 @@ glms_vec3_distance2(vec3s a, vec3s b) { * * @param[in] a vector1 * @param[in] b vector2 - * @return distance + * @return distance */ CGLM_INLINE float @@ -649,7 +649,7 @@ glms_vec3_distance(vec3s a, vec3s b) { * * @param[in] a vector1 * @param[in] b vector2 - * @returns destination + * @returns destination */ CGLM_INLINE vec3s @@ -664,7 +664,7 @@ glms_vec3_maxv(vec3s a, vec3s b) { * * @param[in] a vector1 * @param[in] b vector2 - * @returns destination + * @returns destination */ CGLM_INLINE vec3s @@ -678,7 +678,7 @@ glms_vec3_minv(vec3s a, vec3s b) { * @brief possible orthogonal/perpendicular vector * * @param[in] v vector - * @returns orthogonal/perpendicular vector + * @returns orthogonal/perpendicular vector */ CGLM_INLINE vec3s @@ -691,10 +691,10 @@ glms_vec3_ortho(vec3s v) { /*! * @brief clamp vector's individual members between min and max values * - * @param[in] v vector - * @param[in] minVal minimum value - * @param[in] maxVal maximum value - * @returns clamped vector + * @param[in] v vector + * @param[in] minVal minimum value + * @param[in] maxVal maximum value + * @returns clamped vector */ CGLM_INLINE vec3s @@ -708,10 +708,10 @@ glms_vec3_clamp(vec3s v, float minVal, float maxVal) { * * formula: from + s * (to - from) * - * @param[in] from from value - * @param[in] to to value - * @param[in] t interpolant (amount) clamped between 0 and 1 - * @returns destination + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) clamped between 0 and 1 + * @returns destination */ CGLM_INLINE vec3s @@ -726,9 +726,9 @@ glms_vec3_lerp(vec3s from, vec3s to, float t) { * * this is just convenient wrapper * - * @param[in] a source 1 - * @param[in] b source 2 - * @returns destination + * @param[in] a source 1 + * @param[in] b source 2 + * @returns destination */ CGLM_INLINE vec3s @@ -745,8 +745,7 @@ glms_cross(vec3s a, vec3s b) { * * @param[in] a vector1 * @param[in] b vector2 - * - * @return dot product + * @return dot product */ CGLM_INLINE float @@ -759,8 +758,8 @@ glms_dot(vec3s a, vec3s b) { * * this is just convenient wrapper * - * @param[in] v vector - * @returns normalized vector + * @param[in] v vector + * @returns normalized vector */ CGLM_INLINE vec3s diff --git a/include/cglm/structs/vec4-ext.h b/include/cglm/struct/vec4-ext.h similarity index 79% rename from include/cglm/structs/vec4-ext.h rename to include/cglm/struct/vec4-ext.h index 0b81b49..fdc5059 100644 --- a/include/cglm/structs/vec4-ext.h +++ b/include/cglm/struct/vec4-ext.h @@ -11,19 +11,19 @@ /* Functions: - CGLM_INLINE vec4s glms_vec4_broadcast(float val); - CGLM_INLINE bool glms_vec4_eq(vec4s v, float val); - CGLM_INLINE bool glms_vec4_eq_eps(vec4s v, float val); - CGLM_INLINE bool glms_vec4_eq_all(vec4s v); - CGLM_INLINE bool glms_vec4_eqv(vec4s a, vec4s b); - CGLM_INLINE bool glms_vec4_eqv_eps(vec4s a, vec4s b); - CGLM_INLINE float glms_vec4_max(vec4s v); - CGLM_INLINE float glms_vec4_min(vec4s v); - CGLM_INLINE bool glms_vec4_isnan(vec4s v); - CGLM_INLINE bool glms_vec4_isinf(vec4s v); - CGLM_INLINE bool glms_vec4_isvalid(vec4s v); - CGLM_INLINE vec4s glms_vec4_sign(vec4s v); - CGLM_INLINE vec4s glms_vec4_sqrt(vec4s v); + CGLM_INLINE vec4s glms_vec4_broadcast(float val); + CGLM_INLINE bool glms_vec4_eq(vec4s v, float val); + CGLM_INLINE bool glms_vec4_eq_eps(vec4s v, float val); + CGLM_INLINE bool glms_vec4_eq_all(vec4s v); + CGLM_INLINE bool glms_vec4_eqv(vec4s a, vec4s b); + CGLM_INLINE bool glms_vec4_eqv_eps(vec4s a, vec4s b); + CGLM_INLINE float glms_vec4_max(vec4s v); + CGLM_INLINE float glms_vec4_min(vec4s v); + CGLM_INLINE bool glms_vec4_isnan(vec4s v); + CGLM_INLINE bool glms_vec4_isinf(vec4s v); + CGLM_INLINE bool glms_vec4_isvalid(vec4s v); + CGLM_INLINE vec4s glms_vec4_sign(vec4s v); + CGLM_INLINE vec4s glms_vec4_sqrt(vec4s v); */ #ifndef cglm_vec4s_ext_h @@ -38,7 +38,7 @@ * @brief fill a vector with specified value * * @param val value - * @returns dest + * @returns dest */ CGLM_INLINE vec4s @@ -170,8 +170,8 @@ glms_vec4_isvalid(vec4s v) { * * Important: It returns 0 for zero/NaN input * - * @param v vector - * @returns sign vector + * @param v vector + * @returns sign vector */ CGLM_INLINE vec4s @@ -185,7 +185,7 @@ glms_vec4_sign(vec4s v) { * @brief square root of each vector item * * @param[in] v vector - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec4s diff --git a/include/cglm/structs/vec4.h b/include/cglm/struct/vec4.h similarity index 70% rename from include/cglm/structs/vec4.h rename to include/cglm/struct/vec4.h index 2f950a7..8ae7dc9 100644 --- a/include/cglm/structs/vec4.h +++ b/include/cglm/struct/vec4.h @@ -15,39 +15,39 @@ GLM_VEC4_ZERO Functions: - CGLM_INLINE vec4s glms_vec4(vec3s v3, float last); - CGLM_INLINE vec3s glms_vec4_copy3(vec4s v); - CGLM_INLINE vec4s glms_vec4_copy(vec4s v); - CGLM_INLINE vec4s glms_vec4_ucopy(vec4s v); - CGLM_INLINE void glms_vec4_pack(vec4s dst[], vec4 src[], size_t len); - CGLM_INLINE void glms_vec4_unpack(vec4 dst[], vec4s src[], size_t len); - CGLM_INLINE float glms_vec4_dot(vec4s a, vec4s b); - CGLM_INLINE float glms_vec4_norm2(vec4s v); - CGLM_INLINE float glms_vec4_norm(vec4s v); - CGLM_INLINE vec4s glms_vec4_add(vec4s a, vec4s b); - CGLM_INLINE vec4s glms_vec4_adds(vec4s v, float s); - CGLM_INLINE vec4s glms_vec4_sub(vec4s a, vec4s b); - CGLM_INLINE vec4s glms_vec4_subs(vec4s v, float s); - CGLM_INLINE vec4s glms_vec4_mul(vec4s a, vec4s b); - CGLM_INLINE vec4s glms_vec4_scale(vec4s v, float s); - CGLM_INLINE vec4s glms_vec4_scale_as(vec4s v, float s); - CGLM_INLINE vec4s glms_vec4_div(vec4s a, vec4s b); - CGLM_INLINE vec4s glms_vec4_divs(vec4s v, float s); - CGLM_INLINE vec4s glms_vec4_addadd(vec4s a, vec4s b, vec4s dest); - CGLM_INLINE vec4s glms_vec4_subadd(vec4s a, vec4s b, vec4s dest); - CGLM_INLINE vec4s glms_vec4_muladd(vec4s a, vec4s b, vec4s dest); - 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_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 vec4s glms_vec4_maxv(vec4s a, vec4s b); - CGLM_INLINE vec4s glms_vec4_minv(vec4s a, vec4s b); - CGLM_INLINE vec4s glms_vec4_clamp(vec4s v, float minVal, float maxVal); - CGLM_INLINE vec4s glms_vec4_lerp(vec4s from, vec4s to, float t); - CGLM_INLINE vec4s glms_vec4_cubic(float s); + CGLM_INLINE vec4s glms_vec4(vec3s v3, float last); + CGLM_INLINE vec3s glms_vec4_copy3(vec4s v); + CGLM_INLINE vec4s glms_vec4_copy(vec4s v); + CGLM_INLINE vec4s glms_vec4_ucopy(vec4s v); + CGLM_INLINE void glms_vec4_pack(vec4s dst[], vec4 src[], size_t len); + CGLM_INLINE void glms_vec4_unpack(vec4 dst[], vec4s src[], size_t len); + CGLM_INLINE float glms_vec4_dot(vec4s a, vec4s b); + CGLM_INLINE float glms_vec4_norm2(vec4s v); + CGLM_INLINE float glms_vec4_norm(vec4s v); + CGLM_INLINE vec4s glms_vec4_add(vec4s a, vec4s b); + CGLM_INLINE vec4s glms_vec4_adds(vec4s v, float s); + CGLM_INLINE vec4s glms_vec4_sub(vec4s a, vec4s b); + CGLM_INLINE vec4s glms_vec4_subs(vec4s v, float s); + CGLM_INLINE vec4s glms_vec4_mul(vec4s a, vec4s b); + CGLM_INLINE vec4s glms_vec4_scale(vec4s v, float s); + CGLM_INLINE vec4s glms_vec4_scale_as(vec4s v, float s); + CGLM_INLINE vec4s glms_vec4_div(vec4s a, vec4s b); + CGLM_INLINE vec4s glms_vec4_divs(vec4s v, float s); + CGLM_INLINE vec4s glms_vec4_addadd(vec4s a, vec4s b, vec4s dest); + CGLM_INLINE vec4s glms_vec4_subadd(vec4s a, vec4s b, vec4s dest); + CGLM_INLINE vec4s glms_vec4_muladd(vec4s a, vec4s b, vec4s dest); + 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_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 vec4s glms_vec4_maxv(vec4s a, vec4s b); + CGLM_INLINE vec4s glms_vec4_minv(vec4s a, vec4s b); + CGLM_INLINE vec4s glms_vec4_clamp(vec4s v, float minVal, float maxVal); + CGLM_INLINE vec4s glms_vec4_lerp(vec4s from, vec4s to, float t); + CGLM_INLINE vec4s glms_vec4_cubic(float s); */ #ifndef cglm_vec4s_h @@ -72,7 +72,7 @@ * * @param[in] v3 vector3 * @param[in] last last item - * @returns destination + * @returns destination */ CGLM_INLINE vec4s @@ -86,7 +86,7 @@ glms_vec4(vec3s v3, float last) { * @brief copy first 3 members of [a] to [dest] * * @param[in] a source - * @returns destination + * @returns destination */ CGLM_INLINE vec3s @@ -100,7 +100,7 @@ glms_vec4_copy3(vec4s v) { * @brief copy all members of [a] to [dest] * * @param[in] v source - * @returns destination + * @returns destination */ CGLM_INLINE vec4s @@ -116,7 +116,7 @@ glms_vec4_copy(vec4s v) { * alignment is not required * * @param[in] v source - * @returns destination + * @returns destination */ CGLM_INLINE vec4s @@ -136,13 +136,13 @@ glms_vec4_ucopy(vec4s v) { CGLM_INLINE void glms_vec4_pack(vec4s dst[], vec4 src[], size_t len) { - size_t i; - - for (i = 0; i < len; i++) { - dst[i].x = src[i][0]; - dst[i].y = src[i][1]; - dst[i].z = src[i][2]; - } + size_t i; + + for (i = 0; i < len; i++) { + dst[i].x = src[i][0]; + dst[i].y = src[i][1]; + dst[i].z = src[i][2]; + } } /*! @@ -155,41 +155,41 @@ glms_vec4_pack(vec4s dst[], vec4 src[], size_t len) { CGLM_INLINE void glms_vec4_unpack(vec4 dst[], vec4s src[], size_t len) { - size_t i; + size_t i; - for (i = 0; i < len; i++) { - dst[i][0] = src[i].x; - dst[i][1] = src[i].y; - dst[i][2] = src[i].z; - } + for (i = 0; i < len; i++) { + dst[i][0] = src[i].x; + dst[i][1] = src[i].y; + dst[i][2] = src[i].z; + } } /*! * @brief make vector zero * * @param[in] v vector - * @returns zero vector + * @returns zero vector */ CGLM_INLINE vec4s glms_vec4_zero() { - vec4s r; - glm_vec4_zero(r.raw); - return r; + vec4s r; + glm_vec4_zero(r.raw); + return r; } /*! * @brief make vector one * * @param[in] v vector - * @returns one vector + * @returns one vector */ CGLM_INLINE vec4s glms_vec4_one() { - vec4s r; - glm_vec4_one(r.raw); - return r; + vec4s r; + glm_vec4_one(r.raw); + return r; } /*! @@ -241,7 +241,7 @@ glms_vec4_norm(vec4s v) { * * @param[in] a vector1 * @param[in] b vector2 - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec4s @@ -256,7 +256,7 @@ glms_vec4_add(vec4s a, vec4s b) { * * @param[in] v vector * @param[in] s scalar - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec4s @@ -271,7 +271,7 @@ glms_vec4_adds(vec4s v, float s) { * * @param[in] a vector1 * @param[in] b vector2 - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec4s @@ -286,7 +286,7 @@ glms_vec4_sub(vec4s a, vec4s b) { * * @param[in] v vector * @param[in] s scalar - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec4s @@ -301,7 +301,7 @@ glms_vec4_subs(vec4s v, float s) { * * @param a vector1 * @param b vector2 - * @returns dest = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]) + * @returns dest = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3]) */ CGLM_INLINE vec4s @@ -316,7 +316,7 @@ glms_vec4_mul(vec4s a, vec4s b) { * * @param[in] v vector * @param[in] s scalar - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec4s @@ -331,7 +331,7 @@ glms_vec4_scale(vec4s v, float s) { * * @param[in] v vector * @param[in] s scalar - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec4s @@ -346,7 +346,7 @@ glms_vec4_scale_as(vec4s v, float s) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns result = (a[0]/b[0], a[1]/b[1], a[2]/b[2], a[3]/b[3]) + * @returns result = (a[0]/b[0], a[1]/b[1], a[2]/b[2], a[3]/b[3]) */ CGLM_INLINE vec4s @@ -361,7 +361,7 @@ glms_vec4_div(vec4s a, vec4s b) { * * @param[in] v vector * @param[in] s scalar - * @returns destination vector + * @returns destination vector */ CGLM_INLINE vec4s @@ -378,7 +378,7 @@ glms_vec4_divs(vec4s v, float s) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns dest += (a + b) + * @returns dest += (a + b) */ CGLM_INLINE vec4s @@ -394,7 +394,7 @@ glms_vec4_addadd(vec4s a, vec4s b, vec4s dest) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns dest += (a - b) + * @returns dest += (a - b) */ CGLM_INLINE vec4s @@ -410,7 +410,7 @@ glms_vec4_subadd(vec4s a, vec4s b, vec4s dest) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns dest += (a * b) + * @returns dest += (a * b) */ CGLM_INLINE vec4s @@ -426,7 +426,7 @@ glms_vec4_muladd(vec4s a, vec4s b, vec4s dest) { * * @param[in] a vector * @param[in] s scalar - * @returns dest += (a * b) + * @returns dest += (a * b) */ CGLM_INLINE vec4s @@ -442,7 +442,7 @@ glms_vec4_muladds(vec4s a, float s, vec4s dest) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns dest += max(a, b) + * @returns dest += max(a, b) */ CGLM_INLINE vec4s @@ -458,7 +458,7 @@ glms_vec4_maxadd(vec4s a, vec4s b, vec4s dest) { * * @param[in] a vector 1 * @param[in] b vector 2 - * @returns dest += min(a, b) + * @returns dest += min(a, b) */ CGLM_INLINE vec4s @@ -471,7 +471,7 @@ glms_vec4_minadd(vec4s a, vec4s b, vec4s dest) { * @brief negate vector components and store result in dest * * @param[in] v vector - * @returns result vector + * @returns result vector */ CGLM_INLINE vec4s @@ -483,8 +483,8 @@ glms_vec4_negate(vec4s v) { /*! * @brief normalize vec4 and store result in same vec * - * @param[in] v vector - * @returns normalized vector + * @param[in] v vector + * @returns normalized vector */ CGLM_INLINE vec4s @@ -511,7 +511,7 @@ glms_vec4_distance(vec4s a, vec4s b) { * * @param[in] a vector1 * @param[in] b vector2 - * @returns destination + * @returns destination */ CGLM_INLINE vec4s @@ -526,7 +526,7 @@ glms_vec4_maxv(vec4s a, vec4s b) { * * @param[in] a vector1 * @param[in] b vector2 - * @returns destination + * @returns destination */ CGLM_INLINE vec4s @@ -539,10 +539,10 @@ glms_vec4_minv(vec4s a, vec4s b) { /*! * @brief clamp vector's individual members between min and max values * - * @param[in] v vector - * @param[in] minVal minimum value - * @param[in] maxVal maximum value - * @returns clamped vector + * @param[in] v vector + * @param[in] minVal minimum value + * @param[in] maxVal maximum value + * @returns clamped vector */ CGLM_INLINE vec4s @@ -556,10 +556,10 @@ glms_vec4_clamp(vec4s v, float minVal, float maxVal) { * * formula: from + s * (to - from) * - * @param[in] from from value - * @param[in] to to value - * @param[in] t interpolant (amount) clamped between 0 and 1 - * @returns destination + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) clamped between 0 and 1 + * @returns destination */ CGLM_INLINE vec4s @@ -572,15 +572,15 @@ glms_vec4_lerp(vec4s from, vec4s to, float t) { /*! * @brief helper to fill vec4 as [S^3, S^2, S, 1] * - * @param[in] s parameter - * @returns destination + * @param[in] s parameter + * @returns destination */ CGLM_INLINE vec4s glms_vec4_cubic(float s) { - vec4s r; - glm_vec4_cubic(s, r.raw); - return r; + vec4s r; + glm_vec4_cubic(s, r.raw); + return r; } #endif /* cglm_vec4s_h */ diff --git a/include/cglm/types-struct.h b/include/cglm/types-struct.h index 2d54aa4..f71c286 100644 --- a/include/cglm/types-struct.h +++ b/include/cglm/types-struct.h @@ -53,13 +53,8 @@ typedef union mat3s { float m10, m11, m12; float m20, m21, m22; }; - struct { - vec3s col0; - vec3s col1; - vec3s col2; - }; #endif - vec3s col[3]; + vec3s col[3]; mat3 raw; } mat3s; @@ -67,18 +62,12 @@ typedef union CGLM_ALIGN_MAT mat4s { #ifndef CGLM_NO_ANONYMOUS_STRUCT struct { float m00, m01, m02, m03; - float m10, m11, m12, m13; - float m20, m21, m22, m23; - float m30, m31, m32, m33; - }; - struct { - vec4s col0; - vec4s col1; - vec4s col2; - vec4s col3; + float m10, m11, m12, m13; + float m20, m21, m22, m23; + float m30, m31, m32, m33; }; #endif - vec4s col[4]; + vec4s col[4]; mat4 raw; } mat4s; diff --git a/test/src/test_common.c b/test/src/test_common.c index 02ccaec..d734e72 100644 --- a/test/src/test_common.c +++ b/test/src/test_common.c @@ -49,8 +49,7 @@ test_rand_vec3(vec3 dest) { } vec3s -test_rand_vec3s() -{ +test_rand_vec3s() { vec3s r; test_rand_vec3(r.raw); return r; @@ -67,8 +66,7 @@ test_rand_vec4(vec4 dest) { } vec4s -test_rand_vec4s() -{ +test_rand_vec4s() { vec4s r; test_rand_vec4(r.raw); return r; @@ -137,8 +135,7 @@ test_assert_vec3_eq(vec3 v1, vec3 v2) { } void -test_assert_vec3s_eq(vec3s v1, vec3s v2) -{ +test_assert_vec3s_eq(vec3s v1, vec3s v2) { test_assert_vec3_eq(v1.raw, v2.raw); } @@ -151,8 +148,7 @@ test_assert_vec4_eq(vec4 v1, vec4 v2) { } void -test_assert_vec4s_eq(vec4s v1, vec4s v2) -{ +test_assert_vec4s_eq(vec4s v1, vec4s v2) { test_assert_vec4_eq(v1.raw, v2.raw); } From d322a0ba8ff9b7653465e05f396c55fb173672ea Mon Sep 17 00:00:00 2001 From: acoto87 Date: Wed, 22 May 2019 16:24:11 -0500 Subject: [PATCH 279/292] Replace directly assignment with glm_vec{3,4}_copy functions --- include/cglm/struct/vec3.h | 8 ++------ include/cglm/struct/vec4.h | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/include/cglm/struct/vec3.h b/include/cglm/struct/vec3.h index 06ad75f..91389a2 100644 --- a/include/cglm/struct/vec3.h +++ b/include/cglm/struct/vec3.h @@ -126,9 +126,7 @@ glms_vec3_pack(vec3s dst[], vec3 src[], size_t len) { size_t i; for (i = 0; i < len; i++) { - dst[i].x = src[i][0]; - dst[i].y = src[i][1]; - dst[i].z = src[i][2]; + glm_vec3_copy(src[i], dst[i].raw); } } @@ -145,9 +143,7 @@ glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len) { size_t i; for (i = 0; i < len; i++) { - dst[i][0] = src[i].x; - dst[i][1] = src[i].y; - dst[i][2] = src[i].z; + glm_vec3_copy(src[i].raw, dst[i]); } } diff --git a/include/cglm/struct/vec4.h b/include/cglm/struct/vec4.h index 8ae7dc9..f96725f 100644 --- a/include/cglm/struct/vec4.h +++ b/include/cglm/struct/vec4.h @@ -139,9 +139,7 @@ glms_vec4_pack(vec4s dst[], vec4 src[], size_t len) { size_t i; for (i = 0; i < len; i++) { - dst[i].x = src[i][0]; - dst[i].y = src[i][1]; - dst[i].z = src[i][2]; + glm_vec4_copy(src[i], dst[i].raw); } } @@ -158,9 +156,7 @@ glms_vec4_unpack(vec4 dst[], vec4s src[], size_t len) { size_t i; for (i = 0; i < len; i++) { - dst[i][0] = src[i].x; - dst[i][1] = src[i].y; - dst[i][2] = src[i].z; + glm_vec4_copy(src[i].raw, dst[i]); } } From f26601bfa7e9218050384c169b5e567699e9ff0f Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 25 May 2019 09:12:08 +0300 Subject: [PATCH 280/292] now working on v0.6.0 --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/color.h | 6 ++++++ include/cglm/version.h | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 7bd3c58..9a26778 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.5.5], [info@recp.me]) +AC_INIT([cglm], [0.6.0], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index 33fda4e..4cd1de2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.5.5' +version = u'0.6.0' # The full version, including alpha/beta/rc tags. -release = u'0.5.5' +release = u'0.6.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/color.h b/include/cglm/color.h index 69566ad..77949dc 100644 --- a/include/cglm/color.h +++ b/include/cglm/color.h @@ -23,4 +23,10 @@ glm_luminance(vec3 rgb) { return glm_dot(rgb, l); } +CGLM_INLINE +void +glm_normal(vec3 a, vec3 b, vec3 c, vec3 dest) { + +} + #endif /* cglm_color_h */ diff --git a/include/cglm/version.h b/include/cglm/version.h index d406e2c..5843f4b 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -9,7 +9,7 @@ #define cglm_version_h #define CGLM_VERSION_MAJOR 0 -#define CGLM_VERSION_MINOR 5 -#define CGLM_VERSION_PATCH 5 +#define CGLM_VERSION_MINOR 6 +#define CGLM_VERSION_PATCH 0 #endif /* cglm_version_h */ From 5a6651563180f1d99ab83969560ff6c884011378 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 27 May 2019 09:34:29 +0300 Subject: [PATCH 281/292] Create FUNDING.yml --- .github/FUNDING.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..d5bb755 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,8 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: cglm +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +custom: # Replace with a single custom sponsorship URL From 4e1872c3ac7060b3fc60e495196510e82703cf21 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 31 May 2019 22:30:39 +0300 Subject: [PATCH 282/292] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d03a03f..672d969 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,6 @@ [![Backers on Open Collective](https://opencollective.com/cglm/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/cglm/sponsors/badge.svg)](#sponsors) -The original glm library is for C++ only (templates, namespaces, classes...), this library targeted to C99 but currently you can use it for C89 safely by language extensions e.g `__restrict` - #### Documentation Almost all functions (inline versions) and parameters are documented inside related headers.
@@ -45,6 +43,9 @@ https://github.com/g-truc/glm `cglm` doesn't alloc any memory on heap. So it doesn't provide any allocator. You should alloc memory for **out** parameters too if you pass pointer of memory location. Don't forget that **vec4** (also quat/**versor**) and **mat4** must be aligned (16-bytes), because *cglm* uses SIMD instructions to optimize most operations if available. #### Returning vector or matrix... ? + +**cglm** supports both *ARRAY API* and *STRUCT API*, so you can return structs if you you struct api (`glms_`). + Since almost all types are arrays and **C** doesn't allow returning arrays, so **cglm** doesn't support this feature. In the future *cglm* may use **struct** for some types for this purpose. #### Other APIs like Vulkan, Metal, Dx? @@ -68,6 +69,7 @@ Currently *cglm* uses default clip space configuration (-1, 1) for camera functi ## Features +- array api and struct api, you can use arrays or structs. - general purpose matrix operations (mat4, mat3) - chain matrix multiplication (square only) - general purpose vector operations (cross, dot, rotate, proj, angle...) From 12a7298474834a9454e86302e188ba55d5b70c44 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Fri, 31 May 2019 22:31:10 +0300 Subject: [PATCH 283/292] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 672d969..243d5f9 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,6 @@ https://github.com/g-truc/glm **cglm** supports both *ARRAY API* and *STRUCT API*, so you can return structs if you you struct api (`glms_`). -Since almost all types are arrays and **C** doesn't allow returning arrays, so **cglm** doesn't support this feature. In the future *cglm* may use **struct** for some types for this purpose. - #### Other APIs like Vulkan, Metal, Dx? Currently *cglm* uses default clip space configuration (-1, 1) for camera functions (perspective, extract corners...), in the future other clip space configurations will be supported From f7b45776e95916672fc852dc8a98a73ddb51ac1d Mon Sep 17 00:00:00 2001 From: Carsten Hartenfels Date: Sat, 1 Jun 2019 13:45:19 +0200 Subject: [PATCH 284/292] Find post-build.sh even when not building in . You can make configure build in a different directory than the current one when you give it a `--prefix` option. When doing that, the current directy will be the build directory, not the source directory. This breaks running `./post-build.sh`. This commit fixes it by replacing the invocation with something that takes into account `$VPATH` which properly references the source directory. The `post-build.sh` still works properly because it references the current directory to do its thing, which will (correctly) be the build directory. --- makefile.am | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/makefile.am b/makefile.am index d6cdc70..4e49d4e 100644 --- a/makefile.am +++ b/makefile.am @@ -132,5 +132,11 @@ test_tests_SOURCES=\ test/src/test_affine.c \ test/src/test_bezier.c +# When running configure with --prefix, $VPATH references +# the source directory that post-build.sh is in. When not +# using a prefix, $VPATH will be unset, so we need to fall +# back to using . to run the script. +export VPATH + all-local: - sh ./post-build.sh + sh $${VPATH:-.}/post-build.sh From b22170794a8d203ef2871385ee3001b853cc19ed Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 3 Jun 2019 09:39:11 +0300 Subject: [PATCH 285/292] struct: camera api as structs --- include/cglm/cglms.h | 1 + include/cglm/struct/cam.h | 463 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 464 insertions(+) create mode 100644 include/cglm/struct/cam.h diff --git a/include/cglm/cglms.h b/include/cglm/cglms.h index 0ecc8de..34b08d0 100644 --- a/include/cglm/cglms.h +++ b/include/cglm/cglms.h @@ -23,6 +23,7 @@ extern "C" { #include "struct/box.h" #include "struct/color.h" #include "struct/io.h" +#include "struct/cam.h" #include "struct/project.h" #include "struct/sphere.h" #include "struct/curve.h" diff --git a/include/cglm/struct/cam.h b/include/cglm/struct/cam.h new file mode 100644 index 0000000..0446bf0 --- /dev/null +++ b/include/cglm/struct/cam.h @@ -0,0 +1,463 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_frustum(float left, float right, + float bottom, float top, + float nearVal, float farVal) + CGLM_INLINE mat4s glms_ortho(float left, float right, + float bottom, float top, + float nearVal, float farVal) + CGLM_INLINE mat4s glms_ortho_aabb(vec3s box[2]); + CGLM_INLINE mat4s glms_ortho_aabb_p(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_aabb_pz(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_default(float aspect) + CGLM_INLINE mat4s glms_ortho_default_s(float aspect, float size) + CGLM_INLINE mat4s glms_perspective(float fovy, + float aspect, + float nearVal, + float farVal) + CGLM_INLINE void glms_persp_move_far(mat4s proj, float deltaFar) + CGLM_INLINE mat4s glms_perspective_default(float aspect) + CGLM_INLINE void glms_perspective_resize(mat4s proj, float aspect) + CGLM_INLINE mat4s glms_lookat(vec3s eye, vec3s center, vec3s up) + CGLM_INLINE mat4s glms_look(vec3s eye, vec3s dir, vec3s up) + CGLM_INLINE mat4s glms_look_anyup(vec3s eye, vec3s dir) + CGLM_INLINE void glms_persp_decomp(mat4s proj, + float *nearVal, + float *farVal, + float *top, + float *bottom, + float *left, + float *right) + CGLM_INLINE void glms_persp_decompv(mat4s proj, float dest[6]) + CGLM_INLINE void glms_persp_decomp_x(mat4s proj, + float *left, + float *right) + CGLM_INLINE void glms_persp_decomp_y(mat4s proj, + float *top, + float *bottom) + CGLM_INLINE void glms_persp_decomp_z(mat4s proj, + float *nearVal, + float *farVal) + CGLM_INLINE void glms_persp_decomp_far(mat4s proj, float *farVal) + CGLM_INLINE void glms_persp_decomp_near(mat4s proj, float *nearVal) + CGLM_INLINE float glms_persp_fovy(mat4s proj) + CGLM_INLINE float glms_persp_aspect(mat4s proj) + CGLM_INLINE vec4s glms_persp_sizes(mat4s proj, float fovy) + */ + +#ifndef cglms_cam_h +#define cglms_cam_h + +#include "../common.h" +#include "../types-struct.h" +#include "../plane.h" +#include "../cam.h" + +/*! + * @brief set up perspective peprojection matrix + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearVal near clipping plane + * @param[in] farVal far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_frustum(float left, float right, + float bottom, float top, + float nearVal, float farVal) { + mat4s dest; + glm_frustum(left, right, bottom, top, nearVal, farVal, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearVal near clipping plane + * @param[in] farVal far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho(float left, float right, + float bottom, float top, + float nearVal, float farVal) { + mat4s dest; + glm_ortho(left, right, bottom, top, nearVal, farVal, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb(vec3s box[2]) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb(rawBox, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_p(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_p(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_pz(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_pz(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up unit orthographic projection matrix + * + * @param[in] aspect aspect ration ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default(float aspect) { + mat4s dest; + glm_ortho_default(aspect, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_s(float aspect, float size) { + mat4s dest; + glm_ortho_default_s(aspect, size, dest.raw); + return dest; +} + +/*! + * @brief set up perspective projection matrix + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearVal near clipping plane + * @param[in] farVal far clipping planes + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective(float fovy, float aspect, float nearVal, float farVal) { + mat4s dest; + glm_perspective(fovy, aspect, nearVal, farVal, dest.raw); + return dest; +} + +/*! + * @brief extend perspective projection matrix's far distance + * + * this function does not guarantee far >= near, be aware of that! + * + * @param[in, out] proj projection matrix to extend + * @param[in] deltaFar distance from existing far (negative to shink) + */ +CGLM_INLINE +void +glms_persp_move_far(mat4s proj, float deltaFar) { + glm_persp_move_far(proj.raw, deltaFar); +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values + * + * @param[in] aspect aspect ratio ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_default(float aspect) { + mat4s dest; + glm_perspective_default(aspect, dest.raw); + return dest; +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * reized + * + * @param[in, out] proj perspective projection matrix + * @param[in] aspect aspect ratio ( width / height ) + */ +CGLM_INLINE +void +glms_perspective_resize(mat4s proj, float aspect) { + glm_perspective_resize(aspect, proj.raw); +} + +/*! + * @brief set up view matrix + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] center center vector + * @param[in] up up vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_lookat(vec3s eye, vec3s center, vec3s up) { + mat4s dest; + glm_lookat(eye.raw, center.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * + * convenient wrapper for lookat: if you only have direction not target self + * then this might be useful. Because you need to get target from direction. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[in] up up vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_look(vec3s eye, vec3s dir, vec3s up) { + mat4s dest; + glm_look(eye.raw, dir.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * + * convenient wrapper for look: if you only have direction and if you don't + * care what UP vector is then this might be useful to create view matrix + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_look_anyup(vec3s eye, vec3s dir) { + mat4s dest; + glm_look_anyup(eye.raw, dir.raw, dest.raw); + return dest; +} + +/*! + * @brief decomposes frustum values of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] nearVal near + * @param[out] farVal far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp(mat4s proj, + float * __restrict nearVal, + float * __restrict farVal, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp(proj.raw, nearVal, farVal, top, bottom, left, right); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * this makes easy to get all values at once + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glms_persp_decompv(mat4s proj, float dest[6]) { + glm_persp_decompv(proj.raw, dest); +} + +/*! + * @brief decomposes left and right values of perspective projection. + * x stands for x axis (left / right axis) + * + * @param[in] proj perspective projection matrix + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_x(mat4s proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x(proj.raw, left, right); +} + +/*! + * @brief decomposes top and bottom values of perspective projection. + * y stands for y axis (top / botom axis) + * + * @param[in] proj perspective projection matrix + * @param[out] top top + * @param[out] bottom bottom + */ +CGLM_INLINE +void +glms_persp_decomp_y(mat4s proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y(proj.raw, top, bottom); +} + +/*! + * @brief decomposes near and far values of perspective projection. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearVal near + * @param[out] farVal far + */ +CGLM_INLINE +void +glms_persp_decomp_z(mat4s proj, + float * __restrict nearVal, + float * __restrict farVal) { + glm_persp_decomp_z(proj.raw, nearVal, farVal); +} + +/*! + * @brief decomposes far value of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] farVal far + */ +CGLM_INLINE +void +glms_persp_decomp_far(mat4s proj, float * __restrict farVal) { + glm_persp_decomp_far(proj.raw, farVal); +} + +/*! + * @brief decomposes near value of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] nearVal near + */ +CGLM_INLINE +void +glms_persp_decomp_near(mat4s proj, float * __restrict nearVal) { + glm_persp_decomp_near(proj.raw, nearVal); +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * + * if you need to degrees, use glm_deg to convert it or use this: + * fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_fovy(mat4s proj) { + return glm_persp_fovy(proj.raw); +} + +/*! + * @brief returns aspect ratio of perspective projection + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_aspect(mat4s proj) { + return glm_persp_aspect(proj.raw); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @returns sizes as vector, sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +vec4s +glms_persp_sizes(mat4s proj, float fovy) { + vec4s dest; + glm_persp_sizes(proj.raw, fovy, dest.raw); + return dest; +} + +#endif /* cglms_cam_h */ From 2b1126a2fc4d0f5bf347e88ebef543efce7e7f61 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 3 Jun 2019 09:47:52 +0300 Subject: [PATCH 286/292] code style --- include/cglm/cam.h | 70 ++++++++++++++------------------------- include/cglm/struct/cam.h | 34 ++++++------------- 2 files changed, 35 insertions(+), 69 deletions(-) diff --git a/include/cglm/cam.h b/include/cglm/cam.h index e77b989..ad971fe 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -7,48 +7,37 @@ /* Functions: - CGLM_INLINE void glm_frustum(float left, - float right, - float bottom, - float top, - float nearVal, - float farVal, + CGLM_INLINE void glm_frustum(float left, float right, + float bottom, float top, + float nearVal, float farVal, mat4 dest) - CGLM_INLINE void glm_ortho(float left, - float right, - float bottom, - float top, - float nearVal, - float farVal, + CGLM_INLINE void glm_ortho(float left, float right, + float bottom, float top, + float nearVal, float farVal, mat4 dest) CGLM_INLINE void glm_ortho_aabb(vec3 box[2], mat4 dest) - CGLM_INLINE void glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) + CGLM_INLINE void glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) CGLM_INLINE void glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) CGLM_INLINE void glm_ortho_default(float aspect, mat4 dest) - CGLM_INLINE void glm_ortho_default_s(float aspect, float size, mat4 dest) + CGLM_INLINE void glm_ortho_default_s(float aspect, float size, mat4 dest) CGLM_INLINE void glm_perspective(float fovy, float aspect, float nearVal, float farVal, mat4 dest) - CGLM_INLINE void glm_perspective_default(float aspect, mat4 dest) - CGLM_INLINE void glm_perspective_resize(float aspect, mat4 proj) + CGLM_INLINE void glm_perspective_default(float aspect, mat4 dest) + CGLM_INLINE void glm_perspective_resize(float aspect, mat4 proj) CGLM_INLINE void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) CGLM_INLINE void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) CGLM_INLINE void glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) CGLM_INLINE void glm_persp_decomp(mat4 proj, - float *nearVal, - float *farVal, - float *top, - float *bottom, - float *left, - float *right) + float *nearVal, float *farVal, + float *top, float *bottom, + float *left, float *right) CGLM_INLINE void glm_persp_decompv(mat4 proj, float dest[6]) CGLM_INLINE void glm_persp_decomp_x(mat4 proj, float *left, float *right) CGLM_INLINE void glm_persp_decomp_y(mat4 proj, float *top, float *bottom) - CGLM_INLINE void glm_persp_decomp_z(mat4 proj, - float *nearVal, - float *farVal) + CGLM_INLINE void glm_persp_decomp_z(mat4 proj, float *nearv, float *farv) CGLM_INLINE void glm_persp_decomp_far(mat4 proj, float *farVal) CGLM_INLINE void glm_persp_decomp_near(mat4 proj, float *nearVal) CGLM_INLINE float glm_persp_fovy(mat4 proj) @@ -75,12 +64,9 @@ */ CGLM_INLINE void -glm_frustum(float left, - float right, - float bottom, - float top, - float nearVal, - float farVal, +glm_frustum(float left, float right, + float bottom, float top, + float nearVal, float farVal, mat4 dest) { float rl, tb, fn, nv; @@ -113,12 +99,9 @@ glm_frustum(float left, */ CGLM_INLINE void -glm_ortho(float left, - float right, - float bottom, - float top, - float nearVal, - float farVal, +glm_ortho(float left, float right, + float bottom, float top, + float nearVal, float farVal, mat4 dest) { float rl, tb, fn; @@ -218,9 +201,7 @@ glm_ortho_default(float aspect, mat4 dest) { */ CGLM_INLINE void -glm_ortho_default_s(float aspect, - float size, - mat4 dest) { +glm_ortho_default_s(float aspect, float size, mat4 dest) { if (aspect >= 1.0f) { glm_ortho(-size * aspect, size * aspect, @@ -420,12 +401,9 @@ glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) { CGLM_INLINE void glm_persp_decomp(mat4 proj, - float * __restrict nearVal, - float * __restrict farVal, - float * __restrict top, - float * __restrict bottom, - float * __restrict left, - float * __restrict right) { + float * __restrict nearVal, float * __restrict farVal, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { float m00, m11, m20, m21, m22, m32, n, f; float n_m11, n_m00; diff --git a/include/cglm/struct/cam.h b/include/cglm/struct/cam.h index 0446bf0..dc2427f 100644 --- a/include/cglm/struct/cam.h +++ b/include/cglm/struct/cam.h @@ -14,7 +14,7 @@ float bottom, float top, float nearVal, float farVal) CGLM_INLINE mat4s glms_ortho_aabb(vec3s box[2]); - CGLM_INLINE mat4s glms_ortho_aabb_p(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_aabb_p(vec3s box[2], float padding); CGLM_INLINE mat4s glms_ortho_aabb_pz(vec3s box[2], float padding); CGLM_INLINE mat4s glms_ortho_default(float aspect) CGLM_INLINE mat4s glms_ortho_default_s(float aspect, float size) @@ -29,22 +29,13 @@ CGLM_INLINE mat4s glms_look(vec3s eye, vec3s dir, vec3s up) CGLM_INLINE mat4s glms_look_anyup(vec3s eye, vec3s dir) CGLM_INLINE void glms_persp_decomp(mat4s proj, - float *nearVal, - float *farVal, - float *top, - float *bottom, - float *left, - float *right) - CGLM_INLINE void glms_persp_decompv(mat4s proj, float dest[6]) - CGLM_INLINE void glms_persp_decomp_x(mat4s proj, - float *left, - float *right) - CGLM_INLINE void glms_persp_decomp_y(mat4s proj, - float *top, - float *bottom) - CGLM_INLINE void glms_persp_decomp_z(mat4s proj, - float *nearVal, - float *farVal) + float *nearv, float *farv, + float *top, float *bottom, + float *left, float *right) + CGLM_INLINE void glms_persp_decompv(mat4s proj, float dest[6]) + CGLM_INLINE void glms_persp_decomp_x(mat4s proj, float *left, float *right) + CGLM_INLINE void glms_persp_decomp_y(mat4s proj, float *top, float *bottom) + CGLM_INLINE void glms_persp_decomp_z(mat4s proj, float *nearv, float *farv) CGLM_INLINE void glms_persp_decomp_far(mat4s proj, float *farVal) CGLM_INLINE void glms_persp_decomp_near(mat4s proj, float *nearVal) CGLM_INLINE float glms_persp_fovy(mat4s proj) @@ -326,12 +317,9 @@ glms_look_anyup(vec3s eye, vec3s dir) { CGLM_INLINE void glms_persp_decomp(mat4s proj, - float * __restrict nearVal, - float * __restrict farVal, - float * __restrict top, - float * __restrict bottom, - float * __restrict left, - float * __restrict right) { + float * __restrict nearVal, float * __restrict farVal, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { glm_persp_decomp(proj.raw, nearVal, farVal, top, bottom, left, right); } From b9de553f23557439ae034524520961611e9057ab Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 3 Jun 2019 12:01:14 +0300 Subject: [PATCH 287/292] quat: fix `glm_quat_axis` axis parameter type --- include/cglm/call/quat.h | 2 +- include/cglm/quat.h | 4 ++-- src/quat.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/cglm/call/quat.h b/include/cglm/call/quat.h index 2778a58..3080bc7 100644 --- a/include/cglm/call/quat.h +++ b/include/cglm/call/quat.h @@ -91,7 +91,7 @@ glmc_quat_angle(versor q); CGLM_EXPORT void -glmc_quat_axis(versor q, versor dest); +glmc_quat_axis(versor q, vec3 dest); CGLM_EXPORT void diff --git a/include/cglm/quat.h b/include/cglm/quat.h index 2ebc8b3..7745ed0 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -29,7 +29,7 @@ CGLM_INLINE void glm_quat_imagn(versor q, vec3 dest); CGLM_INLINE float glm_quat_imaglen(versor q); CGLM_INLINE float glm_quat_angle(versor q); - CGLM_INLINE void glm_quat_axis(versor q, versor dest); + CGLM_INLINE void glm_quat_axis(versor q, vec3 dest); CGLM_INLINE void glm_quat_mul(versor p, versor q, versor dest); CGLM_INLINE void glm_quat_mat4(versor q, mat4 dest); CGLM_INLINE void glm_quat_mat4t(versor q, mat4 dest); @@ -388,7 +388,7 @@ glm_quat_angle(versor q) { */ CGLM_INLINE void -glm_quat_axis(versor q, versor dest) { +glm_quat_axis(versor q, vec3 dest) { glm_quat_imagn(q, dest); } diff --git a/src/quat.c b/src/quat.c index 32674a7..8de4696 100644 --- a/src/quat.c +++ b/src/quat.c @@ -124,7 +124,7 @@ glmc_quat_angle(versor q) { CGLM_EXPORT void -glmc_quat_axis(versor q, versor dest) { +glmc_quat_axis(versor q, vec3 dest) { glm_quat_axis(q, dest); } From 290f54bad4fa43f752e32e135dab308c3acc2b4b Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 3 Jun 2019 12:12:50 +0300 Subject: [PATCH 288/292] struct: quaternion api as structs --- include/cglm/cglms.h | 1 + include/cglm/color.h | 6 - include/cglm/struct/quat.h | 514 ++++++++++++++++++++++++++++++++++++ include/cglm/types-struct.h | 17 +- 4 files changed, 531 insertions(+), 7 deletions(-) create mode 100644 include/cglm/struct/quat.h diff --git a/include/cglm/cglms.h b/include/cglm/cglms.h index 34b08d0..3cf7841 100644 --- a/include/cglm/cglms.h +++ b/include/cglm/cglms.h @@ -24,6 +24,7 @@ extern "C" { #include "struct/color.h" #include "struct/io.h" #include "struct/cam.h" +#include "struct/quat.h" #include "struct/project.h" #include "struct/sphere.h" #include "struct/curve.h" diff --git a/include/cglm/color.h b/include/cglm/color.h index 77949dc..69566ad 100644 --- a/include/cglm/color.h +++ b/include/cglm/color.h @@ -23,10 +23,4 @@ glm_luminance(vec3 rgb) { return glm_dot(rgb, l); } -CGLM_INLINE -void -glm_normal(vec3 a, vec3 b, vec3 c, vec3 dest) { - -} - #endif /* cglm_color_h */ diff --git a/include/cglm/struct/quat.h b/include/cglm/struct/quat.h new file mode 100644 index 0000000..c6a4192 --- /dev/null +++ b/include/cglm/struct/quat.h @@ -0,0 +1,514 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLMS_QUAT_IDENTITY_INIT + GLMS_QUAT_IDENTITY + + Functions: + CGLM_INLINE versors glms_quat_identity() + CGLM_INLINE void glms_quat_identity_array(versor *q, size_t count) + CGLM_INLINE versors glms_quat_init(float x, float y, float z, float w) + CGLM_INLINE versors glms_quatv(float angle, vec3s axis) + CGLM_INLINE versors glms_quat(float angle, float x, float y, float z) + CGLM_INLINE float glms_quat_norm(versors q) + CGLM_INLINE versors glms_quat_normalize(versors q) + CGLM_INLINE float glms_quat_dot(versors p, versors q) + CGLM_INLINE versors glms_quat_conjugate(versors q) + CGLM_INLINE versors glms_quat_inv(versors q) + CGLM_INLINE versors glms_quat_add(versors p, versors q) + CGLM_INLINE versors glms_quat_sub(versors p, versors q) + CGLM_INLINE vec3s glms_quat_imagn(versors q) + CGLM_INLINE float glms_quat_imaglen(versors q) + CGLM_INLINE float glms_quat_angle(versors q) + CGLM_INLINE vec3s glms_quat_axis(versors q) + CGLM_INLINE versors glms_quat_mul(versors p, versors q) + CGLM_INLINE mat4s glms_quat_mat4(versors q) + CGLM_INLINE mat4s glms_quat_mat4t(versors q) + CGLM_INLINE mat3s glms_quat_mat3(versors q) + CGLM_INLINE mat3s glms_quat_mat3t(versors q) + CGLM_INLINE versors glms_quat_lerp(versors from, versors to, float t) + CGLM_INLINE versors glms_quat_slerp(versors from, versors to, float t) + CGLM_INLINE mat4s. glms_quat_look(vec3s eye, versors ori) + CGLM_INLINE versors glms_quat_for(vec3s dir, vec3s fwd, vec3s up) + CGLM_INLINE versors glms_quat_forp(vec3s from, vec3s to, vec3s fwd, vec3s up) + CGLM_INLINE vec3s glms_quat_rotatev(versors q, vec3s v) + CGLM_INLINE mat4s glms_quat_rotate(mat4s m, versors q) + CGLM_INLINE mat4s glms_quat_rotate_at(mat4s m, versors q, vec3s pivot) + CGLM_INLINE mat4s glms_quat_rotate_atm(versors q, vec3s pivot) + */ + +#ifndef cglms_quat_h +#define cglms_quat_h + +#include "../common.h" +#include "../types-struct.h" +#include "../plane.h" +#include "../quat.h" + +/* + * IMPORTANT: + * ---------------------------------------------------------------------------- + * cglm stores quat as [x, y, z, w] since v0.3.6 + * + * it was [w, x, y, z] before v0.3.6 it has been changed to [x, y, z, w] + * with v0.3.6 version. + * ---------------------------------------------------------------------------- + */ + +#define GLMS_QUAT_IDENTITY_INIT GLM_QUAT_IDENTITY_INIT +#define GLMS_QUAT_IDENTITY ((versors)GLMS_QUAT_IDENTITY_INIT) + +/*! + * @brief makes given quat to identity + * + * @returns identity quaternion + */ +CGLM_INLINE +versors +glms_quat_identity() { + versors dest; + glm_quat_identity(dest.raw); + return dest; +} + +/*! + * @brief make given quaternion array's each element identity quaternion + * + * @param[in, out] q quat array (must be aligned (16) + * if alignment is not disabled) + * + * @param[in] count count of quaternions + */ +CGLM_INLINE +void +glms_quat_identity_array(versors * __restrict q, size_t count) { + CGLM_ALIGN(16) versor v = GLM_QUAT_IDENTITY_INIT; + size_t i; + + for (i = 0; i < count; i++) { + glm_vec4_copy(v, q[i].raw); + } +} + +/*! + * @brief inits quaterion with raw values + * + * @param[in] x x + * @param[in] y y + * @param[in] z z + * @param[in] w w (real part) + * @returns quaternion + */ +CGLM_INLINE +versors +glms_quat_init(float x, float y, float z, float w) { + versors dest; + glm_quat_init(dest.raw, x, y, z, w); + return dest; +} + +/*! + * @brief creates NEW quaternion with axis vector + * + * @param[in] angle angle (radians) + * @param[in] axis axis + * @returns quaternion + */ +CGLM_INLINE +versors +glms_quatv(float angle, vec3s axis) { + versors dest; + glm_quatv(dest.raw, angle, axis.raw); + return dest; +} + +/*! + * @brief creates NEW quaternion with individual axis components + * + * @param[in] angle angle (radians) + * @param[in] x axis.x + * @param[in] y axis.y + * @param[in] z axis.z + * @returns quaternion + */ +CGLM_INLINE +versors +glms_quat(float angle, float x, float y, float z) { + versors dest; + glm_quat(dest.raw, angle, x, y, z); + return dest; +} + +/*! + * @brief returns norm (magnitude) of quaternion + * + * @param[out] q quaternion + */ +CGLM_INLINE +float +glms_quat_norm(versors q) { + return glm_quat_norm(q.raw); +} + +/*! + * @brief normalize quaternion + * + * @param[in] q quaternion + * @returns quaternion + */ +CGLM_INLINE +versors +glms_quat_normalize(versors q) { + versors dest; + glm_quat_normalize_to(q.raw, dest.raw); + return dest; +} + +/*! + * @brief dot product of two quaternion + * + * @param[in] p quaternion 1 + * @param[in] q quaternion 2 + * @returns dot product + */ +CGLM_INLINE +float +glms_quat_dot(versors p, versors q) { + return glm_quat_dot(p.raw, q.raw); +} + +/*! + * @brief conjugate of quaternion + * + * @param[in] q quaternion + * @returns conjugate + */ +CGLM_INLINE +versors +glms_quat_conjugate(versors q) { + versors dest; + glm_quat_conjugate(q.raw, dest.raw); + return dest; +} + +/*! + * @brief inverse of non-zero quaternion + * + * @param[in] q quaternion + * @returns inverse quaternion + */ +CGLM_INLINE +versors +glms_quat_inv(versors q) { + versors dest; + glm_quat_inv(q.raw, dest.raw); + return dest; +} + +/*! + * @brief add (componentwise) two quaternions and store result in dest + * + * @param[in] p quaternion 1 + * @param[in] q quaternion 2 + * @returns result quaternion + */ +CGLM_INLINE +versors +glms_quat_add(versors p, versors q) { + versors dest; + glm_quat_add(p.raw, q.raw, dest.raw); + return dest; +} + +/*! + * @brief subtract (componentwise) two quaternions and store result in dest + * + * @param[in] p quaternion 1 + * @param[in] q quaternion 2 + * @returns result quaternion + */ +CGLM_INLINE +versors +glms_quat_sub(versors p, versors q) { + versors dest; + glm_quat_sub(p.raw, q.raw, dest.raw); + return dest; +} + +/*! + * @brief returns normalized imaginary part of quaternion + * + * @param[in] q quaternion + */ +CGLM_INLINE +vec3s +glms_quat_imagn(versors q) { + vec3s dest; + glm_normalize_to(q.imag.raw, dest.raw); + return dest; +} + +/*! + * @brief returns length of imaginary part of quaternion + * + * @param[in] q quaternion + */ +CGLM_INLINE +float +glms_quat_imaglen(versors q) { + return glm_quat_imaglen(q.raw); +} + +/*! + * @brief returns angle of quaternion + * + * @param[in] q quaternion + */ +CGLM_INLINE +float +glms_quat_angle(versors q) { + return glm_quat_angle(q.raw); +} + +/*! + * @brief axis of quaternion + * + * @param[in] q quaternion + * @returns axis of quaternion + */ +CGLM_INLINE +vec3s +glms_quat_axis(versors q) { + vec3s dest; + glm_quat_axis(q.raw, dest.raw); + return dest; +} + +/*! + * @brief multiplies two quaternion and stores result in dest + * this is also called Hamilton Product + * + * According to WikiPedia: + * The product of two rotation quaternions [clarification needed] will be + * equivalent to the rotation q followed by the rotation p + * + * @param[in] p quaternion 1 + * @param[in] q quaternion 2 + * @returns result quaternion + */ +CGLM_INLINE +versors +glms_quat_mul(versors p, versors q) { + versors dest; + glm_quat_mul(p.raw, q.raw, dest.raw); + return dest; +} + +/*! + * @brief convert quaternion to mat4 + * + * @param[in] q quaternion + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_quat_mat4(versors q) { + mat4s dest; + glm_quat_mat4(q.raw, dest.raw); + return dest; +} + +/*! + * @brief convert quaternion to mat4 (transposed) + * + * @param[in] q quaternion + * @returns result matrix as transposed + */ +CGLM_INLINE +mat4s +glms_quat_mat4t(versors q) { + mat4s dest; + glm_quat_mat4t(q.raw, dest.raw); + return dest; +} + +/*! + * @brief convert quaternion to mat3 + * + * @param[in] q quaternion + * @returns result matrix + */ +CGLM_INLINE +mat3s +glms_quat_mat3(versors q) { + mat3s dest; + glm_quat_mat3(q.raw, dest.raw); + return dest; +} + +/*! + * @brief convert quaternion to mat3 (transposed) + * + * @param[in] q quaternion + * @returns result matrix + */ +CGLM_INLINE +mat3s +glms_quat_mat3t(versors q) { + mat3s dest; + glm_quat_mat3t(q.raw, dest.raw); + return dest; +} + +/*! + * @brief interpolates between two quaternions + * using linear interpolation (LERP) + * + * @param[in] from from + * @param[in] to to + * @param[in] t interpolant (amount) clamped between 0 and 1 + * @returns result quaternion + */ +CGLM_INLINE +versors +glms_quat_lerp(versors from, versors to, float t) { + versors dest; + glm_quat_lerp(from.raw, to.raw, t, dest.raw); + return dest; +} + +/*! + * @brief interpolates between two quaternions + * using spherical linear interpolation (SLERP) + * + * @param[in] from from + * @param[in] to to + * @param[in] t amout + * @returns result quaternion + */ +CGLM_INLINE +versors +glms_quat_slerp(versors from, versors to, float t) { + versors dest; + glm_quat_slerp(from.raw, to.raw, t, dest.raw); + return dest; +} + +/*! + * @brief creates view matrix using quaternion as camera orientation + * + * @param[in] eye eye + * @param[in] ori orientation in world space as quaternion + * @returns view matrix + */ +CGLM_INLINE +mat4s +glms_quat_look(vec3s eye, versors ori) { + mat4s dest; + glm_quat_look(eye.raw, ori.raw, dest.raw); + return dest; +} + +/*! + * @brief creates look rotation quaternion + * + * @param[in] dir direction to look + * @param[in] fwd forward vector + * @param[in] up up vector + * @returns destination quaternion + */ +CGLM_INLINE +versors +glms_quat_for(vec3s dir, vec3s fwd, vec3s up) { + versors dest; + glm_quat_for(dir.raw, fwd.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief creates look rotation quaternion using source and + * destination positions p suffix stands for position + * + * @param[in] from source point + * @param[in] to destination point + * @param[in] fwd forward vector + * @param[in] up up vector + * @returns destination quaternion + */ +CGLM_INLINE +versors +glms_quat_forp(vec3s from, vec3s to, vec3s fwd, vec3s up) { + versors dest; + glm_quat_forp(from.raw, to.raw, fwd.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief rotate vector using using quaternion + * + * @param[in] q quaternion + * @param[in] v vector to rotate + * @returns rotated vector + */ +CGLM_INLINE +vec3s +glms_quat_rotatev(versors q, vec3s v) { + vec3s dest; + glm_quat_rotatev(q.raw, v.raw, dest.raw); + return dest; +} + +/*! + * @brief rotate existing transform matrix using quaternion + * + * @param[in] m existing transform matrix + * @param[in] q quaternion + * @returns rotated matrix/transform + */ +CGLM_INLINE +mat4s +glms_quat_rotate(mat4s m, versors q) { + glm_quat_rotate(m.raw, q.raw, m.raw); + return m; +} + +/*! + * @brief rotate existing transform matrix using quaternion at pivot point + * + * @param[in, out] m existing transform matrix + * @param[in] q quaternion + * @returns pivot + */ +CGLM_INLINE +mat4s +glms_quat_rotate_at(mat4s m, versors q, vec3s pivot) { + glm_quat_rotate_at(m.raw, q.raw, pivot.raw); + return m; +} + +/*! + * @brief rotate NEW transform matrix using quaternion at pivot point + * + * this creates rotation matrix, it assumes you don't have a matrix + * + * this should work faster than glm_quat_rotate_at because it reduces + * one glm_translate. + * + * @param[in] q quaternion + * @returns pivot + */ +CGLM_INLINE +mat4s +glms_quat_rotate_atm(versors q, vec3s pivot) { + mat4s dest; + glm_quat_rotate_atm(dest.raw, q.raw, pivot.raw); + return dest; +} + +#endif /* cglms_quat_h */ diff --git a/include/cglm/types-struct.h b/include/cglm/types-struct.h index f71c286..4901f01 100644 --- a/include/cglm/types-struct.h +++ b/include/cglm/types-struct.h @@ -44,7 +44,22 @@ typedef union CGLM_ALIGN_IF(16) vec4s { vec4 raw; } vec4s; -typedef vec4s versors; +typedef union CGLM_ALIGN_IF(16) versors { +#ifndef CGLM_NO_ANONYMOUS_STRUCT + struct { + float x; + float y; + float z; + float w; + }; + + struct { + vec3s imag; + float real; + }; +#endif + vec4 raw; +} versors; typedef union mat3s { #ifndef CGLM_NO_ANONYMOUS_STRUCT From 9a73d969a7365a715dfc768c45b52d273ddd5490 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 3 Jun 2019 12:24:18 +0300 Subject: [PATCH 289/292] struct: euler api as structs --- include/cglm/cglms.h | 1 + include/cglm/struct/euler.h | 152 ++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 include/cglm/struct/euler.h diff --git a/include/cglm/cglms.h b/include/cglm/cglms.h index 3cf7841..66a0e9b 100644 --- a/include/cglm/cglms.h +++ b/include/cglm/cglms.h @@ -25,6 +25,7 @@ extern "C" { #include "struct/io.h" #include "struct/cam.h" #include "struct/quat.h" +#include "struct/euler.h" #include "struct/project.h" #include "struct/sphere.h" #include "struct/curve.h" diff --git a/include/cglm/struct/euler.h b/include/cglm/struct/euler.h new file mode 100644 index 0000000..272ea7f --- /dev/null +++ b/include/cglm/struct/euler.h @@ -0,0 +1,152 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + NOTE: + angles must be passed as [X-Angle, Y-Angle, Z-angle] order + For instance you don't pass angles as [Z-Angle, X-Angle, Y-angle] to + glm_euler_zxy funciton, All RELATED functions accept angles same order + which is [X, Y, Z]. + */ + +/* + Types: + enum glm_euler_sq + + Functions: + CGLM_INLINE vec3s glms_euler_angles(mat4s m) + CGLM_INLINE mat4s glms_euler_xyz(vec3s angles) + CGLM_INLINE mat4s glms_euler_xzy(vec3s angles) + CGLM_INLINE mat4s glms_euler_yxz(vec3s angles) + CGLM_INLINE mat4s glms_euler_yzx(vec3s angles) + 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_sq ord) + */ + +#ifndef cglms_euler_h +#define cglms_euler_h + +#include "../common.h" +#include "../types-struct.h" +#include "../euler.h" + +/*! + * @brief extract euler angles (in radians) using xyz order + * + * @param[in] m affine transform + * @returns angles vector [x, y, z] + */ +CGLM_INLINE +vec3s +glms_euler_angles(mat4s m) { + vec3s dest; + glm_euler_angles(m.raw, dest.raw); + return dest; +} + +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] + * @returns rotation matrix + */ +CGLM_INLINE +mat4s +glms_euler_xyz(vec3s angles) { + mat4s dest; + glm_euler_xyz(angles.raw, dest.raw); + return dest; +} + +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] + * @returns rotation matrix + */ +CGLM_INLINE +mat4s +glms_euler_xzy(vec3s angles) { + mat4s dest; + glm_euler_xzy(angles.raw, dest.raw); + return dest; +} + + +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] + * @returns rotation matrix + */ +CGLM_INLINE +mat4s +glms_euler_yxz(vec3s angles) { + mat4s dest; + glm_euler_yxz(angles.raw, dest.raw); + return dest; +} + +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] + * @returns rotation matrix + */ +CGLM_INLINE +mat4s +glms_euler_yzx(vec3s angles) { + mat4s dest; + glm_euler_yzx(angles.raw, dest.raw); + return dest; +} + +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] + * @returns rotation matrix + */ +CGLM_INLINE +mat4s +glms_euler_zxy(vec3s angles) { + mat4s dest; + glm_euler_zxy(angles.raw, dest.raw); + return dest; +} + +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] + * @returns rotation matrix + */ +CGLM_INLINE +mat4s +glms_euler_zyx(vec3s angles) { + mat4s dest; + glm_euler_zyx(angles.raw, dest.raw); + return dest; +} + +/*! + * @brief build rotation matrix from euler angles + * + * @param[in] angles angles as vector [Xangle, Yangle, Zangle] + * @param[in] ord euler order + * @returns rotation matrix + */ +CGLM_INLINE +mat4s +glms_euler_by_order(vec3s angles, glm_euler_sq ord) { + mat4s dest; + glm_euler_by_order(angles.raw, ord, dest.raw); + return dest; +} + +#endif /* cglms_euler_h */ From 099239e3f5e27680fd1d0bceca63ee9d54c6bcdd Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 3 Jun 2019 12:29:36 +0300 Subject: [PATCH 290/292] rename cglms.h to struct.h --- include/cglm/{cglms.h => struct.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename include/cglm/{cglms.h => struct.h} (100%) diff --git a/include/cglm/cglms.h b/include/cglm/struct.h similarity index 100% rename from include/cglm/cglms.h rename to include/cglm/struct.h From 817da18f3abced46b33cb273808d2b3bc0198bf2 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 3 Jun 2019 12:33:07 +0300 Subject: [PATCH 291/292] build: add struct api to makefile --- makefile.am | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/makefile.am b/makefile.am index 4e49d4e..546e67a 100644 --- a/makefile.am +++ b/makefile.am @@ -98,6 +98,26 @@ cglm_simd_avx_HEADERS = include/cglm/simd/avx/mat4.h \ cglm_simd_neondir=$(includedir)/cglm/simd/neon cglm_simd_neon_HEADERS = include/cglm/simd/neon/mat4.h +cglm_structdir=$(includedir)/cglm/struct +cglm_struct_HEADERS = include/cglm/struct/mat4.h \ + include/cglm/struct/mat3.h \ + include/cglm/struct/vec3.h \ + include/cglm/struct/vec3-ext.h \ + include/cglm/struct/vec4.h \ + include/cglm/struct/vec4-ext.h \ + include/cglm/struct/affine.h \ + include/cglm/struct/io.h \ + include/cglm/struct/cam.h \ + include/cglm/struct/quat.h \ + include/cglm/struct/euler.h \ + include/cglm/struct/plane.h \ + include/cglm/struct/frustum.h \ + include/cglm/struct/box.h \ + include/cglm/struct/project.h \ + include/cglm/struct/sphere.h \ + include/cglm/struct/color.h \ + include/cglm/struct/curve.h + libcglm_la_SOURCES=\ src/euler.c \ src/affine.c \ From 3797c55154b08da891f3b9e56737b8a948b272a2 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 3 Jun 2019 12:54:27 +0300 Subject: [PATCH 292/292] fix test build, supress warnings, update header guards for struct api --- include/cglm/struct/affine.h | 8 ++++---- include/cglm/struct/box.h | 8 ++++---- include/cglm/struct/color.h | 6 +++--- include/cglm/struct/curve.h | 6 +++--- include/cglm/struct/frustum.h | 6 +++--- include/cglm/struct/io.h | 6 +++--- include/cglm/struct/mat3.h | 6 +++--- include/cglm/struct/mat4.h | 7 +++---- include/cglm/struct/plane.h | 6 +++--- include/cglm/struct/project.h | 8 ++++---- include/cglm/struct/sphere.h | 6 +++--- include/cglm/struct/vec3-ext.h | 6 +++--- include/cglm/struct/vec3.h | 29 ++++++----------------------- include/cglm/struct/vec4-ext.h | 6 +++--- include/cglm/struct/vec4.h | 12 +++++------- test/src/test_common.h | 6 +++--- 16 files changed, 56 insertions(+), 76 deletions(-) diff --git a/include/cglm/struct/affine.h b/include/cglm/struct/affine.h index 0f753c5..36dbe0f 100644 --- a/include/cglm/struct/affine.h +++ b/include/cglm/struct/affine.h @@ -29,8 +29,8 @@ CGLM_INLINE void glms_decompose(mat4s m, vec4s t, mat4s * r, vec3s * s); */ -#ifndef cglm_affines_h -#define cglm_affines_h +#ifndef cglms_affines_h +#define cglms_affines_h #include "../common.h" #include "../types-struct.h" @@ -117,8 +117,8 @@ glms_translate_make(vec3s v) { /*! * @brief creates NEW scale matrix by v vector * - * @param[out] m affine transfrom * @param[in] v scale vector [x, y, z] + * @returns affine transfrom */ CGLM_INLINE mat4s @@ -334,4 +334,4 @@ glms_decompose(mat4s m, vec4s * __restrict t, mat4s * __restrict r, vec3s * __re glm_decompose(m.raw, t->raw, r->raw, s->raw); } -#endif /* cglm_affines_h */ +#endif /* cglms_affines_h */ diff --git a/include/cglm/struct/box.h b/include/cglm/struct/box.h index 9dc915e..a55884f 100644 --- a/include/cglm/struct/box.h +++ b/include/cglm/struct/box.h @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#ifndef cglm_boxs_h -#define cglm_boxs_h +#ifndef cglms_boxs_h +#define cglms_boxs_h #include "../common.h" #include "../types-struct.h" @@ -178,7 +178,7 @@ glms_aabb_radius(vec3s box[2]) { * @brief computes center point of AABB * * @param[in] box bounding box - * @param[out] dest center of bounding box + * @returns center of bounding box */ CGLM_INLINE vec3s @@ -253,4 +253,4 @@ glms_aabb_contains(vec3s box[2], vec3s other[2]) { return glm_aabb_contains(rawBox, rawOther); } -#endif /* cglm_boxs_h */ +#endif /* cglms_boxs_h */ diff --git a/include/cglm/struct/color.h b/include/cglm/struct/color.h index e9ddc0c..3ce78da 100644 --- a/include/cglm/struct/color.h +++ b/include/cglm/struct/color.h @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#ifndef cglm_colors_h -#define cglm_colors_h +#ifndef cglms_colors_h +#define cglms_colors_h #include "../common.h" #include "../types-struct.h" @@ -24,4 +24,4 @@ glms_luminance(vec3s rgb) { return glm_luminance(rgb.raw); } -#endif /* cglm_colors_h */ +#endif /* cglms_colors_h */ diff --git a/include/cglm/struct/curve.h b/include/cglm/struct/curve.h index 0972f0f..53ea359 100644 --- a/include/cglm/struct/curve.h +++ b/include/cglm/struct/curve.h @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#ifndef cglm_curves_h -#define cglm_curves_h +#ifndef cglms_curves_h +#define cglms_curves_h #include "../common.h" #include "../types-struct.h" @@ -37,4 +37,4 @@ glms_smc(float s, mat4s m, vec4s c) { return glm_smc(s, m.raw, c.raw); } -#endif /* cglm_curves_h */ +#endif /* cglms_curves_h */ diff --git a/include/cglm/struct/frustum.h b/include/cglm/struct/frustum.h index 98931f4..2c51d6d 100644 --- a/include/cglm/struct/frustum.h +++ b/include/cglm/struct/frustum.h @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#ifndef cglm_frustums_h -#define cglm_frustums_h +#ifndef cglms_frustums_h +#define cglms_frustums_h #include "../common.h" #include "../types-struct.h" @@ -152,4 +152,4 @@ glms_frustum_corners_at(vec4s corners[8], glms_vec4_pack(planeCorners, rawPlaneCorners, 8); } -#endif /* cglm_frustums_h */ +#endif /* cglms_frustums_h */ diff --git a/include/cglm/struct/io.h b/include/cglm/struct/io.h index 0a084e4..ec28129 100644 --- a/include/cglm/struct/io.h +++ b/include/cglm/struct/io.h @@ -15,8 +15,8 @@ CGLM_INLINE void glm_versor_print(versor vec, FILE *ostream); */ -#ifndef cglm_ios_h -#define cglm_ios_h +#ifndef cglms_ios_h +#define cglms_ios_h #include "../common.h" #include "../io.h" @@ -79,4 +79,4 @@ glms_aabb_print(vec3s bbox[2], glm_aabb_print(rawBbox, tag, ostream); } -#endif /* cglm_ios_h */ +#endif /* cglms_ios_h */ diff --git a/include/cglm/struct/mat3.h b/include/cglm/struct/mat3.h index 8072746..5c474e6 100644 --- a/include/cglm/struct/mat3.h +++ b/include/cglm/struct/mat3.h @@ -30,8 +30,8 @@ CGLM_INLINE float glms_mat3_rmc(vec3s r, mat3s m, vec3s c); */ -#ifndef cglm_mat3s_h -#define cglm_mat3s_h +#ifndef cglms_mat3s_h +#define cglms_mat3s_h #include "../common.h" #include "../types-struct.h" @@ -286,4 +286,4 @@ glms_mat3_rmc(vec3s r, mat3s m, vec3s c) { return glm_mat3_rmc(r.raw, m.raw, c.raw); } -#endif /* cglm_mat3s_h */ +#endif /* cglms_mat3s_h */ diff --git a/include/cglm/struct/mat4.h b/include/cglm/struct/mat4.h index 5947dc0..ef72e31 100644 --- a/include/cglm/struct/mat4.h +++ b/include/cglm/struct/mat4.h @@ -44,8 +44,8 @@ CGLM_INLINE float glms_mat4_rmc(vec4s r, mat4s m, vec4s c); */ -#ifndef cglm_mat4s_h -#define cglm_mat4s_h +#ifndef cglms_mat4s_h +#define cglms_mat4s_h #include "../common.h" #include "../types-struct.h" @@ -463,5 +463,4 @@ glms_mat4_rmc(vec4s r, mat4s m, vec4s c) { return glm_mat4_rmc(r.raw, m.raw, c.raw); } -#endif /* cglm_mat4s_h */ - \ No newline at end of file +#endif /* cglms_mat4s_h */ diff --git a/include/cglm/struct/plane.h b/include/cglm/struct/plane.h index cea7e8c..6a84ac7 100644 --- a/include/cglm/struct/plane.h +++ b/include/cglm/struct/plane.h @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#ifndef cglm_planes_h -#define cglm_planes_h +#ifndef cglms_planes_h +#define cglms_planes_h #include "../common.h" #include "../types-struct.h" @@ -37,4 +37,4 @@ glms_plane_normalize(vec4s plane) { return plane; } -#endif /* cglm_planes_h */ +#endif /* cglms_planes_h */ diff --git a/include/cglm/struct/project.h b/include/cglm/struct/project.h index d45ba3d..8a2635f 100644 --- a/include/cglm/struct/project.h +++ b/include/cglm/struct/project.h @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#ifndef cglm_projects_h -#define cglm_projects_h +#ifndef cglms_projects_h +#define cglms_projects_h #include "../common.h" #include "../types-struct.h" @@ -91,7 +91,7 @@ glms_unproject(vec3s pos, mat4s m, vec4s vp) { * @param[in] pos object coordinates * @param[in] m MVP matrix * @param[in] vp viewport as [x, y, width, height] - * @param[out] dest projected coordinates + * @returns projected coordinates */ CGLM_INLINE vec3s @@ -101,4 +101,4 @@ glms_project(vec3s pos, mat4s m, vec4s vp) { return r; } -#endif /* cglm_projects_h */ +#endif /* cglms_projects_h */ diff --git a/include/cglm/struct/sphere.h b/include/cglm/struct/sphere.h index 164e8bc..95c36bc 100644 --- a/include/cglm/struct/sphere.h +++ b/include/cglm/struct/sphere.h @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#ifndef cglm_spheres_h -#define cglm_spheres_h +#ifndef cglms_spheres_h +#define cglms_spheres_h #include "../common.h" #include "../types-struct.h" @@ -90,4 +90,4 @@ glms_sphere_point(vec4s s, vec3s point) { return glm_sphere_point(s.raw, point.raw); } -#endif /* cglm_spheres_h */ +#endif /* cglms_spheres_h */ diff --git a/include/cglm/struct/vec3-ext.h b/include/cglm/struct/vec3-ext.h index 53a1199..2cd8749 100644 --- a/include/cglm/struct/vec3-ext.h +++ b/include/cglm/struct/vec3-ext.h @@ -26,8 +26,8 @@ CGLM_INLINE vec3s glms_vec3_sqrt(vec3s v); */ -#ifndef cglm_vec3s_ext_h -#define cglm_vec3s_ext_h +#ifndef cglms_vec3s_ext_h +#define cglms_vec3s_ext_h #include "../common.h" #include "../types-struct.h" @@ -195,4 +195,4 @@ glms_vec3_sqrt(vec3s v) { return r; } -#endif /* cglm_vec3s_ext_h */ +#endif /* cglms_vec3s_ext_h */ diff --git a/include/cglm/struct/vec3.h b/include/cglm/struct/vec3.h index 91389a2..fbe716d 100644 --- a/include/cglm/struct/vec3.h +++ b/include/cglm/struct/vec3.h @@ -17,7 +17,6 @@ Functions: CGLM_INLINE vec3s glms_vec3(vec4s v4); - CGLM_INLINE vec3s glms_vec3_copy(vec3s v); CGLM_INLINE void glms_vec3_pack(vec3s dst[], vec3 src[], size_t len); CGLM_INLINE void glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len); CGLM_INLINE vec3s glms_vec3_zero(); @@ -66,8 +65,8 @@ CGLM_INLINE vec3s glms_normalize(vec3s v); */ -#ifndef cglm_vec3s_h -#define cglm_vec3s_h +#ifndef cglms_vec3s_h +#define cglms_vec3s_h #include "../common.h" #include "../types-struct.h" @@ -99,20 +98,6 @@ glms_vec3(vec4s v4) { return r; } -/*! - * @brief copy all members of [a] to [dest] - * - * @param[in] a source - * @returns destination - */ -CGLM_INLINE -vec3s -glms_vec3_copy(vec3s v) { - vec3s r; - glm_vec3_copy(v.raw, r.raw); - return r; -} - /*! * @brief pack an array of vec3 into an array of vec3s * @@ -150,7 +135,6 @@ glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len) { /*! * @brief make vector zero * - * @param[in] v vector * @returns zero vector */ CGLM_INLINE @@ -164,7 +148,6 @@ glms_vec3_zero() { /*! * @brief make vector one * - * @param[in] v vector * @returns one vector */ CGLM_INLINE @@ -237,7 +220,7 @@ glms_vec3_add(vec3s a, vec3s b) { /*! * @brief add scalar to v vector store result in dest (d = v + s) * - * @param[in] v vector + * @param[in] a vector * @param[in] s scalar * @returns destination vector */ @@ -267,7 +250,7 @@ glms_vec3_sub(vec3s a, vec3s b) { /*! * @brief subtract scalar from v vector store result in dest (d = v - s) * - * @param[in] v vector + * @param[in] a vector * @param[in] s scalar * @returns destination vector */ @@ -342,7 +325,7 @@ glms_vec3_div(vec3s a, vec3s b) { /*! * @brief div vector with scalar: d = v / s * - * @param[in] v vector + * @param[in] a vector * @param[in] s scalar * @returns result = (a[0]/s, a[1]/s, a[2]/s) */ @@ -764,4 +747,4 @@ glms_normalize(vec3s v) { return v; } -#endif /* cglm_vec3s_h */ +#endif /* cglms_vec3s_h */ diff --git a/include/cglm/struct/vec4-ext.h b/include/cglm/struct/vec4-ext.h index fdc5059..52c438e 100644 --- a/include/cglm/struct/vec4-ext.h +++ b/include/cglm/struct/vec4-ext.h @@ -26,8 +26,8 @@ CGLM_INLINE vec4s glms_vec4_sqrt(vec4s v); */ -#ifndef cglm_vec4s_ext_h -#define cglm_vec4s_ext_h +#ifndef cglms_vec4s_ext_h +#define cglms_vec4s_ext_h #include "../common.h" #include "../types-struct.h" @@ -195,4 +195,4 @@ glms_vec4_sqrt(vec4s v) { return r; } -#endif /* cglm_vec4s_ext_h */ +#endif /* cglms_vec4s_ext_h */ diff --git a/include/cglm/struct/vec4.h b/include/cglm/struct/vec4.h index f96725f..4fe75ba 100644 --- a/include/cglm/struct/vec4.h +++ b/include/cglm/struct/vec4.h @@ -50,8 +50,8 @@ CGLM_INLINE vec4s glms_vec4_cubic(float s); */ -#ifndef cglm_vec4s_h -#define cglm_vec4s_h +#ifndef cglms_vec4s_h +#define cglms_vec4s_h #include "../common.h" #include "../types-struct.h" @@ -85,8 +85,8 @@ glms_vec4(vec3s v3, float last) { /*! * @brief copy first 3 members of [a] to [dest] * - * @param[in] a source - * @returns destination + * @param[in] v source + * @returns vec3 */ CGLM_INLINE vec3s @@ -163,7 +163,6 @@ glms_vec4_unpack(vec4 dst[], vec4s src[], size_t len) { /*! * @brief make vector zero * - * @param[in] v vector * @returns zero vector */ CGLM_INLINE @@ -177,7 +176,6 @@ glms_vec4_zero() { /*! * @brief make vector one * - * @param[in] v vector * @returns one vector */ CGLM_INLINE @@ -579,4 +577,4 @@ glms_vec4_cubic(float s) { return r; } -#endif /* cglm_vec4s_h */ +#endif /* cglms_vec4s_h */ diff --git a/test/src/test_common.h b/test/src/test_common.h index 51d1826..690d249 100644 --- a/test/src/test_common.h +++ b/test/src/test_common.h @@ -20,7 +20,7 @@ #include #include -#include +#include #include void @@ -63,13 +63,13 @@ void test_rand_vec3(vec3 dest); vec3s -test_rand_vec3s(); +test_rand_vec3s(void); void test_rand_vec4(vec4 dest); vec4s -test_rand_vec4s(); +test_rand_vec4s(void); float test_rand(void);