From 2f518e5e28d35ae24a5ac0e31000835e43b01972 Mon Sep 17 00:00:00 2001 From: sanine Date: Tue, 14 Jun 2022 00:06:42 -0500 Subject: add cglm as 3rd-party library --- CMakeLists.txt | 6 + libs/cglm/.gitattributes | 1 + libs/cglm/.github/FUNDING.yml | 8 + libs/cglm/.gitignore | 81 + libs/cglm/.gitmodules | 0 libs/cglm/.travis.yml | 68 + libs/cglm/.vscode/settings.json | 4 + libs/cglm/CMakeLists.txt | 170 ++ libs/cglm/CONTRIBUTING.md | 53 + libs/cglm/CREDITS | 84 + libs/cglm/LICENSE | 21 + libs/cglm/Makefile.am | 250 +++ libs/cglm/Package.swift | 44 + libs/cglm/README.md | 475 ++++++ libs/cglm/_config.yml | 1 + libs/cglm/appveyor.yml | 7 + libs/cglm/autogen.sh | 21 + libs/cglm/cglm.pc.in | 11 + libs/cglm/cglm.png | Bin 0 -> 387622 bytes libs/cglm/cglm.podspec | 37 + libs/cglm/configure.ac | 75 + libs/cglm/docs/make.bat | 36 + libs/cglm/docs/source/affine-mat.rst | 99 ++ libs/cglm/docs/source/affine.rst | 345 ++++ libs/cglm/docs/source/affine2d.rst | 140 ++ libs/cglm/docs/source/api.rst | 59 + libs/cglm/docs/source/bezier.rst | 89 + libs/cglm/docs/source/box.rst | 181 ++ libs/cglm/docs/source/build.rst | 153 ++ libs/cglm/docs/source/call.rst | 19 + libs/cglm/docs/source/cam.rst | 313 ++++ libs/cglm/docs/source/cglm-intro.png | Bin 0 -> 74053 bytes libs/cglm/docs/source/color.rst | 34 + libs/cglm/docs/source/conf.py | 203 +++ libs/cglm/docs/source/curve.rst | 41 + libs/cglm/docs/source/euler.rst | 182 ++ libs/cglm/docs/source/features.rst | 28 + libs/cglm/docs/source/frustum.rst | 168 ++ libs/cglm/docs/source/getting_started.rst | 105 ++ libs/cglm/docs/source/index.rst | 53 + libs/cglm/docs/source/io.rst | 119 ++ libs/cglm/docs/source/ivec2.rst | 163 ++ libs/cglm/docs/source/ivec3.rst | 163 ++ libs/cglm/docs/source/ivec4.rst | 163 ++ libs/cglm/docs/source/mat2.rst | 179 ++ libs/cglm/docs/source/mat3.rst | 189 +++ libs/cglm/docs/source/mat4.rst | 304 ++++ libs/cglm/docs/source/opengl.rst | 61 + libs/cglm/docs/source/opt.rst | 124 ++ libs/cglm/docs/source/plane.rst | 33 + libs/cglm/docs/source/project.rst | 102 ++ libs/cglm/docs/source/quat.rst | 422 +++++ libs/cglm/docs/source/ray.rst | 31 + libs/cglm/docs/source/sphere.rst | 74 + libs/cglm/docs/source/troubleshooting.rst | 99 ++ libs/cglm/docs/source/util.rst | 182 ++ libs/cglm/docs/source/vec2-ext.rst | 134 ++ libs/cglm/docs/source/vec2.rst | 375 +++++ libs/cglm/docs/source/vec3-ext.rst | 143 ++ libs/cglm/docs/source/vec3.rst | 503 ++++++ libs/cglm/docs/source/vec4-ext.rst | 138 ++ libs/cglm/docs/source/vec4.rst | 408 +++++ libs/cglm/docs/source/version.rst | 15 + libs/cglm/include/cglm/affine-mat.h | 178 ++ libs/cglm/include/cglm/affine.h | 470 ++++++ libs/cglm/include/cglm/affine2d.h | 268 +++ libs/cglm/include/cglm/applesimd.h | 95 ++ libs/cglm/include/cglm/bezier.h | 154 ++ libs/cglm/include/cglm/box.h | 281 ++++ libs/cglm/include/cglm/call.h | 43 + libs/cglm/include/cglm/call/affine.h | 117 ++ libs/cglm/include/cglm/call/affine2d.h | 67 + libs/cglm/include/cglm/call/bezier.h | 31 + libs/cglm/include/cglm/call/box.h | 79 + libs/cglm/include/cglm/call/cam.h | 133 ++ .../cglm/include/cglm/call/clipspace/ortho_lh_no.h | 46 + .../cglm/include/cglm/call/clipspace/ortho_lh_zo.h | 46 + .../cglm/include/cglm/call/clipspace/ortho_rh_no.h | 46 + .../cglm/include/cglm/call/clipspace/ortho_rh_zo.h | 46 + .../cglm/include/cglm/call/clipspace/persp_lh_no.h | 87 + .../cglm/include/cglm/call/clipspace/persp_lh_zo.h | 87 + .../cglm/include/cglm/call/clipspace/persp_rh_no.h | 87 + .../cglm/include/cglm/call/clipspace/persp_rh_zo.h | 87 + libs/cglm/include/cglm/call/clipspace/project_no.h | 27 + libs/cglm/include/cglm/call/clipspace/project_zo.h | 27 + libs/cglm/include/cglm/call/clipspace/view_lh_no.h | 31 + libs/cglm/include/cglm/call/clipspace/view_lh_zo.h | 31 + libs/cglm/include/cglm/call/clipspace/view_rh_no.h | 31 + libs/cglm/include/cglm/call/clipspace/view_rh_zo.h | 31 + libs/cglm/include/cglm/call/curve.h | 23 + libs/cglm/include/cglm/call/ease.h | 143 ++ libs/cglm/include/cglm/call/euler.h | 55 + libs/cglm/include/cglm/call/frustum.h | 41 + libs/cglm/include/cglm/call/io.h | 45 + libs/cglm/include/cglm/call/ivec2.h | 79 + libs/cglm/include/cglm/call/ivec3.h | 79 + libs/cglm/include/cglm/call/ivec4.h | 79 + libs/cglm/include/cglm/call/mat2.h | 79 + libs/cglm/include/cglm/call/mat3.h | 86 + libs/cglm/include/cglm/call/mat4.h | 127 ++ libs/cglm/include/cglm/call/plane.h | 23 + libs/cglm/include/cglm/call/project.h | 37 + libs/cglm/include/cglm/call/quat.h | 167 ++ libs/cglm/include/cglm/call/ray.h | 27 + libs/cglm/include/cglm/call/sphere.h | 39 + libs/cglm/include/cglm/call/vec2.h | 167 ++ libs/cglm/include/cglm/call/vec3.h | 312 ++++ libs/cglm/include/cglm/call/vec4.h | 290 ++++ libs/cglm/include/cglm/cam.h | 582 +++++++ libs/cglm/include/cglm/cglm.h | 39 + libs/cglm/include/cglm/clipspace/ortho_lh_no.h | 183 +++ libs/cglm/include/cglm/clipspace/ortho_lh_zo.h | 177 ++ libs/cglm/include/cglm/clipspace/ortho_rh_no.h | 183 +++ libs/cglm/include/cglm/clipspace/ortho_rh_zo.h | 181 ++ libs/cglm/include/cglm/clipspace/persp.h | 48 + libs/cglm/include/cglm/clipspace/persp_lh_no.h | 395 +++++ libs/cglm/include/cglm/clipspace/persp_lh_zo.h | 387 +++++ libs/cglm/include/cglm/clipspace/persp_rh_no.h | 395 +++++ libs/cglm/include/cglm/clipspace/persp_rh_zo.h | 389 +++++ libs/cglm/include/cglm/clipspace/project_no.h | 86 + libs/cglm/include/cglm/clipspace/project_zo.h | 88 + libs/cglm/include/cglm/clipspace/view_lh.h | 99 ++ libs/cglm/include/cglm/clipspace/view_lh_no.h | 74 + libs/cglm/include/cglm/clipspace/view_lh_zo.h | 74 + libs/cglm/include/cglm/clipspace/view_rh.h | 99 ++ libs/cglm/include/cglm/clipspace/view_rh_no.h | 74 + libs/cglm/include/cglm/clipspace/view_rh_zo.h | 74 + libs/cglm/include/cglm/color.h | 26 + libs/cglm/include/cglm/common.h | 84 + libs/cglm/include/cglm/curve.h | 40 + libs/cglm/include/cglm/ease.h | 317 ++++ libs/cglm/include/cglm/euler.h | 451 +++++ libs/cglm/include/cglm/frustum.h | 255 +++ libs/cglm/include/cglm/io.h | 344 ++++ libs/cglm/include/cglm/ivec2.h | 242 +++ libs/cglm/include/cglm/ivec3.h | 258 +++ libs/cglm/include/cglm/ivec4.h | 275 ++++ libs/cglm/include/cglm/mat2.h | 337 ++++ libs/cglm/include/cglm/mat3.h | 424 +++++ libs/cglm/include/cglm/mat4.h | 754 +++++++++ libs/cglm/include/cglm/plane.h | 44 + libs/cglm/include/cglm/project.h | 150 ++ libs/cglm/include/cglm/quat.h | 867 ++++++++++ libs/cglm/include/cglm/ray.h | 77 + libs/cglm/include/cglm/simd/arm.h | 173 ++ libs/cglm/include/cglm/simd/avx/affine.h | 66 + libs/cglm/include/cglm/simd/avx/mat4.h | 76 + libs/cglm/include/cglm/simd/intrin.h | 90 + libs/cglm/include/cglm/simd/neon/affine.h | 121 ++ libs/cglm/include/cglm/simd/neon/mat2.h | 44 + libs/cglm/include/cglm/simd/neon/mat4.h | 317 ++++ libs/cglm/include/cglm/simd/neon/quat.h | 56 + libs/cglm/include/cglm/simd/sse2/affine.h | 115 ++ libs/cglm/include/cglm/simd/sse2/mat2.h | 48 + libs/cglm/include/cglm/simd/sse2/mat3.h | 76 + libs/cglm/include/cglm/simd/sse2/mat4.h | 434 +++++ libs/cglm/include/cglm/simd/sse2/quat.h | 54 + libs/cglm/include/cglm/simd/x86.h | 307 ++++ libs/cglm/include/cglm/sphere.h | 99 ++ libs/cglm/include/cglm/struct.h | 39 + libs/cglm/include/cglm/struct/affine.h | 333 ++++ libs/cglm/include/cglm/struct/affine2d.h | 177 ++ libs/cglm/include/cglm/struct/box.h | 256 +++ libs/cglm/include/cglm/struct/cam.h | 646 ++++++++ .../include/cglm/struct/clipspace/ortho_lh_no.h | 152 ++ .../include/cglm/struct/clipspace/ortho_lh_zo.h | 152 ++ .../include/cglm/struct/clipspace/ortho_rh_no.h | 152 ++ .../include/cglm/struct/clipspace/ortho_rh_zo.h | 152 ++ .../include/cglm/struct/clipspace/persp_lh_no.h | 311 ++++ .../include/cglm/struct/clipspace/persp_lh_zo.h | 311 ++++ .../include/cglm/struct/clipspace/persp_rh_no.h | 311 ++++ .../include/cglm/struct/clipspace/persp_rh_zo.h | 311 ++++ .../include/cglm/struct/clipspace/view_lh_no.h | 88 + .../include/cglm/struct/clipspace/view_lh_zo.h | 88 + .../include/cglm/struct/clipspace/view_rh_no.h | 88 + .../include/cglm/struct/clipspace/view_rh_zo.h | 88 + libs/cglm/include/cglm/struct/color.h | 27 + libs/cglm/include/cglm/struct/curve.h | 40 + libs/cglm/include/cglm/struct/euler.h | 152 ++ libs/cglm/include/cglm/struct/frustum.h | 155 ++ libs/cglm/include/cglm/struct/io.h | 82 + libs/cglm/include/cglm/struct/mat2.h | 258 +++ libs/cglm/include/cglm/struct/mat3.h | 285 ++++ libs/cglm/include/cglm/struct/mat4.h | 459 ++++++ libs/cglm/include/cglm/struct/plane.h | 40 + libs/cglm/include/cglm/struct/project.h | 120 ++ libs/cglm/include/cglm/struct/quat.h | 565 +++++++ libs/cglm/include/cglm/struct/sphere.h | 93 ++ libs/cglm/include/cglm/struct/vec2-ext.h | 239 +++ libs/cglm/include/cglm/struct/vec2.h | 561 +++++++ libs/cglm/include/cglm/struct/vec3-ext.h | 257 +++ libs/cglm/include/cglm/struct/vec3.h | 970 +++++++++++ libs/cglm/include/cglm/struct/vec4-ext.h | 257 +++ libs/cglm/include/cglm/struct/vec4.h | 814 +++++++++ libs/cglm/include/cglm/types-struct.h | 218 +++ libs/cglm/include/cglm/types.h | 95 ++ libs/cglm/include/cglm/util.h | 343 ++++ libs/cglm/include/cglm/vec2-ext.h | 241 +++ libs/cglm/include/cglm/vec2.h | 585 +++++++ libs/cglm/include/cglm/vec3-ext.h | 272 +++ libs/cglm/include/cglm/vec3.h | 1082 ++++++++++++ libs/cglm/include/cglm/vec4-ext.h | 313 ++++ libs/cglm/include/cglm/vec4.h | 1066 ++++++++++++ libs/cglm/include/cglm/version.h | 15 + libs/cglm/include/module.modulemap | 14 + libs/cglm/meson.build | 129 ++ libs/cglm/meson_options.txt | 2 + libs/cglm/src/affine.c | 153 ++ libs/cglm/src/affine2d.c | 81 + libs/cglm/src/bezier.c | 27 + libs/cglm/src/box.c | 96 ++ libs/cglm/src/cam.c | 171 ++ libs/cglm/src/clipspace/ortho_lh_no.c | 51 + libs/cglm/src/clipspace/ortho_lh_zo.c | 51 + libs/cglm/src/clipspace/ortho_rh_no.c | 51 + libs/cglm/src/clipspace/ortho_rh_zo.c | 51 + libs/cglm/src/clipspace/persp_lh_no.c | 110 ++ libs/cglm/src/clipspace/persp_lh_zo.c | 110 ++ libs/cglm/src/clipspace/persp_rh_no.c | 110 ++ libs/cglm/src/clipspace/persp_rh_zo.c | 110 ++ libs/cglm/src/clipspace/project_no.c | 21 + libs/cglm/src/clipspace/project_zo.c | 21 + libs/cglm/src/clipspace/view_lh_no.c | 27 + libs/cglm/src/clipspace/view_lh_zo.c | 27 + libs/cglm/src/clipspace/view_rh_no.c | 27 + libs/cglm/src/clipspace/view_rh_zo.c | 27 + libs/cglm/src/config.h | 22 + libs/cglm/src/curve.c | 15 + libs/cglm/src/ease.c | 195 +++ libs/cglm/src/euler.c | 63 + libs/cglm/src/frustum.c | 42 + libs/cglm/src/io.c | 46 + libs/cglm/src/ivec2.c | 99 ++ libs/cglm/src/ivec3.c | 99 ++ libs/cglm/src/ivec4.c | 99 ++ libs/cglm/src/mat2.c | 99 ++ libs/cglm/src/mat3.c | 105 ++ libs/cglm/src/mat4.c | 165 ++ libs/cglm/src/plane.c | 15 + libs/cglm/src/project.c | 33 + libs/cglm/src/quat.c | 231 +++ libs/cglm/src/ray.c | 13 + libs/cglm/src/sphere.c | 39 + libs/cglm/src/swift/empty.c | 1 + libs/cglm/src/vec2.c | 231 +++ libs/cglm/src/vec3.c | 419 +++++ libs/cglm/src/vec4.c | 383 +++++ libs/cglm/test/CMakeLists.txt | 48 + libs/cglm/test/include/common.h | 159 ++ libs/cglm/test/runner.c | 98 ++ libs/cglm/test/src/test_affine.h | 634 +++++++ libs/cglm/test/src/test_affine2d.h | 310 ++++ libs/cglm/test/src/test_affine_mat.h | 112 ++ libs/cglm/test/src/test_bezier.c | 66 + libs/cglm/test/src/test_cam.c | 55 + libs/cglm/test/src/test_cam_lh_no.c | 36 + libs/cglm/test/src/test_cam_lh_zo.c | 36 + libs/cglm/test/src/test_cam_rh_no.c | 36 + libs/cglm/test/src/test_cam_rh_zo.c | 36 + libs/cglm/test/src/test_camera.h | 68 + libs/cglm/test/src/test_clamp.c | 31 + libs/cglm/test/src/test_common.c | 341 ++++ libs/cglm/test/src/test_common.h | 118 ++ libs/cglm/test/src/test_euler.c | 45 + libs/cglm/test/src/test_ivec2.h | 189 +++ libs/cglm/test/src/test_ivec3.h | 199 +++ libs/cglm/test/src/test_ivec4.h | 214 +++ libs/cglm/test/src/test_mat2.h | 286 ++++ libs/cglm/test/src/test_mat3.h | 311 ++++ libs/cglm/test/src/test_mat4.h | 488 ++++++ libs/cglm/test/src/test_plane.h | 39 + libs/cglm/test/src/test_project.h | 92 ++ libs/cglm/test/src/test_quat.h | 1086 ++++++++++++ libs/cglm/test/src/test_ray.h | 34 + libs/cglm/test/src/test_struct.c | 78 + libs/cglm/test/src/test_vec2.h | 625 +++++++ libs/cglm/test/src/test_vec3.h | 1731 ++++++++++++++++++++ libs/cglm/test/src/test_vec4.h | 1420 ++++++++++++++++ libs/cglm/test/src/tests.c | 63 + libs/cglm/test/tests.h | 1672 +++++++++++++++++++ libs/cglm/win/.gitignore | 9 + libs/cglm/win/build.bat | 1 + libs/cglm/win/cglm-test.vcxproj | 204 +++ libs/cglm/win/cglm-test.vcxproj.filters | 104 ++ libs/cglm/win/cglm.sln | 41 + libs/cglm/win/cglm.vcxproj | 345 ++++ libs/cglm/win/cglm.vcxproj.filters | 562 +++++++ 287 files changed, 52123 insertions(+) create mode 100644 libs/cglm/.gitattributes create mode 100644 libs/cglm/.github/FUNDING.yml create mode 100644 libs/cglm/.gitignore create mode 100644 libs/cglm/.gitmodules create mode 100644 libs/cglm/.travis.yml create mode 100644 libs/cglm/.vscode/settings.json create mode 100644 libs/cglm/CMakeLists.txt create mode 100644 libs/cglm/CONTRIBUTING.md create mode 100644 libs/cglm/CREDITS create mode 100644 libs/cglm/LICENSE create mode 100644 libs/cglm/Makefile.am create mode 100644 libs/cglm/Package.swift create mode 100644 libs/cglm/README.md create mode 100644 libs/cglm/_config.yml create mode 100644 libs/cglm/appveyor.yml create mode 100644 libs/cglm/autogen.sh create mode 100644 libs/cglm/cglm.pc.in create mode 100644 libs/cglm/cglm.png create mode 100644 libs/cglm/cglm.podspec create mode 100644 libs/cglm/configure.ac create mode 100644 libs/cglm/docs/make.bat create mode 100644 libs/cglm/docs/source/affine-mat.rst create mode 100644 libs/cglm/docs/source/affine.rst create mode 100644 libs/cglm/docs/source/affine2d.rst create mode 100644 libs/cglm/docs/source/api.rst create mode 100644 libs/cglm/docs/source/bezier.rst create mode 100644 libs/cglm/docs/source/box.rst create mode 100644 libs/cglm/docs/source/build.rst create mode 100644 libs/cglm/docs/source/call.rst create mode 100644 libs/cglm/docs/source/cam.rst create mode 100644 libs/cglm/docs/source/cglm-intro.png create mode 100644 libs/cglm/docs/source/color.rst create mode 100644 libs/cglm/docs/source/conf.py create mode 100644 libs/cglm/docs/source/curve.rst create mode 100644 libs/cglm/docs/source/euler.rst create mode 100644 libs/cglm/docs/source/features.rst create mode 100644 libs/cglm/docs/source/frustum.rst create mode 100644 libs/cglm/docs/source/getting_started.rst create mode 100644 libs/cglm/docs/source/index.rst create mode 100644 libs/cglm/docs/source/io.rst create mode 100644 libs/cglm/docs/source/ivec2.rst create mode 100644 libs/cglm/docs/source/ivec3.rst create mode 100644 libs/cglm/docs/source/ivec4.rst create mode 100644 libs/cglm/docs/source/mat2.rst create mode 100644 libs/cglm/docs/source/mat3.rst create mode 100644 libs/cglm/docs/source/mat4.rst create mode 100644 libs/cglm/docs/source/opengl.rst create mode 100644 libs/cglm/docs/source/opt.rst create mode 100644 libs/cglm/docs/source/plane.rst create mode 100644 libs/cglm/docs/source/project.rst create mode 100644 libs/cglm/docs/source/quat.rst create mode 100644 libs/cglm/docs/source/ray.rst create mode 100644 libs/cglm/docs/source/sphere.rst create mode 100644 libs/cglm/docs/source/troubleshooting.rst create mode 100644 libs/cglm/docs/source/util.rst create mode 100644 libs/cglm/docs/source/vec2-ext.rst create mode 100644 libs/cglm/docs/source/vec2.rst create mode 100644 libs/cglm/docs/source/vec3-ext.rst create mode 100644 libs/cglm/docs/source/vec3.rst create mode 100644 libs/cglm/docs/source/vec4-ext.rst create mode 100644 libs/cglm/docs/source/vec4.rst create mode 100644 libs/cglm/docs/source/version.rst create mode 100644 libs/cglm/include/cglm/affine-mat.h create mode 100644 libs/cglm/include/cglm/affine.h create mode 100644 libs/cglm/include/cglm/affine2d.h create mode 100644 libs/cglm/include/cglm/applesimd.h create mode 100644 libs/cglm/include/cglm/bezier.h create mode 100644 libs/cglm/include/cglm/box.h create mode 100644 libs/cglm/include/cglm/call.h create mode 100644 libs/cglm/include/cglm/call/affine.h create mode 100644 libs/cglm/include/cglm/call/affine2d.h create mode 100644 libs/cglm/include/cglm/call/bezier.h create mode 100644 libs/cglm/include/cglm/call/box.h create mode 100644 libs/cglm/include/cglm/call/cam.h create mode 100644 libs/cglm/include/cglm/call/clipspace/ortho_lh_no.h create mode 100644 libs/cglm/include/cglm/call/clipspace/ortho_lh_zo.h create mode 100644 libs/cglm/include/cglm/call/clipspace/ortho_rh_no.h create mode 100644 libs/cglm/include/cglm/call/clipspace/ortho_rh_zo.h create mode 100644 libs/cglm/include/cglm/call/clipspace/persp_lh_no.h create mode 100644 libs/cglm/include/cglm/call/clipspace/persp_lh_zo.h create mode 100644 libs/cglm/include/cglm/call/clipspace/persp_rh_no.h create mode 100644 libs/cglm/include/cglm/call/clipspace/persp_rh_zo.h create mode 100644 libs/cglm/include/cglm/call/clipspace/project_no.h create mode 100644 libs/cglm/include/cglm/call/clipspace/project_zo.h create mode 100644 libs/cglm/include/cglm/call/clipspace/view_lh_no.h create mode 100644 libs/cglm/include/cglm/call/clipspace/view_lh_zo.h create mode 100644 libs/cglm/include/cglm/call/clipspace/view_rh_no.h create mode 100644 libs/cglm/include/cglm/call/clipspace/view_rh_zo.h create mode 100644 libs/cglm/include/cglm/call/curve.h create mode 100644 libs/cglm/include/cglm/call/ease.h create mode 100644 libs/cglm/include/cglm/call/euler.h create mode 100644 libs/cglm/include/cglm/call/frustum.h create mode 100644 libs/cglm/include/cglm/call/io.h create mode 100644 libs/cglm/include/cglm/call/ivec2.h create mode 100644 libs/cglm/include/cglm/call/ivec3.h create mode 100644 libs/cglm/include/cglm/call/ivec4.h create mode 100644 libs/cglm/include/cglm/call/mat2.h create mode 100644 libs/cglm/include/cglm/call/mat3.h create mode 100644 libs/cglm/include/cglm/call/mat4.h create mode 100644 libs/cglm/include/cglm/call/plane.h create mode 100644 libs/cglm/include/cglm/call/project.h create mode 100644 libs/cglm/include/cglm/call/quat.h create mode 100644 libs/cglm/include/cglm/call/ray.h create mode 100644 libs/cglm/include/cglm/call/sphere.h create mode 100644 libs/cglm/include/cglm/call/vec2.h create mode 100644 libs/cglm/include/cglm/call/vec3.h create mode 100644 libs/cglm/include/cglm/call/vec4.h create mode 100644 libs/cglm/include/cglm/cam.h create mode 100644 libs/cglm/include/cglm/cglm.h create mode 100644 libs/cglm/include/cglm/clipspace/ortho_lh_no.h create mode 100644 libs/cglm/include/cglm/clipspace/ortho_lh_zo.h create mode 100644 libs/cglm/include/cglm/clipspace/ortho_rh_no.h create mode 100644 libs/cglm/include/cglm/clipspace/ortho_rh_zo.h create mode 100644 libs/cglm/include/cglm/clipspace/persp.h create mode 100644 libs/cglm/include/cglm/clipspace/persp_lh_no.h create mode 100644 libs/cglm/include/cglm/clipspace/persp_lh_zo.h create mode 100644 libs/cglm/include/cglm/clipspace/persp_rh_no.h create mode 100644 libs/cglm/include/cglm/clipspace/persp_rh_zo.h create mode 100644 libs/cglm/include/cglm/clipspace/project_no.h create mode 100644 libs/cglm/include/cglm/clipspace/project_zo.h create mode 100644 libs/cglm/include/cglm/clipspace/view_lh.h create mode 100644 libs/cglm/include/cglm/clipspace/view_lh_no.h create mode 100644 libs/cglm/include/cglm/clipspace/view_lh_zo.h create mode 100644 libs/cglm/include/cglm/clipspace/view_rh.h create mode 100644 libs/cglm/include/cglm/clipspace/view_rh_no.h create mode 100644 libs/cglm/include/cglm/clipspace/view_rh_zo.h create mode 100644 libs/cglm/include/cglm/color.h create mode 100644 libs/cglm/include/cglm/common.h create mode 100644 libs/cglm/include/cglm/curve.h create mode 100644 libs/cglm/include/cglm/ease.h create mode 100644 libs/cglm/include/cglm/euler.h create mode 100644 libs/cglm/include/cglm/frustum.h create mode 100644 libs/cglm/include/cglm/io.h create mode 100644 libs/cglm/include/cglm/ivec2.h create mode 100644 libs/cglm/include/cglm/ivec3.h create mode 100644 libs/cglm/include/cglm/ivec4.h create mode 100644 libs/cglm/include/cglm/mat2.h create mode 100644 libs/cglm/include/cglm/mat3.h create mode 100644 libs/cglm/include/cglm/mat4.h create mode 100644 libs/cglm/include/cglm/plane.h create mode 100644 libs/cglm/include/cglm/project.h create mode 100644 libs/cglm/include/cglm/quat.h create mode 100644 libs/cglm/include/cglm/ray.h create mode 100644 libs/cglm/include/cglm/simd/arm.h create mode 100644 libs/cglm/include/cglm/simd/avx/affine.h create mode 100644 libs/cglm/include/cglm/simd/avx/mat4.h create mode 100644 libs/cglm/include/cglm/simd/intrin.h create mode 100644 libs/cglm/include/cglm/simd/neon/affine.h create mode 100644 libs/cglm/include/cglm/simd/neon/mat2.h create mode 100644 libs/cglm/include/cglm/simd/neon/mat4.h create mode 100644 libs/cglm/include/cglm/simd/neon/quat.h create mode 100644 libs/cglm/include/cglm/simd/sse2/affine.h create mode 100644 libs/cglm/include/cglm/simd/sse2/mat2.h create mode 100644 libs/cglm/include/cglm/simd/sse2/mat3.h create mode 100644 libs/cglm/include/cglm/simd/sse2/mat4.h create mode 100644 libs/cglm/include/cglm/simd/sse2/quat.h create mode 100644 libs/cglm/include/cglm/simd/x86.h create mode 100644 libs/cglm/include/cglm/sphere.h create mode 100644 libs/cglm/include/cglm/struct.h create mode 100644 libs/cglm/include/cglm/struct/affine.h create mode 100644 libs/cglm/include/cglm/struct/affine2d.h create mode 100644 libs/cglm/include/cglm/struct/box.h create mode 100644 libs/cglm/include/cglm/struct/cam.h create mode 100644 libs/cglm/include/cglm/struct/clipspace/ortho_lh_no.h create mode 100644 libs/cglm/include/cglm/struct/clipspace/ortho_lh_zo.h create mode 100644 libs/cglm/include/cglm/struct/clipspace/ortho_rh_no.h create mode 100644 libs/cglm/include/cglm/struct/clipspace/ortho_rh_zo.h create mode 100644 libs/cglm/include/cglm/struct/clipspace/persp_lh_no.h create mode 100644 libs/cglm/include/cglm/struct/clipspace/persp_lh_zo.h create mode 100644 libs/cglm/include/cglm/struct/clipspace/persp_rh_no.h create mode 100644 libs/cglm/include/cglm/struct/clipspace/persp_rh_zo.h create mode 100644 libs/cglm/include/cglm/struct/clipspace/view_lh_no.h create mode 100644 libs/cglm/include/cglm/struct/clipspace/view_lh_zo.h create mode 100644 libs/cglm/include/cglm/struct/clipspace/view_rh_no.h create mode 100644 libs/cglm/include/cglm/struct/clipspace/view_rh_zo.h create mode 100644 libs/cglm/include/cglm/struct/color.h create mode 100644 libs/cglm/include/cglm/struct/curve.h create mode 100644 libs/cglm/include/cglm/struct/euler.h create mode 100644 libs/cglm/include/cglm/struct/frustum.h create mode 100644 libs/cglm/include/cglm/struct/io.h create mode 100644 libs/cglm/include/cglm/struct/mat2.h create mode 100644 libs/cglm/include/cglm/struct/mat3.h create mode 100644 libs/cglm/include/cglm/struct/mat4.h create mode 100644 libs/cglm/include/cglm/struct/plane.h create mode 100644 libs/cglm/include/cglm/struct/project.h create mode 100644 libs/cglm/include/cglm/struct/quat.h create mode 100644 libs/cglm/include/cglm/struct/sphere.h create mode 100644 libs/cglm/include/cglm/struct/vec2-ext.h create mode 100644 libs/cglm/include/cglm/struct/vec2.h create mode 100644 libs/cglm/include/cglm/struct/vec3-ext.h create mode 100644 libs/cglm/include/cglm/struct/vec3.h create mode 100644 libs/cglm/include/cglm/struct/vec4-ext.h create mode 100644 libs/cglm/include/cglm/struct/vec4.h create mode 100644 libs/cglm/include/cglm/types-struct.h create mode 100644 libs/cglm/include/cglm/types.h create mode 100644 libs/cglm/include/cglm/util.h create mode 100644 libs/cglm/include/cglm/vec2-ext.h create mode 100644 libs/cglm/include/cglm/vec2.h create mode 100644 libs/cglm/include/cglm/vec3-ext.h create mode 100644 libs/cglm/include/cglm/vec3.h create mode 100644 libs/cglm/include/cglm/vec4-ext.h create mode 100644 libs/cglm/include/cglm/vec4.h create mode 100644 libs/cglm/include/cglm/version.h create mode 100644 libs/cglm/include/module.modulemap create mode 100644 libs/cglm/meson.build create mode 100644 libs/cglm/meson_options.txt create mode 100644 libs/cglm/src/affine.c create mode 100644 libs/cglm/src/affine2d.c create mode 100644 libs/cglm/src/bezier.c create mode 100644 libs/cglm/src/box.c create mode 100644 libs/cglm/src/cam.c create mode 100644 libs/cglm/src/clipspace/ortho_lh_no.c create mode 100644 libs/cglm/src/clipspace/ortho_lh_zo.c create mode 100644 libs/cglm/src/clipspace/ortho_rh_no.c create mode 100644 libs/cglm/src/clipspace/ortho_rh_zo.c create mode 100644 libs/cglm/src/clipspace/persp_lh_no.c create mode 100644 libs/cglm/src/clipspace/persp_lh_zo.c create mode 100644 libs/cglm/src/clipspace/persp_rh_no.c create mode 100644 libs/cglm/src/clipspace/persp_rh_zo.c create mode 100644 libs/cglm/src/clipspace/project_no.c create mode 100644 libs/cglm/src/clipspace/project_zo.c create mode 100644 libs/cglm/src/clipspace/view_lh_no.c create mode 100644 libs/cglm/src/clipspace/view_lh_zo.c create mode 100644 libs/cglm/src/clipspace/view_rh_no.c create mode 100644 libs/cglm/src/clipspace/view_rh_zo.c create mode 100644 libs/cglm/src/config.h create mode 100644 libs/cglm/src/curve.c create mode 100644 libs/cglm/src/ease.c create mode 100644 libs/cglm/src/euler.c create mode 100644 libs/cglm/src/frustum.c create mode 100644 libs/cglm/src/io.c create mode 100644 libs/cglm/src/ivec2.c create mode 100644 libs/cglm/src/ivec3.c create mode 100644 libs/cglm/src/ivec4.c create mode 100644 libs/cglm/src/mat2.c create mode 100644 libs/cglm/src/mat3.c create mode 100644 libs/cglm/src/mat4.c create mode 100644 libs/cglm/src/plane.c create mode 100644 libs/cglm/src/project.c create mode 100644 libs/cglm/src/quat.c create mode 100644 libs/cglm/src/ray.c create mode 100644 libs/cglm/src/sphere.c create mode 100644 libs/cglm/src/swift/empty.c create mode 100644 libs/cglm/src/vec2.c create mode 100644 libs/cglm/src/vec3.c create mode 100644 libs/cglm/src/vec4.c create mode 100644 libs/cglm/test/CMakeLists.txt create mode 100644 libs/cglm/test/include/common.h create mode 100644 libs/cglm/test/runner.c create mode 100644 libs/cglm/test/src/test_affine.h create mode 100644 libs/cglm/test/src/test_affine2d.h create mode 100644 libs/cglm/test/src/test_affine_mat.h create mode 100644 libs/cglm/test/src/test_bezier.c create mode 100644 libs/cglm/test/src/test_cam.c create mode 100644 libs/cglm/test/src/test_cam_lh_no.c create mode 100644 libs/cglm/test/src/test_cam_lh_zo.c create mode 100644 libs/cglm/test/src/test_cam_rh_no.c create mode 100644 libs/cglm/test/src/test_cam_rh_zo.c create mode 100644 libs/cglm/test/src/test_camera.h create mode 100644 libs/cglm/test/src/test_clamp.c create mode 100644 libs/cglm/test/src/test_common.c create mode 100644 libs/cglm/test/src/test_common.h create mode 100644 libs/cglm/test/src/test_euler.c create mode 100644 libs/cglm/test/src/test_ivec2.h create mode 100644 libs/cglm/test/src/test_ivec3.h create mode 100644 libs/cglm/test/src/test_ivec4.h create mode 100644 libs/cglm/test/src/test_mat2.h create mode 100644 libs/cglm/test/src/test_mat3.h create mode 100644 libs/cglm/test/src/test_mat4.h create mode 100644 libs/cglm/test/src/test_plane.h create mode 100644 libs/cglm/test/src/test_project.h create mode 100644 libs/cglm/test/src/test_quat.h create mode 100644 libs/cglm/test/src/test_ray.h create mode 100644 libs/cglm/test/src/test_struct.c create mode 100644 libs/cglm/test/src/test_vec2.h create mode 100644 libs/cglm/test/src/test_vec3.h create mode 100644 libs/cglm/test/src/test_vec4.h create mode 100644 libs/cglm/test/src/tests.c create mode 100644 libs/cglm/test/tests.h create mode 100644 libs/cglm/win/.gitignore create mode 100644 libs/cglm/win/build.bat create mode 100644 libs/cglm/win/cglm-test.vcxproj create mode 100644 libs/cglm/win/cglm-test.vcxproj.filters create mode 100644 libs/cglm/win/cglm.sln create mode 100644 libs/cglm/win/cglm.vcxproj create mode 100644 libs/cglm/win/cglm.vcxproj.filters diff --git a/CMakeLists.txt b/CMakeLists.txt index ef38dec..a29a6f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,11 +20,17 @@ add_library(glad ${SRC_ROOT}/gl/glad/glad.c) # add_library(stb_image src/stb_image/stb_image.c) add_subdirectory(${LIB_ROOT}/assimp) add_subdirectory(${LIB_ROOT}/honeysuckle) +add_subdirectory(${LIB_ROOT}/cglm) set(HONEY_LIB_FILES ${SRC_ROOT}/logging/logging.c + ${SRC_ROOT}/gl/honey_window.c + ${SRC_ROOT}/gl/honey_shader.c + ${SRC_ROOT}/gl/honey_gl_error.c + ${SRC_ROOT}/gl/honey_gl.c + ${SRC_ROOT}/options/honey_options.c ) diff --git a/libs/cglm/.gitattributes b/libs/cglm/.gitattributes new file mode 100644 index 0000000..15a5c58 --- /dev/null +++ b/libs/cglm/.gitattributes @@ -0,0 +1 @@ +*.h linguist-language=C diff --git a/libs/cglm/.github/FUNDING.yml b/libs/cglm/.github/FUNDING.yml new file mode 100644 index 0000000..d5bb755 --- /dev/null +++ b/libs/cglm/.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 diff --git a/libs/cglm/.gitignore b/libs/cglm/.gitignore new file mode 100644 index 0000000..5eec6c2 --- /dev/null +++ b/libs/cglm/.gitignore @@ -0,0 +1,81 @@ +*.xcodeproj +*.xcworkspace +*.sln +*.vcxproj +*.vcxproj.* +*.suo +*.sdf +*.opensdf +ipch/ +Debug/ +Release/ +.DS_Store +.vs +*.nupkg +*.opendb +packages.config +/aclocal.m4 +/ar-lib +/autom4te.cache/ +/compile +/config.guess +/config.log +/config.status +/config.sub +/configure +/depcomp +/install-sh +/ltmain.sh +/missing +/libtool +/.libs/ +.deps/ +*.[oa] +*.l[oa] +Makefile +Makefile.in +m4/*.m4 +.buildstamp +.dirstamp +packages/ +.anjuta/* +*.anjuta* +config.h.* +/config.h +stamp* +COPYING +.idea/* +*.VC.db +cscope.* +*-git-ignored-file.* +test/*.trs +test/test_* +*.log +test/.libs/* +test/tests +cglm_arm/* +cglm_test_ios/* +cglm_test_iosTests/* +docs/build/* +win/cglm_test_* +* copy.* +*.o +*.obj +*codeanalysis.*.xml +*codeanalysis.xml +*.lib +*.tlog +win/x64 +win/x85 +win/Debug +cglm-test-ios* +/cglm.pc +test-driver +Default-568h@2x.png +build/ +conftest.dir/* +confdefs.h +*.xcuserdatad +.idea +cmake-build-debug +*.o.tmp diff --git a/libs/cglm/.gitmodules b/libs/cglm/.gitmodules new file mode 100644 index 0000000..e69de29 diff --git a/libs/cglm/.travis.yml b/libs/cglm/.travis.yml new file mode 100644 index 0000000..7d3d6e0 --- /dev/null +++ b/libs/cglm/.travis.yml @@ -0,0 +1,68 @@ +language: c + +os: + - linux + - osx + +arch: + - amd64 + - ppc64le + - s390x + - arm64 + +sudo: required +dist: trusty + +compiler: + - clang + - gcc + +matrix: + fast_finish: true + exclude: + # Skip GCC builds on macOS. + - os: osx + compiler: gcc + include: + # Additional GCC builds for code coverage. + - os: linux + compiler: gcc + env: CODE_COVERAGE=ON + +cache: + apt: true + +addons: + apt: + packages: + - clang-3.6 + - lcov + +branches: + only: + - master + +script: + - sh ./autogen.sh + - if [[ "$CC" == "gcc" && "$CODE_COVERAGE" == "ON" ]]; then + ./configure CFLAGS="-ftest-coverage -fprofile-arcs -coverage"; + else + ./configure; + fi + - make + - make check + +after_success: + - if [[ "$CC" == "gcc" && "$CODE_COVERAGE" == "ON" ]]; then + pip install --user cpp-coveralls && + coveralls + --build-root . + --exclude lib + --exclude test + --gcov-options '\-lp' + --verbose && + bash <(curl -s https://codecov.io/bash); + fi + +# after_failure: +# - cat ./test-suite.log diff --git a/libs/cglm/.vscode/settings.json b/libs/cglm/.vscode/settings.json new file mode 100644 index 0000000..5b62438 --- /dev/null +++ b/libs/cglm/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "C_Cpp.default.configurationProvider": "vector-of-bool.cmake-tools", + "restructuredtext.confPath": "${workspaceFolder}/docs/source" +} \ No newline at end of file diff --git a/libs/cglm/CMakeLists.txt b/libs/cglm/CMakeLists.txt new file mode 100644 index 0000000..4200ee8 --- /dev/null +++ b/libs/cglm/CMakeLists.txt @@ -0,0 +1,170 @@ +cmake_minimum_required(VERSION 3.8.2) +project(cglm VERSION 0.8.6 LANGUAGES C) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED YES) +set(DEFAULT_BUILD_TYPE "Release") + +set(CGLM_BUILD) +option(CGLM_SHARED "Shared build" OFF) +option(CGLM_STATIC "Static build" ON) +option(CGLM_USE_C99 "" ON) +option(CGLM_USE_TEST "Enable Tests" OFF) + +if(NOT CGLM_STATIC AND CGLM_SHARED) + set(CGLM_BUILD SHARED) +else(CGLM_STATIC) + set(CGLM_BUILD STATIC) +endif() + +if(CGLM_USE_C99) + set(CMAKE_C_STANDARD 99) +endif() + +if(MSVC) + add_definitions(-DNDEBUG -D_WINDOWS -D_USRDLL) + add_compile_options(/W3 /Ox /Gy /Oi /TC) + + # Ref: https://skia.googlesource.com/third_party/sdl/+/refs/heads/master/CMakeLists.txt#225 + # Make sure /RTC1 is disabled, otherwise it will use functions from the CRT + foreach(flag_var + CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) + string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}") + endforeach(flag_var) +else() + add_compile_options(-Wall -Werror -O3) +endif() + +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") + set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() + +include(GNUInstallDirs) + +set(CPACK_PROJECT_NAME ${PROJECT_NAME}) +set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) + +if(NOT CPack_CMake_INCLUDED) + include(CPack) +endif() + +# Target Start +add_library(${PROJECT_NAME} + ${CGLM_BUILD} + src/euler.c + src/affine.c + src/io.c + src/quat.c + src/cam.c + src/vec2.c + src/vec3.c + src/vec4.c + src/ivec2.c + src/ivec3.c + src/ivec4.c + src/mat2.c + src/mat3.c + src/mat4.c + src/plane.c + src/frustum.c + src/box.c + src/project.c + src/sphere.c + src/ease.c + src/curve.c + src/bezier.c + src/ray.c + src/affine2d.c + src/clipspace/persp_lh_zo.c + src/clipspace/persp_rh_zo.c + src/clipspace/persp_lh_no.c + src/clipspace/persp_rh_no.c + src/clipspace/ortho_lh_zo.c + src/clipspace/ortho_rh_zo.c + src/clipspace/ortho_lh_no.c + src/clipspace/ortho_rh_no.c + src/clipspace/view_lh_zo.c + src/clipspace/view_rh_zo.c + src/clipspace/view_lh_no.c + src/clipspace/view_rh_no.c + ) + +if(CGLM_SHARED) + add_definitions(-DCGLM_EXPORTS) +else() + target_compile_definitions(${PROJECT_NAME} PUBLIC -DCGLM_STATIC) +endif() + +set_target_properties(${PROJECT_NAME} PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR}) + +if(WIN32) + # Because SOVERSION has no effect to file naming on Windows + set_target_properties(${PROJECT_NAME} PROPERTIES + RUNTIME_OUTPUT_NAME ${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}) +endif() + +target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src +) + +# Target for header-only usage +add_library(${PROJECT_NAME}_headers INTERFACE) +target_include_directories(${PROJECT_NAME}_headers INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/include) + +# Test Configuration +if(CGLM_USE_TEST) + include(CTest) + enable_testing() + add_subdirectory(test) +endif() + +# Install +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +install(DIRECTORY include/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + PATTERN ".*" EXCLUDE) + +# Config +export(TARGETS ${PROJECT_NAME} + NAMESPACE ${PROJECT_NAME}:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" +) + +install(EXPORT ${PROJECT_NAME} + FILE "${PROJECT_NAME}Config.cmake" + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) + +set(PACKAGE_NAME ${PROJECT_NAME}) +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix ${CMAKE_INSTALL_PREFIX}) +if (IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") + set(includedir "${CMAKE_INSTALL_INCLUDEDIR}") +else() + set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") +endif() +if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") + set(libdir "${CMAKE_INSTALL_LIBDIR}") +else() + set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") +endif() +set(PACKAGE_VERSION "${PROJECT_VERSION}") +configure_file(${CMAKE_CURRENT_LIST_DIR}/cglm.pc.in ${CMAKE_BINARY_DIR}/cglm.pc @ONLY) + +install(FILES ${CMAKE_BINARY_DIR}/cglm.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/libs/cglm/CONTRIBUTING.md b/libs/cglm/CONTRIBUTING.md new file mode 100644 index 0000000..f25a6ab --- /dev/null +++ b/libs/cglm/CONTRIBUTING.md @@ -0,0 +1,53 @@ +# CONTRIBUTING + +Any contributions (code, documentation, ...) are welcome. + +# New Features +- This library may not accept all new features, it is better to create an issue and get approval before coding +- You must add test for every new feature +- The feature must be compiled on both UNIX/POSIX systems (e.g. macos, linux...) and Windows + +# Code Style +This library is written with C99, don't try to add C++ files (yes it can compiled into lib), +if you have enough reason to add C++ files than create an issue and get approval before coding, + +- All functions must have `glm` prefix +- Lines should be wrapped at 80 characters. +- Don't invent new style for existing ones +- Use C89 style comments (`/* comments */`) not C++ style comments (`// comments`) +- Don't use TABs instead use 2 spaces for TABs +- All indents must be 2 spaces, not 1 nor 4 space +- All functions in `include` folder must be exported by `CGLM_EXPORT` and wrapped by `extern "C" {` for C++ +- Crate new line for return type, attribs: + +```C +CGLM_INLINE +void +glm_mul(mat4 m1, mat4 m2, mat4 dest) +``` + +not acceptable: + +```C +CGLM_INLINE void glm_mul(mat4 m1, mat4 m2, mat4 dest) +``` +- Variables must be declared at the top of a scope before usage: +```C +int x; +int y; + +x = y = 0; +``` + +not acceptable: + +```C +int x; + +x = 0; +int y = 0; +``` + +- All files must retain same LICENSE statement +- Code with warnings will not be accepted, please suppress them (not by disabling them) +- Run code anaylysis before submitting pull requests, if you use Xcode you can enable Sanitizer in scheme, you can use valgrind in linux diff --git a/libs/cglm/CREDITS b/libs/cglm/CREDITS new file mode 100644 index 0000000..00cc832 --- /dev/null +++ b/libs/cglm/CREDITS @@ -0,0 +1,84 @@ +This library [initially] used some [piece of] implementations +(may include codes) from these open source projects/resources: + +1. Initial 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. Initial 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/ + +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 + +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 + +12. vec2 cross product +http://allenchou.net/2013/07/cross-product-of-2d-vectors/ + +13. Ray triangle intersect +Möller–Trumbore ray-triangle intersection algorithm, from "Fast, Minimum Storage Ray/Triangle Intersection" +Authors: + Thomas Möller (tompa@clarus.se) + Ben Trumbore (wbt@graphics.cornell.edu) +Link to paper: http://webserver2.tecgraf.puc-rio.br/~mgattass/cg/trbRR/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf + +14. ARM NEON: Matrix Vector Multiplication +https://stackoverflow.com/a/57793352/2676533 + +16. ARM NEON Div + +http://github.com/microsoft/DirectXMath + +17. Pick Matrix + +glu project -> project.c diff --git a/libs/cglm/LICENSE b/libs/cglm/LICENSE new file mode 100644 index 0000000..c92e559 --- /dev/null +++ b/libs/cglm/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Recep Aslantas + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +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. diff --git a/libs/cglm/Makefile.am b/libs/cglm/Makefile.am new file mode 100644 index 0000000..7132e60 --- /dev/null +++ b/libs/cglm/Makefile.am @@ -0,0 +1,250 @@ +#****************************************************************************** +# Copyright (c), Recep Aslantas. * +# * +# MIT License (MIT), http://opensource.org/licenses/MIT * +# Full license can be found in the LICENSE file * +# * +#****************************************************************************** + +ACLOCAL_AMFLAGS = -I m4 +AM_CFLAGS = -Wall \ + -std=gnu11 \ + -O3 \ + -Wstrict-aliasing=2 \ + -fstrict-aliasing \ + -Werror=strict-prototypes + +lib_LTLIBRARIES = libcglm.la +libcglm_la_LDFLAGS = -no-undefined -version-info 0:1:0 + +checkLDFLAGS = -L./.libs \ + -lm \ + -lcglm +checkCFLAGS = $(AM_CFLAGS) \ + -std=gnu11 \ + -O3 \ + -DCGLM_DEFINE_PRINTS \ + -I./include + +check_PROGRAMS = test/tests +TESTS = $(check_PROGRAMS) + +test_tests_LDFLAGS = $(checkLDFLAGS) +test_tests_CFLAGS = $(checkCFLAGS) + +cglmdir=$(includedir)/cglm +cglm_HEADERS = include/cglm/version.h \ + include/cglm/common.h \ + include/cglm/types.h \ + include/cglm/types-struct.h \ + include/cglm/cglm.h \ + include/cglm/call.h \ + include/cglm/struct.h \ + include/cglm/cam.h \ + include/cglm/io.h \ + include/cglm/mat4.h \ + include/cglm/mat3.h \ + include/cglm/mat2.h \ + include/cglm/affine.h \ + include/cglm/vec2.h \ + include/cglm/vec2-ext.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/curve.h \ + include/cglm/bezier.h \ + include/cglm/applesimd.h \ + include/cglm/ray.h \ + include/cglm/affine2d.h + +cglm_clipspacedir=$(includedir)/cglm/clipspace +cglm_clipspace_HEADERS = include/cglm/clipspace/persp.h \ + include/cglm/clipspace/persp_lh_zo.h \ + include/cglm/clipspace/persp_rh_zo.h \ + include/cglm/clipspace/persp_lh_no.h \ + include/cglm/clipspace/persp_rh_no.h \ + include/cglm/clipspace/ortho_lh_zo.h \ + include/cglm/clipspace/ortho_rh_zo.h \ + include/cglm/clipspace/ortho_lh_no.h \ + include/cglm/clipspace/ortho_rh_no.h \ + include/cglm/clipspace/view_lh.h \ + include/cglm/clipspace/view_rh.h \ + include/cglm/clipspace/view_lh_zo.h \ + include/cglm/clipspace/view_rh_zo.h \ + include/cglm/clipspace/view_lh_no.h \ + include/cglm/clipspace/view_rh_no.h \ + include/cglm/clipspace/project_zo.h \ + include/cglm/clipspace/project_no.h + +cglm_calldir=$(includedir)/cglm/call +cglm_call_HEADERS = include/cglm/call/mat4.h \ + include/cglm/call/mat3.h \ + include/cglm/call/mat2.h \ + include/cglm/call/vec2.h \ + include/cglm/call/vec3.h \ + include/cglm/call/vec4.h \ + include/cglm/call/affine.h \ + include/cglm/call/io.h \ + include/cglm/call/cam.h \ + include/cglm/call/quat.h \ + include/cglm/call/euler.h \ + include/cglm/call/plane.h \ + include/cglm/call/frustum.h \ + include/cglm/call/box.h \ + include/cglm/call/project.h \ + include/cglm/call/sphere.h \ + include/cglm/call/ease.h \ + include/cglm/call/curve.h \ + include/cglm/call/bezier.h \ + include/cglm/call/ray.h \ + include/cglm/call/affine2d.h + +cglm_call_clipspacedir=$(includedir)/cglm/call/clipspace +cglm_call_clipspace_HEADERS = include/cglm/call/clipspace/persp_lh_zo.h \ + include/cglm/call/clipspace/persp_rh_zo.h \ + include/cglm/call/clipspace/persp_lh_no.h \ + include/cglm/call/clipspace/persp_rh_no.h \ + include/cglm/call/clipspace/ortho_lh_zo.h \ + include/cglm/call/clipspace/ortho_rh_zo.h \ + include/cglm/call/clipspace/ortho_lh_no.h \ + include/cglm/call/clipspace/ortho_rh_no.h \ + include/cglm/call/clipspace/view_lh_zo.h \ + include/cglm/call/clipspace/view_rh_zo.h \ + include/cglm/call/clipspace/view_lh_no.h \ + include/cglm/call/clipspace/view_rh_no.h \ + include/cglm/call/clipspace/project_no.h \ + include/cglm/call/clipspace/project_zo.h + +cglm_simddir=$(includedir)/cglm/simd +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 \ + include/cglm/simd/sse2/mat4.h \ + include/cglm/simd/sse2/mat3.h \ + include/cglm/simd/sse2/mat2.h \ + include/cglm/simd/sse2/quat.h + +cglm_simd_avxdir=$(includedir)/cglm/simd/avx +cglm_simd_avx_HEADERS = include/cglm/simd/avx/mat4.h \ + include/cglm/simd/avx/affine.h + +cglm_simd_neondir=$(includedir)/cglm/simd/neon +cglm_simd_neon_HEADERS = include/cglm/simd/neon/mat4.h \ + include/cglm/simd/neon/mat2.h \ + include/cglm/simd/neon/affine.h \ + include/cglm/simd/neon/quat.h + +cglm_structdir=$(includedir)/cglm/struct +cglm_struct_HEADERS = include/cglm/struct/mat4.h \ + include/cglm/struct/mat3.h \ + include/cglm/struct/mat2.h \ + include/cglm/struct/vec2.h \ + include/cglm/struct/vec2-ext.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 \ + include/cglm/struct/affine2d.h + +cglm_struct_clipspacedir=$(includedir)/cglm/struct/clipspace +cglm_struct_clipspace_HEADERS = include/cglm/struct/clipspace/persp_lh_zo.h \ + include/cglm/struct/clipspace/persp_rh_zo.h \ + include/cglm/struct/clipspace/persp_lh_no.h \ + include/cglm/struct/clipspace/persp_rh_no.h \ + include/cglm/struct/clipspace/ortho_lh_zo.h \ + include/cglm/struct/clipspace/ortho_rh_zo.h \ + include/cglm/struct/clipspace/ortho_lh_no.h \ + include/cglm/struct/clipspace/ortho_rh_no.h \ + include/cglm/struct/clipspace/view_lh_zo.h \ + include/cglm/struct/clipspace/view_rh_zo.h \ + include/cglm/struct/clipspace/view_lh_no.h \ + include/cglm/struct/clipspace/view_rh_no.h + +libcglm_la_SOURCES=\ + src/euler.c \ + src/affine.c \ + src/io.c \ + src/quat.c \ + src/cam.c \ + src/vec2.c \ + src/vec3.c \ + src/vec4.c \ + src/mat2.c \ + src/mat3.c \ + src/mat4.c \ + src/plane.c \ + src/frustum.c \ + src/box.c \ + src/project.c \ + src/sphere.c \ + src/ease.c \ + src/curve.c \ + src/bezier.c \ + src/ray.c \ + src/affine2d.c \ + src/clipspace/ortho_lh_no.c \ + src/clipspace/ortho_lh_zo.c \ + src/clipspace/ortho_rh_no.c \ + src/clipspace/ortho_rh_zo.c \ + src/clipspace/persp_lh_no.c \ + src/clipspace/persp_lh_zo.c \ + src/clipspace/persp_rh_no.c \ + src/clipspace/persp_rh_zo.c \ + src/clipspace/view_lh_no.c \ + src/clipspace/view_lh_zo.c \ + src/clipspace/view_rh_no.c \ + src/clipspace/view_rh_zo.c \ + src/clipspace/project_no.c \ + src/clipspace/project_zo.c + +test_tests_SOURCES=\ + test/runner.c \ + test/src/test_common.c \ + test/src/tests.c \ + test/src/test_cam.c \ + test/src/test_cam_lh_zo.c \ + test/src/test_cam_rh_zo.c \ + test/src/test_cam_lh_no.c \ + test/src/test_cam_rh_no.c \ + test/src/test_clamp.c \ + test/src/test_euler.c \ + test/src/test_bezier.c \ + test/src/test_struct.c + +pkgconfig_DATA=cglm.pc + +# 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 $${VPATH:-.}/post-build.sh diff --git a/libs/cglm/Package.swift b/libs/cglm/Package.swift new file mode 100644 index 0000000..ac0f7e4 --- /dev/null +++ b/libs/cglm/Package.swift @@ -0,0 +1,44 @@ +// swift-tools-version:5.2 + +import PackageDescription + +let package = Package( + name: "cglm", + products: [ + .library(name: "cglm", type: .static, targets: ["cglmHeader"]), + .library(name: "cglmc", targets: ["cglmCompiled"]), + ], + dependencies: [], + targets: [ + .target( + name: "cglmCompiled", + path: "./", + exclude: [ + "./docs", + "./src/swift", + "./include", + "./test", + "./win", + ], + sources: [ + "./src", + ], + publicHeadersPath: "./include" + ), + .target( + name: "cglmHeader", + path: "./", + exclude: [ + "./docs", + "./include", + "./test", + "./win", + ], + sources: [ + "./src/swift", + ], + publicHeadersPath: "./include" + ), + ], + cLanguageStandard: .c11 +) diff --git a/libs/cglm/README.md b/libs/cglm/README.md new file mode 100644 index 0000000..5f8968e --- /dev/null +++ b/libs/cglm/README.md @@ -0,0 +1,475 @@ +# 🎥 OpenGL Mathematics (glm) for `C` + +

+ +

+
+

+ + Build Status + + + Windows Build Status + + + Documentation Status + + + Codacy Badge + + + Coverage Status + + + Coverage Status + +

+ + Sponsors on Open Collective + + + Backers on Open Collective + +

+ +
+ +

+Highly optimized 2D|3D math library, also known as OpenGL Mathematics (glm) for `C`. cglm provides lot of utils to help math operations to be fast and quick to write. It is community friendly, feel free to bring any issues, bugs you faced. +

+ +--- + +#### 📚 Documentation + +Almost all functions (inline versions) and parameters are documented inside the corresponding headers.
+Complete documentation: http://cglm.readthedocs.io + +#### 📌 Note for previous versions: + +- _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 +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 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 +- **[major change]** by starting v0.7.3, inline print functions are disabled in release/production mode to eliminate print costs (see options in documentation). Print output also improved. You can disable colors if you need (see documentation) +- **[major change]** by starting v0.8.3, **cglm** supports alternative clipspace configuations e.g. Left Handed, Zero-to-One (_zo)... `CGLM_FORCE_DEPTH_ZERO_TO_ONE` and `CGLM_FORCE_LEFT_HANDED` is provided to control clipspace. You should be able to use **cglm** with Vulkan, DirectX and Metal now... see https://cglm.readthedocs.io/en/latest/opt.html#clipspace-option-s + +#### 📌 Note for C++ developers: +If you are not aware of the original GLM library yet, you may also want to look at: +https://github.com/g-truc/glm + +#### 📌 Note for new comers (Important): +- `vec4` and `mat4` variables must be aligned. (There will be unaligned versions later) +- **in** and **[in, out]** parameters must be initialized (please). But **[out]** parameters not, initializing out param is also redundant +- All functions are inline if you don't want to use pre-compiled versions with glmc_ prefix, you can ignore build process. Just include headers. +- if your debugger takes you to cglm headers then make sure you are not trying to copy vec4 to vec3 or alig issues... +- 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. + +#### 📌 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... ? + +**cglm** supports both *ARRAY API* and *STRUCT API*, so you can return structs if you utilize struct api (`glms_`). + +
+ + + + + + + + +
+
Like some other graphics libraries (especially OpenGL) this library use Column-Major layout to keep matrices in the memory.
+
 
+
In the future the library may support an option to use row-major layout, CURRENTLY if you need to row-major layout you will need to transpose it.
+
+ +
+ +## 🚀 Features +- **scalar** and **simd** (sse, avx, neon...) optimizations +- option to use different clipspaces e.g. Left Handed, Zero-to-One... (currrently right handed negative-one is default) +- 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...) +- affine transformations +- 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 (S*M*C, deCasteljau...) +- helpers to convert cglm types to Apple's simd library to pass cglm types to Metal GL without packing them on both sides +- ray intersection helpers +- and others... + +
+ +You have two options to call a function/operation: inline or library call (link) +Almost all functions are marked inline (always_inline) so compiler will probably inline. +To call pre-compiled versions, just use `glmc_` (c stands for 'call') instead of `glm_`. + +```C + #include /* for inline */ + #include /* for library call (this also includes cglm.h) */ + + mat4 rot, trans, rt; + /* ... */ + glm_mul(trans, rot, rt); /* inline */ + glmc_mul(trans, rot, rt); /* call from library */ +``` +Most of math functions are optimized manualy with SSE2 if available, if not? Dont worry there are non-sse versions of all operations + +You can pass matrices and vectors as array to functions rather than get address. + +```C + mat4 m = { + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + }; + + glm_translate(m, (vec3){1.0f, 0.0f, 0.0f}); +``` + +Library contains general purpose mat4 mul and inverse functions, and also contains some special forms (optimized) of these functions for affine transformations' matrices. If you want to multiply two affine transformation matrices you can use glm_mul instead of glm_mat4_mul and glm_inv_tr (ROT + TR) instead glm_mat4_inv +```C +/* multiplication */ +mat4 modelMat; +glm_mul(T, R, modelMat); + +/* othonormal rot + tr matrix inverse (rigid-body) */ +glm_inv_tr(modelMat); +``` + +### Struct API + +The struct API works as follows, note the `s` suffix on types, the `glms_` prefix on functions and the `GLMS_` prefix on constants: + +```C +#include + +mat4s mat = GLMS_MAT4_IDENTITY_INIT; +mat4s inv = glms_mat4_inv(mat); +``` + +Struct functions generally take their parameters as *values* and *return* their results, rather than taking pointers and writing to out parameters. That means your parameters can usually be `const`, if you're into that. + +The types used are actually unions that allow access to the same data multiple ways. One of those ways involves anonymous structures, available since C11. MSVC also supports it for earlier C versions out of the box and GCC/Clang do if you enable `-fms-extensions`. To explicitly enable these anonymous structures, `#define CGLM_USE_ANONYMOUS_STRUCT` to `1`, to disable them, to `0`. For backward compatibility, you can also `#define CGLM_NO_ANONYMOUS_STRUCT` (value is irrelevant) to disable them. If you don't specify explicitly, cglm will do a best guess based on your compiler and the C version you're using. + +## 🔨 Build + +### CMake (All platforms) +```bash +$ mkdir build +$ cd build +$ cmake .. # [Optional] -DCGLM_SHARED=ON +$ make +$ sudo make install # [Optional] +``` + +##### Cmake options with Defaults: + +```CMake +option(CGLM_SHARED "Shared build" ON) +option(CGLM_STATIC "Static build" OFF) +option(CGLM_USE_C99 "" OFF) # C11 +option(CGLM_USE_TEST "Enable Tests" OFF) # for make check - make test +``` + +#### Use as header-only library with your CMake project + +This requires no building or installation of cglm. + +* Example: + +``` cmake +cmake_minimum_required(VERSION 3.8.2) + +project() + +add_executable(${PROJECT_NAME} src/main.c) +target_link_libraries(${LIBRARY_NAME} PRIVATE + cglm_headers) + +add_subdirectory(external/cglm/ EXCLUDE_FROM_ALL) +``` + +#### Use with your CMake project +* Example: +```cmake +cmake_minimum_required(VERSION 3.8.2) + +project() + +add_executable(${PROJECT_NAME} src/main.c) +target_link_libraries(${LIBRARY_NAME} PRIVATE + cglm) + +add_subdirectory(external/cglm/) + +# or you can use find_package to configure cglm +``` + +### Meson (All platforms) + +```bash +$ meson build # [Optional] --default-library=static +$ cd build +$ ninja +$ sudo ninja install # [Optional] +``` + +##### Meson options with Defaults: + +```meson +c_std=c11 +buildtype=release +default_library=shared +enable_tests=false # to run tests: ninja test +``` +#### Use with your Meson project +* Example: +```meson +# Clone cglm or create a cglm.wrap under /subprojects +project('name', 'c') + +cglm_dep = dependency('cglm', fallback : 'cglm', 'cglm_dep') + +executable('exe', 'src/main.c', dependencies : cglm_dep) +``` + +### Swift (Swift Package Manager) + +Currently only default build options are supported. Add **cglm** dependency to your project: + +```swift +... +Package( + ... + dependencies: [ + ... + .package(url: "https://github.com/recp/cglm", .branch("master")), + ] + ... +) +``` + +Now add **cgml** as a dependency to your target. Product choices are: +- **cglm** for inlined version of the library which can be linked only statically +- **cglmc** for a compiled version of the library with no linking limitation + +```swift +... +.target( + ... + dependencies: [ + ... + .product(name: "cglm", package: "cglm"), + ] + ... +) +... +``` + +### Unix (Autotools) + +```bash +$ sh autogen.sh +$ ./configure +$ make +$ make check # [Optional] +$ [sudo] make install # [Optional] +``` + +This will also install pkg-config files so you can use +`pkg-config --cflags cglm` and `pkg-config --libs cglm` to retrieve compiler +and linker flags. + +The files will be installed into the given prefix (usually `/usr/local` by +default on Linux), but your pkg-config may not be configured to actually check +there. You can figure out where it's looking by running `pkg-config --variable +pc_path pkg-config` and change the path the files are installed to via +`./configure --with-pkgconfigdir=/your/path`. Alternatively, you can add the +prefix path to your `PKG_CONFIG_PATH` environment variable. + +### Windows (MSBuild) +Windows related build file and project files are located in `win` folder, +make sure you are inside `cglm/win` folder. +Code Analysis is enabled, so it may take awhile to build. + +```Powershell +$ cd win +$ .\build.bat +``` +if `msbuild` won't work (because of multi version VS) then try to build with `devenv`: +```Powershell +$ devenv cglm.sln /Build Release +``` + +#### Running Tests on Windows + +You can see test project in same visual studio solution file. It is enough to run that project to run tests. + +### 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 the inline versions of functions, then include the main header +```C +#include +``` +the header will include all headers. Then call the func you want e.g. rotate vector by axis: +```C +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_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_vec3_normalize_to(vec, result); +``` +like this function you may see `_to` postfix, this functions store results to another variables and save temp memory + + +to call pre-compiled versions include header with `c` postfix, c means call. Pre-compiled versions are just wrappers. +```C +#include +``` +this header will include all headers with c postfix. You need to call functions with c posfix: +```C +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: +```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 multiplying *m1* and *m2*, the result is stored in *m1*. This is why we send *m1* twice. You may store the result in a different matrix, this is 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: + +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 matrices the same way to other APIs e.g. Vulkan, DX... + +## Notes + +- This library uses float types only, does not support Integers, Double... yet +- If headers are not working properly with your compiler, IDE please open an issue, because I'm using GCC and clang to test it maybe sometimes MSVC + +**TODO:** +- [ ] Unit tests (In Progress) +- [ ] Unit tests for comparing cglm with glm results +- [x] Add version info +- [ ] Unaligned operations (e.g. `glm_umat4_mul`) +- [x] Extra documentation +- [x] ARM Neon Arch + + +## 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 diff --git a/libs/cglm/_config.yml b/libs/cglm/_config.yml new file mode 100644 index 0000000..2f7efbe --- /dev/null +++ b/libs/cglm/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-minimal \ No newline at end of file diff --git a/libs/cglm/appveyor.yml b/libs/cglm/appveyor.yml new file mode 100644 index 0000000..f4c54ef --- /dev/null +++ b/libs/cglm/appveyor.yml @@ -0,0 +1,7 @@ +image: Visual Studio 2017 + +build_script: +- ps: >- + cd win + + .\build.bat diff --git a/libs/cglm/autogen.sh b/libs/cglm/autogen.sh new file mode 100644 index 0000000..b3b8d82 --- /dev/null +++ b/libs/cglm/autogen.sh @@ -0,0 +1,21 @@ +#! /bin/sh +# +# Copyright (c), Recep Aslantas. +# +# MIT License (MIT), http://opensource.org/licenses/MIT +# Full license can be found in the LICENSE file +# + +cd $(dirname "$0") + +autoheader + +if [ "$(uname)" = "Darwin" ]; then + glibtoolize +else + libtoolize +fi + +aclocal -I m4 +autoconf +automake --add-missing --copy diff --git a/libs/cglm/cglm.pc.in b/libs/cglm/cglm.pc.in new file mode 100644 index 0000000..b80b401 --- /dev/null +++ b/libs/cglm/cglm.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: @PACKAGE_NAME@ +Description: OpenGL Mathematics (glm) for C +URL: https://github.com/recp/cglm +Version: @PACKAGE_VERSION@ +Cflags: -I${includedir} +Libs: -L${libdir} -lcglm @LIBS@ diff --git a/libs/cglm/cglm.png b/libs/cglm/cglm.png new file mode 100644 index 0000000..b450f6a Binary files /dev/null and b/libs/cglm/cglm.png differ diff --git a/libs/cglm/cglm.podspec b/libs/cglm/cglm.podspec new file mode 100644 index 0000000..a8609e8 --- /dev/null +++ b/libs/cglm/cglm.podspec @@ -0,0 +1,37 @@ +Pod::Spec.new do |s| + + # Description + s.name = "cglm" + s.version = "0.8.4" + s.summary = "📽 Highly Optimized Graphics Math (glm) for C" + s.description = <<-DESC +cglm is math library for graphics programming for C. See the documentation or README for all features. + 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.exclude_files = "src/win/*", "src/dllmain.c", "src/**/*.h" + s.preserve_paths = "include", "src" + s.header_mappings_dir = "include" + + # Linking + s.library = "m" + + # Configuration + s.pod_target_xcconfig = { + 'CLANG_ENABLE_MODULES' => 'NO', + 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES', + 'CLANG_WARN_DOCUMENTATION_COMMENTS' => 'NO', + 'GCC_C_LANGUAGE_STANDARD' => 'gnu11', + 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GLM_TESTS_NO_COLORFUL_OUTPUT' + } +end diff --git a/libs/cglm/configure.ac b/libs/cglm/configure.ac new file mode 100644 index 0000000..b6405ba --- /dev/null +++ b/libs/cglm/configure.ac @@ -0,0 +1,75 @@ +#***************************************************************************** +# Copyright (c), Recep Aslantas. * +# * +# MIT License (MIT), http://opensource.org/licenses/MIT * +# Full license can be found in the LICENSE file * +# * +#***************************************************************************** + +AC_PREREQ([2.69]) +AC_INIT([cglm], [0.8.6], [info@recp.me]) +AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects serial-tests]) + +# Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am. +: ${CFLAGS=""} + +AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_SRCDIR([src/]) +AC_CONFIG_HEADERS([config.h]) + +# Dependencies for pkg-config. +PKG_PROG_PKG_CONFIG +# Ancient versions of pkg-config (such as the one used in Travis CI) +# don't have this macro, so we need to do it manually. +m4_ifdef([PKG_INSTALLDIR], [ + PKG_INSTALLDIR +], [ + AC_ARG_WITH([pkgconfigdir], + [AS_HELP_STRING([--with-pkgconfigdir], + [pkg-config installation directory ['${libdir}/pkgconfig']])],, + [with_pkgconfigdir=]'${libdir}/pkgconfig') + AC_SUBST([pkgconfigdir], [$with_pkgconfigdir]) +]) + +# Checks for programs. +AC_PROG_CC +AM_PROG_CC_C_O + +AC_PROG_INSTALL +AM_PROG_AR + +AC_ENABLE_SHARED +AC_ENABLE_STATIC + +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. +AC_CHECK_HEADERS([limits.h \ + stddef.h \ + stdint.h \ + stdlib.h \ + string.h ]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_CHECK_HEADER_STDBOOL +AC_C_INLINE +AC_TYPE_INT32_T +AC_TYPE_INT64_T +AC_TYPE_SIZE_T +AC_TYPE_UINT16_T +AC_TYPE_UINT32_T +AC_TYPE_UINT64_T +AC_TYPE_UINT8_T + +# Checks for library functions. +AC_FUNC_ERROR_AT_LINE + +AC_CONFIG_FILES([Makefile cglm.pc]) + +AC_OUTPUT diff --git a/libs/cglm/docs/make.bat b/libs/cglm/docs/make.bat new file mode 100644 index 0000000..f0aed6a --- /dev/null +++ b/libs/cglm/docs/make.bat @@ -0,0 +1,36 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=python -msphinx +) +set SOURCEDIR=source +set BUILDDIR=build +set SPHINXPROJ=cglm + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The Sphinx module was not found. Make sure you have Sphinx installed, + echo.then set the SPHINXBUILD environment variable to point to the full + echo.path of the 'sphinx-build' executable. Alternatively you may add the + echo.Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd diff --git a/libs/cglm/docs/source/affine-mat.rst b/libs/cglm/docs/source/affine-mat.rst new file mode 100644 index 0000000..d0065e9 --- /dev/null +++ b/libs/cglm/docs/source/affine-mat.rst @@ -0,0 +1,99 @@ +.. default-domain:: C + +3D 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_mul_rot` +#. :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_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) + + .. 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/libs/cglm/docs/source/affine.rst b/libs/cglm/docs/source/affine.rst new file mode 100644 index 0000000..df2dcb7 --- /dev/null +++ b/libs/cglm/docs/source/affine.rst @@ -0,0 +1,345 @@ +.. default-domain:: C + +3D 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. + +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. + +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. + +The implementation would be: + +.. code-block:: c + :linenos: + + glm_translate(m, pivot); + glm_rotate(m, angle, axis); + glm_translate(m, pivotInv); /* pivotInv = -pivot */ + +.. _TransformsOrder: + +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? + +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?** + +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 + +.. 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): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +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_scale_uni` +#. :c:func:`glm_rotate_x` +#. :c:func:`glm_rotate_y` +#. :c:func:`glm_rotate_z` +#. :c:func:`glm_rotate_make` +#. :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` +#. :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_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_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(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_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 + + 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/libs/cglm/docs/source/affine2d.rst b/libs/cglm/docs/source/affine2d.rst new file mode 100644 index 0000000..f12cd59 --- /dev/null +++ b/libs/cglm/docs/source/affine2d.rst @@ -0,0 +1,140 @@ +.. default-domain:: C + +2D Affine Transforms +================================================================================ + +Header: cglm/affine2d.h + +2D Transforms uses `2d` suffix for naming. If there is no 2D suffix it is 3D function. + +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. + +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. + +Transforms Order +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +See :ref:`TransformsOrder` to read similar section. + + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_translate2d` +#. :c:func:`glm_translate2d_to` +#. :c:func:`glm_translate2d_x` +#. :c:func:`glm_translate2d_y` +#. :c:func:`glm_translate2d_make` +#. :c:func:`glm_scale2d_to` +#. :c:func:`glm_scale2d_make` +#. :c:func:`glm_scale2d` +#. :c:func:`glm_scale2d_uni` +#. :c:func:`glm_rotate2d_make` +#. :c:func:`glm_rotate2d` +#. :c:func:`glm_rotate2d_to` + +.. c:function:: void glm_translate2d(mat3 m, vec2 v) + + translate existing 2d transform matrix by *v* vector and stores result in same matrix + + Parameters: + | *[in, out]* **m** 2d affine transfrom + | *[in]* **v** translate vector [x, y] + +.. c:function:: void glm_translate2d_to(mat3 m, vec2 v, mat3 dest) + + translate existing 2d transform matrix by *v* vector and store result in dest + + Parameters: + | *[in]* **m** 2d affine transfrom + | *[in]* **v** translate vector [x, y] + | *[out]* **dest** translated matrix + +.. c:function:: void glm_translate2d_x(mat3 m, float x) + + translate existing 2d transform matrix by x factor + + Parameters: + | *[in, out]* **m** 2d affine transfrom + | *[in]* **x** x factor + +.. c:function:: void glm_translate2d_y(mat3 m, float y) + + translate existing 2d transform matrix by y factor + + Parameters: + | *[in, out]* **m** 2d affine transfrom + | *[in]* **y** y factor + +.. c:function:: void glm_translate2d_make(mat3 m, vec2 v) + + creates NEW translate 2d transform matrix by *v* vector + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **v** translate vector [x, y] + +.. c:function:: void glm_scale2d_to(mat3 m, vec2 v, mat3 dest) + + scale existing 2d transform matrix by *v* vector and store result in dest + + Parameters: + | *[in]* **m** affine transfrom + | *[in]* **v** scale vector [x, y] + | *[out]* **dest** scaled matrix + +.. c:function:: void glm_scale2d_make(mat3 m, vec2 v) + + creates NEW 2d scale matrix by *v* vector + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **v** scale vector [x, y] + +.. c:function:: void glm_scale2d(mat3 m, vec2 v) + + scales existing 2d transform matrix by *v* vector and stores result in same matrix + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **v** translate vector [x, y] + +.. c:function:: void glm_scale2d_uni(mat3 m, float s) + + applies uniform scale to existing 2d transform matrix v = [s, s] and stores result in same matrix + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **s** scale factor + +.. c:function:: void glm_rotate2d_make(mat3 m, float angle) + + creates NEW rotation matrix by angle around *Z* axis + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **angle** angle (radians) + +.. c:function:: void glm_rotate2d(mat3 m, float angle) + + rotate existing 2d transform matrix around *Z* axis by angle and store result in same matrix + + Parameters: + | *[in, out]* **m** affine transfrom + | *[in]* **angle** angle (radians) + +.. c:function:: void glm_rotate2d_to(mat3 m, float angle, mat3 dest) + + rotate existing 2d 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 \ No newline at end of file diff --git a/libs/cglm/docs/source/api.rst b/libs/cglm/docs/source/api.rst new file mode 100644 index 0000000..7ffb823 --- /dev/null +++ b/libs/cglm/docs/source/api.rst @@ -0,0 +1,59 @@ +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_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_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 +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: 1 + :caption: API categories: + + affine + affine-mat + affine2d + cam + frustum + box + quat + euler + mat2 + mat3 + mat4 + vec2 + vec2-ext + vec3 + vec3-ext + vec4 + vec4-ext + ivec2 + ivec3 + ivec4 + color + plane + project + util + io + call + sphere + curve + bezier + version + ray diff --git a/libs/cglm/docs/source/bezier.rst b/libs/cglm/docs/source/bezier.rst new file mode 100644 index 0000000..8b29751 --- /dev/null +++ b/libs/cglm/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/libs/cglm/docs/source/box.rst b/libs/cglm/docs/source/box.rst new file mode 100644 index 0000000..7a388e2 --- /dev/null +++ b/libs/cglm/docs/source/box.rst @@ -0,0 +1,181 @@ +.. 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` +#. :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` +#. :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 +~~~~~~~~~~~~~~~~~~~~~~~ + +.. 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_aabb_crop_until(vec3 box[2], vec3 cropBox[2], vec3 clampBox[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 + | *[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 + +.. 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 glm_aabb_isvalid(vec3 box[2]) + + | check if AABB is valid or not + + 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 + +.. c:function:: void glm_aabb_center(vec3 box[2], vec3 dest) + + | 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]* **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/libs/cglm/docs/source/build.rst b/libs/cglm/docs/source/build.rst new file mode 100644 index 0000000..e2eb23d --- /dev/null +++ b/libs/cglm/docs/source/build.rst @@ -0,0 +1,153 @@ +Build cglm +================================ + +| **cglm** does not have any external dependencies. + +**NOTE:** +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 + +CMake (All platforms): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: bash + :linenos: + + $ mkdir build + $ cd build + $ cmake .. # [Optional] -DCGLM_SHARED=ON + $ make + $ sudo make install # [Optional] + +**make** will build cglm to **build** folder. +If you don't want to install **cglm** to your system's folder you can get static and dynamic libs in this folder. + +**CMake Options:** + +.. code-block:: CMake + :linenos: + + option(CGLM_SHARED "Shared build" ON) + option(CGLM_STATIC "Static build" OFF) + option(CGLM_USE_C99 "" OFF) # C11 + option(CGLM_USE_TEST "Enable Tests" OFF) # for make check - make test + +**Use as header-only library with your CMake project example** +This requires no building or installation of cglm. + +.. code-block:: CMake + :linenos: + + cmake_minimum_required(VERSION 3.8.2) + + project() + + add_executable(${PROJECT_NAME} src/main.c) + target_link_libraries(${LIBRARY_NAME} PRIVATE + cglm_headers) + + add_subdirectory(external/cglm/ EXCLUDE_FROM_ALL) + +**Use with your CMake project example** + +.. code-block:: CMake + :linenos: + + cmake_minimum_required(VERSION 3.8.2) + + project() + + add_executable(${PROJECT_NAME} src/main.c) + target_link_libraries(${LIBRARY_NAME} PRIVATE + cglm) + + add_subdirectory(external/cglm/) + +Meson (All platforms): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: + :linenos: + + $ meson build # [Optional] --default-library=static + $ cd build + $ ninja + $ sudo ninja install # [Optional] + +**Meson Options:** + +.. code-block:: + :linenos: + + c_std=c11 + buildtype=release + default_library=shared + enable_tests=false # to run tests: ninja test + + +**Use with your Meson project** + +.. code-block:: + :linenos: + + # Clone cglm or create a cglm.wrap under /subprojects + project('name', 'c') + + cglm_dep = dependency('cglm', fallback : 'cglm', 'cglm_dep') + + executable('exe', 'src/main.c', dependencies : cglm_dep) + + +Unix (Autotools): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. code-block:: bash + :linenos: + + $ sh autogen.sh + $ ./configure + $ make + $ make check # run tests (optional) + $ [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. + +Windows (MSBuild): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +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. + +.. code-block:: bash + :linenos: + + $ cd win + $ .\build.bat + +if *msbuild* is not worked (because of multi versions of Visual Studio) +then try to build with *devenv*: + +.. code-block:: bash + :linenos: + + $ 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/libs/cglm/docs/source/call.rst b/libs/cglm/docs/source/call.rst new file mode 100644 index 0000000..f7765a7 --- /dev/null +++ b/libs/cglm/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/libs/cglm/docs/source/cam.rst b/libs/cglm/docs/source/cam.rst new file mode 100644 index 0000000..7afc5db --- /dev/null +++ b/libs/cglm/docs/source/cam.rst @@ -0,0 +1,313 @@ +.. 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_vec3_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 (click 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_persp_move_far` +#. :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 radians) + | *[in]* **aspect** aspect ratio ( width / height ) + | *[in]* **nearVal** near clipping plane + | *[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 + 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 + + **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 + +.. 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. + + **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]* **dir** 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]* **dir** 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/libs/cglm/docs/source/cglm-intro.png b/libs/cglm/docs/source/cglm-intro.png new file mode 100644 index 0000000..74ac74e Binary files /dev/null and b/libs/cglm/docs/source/cglm-intro.png differ diff --git a/libs/cglm/docs/source/color.rst b/libs/cglm/docs/source/color.rst new file mode 100644 index 0000000..62a4dc1 --- /dev/null +++ b/libs/cglm/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/libs/cglm/docs/source/conf.py b/libs/cglm/docs/source/conf.py new file mode 100644 index 0000000..eaf48b4 --- /dev/null +++ b/libs/cglm/docs/source/conf.py @@ -0,0 +1,203 @@ +# -*- coding: utf-8 -*- +# +# cglm documentation build configuration file, created by +# sphinx-quickstart on Tue Jun 6 20:31:05 2017. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '3.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +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'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'cglm' +copyright = u'2017, Recep Aslantas' +author = u'Recep Aslantas' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = u'0.8.6' +# The full version, including alpha/beta/rc tags. +release = u'0.8.6' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = [] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +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 +# documentation. +# +# 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' +} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + + +# -- Options for HTMLHelp output ------------------------------------------ + +# Output file base name for HTML help builder. +htmlhelp_basename = 'cglmdoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'cglm.tex', u'cglm Documentation', + u'Recep Aslantas', 'manual'), +] + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'cglm', u'cglm Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'cglm', u'cglm Documentation', + 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 + +# -- Options for the C domain ------------------------------------------------ + +c_id_attributes = ['__restrict'] diff --git a/libs/cglm/docs/source/curve.rst b/libs/cglm/docs/source/curve.rst new file mode 100644 index 0000000..26c9b75 --- /dev/null +++ b/libs/cglm/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/libs/cglm/docs/source/euler.rst b/libs/cglm/docs/source/euler.rst new file mode 100644 index 0000000..74ba4c2 --- /dev/null +++ b/libs/cglm/docs/source/euler.rst @@ -0,0 +1,182 @@ +.. 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_xyz` +#. :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 + + this is alias of glm_euler_xyz function + + Parameters: + | *[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) + + | build rotation matrix from euler angles + + Parameters: + | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle] + | *[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 [Xangle, Yangle, Zangle] + | *[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 [Xangle, Yangle, Zangle] + | *[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 [Xangle, Yangle, Zangle] + | *[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 [Xangle, Yangle, Zangle] + | *[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 [Xangle, Yangle, Zangle] + | *[in]* **ord** euler order + | *[in]* **dest** rotation matrix diff --git a/libs/cglm/docs/source/features.rst b/libs/cglm/docs/source/features.rst new file mode 100644 index 0000000..8113f63 --- /dev/null +++ b/libs/cglm/docs/source/features.rst @@ -0,0 +1,28 @@ +Features +================================================================================ + +* **scalar** and **simd** (sse, avx, neon...) optimizations +* option to use different clipspaces e.g. Left Handed, Zero-to-One... (currrently right handed negative-one is default) +* 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...) +* affine transformations +* 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...) +* helpers to convert cglm types to Apple's simd library to pass cglm types to Metal GL without packing them on both sides +* ray intersection helpers +* and others... diff --git a/libs/cglm/docs/source/frustum.rst b/libs/cglm/docs/source/frustum.rst new file mode 100644 index 0000000..b58913c --- /dev/null +++ b/libs/cglm/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_vec3_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/libs/cglm/docs/source/getting_started.rst b/libs/cglm/docs/source/getting_started.rst new file mode 100644 index 0000000..bf2b8f3 --- /dev/null +++ b/libs/cglm/docs/source/getting_started.rst @@ -0,0 +1,105 @@ +Getting Started +================================ + +Types: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**cglm** uses **glm** prefix for all functions e.g. glm_lookat. You can see supported types in common header file: + +.. code-block:: c + :linenos: + + 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]; + + #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: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**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 + + | Check :doc:`opt` page for more details + + 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: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*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** require 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. +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* +* Pre-compiled - *glmc_, glmc_u* + +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: + +.. code-block:: c + + CGLM_INLINE + void + glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest) + +The dest parameter is out parameter. Result will be stored in **dest**. +Also in this case matrix multiplication order is dest = m1 * m2. + +* Changing parameter order will change the multiplication order. +* You can pass all parameter same (this is similar to m1 `*=` m1), you can pass **dest** as m1 or m2 (this is similar to m1 `*=` m2) + +**v** postfix in function names +------------------------------- + +You may see **v** postfix in some function names, v stands for vector. +For instance consider a function that accepts three parameters x, y, z. +This function may be overloaded by **v** postfix to accept vector (vec3) instead of separate parameters. +In some places the v means that it will be apply to a vector. + +**_to** postfix in function names +--------------------------------- + +*_to* version of function will store the result in specified parameter instead of in-out parameter. +Some functions don't have _to prefix but they still behave like this e.g. glm_mat4_mul. diff --git a/libs/cglm/docs/source/index.rst b/libs/cglm/docs/source/index.rst new file mode 100644 index 0000000..34a71c4 --- /dev/null +++ b/libs/cglm/docs/source/index.rst @@ -0,0 +1,53 @@ +.. cglm documentation master file, created by + sphinx-quickstart on Tue Jun 6 20:31:05 2017. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +cglm Documentation +================================ + +**cglm** is an optimized 3D math library written in C99 (compatible with C89). +It is similar to the original **glm** library, except **cglm** is mainly for +**C**. + +**cglm** stores matrices as column-major order but in the future row-major is +considered to be supported as optional. + +.. toctree:: + :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: +=================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/libs/cglm/docs/source/io.rst b/libs/cglm/docs/source/io.rst new file mode 100644 index 0000000..cead0be --- /dev/null +++ b/libs/cglm/docs/source/io.rst @@ -0,0 +1,119 @@ +.. 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 + +Changes since **v0.7.3**: +* Now mis-alignment of columns are fixed: larger numbers are printed via %g and others are printed via %f. Column withs are calculated before print. +* Now values are colorful ;) +* Some print improvements +* New options with default values: + +.. code-block:: c + + #define CGLM_PRINT_PRECISION 5 + #define CGLM_PRINT_MAX_TO_SHORT 1e5 + #define CGLM_PRINT_COLOR "\033[36m" + #define CGLM_PRINT_COLOR_RESET "\033[0m" + +* Inline prints are only enabled in DEBUG mode and if **CGLM_DEFINE_PRINTS** is defined. + +Check options page. + +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` +#. :c:func:`glm_aabb_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 + +.. 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 diff --git a/libs/cglm/docs/source/ivec2.rst b/libs/cglm/docs/source/ivec2.rst new file mode 100644 index 0000000..c10bc4c --- /dev/null +++ b/libs/cglm/docs/source/ivec2.rst @@ -0,0 +1,163 @@ +.. default-domain:: C + +ivec2 +===== + +Header: cglm/ivec2.h + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_ivec2` +#. :c:func:`glm_ivec2_copy` +#. :c:func:`glm_ivec2_zero` +#. :c:func:`glm_ivec2_one` +#. :c:func:`glm_ivec2_add` +#. :c:func:`glm_ivec2_adds` +#. :c:func:`glm_ivec2_sub` +#. :c:func:`glm_ivec2_subs` +#. :c:func:`glm_ivec2_mul` +#. :c:func:`glm_ivec2_scale` +#. :c:func:`glm_ivec2_distance2` +#. :c:func:`glm_ivec2_distance` +#. :c:func:`glm_ivec2_maxv` +#. :c:func:`glm_ivec2_minv` +#. :c:func:`glm_ivec2_clamp` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_ivec2(int * v, ivec2 dest) + + init ivec2 using vec3 or vec4 + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_copy(ivec2 a, ivec2 dest) + + copy all members of [a] to [dest] + + Parameters: + | *[in]* **a** source vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_zero(ivec2 v) + + set all members of [v] to zero + + Parameters: + | *[out]* **v** vector + +.. c:function:: void glm_ivec2_one(ivec2 v) + + set all members of [v] to one + + Parameters: + | *[out]* **v** vector + +.. c:function:: void glm_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) + + add vector [a] to vector [b] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_adds(ivec2 v, int s, ivec2 dest) + + add scalar s to vector [v] and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest) + + subtract vector [b] from vector [a] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_subs(ivec2 v, int s, ivec2 dest) + + subtract scalar s from vector [v] and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest) + + multiply vector [a] with vector [b] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_scale(ivec2 v, int s, ivec2 dest) + + multiply vector [a] with scalar s and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: int glm_ivec2_distance2(ivec2 a, ivec2 b) + + squared distance between two vectors + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + + Returns: + squared distance (distance * distance) + +.. c:function:: float glm_ivec2_distance(ivec2 a, ivec2 b) + + distance between two vectors + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + + Returns: + distance + +.. c:function:: void glm_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest) + + set each member of dest to greater of vector a and b + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest) + + set each member of dest to lesser of vector a and b + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec2_clamp(ivec2 v, int minVal, int maxVal) + + clamp each member of [v] between minVal and maxVal (inclusive) + + Parameters: + | *[in, out]* **v** vector + | *[in]* **minVal** minimum value + | *[in]* **maxVal** maximum value diff --git a/libs/cglm/docs/source/ivec3.rst b/libs/cglm/docs/source/ivec3.rst new file mode 100644 index 0000000..312078a --- /dev/null +++ b/libs/cglm/docs/source/ivec3.rst @@ -0,0 +1,163 @@ +.. default-domain:: C + +ivec3 +===== + +Header: cglm/ivec3.h + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_ivec3` +#. :c:func:`glm_ivec3_copy` +#. :c:func:`glm_ivec3_zero` +#. :c:func:`glm_ivec3_one` +#. :c:func:`glm_ivec3_add` +#. :c:func:`glm_ivec3_adds` +#. :c:func:`glm_ivec3_sub` +#. :c:func:`glm_ivec3_subs` +#. :c:func:`glm_ivec3_mul` +#. :c:func:`glm_ivec3_scale` +#. :c:func:`glm_ivec3_distance2` +#. :c:func:`glm_ivec3_distance` +#. :c:func:`glm_ivec3_maxv` +#. :c:func:`glm_ivec3_minv` +#. :c:func:`glm_ivec3_clamp` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_ivec3(ivec4 v4, ivec3 dest) + + init ivec3 using ivec4 + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_copy(ivec3 a, ivec3 dest) + + copy all members of [a] to [dest] + + Parameters: + | *[in]* **a** source vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_zero(ivec3 v) + + set all members of [v] to zero + + Parameters: + | *[out]* **v** vector + +.. c:function:: void glm_ivec3_one(ivec3 v) + + set all members of [v] to one + + Parameters: + | *[out]* **v** vector + +.. c:function:: void glm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) + + add vector [a] to vector [b] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_adds(ivec3 v, int s, ivec3 dest) + + add scalar s to vector [v] and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest) + + subtract vector [b] from vector [a] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_subs(ivec3 v, int s, ivec3 dest) + + subtract scalar s from vector [v] and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest) + + multiply vector [a] with vector [b] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_scale(ivec3 v, int s, ivec3 dest) + + multiply vector [a] with scalar s and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: int glm_ivec3_distance2(ivec3 a, ivec3 b) + + squared distance between two vectors + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + + Returns: + squared distance (distance * distance) + +.. c:function:: float glm_ivec3_distance(ivec3 a, ivec3 b) + + distance between two vectors + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + + Returns: + distance + +.. c:function:: void glm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest) + + set each member of dest to greater of vector a and b + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest) + + set each member of dest to lesser of vector a and b + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec3_clamp(ivec3 v, int minVal, int maxVal) + + clamp each member of [v] between minVal and maxVal (inclusive) + + Parameters: + | *[in, out]* **v** vector + | *[in]* **minVal** minimum value + | *[in]* **maxVal** maximum value diff --git a/libs/cglm/docs/source/ivec4.rst b/libs/cglm/docs/source/ivec4.rst new file mode 100644 index 0000000..a175631 --- /dev/null +++ b/libs/cglm/docs/source/ivec4.rst @@ -0,0 +1,163 @@ +.. default-domain:: C + +ivec4 +===== + +Header: cglm/ivec4.h + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_ivec4` +#. :c:func:`glm_ivec4_copy` +#. :c:func:`glm_ivec4_zero` +#. :c:func:`glm_ivec4_one` +#. :c:func:`glm_ivec4_add` +#. :c:func:`glm_ivec4_adds` +#. :c:func:`glm_ivec4_sub` +#. :c:func:`glm_ivec4_subs` +#. :c:func:`glm_ivec4_mul` +#. :c:func:`glm_ivec4_scale` +#. :c:func:`glm_ivec4_distance2` +#. :c:func:`glm_ivec4_distance` +#. :c:func:`glm_ivec4_maxv` +#. :c:func:`glm_ivec4_minv` +#. :c:func:`glm_ivec4_clamp` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_ivec4(ivec3 v3, int last, ivec4 dest) + + init ivec4 using ivec3 + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_copy(ivec4 a, ivec4 dest) + + copy all members of [a] to [dest] + + Parameters: + | *[in]* **a** source vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_zero(ivec4 v) + + set all members of [v] to zero + + Parameters: + | *[out]* **v** vector + +.. c:function:: void glm_ivec4_one(ivec4 v) + + set all members of [v] to one + + Parameters: + | *[out]* **v** vector + +.. c:function:: void glm_ivec4_add(ivec4 a, ivec4 b, ivec4 dest) + + add vector [a] to vector [b] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_adds(ivec4 v, int s, ivec4 dest) + + add scalar s to vector [v] and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_sub(ivec4 a, ivec4 b, ivec4 dest) + + subtract vector [b] from vector [a] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_subs(ivec4 v, int s, ivec4 dest) + + subtract scalar s from vector [v] and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_mul(ivec4 a, ivec4 b, ivec4 dest) + + multiply vector [a] with vector [b] and store result in [dest] + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_scale(ivec4 v, int s, ivec4 dest) + + multiply vector [a] with scalar s and store result in [dest] + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination + +.. c:function:: int glm_ivec4_distance2(ivec4 a, ivec4 b) + + squared distance between two vectors + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + + Returns: + squared distance (distance * distance) + +.. c:function:: float glm_ivec4_distance(ivec4 a, ivec4 b) + + distance between two vectors + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + + Returns: + distance + +.. c:function:: void glm_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest) + + set each member of dest to greater of vector a and b + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest) + + set each member of dest to lesser of vector a and b + + Parameters: + | *[in]* **a** first vector + | *[in]* **b** second vector + | *[out]* **dest** destination + +.. c:function:: void glm_ivec4_clamp(ivec4 v, int minVal, int maxVal) + + clamp each member of [v] between minVal and maxVal (inclusive) + + Parameters: + | *[in, out]* **v** vector + | *[in]* **minVal** minimum value + | *[in]* **maxVal** maximum value diff --git a/libs/cglm/docs/source/mat2.rst b/libs/cglm/docs/source/mat2.rst new file mode 100644 index 0000000..6e55c83 --- /dev/null +++ b/libs/cglm/docs/source/mat2.rst @@ -0,0 +1,179 @@ +.. default-domain:: C + +mat2 +==== + +Header: cglm/mat2.h + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Macros: + +1. GLM_mat2_IDENTITY_INIT +#. GLM_mat2_ZERO_INIT +#. GLM_mat2_IDENTITY +#. GLM_mat2_ZERO + +Functions: + +1. :c:func:`glm_mat2_copy` +#. :c:func:`glm_mat2_identity` +#. :c:func:`glm_mat2_identity_array` +#. :c:func:`glm_mat2_zero` +#. :c:func:`glm_mat2_mul` +#. :c:func:`glm_mat2_transpose_to` +#. :c:func:`glm_mat2_transpose` +#. :c:func:`glm_mat2_mulv` +#. :c:func:`glm_mat2_scale` +#. :c:func:`glm_mat2_det` +#. :c:func:`glm_mat2_inv` +#. :c:func:`glm_mat2_trace` +#. :c:func:`glm_mat2_swap_col` +#. :c:func:`glm_mat2_swap_row` +#. :c:func:`glm_mat2_rmc` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_mat2_copy(mat2 mat, mat2 dest) + + copy mat2 to another one (dest). + + Parameters: + | *[in]* **mat** source + | *[out]* **dest** destination + +.. c:function:: void glm_mat2_identity(mat2 mat) + + copy identity mat2 to mat, or makes mat to identiy + + Parameters: + | *[out]* **mat** matrix + +.. c:function:: void glm_mat2_identity_array(mat2 * __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_mat2_zero(mat2 mat) + + make given matrix zero + + Parameters: + | *[in,out]* **mat** matrix to + +.. c:function:: void glm_mat2_mul(mat2 m1, mat2 m2, mat2 dest) + + multiply m1 and m2 to dest + m1, m2 and dest matrices can be same matrix, it is possible to write this: + + .. code-block:: c + + mat2 m = GLM_mat2_IDENTITY_INIT; + glm_mat2_mul(m, m, m); + + Parameters: + | *[in]* **m1** left matrix + | *[in]* **m2** right matrix + | *[out]* **dest** destination matrix + +.. c:function:: void glm_mat2_transpose_to(mat2 m, mat2 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_mat2_transpose(mat2 m) + + tranpose mat2 and store result in same matrix + + Parameters: + | *[in]* **mat** source + | *[out]* **dest** destination + +.. c:function:: void glm_mat2_mulv(mat2 m, vec2 v, vec2 dest) + + multiply mat4 with vec4 (column vector) and store in dest vector + + Parameters: + | *[in]* **mat** mat2 (left) + | *[in]* **v** vec2 (right, column vector) + | *[out]* **dest** destination (result, column vector) + +.. c:function:: void glm_mat2_scale(mat2 m, float s) + + multiply matrix with scalar + + Parameters: + | *[in, out]* **mat** matrix + | *[in]* **dest** scalar + +.. c:function:: float glm_mat2_det(mat2 mat) + + returns mat2 determinant + + Parameters: + | *[in]* **mat** matrix + + Returns: + mat2 determinant + +.. c:function:: void glm_mat2_inv(mat2 mat, mat2 dest) + + inverse mat2 and store in dest + + Parameters: + | *[in]* **mat** matrix + | *[out]* **dest** destination (inverse matrix) + +.. c:function:: void glm_mat2_trace(mat2 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_mat2_swap_col(mat2 mat, int col1, int col2) + + swap two matrix columns + + Parameters: + | *[in, out]* **mat** matrix + | *[in]* **col1** col1 + | *[in]* **col2** col2 + +.. c:function:: void glm_mat2_swap_row(mat2 mat, int row1, int row2) + + swap two matrix rows + + Parameters: + | *[in, out]* **mat** matrix + | *[in]* **row1** row1 + | *[in]* **row2** row2 + +.. c:function:: float glm_mat2_rmc(vec2 r, mat2 m, vec2 c) + + | **rmc** stands for **Row** * **Matrix** * **Column** + + | helper for R (row vector) * M (matrix) * C (column vector) + + | the result is scalar because R * M = Matrix1x2 (row vector), + | then Matrix1x2 * Vec2 (column vector) = Matrix1x1 (Scalar) + + Parameters: + | *[in]* **r** row vector or matrix1x2 + | *[in]* **m** matrix2x2 + | *[in]* **c** column vector or matrix2x1 + + Returns: + scalar value e.g. Matrix1x1 diff --git a/libs/cglm/docs/source/mat3.rst b/libs/cglm/docs/source/mat3.rst new file mode 100644 index 0000000..e577ce4 --- /dev/null +++ b/libs/cglm/docs/source/mat3.rst @@ -0,0 +1,189 @@ +.. default-domain:: C + +mat3 +==== + +Header: cglm/mat3.h + +Table of contents (click 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_identity_array` +#. :c:func:`glm_mat3_zero` +#. :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_quat` +#. :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` +#. :c:func:`glm_mat3_rmc` + +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_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_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 + 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_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 + + 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_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 + + 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 + +.. 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/libs/cglm/docs/source/mat4.rst b/libs/cglm/docs/source/mat4.rst new file mode 100644 index 0000000..33251b9 --- /dev/null +++ b/libs/cglm/docs/source/mat4.rst @@ -0,0 +1,304 @@ +.. 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 (click 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_identity_array` +#. :c:func:`glm_mat4_zero` +#. :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_mat3_trace` +#. :c:func:`glm_mat3_trace3` +#. :c:func:`glm_mat4_quat` +#. :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` +#. :c:func:`glm_mat4_rmc` + +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_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_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 + + 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:: 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...) + | 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) + | *[in]* **last** 4th item to make it vec4 + | *[out]* **dest** vec4 (result, column vector) + +.. c:function:: void glm_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest) + + | multiply **vec3** with **mat4** and get **vec3** as result + | + | actually the result is **vec4**, after multiplication, + the last component is trimmed, if you need the result's last component + then don't use this function and consider to use **glm_mat4_mulv()** + + Parameters: + | *[in]* **m** mat4(affine transform) + | *[in]* **v** vec3 + | *[in]* **last** 4th item to make it vec4 + | *[out]* **dest** result vector (vec3) + +.. 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 + + 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 + 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 + +.. 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 R * 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/libs/cglm/docs/source/opengl.rst b/libs/cglm/docs/source/opengl.rst new file mode 100644 index 0000000..2cebae0 --- /dev/null +++ b/libs/cglm/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 accepts 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/libs/cglm/docs/source/opt.rst b/libs/cglm/docs/source/opt.rst new file mode 100644 index 0000000..9b28054 --- /dev/null +++ b/libs/cglm/docs/source/opt.rst @@ -0,0 +1,124 @@ +.. default-domain:: C + +Options +=============================================================================== + +A few options are provided via macros. + +Alignment Option +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +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 versions 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 + +Clipspace Option[s] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +By starting **v0.8.3** cglm provides options to switch between clipspace configurations. + +Clipspace related files are located at `include/cglm/[struct]/clipspace.h` but +these are included in related files like `cam.h`. If you don't want to change your existing +clipspace configuration and want to use different clipspace function like `glm_lookat_zo` or `glm_lookat_lh_zo`... +then you can include individual headers or just define `CGLM_CLIPSPACE_INCLUDE_ALL` which will iclude all headers for you. + +1. **CGLM_CLIPSPACE_INCLUDE_ALL** +2. **CGLM_FORCE_DEPTH_ZERO_TO_ONE** +3. **CGLM_FORCE_LEFT_HANDED** + + +1. **CGLM_CLIPSPACE_INCLUDE_ALL**: + +By defining this macro, **cglm** will include all clipspace functions for you by just using +`#include cglm/cglm.h` or `#include cglm/struct.h` or `#include cglm/call.h` + +Otherwise you need to include header you want manually e.g. `#include cglm/clipspace/view_rh_zo.h` + +2. **CGLM_FORCE_DEPTH_ZERO_TO_ONE** + +This is similar to **GLM**'s **GLM_FORCE_DEPTH_ZERO_TO_ONE** option. +This will set clip space between 0 to 1 which makes **cglm** Vulkan, Metal friendly. + +You can use functions like `glm_lookat_lh_zo()` individually. By setting **CGLM_FORCE_DEPTH_ZERO_TO_ONE** +functions in cam.h for instance will use `_zo` versions. + +3. **CGLM_FORCE_LEFT_HANDED** + +Force **cglm** to use the left handed coordinate system by default, currently **cglm** uses right handed coordinate system as default, +you can change this behavior with this option. + +**VERY VERY IMPORTANT:** + +Be careful if you include **cglm** in multiple projects. + +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. + +Print Options +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +1. **CGLM_DEFINE_PRINTS** +2. **CGLM_NO_PRINTS_NOOP** (use CGLM_DEFINE_PRINTS) + +Inline prints are only enabled in **DEBUG** mode or if **CGLM_DEFINE_PRINTS** is defined. +**glmc_** versions will always print too. + +Because **cglm** tried to enable print functions in debug mode and disable them in +release/production mode to eliminate printing costs when we do not need them. + +**cglm** checks **DEBUG** or **_DEBUG** macros to test debug mode, if these are not working for you then you can use +**CGLM_DEFINE_PRINTS** to force enable, or create a PR to introduce new macro to test against debugging mode. + +If DEBUG mode is not enabled then print functions will be emptied to eliminate print function calls. +You can disable this feature too by defining **CGLM_DEFINE_PRINTS** macro top of cglm header +or in project/build settings... + +3. **CGLM_PRINT_PRECISION** 5 + +precision. + +4. **CGLM_PRINT_MAX_TO_SHORT** 1e5 + +if a number is greater than this value then %g will be used, since this is shorten print you won't be able to see high precision. + +5. **CGLM_PRINT_COLOR** "\033[36m" +6. **CGLM_PRINT_COLOR_RESET** "\033[0m" + +You can disable colorful print output by defining **CGLM_PRINT_COLOR** and **CGLM_PRINT_COLOR_RESET** as empty macro. +Because some terminals may not support colors. diff --git a/libs/cglm/docs/source/plane.rst b/libs/cglm/docs/source/plane.rst new file mode 100644 index 0000000..b9afbed --- /dev/null +++ b/libs/cglm/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/libs/cglm/docs/source/project.rst b/libs/cglm/docs/source/project.rst new file mode 100644 index 0000000..b31a86a --- /dev/null +++ b/libs/cglm/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/libs/cglm/docs/source/quat.rst b/libs/cglm/docs/source/quat.rst new file mode 100644 index 0000000..a44c918 --- /dev/null +++ b/libs/cglm/docs/source/quat.rst @@ -0,0 +1,422 @@ +.. default-domain:: C + +quaternions +=========== + +Header: cglm/quat.h + + **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. + +What you can do with quaternions with existing functions is (Some of them): + +- 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): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Macros: + +1. GLM_QUAT_IDENTITY_INIT +#. GLM_QUAT_IDENTITY + +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` +#. :c:func:`glm_quat_copy` +#. :c:func:`glm_quat_from_vecs` +#. :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_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_nlerp` +#. :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` +#. :c:func:`glm_quat_rotate` +#. :c:func:`glm_quat_rotate_at` +#. :c:func:`glm_quat_rotate_atm` + +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_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 + + 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) + | *[in]* **x** axis.x + | *[in]* **y** axis.y + | *[in]* **z** axis.z + +.. 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]* **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:: void glm_quat_from_vecs(vec3 a, vec3 b, versor dest) + + | compute unit quaternion needed to rotate a into b + + References: + * `Finding quaternion representing the rotation from one vector to another `_ + * `Quaternion from two vectors `_ + * `Angle between vectors `_ + + Parameters: + | *[in]* **a** unit vector + | *[in]* **b** unit vector + | *[in]* **dest** unit quaternion + +.. 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_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 + + Parameters: + | *[in, out]* **q** quaternion + +.. c:function:: float glm_quat_dot(versor p, versor q) + + dot product of two quaternion + + Parameters: + | *[in]* **p** quaternion 1 + | *[in]* **q** quaternion 2 + + Returns: + dot product + +.. 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]* **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) + + | convert quaternion to mat4 + + Parameters: + | *[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_nlerp(versor q, versor r, float t, versor dest) + + | interpolates between two quaternions + | taking the shortest rotation path using + | normalized linear interpolation (NLERP) + + | This is a cheaper alternative to slerp; most games use nlerp + | for animations as it visually makes little difference. + + References: + * `Understanding Slerp, Then Not Using it `_ + * `Lerp, Slerp and Nlerp `_ + + 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]* **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 up, versor dest) + + | creates look rotation quaternion + + Parameters: + | *[in]* **dir** direction to look + | *[in]* **up** up vector + | *[out]* **dest** result matrix + +.. c:function:: void glm_quat_forp(vec3 from, vec3 to, 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]* **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 + +.. 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_atm(mat4 m, versor q, vec3 pivot) + + | 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/libs/cglm/docs/source/ray.rst b/libs/cglm/docs/source/ray.rst new file mode 100644 index 0000000..c5faf33 --- /dev/null +++ b/libs/cglm/docs/source/ray.rst @@ -0,0 +1,31 @@ +.. default-domain:: C + +ray +==== + +Header: cglm/ray.h + +This is for collision-checks used by ray-tracers and the like. + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_ray_triangle` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: bool glm_ray_triangle(vec3 origin, vec3 direction, vec3 v0, vec3 v1, vec3 v2, float *d) + + Möller–Trumbore ray-triangle intersection algorithm + + Parameters: + | *[in]* **origin** origin of ray + | *[in]* **direction** direction of ray + | *[in]* **v0** first vertex of triangle + | *[in]* **v1** second vertex of triangle + | *[in]* **v2** third vertex of triangle + | *[in, out]* **d** float pointer to save distance to intersection + | *[out]* **intersection** whether there is intersection diff --git a/libs/cglm/docs/source/sphere.rst b/libs/cglm/docs/source/sphere.rst new file mode 100644 index 0000000..db238f4 --- /dev/null +++ b/libs/cglm/docs/source/sphere.rst @@ -0,0 +1,74 @@ +.. 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` +#. :c:func:`glm_sphere_point` + +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 + +.. 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/libs/cglm/docs/source/troubleshooting.rst b/libs/cglm/docs/source/troubleshooting.rst new file mode 100644 index 0000000..fb1433f --- /dev/null +++ b/libs/cglm/docs/source/troubleshooting.rst @@ -0,0 +1,99 @@ +.. 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. + +Alignment: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**vec4** and **mat4** types requires 16 byte alignment. +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 alignment 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 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. + +**This MSVC issue is still in TODOs.** + +**UPDATE:** By starting v0.4.5 cglm provides an option to disable alignment requirement. +Also alignment is disabled for older msvc verisons as default. Now alignment is only required in Visual Studio 2017 version 15.6+ if CGLM_ALL_UNALIGNED macro is not defined. + +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. + +**UPDATE - IMPORTANT:** + + | On MSVC or some other compilers, if alignment is enabled (default) then double check alignment requirements if you got a crash. + + | If you send GLM_VEC4_ONE or similar macros directly to a function, it may be crashed. + | Because compiler may not apply alignment as defined on **typedef** to that macro while passing it (on stack) to a function. + +Wrong Results: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Again, you may used wrong function. + +For instance if you use **glm_normalize()** or **glm_vec3_normalize()** for **vec4**, +it will assume that passed param is **vec3** and will normalize it for **vec3**. +Since you need to **vec4** to be normalized in your case, you will get wrong results. + +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.** + +BAD_ACCESS : Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT) or Similar Errors/Crashes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This is similar issue with alignment. For instance if you compiled **cglm** with +AVX (**-mavx**, intentionally or not) and if you use **cglm** in an environment that doesn't +support AVX (or if AVX is disabled intentionally) e.g. environment that max support SSE2/3/4, +then you probably get **BAD ACCESS** or similar... + +Because if you compile **cglm** with AVX it aligns **mat4** with 32 byte boundary, +and your project aligns that as 16 byte boundary... + +Check alignment, supported vector extension or simd in **cglm** and linked projects... + +Other Issues? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +**Please let us know by creating an issue on Github.** diff --git a/libs/cglm/docs/source/util.rst b/libs/cglm/docs/source/util.rst new file mode 100644 index 0000000..02495f4 --- /dev/null +++ b/libs/cglm/docs/source/util.rst @@ -0,0 +1,182 @@ +.. default-domain:: C + +utils / helpers +================================================================================ + +Header: cglm/util.h + + + +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` +#. :c:func:`glm_make_deg` +#. :c:func:`glm_pow2` +#. :c:func:`glm_min` +#. :c:func:`glm_max` +#. :c:func:`glm_clamp` +#. :c:func:`glm_lerp` +#. :c:func:`glm_swapf` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: int glm_sign(int val) + + | returns sign of 32 bit integer as +1, -1, 0 + + | **Important**: It returns 0 for zero input + + Parameters: + | *[in]* **val** an integer + + 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 + + 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 + +.. 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 + +.. 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 + +.. 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 are equal + +.. 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: + percentage of current value + +.. 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) + +.. c:function:: void glm_swapf(float *a, float *b) + + swap two float values + + Parameters: + | *[in]* **a** float 1 + | *[in]* **b** float 2 diff --git a/libs/cglm/docs/source/vec2-ext.rst b/libs/cglm/docs/source/vec2-ext.rst new file mode 100644 index 0000000..619d48f --- /dev/null +++ b/libs/cglm/docs/source/vec2-ext.rst @@ -0,0 +1,134 @@ +.. default-domain:: C + +vec2 extra +========== + +Header: cglm/vec2-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 vec2.h in the future some of +these functions ma be moved to vec2 header. + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_vec2_fill` +#. :c:func:`glm_vec2_eq` +#. :c:func:`glm_vec2_eq_eps` +#. :c:func:`glm_vec2_eq_all` +#. :c:func:`glm_vec2_eqv` +#. :c:func:`glm_vec2_eqv_eps` +#. :c:func:`glm_vec2_max` +#. :c:func:`glm_vec2_min` +#. :c:func:`glm_vec2_isnan` +#. :c:func:`glm_vec2_isinf` +#. :c:func:`glm_vec2_isvalid` +#. :c:func:`glm_vec2_sign` +#. :c:func:`glm_vec2_sqrt` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_vec2_fill(vec2 v, float val) + + fill a vector with specified value + + Parameters: + | *[in,out]* **dest** destination + | *[in]* **val** value + + +.. c:function:: bool glm_vec2_eq(vec2 v, float val) + + check if vector is equal to value (without epsilon) + + Parameters: + | *[in]* **v** vector + | *[in]* **val** value + +.. c:function:: bool glm_vec2_eq_eps(vec2 v, float val) + + check if vector is equal to value (with epsilon) + + Parameters: + | *[in]* **v** vector + | *[in]* **val** value + +.. c:function:: bool glm_vec2_eq_all(vec2 v) + + check if vectors members are equal (without epsilon) + + Parameters: + | *[in]* **v** vector + +.. c:function:: bool glm_vec2_eqv(vec2 v1, vec2 v2) + + check if vector is equal to another (without epsilon) vector + + Parameters: + | *[in]* **vec** vector 1 + | *[in]* **vec** vector 2 + +.. c:function:: bool glm_vec2_eqv_eps(vec2 v1, vec2 v2) + + check if vector is equal to another (with epsilon) + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + +.. c:function:: float glm_vec2_max(vec2 v) + + max value of vector + + Parameters: + | *[in]* **v** vector + +.. c:function:: float glm_vec2_min(vec2 v) + + min value of vector + + Parameters: + | *[in]* **v** vector + +.. c:function:: bool glm_vec2_isnan(vec2 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_vec2_isinf(vec2 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_vec2_isvalid(vec2 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_vec2_sign(vec2 v, vec2 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_vec2_sqrt(vec2 v, vec2 dest) + + square root of each vector item + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** destination vector (sqrt(v)) diff --git a/libs/cglm/docs/source/vec2.rst b/libs/cglm/docs/source/vec2.rst new file mode 100644 index 0000000..93d8663 --- /dev/null +++ b/libs/cglm/docs/source/vec2.rst @@ -0,0 +1,375 @@ +.. default-domain:: C + +vec2 +==== + +Header: cglm/vec2.h + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Macros: + +1. GLM_vec2_ONE_INIT +#. GLM_vec2_ZERO_INIT +#. GLM_vec2_ONE +#. GLM_vec2_ZERO + +Functions: + +1. :c:func:`glm_vec2` +#. :c:func:`glm_vec2_copy` +#. :c:func:`glm_vec2_zero` +#. :c:func:`glm_vec2_one` +#. :c:func:`glm_vec2_dot` +#. :c:func:`glm_vec2_cross` +#. :c:func:`glm_vec2_norm2` +#. :c:func:`glm_vec2_norm` +#. :c:func:`glm_vec2_add` +#. :c:func:`glm_vec2_adds` +#. :c:func:`glm_vec2_sub` +#. :c:func:`glm_vec2_subs` +#. :c:func:`glm_vec2_mul` +#. :c:func:`glm_vec2_scale` +#. :c:func:`glm_vec2_scale_as` +#. :c:func:`glm_vec2_div` +#. :c:func:`glm_vec2_divs` +#. :c:func:`glm_vec2_addadd` +#. :c:func:`glm_vec2_subadd` +#. :c:func:`glm_vec2_muladd` +#. :c:func:`glm_vec2_muladds` +#. :c:func:`glm_vec2_maxadd` +#. :c:func:`glm_vec2_minadd` +#. :c:func:`glm_vec2_negate` +#. :c:func:`glm_vec2_negate_to` +#. :c:func:`glm_vec2_normalize` +#. :c:func:`glm_vec2_normalize_to` +#. :c:func:`glm_vec2_rotate` +#. :c:func:`glm_vec2_distance2` +#. :c:func:`glm_vec2_distance` +#. :c:func:`glm_vec2_maxv` +#. :c:func:`glm_vec2_minv` +#. :c:func:`glm_vec2_clamp` +#. :c:func:`glm_vec2_lerp` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_vec2(float * v, vec2 dest) + + init vec2 using vec3 or vec4 + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** destination + +.. c:function:: void glm_vec2_copy(vec2 a, vec2 dest) + + copy all members of [a] to [dest] + + Parameters: + | *[in]* **a** source + | *[out]* **dest** destination + +.. c:function:: void glm_vec2_zero(vec2 v) + + makes all members 0.0f (zero) + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec2_one(vec2 v) + + makes all members 1.0f (one) + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: float glm_vec2_dot(vec2 a, vec2 b) + + dot product of vec2 + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + + Returns: + dot product + +.. c:function:: void glm_vec2_cross(vec2 a, vec2 b, vec2 d) + + cross product of two vector (RH) + + | ref: http://allenchou.net/2013/07/cross-product-of-2d-vectors/ + + Parameters: + | *[in]* **a** vector 1 + | *[in]* **b** vector 2 + | *[out]* **dest** destination + + Returns: + Z component of cross product + +.. c:function:: float glm_vec2_norm2(vec2 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_vec2_norm(vec2 vec) + + | euclidean norm (magnitude), also called L2 norm + | this will give magnitude of vector in euclidean space + + Parameters: + | *[in]* **vec** vector + +.. c:function:: void glm_vec2_add(vec2 a, vec2 b, vec2 dest) + + add a vector to b vector store result in dest + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec2_adds(vec2 a, float s, vec2 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_vec2_sub(vec2 v1, vec2 v2, vec2 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_vec2_subs(vec2 v, float s, vec2 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_vec2_mul(vec2 a, vec2 b, vec2 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_vec2_scale(vec2 v, float s, vec2 dest) + + multiply/scale vec2 vector with scalar: result = v * s + + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec2_scale_as(vec2 v, float s, vec2 dest) + + make vec2 vector scale as specified: result = unit(v) * s + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec2_div(vec2 a, vec2 b, vec2 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_vec2_divs(vec2 v, float s, vec2 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_vec2_addadd(vec2 a, vec2 b, vec2 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_vec2_subadd(vec2 a, vec2 b, vec2 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_vec2_muladd(vec2 a, vec2 b, vec2 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_vec2_muladds(vec2 a, float s, vec2 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_vec2_maxadd(vec2 a, vec2 b, vec2 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_vec2_minadd(vec2 a, vec2 b, vec2 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_vec2_negate(vec2 v) + + negate vector components + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec2_negate_to(vec2 v, vec2 dest) + + negate vector components and store result in dest + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** negated vector + +.. c:function:: void glm_vec2_normalize(vec2 v) + + normalize vec2 and store result in same vec + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec2_normalize_to(vec2 vec, vec2 dest) + + normalize vec2 to dest + + Parameters: + | *[in]* **vec** source + | *[out]* **dest** destination + +.. c:function:: void glm_vec2_rotate(vec2 v, float angle, vec2 dest) + + rotate vec2 around axis by angle using Rodrigues' rotation formula + + Parameters: + | *[in]* **v** vector + | *[in]* **axis** axis vector + | *[out]* **dest** destination + +.. c:function:: float glm_vec2_distance2(vec2 v1, vec2 v2) + + squared distance between two vectors + + Parameters: + | *[in]* **mat** vector1 + | *[in]* **row1** vector2 + + Returns: + | squared distance (distance * distance) + +.. c:function:: float glm_vec2_distance(vec2 v1, vec2 v2) + + distance between two vectors + + Parameters: + | *[in]* **mat** vector1 + | *[in]* **row1** vector2 + + Returns: + | distance + +.. c:function:: void glm_vec2_maxv(vec2 v1, vec2 v2, vec2 dest) + + max values of vectors + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + | *[out]* **dest** destination + +.. c:function:: void glm_vec2_minv(vec2 v1, vec2 v2, vec2 dest) + + min values of vectors + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + | *[out]* **dest** destination + +.. c:function:: void glm_vec2_clamp(vec2 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 + +.. c:function:: void glm_vec2_lerp(vec2 from, vec2 to, float t, vec2 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/libs/cglm/docs/source/vec3-ext.rst b/libs/cglm/docs/source/vec3-ext.rst new file mode 100644 index 0000000..88f3699 --- /dev/null +++ b/libs/cglm/docs/source/vec3-ext.rst @@ -0,0 +1,143 @@ +.. 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 (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +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_vec3_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_vec3_broadcast(float val, vec3 d) + + fill a vector with specified value + + Parameters: + | *[in]* **val** value + | *[out]* **dest** destination + +.. c:function:: bool glm_vec3_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_vec3_eq_eps(vec3 v, float val) + + check if vector is equal to value (with epsilon) + + Parameters: + | *[in]* **v** vector + | *[in]* **val** value + +.. 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_vec3_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_vec3_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_vec3_max(vec3 v) + + max value of vector + + Parameters: + | *[in]* **v** vector + +.. c:function:: float glm_vec3_min(vec3 v) + + min value of vector + + Parameters: + | *[in]* **v** vector + +.. 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 + + Parameters: + | *[in]* **v** vector + +.. 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 + + Parameters: + | *[in]* **v** vector + +.. 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 + + Parameters: + | *[in]* **v** vector + +.. c:function:: void glm_vec3_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_vec3_sqrt(vec3 v, vec3 dest) + + square root of each vector item + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** destination vector (sqrt(v)) diff --git a/libs/cglm/docs/source/vec3.rst b/libs/cglm/docs/source/vec3.rst new file mode 100644 index 0000000..17e4824 --- /dev/null +++ b/libs/cglm/docs/source/vec3.rst @@ -0,0 +1,503 @@ +.. default-domain:: C + +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_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 +rotate *vec3* with matrix. + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Macros: + +1. glm_vec3_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_vec3_copy` +#. :c:func:`glm_vec3_zero` +#. :c:func:`glm_vec3_one` +#. :c:func:`glm_vec3_dot` +#. :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_maxadd` +#. :c:func:`glm_vec3_minadd` +#. :c:func:`glm_vec3_flipsign` +#. :c:func:`glm_vec3_flipsign_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_cross` +#. :c:func:`glm_vec3_crossn` +#. :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 +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: void glm_vec3(vec4 v4, vec3 dest) + + init vec3 using vec4 + + Parameters: + | *[in]* **v4** vector4 + | *[out]* **dest** destination + +.. c:function:: void glm_vec3_copy(vec3 a, vec3 dest) + + copy all members of [a] to [dest] + + Parameters: + | *[in]* **a** source + | *[out]* **dest** destination + +.. c:function:: void glm_vec3_zero(vec3 v) + + makes all members 0.0f (zero) + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec3_one(vec3 v) + + makes all members 1.0f (one) + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: float glm_vec3_dot(vec3 a, vec3 b) + + dot product of vec3 + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + + Returns: + dot product + +.. c:function:: void glm_vec3_cross(vec3 a, vec3 b, vec3 d) + + cross product of two vector (RH) + + Parameters: + | *[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) + + 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_vec3_norm(vec3 vec) + + | euclidean norm (magnitude), also called L2 norm + | this will give magnitude of vector in euclidean space + + Parameters: + | *[in]* **vec** vector + +.. c:function:: void glm_vec3_add(vec3 a, vec3 b, vec3 dest) + + add a vector to b vector store result in dest + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + | *[out]* **dest** destination vector + +.. 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)) + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination vector + +.. 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) + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + | *[out]* **dest** destination vector + +.. 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)) + + Parameters: + | *[in]* **v** vector + | *[in]* **s** scalar + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec3_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_vec3_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_vec3_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_vec3_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_vec3_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_vec3_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_vec3_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_vec3_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_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 + + Parameters: + | *[in]* **a** vector + | *[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!** + + use :c:func:`glm_vec3_negate` + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec3_flipsign_to(vec3 v, vec3 dest) + + **DEPRACATED!** + + use :c:func:`glm_vec3_negate_to` + + Parameters: + | *[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 + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec3_negate_to(vec3 v, vec3 dest) + + negate vector components and store result in dest + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** negated vector + +.. c:function:: void glm_vec3_normalize(vec3 v) + + normalize vec3 and store result in same vec + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec3_normalize_to(vec3 vec, vec3 dest) + + normalize vec3 to dest + + Parameters: + | *[in]* **vec** source + | *[out]* **dest** destination + +.. c:function:: float glm_vec3_angle(vec3 v1, vec3 v2) + + angle betwen two vector + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + + Return: + | angle as radians + +.. c:function:: void glm_vec3_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 (will be normalized) + | *[in]* **angle** angle (radians) + +.. c:function:: void glm_vec3_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_vec3_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_vec3_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_vec3_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_vec3_distance2(vec3 v1, vec3 v2) + + squared distance between two vectors + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + + Returns: + | squared distance (distance * distance) + +.. c:function:: float glm_vec3_distance(vec3 v1, vec3 v2) + + distance between two vectors + + Parameters: + | *[in]* **v1** vector1 + | *[in]* **v2** vector2 + + Returns: + | distance + +.. c:function:: void glm_vec3_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_vec3_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_vec3_ortho(vec3 v, vec3 dest) + + possible orthogonal/perpendicular vector + + References: + * `On picking an orthogonal vector (and combing coconuts) `_ + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** orthogonal/perpendicular vector + +.. c:function:: void glm_vec3_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 + +.. c:function:: void glm_vec3_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/libs/cglm/docs/source/vec4-ext.rst b/libs/cglm/docs/source/vec4-ext.rst new file mode 100644 index 0000000..722424e --- /dev/null +++ b/libs/cglm/docs/source/vec4-ext.rst @@ -0,0 +1,138 @@ +.. 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 (click 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 + +.. 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/libs/cglm/docs/source/vec4.rst b/libs/cglm/docs/source/vec4.rst new file mode 100644 index 0000000..58c861e --- /dev/null +++ b/libs/cglm/docs/source/vec4.rst @@ -0,0 +1,408 @@ +.. default-domain:: C + +vec4 +==== + +Header: cglm/vec4.h + +Table of contents (click 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_ucopy` +#. :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` +#. :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_addadd` +#. :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` +#. :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` +#. :c:func:`glm_vec4_maxv` +#. :c:func:`glm_vec4_minv` +#. :c:func:`glm_vec4_clamp` +#. :c:func:`glm_vec4_lerp` +#. :c:func:`glm_vec4_cubic` + +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:: 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 + + Parameters: + | *[in, out]* **v** vector + +.. 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) + + | euclidean norm (magnitude), also called L2 norm + | this will give magnitude of vector in euclidean space + + Parameters: + | *[in]* **vec** vector + +.. c:function:: void glm_vec4_add(vec4 a, vec4 b, vec4 dest) + + add a vector to b vector store result in dest + + Parameters: + | *[in]* **a** vector1 + | *[in]* **b** vector2 + | *[out]* **dest** destination vector + +.. c:function:: void glm_vec4_adds(vec4 v, float s, vec4 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_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 + + 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_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_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_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_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!** + + use :c:func:`glm_vec4_negate` + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec4_flipsign_to(vec4 v, vec4 dest) + + **DEPRACATED!** + + 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 + + Parameters: + | *[in, out]* **v** vector + +.. c:function:: void glm_vec4_negate_to(vec4 v, vec4 dest) + + negate vector components and store result in dest + + Parameters: + | *[in]* **v** vector + | *[out]* **dest** negated vector + +.. c:function:: void glm_vec4_normalize(vec4 v) + + 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 + +.. 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 + +.. 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 + +.. 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/libs/cglm/docs/source/version.rst b/libs/cglm/docs/source/version.rst new file mode 100644 index 0000000..7e662f9 --- /dev/null +++ b/libs/cglm/docs/source/version.rst @@ -0,0 +1,15 @@ +.. default-domain:: C + +version +================================================================================ + +Header: cglm/version.h + +**cglm** uses semantic versioning (http://semver.org) which is MAJOR.MINOR.PATCH + +| **CGLM_VERSION_MAJOR** is major number of the version. +| **CGLM_VERSION_MINOR** is minor number of the version. +| **CGLM_VERSION_PATCH** is patch number of the version. + +every release increases these numbers. You can check existing version by +including `cglm/version.h` diff --git a/libs/cglm/include/cglm/affine-mat.h b/libs/cglm/include/cglm/affine-mat.h new file mode 100644 index 0000000..75607e7 --- /dev/null +++ b/libs/cglm/include/cglm/affine-mat.h @@ -0,0 +1,178 @@ +/* + * 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_mul(mat4 m1, mat4 m2, mat4 dest); + CGLM_INLINE void glm_inv_tr(mat4 mat); + */ + +#ifndef cglm_affine_mat_h +#define cglm_affine_mat_h + +#include "common.h" +#include "mat4.h" +#include "mat3.h" + +#ifdef CGLM_SSE_FP +# include "simd/sse2/affine.h" +#endif + +#ifdef CGLM_AVX_FP +# include "simd/avx/affine.h" +#endif + +#ifdef CGLM_NEON_FP +# include "simd/neon/affine.h" +#endif + +/*! + * @brief this is similar to glm_mat4_mul but specialized to affine transform + * + * Matrix format should be: + * 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 + * + * @param[in] m1 affine matrix 1 + * @param[in] m2 affine matrix 2 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_mul(mat4 m1, mat4 m2, mat4 dest) { +#ifdef __AVX__ + glm_mul_avx(m1, m2, dest); +#elif defined( __SSE__ ) || defined( __SSE2__ ) + glm_mul_sse2(m1, m2, dest); +#elif defined(CGLM_NEON_FP) + glm_mul_neon(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], + b30 = m2[3][0], b31 = m2[3][1], b32 = m2[3][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] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33; + dest[3][1] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33; + dest[3][2] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33; + dest[3][3] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33; +#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); +#elif defined(CGLM_NEON_FP) + glm_mul_rot_neon(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]; + + 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) + * + * @code + * X = | R T | X' = | R' -R'T | + * | 0 1 | | 0 1 | + * @endcode + * + * @param[in,out] mat matrix + */ +CGLM_INLINE +void +glm_inv_tr(mat4 mat) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_inv_tr_sse2(mat); +#elif defined(CGLM_NEON_FP) + glm_inv_tr_neon(mat); +#else + CGLM_ALIGN_MAT mat3 r; + CGLM_ALIGN(8) vec3 t; + + /* rotate */ + glm_mat4_pick3t(mat, r); + glm_mat4_ins3(r, mat); + + /* translate */ + glm_mat3_mulv(r, mat[3], t); + glm_vec3_negate(t); + glm_vec3_copy(t, mat[3]); +#endif +} + +#endif /* cglm_affine_mat_h */ diff --git a/libs/cglm/include/cglm/affine.h b/libs/cglm/include/cglm/affine.h new file mode 100644 index 0000000..d0e5bc9 --- /dev/null +++ b/libs/cglm/include/cglm/affine.h @@ -0,0 +1,470 @@ +/* + * 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_translate_to(mat4 m, vec3 v, mat4 dest); + CGLM_INLINE void glm_translate(mat4 m, vec3 v); + CGLM_INLINE void glm_translate_x(mat4 m, float to); + CGLM_INLINE void glm_translate_y(mat4 m, float to); + CGLM_INLINE void glm_translate_z(mat4 m, float to); + CGLM_INLINE void glm_translate_make(mat4 m, vec3 v); + 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_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); + CGLM_INLINE void glm_rotate_z(mat4 m, float angle, mat4 dest); + CGLM_INLINE void glm_rotate_make(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); + CGLM_INLINE void glm_decompose(mat4 m, vec4 t, mat4 r, vec3 s); + */ + +#ifndef cglm_affine_h +#define cglm_affine_h + +#include "common.h" +#include "util.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" +#include "affine-mat.h" + +/*! + * @brief translate existing transform matrix by v vector + * and stores result in same matrix + * + * @param[in, out] m affine transfrom + * @param[in] v translate vector [x, y, z] + */ +CGLM_INLINE +void +glm_translate(mat4 m, vec3 v) { +#if defined(CGLM_SIMD) + glmm_128 m0, m1, m2, m3; + + m0 = glmm_load(m[0]); + m1 = glmm_load(m[1]); + m2 = glmm_load(m[2]); + m3 = glmm_load(m[3]); + + glmm_store(m[3], + glmm_fmadd(m0, glmm_set1(v[0]), + glmm_fmadd(m1, glmm_set1(v[1]), + glmm_fmadd(m2, glmm_set1(v[2]), m3)))); +#else + glm_vec4_muladds(m[0], v[0], m[3]); + glm_vec4_muladds(m[1], v[1], m[3]); + glm_vec4_muladds(m[2], v[2], m[3]); +#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 + * + * @param[in, out] m affine transfrom + * @param[in] x x factor + */ +CGLM_INLINE +void +glm_translate_x(mat4 m, float x) { +#if defined(CGLM_SIMD) + glmm_store(m[3], glmm_fmadd(glmm_load(m[0]), glmm_set1(x), glmm_load(m[3]))); +#else + vec4 v1; + glm_vec4_scale(m[0], x, v1); + glm_vec4_add(v1, m[3], m[3]); +#endif +} + +/*! + * @brief translate existing transform matrix by y factor + * + * @param[in, out] m affine transfrom + * @param[in] y y factor + */ +CGLM_INLINE +void +glm_translate_y(mat4 m, float y) { +#if defined(CGLM_SIMD) + glmm_store(m[3], glmm_fmadd(glmm_load(m[1]), glmm_set1(y), glmm_load(m[3]))); +#else + vec4 v1; + glm_vec4_scale(m[1], y, v1); + glm_vec4_add(v1, m[3], m[3]); +#endif +} + +/*! + * @brief translate existing transform matrix by z factor + * + * @param[in, out] m affine transfrom + * @param[in] z z factor + */ +CGLM_INLINE +void +glm_translate_z(mat4 m, float z) { +#if defined(CGLM_SIMD) + glmm_store(m[3], glmm_fmadd(glmm_load(m[2]), glmm_set1(z), glmm_load(m[3]))); +#else + vec4 v1; + glm_vec4_scale(m[2], z, v1); + glm_vec4_add(v1, m[3], m[3]); +#endif +} + +/*! + * @brief creates NEW translate transform matrix by v vector + * + * @param[out] m affine transfrom + * @param[in] v translate vector [x, y, z] + */ +CGLM_INLINE +void +glm_translate_make(mat4 m, vec3 v) { + glm_mat4_identity(m); + glm_vec3_copy(v, m[3]); +} + +/*! + * @brief scale existing transform matrix by v vector + * and store result in dest + * + * @param[in] m affine transfrom + * @param[in] v scale vector [x, y, z] + * @param[out] dest scaled matrix + */ +CGLM_INLINE +void +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]); + + glm_vec4_copy(m[3], dest[3]); +} + +/*! + * @brief creates NEW scale matrix by v vector + * + * @param[out] m affine transfrom + * @param[in] v scale vector [x, y, z] + */ +CGLM_INLINE +void +glm_scale_make(mat4 m, vec3 v) { + glm_mat4_identity(m); + m[0][0] = v[0]; + m[1][1] = v[1]; + m[2][2] = v[2]; +} + +/*! + * @brief scales existing transform matrix by v vector + * and stores result in same matrix + * + * @param[in, out] m affine transfrom + * @param[in] v scale vector [x, y, z] + */ +CGLM_INLINE +void +glm_scale(mat4 m, vec3 v) { + glm_scale_to(m, v, m); +} + +/*! + * @brief applies uniform scale to existing transform matrix v = [s, s, s] + * and stores result in same matrix + * + * @param[in, out] m affine transfrom + * @param[in] s scale factor + */ +CGLM_INLINE +void +glm_scale_uni(mat4 m, float s) { + CGLM_ALIGN(8) vec3 v = { s, s, s }; + glm_scale_to(m, v, 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) + * @param[out] dest rotated matrix + */ +CGLM_INLINE +void +glm_rotate_x(mat4 m, float angle, mat4 dest) { + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; + float c, s; + + c = cosf(angle); + s = sinf(angle); + + t[1][1] = c; + t[1][2] = s; + t[2][1] = -s; + t[2][2] = c; + + glm_mul_rot(m, t, dest); +} + +/*! + * @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) + * @param[out] dest rotated matrix + */ +CGLM_INLINE +void +glm_rotate_y(mat4 m, float angle, mat4 dest) { + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; + float c, s; + + c = cosf(angle); + s = sinf(angle); + + t[0][0] = c; + t[0][2] = -s; + t[2][0] = s; + t[2][2] = c; + + glm_mul_rot(m, t, dest); +} + +/*! + * @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) + * @param[out] dest rotated matrix + */ +CGLM_INLINE +void +glm_rotate_z(mat4 m, float angle, mat4 dest) { + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; + float c, s; + + c = cosf(angle); + s = sinf(angle); + + t[0][0] = c; + t[0][1] = s; + t[1][0] = -s; + t[1][1] = c; + + glm_mul_rot(m, t, dest); +} + +/*! + * @brief creates NEW rotation matrix by angle and axis + * + * axis will be normalized so you don't need to normalize it + * + * @param[out] m affine transfrom + * @param[in] angle angle (radians) + * @param[in] axis axis + */ +CGLM_INLINE +void +glm_rotate_make(mat4 m, float angle, vec3 axis) { + CGLM_ALIGN(8) vec3 axisn, v, vs; + float c; + + c = cosf(angle); + + glm_vec3_normalize_to(axis, axisn); + glm_vec3_scale(axisn, 1.0f - c, v); + glm_vec3_scale(axisn, sinf(angle), vs); + + 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]; + 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 + * + * @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) { + CGLM_ALIGN_MAT mat4 rot; + glm_rotate_make(rot, angle, axis); + glm_mul_rot(m, rot, m); +} + +/*! + * @brief rotate existing transform + * 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 m, vec3 pivot, float angle, vec3 axis) { + CGLM_ALIGN(8) vec3 pivotInv; + + glm_vec3_negate_to(pivot, 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) { + CGLM_ALIGN(8) vec3 pivotInv; + + glm_vec3_negate_to(pivot, pivotInv); + + glm_translate_make(m, pivot); + glm_rotate(m, angle, axis); + glm_translate(m, pivotInv); +} + +/*! + * @brief decompose scale vector + * + * @param[in] m affine transform + * @param[out] s scale vector (Sx, Sy, Sz) + */ +CGLM_INLINE +void +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]); +} + +/*! + * @brief returns true if matrix is uniform scaled. This is helpful for + * creating normal matrix. + * + * @param[in] m m + * + * @return boolean + */ +CGLM_INLINE +bool +glm_uniscaled(mat4 m) { + CGLM_ALIGN(8) vec3 s; + glm_decompose_scalev(m, s); + return glm_vec3_eq_all(s); +} + +/*! + * @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 +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; + + glm_vec4_copy(m[0], r[0]); + glm_vec4_copy(m[1], r[1]); + glm_vec4_copy(m[2], r[2]); + glm_vec4_copy(t, r[3]); + + 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]); + glm_vec4_scale(r[2], 1.0f/s[2], r[2]); + + /* Note from Apple Open Source (assume 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_vec3_cross(m[0], m[1], v); + if (glm_vec3_dot(v, m[2]) < 0.0f) { + glm_vec4_negate(r[0]); + glm_vec4_negate(r[1]); + glm_vec4_negate(r[2]); + glm_vec3_negate(s); + } +} + +/*! + * @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 +glm_decompose(mat4 m, vec4 t, mat4 r, vec3 s) { + glm_vec4_copy(m[3], t); + glm_decompose_rs(m, r, s); +} + +#endif /* cglm_affine_h */ diff --git a/libs/cglm/include/cglm/affine2d.h b/libs/cglm/include/cglm/affine2d.h new file mode 100644 index 0000000..bb66289 --- /dev/null +++ b/libs/cglm/include/cglm/affine2d.h @@ -0,0 +1,268 @@ +/* + * 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_translate2d(mat3 m, vec2 v) + CGLM_INLINE void glm_translate2d_to(mat3 m, vec2 v, mat3 dest) + CGLM_INLINE void glm_translate2d_x(mat3 m, float x) + CGLM_INLINE void glm_translate2d_y(mat3 m, float y) + CGLM_INLINE void glm_translate2d_make(mat3 m, vec2 v) + CGLM_INLINE void glm_scale2d_to(mat3 m, vec2 v, mat3 dest) + CGLM_INLINE void glm_scale2d_make(mat3 m, vec2 v) + CGLM_INLINE void glm_scale2d(mat3 m, vec2 v) + CGLM_INLINE void glm_scale2d_uni(mat3 m, float s) + CGLM_INLINE void glm_rotate2d_make(mat3 m, float angle) + CGLM_INLINE void glm_rotate2d(mat3 m, float angle) + CGLM_INLINE void glm_rotate2d_to(mat3 m, float angle, mat3 dest) + */ + +#ifndef cglm_affine2d_h +#define cglm_affine2d_h + +#include "common.h" +#include "util.h" +#include "vec2.h" +#include "mat3.h" + +/*! + * @brief translate existing 2d transform matrix by v vector + * and stores result in same matrix + * + * @param[in, out] m affine transfrom + * @param[in] v translate vector [x, y] + */ +CGLM_INLINE +void +glm_translate2d(mat3 m, vec2 v) { + m[2][0] = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0]; + m[2][1] = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1]; + m[2][2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2]; +} + +/*! + * @brief translate existing 2d 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] + * @param[out] dest translated matrix + */ +CGLM_INLINE +void +glm_translate2d_to(mat3 m, vec2 v, mat3 dest) { + glm_mat3_copy(m, dest); + glm_translate2d(dest, v); +} + +/*! + * @brief translate existing 2d transform matrix by x factor + * + * @param[in, out] m affine transfrom + * @param[in] x x factor + */ +CGLM_INLINE +void +glm_translate2d_x(mat3 m, float x) { + m[2][0] = m[0][0] * x + m[2][0]; + m[2][1] = m[0][1] * x + m[2][1]; + m[2][2] = m[0][2] * x + m[2][2]; +} + +/*! + * @brief translate existing 2d transform matrix by y factor + * + * @param[in, out] m affine transfrom + * @param[in] y y factor + */ +CGLM_INLINE +void +glm_translate2d_y(mat3 m, float y) { + m[2][0] = m[1][0] * y + m[2][0]; + m[2][1] = m[1][1] * y + m[2][1]; + m[2][2] = m[1][2] * y + m[2][2]; +} + +/*! + * @brief creates NEW translate 2d transform matrix by v vector + * + * @param[out] m affine transfrom + * @param[in] v translate vector [x, y] + */ +CGLM_INLINE +void +glm_translate2d_make(mat3 m, vec2 v) { + glm_mat3_identity(m); + m[2][0] = v[0]; + m[2][1] = v[1]; +} + +/*! + * @brief scale existing 2d transform matrix by v vector + * and store result in dest + * + * @param[in] m affine transfrom + * @param[in] v scale vector [x, y] + * @param[out] dest scaled matrix + */ +CGLM_INLINE +void +glm_scale2d_to(mat3 m, vec2 v, mat3 dest) { + dest[0][0] = m[0][0] * v[0]; + dest[0][1] = m[0][1] * v[0]; + dest[0][2] = m[0][2] * v[0]; + + dest[1][0] = m[1][0] * v[1]; + dest[1][1] = m[1][1] * v[1]; + dest[1][2] = m[1][2] * v[1]; + + dest[2][0] = m[2][0]; + dest[2][1] = m[2][1]; + dest[2][2] = m[2][2]; +} + +/*! + * @brief creates NEW 2d scale matrix by v vector + * + * @param[out] m affine transfrom + * @param[in] v scale vector [x, y] + */ +CGLM_INLINE +void +glm_scale2d_make(mat3 m, vec2 v) { + glm_mat3_identity(m); + m[0][0] = v[0]; + m[1][1] = v[1]; +} + +/*! + * @brief scales existing 2d transform matrix by v vector + * and stores result in same matrix + * + * @param[in, out] m affine transfrom + * @param[in] v scale vector [x, y] + */ +CGLM_INLINE +void +glm_scale2d(mat3 m, vec2 v) { + m[0][0] = m[0][0] * v[0]; + m[0][1] = m[0][1] * v[0]; + m[0][2] = m[0][2] * v[0]; + + m[1][0] = m[1][0] * v[1]; + m[1][1] = m[1][1] * v[1]; + m[1][2] = m[1][2] * v[1]; +} + +/*! + * @brief applies uniform scale to existing 2d transform matrix v = [s, s] + * and stores result in same matrix + * + * @param[in, out] m affine transfrom + * @param[in] s scale factor + */ +CGLM_INLINE +void +glm_scale2d_uni(mat3 m, float s) { + m[0][0] = m[0][0] * s; + m[0][1] = m[0][1] * s; + m[0][2] = m[0][2] * s; + + m[1][0] = m[1][0] * s; + m[1][1] = m[1][1] * s; + m[1][2] = m[1][2] * s; +} + +/*! + * @brief creates NEW rotation matrix by angle around Z axis + * + * @param[out] m affine transfrom + * @param[in] angle angle (radians) + */ +CGLM_INLINE +void +glm_rotate2d_make(mat3 m, float angle) { + float c, s; + + s = sinf(angle); + c = cosf(angle); + + m[0][0] = c; + m[0][1] = s; + m[0][2] = 0; + + m[1][0] = -s; + m[1][1] = c; + m[1][2] = 0; + + m[2][0] = 0.0f; + m[2][1] = 0.0f; + m[2][2] = 1.0f; +} + +/*! + * @brief rotate existing 2d transform matrix around Z axis by angle + * and store result in same matrix + * + * @param[in, out] m affine transfrom + * @param[in] angle angle (radians) + */ +CGLM_INLINE +void +glm_rotate2d(mat3 m, float angle) { + float m00 = m[0][0], m10 = m[1][0], + m01 = m[0][1], m11 = m[1][1], + m02 = m[0][2], m12 = m[1][2]; + float c, s; + + s = sinf(angle); + c = cosf(angle); + + m[0][0] = m00 * c + m10 * s; + m[0][1] = m01 * c + m11 * s; + m[0][2] = m02 * c + m12 * s; + + m[1][0] = m00 * -s + m10 * c; + m[1][1] = m01 * -s + m11 * c; + m[1][2] = m02 * -s + m12 * c; +} + +/*! + * @brief rotate existing 2d transform matrix around Z axis by angle + * and store result in dest + * + * @param[in] m affine transfrom + * @param[in] angle angle (radians) + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_rotate2d_to(mat3 m, float angle, mat3 dest) { + float m00 = m[0][0], m10 = m[1][0], + m01 = m[0][1], m11 = m[1][1], + m02 = m[0][2], m12 = m[1][2]; + float c, s; + + s = sinf(angle); + c = cosf(angle); + + dest[0][0] = m00 * c + m10 * s; + dest[0][1] = m01 * c + m11 * s; + dest[0][2] = m02 * c + m12 * s; + + dest[1][0] = m00 * -s + m10 * c; + dest[1][1] = m01 * -s + m11 * c; + dest[1][2] = m02 * -s + m12 * c; + + dest[2][0] = m[2][0]; + dest[2][1] = m[2][1]; + dest[2][2] = m[2][2]; +} + +#endif /* cglm_affine2d_h */ diff --git a/libs/cglm/include/cglm/applesimd.h b/libs/cglm/include/cglm/applesimd.h new file mode 100644 index 0000000..3608bb3 --- /dev/null +++ b/libs/cglm/include/cglm/applesimd.h @@ -0,0 +1,95 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_applesimd_h +#define cglm_applesimd_h +#if defined(__APPLE__) \ + && defined(SIMD_COMPILER_HAS_REQUIRED_FEATURES) \ + && defined(SIMD_BASE) \ + && defined(SIMD_TYPES) \ + && defined(SIMD_VECTOR_TYPES) + +#include "common.h" + +/*! +* @brief converts mat4 to Apple's simd type simd_float4x4 +* @return simd_float4x4 +*/ +CGLM_INLINE +simd_float4x4 +glm_mat4_applesimd(mat4 m) { + simd_float4x4 t; + + t.columns[0][0] = m[0][0]; + t.columns[0][1] = m[0][1]; + t.columns[0][2] = m[0][2]; + t.columns[0][3] = m[0][3]; + + t.columns[1][0] = m[1][0]; + t.columns[1][1] = m[1][1]; + t.columns[1][2] = m[1][2]; + t.columns[1][3] = m[1][3]; + + t.columns[2][0] = m[2][0]; + t.columns[2][1] = m[2][1]; + t.columns[2][2] = m[2][2]; + t.columns[2][3] = m[2][3]; + + t.columns[3][0] = m[3][0]; + t.columns[3][1] = m[3][1]; + t.columns[3][2] = m[3][2]; + t.columns[3][3] = m[3][3]; + + return t; +} + +/*! +* @brief converts mat3 to Apple's simd type simd_float3x3 +* @return simd_float3x3 +*/ +CGLM_INLINE +simd_float3x3 +glm_mat3_applesimd(mat3 m) { + simd_float3x3 t; + + t.columns[0][0] = m[0][0]; + t.columns[0][1] = m[0][1]; + t.columns[0][2] = m[0][2]; + + t.columns[1][0] = m[1][0]; + t.columns[1][1] = m[1][1]; + t.columns[1][2] = m[1][2]; + + t.columns[2][0] = m[2][0]; + t.columns[2][1] = m[2][1]; + t.columns[2][2] = m[2][2]; + + return t; +} + +/*! +* @brief converts vec4 to Apple's simd type simd_float4 +* @return simd_float4 +*/ +CGLM_INLINE +simd_float4 +glm_vec4_applesimd(vec4 v) { + return (simd_float4){v[0], v[1], v[2], v[3]}; +} + +/*! +* @brief converts vec3 to Apple's simd type simd_float3 +* @return v +*/ +CGLM_INLINE +simd_float3 +glm_vec3_applesimd(vec3 v) { + return (simd_float3){v[0], v[1], v[2]}; +} + +#endif +#endif /* cglm_applesimd_h */ diff --git a/libs/cglm/include/cglm/bezier.h b/libs/cglm/include/cglm/bezier.h new file mode 100644 index 0000000..2bbe09f --- /dev/null +++ b/libs/cglm/include/cglm/bezier.h @@ -0,0 +1,154 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#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}, \ + { 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_HERMITE_MAT ((mat4)GLM_HERMITE_MAT_INIT) + +#define CGLM_DECASTEL_EPS 1e-9f +#define CGLM_DECASTEL_MAX 1000.0f +#define CGLM_DECASTEL_SMALL 1e-20f + +/*! + * @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); +} + +/*! + * @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 H(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 + * + * @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); +} + +#endif /* cglm_bezier_h */ diff --git a/libs/cglm/include/cglm/box.h b/libs/cglm/include/cglm/box.h new file mode 100644 index 0000000..4400797 --- /dev/null +++ b/libs/cglm/include/cglm/box.h @@ -0,0 +1,281 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_box_h +#define cglm_box_h + +#include "common.h" +#include "vec3.h" +#include "vec4.h" +#include "util.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 +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); + glm_vec3_scale(m[0], box[1][0], xb); + + glm_vec3_scale(m[1], box[0][1], ya); + glm_vec3_scale(m[1], box[1][1], yb); + + glm_vec3_scale(m[2], box[0][2], za); + glm_vec3_scale(m[2], box[1][2], zb); + + /* 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]); + + /* 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]); +} + +/*! + * @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 +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]); + + dest[1][0] = glm_max(box1[1][0], box2[1][0]); + dest[1][1] = glm_max(box1[1][1], box2[1][1]); + dest[1][2] = glm_max(box1[1][2], box2[1][2]); +} + +/*! + * @brief crops a bounding box with another one. + * + * this could be useful for gettng a bbox which fits with view frustum and + * object bounding boxes. In this case you crop view frustum box with objects + * box + * + * @param[in] box bounding box 1 + * @param[in] cropBox crop box + * @param[out] dest cropped bounding box + */ +CGLM_INLINE +void +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]); + + dest[1][0] = glm_min(box[1][0], cropBox[1][0]); + dest[1][1] = glm_min(box[1][1], cropBox[1][1]); + dest[1][2] = glm_min(box[1][2], cropBox[1][2]); +} + +/*! + * @brief crops a bounding box with another one. + * + * this could be useful for gettng a bbox which fits with view frustum and + * object bounding boxes. In this case you crop view frustum box with objects + * box + * + * @param[in] box bounding box + * @param[in] cropBox crop box + * @param[in] clampBox miniumum box + * @param[out] dest cropped bounding box + */ +CGLM_INLINE +void +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); +} + +/*! + * @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 +glm_aabb_frustum(vec3 box[2], vec4 planes[6]) { + float *p, dp; + int i; + + for (i = 0; i < 6; i++) { + p = planes[i]; + dp = p[0] * box[p[0] > 0.0f][0] + + p[1] * box[p[1] > 0.0f][1] + + p[2] * box[p[2] > 0.0f][2]; + + if (dp < -p[3]) + return false; + } + + 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_vec3_broadcast(FLT_MAX, box[0]); + glm_vec3_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_vec3_max(box[0]) != FLT_MAX + && glm_vec3_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_vec3_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; +} + +/*! + * @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_vec3_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 + * + * https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c + * Solid Box - Solid Sphere test. + * + * Sphere Representation in cglm: [center.x, center.y, center.z, radii] + * + * @param[in] box solid bounding box + * @param[in] s solid sphere + */ +CGLM_INLINE +bool +glm_aabb_sphere(vec3 box[2], vec4 s) { + float dmin; + int a, b, c; + + a = (s[0] < box[0][0]) + (s[0] > box[1][0]); + b = (s[1] < box[0][1]) + (s[1] > box[1][1]); + c = (s[2] < box[0][2]) + (s[2] > box[1][2]); + + dmin = glm_pow2((s[0] - box[!(a - 1)][0]) * (a != 0)) + + glm_pow2((s[1] - box[!(b - 1)][1]) * (b != 0)) + + glm_pow2((s[2] - box[!(c - 1)][2]) * (c != 0)); + + 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 +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/libs/cglm/include/cglm/call.h b/libs/cglm/include/cglm/call.h new file mode 100644 index 0000000..734bd46 --- /dev/null +++ b/libs/cglm/include/cglm/call.h @@ -0,0 +1,43 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_call_h +#define cglm_call_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "cglm.h" +#include "call/vec2.h" +#include "call/vec3.h" +#include "call/vec4.h" +#include "call/ivec2.h" +#include "call/ivec3.h" +#include "call/ivec4.h" +#include "call/mat2.h" +#include "call/mat3.h" +#include "call/mat4.h" +#include "call/affine.h" +#include "call/cam.h" +#include "call/quat.h" +#include "call/euler.h" +#include "call/plane.h" +#include "call/frustum.h" +#include "call/box.h" +#include "call/io.h" +#include "call/project.h" +#include "call/sphere.h" +#include "call/ease.h" +#include "call/curve.h" +#include "call/bezier.h" +#include "call/ray.h" +#include "call/affine2d.h" + +#ifdef __cplusplus +} +#endif +#endif /* cglm_call_h */ diff --git a/libs/cglm/include/cglm/call/affine.h b/libs/cglm/include/cglm/call/affine.h new file mode 100644 index 0000000..c11405b --- /dev/null +++ b/libs/cglm/include/cglm/call/affine.h @@ -0,0 +1,117 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_affine_h +#define cglmc_affine_h +#ifdef __cplusplus +extern "C" { +#endif + +#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); + +CGLM_EXPORT +void +glmc_translate(mat4 m, vec3 v); + +CGLM_EXPORT +void +glmc_translate_x(mat4 m, float to); + +CGLM_EXPORT +void +glmc_translate_y(mat4 m, float to); + +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); + +CGLM_EXPORT +void +glmc_scale(mat4 m, vec3 v); + +CGLM_EXPORT +void +glmc_scale_uni(mat4 m, float s); + +CGLM_EXPORT +void +glmc_rotate_x(mat4 m, float rad, mat4 dest); + +CGLM_EXPORT +void +glmc_rotate_y(mat4 m, float rad, mat4 dest); + +CGLM_EXPORT +void +glmc_rotate_z(mat4 m, float rad, mat4 dest); + +CGLM_EXPORT +void +glmc_rotate_make(mat4 m, float angle, vec3 axis); + +CGLM_EXPORT +void +glmc_rotate(mat4 m, float angle, vec3 axis); + +CGLM_EXPORT +void +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 +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); + +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 +#endif /* cglmc_affine_h */ diff --git a/libs/cglm/include/cglm/call/affine2d.h b/libs/cglm/include/cglm/call/affine2d.h new file mode 100644 index 0000000..e1b9462 --- /dev/null +++ b/libs/cglm/include/cglm/call/affine2d.h @@ -0,0 +1,67 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_affine2d_h +#define cglmc_affine2d_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_translate2d_make(mat3 m, vec2 v); + +CGLM_EXPORT +void +glmc_translate2d_to(mat3 m, vec2 v, mat3 dest); + +CGLM_EXPORT +void +glmc_translate2d(mat3 m, vec2 v); + +CGLM_EXPORT +void +glmc_translate2d_x(mat3 m, float to); + +CGLM_EXPORT +void +glmc_translate2d_y(mat3 m, float to); + +CGLM_EXPORT +void +glmc_scale2d_to(mat3 m, vec2 v, mat3 dest); + +CGLM_EXPORT +void +glmc_scale2d_make(mat3 m, vec2 v); + +CGLM_EXPORT +void +glmc_scale2d(mat3 m, vec2 v); + +CGLM_EXPORT +void +glmc_scale2d_uni(mat3 m, float s); + +CGLM_EXPORT +void +glmc_rotate2d_make(mat3 m, float angle); + +CGLM_EXPORT +void +glmc_rotate2d(mat3 m, float angle); + +CGLM_EXPORT +void +glmc_rotate2d_to(mat3 m, float angle, mat3 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_affine2d_h */ diff --git a/libs/cglm/include/cglm/call/bezier.h b/libs/cglm/include/cglm/call/bezier.h new file mode 100644 index 0000000..a6a0eb4 --- /dev/null +++ b/libs/cglm/include/cglm/call/bezier.h @@ -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 + */ + +#ifndef cglmc_bezier_h +#define cglmc_bezier_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +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); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_bezier_h */ diff --git a/libs/cglm/include/cglm/call/box.h b/libs/cglm/include/cglm/call/box.h new file mode 100644 index 0000000..afb7558 --- /dev/null +++ b/libs/cglm/include/cglm/call/box.h @@ -0,0 +1,79 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_box_h +#define cglmc_box_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]); + +CGLM_EXPORT +void +glmc_aabb_merge(vec3 box1[2], vec3 box2[2], vec3 dest[2]); + +CGLM_EXPORT +void +glmc_aabb_crop(vec3 box[2], 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]); + +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]); + +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 s); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_box_h */ + diff --git a/libs/cglm/include/cglm/call/cam.h b/libs/cglm/include/cglm/call/cam.h new file mode 100644 index 0000000..d9567ec --- /dev/null +++ b/libs/cglm/include/cglm/call/cam.h @@ -0,0 +1,133 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_cam_h +#define cglmc_cam_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_frustum(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_ortho(float left, float right, + float bottom, float top, + float nearZ, float farZ, + 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, float aspect, float nearZ, float farZ, mat4 dest); + +CGLM_EXPORT +void +glmc_persp_move_far(mat4 proj, float deltaFar); + +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); + +CGLM_EXPORT +void +glmc_look(vec3 eye, vec3 dir, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_anyup(vec3 eye, vec3 dir, mat4 dest); + +CGLM_EXPORT +void +glmc_persp_decomp(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ, + 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 nearZ, + float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_far(mat4 proj, float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_near(mat4 proj, float * __restrict nearZ); + +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 +#endif /* cglmc_cam_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/ortho_lh_no.h b/libs/cglm/include/cglm/call/clipspace/ortho_lh_no.h new file mode 100644 index 0000000..3e26fa9 --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/ortho_lh_no.h @@ -0,0 +1,46 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ortho_lh_no_h +#define cglmc_ortho_lh_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_ortho_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_lh_no(vec3 box[2], mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_p_lh_no(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_lh_no(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_lh_no(float aspect, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_s_lh_no(float aspect, float size, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ortho_lh_no_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/ortho_lh_zo.h b/libs/cglm/include/cglm/call/clipspace/ortho_lh_zo.h new file mode 100644 index 0000000..dc4c610 --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/ortho_lh_zo.h @@ -0,0 +1,46 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ortho_lh_zo_h +#define cglmc_ortho_lh_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_ortho_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_lh_zo(vec3 box[2], mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_p_lh_zo(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_lh_zo(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_lh_zo(float aspect, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_s_lh_zo(float aspect, float size, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ortho_lh_zo_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/ortho_rh_no.h b/libs/cglm/include/cglm/call/clipspace/ortho_rh_no.h new file mode 100644 index 0000000..dbba497 --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/ortho_rh_no.h @@ -0,0 +1,46 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ortho_rh_no_h +#define cglmc_ortho_rh_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_ortho_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_rh_no(vec3 box[2], mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_p_rh_no(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_rh_no(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_rh_no(float aspect, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_s_rh_no(float aspect, float size, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ortho_rh_no_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/ortho_rh_zo.h b/libs/cglm/include/cglm/call/clipspace/ortho_rh_zo.h new file mode 100644 index 0000000..e79ae83 --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/ortho_rh_zo.h @@ -0,0 +1,46 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ortho_rh_zo_h +#define cglmc_ortho_rh_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_ortho_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_rh_zo(vec3 box[2], mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_p_rh_zo(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_rh_zo(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_rh_zo(float aspect, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_s_rh_zo(float aspect, float size, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ortho_rh_zo_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/persp_lh_no.h b/libs/cglm/include/cglm/call/clipspace/persp_lh_no.h new file mode 100644 index 0000000..4bdbcfe --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/persp_lh_no.h @@ -0,0 +1,87 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_persp_lh_no_h +#define cglmc_persp_lh_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_frustum_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_perspective_lh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest); + +CGLM_EXPORT +void +glmc_persp_move_far_lh_no(mat4 proj, float deltaFar); + +CGLM_EXPORT +void +glmc_persp_decomp_lh_no(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decompv_lh_no(mat4 proj, float dest[6]); + +CGLM_EXPORT +void +glmc_persp_decomp_x_lh_no(mat4 proj, + float * __restrict left, + float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decomp_y_lh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom); + +CGLM_EXPORT +void +glmc_persp_decomp_z_lh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_far_lh_no(mat4 proj, float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_near_lh_no(mat4 proj, float * __restrict nearZ); + +CGLM_EXPORT +void +glmc_persp_sizes_lh_no(mat4 proj, float fovy, vec4 dest); + +CGLM_EXPORT +float +glmc_persp_fovy_lh_no(mat4 proj); + +CGLM_EXPORT +float +glmc_persp_aspect_lh_no(mat4 proj); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_persp_lh_no_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/persp_lh_zo.h b/libs/cglm/include/cglm/call/clipspace/persp_lh_zo.h new file mode 100644 index 0000000..53c2c1c --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/persp_lh_zo.h @@ -0,0 +1,87 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_persp_lh_zo_h +#define cglmc_persp_lh_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_frustum_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_perspective_lh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest); + +CGLM_EXPORT +void +glmc_persp_move_far_lh_zo(mat4 proj, float deltaFar); + +CGLM_EXPORT +void +glmc_persp_decomp_lh_zo(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decompv_lh_zo(mat4 proj, float dest[6]); + +CGLM_EXPORT +void +glmc_persp_decomp_x_lh_zo(mat4 proj, + float * __restrict left, + float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decomp_y_lh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom); + +CGLM_EXPORT +void +glmc_persp_decomp_z_lh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_far_lh_zo(mat4 proj, float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_near_lh_zo(mat4 proj, float * __restrict nearZ); + +CGLM_EXPORT +void +glmc_persp_sizes_lh_zo(mat4 proj, float fovy, vec4 dest); + +CGLM_EXPORT +float +glmc_persp_fovy_lh_zo(mat4 proj); + +CGLM_EXPORT +float +glmc_persp_aspect_lh_zo(mat4 proj); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_persp_lh_zo_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/persp_rh_no.h b/libs/cglm/include/cglm/call/clipspace/persp_rh_no.h new file mode 100644 index 0000000..9c0d65d --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/persp_rh_no.h @@ -0,0 +1,87 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_persp_rh_no_h +#define cglmc_persp_rh_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_frustum_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_perspective_rh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest); + +CGLM_EXPORT +void +glmc_persp_move_far_rh_no(mat4 proj, float deltaFar); + +CGLM_EXPORT +void +glmc_persp_decomp_rh_no(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decompv_rh_no(mat4 proj, float dest[6]); + +CGLM_EXPORT +void +glmc_persp_decomp_x_rh_no(mat4 proj, + float * __restrict left, + float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decomp_y_rh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom); + +CGLM_EXPORT +void +glmc_persp_decomp_z_rh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_far_rh_no(mat4 proj, float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_near_rh_no(mat4 proj, float * __restrict nearZ); + +CGLM_EXPORT +void +glmc_persp_sizes_rh_no(mat4 proj, float fovy, vec4 dest); + +CGLM_EXPORT +float +glmc_persp_fovy_rh_no(mat4 proj); + +CGLM_EXPORT +float +glmc_persp_aspect_rh_no(mat4 proj); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_persp_rh_no_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/persp_rh_zo.h b/libs/cglm/include/cglm/call/clipspace/persp_rh_zo.h new file mode 100644 index 0000000..718d4ad --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/persp_rh_zo.h @@ -0,0 +1,87 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_persp_rh_zo_h +#define cglmc_persp_rh_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_frustum_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_perspective_rh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest); + +CGLM_EXPORT +void +glmc_persp_move_far_rh_zo(mat4 proj, float deltaFar); + +CGLM_EXPORT +void +glmc_persp_decomp_rh_zo(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decompv_rh_zo(mat4 proj, float dest[6]); + +CGLM_EXPORT +void +glmc_persp_decomp_x_rh_zo(mat4 proj, + float * __restrict left, + float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decomp_y_rh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom); + +CGLM_EXPORT +void +glmc_persp_decomp_z_rh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_far_rh_zo(mat4 proj, float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_near_rh_zo(mat4 proj, float * __restrict nearZ); + +CGLM_EXPORT +void +glmc_persp_sizes_rh_zo(mat4 proj, float fovy, vec4 dest); + +CGLM_EXPORT +float +glmc_persp_fovy_rh_zo(mat4 proj); + +CGLM_EXPORT +float +glmc_persp_aspect_rh_zo(mat4 proj); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_persp_rh_zo_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/project_no.h b/libs/cglm/include/cglm/call/clipspace/project_no.h new file mode 100644 index 0000000..c62c37b --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/project_no.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 cglmc_project_no_h +#define cglmc_project_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_unprojecti_no(vec3 pos, mat4 invMat, vec4 vp, vec3 dest); + +CGLM_EXPORT +void +glmc_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_project_no_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/project_zo.h b/libs/cglm/include/cglm/call/clipspace/project_zo.h new file mode 100644 index 0000000..a7137bd --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/project_zo.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 cglmc_project_zo_h +#define cglmc_project_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_unprojecti_zo(vec3 pos, mat4 invMat, vec4 vp, vec3 dest); + +CGLM_EXPORT +void +glmc_project_zo(vec3 pos, mat4 m, vec4 vp, vec3 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_project_zo_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/view_lh_no.h b/libs/cglm/include/cglm/call/clipspace/view_lh_no.h new file mode 100644 index 0000000..3b58c84 --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/view_lh_no.h @@ -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 + */ + +#ifndef cglmc_view_lh_no_h +#define cglmc_view_lh_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_lookat_lh_no(vec3 eye, vec3 center, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_lh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_anyup_lh_no(vec3 eye, vec3 dir, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_view_lh_no_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/view_lh_zo.h b/libs/cglm/include/cglm/call/clipspace/view_lh_zo.h new file mode 100644 index 0000000..c877367 --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/view_lh_zo.h @@ -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 + */ + +#ifndef cglmc_view_lh_zo_h +#define cglmc_view_lh_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_lookat_lh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_lh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_anyup_lh_zo(vec3 eye, vec3 dir, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_view_lh_zo_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/view_rh_no.h b/libs/cglm/include/cglm/call/clipspace/view_rh_no.h new file mode 100644 index 0000000..6303dbf --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/view_rh_no.h @@ -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 + */ + +#ifndef cglmc_view_rh_no_h +#define cglmc_view_rh_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_lookat_rh_no(vec3 eye, vec3 center, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_rh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_anyup_rh_no(vec3 eye, vec3 dir, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_view_rh_no_h */ diff --git a/libs/cglm/include/cglm/call/clipspace/view_rh_zo.h b/libs/cglm/include/cglm/call/clipspace/view_rh_zo.h new file mode 100644 index 0000000..00b8707 --- /dev/null +++ b/libs/cglm/include/cglm/call/clipspace/view_rh_zo.h @@ -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 + */ + +#ifndef cglmc_view_rh_zo_h +#define cglmc_view_rh_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../../cglm.h" + +CGLM_EXPORT +void +glmc_lookat_rh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_rh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_anyup_rh_zo(vec3 eye, vec3 dir, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_view_rh_zo_h */ diff --git a/libs/cglm/include/cglm/call/curve.h b/libs/cglm/include/cglm/call/curve.h new file mode 100644 index 0000000..061fdb9 --- /dev/null +++ b/libs/cglm/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/libs/cglm/include/cglm/call/ease.h b/libs/cglm/include/cglm/call/ease.h new file mode 100644 index 0000000..87e39ca --- /dev/null +++ b/libs/cglm/include/cglm/call/ease.h @@ -0,0 +1,143 @@ +/* + * 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); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ease_h */ diff --git a/libs/cglm/include/cglm/call/euler.h b/libs/cglm/include/cglm/call/euler.h new file mode 100644 index 0000000..2de68fb --- /dev/null +++ b/libs/cglm/include/cglm/call/euler.h @@ -0,0 +1,55 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_euler_h +#define cglmc_euler_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_euler_angles(mat4 m, vec3 dest); + +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); + +CGLM_EXPORT +void +glmc_euler_zxy(vec3 angles, mat4 dest); + +CGLM_EXPORT +void +glmc_euler_xzy(vec3 angles, mat4 dest); + +CGLM_EXPORT +void +glmc_euler_yzx(vec3 angles, mat4 dest); + +CGLM_EXPORT +void +glmc_euler_yxz(vec3 angles, mat4 dest); + +CGLM_EXPORT +void +glmc_euler_by_order(vec3 angles, glm_euler_seq axis, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_euler_h */ diff --git a/libs/cglm/include/cglm/call/frustum.h b/libs/cglm/include/cglm/call/frustum.h new file mode 100644 index 0000000..6b4facb --- /dev/null +++ b/libs/cglm/include/cglm/call/frustum.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 cglmc_frustum_h +#define cglmc_frustum_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_frustum_planes(mat4 m, vec4 dest[6]); + +CGLM_EXPORT +void +glmc_frustum_corners(mat4 invMat, vec4 dest[8]); + +CGLM_EXPORT +void +glmc_frustum_center(vec4 corners[8], vec4 dest); + +CGLM_EXPORT +void +glmc_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]); + +CGLM_EXPORT +void +glmc_frustum_corners_at(vec4 corners[8], + float splitDist, + float farDist, + vec4 planeCorners[4]); +#ifdef __cplusplus +} +#endif +#endif /* cglmc_frustum_h */ diff --git a/libs/cglm/include/cglm/call/io.h b/libs/cglm/include/cglm/call/io.h new file mode 100644 index 0000000..19ea06f --- /dev/null +++ b/libs/cglm/include/cglm/call/io.h @@ -0,0 +1,45 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_io_h +#define cglmc_io_h + +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_mat4_print(mat4 matrix, + FILE * __restrict ostream); + +CGLM_EXPORT +void +glmc_mat3_print(mat3 matrix, + FILE * __restrict ostream); + +CGLM_EXPORT +void +glmc_vec4_print(vec4 vec, + FILE * __restrict ostream); + +CGLM_EXPORT +void +glmc_vec3_print(vec3 vec, + FILE * __restrict ostream); + +CGLM_EXPORT +void +glmc_versor_print(versor vec, + FILE * __restrict ostream); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_io_h */ diff --git a/libs/cglm/include/cglm/call/ivec2.h b/libs/cglm/include/cglm/call/ivec2.h new file mode 100644 index 0000000..d3b8fd2 --- /dev/null +++ b/libs/cglm/include/cglm/call/ivec2.h @@ -0,0 +1,79 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ivec2_h +#define cglmc_ivec2_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_ivec2(int * __restrict v, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_copy(ivec2 a, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_zero(ivec2 v); + +CGLM_EXPORT +void +glmc_ivec2_one(ivec2 v); + +CGLM_EXPORT +void +glmc_ivec2_add(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_adds(ivec2 v, int s, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_subs(ivec2 v, int s, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_scale(ivec2 v, int s, ivec2 dest); + +CGLM_EXPORT +int +glmc_ivec2_distance2(ivec2 a, ivec2 b); + +CGLM_EXPORT +float +glmc_ivec2_distance(ivec2 a, ivec2 b); + +CGLM_EXPORT +void +glmc_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest); + +CGLM_EXPORT +void +glmc_ivec2_clamp(ivec2 v, int minVal, int maxVal); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ivec2_h */ diff --git a/libs/cglm/include/cglm/call/ivec3.h b/libs/cglm/include/cglm/call/ivec3.h new file mode 100644 index 0000000..3c28811 --- /dev/null +++ b/libs/cglm/include/cglm/call/ivec3.h @@ -0,0 +1,79 @@ +/* + * Copyright (c);, Recep Aslantas. + * + * MIT License (MIT);, http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ivec3_h +#define cglmc_ivec3_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_ivec3(ivec4 v4, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_copy(ivec3 a, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_zero(ivec3 v); + +CGLM_EXPORT +void +glmc_ivec3_one(ivec3 v); + +CGLM_EXPORT +void +glmc_ivec3_add(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_adds(ivec3 v, int s, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_subs(ivec3 v, int s, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_scale(ivec3 v, int s, ivec3 dest); + +CGLM_EXPORT +int +glmc_ivec3_distance2(ivec3 a, ivec3 b); + +CGLM_EXPORT +float +glmc_ivec3_distance(ivec3 a, ivec3 b); + +CGLM_EXPORT +void +glmc_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest); + +CGLM_EXPORT +void +glmc_ivec3_clamp(ivec3 v, int minVal, int maxVal); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ivec3_h */ diff --git a/libs/cglm/include/cglm/call/ivec4.h b/libs/cglm/include/cglm/call/ivec4.h new file mode 100644 index 0000000..79e11b1 --- /dev/null +++ b/libs/cglm/include/cglm/call/ivec4.h @@ -0,0 +1,79 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ivec4_h +#define cglmc_ivec4_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_ivec4(ivec3 v3, int last, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_copy(ivec4 a, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_zero(ivec4 v); + +CGLM_EXPORT +void +glmc_ivec4_one(ivec4 v); + +CGLM_EXPORT +void +glmc_ivec4_add(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_adds(ivec4 v, int s, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_sub(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_subs(ivec4 v, int s, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_mul(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_scale(ivec4 v, int s, ivec4 dest); + +CGLM_EXPORT +int +glmc_ivec4_distance2(ivec4 a, ivec4 b); + +CGLM_EXPORT +float +glmc_ivec4_distance(ivec4 a, ivec4 b); + +CGLM_EXPORT +void +glmc_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest); + +CGLM_EXPORT +void +glmc_ivec4_clamp(ivec4 v, int minVal, int maxVal); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ivec4_h */ diff --git a/libs/cglm/include/cglm/call/mat2.h b/libs/cglm/include/cglm/call/mat2.h new file mode 100644 index 0000000..91234a3 --- /dev/null +++ b/libs/cglm/include/cglm/call/mat2.h @@ -0,0 +1,79 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_mat2_h +#define cglmc_mat2_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_mat2_copy(mat2 mat, mat2 dest); + +CGLM_EXPORT +void +glmc_mat2_identity(mat2 mat); + +CGLM_EXPORT +void +glmc_mat2_identity_array(mat2 * __restrict mat, size_t count); + +CGLM_EXPORT +void +glmc_mat2_zero(mat2 mat); + +CGLM_EXPORT +void +glmc_mat2_mul(mat2 m1, mat2 m2, mat2 dest); + +CGLM_EXPORT +void +glmc_mat2_transpose_to(mat2 m, mat2 dest); + +CGLM_EXPORT +void +glmc_mat2_transpose(mat2 m); + +CGLM_EXPORT +void +glmc_mat2_mulv(mat2 m, vec2 v, vec2 dest); + +CGLM_EXPORT +float +glmc_mat2_trace(mat2 m); + +CGLM_EXPORT +void +glmc_mat2_scale(mat2 m, float s); + +CGLM_EXPORT +float +glmc_mat2_det(mat2 mat); + +CGLM_EXPORT +void +glmc_mat2_inv(mat2 mat, mat2 dest); + +CGLM_EXPORT +void +glmc_mat2_swap_col(mat2 mat, int col1, int col2); + +CGLM_EXPORT +void +glmc_mat2_swap_row(mat2 mat, int row1, int row2); + +CGLM_EXPORT +float +glmc_mat2_rmc(vec2 r, mat2 m, vec2 c); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_mat2_h */ diff --git a/libs/cglm/include/cglm/call/mat3.h b/libs/cglm/include/cglm/call/mat3.h new file mode 100644 index 0000000..36dcb27 --- /dev/null +++ b/libs/cglm/include/cglm/call/mat3.h @@ -0,0 +1,86 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_mat3_h +#define cglmc_mat3_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +/* DEPRECATED! use _copy, _ucopy versions */ +#define glmc_mat3_dup(mat, dest) glmc_mat3_copy(mat, dest) + +CGLM_EXPORT +void +glmc_mat3_copy(mat3 mat, mat3 dest); + +CGLM_EXPORT +void +glmc_mat3_identity(mat3 mat); + +CGLM_EXPORT +void +glmc_mat3_zero(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); + +CGLM_EXPORT +void +glmc_mat3_transpose_to(mat3 m, mat3 dest); + +CGLM_EXPORT +void +glmc_mat3_transpose(mat3 m); + +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); + +CGLM_EXPORT +void +glmc_mat3_scale(mat3 m, float s); + +CGLM_EXPORT +float +glmc_mat3_det(mat3 mat); + +CGLM_EXPORT +void +glmc_mat3_inv(mat3 mat, mat3 dest); + +CGLM_EXPORT +void +glmc_mat3_swap_col(mat3 mat, int col1, int col2); + +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 +#endif /* cglmc_mat3_h */ diff --git a/libs/cglm/include/cglm/call/mat4.h b/libs/cglm/include/cglm/call/mat4.h new file mode 100644 index 0000000..1c71da1 --- /dev/null +++ b/libs/cglm/include/cglm/call/mat4.h @@ -0,0 +1,127 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_mat_h +#define cglmc_mat_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +/* DEPRECATED! use _copy, _ucopy versions */ +#define glmc_mat4_udup(mat, dest) glmc_mat4_ucopy(mat, dest) +#define glmc_mat4_dup(mat, dest) glmc_mat4_copy(mat, dest) + +CGLM_EXPORT +void +glmc_mat4_ucopy(mat4 mat, mat4 dest); + +CGLM_EXPORT +void +glmc_mat4_copy(mat4 mat, mat4 dest); + +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_zero(mat4 mat); + +CGLM_EXPORT +void +glmc_mat4_pick3(mat4 mat, mat3 dest); + +CGLM_EXPORT +void +glmc_mat4_pick3t(mat4 mat, mat3 dest); + +CGLM_EXPORT +void +glmc_mat4_ins3(mat3 mat, mat4 dest); + +CGLM_EXPORT +void +glmc_mat4_mul(mat4 m1, mat4 m2, mat4 dest); + +CGLM_EXPORT +void +glmc_mat4_mulN(mat4 * __restrict matrices[], uint32_t len, mat4 dest); + +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 +float +glmc_mat4_trace(mat4 m); + +CGLM_EXPORT +float +glmc_mat4_trace3(mat4 m); + +CGLM_EXPORT +void +glmc_mat4_quat(mat4 m, versor dest); + +CGLM_EXPORT +void +glmc_mat4_transpose_to(mat4 m, mat4 dest); + +CGLM_EXPORT +void +glmc_mat4_transpose(mat4 m); + +CGLM_EXPORT +void +glmc_mat4_scale_p(mat4 m, float s); + +CGLM_EXPORT +void +glmc_mat4_scale(mat4 m, float s); + +CGLM_EXPORT +float +glmc_mat4_det(mat4 mat); + +CGLM_EXPORT +void +glmc_mat4_inv(mat4 mat, mat4 dest); + +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); + +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 +#endif /* cglmc_mat_h */ diff --git a/libs/cglm/include/cglm/call/plane.h b/libs/cglm/include/cglm/call/plane.h new file mode 100644 index 0000000..f991121 --- /dev/null +++ b/libs/cglm/include/cglm/call/plane.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_plane_h +#define cglmc_plane_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_plane_normalize(vec4 plane); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_plane_h */ diff --git a/libs/cglm/include/cglm/call/project.h b/libs/cglm/include/cglm/call/project.h new file mode 100644 index 0000000..991ba1d --- /dev/null +++ b/libs/cglm/include/cglm/call/project.h @@ -0,0 +1,37 @@ +/* + * 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(vec3 pos, mat4 invMat, vec4 vp, vec3 dest); + +CGLM_EXPORT +void +glmc_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest); + +CGLM_EXPORT +void +glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest); + +CGLM_EXPORT +void +glmc_pickmatrix(vec2 center, vec2 size, vec4 vp, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_project_h */ + + diff --git a/libs/cglm/include/cglm/call/quat.h b/libs/cglm/include/cglm/call/quat.h new file mode 100644 index 0000000..1a2766d --- /dev/null +++ b/libs/cglm/include/cglm/call/quat.h @@ -0,0 +1,167 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_quat_h +#define cglmc_quat_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +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); + +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 axis); + +CGLM_EXPORT +void +glmc_quat_copy(versor q, versor dest); + +CGLM_EXPORT +void +glmc_quat_from_vecs(vec3 a, vec3 b, 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 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, vec3 dest); + +CGLM_EXPORT +void +glmc_quat_mul(versor p, versor q, versor dest); + +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_lerpc(versor from, versor to, float t, versor dest); + +CGLM_EXPORT +void +glmc_quat_nlerp(versor q, versor r, 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 up, versor dest); + +CGLM_EXPORT +void +glmc_quat_forp(vec3 from, vec3 to, 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); + +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 +#endif /* cglmc_quat_h */ diff --git a/libs/cglm/include/cglm/call/ray.h b/libs/cglm/include/cglm/call/ray.h new file mode 100644 index 0000000..1fff055 --- /dev/null +++ b/libs/cglm/include/cglm/call/ray.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 cglmc_ray_h +#define cglmc_ray_h +#ifdef __cplusplus +extern "C" { +#endif +#include "../cglm.h" + +CGLM_EXPORT +bool +glmc_ray_triangle(vec3 origin, + vec3 direction, + vec3 v0, + vec3 v1, + vec3 v2, + float *d); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ray_h */ diff --git a/libs/cglm/include/cglm/call/sphere.h b/libs/cglm/include/cglm/call/sphere.h new file mode 100644 index 0000000..9b96546 --- /dev/null +++ b/libs/cglm/include/cglm/call/sphere.h @@ -0,0 +1,39 @@ +/* + * 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); + +CGLM_EXPORT +bool +glmc_sphere_point(vec4 s, vec3 point); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_sphere_h */ diff --git a/libs/cglm/include/cglm/call/vec2.h b/libs/cglm/include/cglm/call/vec2.h new file mode 100644 index 0000000..6e8101e --- /dev/null +++ b/libs/cglm/include/cglm/call/vec2.h @@ -0,0 +1,167 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_vec2_h +#define cglmc_vec2_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_vec2(float * __restrict v, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_copy(vec2 a, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_zero(vec2 v); + +CGLM_EXPORT +void +glmc_vec2_one(vec2 v); + +CGLM_EXPORT +float +glmc_vec2_dot(vec2 a, vec2 b); + +CGLM_EXPORT +float +glmc_vec2_cross(vec2 a, vec2 b); + +CGLM_EXPORT +float +glmc_vec2_norm2(vec2 v); + +CGLM_EXPORT +float +glmc_vec2_norm(vec2 v); + +CGLM_EXPORT +void +glmc_vec2_add(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_adds(vec2 v, float s, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_sub(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_subs(vec2 v, float s, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_mul(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_scale(vec2 v, float s, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_scale_as(vec2 v, float s, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_div(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_divs(vec2 v, float s, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_addadd(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_subadd(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_muladd(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_muladds(vec2 a, float s, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_maxadd(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_minadd(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_negate_to(vec2 v, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_negate(vec2 v); + +CGLM_EXPORT +void +glmc_vec2_normalize(vec2 v); + +CGLM_EXPORT +void +glmc_vec2_normalize_to(vec2 v, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_rotate(vec2 v, float angle, vec2 dest); + +CGLM_EXPORT +float +glmc_vec2_distance2(vec2 a, vec2 b); + +CGLM_EXPORT +float +glmc_vec2_distance(vec2 a, vec2 b); + +CGLM_EXPORT +void +glmc_vec2_maxv(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_minv(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_clamp(vec2 v, float minval, float maxval); + +CGLM_EXPORT +void +glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_complex_mul(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_complex_div(vec2 a, vec2 b, vec2 dest); + +CGLM_EXPORT +void +glmc_vec2_complex_conjugate(vec2 a, vec2 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_vec2_h */ diff --git a/libs/cglm/include/cglm/call/vec3.h b/libs/cglm/include/cglm/call/vec3.h new file mode 100644 index 0000000..69fc0e2 --- /dev/null +++ b/libs/cglm/include/cglm/call/vec3.h @@ -0,0 +1,312 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_vec3_h +#define cglmc_vec3_h +#ifdef __cplusplus +extern "C" { +#endif + +#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) +#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 +glmc_vec3(vec4 v4, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_copy(vec3 a, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_zero(vec3 v); + +CGLM_EXPORT +void +glmc_vec3_one(vec3 v); + +CGLM_EXPORT +float +glmc_vec3_dot(vec3 a, vec3 b); + +CGLM_EXPORT +void +glmc_vec3_cross(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_crossn(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +float +glmc_vec3_norm(vec3 v); + +CGLM_EXPORT +float +glmc_vec3_norm2(vec3 v); + +CGLM_EXPORT +float +glmc_vec3_norm_one(vec3 v); + +CGLM_EXPORT +float +glmc_vec3_norm_inf(vec3 v); + +CGLM_EXPORT +void +glmc_vec3_normalize_to(vec3 v, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_normalize(vec3 v); + +CGLM_EXPORT +void +glmc_vec3_add(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_adds(vec3 v, float s, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_sub(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_subs(vec3 v, float s, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_mul(vec3 a, vec3 b, vec3 d); + +CGLM_EXPORT +void +glmc_vec3_scale(vec3 v, float s, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_scale_as(vec3 v, float s, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_div(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_divs(vec3 a, float s, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_addadd(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_subadd(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_muladd(vec3 a, vec3 b, vec3 dest); + +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); + +CGLM_EXPORT +void +glmc_vec3_negate_to(vec3 v, vec3 dest); + +CGLM_EXPORT +float +glmc_vec3_angle(vec3 a, vec3 b); + +CGLM_EXPORT +void +glmc_vec3_rotate(vec3 v, float angle, vec3 axis); + +CGLM_EXPORT +void +glmc_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_proj(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_center(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +float +glmc_vec3_distance2(vec3 a, vec3 b); + +CGLM_EXPORT +float +glmc_vec3_distance(vec3 a, vec3 b); + +CGLM_EXPORT +void +glmc_vec3_maxv(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_minv(vec3 a, vec3 b, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_clamp(vec3 v, float minVal, float maxVal); + +CGLM_EXPORT +void +glmc_vec3_ortho(vec3 v, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_lerpc(vec3 from, vec3 to, float t, vec3 dest); + +CGLM_INLINE +void +glmc_vec3_mix(vec3 from, vec3 to, float t, vec3 dest) { + glmc_vec3_lerp(from, to, t, dest); +} + +CGLM_INLINE +void +glmc_vec3_mixc(vec3 from, vec3 to, float t, vec3 dest) { + glmc_vec3_lerpc(from, to, t, dest); +} + +CGLM_EXPORT +void +glmc_vec3_step_uni(float edge, vec3 x, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_step(vec3 edge, vec3 x, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_smoothstep_uni(float edge0, float edge1, vec3 x, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_smoothstep(vec3 edge0, vec3 edge1, vec3 x, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_smoothinterp(vec3 from, vec3 to, float t, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_smoothinterpc(vec3 from, vec3 to, float t, vec3 dest); + +/* ext */ + +CGLM_EXPORT +void +glmc_vec3_mulv(vec3 a, vec3 b, vec3 d); + +CGLM_EXPORT +void +glmc_vec3_broadcast(float val, vec3 d); + +CGLM_EXPORT +void +glmc_vec3_fill(vec3 v, float val); + +CGLM_EXPORT +bool +glmc_vec3_eq(vec3 v, float val); + +CGLM_EXPORT +bool +glmc_vec3_eq_eps(vec3 v, float val); + +CGLM_EXPORT +bool +glmc_vec3_eq_all(vec3 v); + +CGLM_EXPORT +bool +glmc_vec3_eqv(vec3 a, vec3 b); + +CGLM_EXPORT +bool +glmc_vec3_eqv_eps(vec3 a, vec3 b); + +CGLM_EXPORT +float +glmc_vec3_max(vec3 v); + +CGLM_EXPORT +float +glmc_vec3_min(vec3 v); + +CGLM_EXPORT +bool +glmc_vec3_isnan(vec3 v); + +CGLM_EXPORT +bool +glmc_vec3_isinf(vec3 v); + +CGLM_EXPORT +bool +glmc_vec3_isvalid(vec3 v); + +CGLM_EXPORT +void +glmc_vec3_sign(vec3 v, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_abs(vec3 v, vec3 dest); + +CGLM_EXPORT +void +glmc_vec3_fract(vec3 v, vec3 dest); + +CGLM_EXPORT +float +glmc_vec3_hadd(vec3 v); + +CGLM_EXPORT +void +glmc_vec3_sqrt(vec3 v, vec3 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_vec3_h */ diff --git a/libs/cglm/include/cglm/call/vec4.h b/libs/cglm/include/cglm/call/vec4.h new file mode 100644 index 0000000..f56f599 --- /dev/null +++ b/libs/cglm/include/cglm/call/vec4.h @@ -0,0 +1,290 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_vec4_h +#define cglmc_vec4_h +#ifdef __cplusplus +extern "C" { +#endif + +#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_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 +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 v, vec3 dest); + +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); + +CGLM_EXPORT +float +glmc_vec4_norm(vec4 v); + +CGLM_EXPORT +float +glmc_vec4_norm2(vec4 v); + +CGLM_EXPORT +float +glmc_vec4_norm_one(vec4 v); + +CGLM_EXPORT +float +glmc_vec4_norm_inf(vec4 v); + +CGLM_EXPORT +void +glmc_vec4_normalize_to(vec4 v, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_normalize(vec4 v); + +CGLM_EXPORT +void +glmc_vec4_add(vec4 a, vec4 b, vec4 dest); + +CGLM_EXPORT +void +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 +glmc_vec4_scale(vec4 v, float s, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_scale_as(vec4 v, float s, vec4 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_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_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); + +CGLM_EXPORT +void +glmc_vec4_negate_to(vec4 v, vec4 dest); + +CGLM_EXPORT +float +glmc_vec4_distance(vec4 a, vec4 b); + +CGLM_EXPORT +float +glmc_vec4_distance2(vec4 a, vec4 b); + +CGLM_EXPORT +void +glmc_vec4_maxv(vec4 a, vec4 b, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_minv(vec4 a, vec4 b, vec4 dest); + +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); + +CGLM_EXPORT +void +glmc_vec4_lerpc(vec4 from, vec4 to, float t, vec4 dest); + +CGLM_INLINE +void +glmc_vec4_mix(vec4 from, vec4 to, float t, vec4 dest) { + glmc_vec4_lerp(from, to, t, dest); +} + +CGLM_INLINE +void +glmc_vec4_mixc(vec4 from, vec4 to, float t, vec4 dest) { + glmc_vec4_lerpc(from, to, t, dest); +} + +CGLM_EXPORT +void +glmc_vec4_step_uni(float edge, vec4 x, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_step(vec4 edge, vec4 x, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_smoothstep_uni(float edge0, float edge1, vec4 x, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_smoothstep(vec4 edge0, vec4 edge1, vec4 x, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_smoothinterp(vec4 from, vec4 to, float t, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_smoothinterpc(vec4 from, vec4 to, float t, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_cubic(float s, 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 +void +glmc_vec4_fill(vec4 v, float val); + +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 a, vec4 b); + +CGLM_EXPORT +bool +glmc_vec4_eqv_eps(vec4 a, vec4 b); + +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_abs(vec4 v, vec4 dest); + +CGLM_EXPORT +void +glmc_vec4_fract(vec4 v, vec4 dest); + +CGLM_EXPORT +float +glmc_vec4_hadd(vec4 v); + +CGLM_EXPORT +void +glmc_vec4_sqrt(vec4 v, vec4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_vec4_h */ + diff --git a/libs/cglm/include/cglm/cam.h b/libs/cglm/include/cglm/cam.h new file mode 100644 index 0000000..c8cfd42 --- /dev/null +++ b/libs/cglm/include/cglm/cam.h @@ -0,0 +1,582 @@ +/* + * 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_frustum(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_ortho(float left, float right, + float bottom, float top, + float nearZ, float farZ, + 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 nearZ, + float farZ, + 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 *nearZ, float *farZ, + 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 *nearv, float *farv) + CGLM_INLINE void glm_persp_decomp_far(mat4 proj, float *farZ) + CGLM_INLINE void glm_persp_decomp_near(mat4 proj, float *nearZ) + 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_cam_h +#define cglm_cam_h + +#include "common.h" +#include "plane.h" + +#include "clipspace/persp.h" + +#ifndef CGLM_CLIPSPACE_INCLUDE_ALL +# if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO +# include "clipspace/ortho_lh_zo.h" +# include "clipspace/persp_lh_zo.h" +# include "clipspace/view_lh_zo.h" +# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO +# include "clipspace/ortho_lh_no.h" +# include "clipspace/persp_lh_no.h" +# include "clipspace/view_lh_no.h" +# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO +# include "clipspace/ortho_rh_zo.h" +# include "clipspace/persp_rh_zo.h" +# include "clipspace/view_rh_zo.h" +# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO +# include "clipspace/ortho_rh_no.h" +# include "clipspace/persp_rh_no.h" +# include "clipspace/view_rh_no.h" +# endif +#else +# include "clipspace/ortho_lh_zo.h" +# include "clipspace/persp_lh_zo.h" +# include "clipspace/ortho_lh_no.h" +# include "clipspace/persp_lh_no.h" +# include "clipspace/ortho_rh_zo.h" +# include "clipspace/persp_rh_zo.h" +# include "clipspace/ortho_rh_no.h" +# include "clipspace/persp_rh_no.h" +# include "clipspace/view_lh_zo.h" +# include "clipspace/view_lh_no.h" +# include "clipspace/view_rh_zo.h" +# include "clipspace/view_rh_no.h" +#endif + +/*! + * @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] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_frustum(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_frustum_lh_zo(left, right, bottom, top, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_frustum_lh_no(left, right, bottom, top, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_frustum_rh_zo(left, right, bottom, top, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_frustum_rh_no(left, right, bottom, top, nearZ, farZ, dest); +#endif +} + +/*! + * @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] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_ortho_lh_zo(left, right, bottom, top, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_ortho_lh_no(left, right, bottom, top, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_ortho_rh_zo(left, right, bottom, top, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_ortho_rh_no(left, right, bottom, top, nearZ, farZ, dest); +#endif +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb(vec3 box[2], mat4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_ortho_aabb_lh_zo(box, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_ortho_aabb_lh_no(box, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_ortho_aabb_rh_zo(box, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_ortho_aabb_rh_no(box, dest); +#endif +} + +/*! + * @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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_ortho_aabb_p_lh_zo(box, padding, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_ortho_aabb_p_lh_no(box, padding, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_ortho_aabb_p_rh_zo(box, padding, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_ortho_aabb_p_rh_no(box, padding, dest); +#endif +} + +/*! + * @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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_ortho_aabb_pz_lh_zo(box, padding, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_ortho_aabb_pz_lh_no(box, padding, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_ortho_aabb_pz_rh_zo(box, padding, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_ortho_aabb_pz_rh_no(box, padding, dest); +#endif +} + +/*! + * @brief set up unit orthographic projection matrix + * + * @param[in] aspect aspect ration ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default(float aspect, mat4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_ortho_default_lh_zo(aspect, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_ortho_default_lh_no(aspect, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_ortho_default_rh_zo(aspect, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_ortho_default_rh_no(aspect, dest); +#endif +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_s(float aspect, float size, mat4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_ortho_default_s_lh_zo(aspect, size, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_ortho_default_s_lh_no(aspect, size, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_ortho_default_s_rh_zo(aspect, size, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_ortho_default_s_rh_no(aspect, size, dest); +#endif +} + +/*! + * @brief set up perspective projection matrix + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective(float fovy, float aspect, float nearZ, float farZ, mat4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_perspective_lh_zo(fovy, aspect, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_perspective_lh_no(fovy, aspect, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_perspective_rh_zo(fovy, aspect, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_perspective_rh_no(fovy, aspect, nearZ, farZ, dest); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_move_far_lh_zo(proj, deltaFar); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_move_far_lh_no(proj, deltaFar); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_move_far_rh_zo(proj, deltaFar); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_move_far_rh_no(proj, deltaFar); +#endif +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_default(float aspect, mat4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_perspective_default_lh_zo(aspect, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_perspective_default_lh_no(aspect, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_perspective_default_rh_zo(aspect, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_perspective_default_rh_no(aspect, dest); +#endif +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * reized + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in, out] proj perspective projection matrix + */ +CGLM_INLINE +void +glm_perspective_resize(float aspect, mat4 proj) { + if (proj[0][0] == 0.0f) + return; + + proj[0][0] = proj[1][1] / 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH_BIT + glm_lookat_lh(eye, center, up, dest); +#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH_BIT + glm_lookat_rh(eye, center, up, dest); +#endif +} + +/*! + * @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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH_BIT + glm_look_lh(eye, dir, up, dest); +#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH_BIT + glm_look_rh(eye, dir, up, dest); +#endif +} + +/*! + * @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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH_BIT + glm_look_anyup_lh(eye, dir, dest); +#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH_BIT + glm_look_anyup_rh(eye, dir, dest); +#endif +} + +/*! + * @brief decomposes frustum values of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decomp_lh_zo(proj, nearZ, farZ, top, bottom, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decomp_lh_no(proj, nearZ, farZ, top, bottom, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decomp_rh_zo(proj, nearZ, farZ, top, bottom, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decomp_rh_no(proj, nearZ, farZ, top, bottom, left, right); +#endif +} + +/*! + * @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 +glm_persp_decompv(mat4 proj, float dest[6]) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decompv_lh_zo(proj, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decompv_lh_no(proj, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decompv_rh_zo(proj, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decompv_rh_no(proj, dest); +#endif +} + +/*! + * @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 +glm_persp_decomp_x(mat4 proj, + float * __restrict left, + float * __restrict right) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decomp_x_lh_zo(proj, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decomp_x_lh_no(proj, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decomp_x_rh_zo(proj, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decomp_x_rh_no(proj, left, right); +#endif +} + +/*! + * @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 +glm_persp_decomp_y(mat4 proj, + float * __restrict top, + float * __restrict bottom) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decomp_y_lh_zo(proj, top, bottom); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decomp_y_lh_no(proj, top, bottom); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decomp_y_rh_zo(proj, top, bottom); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decomp_y_rh_no(proj, top, bottom); +#endif +} + +/*! + * @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] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_z(mat4 proj, float * __restrict nearZ, float * __restrict farZ) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decomp_z_lh_zo(proj, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decomp_z_lh_no(proj, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decomp_z_rh_zo(proj, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decomp_z_rh_no(proj, nearZ, farZ); +#endif +} + +/*! + * @brief decomposes far value of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_far(mat4 proj, float * __restrict farZ) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decomp_far_lh_zo(proj, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decomp_far_lh_no(proj, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decomp_far_rh_zo(proj, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decomp_far_rh_no(proj, farZ); +#endif +} + +/*! + * @brief decomposes near value of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glm_persp_decomp_near(mat4 proj, float * __restrict nearZ) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decomp_near_lh_zo(proj, nearZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decomp_near_lh_no(proj, nearZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decomp_near_rh_zo(proj, nearZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decomp_near_rh_no(proj, nearZ); +#endif +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @param[out] dest sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +void +glm_persp_sizes(mat4 proj, float fovy, vec4 dest) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_sizes_lh_zo(proj, fovy, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_sizes_lh_no(proj, fovy, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_sizes_rh_zo(proj, fovy, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_sizes_rh_no(proj, fovy, dest); +#endif +} + +#endif /* cglm_cam_h */ diff --git a/libs/cglm/include/cglm/cglm.h b/libs/cglm/include/cglm/cglm.h new file mode 100644 index 0000000..1828cb4 --- /dev/null +++ b/libs/cglm/include/cglm/cglm.h @@ -0,0 +1,39 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_h +#define cglm_h + +#include "common.h" +#include "vec2.h" +#include "vec3.h" +#include "vec4.h" +#include "ivec2.h" +#include "ivec3.h" +#include "ivec4.h" +#include "mat4.h" +#include "mat3.h" +#include "mat2.h" +#include "affine.h" +#include "cam.h" +#include "frustum.h" +#include "quat.h" +#include "euler.h" +#include "plane.h" +#include "box.h" +#include "color.h" +#include "util.h" +#include "io.h" +#include "project.h" +#include "sphere.h" +#include "ease.h" +#include "curve.h" +#include "bezier.h" +#include "ray.h" +#include "affine2d.h" + +#endif /* cglm_h */ diff --git a/libs/cglm/include/cglm/clipspace/ortho_lh_no.h b/libs/cglm/include/cglm/clipspace/ortho_lh_no.h new file mode 100644 index 0000000..76c7a94 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/ortho_lh_no.h @@ -0,0 +1,183 @@ +/* + * 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_ortho_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_lh_no(vec3 box[2], mat4 dest) + CGLM_INLINE void glm_ortho_aabb_p_lh_no(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_pz_lh_no(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_default_lh_no(float aspect, + mat4 dest) + CGLM_INLINE void glm_ortho_default_s_lh_no(float aspect, + float size, + mat4 dest) + */ + +#ifndef cglm_ortho_lh_no_h +#define cglm_ortho_lh_no_h + +#include "../common.h" +#include "../plane.h" +#include "../mat4.h" + +/*! + * @brief set up orthographic projection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + + dest[0][0] = 2.0f * rl; + dest[1][1] = 2.0f * tb; + dest[2][2] =-2.0f * fn; + dest[3][0] =-(right + left) * rl; + dest[3][1] =-(top + bottom) * tb; + dest[3][2] = (farZ + nearZ) * fn; + dest[3][3] = 1.0f; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_lh_no(vec3 box[2], mat4 dest) { + glm_ortho_lh_no(box[0][0], box[1][0], + box[0][1], box[1][1], + -box[1][2], -box[0][2], + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_p_lh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_lh_no(box[0][0] - padding, box[1][0] + padding, + box[0][1] - padding, box[1][1] + padding, + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_pz_lh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_lh_no(box[0][0], box[1][0], + box[0][1], box[1][1], + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up unit orthographic projection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_lh_no(float aspect, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_lh_no(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest); + return; + } + + aspect = 1.0f / aspect; + + glm_ortho_lh_no(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest); +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_s_lh_no(float aspect, float size, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_lh_no(-size * aspect, + size * aspect, + -size, + size, + -size - 100.0f, + size + 100.0f, + dest); + return; + } + + glm_ortho_lh_no(-size, + size, + -size / aspect, + size / aspect, + -size - 100.0f, + size + 100.0f, + dest); +} + +#endif /*cglm_ortho_lh_no_h*/ diff --git a/libs/cglm/include/cglm/clipspace/ortho_lh_zo.h b/libs/cglm/include/cglm/clipspace/ortho_lh_zo.h new file mode 100644 index 0000000..e45530d --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/ortho_lh_zo.h @@ -0,0 +1,177 @@ +/* + * 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_ortho_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_lh_zo(vec3 box[2], mat4 dest) + CGLM_INLINE void glm_ortho_aabb_p_lh_zo(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_pz_lh_zo(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_default_lh_zo(float aspect, + mat4 dest) + CGLM_INLINE void glm_ortho_default_s_lh_zo(float aspect, + float size, + mat4 dest) + */ + +#ifndef cglm_ortho_lh_zo_h +#define cglm_ortho_lh_zo_h + +#include "../common.h" +#include "../plane.h" +#include "../mat4.h" + +/*! + * @brief set up orthographic projection matrix with a left-hand coordinate + * system and a clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + + dest[0][0] = 2.0f * rl; + dest[1][1] = 2.0f * tb; + dest[2][2] =-fn; + dest[3][0] =-(right + left) * rl; + dest[3][1] =-(top + bottom) * tb; + dest[3][2] = nearZ * fn; + dest[3][3] = 1.0f; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a clip-space of [0, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_lh_zo(vec3 box[2], mat4 dest) { + glm_ortho_lh_zo(box[0][0], box[1][0], + box[0][1], box[1][1], + -box[1][2], -box[0][2], + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a clip-space of [0, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_p_lh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_lh_zo(box[0][0] - padding, box[1][0] + padding, + box[0][1] - padding, box[1][1] + padding, + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a clip-space of [0, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_pz_lh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_lh_zo(box[0][0], box[1][0], + box[0][1], box[1][1], + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up unit orthographic projection matrix + * with a left-hand coordinate system and a clip-space of [0, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_lh_zo(float aspect, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_lh_zo(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest); + return; + } + + aspect = 1.0f / aspect; + + glm_ortho_lh_zo(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest); +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a left-hand coordinate system and a clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_s_lh_zo(float aspect, float size, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_lh_zo(-size * aspect, + size * aspect, + -size, + size, + -size - 100.0f, + size + 100.0f, + dest); + return; + } + + glm_ortho_lh_zo(-size, + size, + -size / aspect, + size / aspect, + -size - 100.0f, + size + 100.0f, + dest); +} + +#endif /*cglm_ortho_lh_zo_h*/ diff --git a/libs/cglm/include/cglm/clipspace/ortho_rh_no.h b/libs/cglm/include/cglm/clipspace/ortho_rh_no.h new file mode 100644 index 0000000..aa7a906 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/ortho_rh_no.h @@ -0,0 +1,183 @@ +/* + * 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_ortho_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_rh_no(vec3 box[2], mat4 dest) + CGLM_INLINE void glm_ortho_aabb_p_rh_no(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_pz_rh_no(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_default_rh_no(float aspect, + mat4 dest) + CGLM_INLINE void glm_ortho_default_s_rh_no(float aspect, + float size, + mat4 dest) + */ + +#ifndef cglm_ortho_rh_no_h +#define cglm_ortho_rh_no_h + +#include "../common.h" +#include "../plane.h" +#include "../mat4.h" + +/*! + * @brief set up orthographic projection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + + dest[0][0] = 2.0f * rl; + dest[1][1] = 2.0f * tb; + dest[2][2] = 2.0f * fn; + dest[3][0] =-(right + left) * rl; + dest[3][1] =-(top + bottom) * tb; + dest[3][2] = (farZ + nearZ) * fn; + dest[3][3] = 1.0f; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_rh_no(vec3 box[2], mat4 dest) { + glm_ortho_rh_no(box[0][0], box[1][0], + box[0][1], box[1][1], + -box[1][2], -box[0][2], + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_p_rh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_rh_no(box[0][0] - padding, box[1][0] + padding, + box[0][1] - padding, box[1][1] + padding, + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_pz_rh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_rh_no(box[0][0], box[1][0], + box[0][1], box[1][1], + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up unit orthographic projection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_rh_no(float aspect, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_rh_no(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest); + return; + } + + aspect = 1.0f / aspect; + + glm_ortho_rh_no(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest); +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_s_rh_no(float aspect, float size, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_rh_no(-size * aspect, + size * aspect, + -size, + size, + -size - 100.0f, + size + 100.0f, + dest); + return; + } + + glm_ortho_rh_no(-size, + size, + -size / aspect, + size / aspect, + -size - 100.0f, + size + 100.0f, + dest); +} + +#endif /*cglm_ortho_rh_no_h*/ diff --git a/libs/cglm/include/cglm/clipspace/ortho_rh_zo.h b/libs/cglm/include/cglm/clipspace/ortho_rh_zo.h new file mode 100644 index 0000000..7a0876c --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/ortho_rh_zo.h @@ -0,0 +1,181 @@ +/* + * 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_ortho_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_rh_zo(vec3 box[2], mat4 dest) + CGLM_INLINE void glm_ortho_aabb_p_rh_zo(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_pz_rh_zo(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_default_rh_zo(float aspect, + mat4 dest) + CGLM_INLINE void glm_ortho_default_s_rh_zo(float aspect, + float size, + mat4 dest) + */ + +#ifndef cglm_ortho_rh_zo_h +#define cglm_ortho_rh_zo_h + +#include "../common.h" +#include "../plane.h" +#include "../mat4.h" + +/*! + * @brief set up orthographic projection matrix with a right-hand coordinate + * system and a clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + + dest[0][0] = 2.0f * rl; + dest[1][1] = 2.0f * tb; + dest[2][2] = fn; + dest[3][0] =-(right + left) * rl; + dest[3][1] =-(top + bottom) * tb; + dest[3][2] = nearZ * fn; + dest[3][3] = 1.0f; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a clip-space with depth + * values from zero to one. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_rh_zo(vec3 box[2], mat4 dest) { + glm_ortho_rh_zo(box[0][0], box[1][0], + box[0][1], box[1][1], + -box[1][2], -box[0][2], + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a clip-space with depth + * values from zero to one. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_p_rh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_rh_zo(box[0][0] - padding, box[1][0] + padding, + box[0][1] - padding, box[1][1] + padding, + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a clip-space with depth + * values from zero to one. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_pz_rh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_rh_zo(box[0][0], box[1][0], + box[0][1], box[1][1], + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up unit orthographic projection matrix with a right-hand + * coordinate system and a clip-space of [0, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_rh_zo(float aspect, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_rh_zo(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest); + return; + } + + aspect = 1.0f / aspect; + + glm_ortho_rh_zo(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest); +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a right-hand coordinate system and a clip-space with depth + * values from zero to one. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_s_rh_zo(float aspect, float size, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_rh_zo(-size * aspect, + size * aspect, + -size, + size, + -size - 100.0f, + size + 100.0f, + dest); + return; + } + + glm_ortho_rh_zo(-size, + size, + -size / aspect, + size / aspect, + -size - 100.0f, + size + 100.0f, + dest); +} + +#endif /*cglm_ortho_rh_zo_h*/ diff --git a/libs/cglm/include/cglm/clipspace/persp.h b/libs/cglm/include/cglm/clipspace/persp.h new file mode 100644 index 0000000..15aa715 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/persp.h @@ -0,0 +1,48 @@ +/* + * 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_persp_decomp_far(mat4 proj, float *farZ) + 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_persp_h +#define cglm_persp_h + +#include "../common.h" +#include "../plane.h" +#include "../mat4.h" + +/*! + * @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 +glm_persp_fovy(mat4 proj) { + return 2.0f * atanf(1.0f / proj[1][1]); +} + +/*! + * @brief returns aspect ratio of perspective projection + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_aspect(mat4 proj) { + return proj[1][1] / proj[0][0]; +} + +#endif /* cglm_persp_h */ diff --git a/libs/cglm/include/cglm/clipspace/persp_lh_no.h b/libs/cglm/include/cglm/clipspace/persp_lh_no.h new file mode 100644 index 0000000..703530e --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/persp_lh_no.h @@ -0,0 +1,395 @@ +/* + * 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_frustum_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_lh_no(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_default_lh_no(float aspect, mat4 dest) + CGLM_INLINE void glm_perspective_resize_lh_no(float aspect, mat4 proj) + CGLM_INLINE void glm_persp_move_far_lh_no(mat4 proj, + float deltaFar) + CGLM_INLINE void glm_persp_decomp_lh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decompv_lh_no(mat4 proj, + float dest[6]) + CGLM_INLINE void glm_persp_decomp_x_lh_no(mat4 proj, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decomp_y_lh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom) + CGLM_INLINE void glm_persp_decomp_z_lh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_far_lh_no(mat4 proj, float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_near_lh_no(mat4 proj, float * __restrict nearZ) + CGLM_INLINE void glm_persp_sizes_lh_no(mat4 proj, float fovy, vec4 dest) + */ + +#ifndef cglm_persp_lh_no_h +#define cglm_persp_lh_no_h + +#include "../common.h" +#include "persp.h" + +/*! + * @brief set up perspective peprojection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_frustum_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn, nv; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + nv = 2.0f * nearZ; + + dest[0][0] = nv * rl; + dest[1][1] = nv * tb; + dest[2][0] = (right + left) * rl; + dest[2][1] = (top + bottom) * tb; + dest[2][2] =-(farZ + nearZ) * fn; + dest[2][3] = 1.0f; + dest[3][2] = farZ * nv * fn; +} + +/*! + * @brief set up perspective projection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_lh_no(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) { + float f, fn; + + glm_mat4_zero(dest); + + f = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (nearZ - farZ); + + dest[0][0] = f / aspect; + dest[1][1] = f; + dest[2][2] =-(nearZ + farZ) * fn; + dest[2][3] = 1.0f; + dest[3][2] = 2.0f * nearZ * farZ * fn; + +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_default_lh_no(float aspect, mat4 dest) { + glm_perspective_lh_no(GLM_PI_4f, aspect, 0.01f, 100.0f, dest); +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * resized with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in, out] proj perspective projection matrix + */ +CGLM_INLINE +void +glm_perspective_resize_lh_no(float aspect, mat4 proj) { + if (proj[0][0] == 0.0f) + return; + + proj[0][0] = proj[1][1] / aspect; +} + +/*! + * @brief extend perspective projection matrix's far distance + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_lh_no(mat4 proj, float deltaFar) { + float fn, farZ, nearZ, p22, p32; + + p22 = -proj[2][2]; + p32 = proj[3][2]; + + nearZ = p32 / (p22 - 1.0f); + farZ = p32 / (p22 + 1.0f) + deltaFar; + fn = 1.0f / (nearZ - farZ); + + proj[2][2] = -(farZ + nearZ) * fn; + proj[3][2] = 2.0f * nearZ * farZ * fn; +} + +/*! + * @brief decomposes frustum values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_lh_no(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + 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; + + m00 = proj[0][0]; + m11 = proj[1][1]; + m20 = proj[2][0]; + m21 = proj[2][1]; + m22 =-proj[2][2]; + m32 = proj[3][2]; + + n = m32 / (m22 - 1.0f); + f = m32 / (m22 + 1.0f); + + n_m11 = n / m11; + n_m00 = n / m00; + + *nearZ = n; + *farZ = f; + *bottom = n_m11 * (m21 - 1.0f); + *top = n_m11 * (m21 + 1.0f); + *left = n_m00 * (m20 - 1.0f); + *right = n_m00 * (m20 + 1.0f); +} + +/*! + * @brief decomposes frustum values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * this makes easy to get all values at once + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glm_persp_decompv_lh_no(mat4 proj, float dest[6]) { + glm_persp_decomp_lh_no(proj, &dest[0], &dest[1], &dest[2], + &dest[3], &dest[4], &dest[5]); +} + +/*! + * @brief decomposes left and right values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * 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 +glm_persp_decomp_x_lh_no(mat4 proj, + float * __restrict left, + float * __restrict right) { + float nearZ, m20, m00, m22; + + m00 = proj[0][0]; + m20 = proj[2][0]; + m22 =-proj[2][2]; + + nearZ = proj[3][2] / (m22 - 1.0f); + *left = nearZ * (m20 - 1.0f) / m00; + *right = nearZ * (m20 + 1.0f) / m00; +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * 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 +glm_persp_decomp_y_lh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + float nearZ, m21, m11, m22; + + m21 = proj[2][1]; + m11 = proj[1][1]; + m22 =-proj[2][2]; + + nearZ = proj[3][2] / (m22 - 1.0f); + *bottom = nearZ * (m21 - 1.0f) / m11; + *top = nearZ * (m21 + 1.0f) / m11; +} + +/*! + * @brief decomposes near and far values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_z_lh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + float m32, m22; + + m32 = proj[3][2]; + m22 =-proj[2][2]; + + *nearZ = m32 / (m22 - 1.0f); + *farZ = m32 / (m22 + 1.0f); +} + +/*! + * @brief decomposes far value of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_far_lh_no(mat4 proj, float * __restrict farZ) { + *farZ = proj[3][2] / (-proj[2][2] + 1.0f); +} + +/*! + * @brief decomposes near value of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glm_persp_decomp_near_lh_no(mat4 proj, float * __restrict nearZ) { + *nearZ = proj[3][2] / (-proj[2][2] - 1.0f); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @param[out] dest sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +void +glm_persp_sizes_lh_no(mat4 proj, float fovy, vec4 dest) { + float t, a, nearZ, farZ; + + t = 2.0f * tanf(fovy * 0.5f); + a = glm_persp_aspect(proj); + + glm_persp_decomp_z_lh_no(proj, &nearZ, &farZ); + + dest[1] = t * nearZ; + dest[3] = t * farZ; + dest[0] = a * dest[1]; + dest[2] = a * dest[3]; +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a left-hand coordinate system and a clip-space of [-1, 1]. + * + * 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 +glm_persp_fovy_lh_no(mat4 proj) { + return glm_persp_fovy(proj); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a left-hand coordinate system and a clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_aspect_lh_no(mat4 proj) { + return glm_persp_aspect(proj); +} + +#endif /*cglm_cam_lh_no_h*/ diff --git a/libs/cglm/include/cglm/clipspace/persp_lh_zo.h b/libs/cglm/include/cglm/clipspace/persp_lh_zo.h new file mode 100644 index 0000000..de89643 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/persp_lh_zo.h @@ -0,0 +1,387 @@ +/* + * 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_frustum_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_lh_zo(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_default_lh_zo(float aspect, mat4 dest) + CGLM_INLINE void glm_perspective_resize_lh_zo(float aspect, mat4 proj) + CGLM_INLINE void glm_persp_move_far_lh_zo(mat4 proj, + float deltaFar) + CGLM_INLINE void glm_persp_decomp_lh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decompv_lh_zo(mat4 proj, + float dest[6]) + CGLM_INLINE void glm_persp_decomp_x_lh_zo(mat4 proj, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decomp_y_lh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom) + CGLM_INLINE void glm_persp_decomp_z_lh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_far_lh_zo(mat4 proj, float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_near_lh_zo(mat4 proj, float * __restrict nearZ) + CGLM_INLINE void glm_persp_sizes_lh_zo(mat4 proj, float fovy, vec4 dest) + */ + +#ifndef cglm_persp_lh_zo_h +#define cglm_persp_lh_zo_h + +#include "../common.h" +#include "persp.h" + +/*! + * @brief set up perspective peprojection matrix with a left-hand coordinate + * system and a clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_frustum_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn, nv; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + nv = 2.0f * nearZ; + + dest[0][0] = nv * rl; + dest[1][1] = nv * tb; + dest[2][0] = (right + left) * rl; + dest[2][1] = (top + bottom) * tb; + dest[2][2] =-farZ * fn; + dest[2][3] = 1.0f; + dest[3][2] = farZ * nearZ * fn; +} + +/*! + * @brief set up perspective projection matrix with a left-hand coordinate + * system and a clip-space of [0, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_lh_zo(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) { + float f, fn; + + glm_mat4_zero(dest); + + f = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (nearZ - farZ); + + dest[0][0] = f / aspect; + dest[1][1] = f; + dest[2][2] =-farZ * fn; + dest[2][3] = 1.0f; + dest[3][2] = nearZ * farZ * fn; +} + +/*! + * @brief extend perspective projection matrix's far distance with a + * left-hand coordinate system and a clip-space with depth values + * from zero to one. + * + * 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_lh_zo(mat4 proj, float deltaFar) { + float fn, farZ, nearZ, p22, p32; + + p22 = -proj[2][2]; + p32 = proj[3][2]; + + nearZ = p32 / p22; + farZ = p32 / (p22 + 1.0f) + deltaFar; + fn = 1.0f / (nearZ - farZ); + + proj[2][2] = -farZ * fn; + proj[3][2] = nearZ * farZ * fn; +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_default_lh_zo(float aspect, mat4 dest) { + glm_perspective_lh_zo(GLM_PI_4f, aspect, 0.01f, 100.0f, dest); +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * reized + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in, out] proj perspective projection matrix + */ +CGLM_INLINE +void +glm_perspective_resize_lh_zo(float aspect, mat4 proj) { + if (proj[0][0] == 0.0f) + return; + + proj[0][0] = proj[1][1] / aspect; +} + +/*! + * @brief decomposes frustum values of perspective projection + * with angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_lh_zo(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + 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; + + m00 = proj[0][0]; + m11 = proj[1][1]; + m20 = proj[2][0]; + m21 = proj[2][1]; + m22 =-proj[2][2]; + m32 = proj[3][2]; + + n = m32 / m22; + f = m32 / (m22 + 1.0f); + + n_m11 = n / m11; + n_m00 = n / m00; + + *nearZ = n; + *farZ = f; + *bottom = n_m11 * (m21 - 1.0f); + *top = n_m11 * (m21 + 1.0f); + *left = n_m00 * (m20 - 1.0f); + *right = n_m00 * (m20 + 1.0f); +} + +/*! + * @brief decomposes frustum values of perspective projection + * with angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * this makes easy to get all values at once + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glm_persp_decompv_lh_zo(mat4 proj, float dest[6]) { + glm_persp_decomp_lh_zo(proj, &dest[0], &dest[1], &dest[2], + &dest[3], &dest[4], &dest[5]); +} + +/*! + * @brief decomposes left and right values of perspective projection (ZO). + * 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 +glm_persp_decomp_x_lh_zo(mat4 proj, + float * __restrict left, + float * __restrict right) { + float nearZ, m20, m00; + + m00 = proj[0][0]; + m20 = proj[2][0]; + + nearZ = proj[3][2] / (proj[3][3]); + *left = nearZ * (m20 - 1.0f) / m00; + *right = nearZ * (m20 + 1.0f) / m00; +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * y stands for y axis (top / bottom axis) + * + * @param[in] proj perspective projection matrix + * @param[out] top top + * @param[out] bottom bottom + */ +CGLM_INLINE +void +glm_persp_decomp_y_lh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + float nearZ, m21, m11; + + m21 = proj[2][1]; + m11 = proj[1][1]; + + nearZ = proj[3][2] / (proj[3][3]); + *bottom = nearZ * (m21 - 1) / m11; + *top = nearZ * (m21 + 1) / m11; +} + +/*! + * @brief decomposes near and far values of perspective projection + * with angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_z_lh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + float m32, m22; + + m32 = proj[3][2]; + m22 = -proj[2][2]; + + *nearZ = m32 / m22; + *farZ = m32 / (m22 + 1.0f); +} + +/*! + * @brief decomposes far value of perspective projection + * with angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_far_lh_zo(mat4 proj, float * __restrict farZ) { + *farZ = proj[3][2] / (-proj[2][2] + 1.0f); +} + +/*! + * @brief decomposes near value of perspective projection + * with angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glm_persp_decomp_near_lh_zo(mat4 proj, float * __restrict nearZ) { + *nearZ = proj[3][2] / -proj[2][2]; +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @param[out] dest sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +void +glm_persp_sizes_lh_zo(mat4 proj, float fovy, vec4 dest) { + float t, a, nearZ, farZ; + + t = 2.0f * tanf(fovy * 0.5f); + a = glm_persp_aspect(proj); + + glm_persp_decomp_z_lh_zo(proj, &nearZ, &farZ); + + dest[1] = t * nearZ; + dest[3] = t * farZ; + dest[0] = a * dest[1]; + dest[2] = a * dest[3]; +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a left-hand coordinate system and a clip-space of [0, 1]. + * + * 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 +glm_persp_fovy_lh_zo(mat4 proj) { + return glm_persp_fovy(proj); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a left-hand coordinate system and a clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_aspect_lh_zo(mat4 proj) { + return glm_persp_aspect(proj); +} + +#endif /*cglm_persp_lh_zo_h*/ diff --git a/libs/cglm/include/cglm/clipspace/persp_rh_no.h b/libs/cglm/include/cglm/clipspace/persp_rh_no.h new file mode 100644 index 0000000..021b7d8 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/persp_rh_no.h @@ -0,0 +1,395 @@ +/* + * 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_frustum_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_rh_no(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_default_rh_no(float aspect, mat4 dest) + CGLM_INLINE void glm_perspective_resize_rh_no(float aspect, mat4 proj) + CGLM_INLINE void glm_persp_move_far_rh_no(mat4 proj, + float deltaFar) + CGLM_INLINE void glm_persp_decomp_rh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decompv_rh_no(mat4 proj, + float dest[6]) + CGLM_INLINE void glm_persp_decomp_x_rh_no(mat4 proj, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decomp_y_rh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom) + CGLM_INLINE void glm_persp_decomp_z_rh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_far_rh_no(mat4 proj, float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_near_rh_no(mat4 proj, float * __restrict nearZ) + CGLM_INLINE void glm_persp_sizes_rh_no(mat4 proj, float fovy, vec4 dest) + */ + +#ifndef cglm_persp_rh_no_h +#define cglm_persp_rh_no_h + +#include "../common.h" +#include "persp.h" + +/*! + * @brief set up perspective peprojection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_frustum_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn, nv; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + nv = 2.0f * nearZ; + + dest[0][0] = nv * rl; + dest[1][1] = nv * tb; + dest[2][0] = (right + left) * rl; + dest[2][1] = (top + bottom) * tb; + dest[2][2] = (farZ + nearZ) * fn; + dest[2][3] =-1.0f; + dest[3][2] = farZ * nv * fn; +} + +/*! + * @brief set up perspective projection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_rh_no(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) { + float f, fn; + + glm_mat4_zero(dest); + + f = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (nearZ - farZ); + + dest[0][0] = f / aspect; + dest[1][1] = f; + dest[2][2] = (nearZ + farZ) * fn; + dest[2][3] =-1.0f; + dest[3][2] = 2.0f * nearZ * farZ * fn; + +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_default_rh_no(float aspect, mat4 dest) { + glm_perspective_rh_no(GLM_PI_4f, aspect, 0.01f, 100.0f, dest); +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * resized with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in, out] proj perspective projection matrix + */ +CGLM_INLINE +void +glm_perspective_resize_rh_no(float aspect, mat4 proj) { + if (proj[0][0] == 0.0f) + return; + + proj[0][0] = proj[1][1] / aspect; +} + +/*! + * @brief extend perspective projection matrix's far distance + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_rh_no(mat4 proj, float deltaFar) { + float fn, farZ, nearZ, p22, p32; + + p22 = proj[2][2]; + p32 = proj[3][2]; + + nearZ = p32 / (p22 - 1.0f); + farZ = p32 / (p22 + 1.0f) + deltaFar; + fn = 1.0f / (nearZ - farZ); + + proj[2][2] = (farZ + nearZ) * fn; + proj[3][2] = 2.0f * nearZ * farZ * fn; +} + +/*! + * @brief decomposes frustum values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_rh_no(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + 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; + + m00 = proj[0][0]; + m11 = proj[1][1]; + m20 = proj[2][0]; + m21 = proj[2][1]; + m22 = proj[2][2]; + m32 = proj[3][2]; + + n = m32 / (m22 - 1.0f); + f = m32 / (m22 + 1.0f); + + n_m11 = n / m11; + n_m00 = n / m00; + + *nearZ = n; + *farZ = f; + *bottom = n_m11 * (m21 - 1.0f); + *top = n_m11 * (m21 + 1.0f); + *left = n_m00 * (m20 - 1.0f); + *right = n_m00 * (m20 + 1.0f); +} + +/*! + * @brief decomposes frustum values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * this makes easy to get all values at once + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glm_persp_decompv_rh_no(mat4 proj, float dest[6]) { + glm_persp_decomp_rh_no(proj, &dest[0], &dest[1], &dest[2], + &dest[3], &dest[4], &dest[5]); +} + +/*! + * @brief decomposes left and right values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * 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 +glm_persp_decomp_x_rh_no(mat4 proj, + float * __restrict left, + float * __restrict right) { + float nearZ, m20, m00, m22; + + m00 = proj[0][0]; + m20 = proj[2][0]; + m22 = proj[2][2]; + + nearZ = proj[3][2] / (m22 - 1.0f); + *left = nearZ * (m20 - 1.0f) / m00; + *right = nearZ * (m20 + 1.0f) / m00; +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * 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 +glm_persp_decomp_y_rh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + float nearZ, m21, m11, m22; + + m21 = proj[2][1]; + m11 = proj[1][1]; + m22 = proj[2][2]; + + nearZ = proj[3][2] / (m22 - 1.0f); + *bottom = nearZ * (m21 - 1.0f) / m11; + *top = nearZ * (m21 + 1.0f) / m11; +} + +/*! + * @brief decomposes near and far values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_z_rh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + float m32, m22; + + m32 = proj[3][2]; + m22 = proj[2][2]; + + *nearZ = m32 / (m22 - 1.0f); + *farZ = m32 / (m22 + 1.0f); +} + +/*! + * @brief decomposes far value of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_far_rh_no(mat4 proj, float * __restrict farZ) { + *farZ = proj[3][2] / (proj[2][2] + 1.0f); +} + +/*! + * @brief decomposes near value of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glm_persp_decomp_near_rh_no(mat4 proj, float * __restrict nearZ) { + *nearZ = proj[3][2] / (proj[2][2] - 1.0f); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @param[out] dest sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +void +glm_persp_sizes_rh_no(mat4 proj, float fovy, vec4 dest) { + float t, a, nearZ, farZ; + + t = 2.0f * tanf(fovy * 0.5f); + a = glm_persp_aspect(proj); + + glm_persp_decomp_z_rh_no(proj, &nearZ, &farZ); + + dest[1] = t * nearZ; + dest[3] = t * farZ; + dest[0] = a * dest[1]; + dest[2] = a * dest[3]; +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a right-hand coordinate system and a clip-space of [-1, 1]. + * + * 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 +glm_persp_fovy_rh_no(mat4 proj) { + return glm_persp_fovy(proj); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a right-hand coordinate system and a clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_aspect_rh_no(mat4 proj) { + return glm_persp_aspect(proj); +} + +#endif /*cglm_cam_rh_no_h*/ diff --git a/libs/cglm/include/cglm/clipspace/persp_rh_zo.h b/libs/cglm/include/cglm/clipspace/persp_rh_zo.h new file mode 100644 index 0000000..ce632b3 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/persp_rh_zo.h @@ -0,0 +1,389 @@ +/* + * 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_frustum_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_rh_zo(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_default_rh_zo(float aspect, mat4 dest) + CGLM_INLINE void glm_perspective_resize_rh_zo(float aspect, mat4 proj) + CGLM_INLINE void glm_persp_move_far_rh_zo(mat4 proj, + float deltaFar) + CGLM_INLINE void glm_persp_decomp_rh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decompv_rh_zo(mat4 proj, + float dest[6]) + CGLM_INLINE void glm_persp_decomp_x_rh_zo(mat4 proj, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decomp_y_rh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom) + CGLM_INLINE void glm_persp_decomp_z_rh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_far_rh_zo(mat4 proj, float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_near_rh_zo(mat4 proj, float * __restrict nearZ) + CGLM_INLINE void glm_persp_sizes_rh_zo(mat4 proj, float fovy, vec4 dest) + */ + +#ifndef cglm_persp_rh_zo_h +#define cglm_persp_rh_zo_h + +#include "../common.h" +#include "persp.h" + +/*! + * @brief set up perspective peprojection matrix with a right-hand coordinate + * system and a clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_frustum_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn, nv; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + nv = 2.0f * nearZ; + + dest[0][0] = nv * rl; + dest[1][1] = nv * tb; + dest[2][0] = (right + left) * rl; + dest[2][1] = (top + bottom) * tb; + dest[2][2] = farZ * fn; + dest[2][3] =-1.0f; + dest[3][2] = farZ * nearZ * fn; +} + +/*! + * @brief set up perspective projection matrix with a right-hand coordinate + * system and a clip-space of [0, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_rh_zo(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) { + float f, fn; + + glm_mat4_zero(dest); + + f = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (nearZ - farZ); + + dest[0][0] = f / aspect; + dest[1][1] = f; + dest[2][2] = farZ * fn; + dest[2][3] =-1.0f; + dest[3][2] = nearZ * farZ * fn; +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_default_rh_zo(float aspect, mat4 dest) { + glm_perspective_rh_zo(GLM_PI_4f, aspect, 0.01f, 100.0f, dest); +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * resized with a right-hand coordinate system and a clip-space of + * [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in, out] proj perspective projection matrix + */ +CGLM_INLINE +void +glm_perspective_resize_rh_zo(float aspect, mat4 proj) { + if (proj[0][0] == 0.0f) + return; + + proj[0][0] = proj[1][1] / aspect; +} + +/*! + * @brief extend perspective projection matrix's far distance with a + * right-hand coordinate system and a clip-space of [0, 1]. + * + * 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_rh_zo(mat4 proj, float deltaFar) { + float fn, farZ, nearZ, p22, p32; + + p22 = proj[2][2]; + p32 = proj[3][2]; + + nearZ = p32 / p22; + farZ = p32 / (p22 + 1.0f) + deltaFar; + fn = 1.0f / (nearZ - farZ); + + proj[2][2] = farZ * fn; + proj[3][2] = nearZ * farZ * fn; +} + +/*! + * @brief decomposes frustum values of perspective projection + * with angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_rh_zo(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + 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; + + m00 = proj[0][0]; + m11 = proj[1][1]; + m20 = proj[2][0]; + m21 = proj[2][1]; + m22 = proj[2][2]; + m32 = proj[3][2]; + + n = m32 / m22; + f = m32 / (m22 + 1.0f); + + n_m11 = n / m11; + n_m00 = n / m00; + + *nearZ = n; + *farZ = f; + *bottom = n_m11 * (m21 - 1.0f); + *top = n_m11 * (m21 + 1.0f); + *left = n_m00 * (m20 - 1.0f); + *right = n_m00 * (m20 + 1.0f); +} + +/*! + * @brief decomposes frustum values of perspective projection + * with angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * this makes easy to get all values at once + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glm_persp_decompv_rh_zo(mat4 proj, float dest[6]) { + glm_persp_decomp_rh_zo(proj, &dest[0], &dest[1], &dest[2], + &dest[3], &dest[4], &dest[5]); +} + +/*! + * @brief decomposes left and right values of perspective projection (ZO). + * 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 +glm_persp_decomp_x_rh_zo(mat4 proj, + float * __restrict left, + float * __restrict right) { + float nearZ, m20, m00, m22; + + m00 = proj[0][0]; + m20 = proj[2][0]; + m22 = proj[2][2]; + + nearZ = proj[3][2] / m22; + *left = nearZ * (m20 - 1.0f) / m00; + *right = nearZ * (m20 + 1.0f) / m00; +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * y stands for y axis (top / bottom axis) + * + * @param[in] proj perspective projection matrix + * @param[out] top top + * @param[out] bottom bottom + */ +CGLM_INLINE +void +glm_persp_decomp_y_rh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + float nearZ, m21, m11, m22; + + m21 = proj[2][1]; + m11 = proj[1][1]; + m22 = proj[2][2]; + + nearZ = proj[3][2] / m22; + *bottom = nearZ * (m21 - 1) / m11; + *top = nearZ * (m21 + 1) / m11; +} + +/*! + * @brief decomposes near and far values of perspective projection + * with angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_z_rh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + float m32, m22; + + m32 = proj[3][2]; + m22 = proj[2][2]; + + *nearZ = m32 / m22; + *farZ = m32 / (m22 + 1.0f); +} + +/*! + * @brief decomposes far value of perspective projection + * with angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_far_rh_zo(mat4 proj, float * __restrict farZ) { + *farZ = proj[3][2] / (proj[2][2] + 1.0f); +} + +/*! + * @brief decomposes near value of perspective projection + * with angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glm_persp_decomp_near_rh_zo(mat4 proj, float * __restrict nearZ) { + *nearZ = proj[3][2] / proj[2][2]; +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @param[out] dest sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +void +glm_persp_sizes_rh_zo(mat4 proj, float fovy, vec4 dest) { + float t, a, nearZ, farZ; + + t = 2.0f * tanf(fovy * 0.5f); + a = glm_persp_aspect(proj); + + glm_persp_decomp_z_rh_zo(proj, &nearZ, &farZ); + + dest[1] = t * nearZ; + dest[3] = t * farZ; + dest[0] = a * dest[1]; + dest[2] = a * dest[3]; +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a right-hand coordinate system and a clip-space of [0, 1]. + * + * 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 +glm_persp_fovy_rh_zo(mat4 proj) { + return glm_persp_fovy(proj); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a right-hand coordinate system and a clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_aspect_rh_zo(mat4 proj) { + return glm_persp_aspect(proj); +} + +#endif /*cglm_persp_rh_zo_h*/ diff --git a/libs/cglm/include/cglm/clipspace/project_no.h b/libs/cglm/include/cglm/clipspace/project_no.h new file mode 100644 index 0000000..7e74323 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/project_no.h @@ -0,0 +1,86 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_project_no_h +#define cglm_project_no_h + +#include "../common.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] + * @param[out] dest unprojected coordinates + */ +CGLM_INLINE +void +glm_unprojecti_no(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { + vec4 v; + + 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], v); + glm_vec3(v, 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] + * @param[out] dest projected coordinates + */ +CGLM_INLINE +void +glm_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest) { + CGLM_ALIGN(16) 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 */ + glm_vec4_scale(pos4, 0.5f, pos4); + glm_vec4_adds(pos4, 0.5f, pos4); + + dest[0] = pos4[0] * vp[2] + vp[0]; + dest[1] = pos4[1] * vp[3] + vp[1]; + dest[2] = pos4[2]; +} + +#endif /* cglm_project_no_h */ diff --git a/libs/cglm/include/cglm/clipspace/project_zo.h b/libs/cglm/include/cglm/clipspace/project_zo.h new file mode 100644 index 0000000..98e58af --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/project_zo.h @@ -0,0 +1,88 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_project_zo_h +#define cglm_project_zo_h + +#include "../common.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] + * @param[out] dest unprojected coordinates + */ +CGLM_INLINE +void +glm_unprojecti_zo(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { + vec4 v; + + 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] = pos[2]; + v[3] = 1.0f; + + glm_mat4_mulv(invMat, v, v); + glm_vec4_scale(v, 1.0f / v[3], v); + glm_vec3(v, 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] + * @param[out] dest projected coordinates + */ +CGLM_INLINE +void +glm_project_zo(vec3 pos, mat4 m, vec4 vp, vec3 dest) { + CGLM_ALIGN(16) 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[2] = pos4[2]; + + glm_vec4_scale(pos4, 0.5f, pos4); + glm_vec4_adds(pos4, 0.5f, pos4); + + dest[0] = pos4[0] * vp[2] + vp[0]; + dest[1] = pos4[1] * vp[3] + vp[1]; +} + +#endif /* cglm_project_zo_h */ diff --git a/libs/cglm/include/cglm/clipspace/view_lh.h b/libs/cglm/include/cglm/clipspace/view_lh.h new file mode 100644 index 0000000..5667694 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/view_lh.h @@ -0,0 +1,99 @@ +/* + * 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_lookat_lh(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_lh(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup_lh(vec3 eye, vec3 dir, mat4 dest) + */ + +#ifndef cglm_view_lh_h +#define cglm_view_lh_h + +#include "../common.h" +#include "../plane.h" + +/*! + * @brief set up view matrix (LH) + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat_lh(vec3 eye, vec3 center, vec3 up, mat4 dest) { + CGLM_ALIGN(8) vec3 f, u, s; + + glm_vec3_sub(center, eye, f); + glm_vec3_normalize(f); + + glm_vec3_crossn(up, f, s); + glm_vec3_cross(f, s, u); + + dest[0][0] = s[0]; + dest[0][1] = u[0]; + dest[0][2] = f[0]; + dest[1][0] = s[1]; + dest[1][1] = u[1]; + dest[1][2] = f[1]; + dest[2][0] = s[2]; + dest[2][1] = u[2]; + dest[2][2] = f[2]; + 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; +} + +/*! + * @brief set up view matrix with left handed coordinate system + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_lh(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + CGLM_ALIGN(8) vec3 target; + glm_vec3_add(eye, dir, target); + glm_lookat_lh(eye, target, up, dest); +} + +/*! + * @brief set up view matrix with left handed coordinate system + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup_lh(vec3 eye, vec3 dir, mat4 dest) { + CGLM_ALIGN(8) vec3 up; + glm_vec3_ortho(dir, up); + glm_look_lh(eye, dir, up, dest); +} + +#endif /*cglm_view_lh_h*/ diff --git a/libs/cglm/include/cglm/clipspace/view_lh_no.h b/libs/cglm/include/cglm/clipspace/view_lh_no.h new file mode 100644 index 0000000..454d903 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/view_lh_no.h @@ -0,0 +1,74 @@ +/* + * 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_lookat_lh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_lh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup_lh_no(vec3 eye, vec3 dir, mat4 dest) + */ + +#ifndef cglm_view_lh_no_h +#define cglm_view_lh_no_h + +#include "../common.h" +#include "view_lh.h" + +/*! + * @brief set up view matrix with left handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat_lh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_lh(eye, center, up, dest); +} + +/*! + * @brief set up view matrix with left handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_lh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_lh(eye, dir, up, dest); +} + +/*! + * @brief set up view matrix with left handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup_lh_no(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_lh(eye, dir, dest); +} + +#endif /*cglm_view_lh_no_h*/ diff --git a/libs/cglm/include/cglm/clipspace/view_lh_zo.h b/libs/cglm/include/cglm/clipspace/view_lh_zo.h new file mode 100644 index 0000000..6b0c4d1 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/view_lh_zo.h @@ -0,0 +1,74 @@ +/* + * 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_lookat_lh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_lh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup_lh_zo(vec3 eye, vec3 dir, mat4 dest) + */ + +#ifndef cglm_view_lh_zo_h +#define cglm_view_lh_zo_h + +#include "../common.h" +#include "view_lh.h" + +/*! + * @brief set up view matrix with left handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat_lh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_lh(eye, center, up, dest); +} + +/*! + * @brief set up view matrix with left handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_lh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_lh(eye, dir, up, dest); +} + +/*! + * @brief set up view matrix with left handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup_lh_zo(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_lh(eye, dir, dest); +} + +#endif /*cglm_view_lh_zo_h*/ diff --git a/libs/cglm/include/cglm/clipspace/view_rh.h b/libs/cglm/include/cglm/clipspace/view_rh.h new file mode 100644 index 0000000..51ec916 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/view_rh.h @@ -0,0 +1,99 @@ +/* + * 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_lookat_rh(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_rh(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup_rh(vec3 eye, vec3 dir, mat4 dest) + */ + +#ifndef cglm_view_rh_h +#define cglm_view_rh_h + +#include "../common.h" +#include "../plane.h" + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat_rh(vec3 eye, vec3 center, vec3 up, mat4 dest) { + CGLM_ALIGN(8) vec3 f, u, s; + + glm_vec3_sub(center, eye, f); + glm_vec3_normalize(f); + + glm_vec3_crossn(f, up, s); + glm_vec3_cross(s, f, u); + + dest[0][0] = s[0]; + dest[0][1] = u[0]; + dest[0][2] =-f[0]; + dest[1][0] = s[1]; + dest[1][1] = u[1]; + dest[1][2] =-f[1]; + dest[2][0] = s[2]; + dest[2][1] = u[2]; + dest[2][2] =-f[2]; + 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; +} + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_rh(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + CGLM_ALIGN(8) vec3 target; + glm_vec3_add(eye, dir, target); + glm_lookat_rh(eye, target, up, dest); +} + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup_rh(vec3 eye, vec3 dir, mat4 dest) { + CGLM_ALIGN(8) vec3 up; + glm_vec3_ortho(dir, up); + glm_look_rh(eye, dir, up, dest); +} + +#endif /*cglm_view_rh_h*/ diff --git a/libs/cglm/include/cglm/clipspace/view_rh_no.h b/libs/cglm/include/cglm/clipspace/view_rh_no.h new file mode 100644 index 0000000..ca36d30 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/view_rh_no.h @@ -0,0 +1,74 @@ +/* + * 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_lookat_rh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_rh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup_rh_no(vec3 eye, vec3 dir, mat4 dest) + */ + +#ifndef cglm_view_rh_no_h +#define cglm_view_rh_no_h + +#include "../common.h" +#include "view_rh.h" + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat_rh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_rh(eye, center, up, dest); +} + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_rh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_rh(eye, dir, up, dest); +} + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup_rh_no(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_rh(eye, dir, dest); +} + +#endif /*cglm_view_rh_no_h*/ diff --git a/libs/cglm/include/cglm/clipspace/view_rh_zo.h b/libs/cglm/include/cglm/clipspace/view_rh_zo.h new file mode 100644 index 0000000..1ad5c91 --- /dev/null +++ b/libs/cglm/include/cglm/clipspace/view_rh_zo.h @@ -0,0 +1,74 @@ +/* + * 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_lookat_rh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_rh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup_rh_zo(vec3 eye, vec3 dir, mat4 dest) + */ + +#ifndef cglm_view_rh_zo_h +#define cglm_view_rh_zo_h + +#include "../common.h" +#include "view_rh.h" + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat_rh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_rh(eye, center, up, dest); +} + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_rh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_rh(eye, dir, up, dest); +} + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * 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 + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup_rh_zo(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_rh(eye, dir, dest); +} + +#endif /*cglm_view_rh_zo_h*/ diff --git a/libs/cglm/include/cglm/color.h b/libs/cglm/include/cglm/color.h new file mode 100644 index 0000000..69566ad --- /dev/null +++ b/libs/cglm/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/libs/cglm/include/cglm/common.h b/libs/cglm/include/cglm/common.h new file mode 100644 index 0000000..261c9d7 --- /dev/null +++ b/libs/cglm/include/cglm/common.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_common_h +#define cglm_common_h + +#ifndef _USE_MATH_DEFINES +# define _USE_MATH_DEFINES /* for windows */ +#endif + +#ifndef _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS /* for windows */ +#endif + +#include +#include +#include +#include +#include + +#if defined(_MSC_VER) +# ifdef CGLM_STATIC +# define CGLM_EXPORT +# elif defined(CGLM_EXPORTS) +# define CGLM_EXPORT __declspec(dllexport) +# else +# define CGLM_EXPORT __declspec(dllimport) +# endif +# define CGLM_INLINE __forceinline +#else +# define CGLM_EXPORT __attribute__((visibility("default"))) +# define CGLM_INLINE static inline __attribute((always_inline)) +#endif + +#define GLM_SHUFFLE4(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2) | (w)) +#define GLM_SHUFFLE3(z, y, x) (((z) << 4) | ((y) << 2) | (x)) + +#include "types.h" +#include "simd/intrin.h" + +#ifndef CGLM_USE_DEFAULT_EPSILON +# ifndef GLM_FLT_EPSILON +# define GLM_FLT_EPSILON 1e-5 +# endif +#else +# define GLM_FLT_EPSILON FLT_EPSILON +#endif + +/* + * Clip control: define GLM_FORCE_DEPTH_ZERO_TO_ONE before including + * CGLM to use a clip space between 0 to 1. + * Coordinate system: define GLM_FORCE_LEFT_HANDED before including + * CGLM to use the left handed coordinate system by default. + */ + +#define CGLM_CLIP_CONTROL_ZO_BIT (1 << 0) /* ZERO_TO_ONE */ +#define CGLM_CLIP_CONTROL_NO_BIT (1 << 1) /* NEGATIVE_ONE_TO_ONE */ +#define CGLM_CLIP_CONTROL_LH_BIT (1 << 2) /* LEFT_HANDED, For DirectX, Metal, Vulkan */ +#define CGLM_CLIP_CONTROL_RH_BIT (1 << 3) /* RIGHT_HANDED, For OpenGL, default in GLM */ + +#define CGLM_CLIP_CONTROL_LH_ZO (CGLM_CLIP_CONTROL_LH_BIT | CGLM_CLIP_CONTROL_ZO_BIT) +#define CGLM_CLIP_CONTROL_LH_NO (CGLM_CLIP_CONTROL_LH_BIT | CGLM_CLIP_CONTROL_NO_BIT) +#define CGLM_CLIP_CONTROL_RH_ZO (CGLM_CLIP_CONTROL_RH_BIT | CGLM_CLIP_CONTROL_ZO_BIT) +#define CGLM_CLIP_CONTROL_RH_NO (CGLM_CLIP_CONTROL_RH_BIT | CGLM_CLIP_CONTROL_NO_BIT) + +#ifdef CGLM_FORCE_DEPTH_ZERO_TO_ONE +# ifdef CGLM_FORCE_LEFT_HANDED +# define CGLM_CONFIG_CLIP_CONTROL CGLM_CLIP_CONTROL_LH_ZO +# else +# define CGLM_CONFIG_CLIP_CONTROL CGLM_CLIP_CONTROL_RH_ZO +# endif +#else +# ifdef CGLM_FORCE_LEFT_HANDED +# define CGLM_CONFIG_CLIP_CONTROL CGLM_CLIP_CONTROL_LH_NO +# else +# define CGLM_CONFIG_CLIP_CONTROL CGLM_CLIP_CONTROL_RH_NO +# endif +#endif + +#endif /* cglm_common_h */ diff --git a/libs/cglm/include/cglm/curve.h b/libs/cglm/include/cglm/curve.h new file mode 100644 index 0000000..5033be5 --- /dev/null +++ b/libs/cglm/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/libs/cglm/include/cglm/ease.h b/libs/cglm/include/cglm/ease.h new file mode 100644 index 0000000..b40b75e --- /dev/null +++ b/libs/cglm/include/cglm/ease.h @@ -0,0 +1,317 @@ +/* + * 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) * GLM_PI_2f) + 1.0f; +} + +CGLM_INLINE +float +glm_ease_sine_out(float t) { + return sinf(t * GLM_PI_2f); +} + +CGLM_INLINE +float +glm_ease_sine_inout(float t) { + return 0.5f * (1.0f - cosf(t * GLM_PIf)); +} + +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 * t; + } + + 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) { + if (t == 0.0f) + return t; + + return powf(2.0f, 10.0f * (t - 1.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.0f || t == 1.0f) + return 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.0f) { + z = (s + 1) * n - s; + m = n * n * z; + return x * m; + } + + n -= 2.0f; + z = (s + 1.0f) * n + s; + m = (n * n * z) + 2; + + return x * m; +} + +CGLM_INLINE +float +glm_ease_elast_in(float t) { + 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 * GLM_PI_2f * (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 * GLM_PI_2f * a) + * powf(2.0f, 10.0f * (a - 1.0f)); + + return 0.5f * (sinf(-13.0f * GLM_PI_2f * a) + * 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/libs/cglm/include/cglm/euler.h b/libs/cglm/include/cglm/euler.h new file mode 100644 index 0000000..725a205 --- /dev/null +++ b/libs/cglm/include/cglm/euler.h @@ -0,0 +1,451 @@ +/* + * 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_seq + + Functions: + CGLM_INLINE glm_euler_seq 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); + 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_seq ord, + mat4 dest); + */ + +#ifndef cglm_euler_h +#define cglm_euler_h + +#include "common.h" + +/*! + * if you have axis order like vec3 orderVec = [0, 1, 2] or [0, 2, 1]... + * vector then you can convert it to this enum by doing this: + * @code + * glm_euler_seq order; + * order = orderVec[0] | orderVec[1] << 2 | orderVec[2] << 4; + * @endcode + * you may need to explicit cast if required + */ +typedef enum glm_euler_seq { + GLM_EULER_XYZ = 0 << 0 | 1 << 2 | 2 << 4, + GLM_EULER_XZY = 0 << 0 | 2 << 2 | 1 << 4, + GLM_EULER_YZX = 1 << 0 | 2 << 2 | 0 << 4, + GLM_EULER_YXZ = 1 << 0 | 0 << 2 | 2 << 4, + GLM_EULER_ZXY = 2 << 0 | 0 << 2 | 1 << 4, + GLM_EULER_ZYX = 2 << 0 | 1 << 2 | 0 << 4 +} glm_euler_seq; + +CGLM_INLINE +glm_euler_seq +glm_euler_order(int ord[3]) { + return (glm_euler_seq)(ord[0] << 0 | ord[1] << 2 | ord[2] << 4); +} + +/*! + * @brief extract euler angles (in radians) using xyz order + * + * @param[in] m affine transform + * @param[out] dest angles vector [x, y, z] + */ +CGLM_INLINE +void +glm_euler_angles(mat4 m, vec3 dest) { + float m00, m01, m10, m11, m20, m21, m22; + float thetaX, thetaY, thetaZ; + + 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]; + + 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 */ + thetaY = -GLM_PI_2f; + thetaX = -atan2f(m01, m11); + thetaZ = 0.0f; + } + } else { /* m20 == +1 */ + thetaY = GLM_PI_2f; + thetaX = atan2f(m01, m11); + thetaZ = 0.0f; + } + + dest[0] = thetaX; + dest[1] = thetaY; + dest[2] = thetaZ; +} + +/*! + * @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_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) { + glm_euler_xyz(angles, dest); +} + +/*! + * @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_xzy(vec3 angles, mat4 dest) { + float cx, cy, cz, + 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]); + + 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 [Xangle, Yangle, Zangle] + * @param[out] dest rotation matrix + */ +CGLM_INLINE +void +glm_euler_yxz(vec3 angles, mat4 dest) { + float cx, cy, cz, + 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]); + + 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 [Xangle, Yangle, Zangle] + * @param[out] dest rotation matrix + */ +CGLM_INLINE +void +glm_euler_yzx(vec3 angles, mat4 dest) { + float cx, cy, cz, + 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]); + + 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 [Xangle, Yangle, Zangle] + * @param[out] dest rotation matrix + */ +CGLM_INLINE +void +glm_euler_zxy(vec3 angles, mat4 dest) { + float cx, cy, cz, + 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]); + + 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 [Xangle, Yangle, Zangle] + * @param[out] dest rotation matrix + */ +CGLM_INLINE +void +glm_euler_zyx(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] = 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 [Xangle, Yangle, Zangle] + * @param[in] ord euler order + * @param[out] dest rotation matrix + */ +CGLM_INLINE +void +glm_euler_by_order(vec3 angles, glm_euler_seq ord, mat4 dest) { + float cx, cy, cz, + sx, sy, sz; + + float cycz, cysz, cysx, cxcy, + czsy, cxcz, czsx, cxsz, + 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]); + + cycz = cy * cz; cysz = cy * sz; + cysx = cy * sx; cxcy = cx * cy; + czsy = cz * sy; cxcz = cx * cz; + czsx = cz * sx; cxsz = cx * sz; + sysz = sy * sz; + + switch (ord) { + case GLM_EULER_XZY: + 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_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] = 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] = 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; + } + + 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; +} + +#endif /* cglm_euler_h */ diff --git a/libs/cglm/include/cglm/frustum.h b/libs/cglm/include/cglm/frustum.h new file mode 100644 index 0000000..5aa3c17 --- /dev/null +++ b/libs/cglm/include/cglm/frustum.h @@ -0,0 +1,255 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_frustum_h +#define cglm_frustum_h + +#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 */ +#define GLM_RTN 2 /* right top near */ +#define GLM_RBN 3 /* right bottom near */ + +#define GLM_LBF 4 /* left bottom far */ +#define GLM_LTF 5 /* left top far */ +#define GLM_RTF 6 /* right top far */ +#define GLM_RBF 7 /* right bottom far */ + +#define GLM_LEFT 0 +#define GLM_RIGHT 1 +#define GLM_BOTTOM 2 +#define GLM_TOP 3 +#define GLM_NEAR 4 +#define GLM_FAR 5 + +/* 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 GLM_CSCOORD_LBN {-1.0f, -1.0f, -1.0f, 1.0f} +#define GLM_CSCOORD_LTN {-1.0f, 1.0f, -1.0f, 1.0f} +#define GLM_CSCOORD_RTN { 1.0f, 1.0f, -1.0f, 1.0f} +#define GLM_CSCOORD_RBN { 1.0f, -1.0f, -1.0f, 1.0f} + +/* far */ +#define GLM_CSCOORD_LBF {-1.0f, -1.0f, 1.0f, 1.0f} +#define GLM_CSCOORD_LTF {-1.0f, 1.0f, 1.0f, 1.0f} +#define GLM_CSCOORD_RTF { 1.0f, 1.0f, 1.0f, 1.0f} +#define GLM_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 +glm_frustum_planes(mat4 m, vec4 dest[6]) { + mat4 t; + + glm_mat4_transpose_to(m, t); + + glm_vec4_add(t[3], t[0], dest[0]); /* left */ + glm_vec4_sub(t[3], t[0], dest[1]); /* right */ + glm_vec4_add(t[3], t[1], dest[2]); /* bottom */ + glm_vec4_sub(t[3], t[1], dest[3]); /* top */ + glm_vec4_add(t[3], t[2], dest[4]); /* near */ + glm_vec4_sub(t[3], t[2], dest[5]); /* far */ + + glm_plane_normalize(dest[0]); + glm_plane_normalize(dest[1]); + glm_plane_normalize(dest[2]); + glm_plane_normalize(dest[3]); + glm_plane_normalize(dest[4]); + glm_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 +glm_frustum_corners(mat4 invMat, vec4 dest[8]) { + vec4 c[8]; + + /* indexOf(nearCoord) = indexOf(farCoord) + 4 */ + vec4 csCoords[8] = { + GLM_CSCOORD_LBN, + GLM_CSCOORD_LTN, + GLM_CSCOORD_RTN, + GLM_CSCOORD_RBN, + + GLM_CSCOORD_LBF, + GLM_CSCOORD_LTF, + GLM_CSCOORD_RTF, + GLM_CSCOORD_RBF + }; + + glm_mat4_mulv(invMat, csCoords[0], c[0]); + glm_mat4_mulv(invMat, csCoords[1], c[1]); + glm_mat4_mulv(invMat, csCoords[2], c[2]); + glm_mat4_mulv(invMat, csCoords[3], c[3]); + glm_mat4_mulv(invMat, csCoords[4], c[4]); + glm_mat4_mulv(invMat, csCoords[5], c[5]); + glm_mat4_mulv(invMat, csCoords[6], c[6]); + glm_mat4_mulv(invMat, csCoords[7], c[7]); + + glm_vec4_scale(c[0], 1.0f / c[0][3], dest[0]); + glm_vec4_scale(c[1], 1.0f / c[1][3], dest[1]); + glm_vec4_scale(c[2], 1.0f / c[2][3], dest[2]); + glm_vec4_scale(c[3], 1.0f / c[3][3], dest[3]); + glm_vec4_scale(c[4], 1.0f / c[4][3], dest[4]); + glm_vec4_scale(c[5], 1.0f / c[5][3], dest[5]); + glm_vec4_scale(c[6], 1.0f / c[6][3], dest[6]); + glm_vec4_scale(c[7], 1.0f / c[7][3], dest[7]); +} + +/*! + * @brief finds center of view frustum + * + * @param[in] corners view frustum corners + * @param[out] dest view frustum center + */ +CGLM_INLINE +void +glm_frustum_center(vec4 corners[8], vec4 dest) { + vec4 center; + + glm_vec4_copy(corners[0], center); + + glm_vec4_add(corners[1], center, center); + glm_vec4_add(corners[2], center, center); + glm_vec4_add(corners[3], center, center); + glm_vec4_add(corners[4], center, center); + glm_vec4_add(corners[5], center, center); + glm_vec4_add(corners[6], center, center); + glm_vec4_add(corners[7], center, center); + + glm_vec4_scale(center, 0.125f, dest); +} + +/*! + * @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 +glm_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) { + vec4 v; + vec3 min, max; + int i; + + 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); + + min[0] = glm_min(min[0], v[0]); + min[1] = glm_min(min[1], v[1]); + min[2] = glm_min(min[2], v[2]); + + max[0] = glm_max(max[0], v[0]); + max[1] = glm_max(max[1], v[1]); + max[2] = glm_max(max[2], v[2]); + } + + glm_vec3_copy(min, box[0]); + glm_vec3_copy(max, box[1]); +} + +/*! + * @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 +glm_frustum_corners_at(vec4 corners[8], + float splitDist, + float farDist, + vec4 planeCorners[4]) { + vec4 corner; + float dist, sc; + + /* because distance and scale is same for all */ + dist = glm_vec3_distance(corners[GLM_RTF], corners[GLM_RTN]); + sc = dist * (splitDist / farDist); + + /* left bottom */ + glm_vec4_sub(corners[GLM_LBF], corners[GLM_LBN], corner); + glm_vec4_scale_as(corner, sc, corner); + glm_vec4_add(corners[GLM_LBN], corner, planeCorners[0]); + + /* left top */ + glm_vec4_sub(corners[GLM_LTF], corners[GLM_LTN], corner); + glm_vec4_scale_as(corner, sc, corner); + glm_vec4_add(corners[GLM_LTN], corner, planeCorners[1]); + + /* right top */ + glm_vec4_sub(corners[GLM_RTF], corners[GLM_RTN], corner); + glm_vec4_scale_as(corner, sc, corner); + glm_vec4_add(corners[GLM_RTN], corner, planeCorners[2]); + + /* right bottom */ + glm_vec4_sub(corners[GLM_RBF], corners[GLM_RBN], corner); + glm_vec4_scale_as(corner, sc, corner); + glm_vec4_add(corners[GLM_RBN], corner, planeCorners[3]); +} + +#endif /* cglm_frustum_h */ diff --git a/libs/cglm/include/cglm/io.h b/libs/cglm/include/cglm/io.h new file mode 100644 index 0000000..f625791 --- /dev/null +++ b/libs/cglm/include/cglm/io.h @@ -0,0 +1,344 @@ +/* + * 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); + */ + +/* + cglm tried to enable print functions in debug mode and disable them in + release/production mode to eliminate printing costs. + + if you need to force enable then define CGLM_DEFINE_PRINTS macro not DEBUG one + + Print functions are enabled if: + + - DEBUG or _DEBUG macro is defined (mostly defined automatically in debugging) + - CGLM_DEFINE_PRINTS macro is defined including release/production + which makes enabled printing always + - glmc_ calls for io are always prints + + */ + +/* DEPRECATED: CGLM_NO_PRINTS_NOOP (use CGLM_DEFINE_PRINTS) */ + +#ifndef cglm_io_h +#define cglm_io_h +#if defined(DEBUG) || defined(_DEBUG) \ + || defined(CGLM_DEFINE_PRINTS) || defined(CGLM_LIB_SRC) \ + || defined(CGLM_NO_PRINTS_NOOP) + +#include "common.h" + +#include +#include + +#ifndef CGLM_PRINT_PRECISION +# define CGLM_PRINT_PRECISION 5 +#endif + +#ifndef CGLM_PRINT_MAX_TO_SHORT +# define CGLM_PRINT_MAX_TO_SHORT 1e5 +#endif + +#ifndef CGLM_PRINT_COLOR +# define CGLM_PRINT_COLOR "\033[36m" +#endif + +#ifndef CGLM_PRINT_COLOR_RESET +# define CGLM_PRINT_COLOR_RESET "\033[0m" +#endif + +CGLM_INLINE +void +glm_mat4_print(mat4 matrix, + FILE * __restrict ostream) { + char buff[16]; + int i, j, cw[4], cwi; + +#define m 4 +#define n 4 + + fprintf(ostream, "Matrix (float%dx%d): " CGLM_PRINT_COLOR "\n" , m, n); + + cw[0] = cw[1] = cw[2] = cw[3] = 0; + + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { + if (matrix[i][j] < CGLM_PRINT_MAX_TO_SHORT) + cwi = sprintf(buff, "% .*f", CGLM_PRINT_PRECISION, matrix[i][j]); + else + cwi = sprintf(buff, "% g", matrix[i][j]); + cw[i] = GLM_MAX(cw[i], cwi); + } + } + + for (i = 0; i < m; i++) { + fprintf(ostream, " |"); + + for (j = 0; j < n; j++) + if (matrix[i][j] < CGLM_PRINT_MAX_TO_SHORT) + fprintf(ostream, " % *.*f", cw[j], CGLM_PRINT_PRECISION, matrix[j][i]); + else + fprintf(ostream, " % *g", cw[j], matrix[j][i]); + + fprintf(ostream, " |\n"); + } + + fprintf(ostream, CGLM_PRINT_COLOR_RESET "\n"); + +#undef m +#undef n +} + + +CGLM_INLINE +void +glm_mat3_print(mat3 matrix, + FILE * __restrict ostream) { + char buff[16]; + int i, j, cw[4], cwi; + +#define m 3 +#define n 3 + + fprintf(ostream, "Matrix (float%dx%d): " CGLM_PRINT_COLOR "\n", m, n); + + cw[0] = cw[1] = cw[2] = 0; + + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { + if (matrix[i][j] < CGLM_PRINT_MAX_TO_SHORT) + cwi = sprintf(buff, "% .*f", CGLM_PRINT_PRECISION, matrix[i][j]); + else + cwi = sprintf(buff, "% g", matrix[i][j]); + cw[i] = GLM_MAX(cw[i], cwi); + } + } + + for (i = 0; i < m; i++) { + fprintf(ostream, " |"); + + for (j = 0; j < n; j++) + if (matrix[i][j] < CGLM_PRINT_MAX_TO_SHORT) + fprintf(ostream, " % *.*f", cw[j], CGLM_PRINT_PRECISION, matrix[j][i]); + else + fprintf(ostream, " % *g", cw[j], matrix[j][i]); + + fprintf(ostream, " |\n"); + } + + fprintf(ostream, CGLM_PRINT_COLOR_RESET "\n"); + +#undef m +#undef n +} + +CGLM_INLINE +void +glm_mat2_print(mat2 matrix, + FILE * __restrict ostream) { + char buff[16]; + int i, j, cw[4], cwi; + +#define m 2 +#define n 2 + + fprintf(ostream, "Matrix (float%dx%d): " CGLM_PRINT_COLOR "\n", m, n); + + cw[0] = cw[1] = 0; + + for (i = 0; i < m; i++) { + for (j = 0; j < n; j++) { + if (matrix[i][j] < CGLM_PRINT_MAX_TO_SHORT) + cwi = sprintf(buff, "% .*f", CGLM_PRINT_PRECISION, matrix[i][j]); + else + cwi = sprintf(buff, "% g", matrix[i][j]); + cw[i] = GLM_MAX(cw[i], cwi); + } + } + + for (i = 0; i < m; i++) { + fprintf(ostream, " |"); + + for (j = 0; j < n; j++) + if (matrix[i][j] < CGLM_PRINT_MAX_TO_SHORT) + fprintf(ostream, " % *.*f", cw[j], CGLM_PRINT_PRECISION, matrix[j][i]); + else + fprintf(ostream, " % *g", cw[j], matrix[j][i]); + + fprintf(ostream, " |\n"); + } + + fprintf(ostream, CGLM_PRINT_COLOR_RESET "\n"); + +#undef m +#undef n +} + +CGLM_INLINE +void +glm_vec4_print(vec4 vec, + FILE * __restrict ostream) { + int i; + +#define m 4 + + fprintf(ostream, "Vector (float%d): " CGLM_PRINT_COLOR "\n (", m); + + for (i = 0; i < m; i++) { + if (vec[i] < CGLM_PRINT_MAX_TO_SHORT) + fprintf(ostream, " % .*f", CGLM_PRINT_PRECISION, vec[i]); + else + fprintf(ostream, " % g", vec[i]); + } + + fprintf(ostream, " )" CGLM_PRINT_COLOR_RESET "\n\n"); + +#undef m +} + +CGLM_INLINE +void +glm_vec3_print(vec3 vec, + FILE * __restrict ostream) { + int i; + +#define m 3 + + fprintf(ostream, "Vector (float%d): " CGLM_PRINT_COLOR "\n (", m); + + for (i = 0; i < m; i++) { + if (vec[i] < CGLM_PRINT_MAX_TO_SHORT) + fprintf(ostream, " % .*f", CGLM_PRINT_PRECISION, vec[i]); + else + fprintf(ostream, " % g", vec[i]); + } + + fprintf(ostream, " )" CGLM_PRINT_COLOR_RESET "\n\n"); + +#undef m +} + +CGLM_INLINE +void +glm_ivec3_print(ivec3 vec, + FILE * __restrict ostream) { + int i; + +#define m 3 + + fprintf(ostream, "Vector (int%d): " CGLM_PRINT_COLOR "\n (", m); + + for (i = 0; i < m; i++) + fprintf(ostream, " % d", vec[i]); + + fprintf(ostream, " )" CGLM_PRINT_COLOR_RESET "\n\n"); + +#undef m +} + +CGLM_INLINE +void +glm_vec2_print(vec2 vec, + FILE * __restrict ostream) { + int i; + +#define m 2 + + fprintf(ostream, "Vector (float%d): " CGLM_PRINT_COLOR "\n (", m); + + for (i = 0; i < m; i++) { + if (vec[i] < CGLM_PRINT_MAX_TO_SHORT) + fprintf(ostream, " % .*f", CGLM_PRINT_PRECISION, vec[i]); + else + fprintf(ostream, " % g", vec[i]); + } + + fprintf(ostream, " )" CGLM_PRINT_COLOR_RESET "\n\n"); + +#undef m +} + +CGLM_INLINE +void +glm_versor_print(versor vec, + FILE * __restrict ostream) { + int i; + +#define m 4 + + fprintf(ostream, "Quaternion (float%d): " CGLM_PRINT_COLOR "\n (", m); + + for (i = 0; i < m; i++) { + if (vec[i] < CGLM_PRINT_MAX_TO_SHORT) + fprintf(ostream, " % .*f", CGLM_PRINT_PRECISION, vec[i]); + else + fprintf(ostream, " % g", vec[i]); + } + + + fprintf(ostream, " )" CGLM_PRINT_COLOR_RESET "\n\n"); + +#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): " CGLM_PRINT_COLOR "\n", tag ? tag: "float"); + + for (i = 0; i < 2; i++) { + fprintf(ostream, " ("); + + for (j = 0; j < m; j++) { + if (bbox[i][j] < CGLM_PRINT_MAX_TO_SHORT) + fprintf(ostream, " % .*f", CGLM_PRINT_PRECISION, bbox[i][j]); + else + fprintf(ostream, " % g", bbox[i][j]); + } + + fprintf(ostream, " )\n"); + } + + fprintf(ostream, CGLM_PRINT_COLOR_RESET "\n"); + +#undef m +} + +#else + +#include "common.h" + +#include +#include + +/* NOOP: Remove print from DEBUG */ +#define glm_mat4_print(v, s) (void)v; (void)s; +#define glm_mat3_print(v, s) (void)v; (void)s; +#define glm_mat2_print(v, s) (void)v; (void)s; +#define glm_vec4_print(v, s) (void)v; (void)s; +#define glm_vec3_print(v, s) (void)v; (void)s; +#define glm_ivec3_print(v, s) (void)v; (void)s; +#define glm_vec2_print(v, s) (void)v; (void)s; +#define glm_versor_print(v, s) (void)v; (void)s; +#define glm_aabb_print(v, t, s) (void)v; (void)t; (void)s; + +#endif +#endif /* cglm_io_h */ diff --git a/libs/cglm/include/cglm/ivec2.h b/libs/cglm/include/cglm/ivec2.h new file mode 100644 index 0000000..c1209a9 --- /dev/null +++ b/libs/cglm/include/cglm/ivec2.h @@ -0,0 +1,242 @@ +/* + * 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_ivec2(int * __restrict v, ivec2 dest) + CGLM_INLINE void glm_ivec2_copy(ivec2 a, ivec2 dest) + CGLM_INLINE void glm_ivec2_zero(ivec2 v) + CGLM_INLINE void glm_ivec2_one(ivec2 v) + CGLM_INLINE void glm_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_adds(ivec2 v, int s, ivec2 dest) + CGLM_INLINE void glm_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_subs(ivec2 v, int s, ivec2 dest) + CGLM_INLINE void glm_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_scale(ivec2 v, int s, ivec2 dest) + CGLM_INLINE int glm_ivec2_distance2(ivec2 a, ivec2 b) + CGLM_INLINE float glm_ivec2_distance(ivec2 a, ivec2 b) + CGLM_INLINE void glm_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest) + CGLM_INLINE void glm_ivec2_clamp(ivec2 v, int minVal, int maxVal) + */ + +#ifndef cglm_ivec2_h +#define cglm_ivec2_h + +#include "common.h" + +/*! + * @brief init ivec2 using vec3 or vec4 + * + * @param[in] v vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec2(int * __restrict v, ivec2 dest) { + dest[0] = v[0]; + dest[1] = v[1]; +} + +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] a source vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec2_copy(ivec2 a, ivec2 dest) { + dest[0] = a[0]; + dest[1] = a[1]; +} + +/*! + * @brief set all members of [v] to zero + * + * @param[out] v vector + */ +CGLM_INLINE +void +glm_ivec2_zero(ivec2 v) { + v[0] = v[1] = 0; +} + +/*! + * @brief set all members of [v] to one + * + * @param[out] v vector + */ +CGLM_INLINE +void +glm_ivec2_one(ivec2 v) { + v[0] = v[1] = 1; +} + +/*! + * @brief add vector [a] to vector [b] and store result in [dest] + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] = a[0] + b[0]; + dest[1] = a[1] + b[1]; +} + +/*! + * @brief add scalar s to vector [v] and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec2_adds(ivec2 v, int s, ivec2 dest) { + dest[0] = v[0] + s; + dest[1] = v[1] + s; +} + +/*! + * @brief subtract vector [b] from vector [a] and store result in [dest] + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] = a[0] - b[0]; + dest[1] = a[1] - b[1]; +} + +/*! + * @brief subtract scalar s from vector [v] and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec2_subs(ivec2 v, int s, ivec2 dest) { + dest[0] = v[0] - s; + dest[1] = v[1] - s; +} + +/*! + * @brief multiply vector [a] with vector [b] and store result in [dest] + * + * @param[in] a frist vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] = a[0] * b[0]; + dest[1] = a[1] * b[1]; +} + +/*! + * @brief multiply vector [a] with scalar s and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec2_scale(ivec2 v, int s, ivec2 dest) { + dest[0] = v[0] * s; + dest[1] = v[1] * s; +} + +/*! + * @brief squared distance between two vectors + * + * @param[in] a first vector + * @param[in] b second vector + * @return returns squared distance (distance * distance) + */ +CGLM_INLINE +int +glm_ivec2_distance2(ivec2 a, ivec2 b) { + int xd, yd; + xd = a[0] - b[0]; + yd = a[1] - b[1]; + return xd * xd + yd * yd; +} + +/*! + * @brief distance between two vectors + * + * @param[in] a first vector + * @param[in] b second vector + * @return returns distance + */ +CGLM_INLINE +float +glm_ivec2_distance(ivec2 a, ivec2 b) { + return sqrtf((float)glm_ivec2_distance2(a, b)); +} + +/*! + * @brief set each member of dest to greater of vector a and b + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] = a[0] > b[0] ? a[0] : b[0]; + dest[1] = a[1] > b[1] ? a[1] : b[1]; +} + +/*! + * @brief set each member of dest to lesser of vector a and b + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest) { + dest[0] = a[0] < b[0] ? a[0] : b[0]; + dest[1] = a[1] < b[1] ? a[1] : b[1]; +} + +/*! + * @brief clamp each member of [v] between minVal and maxVal (inclusive) + * + * @param[in, out] v vector + * @param[in] minVal minimum value + * @param[in] maxVal maximum value + */ +CGLM_INLINE +void +glm_ivec2_clamp(ivec2 v, int minVal, int maxVal) { + if (v[0] < minVal) + v[0] = minVal; + else if(v[0] > maxVal) + v[0] = maxVal; + + if (v[1] < minVal) + v[1] = minVal; + else if(v[1] > maxVal) + v[1] = maxVal; +} + +#endif /* cglm_ivec2_h */ diff --git a/libs/cglm/include/cglm/ivec3.h b/libs/cglm/include/cglm/ivec3.h new file mode 100644 index 0000000..69f27f3 --- /dev/null +++ b/libs/cglm/include/cglm/ivec3.h @@ -0,0 +1,258 @@ +/* + * 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_ivec3(ivec4 v4, ivec3 dest) + CGLM_INLINE void glm_ivec3_copy(ivec3 a, ivec3 dest) + CGLM_INLINE void glm_ivec3_zero(ivec3 v) + CGLM_INLINE void glm_ivec3_one(ivec3 v) + CGLM_INLINE void glm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_adds(ivec3 v, int s, ivec3 dest) + CGLM_INLINE void glm_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_subs(ivec3 v, int s, ivec3 dest) + CGLM_INLINE void glm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_scale(ivec3 v, int s, ivec3 dest) + CGLM_INLINE int glm_ivec3_distance2(ivec3 a, ivec3 b) + CGLM_INLINE float glm_ivec3_distance(ivec3 a, ivec3 b) + CGLM_INLINE void glm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest) + CGLM_INLINE void glm_ivec3_clamp(ivec3 v, int minVal, int maxVal) + */ + +#ifndef cglm_ivec3_h +#define cglm_ivec3_h + +#include "common.h" + +/*! + * @brief init ivec3 using ivec4 + * + * @param[in] v4 vector4 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec3(ivec4 v4, ivec3 dest) { + dest[0] = v4[0]; + dest[1] = v4[1]; + dest[2] = v4[2]; +} + +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] a source vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec3_copy(ivec3 a, ivec3 dest) { + dest[0] = a[0]; + dest[1] = a[1]; + dest[2] = a[2]; +} + +/*! + * @brief set all members of [v] to zero + * + * @param[out] v vector + */ +CGLM_INLINE +void +glm_ivec3_zero(ivec3 v) { + v[0] = v[1] = v[2] = 0; +} + +/*! + * @brief set all members of [v] to one + * + * @param[out] v vector + */ +CGLM_INLINE +void +glm_ivec3_one(ivec3 v) { + v[0] = v[1] = v[2] = 1; +} + +/*! + * @brief add vector [a] to vector [b] and store result in [dest] + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] = a[0] + b[0]; + dest[1] = a[1] + b[1]; + dest[2] = a[2] + b[2]; +} + +/*! + * @brief add scalar s to vector [v] and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec3_adds(ivec3 v, int s, ivec3 dest) { + dest[0] = v[0] + s; + dest[1] = v[1] + s; + dest[2] = v[2] + s; +} + +/*! + * @brief subtract vector [b] from vector [a] and store result in [dest] + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] = a[0] - b[0]; + dest[1] = a[1] - b[1]; + dest[2] = a[2] - b[2]; +} + +/*! + * @brief subtract scalar s from vector [v] and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec3_subs(ivec3 v, int s, ivec3 dest) { + dest[0] = v[0] - s; + dest[1] = v[1] - s; + dest[2] = v[2] - s; +} + +/*! + * @brief multiply vector [a] with vector [b] and store result in [dest] + * + * @param[in] a frist vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] = a[0] * b[0]; + dest[1] = a[1] * b[1]; + dest[2] = a[2] * b[2]; +} + +/*! + * @brief multiply vector [a] with scalar s and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec3_scale(ivec3 v, int s, ivec3 dest) { + dest[0] = v[0] * s; + dest[1] = v[1] * s; + dest[2] = v[2] * s; +} + +/*! + * @brief squared distance between two vectors + * + * @param[in] a first vector + * @param[in] b second vector + * @return returns squared distance (distance * distance) + */ +CGLM_INLINE +int +glm_ivec3_distance2(ivec3 a, ivec3 b) { + int xd, yd, zd; + xd = a[0] - b[0]; + yd = a[1] - b[1]; + zd = a[2] - b[2]; + return xd * xd + yd * yd + zd * zd; +} + +/*! + * @brief distance between two vectors + * + * @param[in] a first vector + * @param[in] b second vector + * @return returns distance + */ +CGLM_INLINE +float +glm_ivec3_distance(ivec3 a, ivec3 b) { + return sqrtf((float)glm_ivec3_distance2(a, b)); +} + +/*! + * @brief set each member of dest to greater of vector a and b + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] = a[0] > b[0] ? a[0] : b[0]; + dest[1] = a[1] > b[1] ? a[1] : b[1]; + dest[2] = a[2] > b[2] ? a[2] : b[2]; +} + +/*! + * @brief set each member of dest to lesser of vector a and b + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest) { + dest[0] = a[0] < b[0] ? a[0] : b[0]; + dest[1] = a[1] < b[1] ? a[1] : b[1]; + dest[2] = a[2] < b[2] ? a[2] : b[2]; +} + +/*! + * @brief clamp each member of [v] between minVal and maxVal (inclusive) + * + * @param[in, out] v vector + * @param[in] minVal minimum value + * @param[in] maxVal maximum value + */ +CGLM_INLINE +void +glm_ivec3_clamp(ivec3 v, int minVal, int maxVal) { + if (v[0] < minVal) + v[0] = minVal; + else if(v[0] > maxVal) + v[0] = maxVal; + + if (v[1] < minVal) + v[1] = minVal; + else if(v[1] > maxVal) + v[1] = maxVal; + + if (v[2] < minVal) + v[2] = minVal; + else if(v[2] > maxVal) + v[2] = maxVal; +} + +#endif /* cglm_ivec3_h */ diff --git a/libs/cglm/include/cglm/ivec4.h b/libs/cglm/include/cglm/ivec4.h new file mode 100644 index 0000000..363ee58 --- /dev/null +++ b/libs/cglm/include/cglm/ivec4.h @@ -0,0 +1,275 @@ +/* + * 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_ivec4(ivec3 v3, int last, ivec4 dest) + CGLM_INLINE void glm_ivec4_copy(ivec4 a, ivec4 dest) + CGLM_INLINE void glm_ivec4_zero(ivec4 v) + CGLM_INLINE void glm_ivec4_one(ivec4 v) + CGLM_INLINE void glm_ivec4_add(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_adds(ivec4 v, int s, ivec4 dest) + CGLM_INLINE void glm_ivec4_sub(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_subs(ivec4 v, int s, ivec4 dest) + CGLM_INLINE void glm_ivec4_mul(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_scale(ivec4 v, int s, ivec4 dest) + CGLM_INLINE int glm_ivec4_distance2(ivec4 a, ivec4 b) + CGLM_INLINE float glm_ivec4_distance(ivec4 a, ivec4 b) + CGLM_INLINE void glm_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest) + CGLM_INLINE void glm_ivec4_clamp(ivec4 v, int minVal, int maxVal) + */ + +#ifndef cglm_ivec4_h +#define cglm_ivec4_h + +#include "common.h" + +/*! + * @brief init ivec4 using ivec3 + * + * @param[in] v3 vector3 + * @param[in] last last item + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec4(ivec3 v3, int last, ivec4 dest) { + dest[0] = v3[0]; + dest[1] = v3[1]; + dest[2] = v3[2]; + dest[3] = last; +} + +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] a source vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec4_copy(ivec4 a, ivec4 dest) { + dest[0] = a[0]; + dest[1] = a[1]; + dest[2] = a[2]; + dest[3] = a[3]; +} + +/*! + * @brief set all members of [v] to zero + * + * @param[out] v vector + */ +CGLM_INLINE +void +glm_ivec4_zero(ivec4 v) { + v[0] = v[1] = v[2] = v[3] = 0; +} + +/*! + * @brief set all members of [v] to one + * + * @param[out] v vector + */ +CGLM_INLINE +void +glm_ivec4_one(ivec4 v) { + v[0] = v[1] = v[2] = v[3] = 1; +} + +/*! + * @brief add vector [a] to vector [b] and store result in [dest] + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec4_add(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] = a[0] + b[0]; + dest[1] = a[1] + b[1]; + dest[2] = a[2] + b[2]; + dest[3] = a[3] + b[3]; +} + +/*! + * @brief add scalar s to vector [v] and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec4_adds(ivec4 v, int s, ivec4 dest) { + dest[0] = v[0] + s; + dest[1] = v[1] + s; + dest[2] = v[2] + s; + dest[3] = v[3] + s; +} + +/*! + * @brief subtract vector [b] from vector [a] and store result in [dest] + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec4_sub(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] = a[0] - b[0]; + dest[1] = a[1] - b[1]; + dest[2] = a[2] - b[2]; + dest[3] = a[3] - b[3]; +} + +/*! + * @brief subtract scalar s from vector [v] and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec4_subs(ivec4 v, int s, ivec4 dest) { + dest[0] = v[0] - s; + dest[1] = v[1] - s; + dest[2] = v[2] - s; + dest[3] = v[3] - s; +} + +/*! + * @brief multiply vector [a] with vector [b] and store result in [dest] + * + * @param[in] a frist vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec4_mul(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] = a[0] * b[0]; + dest[1] = a[1] * b[1]; + dest[2] = a[2] * b[2]; + dest[3] = a[3] * b[3]; +} + +/*! + * @brief multiply vector [a] with scalar s and store result in [dest] + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec4_scale(ivec4 v, int s, ivec4 dest) { + dest[0] = v[0] * s; + dest[1] = v[1] * s; + dest[2] = v[2] * s; + dest[3] = v[3] * s; +} + +/*! + * @brief squared distance between two vectors + * + * @param[in] a first vector + * @param[in] b second vector + * @return returns squared distance (distance * distance) + */ +CGLM_INLINE +int +glm_ivec4_distance2(ivec4 a, ivec4 b) { + int xd, yd, zd, wd; + xd = a[0] - b[0]; + yd = a[1] - b[1]; + zd = a[2] - b[2]; + wd = a[3] - b[3]; + return xd * xd + yd * yd + zd * zd + wd * wd; +} + +/*! + * @brief distance between two vectors + * + * @param[in] a first vector + * @param[in] b second vector + * @return returns distance + */ +CGLM_INLINE +float +glm_ivec4_distance(ivec4 a, ivec4 b) { + return sqrtf((float)glm_ivec4_distance2(a, b)); +} + +/*! + * @brief set each member of dest to greater of vector a and b + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] = a[0] > b[0] ? a[0] : b[0]; + dest[1] = a[1] > b[1] ? a[1] : b[1]; + dest[2] = a[2] > b[2] ? a[2] : b[2]; + dest[3] = a[3] > b[3] ? a[3] : b[3]; +} + +/*! + * @brief set each member of dest to lesser of vector a and b + * + * @param[in] a first vector + * @param[in] b second vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest) { + dest[0] = a[0] < b[0] ? a[0] : b[0]; + dest[1] = a[1] < b[1] ? a[1] : b[1]; + dest[2] = a[2] < b[2] ? a[2] : b[2]; + dest[3] = a[3] < b[3] ? a[3] : b[3]; +} + +/*! + * @brief clamp each member of [v] between minVal and maxVal (inclusive) + * + * @param[in, out] v vector + * @param[in] minVal minimum value + * @param[in] maxVal maximum value + */ +CGLM_INLINE +void +glm_ivec4_clamp(ivec4 v, int minVal, int maxVal) { + if (v[0] < minVal) + v[0] = minVal; + else if(v[0] > maxVal) + v[0] = maxVal; + + if (v[1] < minVal) + v[1] = minVal; + else if(v[1] > maxVal) + v[1] = maxVal; + + if (v[2] < minVal) + v[2] = minVal; + else if(v[2] > maxVal) + v[2] = maxVal; + + if (v[3] < minVal) + v[3] = minVal; + else if(v[3] > maxVal) + v[3] = maxVal; +} + +#endif /* cglm_ivec4_h */ diff --git a/libs/cglm/include/cglm/mat2.h b/libs/cglm/include/cglm/mat2.h new file mode 100644 index 0000000..871d6bd --- /dev/null +++ b/libs/cglm/include/cglm/mat2.h @@ -0,0 +1,337 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLM_MAT2_IDENTITY_INIT + GLM_MAT2_ZERO_INIT + GLM_MAT2_IDENTITY + GLM_MAT2_ZERO + + Functions: + CGLM_INLINE void glm_mat2_copy(mat2 mat, mat2 dest) + CGLM_INLINE void glm_mat2_identity(mat2 mat) + CGLM_INLINE void glm_mat2_identity_array(mat2 * restrict mat, size_t count) + CGLM_INLINE void glm_mat2_zero(mat2 mat) + CGLM_INLINE void glm_mat2_mul(mat2 m1, mat2 m2, mat2 dest) + CGLM_INLINE void glm_mat2_transpose_to(mat2 m, mat2 dest) + CGLM_INLINE void glm_mat2_transpose(mat2 m) + CGLM_INLINE void glm_mat2_mulv(mat2 m, vec2 v, vec2 dest) + CGLM_INLINE float glm_mat2_trace(mat2 m) + CGLM_INLINE void glm_mat2_scale(mat2 m, float s) + CGLM_INLINE float glm_mat2_det(mat2 mat) + CGLM_INLINE void glm_mat2_inv(mat2 mat, mat2 dest) + CGLM_INLINE void glm_mat2_swap_col(mat2 mat, int col1, int col2) + CGLM_INLINE void glm_mat2_swap_row(mat2 mat, int row1, int row2) + CGLM_INLINE float glm_mat2_rmc(vec2 r, mat2 m, vec2 c) + */ + +#ifndef cglm_mat2_h +#define cglm_mat2_h + +#include "common.h" +#include "vec2.h" + +#ifdef CGLM_SSE_FP +# include "simd/sse2/mat2.h" +#endif + +#ifdef CGLM_NEON_FP +# include "simd/neon/mat2.h" +#endif + +#define GLM_MAT2_IDENTITY_INIT {{1.0f, 0.0f}, {0.0f, 1.0f}} +#define GLM_MAT2_ZERO_INIT {{0.0f, 0.0f}, {0.0f, 0.0f}} + +/* for C only */ +#define GLM_MAT2_IDENTITY ((mat2)GLM_MAT2_IDENTITY_INIT) +#define GLM_MAT2_ZERO ((mat2)GLM_MAT2_ZERO_INIT) + +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_mat2_copy(mat2 mat, mat2 dest) { + glm_vec4_ucopy(mat[0], dest[0]); +} + +/*! + * @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_mat2_identity(aStruct->aMatrix); + * + * @code + * glm_mat2_copy(GLM_MAT2_IDENTITY, mat); // C only + * + * // or + * mat2 mat = GLM_MAT2_IDENTITY_INIT; + * @endcode + * + * @param[in, out] mat destination + */ +CGLM_INLINE +void +glm_mat2_identity(mat2 mat) { + CGLM_ALIGN_MAT mat2 t = GLM_MAT2_IDENTITY_INIT; + glm_mat2_copy(t, mat); +} + +/*! + * @brief make given matrix array's each element identity matrix + * + * @param[in, out] mat matrix array (must be aligned (16) + * if alignment is not disabled) + * + * @param[in] count count of matrices + */ +CGLM_INLINE +void +glm_mat2_identity_array(mat2 * __restrict mat, size_t count) { + CGLM_ALIGN_MAT mat2 t = GLM_MAT2_IDENTITY_INIT; + size_t i; + + for (i = 0; i < count; i++) { + glm_mat2_copy(t, mat[i]); + } +} + +/*! + * @brief make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +void +glm_mat2_zero(mat2 mat) { + CGLM_ALIGN_MAT mat2 t = GLM_MAT2_ZERO_INIT; + glm_mat2_copy(t, mat); +} + +/*! + * @brief multiply m1 and m2 to dest + * + * m1, m2 and dest matrices can be same matrix, it is possible to write this: + * + * @code + * mat2 m = GLM_MAT2_IDENTITY_INIT; + * glm_mat2_mul(m, m, m); + * @endcode + * + * @param[in] m1 left matrix + * @param[in] m2 right matrix + * @param[out] dest destination matrix + */ +CGLM_INLINE +void +glm_mat2_mul(mat2 m1, mat2 m2, mat2 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat2_mul_sse2(m1, m2, dest); +#elif defined(CGLM_NEON_FP) + glm_mat2_mul_neon(m1, m2, dest); +#else + float a00 = m1[0][0], a01 = m1[0][1], + a10 = m1[1][0], a11 = m1[1][1], + b00 = m2[0][0], b01 = m2[0][1], + b10 = m2[1][0], b11 = m2[1][1]; + + dest[0][0] = a00 * b00 + a10 * b01; + dest[0][1] = a01 * b00 + a11 * b01; + dest[1][0] = a00 * b10 + a10 * b11; + dest[1][1] = a01 * b10 + a11 * b11; +#endif +} + +/*! + * @brief transpose mat2 and store in dest + * + * source matrix will not be transposed unless dest is m + * + * @param[in] m matrix + * @param[out] dest result + */ +CGLM_INLINE +void +glm_mat2_transpose_to(mat2 m, mat2 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat2_transp_sse2(m, dest); +#else + dest[0][0] = m[0][0]; + dest[0][1] = m[1][0]; + dest[1][0] = m[0][1]; + dest[1][1] = m[1][1]; +#endif +} + +/*! + * @brief tranpose mat2 and store result in same matrix + * + * @param[in, out] m source and dest + */ +CGLM_INLINE +void +glm_mat2_transpose(mat2 m) { + float tmp; + tmp = m[0][1]; + m[0][1] = m[1][0]; + m[1][0] = tmp; +} + +/*! + * @brief multiply mat2 with vec2 (column vector) and store in dest vector + * + * @param[in] m mat2 (left) + * @param[in] v vec2 (right, column vector) + * @param[out] dest vec2 (result, column vector) + */ +CGLM_INLINE +void +glm_mat2_mulv(mat2 m, vec2 v, vec2 dest) { + dest[0] = m[0][0] * v[0] + m[1][0] * v[1]; + dest[1] = m[0][1] * v[0] + m[1][1] * v[1]; +} + +/*! + * @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_mat2_trace(mat2 m) { + return m[0][0] + m[1][1]; +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +void +glm_mat2_scale(mat2 m, float s) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glmm_store(m[0], _mm_mul_ps(_mm_loadu_ps(m[0]), _mm_set1_ps(s))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(m[0], vmulq_f32(vld1q_f32(m[0]), vdupq_n_f32(s))); +#else + m[0][0] = m[0][0] * s; + m[0][1] = m[0][1] * s; + m[1][0] = m[1][0] * s; + m[1][1] = m[1][1] * s; +#endif +} + +/*! + * @brief mat2 determinant + * + * @param[in] mat matrix + * + * @return determinant + */ +CGLM_INLINE +float +glm_mat2_det(mat2 mat) { + return mat[0][0] * mat[1][1] - mat[1][0] * mat[0][1]; +} + +/*! + * @brief inverse mat2 and store in dest + * + * @param[in] mat matrix + * @param[out] dest inverse matrix + */ +CGLM_INLINE +void +glm_mat2_inv(mat2 mat, mat2 dest) { + float det; + float a = mat[0][0], b = mat[0][1], + c = mat[1][0], d = mat[1][1]; + + det = 1.0f / (a * d - b * c); + + dest[0][0] = d * det; + dest[0][1] = -b * det; + dest[1][0] = -c * det; + dest[1][1] = a * det; +} + +/*! + * @brief swap two matrix columns + * + * @param[in,out] mat matrix + * @param[in] col1 col1 + * @param[in] col2 col2 + */ +CGLM_INLINE +void +glm_mat2_swap_col(mat2 mat, int col1, int col2) { + float a, b; + + a = mat[col1][0]; + b = mat[col1][1]; + + mat[col1][0] = mat[col2][0]; + mat[col1][1] = mat[col2][1]; + + mat[col2][0] = a; + mat[col2][1] = b; +} + +/*! + * @brief swap two matrix rows + * + * @param[in,out] mat matrix + * @param[in] row1 row1 + * @param[in] row2 row2 + */ +CGLM_INLINE +void +glm_mat2_swap_row(mat2 mat, int row1, int row2) { + float a, b; + + a = mat[0][row1]; + b = mat[1][row1]; + + mat[0][row1] = mat[0][row2]; + mat[1][row1] = mat[1][row2]; + + mat[0][row2] = a; + mat[1][row2] = b; +} + +/*! + * @brief helper for R (row vector) * M (matrix) * C (column vector) + * + * rmc stands for Row * Matrix * Column + * + * the result is scalar because R * M = Matrix1x2 (row vector), + * then Matrix1x2 * Vec2 (column vector) = Matrix1x1 (Scalar) + * + * @param[in] r row vector or matrix1x2 + * @param[in] m matrix2x2 + * @param[in] c column vector or matrix2x1 + * + * @return scalar value e.g. Matrix1x1 + */ +CGLM_INLINE +float +glm_mat2_rmc(vec2 r, mat2 m, vec2 c) { + vec2 tmp; + glm_mat2_mulv(m, c, tmp); + return glm_vec2_dot(r, tmp); +} + +#endif /* cglm_mat2_h */ diff --git a/libs/cglm/include/cglm/mat3.h b/libs/cglm/include/cglm/mat3.h new file mode 100644 index 0000000..0b29f97 --- /dev/null +++ b/libs/cglm/include/cglm/mat3.h @@ -0,0 +1,424 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLM_MAT3_IDENTITY_INIT + GLM_MAT3_ZERO_INIT + GLM_MAT3_IDENTITY + GLM_MAT3_ZERO + glm_mat3_dup(mat, dest) + + 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_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); + 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 +#define cglm_mat3_h + +#include "common.h" +#include "vec3.h" + +#ifdef CGLM_SSE_FP +# include "simd/sse2/mat3.h" +#endif + +#define GLM_MAT3_IDENTITY_INIT {{1.0f, 0.0f, 0.0f}, \ + {0.0f, 1.0f, 0.0f}, \ + {0.0f, 0.0f, 1.0f}} +#define GLM_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 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) + +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +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]; + + 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]; +} + +/*! + * @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 + * + * @param[in, out] mat destination + */ +CGLM_INLINE +void +glm_mat3_identity(mat3 mat) { + CGLM_ALIGN_MAT mat3 t = GLM_MAT3_IDENTITY_INIT; + 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 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 + * + * 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 + * @param[out] dest destination matrix + */ +CGLM_INLINE +void +glm_mat3_mul(mat3 m1, mat3 m2, mat3 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat3_mul_sse2(m1, m2, dest); +#else + float a00 = m1[0][0], a01 = m1[0][1], a02 = m1[0][2], + a10 = m1[1][0], a11 = m1[1][1], a12 = m1[1][2], + a20 = m1[2][0], a21 = m1[2][1], a22 = m1[2][2], + + 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]; + + 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[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[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; +#endif +} + +/*! + * @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 +void +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]; + dest[1][0] = m[0][1]; + dest[1][1] = m[1][1]; + dest[1][2] = m[2][1]; + dest[2][0] = m[0][2]; + dest[2][1] = m[1][2]; + dest[2][2] = m[2][2]; +} + +/*! + * @brief tranpose mat3 and store result in same matrix + * + * @param[in, out] m source and dest + */ +CGLM_INLINE +void +glm_mat3_transpose(mat3 m) { + CGLM_ALIGN_MAT mat3 tmp; + + tmp[0][1] = m[1][0]; + tmp[0][2] = m[2][0]; + tmp[1][0] = m[0][1]; + tmp[1][2] = m[2][1]; + tmp[2][0] = m[0][2]; + tmp[2][1] = m[1][2]; + + m[0][1] = tmp[0][1]; + m[0][2] = tmp[0][2]; + m[1][0] = tmp[1][0]; + m[1][2] = tmp[1][2]; + m[2][0] = tmp[2][0]; + m[2][1] = tmp[2][1]; +} + +/*! + * @brief multiply mat3 with vec3 (column vector) and store in dest vector + * + * @param[in] m mat3 (left) + * @param[in] v vec3 (right, column vector) + * @param[out] dest vec3 (result, column vector) + */ +CGLM_INLINE +void +glm_mat3_mulv(mat3 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_vec3_copy(res, dest); +} + +/*! + * @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 + * + * @param[in] m rotation matrix + * @param[out] dest destination quaternion + */ +CGLM_INLINE +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 = sqrtf(1.0f + trace); + rinv = 0.5f / r; + + dest[0] = rinv * (m[1][2] - m[2][1]); + 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] = 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[0] = rinv * (m[0][1] + m[1][0]); + dest[1] = r * 0.5f; + dest[2] = rinv * (m[1][2] + m[2][1]); + 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]); + } +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +void +glm_mat3_scale(mat3 m, float s) { + m[0][0] *= s; m[0][1] *= s; m[0][2] *= s; + m[1][0] *= s; m[1][1] *= s; m[1][2] *= s; + m[2][0] *= s; m[2][1] *= s; m[2][2] *= s; +} + +/*! + * @brief mat3 determinant + * + * @param[in] mat matrix + * + * @return determinant + */ +CGLM_INLINE +float +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]; + + return a * (e * i - h * f) - d * (b * i - c * h) + g * (b * f - c * e); +} + +/*! + * @brief inverse mat3 and store in dest + * + * @param[in] mat matrix + * @param[out] dest inverse matrix + */ +CGLM_INLINE +void +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], + g = mat[2][0], h = mat[2][1], i = mat[2][2]; + + dest[0][0] = e * i - f * h; + dest[0][1] = -(b * i - h * c); + dest[0][2] = b * f - e * c; + dest[1][0] = -(d * i - g * f); + dest[1][1] = a * i - c * g; + dest[1][2] = -(a * f - d * c); + dest[2][0] = d * h - g * e; + dest[2][1] = -(a * h - g * b); + dest[2][2] = a * e - b * d; + + det = 1.0f / (a * dest[0][0] + b * dest[1][0] + c * dest[2][0]); + + glm_mat3_scale(dest, det); +} + +/*! + * @brief swap two matrix columns + * + * @param[in,out] mat matrix + * @param[in] col1 col1 + * @param[in] col2 col2 + */ +CGLM_INLINE +void +glm_mat3_swap_col(mat3 mat, int col1, int col2) { + vec3 tmp; + glm_vec3_copy(mat[col1], tmp); + glm_vec3_copy(mat[col2], mat[col1]); + glm_vec3_copy(tmp, mat[col2]); +} + +/*! + * @brief swap two matrix rows + * + * @param[in,out] mat matrix + * @param[in] row1 row1 + * @param[in] row2 row2 + */ +CGLM_INLINE +void +glm_mat3_swap_row(mat3 mat, int row1, int row2) { + vec3 tmp; + tmp[0] = mat[0][row1]; + tmp[1] = mat[1][row1]; + tmp[2] = mat[2][row1]; + + mat[0][row1] = mat[0][row2]; + mat[1][row1] = mat[1][row2]; + mat[2][row1] = mat[2][row2]; + + mat[0][row2] = tmp[0]; + mat[1][row2] = tmp[1]; + 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/libs/cglm/include/cglm/mat4.h b/libs/cglm/include/cglm/mat4.h new file mode 100644 index 0000000..04cfece --- /dev/null +++ b/libs/cglm/include/cglm/mat4.h @@ -0,0 +1,754 @@ +/* + * 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 + */ + +/* + Macros: + GLM_MAT4_IDENTITY_INIT + GLM_MAT4_ZERO_INIT + GLM_MAT4_IDENTITY + GLM_MAT4_ZERO + + Functions: + 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_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); + CGLM_INLINE void glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest); + CGLM_INLINE void glm_mat4_mulN(mat4 *matrices[], int len, mat4 dest); + CGLM_INLINE void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); + CGLM_INLINE void glm_mat4_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); + CGLM_INLINE void glm_mat4_scale(mat4 m, float s); + CGLM_INLINE float glm_mat4_det(mat4 mat); + CGLM_INLINE void glm_mat4_inv(mat4 mat, mat4 dest); + 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 +#define cglm_mat_h + +#include "common.h" +#include "vec4.h" +#include "vec3.h" + +#ifdef CGLM_SSE_FP +# include "simd/sse2/mat4.h" +#endif + +#ifdef CGLM_AVX_FP +# include "simd/avx/mat4.h" +#endif + +#ifdef CGLM_NEON_FP +# include "simd/neon/mat4.h" +#endif + +#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}, \ + {0.0f, 0.0f, 1.0f, 0.0f}, \ + {0.0f, 0.0f, 0.0f, 1.0f}} + +#define GLM_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 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) +#define glm_mat4_dup(mat, dest) glm_mat4_copy(mat, dest) + +/* DEPRECATED! default is precise now. */ +#define glm_mat4_inv_precise(mat, dest) glm_mat4_inv(mat, dest) + +/*! + * @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 + * @param[out] dest destination + */ +CGLM_INLINE +void +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]; + 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]; +} + +/*! + * @brief copy all members of [mat] to [dest] + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +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])); +#elif defined( __SSE__ ) || defined( __SSE2__ ) + 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])); +#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 +} + +/*! + * @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 + * + * @param[in, out] mat destination + */ +CGLM_INLINE +void +glm_mat4_identity(mat4 mat) { + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_IDENTITY_INIT; + 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 make given matrix zero. + * + * @param[in, out] mat matrix + */ +CGLM_INLINE +void +glm_mat4_zero(mat4 mat) { +#ifdef __AVX__ + __m256 y0; + y0 = _mm256_setzero_ps(); + glmm_store256(mat[0], y0); + glmm_store256(mat[2], y0); +#elif defined( __SSE__ ) || defined( __SSE2__ ) + glmm_128 x0; + x0 = _mm_setzero_ps(); + glmm_store(mat[0], x0); + glmm_store(mat[1], x0); + glmm_store(mat[2], x0); + glmm_store(mat[3], x0); +#elif defined(CGLM_NEON_FP) + glmm_128 x0; + x0 = vdupq_n_f32(0.0f); + vst1q_f32(mat[0], x0); + vst1q_f32(mat[1], x0); + vst1q_f32(mat[2], x0); + vst1q_f32(mat[3], x0); +#else + CGLM_ALIGN_MAT mat4 t = GLM_MAT4_ZERO_INIT; + glm_mat4_copy(t, mat); +#endif +} + +/*! + * @brief copy upper-left of mat4 to mat3 + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +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]; + + 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]; +} + +/*! + * @brief copy upper-left of mat4 to mat3 (transposed) + * + * the postfix t stands for transpose + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +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]; + + dest[1][0] = mat[0][1]; + dest[1][1] = mat[1][1]; + dest[1][2] = mat[2][1]; + + dest[2][0] = mat[0][2]; + dest[2][1] = mat[1][2]; + dest[2][2] = mat[2][2]; +} + +/*! + * @brief copy mat3 to mat4's upper-left + * + * @param[in] mat source + * @param[out] dest destination + */ +CGLM_INLINE +void +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]; + + 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]; +} + +/*! + * @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 + * @param[out] dest destination matrix + */ +CGLM_INLINE +void +glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest) { +#ifdef __AVX__ + glm_mat4_mul_avx(m1, m2, dest); +#elif defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_mul_sse2(m1, m2, dest); +#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], + 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], b03 = m2[0][3], + b10 = m2[1][0], b11 = m2[1][1], b12 = m2[1][2], b13 = m2[1][3], + b20 = m2[2][0], b21 = m2[2][1], b22 = m2[2][2], b23 = m2[2][3], + b30 = m2[3][0], b31 = m2[3][1], b32 = m2[3][2], b33 = m2[3][3]; + + dest[0][0] = a00 * b00 + a10 * b01 + a20 * b02 + a30 * b03; + dest[0][1] = a01 * b00 + a11 * b01 + a21 * b02 + a31 * b03; + dest[0][2] = a02 * b00 + a12 * b01 + a22 * b02 + a32 * b03; + dest[0][3] = a03 * b00 + a13 * b01 + a23 * b02 + a33 * b03; + dest[1][0] = a00 * b10 + a10 * b11 + a20 * b12 + a30 * b13; + dest[1][1] = a01 * b10 + a11 * b11 + a21 * b12 + a31 * b13; + dest[1][2] = a02 * b10 + a12 * b11 + a22 * b12 + a32 * b13; + dest[1][3] = a03 * b10 + a13 * b11 + a23 * b12 + a33 * b13; + dest[2][0] = a00 * b20 + a10 * b21 + a20 * b22 + a30 * b23; + dest[2][1] = a01 * b20 + a11 * b21 + a21 * b22 + a31 * b23; + dest[2][2] = a02 * b20 + a12 * b21 + a22 * b22 + a32 * b23; + dest[2][3] = a03 * b20 + a13 * b21 + a23 * b22 + a33 * b23; + dest[3][0] = a00 * b30 + a10 * b31 + a20 * b32 + a30 * b33; + dest[3][1] = a01 * b30 + a11 * b31 + a21 * b32 + a31 * b33; + dest[3][2] = a02 * b30 + a12 * b31 + a22 * b32 + a32 * b33; + dest[3][3] = a03 * b30 + a13 * b31 + a23 * b32 + a33 * b33; +#endif +} + +/*! + * @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 + * @param[out] dest result + */ +CGLM_INLINE +void +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); + + for (i = 2; i < len; i++) + glm_mat4_mul(dest, *matrices[i], dest); +} + +/*! + * @brief multiply mat4 with vec4 (column vector) and store in dest vector + * + * @param[in] m mat4 (left) + * @param[in] v vec4 (right, column vector) + * @param[out] dest vec4 (result, column vector) + */ +CGLM_INLINE +void +glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_mulv_sse2(m, v, dest); +#elif defined(CGLM_NEON_FP) + glm_mat4_mulv_neon(m, v, dest); +#else + vec4 res; + res[0] = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0] * v[2] + m[3][0] * v[3]; + res[1] = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1] * v[2] + m[3][1] * v[3]; + res[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2] + m[3][2] * v[3]; + res[3] = m[0][3] * v[0] + m[1][3] * v[1] + m[2][3] * v[2] + m[3][3] * v[3]; + glm_vec4_copy(res, 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 + * + * @param[in] m affine matrix + * @param[out] dest destination quaternion + */ +CGLM_INLINE +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 = sqrtf(1.0f + trace); + rinv = 0.5f / r; + + dest[0] = rinv * (m[1][2] - m[2][1]); + 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] = 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[0] = rinv * (m[0][1] + m[1][0]); + dest[1] = r * 0.5f; + dest[2] = rinv * (m[1][2] + m[2][1]); + 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]); + } +} + +/*! + * @brief multiply vector with mat4 + * + * actually the result is vec4, after multiplication the last component + * is trimmed. if you need it don't use this func. + * + * @param[in] m mat4(affine transform) + * @param[in] v 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, float last, vec3 dest) { + vec4 res; + glm_vec4(v, last, res); + glm_mat4_mulv(m, res, res); + glm_vec3(res, dest); +} + +/*! + * @brief transpose mat4 and store in dest + * + * source matrix will not be transposed unless dest is m + * + * @param[in] m matrix + * @param[out] dest result + */ +CGLM_INLINE +void +glm_mat4_transpose_to(mat4 m, mat4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_transp_sse2(m, dest); +#elif defined(CGLM_NEON_FP) + glm_mat4_transp_neon(m, dest); +#else + dest[0][0] = m[0][0]; dest[1][0] = m[0][1]; + dest[0][1] = m[1][0]; dest[1][1] = m[1][1]; + dest[0][2] = m[2][0]; dest[1][2] = m[2][1]; + dest[0][3] = m[3][0]; dest[1][3] = m[3][1]; + dest[2][0] = m[0][2]; dest[3][0] = m[0][3]; + dest[2][1] = m[1][2]; dest[3][1] = m[1][3]; + dest[2][2] = m[2][2]; dest[3][2] = m[2][3]; + dest[2][3] = m[3][2]; dest[3][3] = m[3][3]; +#endif +} + +/*! + * @brief tranpose mat4 and store result in same matrix + * + * @param[in, out] m source and dest + */ +CGLM_INLINE +void +glm_mat4_transpose(mat4 m) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_transp_sse2(m, m); +#elif defined(CGLM_NEON_FP) + glm_mat4_transp_neon(m, m); +#else + mat4 d; + glm_mat4_transpose_to(m, d); + glm_mat4_ucopy(d, m); +#endif +} + +/*! + * @brief scale (multiply with scalar) matrix without simd optimization + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +void +glm_mat4_scale_p(mat4 m, float s) { + m[0][0] *= s; m[0][1] *= s; m[0][2] *= s; m[0][3] *= s; + m[1][0] *= s; m[1][1] *= s; m[1][2] *= s; m[1][3] *= s; + m[2][0] *= s; m[2][1] *= s; m[2][2] *= s; m[2][3] *= s; + m[3][0] *= s; m[3][1] *= s; m[3][2] *= s; m[3][3] *= s; +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + */ +CGLM_INLINE +void +glm_mat4_scale(mat4 m, float s) { +#ifdef __AVX__ + glm_mat4_scale_avx(m, s); +#elif defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_scale_sse2(m, s); +#elif defined(CGLM_NEON_FP) + glm_mat4_scale_neon(m, s); +#else + glm_mat4_scale_p(m, s); +#endif +} + +/*! + * @brief mat4 determinant + * + * @param[in] mat matrix + * + * @return determinant + */ +CGLM_INLINE +float +glm_mat4_det(mat4 mat) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + return glm_mat4_det_sse2(mat); +#elif defined(CGLM_NEON_FP) + return glm_mat4_det_neon(mat); +#else + /* [square] det(A) = det(At) */ + float t[6]; + float a = mat[0][0], b = mat[0][1], c = mat[0][2], d = mat[0][3], + e = mat[1][0], f = mat[1][1], g = mat[1][2], h = mat[1][3], + i = mat[2][0], j = mat[2][1], k = mat[2][2], l = mat[2][3], + m = mat[3][0], n = mat[3][1], o = mat[3][2], p = mat[3][3]; + + t[0] = k * p - o * l; + t[1] = j * p - n * l; + t[2] = j * o - n * k; + t[3] = i * p - m * l; + t[4] = i * o - m * k; + t[5] = i * n - m * j; + + return a * (f * t[0] - g * t[1] + h * t[2]) + - b * (e * t[0] - g * t[3] + h * t[4]) + + c * (e * t[1] - f * t[3] + h * t[5]) + - d * (e * t[2] - f * t[4] + g * t[5]); +#endif +} + +/*! + * @brief inverse mat4 and store in dest + * + * @param[in] mat matrix + * @param[out] dest inverse matrix + */ +CGLM_INLINE +void +glm_mat4_inv(mat4 mat, mat4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_inv_sse2(mat, dest); +#elif defined(CGLM_NEON_FP) + glm_mat4_inv_neon(mat, dest); +#else + float t[6]; + float det; + float a = mat[0][0], b = mat[0][1], c = mat[0][2], d = mat[0][3], + e = mat[1][0], f = mat[1][1], g = mat[1][2], h = mat[1][3], + i = mat[2][0], j = mat[2][1], k = mat[2][2], l = mat[2][3], + m = mat[3][0], n = mat[3][1], o = mat[3][2], p = mat[3][3]; + + t[0] = k * p - o * l; t[1] = j * p - n * l; t[2] = j * o - n * k; + t[3] = i * p - m * l; t[4] = i * o - m * k; t[5] = i * n - m * j; + + dest[0][0] = f * t[0] - g * t[1] + h * t[2]; + dest[1][0] =-(e * t[0] - g * t[3] + h * t[4]); + dest[2][0] = e * t[1] - f * t[3] + h * t[5]; + dest[3][0] =-(e * t[2] - f * t[4] + g * t[5]); + + dest[0][1] =-(b * t[0] - c * t[1] + d * t[2]); + dest[1][1] = a * t[0] - c * t[3] + d * t[4]; + dest[2][1] =-(a * t[1] - b * t[3] + d * t[5]); + dest[3][1] = a * t[2] - b * t[4] + c * t[5]; + + t[0] = g * p - o * h; t[1] = f * p - n * h; t[2] = f * o - n * g; + t[3] = e * p - m * h; t[4] = e * o - m * g; t[5] = e * n - m * f; + + dest[0][2] = b * t[0] - c * t[1] + d * t[2]; + dest[1][2] =-(a * t[0] - c * t[3] + d * t[4]); + dest[2][2] = a * t[1] - b * t[3] + d * t[5]; + dest[3][2] =-(a * t[2] - b * t[4] + c * t[5]); + + t[0] = g * l - k * h; t[1] = f * l - j * h; t[2] = f * k - j * g; + t[3] = e * l - i * h; t[4] = e * k - i * g; t[5] = e * j - i * f; + + dest[0][3] =-(b * t[0] - c * t[1] + d * t[2]); + dest[1][3] = a * t[0] - c * t[3] + d * t[4]; + dest[2][3] =-(a * t[1] - b * t[3] + d * t[5]); + dest[3][3] = a * t[2] - b * t[4] + c * t[5]; + + det = 1.0f / (a * dest[0][0] + b * dest[1][0] + + c * dest[2][0] + d * dest[3][0]); + + glm_mat4_scale_p(dest, det); +#endif +} + +/*! + * @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 + * @param[out] dest inverse matrix + */ +CGLM_INLINE +void +glm_mat4_inv_fast(mat4 mat, mat4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glm_mat4_inv_fast_sse2(mat, dest); +#else + glm_mat4_inv(mat, dest); +#endif +} + +/*! + * @brief swap two matrix columns + * + * @param[in,out] mat matrix + * @param[in] col1 col1 + * @param[in] col2 col2 + */ +CGLM_INLINE +void +glm_mat4_swap_col(mat4 mat, int col1, int col2) { + CGLM_ALIGN(16) vec4 tmp; + glm_vec4_copy(mat[col1], tmp); + glm_vec4_copy(mat[col2], mat[col1]); + glm_vec4_copy(tmp, mat[col2]); +} + +/*! + * @brief swap two matrix rows + * + * @param[in,out] mat matrix + * @param[in] row1 row1 + * @param[in] row2 row2 + */ +CGLM_INLINE +void +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]; + tmp[2] = mat[2][row1]; + tmp[3] = mat[3][row1]; + + mat[0][row1] = mat[0][row2]; + mat[1][row1] = mat[1][row2]; + mat[2][row1] = mat[2][row2]; + mat[3][row1] = mat[3][row2]; + + mat[0][row2] = tmp[0]; + mat[1][row2] = tmp[1]; + mat[2][row2] = tmp[2]; + 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 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 +glm_mat4_rmc(vec4 r, mat4 m, vec4 c) { + vec4 tmp; + glm_mat4_mulv(m, c, tmp); + return glm_vec4_dot(r, tmp); +} + +#endif /* cglm_mat_h */ diff --git a/libs/cglm/include/cglm/plane.h b/libs/cglm/include/cglm/plane.h new file mode 100644 index 0000000..0504373 --- /dev/null +++ b/libs/cglm/include/cglm/plane.h @@ -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 + */ + +#ifndef cglm_plane_h +#define cglm_plane_h + +#include "common.h" +#include "vec3.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 void glm_plane_normalize(vec4 plane); + */ + +/*! + * @brief normalizes a plane + * + * @param[in, out] plane plane to normalize + */ +CGLM_INLINE +void +glm_plane_normalize(vec4 plane) { + float norm; + + if ((norm = glm_vec3_norm(plane)) == 0.0f) { + glm_vec4_zero(plane); + return; + } + + glm_vec4_scale(plane, 1.0f / norm, plane); +} + +#endif /* cglm_plane_h */ diff --git a/libs/cglm/include/cglm/project.h b/libs/cglm/include/cglm/project.h new file mode 100644 index 0000000..f52d3a0 --- /dev/null +++ b/libs/cglm/include/cglm/project.h @@ -0,0 +1,150 @@ +/* + * 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 "common.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" + +#ifndef CGLM_CLIPSPACE_INCLUDE_ALL +# if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_ZO_BIT +# include "clipspace/project_zo.h" +# elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_NO_BIT +# include "clipspace/project_no.h" +# endif +#else +# include "clipspace/project_zo.h" +# include "clipspace/project_no.h" +#endif + +/*! + * @brief maps the specified viewport coordinates into specified space [1] + * the matrix should contain projection matrix. + * + * 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] + * @param[out] dest unprojected coordinates + */ +CGLM_INLINE +void +glm_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { +#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_ZO_BIT + glm_unprojecti_zo(pos, invMat, vp, dest); +#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_NO_BIT + glm_unprojecti_no(pos, invMat, vp, dest); +#endif +} + +/*! + * @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] + * @param[out] dest unprojected coordinates + */ +CGLM_INLINE +void +glm_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) { + mat4 inv; + glm_mat4_inv(m, inv); + glm_unprojecti(pos, inv, vp, 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] + * @param[out] dest projected coordinates + */ +CGLM_INLINE +void +glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { +#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_ZO_BIT + glm_project_zo(pos, m, vp, dest); +#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_NO_BIT + glm_project_no(pos, m, vp, dest); +#endif +} + +/*! + * @brief define a picking region + * + * @param[in] center center [x, y] of a picking region in window coordinates + * @param[in] size size [width, height] of the picking region in window coordinates + * @param[in] vp viewport as [x, y, width, height] + * @param[out] dest projected coordinates + */ +CGLM_INLINE +void +glm_pickmatrix(vec2 center, vec2 size, vec4 vp, mat4 dest) { + mat4 res; + vec3 v; + + if (size[0] <= 0.0f || size[1] <= 0.0f) + return; + + /* Translate and scale the picked region to the entire window */ + v[0] = (vp[2] - 2.0f * (center[0] - vp[0])) / size[0]; + v[1] = (vp[3] - 2.0f * (center[1] - vp[1])) / size[1]; + v[2] = 0.0f; + + glm_translate_make(res, v); + + v[0] = vp[2] / size[0]; + v[1] = vp[3] / size[1]; + v[2] = 1.0f; + + glm_scale(res, v); + + glm_mat4_copy(res, dest); +} + +#endif /* cglm_project_h */ diff --git a/libs/cglm/include/cglm/quat.h b/libs/cglm/include/cglm/quat.h new file mode 100644 index 0000000..c76fa03 --- /dev/null +++ b/libs/cglm/include/cglm/quat.h @@ -0,0 +1,867 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLM_QUAT_IDENTITY_INIT + GLM_QUAT_IDENTITY + + Functions: + 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 void glm_quat_copy(versor q, versor dest); + CGLM_INLINE void glm_quat_from_vecs(vec3 a, vec3 b, 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 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); + 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, 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); + 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_lerpc(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_nlerp(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 +#define cglm_quat_h + +#include "common.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" +#include "mat3.h" +#include "affine-mat.h" +#include "affine.h" + +#ifdef CGLM_SSE_FP +# include "simd/sse2/quat.h" +#endif + +#ifdef CGLM_NEON_FP +# include "simd/neon/quat.h" +#endif + +CGLM_INLINE void glm_quat_normalize(versor q); + +/* + * 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 GLM_QUAT_IDENTITY_INIT {0.0f, 0.0f, 0.0f, 1.0f} +#define GLM_QUAT_IDENTITY ((versor)GLM_QUAT_IDENTITY_INIT) + +/*! + * @brief makes given quat to identity + * + * @param[in, out] q quaternion + */ +CGLM_INLINE +void +glm_quat_identity(versor q) { + CGLM_ALIGN(16) versor v = GLM_QUAT_IDENTITY_INIT; + 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 + * + * @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 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) { + CGLM_ALIGN(8) 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 + * + * @param[out] q quaternion + * @param[in] angle angle (radians) + * @param[in] x axis.x + * @param[in] y axis.y + * @param[in] z axis.z + */ +CGLM_INLINE +void +glm_quat(versor q, float angle, float x, float y, float z) { + CGLM_ALIGN(8) vec3 axis = {x, y, z}; + glm_quatv(q, angle, axis); +} + +/*! + * @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 compute quaternion rotating vector A to vector B + * + * @param[in] a vec3 (must have unit length) + * @param[in] b vec3 (must have unit length) + * @param[out] dest quaternion (of unit length) + */ +CGLM_INLINE +void +glm_quat_from_vecs(vec3 a, vec3 b, versor dest) { + CGLM_ALIGN(8) vec3 axis; + float cos_theta; + float cos_half_theta; + + cos_theta = glm_vec3_dot(a, b); + if (cos_theta >= 1.f - GLM_FLT_EPSILON) { /* a ∥ b */ + glm_quat_identity(dest); + return; + } + if (cos_theta < -1.f + GLM_FLT_EPSILON) { /* angle(a, b) = π */ + glm_vec3_ortho(a, axis); + cos_half_theta = 0.f; /* cos π/2 */ + } else { + glm_vec3_cross(a, b, axis); + cos_half_theta = 1.0f + cos_theta; /* cos 0 + cos θ */ + } + + glm_quat_init(dest, axis[0], axis[1], axis[2], cos_half_theta); + glm_quat_normalize(dest); +} + +/*! + * @brief returns norm (magnitude) of quaternion + * + * @param[in] q quaternion + */ +CGLM_INLINE +float +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 = glmm_load(q); + xdot = glmm_vdot(x0, x0); + dot = _mm_cvtss_f32(xdot); + + if (dot <= 0.0f) { + glm_quat_identity(dest); + return; + } + + glmm_store(dest, _mm_div_ps(x0, _mm_sqrt_ps(xdot))); +#else + float dot; + + dot = glm_vec4_norm2(q); + + if (dot <= 0.0f) { + glm_quat_identity(dest); + return; + } + + glm_vec4_scale(q, 1.0f / sqrtf(dot), dest); +#endif +} + +/*! + * @brief normalize quaternion + * + * @param[in, out] q quaternion + */ +CGLM_INLINE +void +glm_quat_normalize(versor q) { + glm_quat_normalize_to(q, q); +} + +/*! + * @brief dot product of two quaternion + * + * @param[in] p quaternion 1 + * @param[in] q quaternion 2 + */ +CGLM_INLINE +float +glm_quat_dot(versor p, versor q) { + return glm_vec4_dot(p, q); +} + +/*! + * @brief conjugate of quaternion + * + * @param[in] q quaternion + * @param[out] dest conjugate + */ +CGLM_INLINE +void +glm_quat_conjugate(versor q, versor dest) { + glm_vec4_negate_to(q, 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) { + CGLM_ALIGN(16) versor conj; + glm_quat_conjugate(q, conj); + glm_vec4_scale(conj, 1.0f / 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 + * @param[out] dest imag + */ +CGLM_INLINE +void +glm_quat_imag(versor q, vec3 dest) { + dest[0] = q[0]; + dest[1] = q[1]; + 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_vec3_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, vec3 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); +#elif defined(CGLM_NEON_FP) + glm_quat_mul_neon(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 + * + * @param[in] q quaternion + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_quat_mat4(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[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; + + 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 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 + * + * @param[in] q quaternion + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_quat_mat3(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[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 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) + * + * @param[in] from from + * @param[in] to to + * @param[in] t interpolant (amount) + * @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 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_lerpc(versor from, versor to, float t, versor dest) { + glm_vec4_lerpc(from, to, t, dest); +} + +/*! + * @brief interpolates between two quaternions + * taking the shortest rotation path using + * normalized linear interpolation (NLERP) + * + * @param[in] from from + * @param[in] to to + * @param[in] t interpolant (amount) + * @param[out] dest result quaternion + */ +CGLM_INLINE +void +glm_quat_nlerp(versor from, versor to, float t, versor dest) { + versor target; + float dot; + + dot = glm_vec4_dot(from, to); + + glm_vec4_scale(to, (dot >= 0) ? 1.0f : -1.0f, target); + glm_quat_lerp(from, target, t, dest); + glm_quat_normalize(dest); +} + +/*! + * @brief interpolates between two quaternions + * using spherical linear interpolation (SLERP) + * + * @param[in] from from + * @param[in] to to + * @param[in] t amout + * @param[out] dest result quaternion + */ +CGLM_INLINE +void +glm_quat_slerp(versor from, versor to, float t, versor dest) { + CGLM_ALIGN(16) vec4 q1, q2; + float cosTheta, sinTheta, angle; + + cosTheta = glm_quat_dot(from, to); + glm_quat_copy(from, q1); + + if (fabsf(cosTheta) >= 1.0f) { + glm_quat_copy(q1, dest); + return; + } + + if (cosTheta < 0.0f) { + glm_vec4_negate(q1); + cosTheta = -cosTheta; + } + + sinTheta = sqrtf(1.0f - cosTheta * cosTheta); + + /* LERP to avoid zero division */ + if (fabsf(sinTheta) < 0.001f) { + glm_quat_lerp(from, to, t, dest); + return; + } + + /* SLERP */ + angle = acosf(cosTheta); + glm_vec4_scale(q1, sinf((1.0f - t) * angle), q1); + glm_vec4_scale(to, sinf(t * angle), q2); + + glm_vec4_add(q1, q2, q1); + glm_vec4_scale(q1, 1.0f / sinTheta, 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) { + /* orientation */ + glm_quat_mat4t(ori, dest); + + /* translate */ + glm_mat4_mulv3(dest, eye, 1.0f, dest[3]); + glm_vec3_negate(dest[3]); +} + +/*! + * @brief creates look rotation quaternion + * + * @param[in] dir direction to look + * @param[in] up up vector + * @param[out] dest destination quaternion + */ +CGLM_INLINE +void +glm_quat_for(vec3 dir, vec3 up, versor dest) { + CGLM_ALIGN_MAT mat3 m; + + glm_vec3_normalize_to(dir, m[2]); + + /* No need to negate in LH, but we use RH here */ + glm_vec3_negate(m[2]); + + glm_vec3_crossn(up, m[2], m[0]); + glm_vec3_cross(m[2], m[0], m[1]); + + glm_mat3_quat(m, 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] up up vector + * @param[out] dest destination quaternion + */ +CGLM_INLINE +void +glm_quat_forp(vec3 from, vec3 to, vec3 up, versor dest) { + CGLM_ALIGN(8) vec3 dir; + glm_vec3_sub(to, from, dir); + glm_quat_for(dir, up, dest); +} + +/*! + * @brief rotate vector using using quaternion + * + * @param[in] q quaternion + * @param[in] v vector to rotate + * @param[out] dest rotated vector + */ +CGLM_INLINE +void +glm_quat_rotatev(versor q, vec3 v, vec3 dest) { + 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); + s = glm_quat_real(p); + + 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_vec3_cross(u, v, v2); + glm_vec3_scale(v2, 2.0f * s, v2); + + glm_vec3_add(v1, v2, dest); +} + +/*! + * @brief rotate existing transform matrix using quaternion + * + * @param[in] m existing transform matrix + * @param[in] q quaternion + * @param[out] dest rotated matrix/transform + */ +CGLM_INLINE +void +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); +} + +/*! + * @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 m, versor q, vec3 pivot) { + CGLM_ALIGN(8) vec3 pivotInv; + + glm_vec3_negate_to(pivot, pivotInv); + + glm_translate(m, pivot); + glm_quat_rotate(m, q, m); + glm_translate(m, 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) { + CGLM_ALIGN(8) vec3 pivotInv; + + glm_vec3_negate_to(pivot, pivotInv); + + glm_translate_make(m, pivot); + glm_quat_rotate(m, q, m); + glm_translate(m, pivotInv); +} + +#endif /* cglm_quat_h */ diff --git a/libs/cglm/include/cglm/ray.h b/libs/cglm/include/cglm/ray.h new file mode 100644 index 0000000..ced1ad6 --- /dev/null +++ b/libs/cglm/include/cglm/ray.h @@ -0,0 +1,77 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE bool glm_line_triangle_intersect(vec3 origin, + vec3 direction, + vec3 v0, + vec3 v1, + vec3 v2, + float *d); +*/ + +#ifndef cglm_ray_h +#define cglm_ray_h + +#include "vec3.h" + +/*! + * @brief Möller–Trumbore ray-triangle intersection algorithm + * + * @param[in] origin origin of ray + * @param[in] direction direction of ray + * @param[in] v0 first vertex of triangle + * @param[in] v1 second vertex of triangle + * @param[in] v2 third vertex of triangle + * @param[in, out] d distance to intersection + * @return whether there is intersection + */ + +CGLM_INLINE +bool +glm_ray_triangle(vec3 origin, + vec3 direction, + vec3 v0, + vec3 v1, + vec3 v2, + float *d) { + vec3 edge1, edge2, p, t, q; + float det, inv_det, u, v, dist; + const float epsilon = 0.000001f; + + glm_vec3_sub(v1, v0, edge1); + glm_vec3_sub(v2, v0, edge2); + glm_vec3_cross(direction, edge2, p); + + det = glm_vec3_dot(edge1, p); + if (det > -epsilon && det < epsilon) + return false; + + inv_det = 1.0f / det; + + glm_vec3_sub(origin, v0, t); + + u = inv_det * glm_vec3_dot(t, p); + if (u < 0.0f || u > 1.0f) + return false; + + glm_vec3_cross(t, edge1, q); + + v = inv_det * glm_vec3_dot(direction, q); + if (v < 0.0f || u + v > 1.0f) + return false; + + dist = inv_det * glm_vec3_dot(edge2, q); + + if (d) + *d = dist; + + return dist > epsilon; +} + +#endif diff --git a/libs/cglm/include/cglm/simd/arm.h b/libs/cglm/include/cglm/simd/arm.h new file mode 100644 index 0000000..50cec46 --- /dev/null +++ b/libs/cglm/include/cglm/simd/arm.h @@ -0,0 +1,173 @@ +/* + * 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 + +#if defined(_M_ARM64) || defined(_M_HYBRID_X86_ARM64) || defined(_M_ARM64EC) || defined(__aarch64__) +# define CGLM_ARM64 1 +#endif + +#define glmm_load(p) vld1q_f32(p) +#define glmm_store(p, a) vst1q_f32(p, a) + +#define glmm_set1(x) vdupq_n_f32(x) +#define glmm_128 float32x4_t + +#define glmm_splat_x(x) vdupq_lane_f32(vget_low_f32(x), 0) +#define glmm_splat_y(x) vdupq_lane_f32(vget_low_f32(x), 1) +#define glmm_splat_z(x) vdupq_lane_f32(vget_high_f32(x), 0) +#define glmm_splat_w(x) vdupq_lane_f32(vget_high_f32(x), 1) + +#define glmm_xor(a, b) \ + vreinterpretq_f32_s32(veorq_s32(vreinterpretq_s32_f32(a), \ + vreinterpretq_s32_f32(b))) + +#define glmm_swplane(v) vextq_f32(v, v, 2) +#define glmm_low(x) vget_low_f32(x) +#define glmm_high(x) vget_high_f32(x) + +#define glmm_combine_ll(x, y) vcombine_f32(vget_low_f32(x), vget_low_f32(y)) +#define glmm_combine_hl(x, y) vcombine_f32(vget_high_f32(x), vget_low_f32(y)) +#define glmm_combine_lh(x, y) vcombine_f32(vget_low_f32(x), vget_high_f32(y)) +#define glmm_combine_hh(x, y) vcombine_f32(vget_high_f32(x), vget_high_f32(y)) + +static inline +float32x4_t +glmm_abs(float32x4_t v) { + return vabsq_f32(v); +} + +static inline +float32x4_t +glmm_vhadd(float32x4_t v) { + return vaddq_f32(vaddq_f32(glmm_splat_x(v), glmm_splat_y(v)), + vaddq_f32(glmm_splat_z(v), glmm_splat_w(v))); + /* + this seems slower: + v = vaddq_f32(v, vrev64q_f32(v)); + return vaddq_f32(v, vcombine_f32(vget_high_f32(v), vget_low_f32(v))); + */ +} + +static inline +float +glmm_hadd(float32x4_t v) { +#if CGLM_ARM64 + 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_hmin(float32x4_t v) { + float32x2_t t; + t = vpmin_f32(vget_low_f32(v), vget_high_f32(v)); + t = vpmin_f32(t, t); + return vget_lane_f32(t, 0); +} + +static inline +float +glmm_hmax(float32x4_t v) { + float32x2_t t; + t = vpmax_f32(vget_low_f32(v), vget_high_f32(v)); + t = vpmax_f32(t, t); + return vget_lane_f32(t, 0); +} + +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)); +} + +static inline +float +glmm_norm2(float32x4_t a) { + return glmm_dot(a, a); +} + +static inline +float +glmm_norm_one(float32x4_t a) { + return glmm_hadd(glmm_abs(a)); +} + +static inline +float +glmm_norm_inf(float32x4_t a) { + return glmm_hmax(glmm_abs(a)); +} + +static inline +float32x4_t +glmm_div(float32x4_t a, float32x4_t b) { +#if CGLM_ARM64 + return vdivq_f32(a, b); +#else + /* 2 iterations of Newton-Raphson refinement of reciprocal */ + float32x4_t r0, r1; + r0 = vrecpeq_f32(b); + r1 = vrecpsq_f32(r0, b); + r0 = vmulq_f32(r1, r0); + r1 = vrecpsq_f32(r0, b); + r0 = vmulq_f32(r1, r0); + return vmulq_f32(a, r0); +#endif +} + +static inline +float32x4_t +glmm_fmadd(float32x4_t a, float32x4_t b, float32x4_t c) { +#if CGLM_ARM64 + return vfmaq_f32(c, a, b); /* why vfmaq_f32 is slower than vmlaq_f32 ??? */ +#else + return vmlaq_f32(c, a, b); +#endif +} + +static inline +float32x4_t +glmm_fnmadd(float32x4_t a, float32x4_t b, float32x4_t c) { +#if CGLM_ARM64 + return vfmsq_f32(c, a, b); +#else + return vmlsq_f32(c, a, b); +#endif +} + +static inline +float32x4_t +glmm_fmsub(float32x4_t a, float32x4_t b, float32x4_t c) { +#if CGLM_ARM64 + return vfmsq_f32(c, a, b); +#else + return vmlsq_f32(c, a, b); +#endif +} + +static inline +float32x4_t +glmm_fnmsub(float32x4_t a, float32x4_t b, float32x4_t c) { + return vsubq_f32(vdupq_n_f32(0.0f), glmm_fmadd(a, b, c)); +} + +#endif +#endif /* cglm_simd_arm_h */ diff --git a/libs/cglm/include/cglm/simd/avx/affine.h b/libs/cglm/include/cglm/simd/avx/affine.h new file mode 100644 index 0000000..b02ff0c --- /dev/null +++ b/libs/cglm/include/cglm/simd/avx/affine.h @@ -0,0 +1,66 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_affine_mat_avx_h +#define cglm_affine_mat_avx_h +#ifdef __AVX__ + +#include "../../common.h" +#include "../intrin.h" + +#include + +CGLM_INLINE +void +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; + + 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 = 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 */ + + /* 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 */ + /* e e e e b b b b */ + /* 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(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 */ + /* m m m m j j j j */ + /* o o o o l l l l */ + y6 = _mm256_permutevar_ps(y1, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); + y7 = _mm256_permutevar_ps(y1, _mm256_set_epi32(3, 3, 3, 3, 2, 2, 2, 2)); + 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)); + + 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 +#endif /* cglm_affine_mat_avx_h */ diff --git a/libs/cglm/include/cglm/simd/avx/mat4.h b/libs/cglm/include/cglm/simd/avx/mat4.h new file mode 100644 index 0000000..e8c36c8 --- /dev/null +++ b/libs/cglm/include/cglm/simd/avx/mat4.h @@ -0,0 +1,76 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_mat_simd_avx_h +#define cglm_mat_simd_avx_h +#ifdef __AVX__ + +#include "../../common.h" +#include "../intrin.h" + +#include + +CGLM_INLINE +void +glm_mat4_scale_avx(mat4 m, float s) { + __m256 y0; + y0 = _mm256_set1_ps(s); + + glmm_store256(m[0], _mm256_mul_ps(y0, glmm_load256(m[0]))); + glmm_store256(m[2], _mm256_mul_ps(y0, glmm_load256(m[2]))); +} + +CGLM_INLINE +void +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; + + 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 = 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 */ + + /* 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 */ + /* e e e e b b b b */ + /* 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(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 */ + /* m m m m j j j j */ + /* o o o o l l l l */ + y6 = _mm256_permutevar_ps(y1, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); + y7 = _mm256_permutevar_ps(y1, _mm256_set_epi32(3, 3, 3, 3, 2, 2, 2, 2)); + 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)); + + 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 +#endif /* cglm_mat_simd_avx_h */ diff --git a/libs/cglm/include/cglm/simd/intrin.h b/libs/cglm/include/cglm/simd/intrin.h new file mode 100644 index 0000000..a6ca5b0 --- /dev/null +++ b/libs/cglm/include/cglm/simd/intrin.h @@ -0,0 +1,90 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_intrin_h +#define cglm_intrin_h + +#if defined( _MSC_VER ) +# if (defined(_M_AMD64) || defined(_M_X64)) || _M_IX86_FP == 2 +# ifndef __SSE2__ +# define __SSE2__ +# endif +# elif _M_IX86_FP == 1 +# ifndef __SSE__ +# 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__ ) +# include +# include +# define CGLM_SSE_FP 1 +# 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 */ +#if defined(__ARM_NEON) +# include +# if defined(__ARM_NEON_FP) +# define CGLM_NEON_FP 1 +# ifndef CGLM_SIMD_ARM +# define CGLM_SIMD_ARM +# endif +# endif +#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/libs/cglm/include/cglm/simd/neon/affine.h b/libs/cglm/include/cglm/simd/neon/affine.h new file mode 100644 index 0000000..da0a350 --- /dev/null +++ b/libs/cglm/include/cglm/simd/neon/affine.h @@ -0,0 +1,121 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_affine_neon_h +#define cglm_affine_neon_h +#if defined(__ARM_NEON_FP) + +#include "../../common.h" +#include "../intrin.h" + +CGLM_INLINE +void +glm_mul_neon(mat4 m1, mat4 m2, mat4 dest) { + /* D = R * L (Column-Major) */ + + glmm_128 l, r0, r1, r2, r3, v0, v1, v2, v3; + + l = glmm_load(m1[0]); + r0 = glmm_load(m2[0]); + r1 = glmm_load(m2[1]); + r2 = glmm_load(m2[2]); + r3 = glmm_load(m2[3]); + + v0 = vmulq_f32(glmm_splat_x(r0), l); + v1 = vmulq_f32(glmm_splat_x(r1), l); + v2 = vmulq_f32(glmm_splat_x(r2), l); + v3 = vmulq_f32(glmm_splat_x(r3), l); + + l = glmm_load(m1[1]); + v0 = glmm_fmadd(glmm_splat_y(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_y(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_y(r2), l, v2); + v3 = glmm_fmadd(glmm_splat_y(r3), l, v3); + + l = glmm_load(m1[2]); + v0 = glmm_fmadd(glmm_splat_z(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_z(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_z(r2), l, v2); + v3 = glmm_fmadd(glmm_splat_z(r3), l, v3); + + v3 = glmm_fmadd(glmm_splat_w(r3), glmm_load(m1[3]), v3); + + glmm_store(dest[0], v0); + glmm_store(dest[1], v1); + glmm_store(dest[2], v2); + glmm_store(dest[3], v3); +} + +CGLM_INLINE +void +glm_mul_rot_neon(mat4 m1, mat4 m2, mat4 dest) { + /* D = R * L (Column-Major) */ + + glmm_128 l, r0, r1, r2, v0, v1, v2; + + l = glmm_load(m1[0]); + r0 = glmm_load(m2[0]); + r1 = glmm_load(m2[1]); + r2 = glmm_load(m2[2]); + + v0 = vmulq_f32(glmm_splat_x(r0), l); + v1 = vmulq_f32(glmm_splat_x(r1), l); + v2 = vmulq_f32(glmm_splat_x(r2), l); + + l = glmm_load(m1[1]); + v0 = glmm_fmadd(glmm_splat_y(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_y(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_y(r2), l, v2); + + l = glmm_load(m1[2]); + v0 = glmm_fmadd(glmm_splat_z(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_z(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_z(r2), l, v2); + + glmm_store(dest[0], v0); + glmm_store(dest[1], v1); + glmm_store(dest[2], v2); + glmm_store(dest[3], glmm_load(m1[3])); +} + +CGLM_INLINE +void +glm_inv_tr_neon(mat4 mat) { + float32x4x4_t vmat; + glmm_128 r0, r1, r2, x0; + + vmat = vld4q_f32(mat[0]); + r0 = vmat.val[0]; + r1 = vmat.val[1]; + r2 = vmat.val[2]; + + x0 = glmm_fmadd(r0, glmm_splat_w(r0), + glmm_fmadd(r1, glmm_splat_w(r1), + vmulq_f32(r2, glmm_splat_w(r2)))); + x0 = vnegq_f32(x0); + + glmm_store(mat[0], r0); + glmm_store(mat[1], r1); + glmm_store(mat[2], r2); + glmm_store(mat[3], x0); + + mat[0][3] = 0.0f; + mat[1][3] = 0.0f; + mat[2][3] = 0.0f; + mat[3][3] = 1.0f; + + /* TODO: ? + zo = vget_high_f32(r3); + vst1_lane_f32(&mat[0][3], zo, 0); + vst1_lane_f32(&mat[1][3], zo, 0); + vst1_lane_f32(&mat[2][3], zo, 0); + vst1_lane_f32(&mat[3][3], zo, 1); + */ +} + +#endif +#endif /* cglm_affine_neon_h */ diff --git a/libs/cglm/include/cglm/simd/neon/mat2.h b/libs/cglm/include/cglm/simd/neon/mat2.h new file mode 100644 index 0000000..471ebea --- /dev/null +++ b/libs/cglm/include/cglm/simd/neon/mat2.h @@ -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 + */ + +#ifndef cglm_mat2_neon_h +#define cglm_mat2_neon_h +#if defined(__ARM_NEON_FP) + +#include "../../common.h" +#include "../intrin.h" + +CGLM_INLINE +void +glm_mat2_mul_neon(mat2 m1, mat2 m2, mat2 dest) { + float32x4x2_t a1; + glmm_128 x0, x1, x2; + float32x2_t dc, ba; + + x1 = glmm_load(m1[0]); /* d c b a */ + x2 = glmm_load(m2[0]); /* h g f e */ + + dc = vget_high_f32(x1); + ba = vget_low_f32(x1); + + /* g g e e, h h f f */ + a1 = vtrnq_f32(x2, x2); + + /* + dest[0][0] = a * e + c * f; + dest[0][1] = b * e + d * f; + dest[1][0] = a * g + c * h; + dest[1][1] = b * g + d * h; + */ + x0 = glmm_fmadd(vcombine_f32(ba, ba), a1.val[0], + vmulq_f32(vcombine_f32(dc, dc), a1.val[1])); + + glmm_store(dest[0], x0); +} + +#endif +#endif /* cglm_mat2_neon_h */ diff --git a/libs/cglm/include/cglm/simd/neon/mat4.h b/libs/cglm/include/cglm/simd/neon/mat4.h new file mode 100644 index 0000000..5b9f014 --- /dev/null +++ b/libs/cglm/include/cglm/simd/neon/mat4.h @@ -0,0 +1,317 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_mat4_neon_h +#define cglm_mat4_neon_h +#if defined(__ARM_NEON_FP) + +#include "../../common.h" +#include "../intrin.h" + +CGLM_INLINE +void +glm_mat4_scale_neon(mat4 m, float s) { + 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)); +} + +CGLM_INLINE +void +glm_mat4_transp_neon(mat4 m, mat4 dest) { + float32x4x4_t vmat; + + vmat = vld4q_f32(m[0]); + + vst1q_f32(dest[0], vmat.val[0]); + vst1q_f32(dest[1], vmat.val[1]); + vst1q_f32(dest[2], vmat.val[2]); + vst1q_f32(dest[3], vmat.val[3]); +} + +CGLM_INLINE +void +glm_mat4_mul_neon(mat4 m1, mat4 m2, mat4 dest) { + /* D = R * L (Column-Major) */ + + glmm_128 l, r0, r1, r2, r3, v0, v1, v2, v3; + + l = glmm_load(m1[0]); + r0 = glmm_load(m2[0]); + r1 = glmm_load(m2[1]); + r2 = glmm_load(m2[2]); + r3 = glmm_load(m2[3]); + + v0 = vmulq_f32(glmm_splat_x(r0), l); + v1 = vmulq_f32(glmm_splat_x(r1), l); + v2 = vmulq_f32(glmm_splat_x(r2), l); + v3 = vmulq_f32(glmm_splat_x(r3), l); + + l = glmm_load(m1[1]); + v0 = glmm_fmadd(glmm_splat_y(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_y(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_y(r2), l, v2); + v3 = glmm_fmadd(glmm_splat_y(r3), l, v3); + + l = glmm_load(m1[2]); + v0 = glmm_fmadd(glmm_splat_z(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_z(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_z(r2), l, v2); + v3 = glmm_fmadd(glmm_splat_z(r3), l, v3); + + l = glmm_load(m1[3]); + v0 = glmm_fmadd(glmm_splat_w(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_w(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_w(r2), l, v2); + v3 = glmm_fmadd(glmm_splat_w(r3), l, v3); + + glmm_store(dest[0], v0); + glmm_store(dest[1], v1); + glmm_store(dest[2], v2); + glmm_store(dest[3], v3); +} + +CGLM_INLINE +void +glm_mat4_mulv_neon(mat4 m, vec4 v, vec4 dest) { + float32x4_t l0, l1, l2, l3; + float32x2_t vlo, vhi; + + l0 = vld1q_f32(m[0]); + l1 = vld1q_f32(m[1]); + l2 = vld1q_f32(m[2]); + l3 = vld1q_f32(m[3]); + + vlo = vld1_f32(&v[0]); + vhi = vld1_f32(&v[2]); + + l0 = vmulq_lane_f32(l0, vlo, 0); + l0 = vmlaq_lane_f32(l0, l1, vlo, 1); + l0 = vmlaq_lane_f32(l0, l2, vhi, 0); + l0 = vmlaq_lane_f32(l0, l3, vhi, 1); + + vst1q_f32(dest, l0); +} + +CGLM_INLINE +float +glm_mat4_det_neon(mat4 mat) { + float32x4_t r0, r1, r2, r3, x0, x1, x2; + float32x2_t ij, op, mn, kl, nn, mm, jj, ii, gh, ef, t12, t34; + float32x4x2_t a1; + float32x4_t x3 = { 0.f, -0.f, 0.f, -0.f }; + + /* 127 <- 0, [square] det(A) = det(At) */ + r0 = glmm_load(mat[0]); /* d c b a */ + r1 = vrev64q_f32(glmm_load(mat[1])); /* g h e f */ + r2 = vrev64q_f32(glmm_load(mat[2])); /* l k i j */ + r3 = vrev64q_f32(glmm_load(mat[3])); /* o p m n */ + + gh = vget_high_f32(r1); + ef = vget_low_f32(r1); + kl = vget_high_f32(r2); + ij = vget_low_f32(r2); + op = vget_high_f32(r3); + mn = vget_low_f32(r3); + mm = vdup_lane_f32(mn, 1); + nn = vdup_lane_f32(mn, 0); + ii = vdup_lane_f32(ij, 1); + jj = vdup_lane_f32(ij, 0); + + /* + t[1] = j * p - n * l; + t[2] = j * o - n * k; + t[3] = i * p - m * l; + t[4] = i * o - m * k; + */ + x0 = glmm_fnmadd(vcombine_f32(kl, kl), vcombine_f32(nn, mm), + vmulq_f32(vcombine_f32(op, op), vcombine_f32(jj, ii))); + + t12 = vget_low_f32(x0); + t34 = vget_high_f32(x0); + + /* 1 3 1 3 2 4 2 4 */ + a1 = vuzpq_f32(x0, x0); + + /* + 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 = glmm_fnmadd(vcombine_f32(vdup_lane_f32(kl, 0), jj), + vcombine_f32(vdup_lane_f32(op, 1), mm), + vmulq_f32(vcombine_f32(vdup_lane_f32(op, 0), nn), + vcombine_f32(vdup_lane_f32(kl, 1), ii))); + + /* + a * (f * t[0] - g * t[1] + h * t[2]) + - b * (e * t[0] - g * t[3] + h * t[4]) + + c * (e * t[1] - f * t[3] + h * t[5]) + - d * (e * t[2] - f * t[4] + g * t[5]) + */ + x2 = glmm_fnmadd(vcombine_f32(vdup_lane_f32(gh, 1), vdup_lane_f32(ef, 0)), + vcombine_f32(vget_low_f32(a1.val[0]), t34), + vmulq_f32(vcombine_f32(ef, vdup_lane_f32(ef, 1)), + vcombine_f32(vget_low_f32(x1), t12))); + + x2 = glmm_fmadd(vcombine_f32(vdup_lane_f32(gh, 0), gh), + vcombine_f32(vget_low_f32(a1.val[1]), vget_high_f32(x1)), x2); + + x2 = glmm_xor(x2, x3); + + return glmm_hadd(vmulq_f32(x2, r0)); +} + +CGLM_INLINE +void +glm_mat4_inv_neon(mat4 mat, mat4 dest) { + float32x4_t r0, r1, r2, r3, + v0, v1, v2, v3, + t0, t1, t2, t3, t4, t5, + x0, x1, x2, x3, x4, x5, x6, x7, x8; + float32x4x2_t a1; + float32x2_t lp, ko, hg, jn, im, fe, ae, bf, cg, dh; + float32x4_t x9 = { -0.f, 0.f, -0.f, 0.f }; + + x8 = vrev64q_f32(x9); + + /* 127 <- 0 */ + 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 */ + + /* l p k o, j n i m */ + a1 = vzipq_f32(r3, r2); + + jn = vget_high_f32(a1.val[0]); + im = vget_low_f32(a1.val[0]); + lp = vget_high_f32(a1.val[1]); + ko = vget_low_f32(a1.val[1]); + hg = vget_high_f32(r1); + + x1 = vcombine_f32(vdup_lane_f32(lp, 0), lp); /* l p p p */ + x2 = vcombine_f32(vdup_lane_f32(ko, 0), ko); /* k o o o */ + x0 = vcombine_f32(vdup_lane_f32(lp, 1), vdup_lane_f32(hg, 1)); /* h h l l */ + x3 = vcombine_f32(vdup_lane_f32(ko, 1), vdup_lane_f32(hg, 0)); /* g g k k */ + + /* t1[0] = k * p - o * l; + t1[0] = k * p - o * l; + t2[0] = g * p - o * h; + t3[0] = g * l - k * h; */ + t0 = glmm_fnmadd(x2, x0, vmulq_f32(x3, x1)); + + fe = vget_low_f32(r1); + x4 = vcombine_f32(vdup_lane_f32(jn, 0), jn); /* j n n n */ + x5 = vcombine_f32(vdup_lane_f32(jn, 1), vdup_lane_f32(fe, 1)); /* f f j j */ + + /* t1[1] = j * p - n * l; + t1[1] = j * p - n * l; + t2[1] = f * p - n * h; + t3[1] = f * l - j * h; */ + t1 = glmm_fnmadd(x4, x0, vmulq_f32(x5, x1)); + + /* t1[2] = j * o - n * k + t1[2] = j * o - n * k; + t2[2] = f * o - n * g; + t3[2] = f * k - j * g; */ + t2 = glmm_fnmadd(x4, x3, vmulq_f32(x5, x2)); + + x6 = vcombine_f32(vdup_lane_f32(im, 1), vdup_lane_f32(fe, 0)); /* e e i i */ + x7 = vcombine_f32(vdup_lane_f32(im, 0), im); /* i m m m */ + + /* t1[3] = i * p - m * l; + t1[3] = i * p - m * l; + t2[3] = e * p - m * h; + t3[3] = e * l - i * h; */ + t3 = glmm_fnmadd(x7, x0, vmulq_f32(x6, x1)); + + /* t1[4] = i * o - m * k; + t1[4] = i * o - m * k; + t2[4] = e * o - m * g; + t3[4] = e * k - i * g; */ + t4 = glmm_fnmadd(x7, x3, vmulq_f32(x6, x2)); + + /* t1[5] = i * n - m * j; + t1[5] = i * n - m * j; + t2[5] = e * n - m * f; + t3[5] = e * j - i * f; */ + t5 = glmm_fnmadd(x7, x5, vmulq_f32(x6, x4)); + + /* h d f b, g c e a */ + a1 = vtrnq_f32(r0, r1); + + x4 = vrev64q_f32(a1.val[0]); /* c g a e */ + x5 = vrev64q_f32(a1.val[1]); /* d h b f */ + + ae = vget_low_f32(x4); + cg = vget_high_f32(x4); + bf = vget_low_f32(x5); + dh = vget_high_f32(x5); + + x0 = vcombine_f32(ae, vdup_lane_f32(ae, 1)); /* a a a e */ + x1 = vcombine_f32(bf, vdup_lane_f32(bf, 1)); /* b b b f */ + x2 = vcombine_f32(cg, vdup_lane_f32(cg, 1)); /* c c c g */ + x3 = vcombine_f32(dh, vdup_lane_f32(dh, 1)); /* d d d h */ + + /* + dest[0][0] = f * t1[0] - g * t1[1] + h * t1[2]; + dest[0][1] =-(b * t1[0] - c * t1[1] + d * t1[2]); + dest[0][2] = b * t2[0] - c * t2[1] + d * t2[2]; + dest[0][3] =-(b * t3[0] - c * t3[1] + d * t3[2]); */ + v0 = glmm_xor(glmm_fmadd(x3, t2, glmm_fnmadd(x2, t1, vmulq_f32(x1, t0))), x8); + + /* + dest[2][0] = e * t1[1] - f * t1[3] + h * t1[5]; + dest[2][1] =-(a * t1[1] - b * t1[3] + d * t1[5]); + dest[2][2] = a * t2[1] - b * t2[3] + d * t2[5]; + dest[2][3] =-(a * t3[1] - b * t3[3] + d * t3[5]);*/ + v2 = glmm_xor(glmm_fmadd(x3, t5, glmm_fnmadd(x1, t3, vmulq_f32(x0, t1))), x8); + + /* + dest[1][0] =-(e * t1[0] - g * t1[3] + h * t1[4]); + dest[1][1] = a * t1[0] - c * t1[3] + d * t1[4]; + dest[1][2] =-(a * t2[0] - c * t2[3] + d * t2[4]); + dest[1][3] = a * t3[0] - c * t3[3] + d * t3[4]; */ + v1 = glmm_xor(glmm_fmadd(x3, t4, glmm_fnmadd(x2, t3, vmulq_f32(x0, t0))), x9); + + /* + dest[3][0] =-(e * t1[2] - f * t1[4] + g * t1[5]); + dest[3][1] = a * t1[2] - b * t1[4] + c * t1[5]; + dest[3][2] =-(a * t2[2] - b * t2[4] + c * t2[5]); + dest[3][3] = a * t3[2] - b * t3[4] + c * t3[5]; */ + v3 = glmm_xor(glmm_fmadd(x2, t5, glmm_fnmadd(x1, t4, vmulq_f32(x0, t2))), x9); + + /* determinant */ + x0 = vcombine_f32(vget_low_f32(vzipq_f32(v0, v1).val[0]), + vget_low_f32(vzipq_f32(v2, v3).val[0])); + + /* + x0 = glmm_div(glmm_set1(1.0f), glmm_vhadd(vmulq_f32(x0, r0))); + + glmm_store(dest[0], vmulq_f32(v0, x0)); + glmm_store(dest[1], vmulq_f32(v1, x0)); + glmm_store(dest[2], vmulq_f32(v2, x0)); + glmm_store(dest[3], vmulq_f32(v3, x0)); + */ + + x0 = glmm_vhadd(vmulq_f32(x0, r0)); + + glmm_store(dest[0], glmm_div(v0, x0)); + glmm_store(dest[1], glmm_div(v1, x0)); + glmm_store(dest[2], glmm_div(v2, x0)); + glmm_store(dest[3], glmm_div(v3, x0)); +} + +#endif +#endif /* cglm_mat4_neon_h */ diff --git a/libs/cglm/include/cglm/simd/neon/quat.h b/libs/cglm/include/cglm/simd/neon/quat.h new file mode 100644 index 0000000..f6b9e99 --- /dev/null +++ b/libs/cglm/include/cglm/simd/neon/quat.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_quat_neon_h +#define cglm_quat_neon_h +#if defined(__ARM_NEON_FP) + +#include "../../common.h" +#include "../intrin.h" + +CGLM_INLINE +void +glm_quat_mul_neon(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 + */ + + glmm_128 xp, xq, xqr, r, x, y, z, s2, s3; + glmm_128 s1 = {-0.f, 0.f, 0.f, -0.f}; + float32x2_t qh, ql; + + xp = glmm_load(p); /* 3 2 1 0 */ + xq = glmm_load(q); + + r = vmulq_f32(glmm_splat_w(xp), xq); + x = glmm_splat_x(xp); + y = glmm_splat_y(xp); + z = glmm_splat_z(xp); + + ql = vget_high_f32(s1); + s3 = vcombine_f32(ql, ql); + s2 = vzipq_f32(s3, s3).val[0]; + + xqr = vrev64q_f32(xq); + qh = vget_high_f32(xqr); + ql = vget_low_f32(xqr); + + r = glmm_fmadd(glmm_xor(x, s3), vcombine_f32(qh, ql), r); + + r = glmm_fmadd(glmm_xor(y, s2), vcombine_f32(vget_high_f32(xq), + vget_low_f32(xq)), r); + + r = glmm_fmadd(glmm_xor(z, s1), vcombine_f32(ql, qh), r); + + glmm_store(dest, r); +} + +#endif +#endif /* cglm_quat_neon_h */ diff --git a/libs/cglm/include/cglm/simd/sse2/affine.h b/libs/cglm/include/cglm/simd/sse2/affine.h new file mode 100644 index 0000000..99edaa0 --- /dev/null +++ b/libs/cglm/include/cglm/simd/sse2/affine.h @@ -0,0 +1,115 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_affine_mat_sse2_h +#define cglm_affine_mat_sse2_h +#if defined( __SSE__ ) || defined( __SSE2__ ) + +#include "../../common.h" +#include "../intrin.h" + +CGLM_INLINE +void +glm_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { + /* D = R * L (Column-Major) */ + glmm_128 l, r0, r1, r2, r3, v0, v1, v2, v3; + + l = glmm_load(m1[0]); + r0 = glmm_load(m2[0]); + r1 = glmm_load(m2[1]); + r2 = glmm_load(m2[2]); + r3 = glmm_load(m2[3]); + + v0 = _mm_mul_ps(glmm_splat_x(r0), l); + v1 = _mm_mul_ps(glmm_splat_x(r1), l); + v2 = _mm_mul_ps(glmm_splat_x(r2), l); + v3 = _mm_mul_ps(glmm_splat_x(r3), l); + + l = glmm_load(m1[1]); + v0 = glmm_fmadd(glmm_splat_y(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_y(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_y(r2), l, v2); + v3 = glmm_fmadd(glmm_splat_y(r3), l, v3); + + l = glmm_load(m1[2]); + v0 = glmm_fmadd(glmm_splat_z(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_z(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_z(r2), l, v2); + v3 = glmm_fmadd(glmm_splat_z(r3), l, v3); + + l = glmm_load(m1[3]); + v3 = glmm_fmadd(glmm_splat_w(r3), l, v3); + + glmm_store(dest[0], v0); + glmm_store(dest[1], v1); + glmm_store(dest[2], v2); + glmm_store(dest[3], v3); +} + +CGLM_INLINE +void +glm_mul_rot_sse2(mat4 m1, mat4 m2, mat4 dest) { + /* D = R * L (Column-Major) */ + + glmm_128 l, r0, r1, r2, v0, v1, v2; + + l = glmm_load(m1[0]); + r0 = glmm_load(m2[0]); + r1 = glmm_load(m2[1]); + r2 = glmm_load(m2[2]); + + v0 = _mm_mul_ps(glmm_splat_x(r0), l); + v1 = _mm_mul_ps(glmm_splat_x(r1), l); + v2 = _mm_mul_ps(glmm_splat_x(r2), l); + + l = glmm_load(m1[1]); + v0 = glmm_fmadd(glmm_splat_y(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_y(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_y(r2), l, v2); + + l = glmm_load(m1[2]); + v0 = glmm_fmadd(glmm_splat_z(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_z(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_z(r2), l, v2); + + glmm_store(dest[0], v0); + glmm_store(dest[1], v1); + glmm_store(dest[2], v2); + glmm_store(dest[3], glmm_load(m1[3])); +} + +CGLM_INLINE +void +glm_inv_tr_sse2(mat4 mat) { + __m128 r0, r1, r2, r3, x0, x1, x2, x3, x4, x5; + + 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); + + x2 = glmm_shuff1(r3, 0, 0, 0, 0); + x3 = glmm_shuff1(r3, 1, 1, 1, 1); + x4 = glmm_shuff1(r3, 2, 2, 2, 2); + x5 = _mm_set1_ps(-0.f); + + x0 = glmm_fmadd(r0, x2, glmm_fmadd(r1, x3, _mm_mul_ps(r2, x4))); + x0 = _mm_xor_ps(x0, x5); + + x0 = _mm_add_ps(x0, x1); + + glmm_store(mat[0], r0); + glmm_store(mat[1], r1); + glmm_store(mat[2], r2); + glmm_store(mat[3], x0); +} + +#endif +#endif /* cglm_affine_mat_sse2_h */ diff --git a/libs/cglm/include/cglm/simd/sse2/mat2.h b/libs/cglm/include/cglm/simd/sse2/mat2.h new file mode 100644 index 0000000..31b3a29 --- /dev/null +++ b/libs/cglm/include/cglm/simd/sse2/mat2.h @@ -0,0 +1,48 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_mat2_sse_h +#define cglm_mat2_sse_h +#if defined( __SSE__ ) || defined( __SSE2__ ) + +#include "../../common.h" +#include "../intrin.h" + +CGLM_INLINE +void +glm_mat2_mul_sse2(mat2 m1, mat2 m2, mat2 dest) { + __m128 x0, x1, x2, x3, x4; + + x1 = glmm_load(m1[0]); /* d c b a */ + x2 = glmm_load(m2[0]); /* h g f e */ + + x3 = glmm_shuff1(x2, 2, 2, 0, 0); + x4 = glmm_shuff1(x2, 3, 3, 1, 1); + x0 = _mm_movelh_ps(x1, x1); + x2 = _mm_movehl_ps(x1, x1); + + /* + dest[0][0] = a * e + c * f; + dest[0][1] = b * e + d * f; + dest[1][0] = a * g + c * h; + dest[1][1] = b * g + d * h; + */ + x0 = glmm_fmadd(x0, x3, _mm_mul_ps(x2, x4)); + + glmm_store(dest[0], x0); +} + +CGLM_INLINE +void +glm_mat2_transp_sse2(mat2 m, mat2 dest) { + /* d c b a */ + /* d b c a */ + glmm_store(dest[0], glmm_shuff1(glmm_load(m[0]), 3, 1, 2, 0)); +} + +#endif +#endif /* cglm_mat2_sse_h */ diff --git a/libs/cglm/include/cglm/simd/sse2/mat3.h b/libs/cglm/include/cglm/simd/sse2/mat3.h new file mode 100644 index 0000000..f07320c --- /dev/null +++ b/libs/cglm/include/cglm/simd/sse2/mat3.h @@ -0,0 +1,76 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_mat3_sse_h +#define cglm_mat3_sse_h +#if defined( __SSE__ ) || defined( __SSE2__ ) + +#include "../../common.h" +#include "../intrin.h" + +CGLM_INLINE +void +glm_mat3_mul_sse2(mat3 m1, mat3 m2, mat3 dest) { + __m128 l0, l1, l2, r0, r1, r2, x0, x1, x2, x3, x4, x5, x6, x7, x8, x9; + + l0 = _mm_loadu_ps(m1[0]); + l1 = _mm_loadu_ps(&m1[1][1]); + + r0 = _mm_loadu_ps(m2[0]); + r1 = _mm_loadu_ps(&m2[1][1]); + + x8 = glmm_shuff1(l0, 0, 2, 1, 0); /* a00 a02 a01 a00 */ + x1 = glmm_shuff1(r0, 3, 0, 0, 0); /* b10 b00 b00 b00 */ + x2 = _mm_shuffle_ps(l0, l1, _MM_SHUFFLE(1, 0, 3, 3)); /* a12 a11 a10 a10 */ + x3 = _mm_shuffle_ps(r0, r1, _MM_SHUFFLE(2, 0, 3, 1)); /* b20 b11 b10 b01 */ + x0 = _mm_mul_ps(x8, x1); + + x6 = glmm_shuff1(l0, 1, 0, 2, 1); /* a01 a00 a02 a01 */ + x7 = glmm_shuff1(x3, 3, 3, 1, 1); /* b20 b20 b10 b10 */ + l2 = _mm_load_ss(&m1[2][2]); + r2 = _mm_load_ss(&m2[2][2]); + x1 = _mm_mul_ps(x6, x7); + l2 = glmm_shuff1(l2, 0, 0, 1, 0); /* a22 a22 0.f a22 */ + r2 = glmm_shuff1(r2, 0, 0, 1, 0); /* b22 b22 0.f b22 */ + + x4 = glmm_shuff1(x2, 0, 3, 2, 0); /* a10 a12 a11 a10 */ + x5 = glmm_shuff1(x2, 2, 0, 3, 2); /* a11 a10 a12 a11 */ + x6 = glmm_shuff1(x3, 2, 0, 0, 0); /* b11 b01 b01 b01 */ + x2 = glmm_shuff1(r1, 3, 3, 0, 0); /* b21 b21 b11 b11 */ + + x8 = _mm_unpackhi_ps(x8, x4); /* a10 a00 a12 a02 */ + x9 = _mm_unpackhi_ps(x7, x2); /* b21 b20 b21 b20 */ + + x0 = glmm_fmadd(x4, x6, x0); + x1 = glmm_fmadd(x5, x2, x1); + + x2 = _mm_movehl_ps(l2, l1); /* a22 a22 a21 a20 */ + x3 = glmm_shuff1(x2, 0, 2, 1, 0); /* a20 a22 a21 a20 */ + x2 = glmm_shuff1(x2, 1, 0, 2, 1); /* a21 a20 a22 a21 */ + x4 = _mm_shuffle_ps(r0, r1, _MM_SHUFFLE(1, 1, 2, 2)); /* b12 b12 b02 b02 */ + + x5 = glmm_shuff1(x4, 3, 0, 0, 0); /* b12 b02 b02 b02 */ + x4 = _mm_movehl_ps(r2, x4); /* b22 b22 b12 b12 */ + x0 = glmm_fmadd(x3, x5, x0); + x1 = glmm_fmadd(x2, x4, x1); + + /* + Dot Product : dest[2][2] = a02 * b20 + + a12 * b21 + + a22 * b22 + + 0 * 00 */ + x2 = _mm_movelh_ps(x8, l2); /* 0.f a22 a12 a02 */ + x3 = _mm_movelh_ps(x9, r2); /* 0.f b22 b21 b20 */ + x2 = glmm_vdots(x2, x3); + + _mm_storeu_ps(&dest[0][0], x0); + _mm_storeu_ps(&dest[1][1], x1); + _mm_store_ss (&dest[2][2], x2); +} + +#endif +#endif /* cglm_mat3_sse_h */ diff --git a/libs/cglm/include/cglm/simd/sse2/mat4.h b/libs/cglm/include/cglm/simd/sse2/mat4.h new file mode 100644 index 0000000..5c78499 --- /dev/null +++ b/libs/cglm/include/cglm/simd/sse2/mat4.h @@ -0,0 +1,434 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_mat_sse_h +#define cglm_mat_sse_h +#if defined( __SSE__ ) || defined( __SSE2__ ) + +#include "../../common.h" +#include "../intrin.h" + +#define glm_mat4_inv_precise_sse2(mat, dest) glm_mat4_inv_sse2(mat, dest) + +CGLM_INLINE +void +glm_mat4_scale_sse2(mat4 m, float s) { + __m128 x0; + x0 = _mm_set1_ps(s); + + 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 +void +glm_mat4_transp_sse2(mat4 m, mat4 dest) { + __m128 r0, r1, r2, r3; + + 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); + + glmm_store(dest[0], r0); + glmm_store(dest[1], r1); + glmm_store(dest[2], r2); + glmm_store(dest[3], r3); +} + +CGLM_INLINE +void +glm_mat4_mul_sse2(mat4 m1, mat4 m2, mat4 dest) { + /* D = R * L (Column-Major) */ + + glmm_128 l, r0, r1, r2, r3, v0, v1, v2, v3; + + l = glmm_load(m1[0]); + r0 = glmm_load(m2[0]); + r1 = glmm_load(m2[1]); + r2 = glmm_load(m2[2]); + r3 = glmm_load(m2[3]); + + v0 = _mm_mul_ps(glmm_splat_x(r0), l); + v1 = _mm_mul_ps(glmm_splat_x(r1), l); + v2 = _mm_mul_ps(glmm_splat_x(r2), l); + v3 = _mm_mul_ps(glmm_splat_x(r3), l); + + l = glmm_load(m1[1]); + v0 = glmm_fmadd(glmm_splat_y(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_y(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_y(r2), l, v2); + v3 = glmm_fmadd(glmm_splat_y(r3), l, v3); + + l = glmm_load(m1[2]); + v0 = glmm_fmadd(glmm_splat_z(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_z(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_z(r2), l, v2); + v3 = glmm_fmadd(glmm_splat_z(r3), l, v3); + + l = glmm_load(m1[3]); + v0 = glmm_fmadd(glmm_splat_w(r0), l, v0); + v1 = glmm_fmadd(glmm_splat_w(r1), l, v1); + v2 = glmm_fmadd(glmm_splat_w(r2), l, v2); + v3 = glmm_fmadd(glmm_splat_w(r3), l, v3); + + glmm_store(dest[0], v0); + glmm_store(dest[1], v1); + glmm_store(dest[2], v2); + glmm_store(dest[3], v3); +} + +CGLM_INLINE +void +glm_mat4_mulv_sse2(mat4 m, vec4 v, vec4 dest) { + __m128 x0, x1, m0, m1, m2, m3, v0, v1, v2, v3; + + m0 = glmm_load(m[0]); + m1 = glmm_load(m[1]); + m2 = glmm_load(m[2]); + m3 = glmm_load(m[3]); + + x0 = glmm_load(v); + v0 = glmm_splat_x(x0); + v1 = glmm_splat_y(x0); + v2 = glmm_splat_z(x0); + v3 = glmm_splat_w(x0); + + x1 = _mm_mul_ps(m3, v3); + x1 = glmm_fmadd(m2, v2, x1); + x1 = glmm_fmadd(m1, v1, x1); + x1 = glmm_fmadd(m0, v0, x1); + + glmm_store(dest, x1); +} + +CGLM_INLINE +float +glm_mat4_det_sse2(mat4 mat) { + __m128 r0, r1, r2, r3, x0, x1, x2; + + /* 127 <- 0, [square] det(A) = det(At) */ + 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; + t[2] = j * o - n * k; + t[3] = i * p - m * l; + t[4] = i * o - m * k; + */ + x0 = glmm_fnmadd(glmm_shuff1(r3, 0, 0, 1, 1), glmm_shuff1(r2, 2, 3, 2, 3), + _mm_mul_ps(glmm_shuff1(r2, 0, 0, 1, 1), + glmm_shuff1(r3, 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 = glmm_fnmadd(glmm_shuff1(r3, 0, 0, 2, 2), glmm_shuff1(r2, 1, 1, 3, 3), + _mm_mul_ps(glmm_shuff1(r2, 0, 0, 2, 2), + glmm_shuff1(r3, 1, 1, 3, 3))); + + /* + a * (f * t[0] - g * t[1] + h * t[2]) + - b * (e * t[0] - g * t[3] + h * t[4]) + + c * (e * t[1] - f * t[3] + h * t[5]) + - d * (e * t[2] - f * t[4] + g * t[5]) + */ + x2 = glmm_fnmadd(glmm_shuff1(r1, 1, 1, 2, 2), glmm_shuff1(x0, 3, 2, 2, 0), + _mm_mul_ps(glmm_shuff1(r1, 0, 0, 0, 1), + _mm_shuffle_ps(x1, x0, _MM_SHUFFLE(1, 0, 0, 0)))); + x2 = glmm_fmadd(glmm_shuff1(r1, 2, 3, 3, 3), + _mm_shuffle_ps(x0, x1, _MM_SHUFFLE(2, 2, 3, 1)), + x2); + + x2 = _mm_xor_ps(x2, _mm_set_ps(-0.f, 0.f, -0.f, 0.f)); + + return glmm_hadd(_mm_mul_ps(x2, r0)); +} + +CGLM_INLINE +void +glm_mat4_inv_fast_sse2(mat4 mat, mat4 dest) { + __m128 r0, r1, r2, r3, + v0, v1, v2, v3, + t0, t1, t2, t3, t4, t5, + x0, x1, x2, x3, x4, x5, x6, x7, x8, x9; + + x8 = _mm_set_ps(-0.f, 0.f, -0.f, 0.f); + x9 = glmm_shuff1(x8, 2, 1, 2, 1); + + /* 127 <- 0 */ + 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_movehl_ps(r3, r2); /* p o l k */ + x3 = _mm_movelh_ps(r2, r3); /* n m j i */ + x1 = glmm_shuff1(x0, 1, 3, 3 ,3); /* l p p p */ + x2 = glmm_shuff1(x0, 0, 2, 2, 2); /* k o o o */ + x4 = glmm_shuff1(x3, 1, 3, 3, 3); /* j n n n */ + x7 = glmm_shuff1(x3, 0, 2, 2, 2); /* i m m m */ + + x6 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(0, 0, 0, 0)); /* e e i i */ + x5 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(1, 1, 1, 1)); /* f f j j */ + x3 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(2, 2, 2, 2)); /* g g k k */ + x0 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(3, 3, 3, 3)); /* h h l l */ + + t0 = _mm_mul_ps(x3, x1); + t1 = _mm_mul_ps(x5, x1); + t2 = _mm_mul_ps(x5, x2); + t3 = _mm_mul_ps(x6, x1); + t4 = _mm_mul_ps(x6, x2); + t5 = _mm_mul_ps(x6, x4); + + /* t1[0] = k * p - o * l; + t1[0] = k * p - o * l; + t2[0] = g * p - o * h; + t3[0] = g * l - k * h; */ + t0 = glmm_fnmadd(x2, x0, t0); + + /* t1[1] = j * p - n * l; + t1[1] = j * p - n * l; + t2[1] = f * p - n * h; + t3[1] = f * l - j * h; */ + t1 = glmm_fnmadd(x4, x0, t1); + + /* t1[2] = j * o - n * k + t1[2] = j * o - n * k; + t2[2] = f * o - n * g; + t3[2] = f * k - j * g; */ + t2 = glmm_fnmadd(x4, x3, t2); + + /* t1[3] = i * p - m * l; + t1[3] = i * p - m * l; + t2[3] = e * p - m * h; + t3[3] = e * l - i * h; */ + t3 = glmm_fnmadd(x7, x0, t3); + + /* t1[4] = i * o - m * k; + t1[4] = i * o - m * k; + t2[4] = e * o - m * g; + t3[4] = e * k - i * g; */ + t4 = glmm_fnmadd(x7, x3, t4); + + /* t1[5] = i * n - m * j; + t1[5] = i * n - m * j; + t2[5] = e * n - m * f; + t3[5] = e * j - i * f; */ + t5 = glmm_fnmadd(x7, x5, t5); + + x4 = _mm_movelh_ps(r0, r1); /* f e b a */ + x5 = _mm_movehl_ps(r1, r0); /* h g d c */ + + x0 = glmm_shuff1(x4, 0, 0, 0, 2); /* a a a e */ + x1 = glmm_shuff1(x4, 1, 1, 1, 3); /* b b b f */ + x2 = glmm_shuff1(x5, 0, 0, 0, 2); /* c c c g */ + x3 = glmm_shuff1(x5, 1, 1, 1, 3); /* d d d h */ + + v2 = _mm_mul_ps(x0, t1); + v1 = _mm_mul_ps(x0, t0); + v3 = _mm_mul_ps(x0, t2); + v0 = _mm_mul_ps(x1, t0); + + v2 = glmm_fnmadd(x1, t3, v2); + v3 = glmm_fnmadd(x1, t4, v3); + v0 = glmm_fnmadd(x2, t1, v0); + v1 = glmm_fnmadd(x2, t3, v1); + + v3 = glmm_fmadd(x2, t5, v3); + v0 = glmm_fmadd(x3, t2, v0); + v2 = glmm_fmadd(x3, t5, v2); + v1 = glmm_fmadd(x3, t4, v1); + + /* + dest[0][0] = f * t1[0] - g * t1[1] + h * t1[2]; + dest[0][1] =-(b * t1[0] - c * t1[1] + d * t1[2]); + dest[0][2] = b * t2[0] - c * t2[1] + d * t2[2]; + dest[0][3] =-(b * t3[0] - c * t3[1] + d * t3[2]); */ + v0 = _mm_xor_ps(v0, x8); + + /* + dest[2][0] = e * t1[1] - f * t1[3] + h * t1[5]; + dest[2][1] =-(a * t1[1] - b * t1[3] + d * t1[5]); + dest[2][2] = a * t2[1] - b * t2[3] + d * t2[5]; + dest[2][3] =-(a * t3[1] - b * t3[3] + d * t3[5]);*/ + v2 = _mm_xor_ps(v2, x8); + + /* + dest[1][0] =-(e * t1[0] - g * t1[3] + h * t1[4]); + dest[1][1] = a * t1[0] - c * t1[3] + d * t1[4]; + dest[1][2] =-(a * t2[0] - c * t2[3] + d * t2[4]); + dest[1][3] = a * t3[0] - c * t3[3] + d * t3[4]; */ + v1 = _mm_xor_ps(v1, x9); + + /* + dest[3][0] =-(e * t1[2] - f * t1[4] + g * t1[5]); + dest[3][1] = a * t1[2] - b * t1[4] + c * t1[5]; + dest[3][2] =-(a * t2[2] - b * t2[4] + c * t2[5]); + dest[3][3] = a * t3[2] - b * t3[4] + c * t3[5]; */ + v3 = _mm_xor_ps(v3, x9); + + /* determinant */ + x0 = _mm_shuffle_ps(v0, v1, _MM_SHUFFLE(0, 0, 0, 0)); + x1 = _mm_shuffle_ps(v2, v3, _MM_SHUFFLE(0, 0, 0, 0)); + x0 = _mm_shuffle_ps(x0, x1, _MM_SHUFFLE(2, 0, 2, 0)); + + x0 = _mm_rcp_ps(glmm_vhadd(_mm_mul_ps(x0, r0))); + + 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 +void +glm_mat4_inv_sse2(mat4 mat, mat4 dest) { + __m128 r0, r1, r2, r3, + v0, v1, v2, v3, + t0, t1, t2, t3, t4, t5, + x0, x1, x2, x3, x4, x5, x6, x7, x8, x9; + + x8 = _mm_set_ps(-0.f, 0.f, -0.f, 0.f); + x9 = glmm_shuff1(x8, 2, 1, 2, 1); + + /* 127 <- 0 */ + 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_movehl_ps(r3, r2); /* p o l k */ + x3 = _mm_movelh_ps(r2, r3); /* n m j i */ + x1 = glmm_shuff1(x0, 1, 3, 3 ,3); /* l p p p */ + x2 = glmm_shuff1(x0, 0, 2, 2, 2); /* k o o o */ + x4 = glmm_shuff1(x3, 1, 3, 3, 3); /* j n n n */ + x7 = glmm_shuff1(x3, 0, 2, 2, 2); /* i m m m */ + + x6 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(0, 0, 0, 0)); /* e e i i */ + x5 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(1, 1, 1, 1)); /* f f j j */ + x3 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(2, 2, 2, 2)); /* g g k k */ + x0 = _mm_shuffle_ps(r2, r1, _MM_SHUFFLE(3, 3, 3, 3)); /* h h l l */ + + t0 = _mm_mul_ps(x3, x1); + t1 = _mm_mul_ps(x5, x1); + t2 = _mm_mul_ps(x5, x2); + t3 = _mm_mul_ps(x6, x1); + t4 = _mm_mul_ps(x6, x2); + t5 = _mm_mul_ps(x6, x4); + + /* t1[0] = k * p - o * l; + t1[0] = k * p - o * l; + t2[0] = g * p - o * h; + t3[0] = g * l - k * h; */ + t0 = glmm_fnmadd(x2, x0, t0); + + /* t1[1] = j * p - n * l; + t1[1] = j * p - n * l; + t2[1] = f * p - n * h; + t3[1] = f * l - j * h; */ + t1 = glmm_fnmadd(x4, x0, t1); + + /* t1[2] = j * o - n * k + t1[2] = j * o - n * k; + t2[2] = f * o - n * g; + t3[2] = f * k - j * g; */ + t2 = glmm_fnmadd(x4, x3, t2); + + /* t1[3] = i * p - m * l; + t1[3] = i * p - m * l; + t2[3] = e * p - m * h; + t3[3] = e * l - i * h; */ + t3 = glmm_fnmadd(x7, x0, t3); + + /* t1[4] = i * o - m * k; + t1[4] = i * o - m * k; + t2[4] = e * o - m * g; + t3[4] = e * k - i * g; */ + t4 = glmm_fnmadd(x7, x3, t4); + + /* t1[5] = i * n - m * j; + t1[5] = i * n - m * j; + t2[5] = e * n - m * f; + t3[5] = e * j - i * f; */ + t5 = glmm_fnmadd(x7, x5, t5); + + x4 = _mm_movelh_ps(r0, r1); /* f e b a */ + x5 = _mm_movehl_ps(r1, r0); /* h g d c */ + + x0 = glmm_shuff1(x4, 0, 0, 0, 2); /* a a a e */ + x1 = glmm_shuff1(x4, 1, 1, 1, 3); /* b b b f */ + x2 = glmm_shuff1(x5, 0, 0, 0, 2); /* c c c g */ + x3 = glmm_shuff1(x5, 1, 1, 1, 3); /* d d d h */ + + v2 = _mm_mul_ps(x0, t1); + v1 = _mm_mul_ps(x0, t0); + v3 = _mm_mul_ps(x0, t2); + v0 = _mm_mul_ps(x1, t0); + + v2 = glmm_fnmadd(x1, t3, v2); + v3 = glmm_fnmadd(x1, t4, v3); + v0 = glmm_fnmadd(x2, t1, v0); + v1 = glmm_fnmadd(x2, t3, v1); + + v3 = glmm_fmadd(x2, t5, v3); + v0 = glmm_fmadd(x3, t2, v0); + v2 = glmm_fmadd(x3, t5, v2); + v1 = glmm_fmadd(x3, t4, v1); + + /* + dest[0][0] = f * t1[0] - g * t1[1] + h * t1[2]; + dest[0][1] =-(b * t1[0] - c * t1[1] + d * t1[2]); + dest[0][2] = b * t2[0] - c * t2[1] + d * t2[2]; + dest[0][3] =-(b * t3[0] - c * t3[1] + d * t3[2]); */ + v0 = _mm_xor_ps(v0, x8); + + /* + dest[2][0] = e * t1[1] - f * t1[3] + h * t1[5]; + dest[2][1] =-(a * t1[1] - b * t1[3] + d * t1[5]); + dest[2][2] = a * t2[1] - b * t2[3] + d * t2[5]; + dest[2][3] =-(a * t3[1] - b * t3[3] + d * t3[5]);*/ + v2 = _mm_xor_ps(v2, x8); + + /* + dest[1][0] =-(e * t1[0] - g * t1[3] + h * t1[4]); + dest[1][1] = a * t1[0] - c * t1[3] + d * t1[4]; + dest[1][2] =-(a * t2[0] - c * t2[3] + d * t2[4]); + dest[1][3] = a * t3[0] - c * t3[3] + d * t3[4]; */ + v1 = _mm_xor_ps(v1, x9); + + /* + dest[3][0] =-(e * t1[2] - f * t1[4] + g * t1[5]); + dest[3][1] = a * t1[2] - b * t1[4] + c * t1[5]; + dest[3][2] =-(a * t2[2] - b * t2[4] + c * t2[5]); + dest[3][3] = a * t3[2] - b * t3[4] + c * t3[5]; */ + v3 = _mm_xor_ps(v3, x9); + + /* determinant */ + x0 = _mm_shuffle_ps(v0, v1, _MM_SHUFFLE(0, 0, 0, 0)); + x1 = _mm_shuffle_ps(v2, v3, _MM_SHUFFLE(0, 0, 0, 0)); + x0 = _mm_shuffle_ps(x0, x1, _MM_SHUFFLE(2, 0, 2, 0)); + + x0 = _mm_div_ps(_mm_set1_ps(1.0f), glmm_vhadd(_mm_mul_ps(x0, r0))); + + 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 +#endif /* cglm_mat_sse_h */ diff --git a/libs/cglm/include/cglm/simd/sse2/quat.h b/libs/cglm/include/cglm/simd/sse2/quat.h new file mode 100644 index 0000000..94850cc --- /dev/null +++ b/libs/cglm/include/cglm/simd/sse2/quat.h @@ -0,0 +1,54 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_quat_simd_h +#define cglm_quat_simd_h +#if defined( __SSE__ ) || defined( __SSE2__ ) + +#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, x1, x2, x3, r, x, y, z; + + xp = glmm_load(p); /* 3 2 1 0 */ + xq = glmm_load(q); + x1 = _mm_set_ps(-0.f, 0.f, -0.f, 0.f); /* TODO: _mm_set1_ss() + shuff ? */ + r = _mm_mul_ps(glmm_splat_w(xp), xq); + + x2 = _mm_unpackhi_ps(x1, x1); + x3 = glmm_shuff1(x1, 3, 2, 0, 1); + x = glmm_splat_x(xp); + y = glmm_splat_y(xp); + z = glmm_splat_z(xp); + + x = _mm_xor_ps(x, x1); + y = _mm_xor_ps(y, x2); + z = _mm_xor_ps(z, x3); + + x1 = glmm_shuff1(xq, 0, 1, 2, 3); + x2 = glmm_shuff1(xq, 1, 0, 3, 2); + x3 = glmm_shuff1(xq, 2, 3, 0, 1); + + r = glmm_fmadd(x, x1, r); + r = glmm_fmadd(y, x2, r); + r = glmm_fmadd(z, x3, r); + + glmm_store(dest, r); +} + +#endif +#endif /* cglm_quat_simd_h */ diff --git a/libs/cglm/include/cglm/simd/x86.h b/libs/cglm/include/cglm/simd/x86.h new file mode 100644 index 0000000..dbbd0f8 --- /dev/null +++ b/libs/cglm/include/cglm/simd/x86.h @@ -0,0 +1,307 @@ +/* + * 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 + +#define glmm_set1(x) _mm_set1_ps(x) +#define glmm_128 __m128 + +#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_splat(x, lane) glmm_shuff1(x, lane, lane, lane, lane) + +#define glmm_splat_x(x) glmm_splat(x, 0) +#define glmm_splat_y(x) glmm_splat(x, 1) +#define glmm_splat_z(x) glmm_splat(x, 2) +#define glmm_splat_w(x) glmm_splat(x, 3) + +/* glmm_shuff1x() is DEPRECATED!, use glmm_splat() */ +#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_abs(__m128 x) { + return _mm_andnot_ps(_mm_set1_ps(-0.0f), x); +} + +static inline +__m128 +glmm_vhadd(__m128 v) { + __m128 x0; + x0 = _mm_add_ps(v, glmm_shuff1(v, 0, 1, 2, 3)); + x0 = _mm_add_ps(x0, glmm_shuff1(x0, 1, 0, 0, 1)); + return x0; +} + +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_vhmin(__m128 v) { + __m128 x0, x1, x2; + x0 = _mm_movehl_ps(v, v); /* [2, 3, 2, 3] */ + x1 = _mm_min_ps(x0, v); /* [0|2, 1|3, 2|2, 3|3] */ + x2 = glmm_splat(x1, 1); /* [1|3, 1|3, 1|3, 1|3] */ + return _mm_min_ss(x1, x2); +} + +static inline +float +glmm_hmin(__m128 v) { + return _mm_cvtss_f32(glmm_vhmin(v)); +} + +static inline +__m128 +glmm_vhmax(__m128 v) { + __m128 x0, x1, x2; + x0 = _mm_movehl_ps(v, v); /* [2, 3, 2, 3] */ + x1 = _mm_max_ps(x0, v); /* [0|2, 1|3, 2|2, 3|3] */ + x2 = glmm_splat(x1, 1); /* [1|3, 1|3, 1|3, 1|3] */ + return _mm_max_ss(x1, x2); +} + +static inline +float +glmm_hmax(__m128 v) { + return _mm_cvtss_f32(glmm_vhmax(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(a, b, 0xFF); +#elif defined(__SSE3__) && defined(CGLM_SSE3_DOT) + __m128 x0, x1; + x0 = _mm_mul_ps(a, 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(a, b, 0xFF); +#elif defined(__SSE3__) && defined(CGLM_SSE3_DOT) + __m128 x0, x1; + x0 = _mm_mul_ps(a, 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 +float +glmm_norm2(__m128 a) { + return _mm_cvtss_f32(glmm_vhadds(_mm_mul_ps(a, a))); +} + +static inline +float +glmm_norm_one(__m128 a) { + return _mm_cvtss_f32(glmm_vhadds(glmm_abs(a))); +} + +static inline +float +glmm_norm_inf(__m128 a) { + return _mm_cvtss_f32(glmm_vhmax(glmm_abs(a))); +} + +static inline +__m128 +glmm_load3(float v[3]) { + __m128i xy; + __m128 z; + + xy = _mm_loadl_epi64(CGLM_CASTPTR_ASSUME_ALIGNED(v, const __m128i)); + z = _mm_load_ss(&v[2]); + + return _mm_movelh_ps(_mm_castsi128_ps(xy), z); +} + +static inline +void +glmm_store3(float v[3], __m128 vx) { + _mm_storel_pi(CGLM_CASTPTR_ASSUME_ALIGNED(v, __m64), vx); + _mm_store_ss(&v[2], glmm_shuff1(vx, 2, 2, 2, 2)); +} + +static inline +__m128 +glmm_div(__m128 a, __m128 b) { + return _mm_div_ps(a, b); +} + +/* enable FMA macro for MSVC? */ +#if defined(_MSC_VER) && !defined(__FMA__) && defined(__AVX2__) +# define __FMA__ 1 +#endif + +static inline +__m128 +glmm_fmadd(__m128 a, __m128 b, __m128 c) { +#ifdef __FMA__ + return _mm_fmadd_ps(a, b, c); +#else + return _mm_add_ps(c, _mm_mul_ps(a, b)); +#endif +} + +static inline +__m128 +glmm_fnmadd(__m128 a, __m128 b, __m128 c) { +#ifdef __FMA__ + return _mm_fnmadd_ps(a, b, c); +#else + return _mm_sub_ps(c, _mm_mul_ps(a, b)); +#endif +} + +static inline +__m128 +glmm_fmsub(__m128 a, __m128 b, __m128 c) { +#ifdef __FMA__ + return _mm_fmsub_ps(a, b, c); +#else + return _mm_sub_ps(_mm_mul_ps(a, b), c); +#endif +} + +static inline +__m128 +glmm_fnmsub(__m128 a, __m128 b, __m128 c) { +#ifdef __FMA__ + return _mm_fnmsub_ps(a, b, c); +#else + return _mm_xor_ps(_mm_add_ps(_mm_mul_ps(a, b), c), _mm_set1_ps(-0.0f)); +#endif +} + +#if defined(__AVX__) +static inline +__m256 +glmm256_fmadd(__m256 a, __m256 b, __m256 c) { +#ifdef __FMA__ + return _mm256_fmadd_ps(a, b, c); +#else + return _mm256_add_ps(c, _mm256_mul_ps(a, b)); +#endif +} + +static inline +__m256 +glmm256_fnmadd(__m256 a, __m256 b, __m256 c) { +#ifdef __FMA__ + return _mm256_fnmadd_ps(a, b, c); +#else + return _mm256_sub_ps(c, _mm256_mul_ps(a, b)); +#endif +} + +static inline +__m256 +glmm256_fmsub(__m256 a, __m256 b, __m256 c) { +#ifdef __FMA__ + return _mm256_fmsub_ps(a, b, c); +#else + return _mm256_sub_ps(_mm256_mul_ps(a, b), c); +#endif +} + +static inline +__m256 +glmm256_fnmsub(__m256 a, __m256 b, __m256 c) { +#ifdef __FMA__ + return _mm256_fmsub_ps(a, b, c); +#else + return _mm256_xor_ps(_mm256_sub_ps(_mm256_mul_ps(a, b), c), + _mm256_set1_ps(-0.0f)); +#endif +} +#endif + +#endif +#endif /* cglm_simd_x86_h */ diff --git a/libs/cglm/include/cglm/sphere.h b/libs/cglm/include/cglm/sphere.h new file mode 100644 index 0000000..334b83a --- /dev/null +++ b/libs/cglm/include/cglm/sphere.h @@ -0,0 +1,99 @@ +/* + * 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 + */ + +/*! + * @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) { + glm_mat4_mulv3(m, s, 1.0f, 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) { + float dist, radii; + + 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_vec3_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_vec3_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_vec3_distance2(point, s) <= rr; +} + +#endif /* cglm_sphere_h */ diff --git a/libs/cglm/include/cglm/struct.h b/libs/cglm/include/cglm/struct.h new file mode 100644 index 0000000..871525a --- /dev/null +++ b/libs/cglm/include/cglm/struct.h @@ -0,0 +1,39 @@ +/* + * 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 "types-struct.h" +#include "struct/vec2.h" +#include "struct/vec3.h" +#include "struct/vec4.h" +#include "struct/mat2.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/cam.h" +#include "struct/quat.h" +#include "struct/euler.h" +#include "struct/project.h" +#include "struct/sphere.h" +#include "struct/curve.h" +#include "struct/affine2d.h" + +#ifdef __cplusplus +} +#endif +#endif /* cglm_structs_h */ diff --git a/libs/cglm/include/cglm/struct/affine.h b/libs/cglm/include/cglm/struct/affine.h new file mode 100644 index 0000000..cd23226 --- /dev/null +++ b/libs/cglm/include/cglm/struct/affine.h @@ -0,0 +1,333 @@ +/* + * 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 glms_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 cglms_affines_h +#define cglms_affines_h + +#include "../common.h" +#include "../types-struct.h" +#include "../affine.h" +#include "vec3.h" +#include "vec4.h" +#include "mat4.h" + +/*! + * @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[in] v scale vector [x, y, z] + * @returns affine transfrom + */ +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 +glms_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) { + vec3s r; + glm_decompose_scalev(m.raw, r.raw); + return r; +} + +/*! + * @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 * __restrict r, vec3s * __restrict 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 * __restrict t, mat4s * __restrict r, vec3s * __restrict s) { + glm_decompose(m.raw, t->raw, r->raw, s->raw); +} + +#endif /* cglms_affines_h */ diff --git a/libs/cglm/include/cglm/struct/affine2d.h b/libs/cglm/include/cglm/struct/affine2d.h new file mode 100644 index 0000000..412bd47 --- /dev/null +++ b/libs/cglm/include/cglm/struct/affine2d.h @@ -0,0 +1,177 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat3s glms_translate2d(mat3 m, vec2 v) + CGLM_INLINE mat3s glms_translate2d_x(mat3s m, float x) + CGLM_INLINE mat3s glms_translate2d_y(mat3s m, float y) + CGLM_INLINE mat3s glms_translate2d_make(vec2s v) + CGLM_INLINE mat3s glms_scale2d_make(vec2s v) + CGLM_INLINE mat3s glms_scale2d(mat3s m, vec2s v) + CGLM_INLINE mat3s glms_scale2d_uni(mat3s m, float s) + CGLM_INLINE mat3s glms_rotate2d_make(float angle) + CGLM_INLINE mat3s glms_rotate2d(mat3s m, float angle) + CGLM_INLINE mat3s glms_rotate2d_to(mat3s m, float angle) + */ + +#ifndef cglms_affine2ds_h +#define cglms_affine2ds_h + +#include "../common.h" +#include "../types-struct.h" +#include "../affine2d.h" +#include "vec3.h" +#include "mat3.h" + +/*! + * @brief translate existing 2d transform matrix by v vector + * and stores result in same matrix + * + * @param[in] m affine transfrom + * @param[in] v translate vector [x, y] + * @returns affine transfrom + */ +CGLM_INLINE +mat3s +glms_translate2d(mat3s m, vec2s v) { + glm_translate2d(m.raw, v.raw); + return m; +} + +/*! + * @brief translate existing 2d transform matrix by x factor + * + * @param[in] m affine transfrom + * @param[in] x x factor + * @returns affine transfrom + */ +CGLM_INLINE +mat3s +glms_translate2d_x(mat3s m, float x) { + glm_translate2d_x(m.raw, x); + return m; +} + +/*! + * @brief translate existing 2d transform matrix by y factor + * + * @param[in] m affine transfrom + * @param[in] y y factor + * @returns affine transfrom + */ +CGLM_INLINE +mat3s +glms_translate2d_y(mat3s m, float y) { + glm_translate2d_y(m.raw, y); + return m; +} + +/*! + * @brief creates NEW translate 2d transform matrix by v vector + * + * @param[in] v translate vector [x, y] + * @returns affine transfrom + */ +CGLM_INLINE +mat3s +glms_translate2d_make(vec2s v) { + mat3s m; + glm_translate2d_make(m.raw, v.raw); + return m; +} + +/*! + * @brief creates NEW 2d scale matrix by v vector + * + * @param[in] v scale vector [x, y] + * @returns affine transfrom + */ +CGLM_INLINE +mat3s +glms_scale2d_make(vec2s v) { + mat3s m; + glm_scale2d_make(m.raw, v.raw); + return m; +} + +/*! + * @brief scales existing 2d 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 +mat3s +glms_scale2d(mat3s m, vec2s v) { + mat3s r; + glm_scale2d_to(m.raw, v.raw, r.raw); + return r; +} + +/*! + * @brief applies uniform scale to existing 2d 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 +mat3s +glms_scale2d_uni(mat3s m, float s) { + glm_scale2d_uni(m.raw, s); + return m; +} + +/*! + * @brief creates NEW 2d rotation matrix by angle and axis + * + * axis will be normalized so you don't need to normalize it + * + * @param[in] angle angle (radians) + * @returns affine transfrom + */ +CGLM_INLINE +mat3s +glms_rotate2d_make(float angle) { + mat3s m; + glm_rotate2d_make(m.raw, angle); + return m; +} + +/*! + * @brief rotate existing 2d transform matrix around given axis by angle + * + * @param[in] m affine transfrom + * @param[in] angle angle (radians) + * @returns affine transfrom + */ +CGLM_INLINE +mat3s +glms_rotate2d(mat3s m, float angle) { + glm_rotate2d(m.raw, angle); + return m; +} + +/*! + * @brief rotate existing 2d transform matrix around given axis by angle + * + * @param[in] m affine transfrom + * @param[in] angle angle (radians) + * @returns affine transfrom + */ +CGLM_INLINE +mat3s +glms_rotate2d_to(mat3s m, float angle) { + glm_rotate2d(m.raw, angle); + return m; +} + +#endif /* cglms_affine2ds_h */ diff --git a/libs/cglm/include/cglm/struct/box.h b/libs/cglm/include/cglm/struct/box.h new file mode 100644 index 0000000..a55884f --- /dev/null +++ b/libs/cglm/include/cglm/struct/box.h @@ -0,0 +1,256 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglms_boxs_h +#define cglms_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]) { + 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); +} + +/*! + * @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]) { + 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); +} + +/*! + * @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]) { + 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); +} + +/*! + * @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]) { + vec3 rawBox[2]; + vec4 rawPlanes[6]; + + glms_vec3_unpack(rawBox, box, 2); + glms_vec4_unpack(rawPlanes, planes, 6); + return glm_aabb_frustum(rawBox, rawPlanes); +} + +/*! + * @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]) { + vec3 rawBox[2]; + glms_vec3_unpack(rawBox, box, 2); + return glm_aabb_isvalid(rawBox); +} + +/*! + * @brief distance between of min and max + * + * @param[in] box bounding box + */ +CGLM_INLINE +float +glms_aabb_size(vec3s box[2]) { + return glm_vec3_distance(box[0].raw, box[1].raw); +} + +/*! + * @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 + * @returns 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]) { + vec3 rawBox[2]; + vec3 rawOther[2]; + + glms_vec3_unpack(rawBox, box, 2); + glms_vec3_unpack(rawOther, other, 2); + return glm_aabb_aabb(rawBox, rawOther); +} + +/*! + * @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], vec4s s) { + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + return glm_aabb_sphere(rawBox, s.raw); +} + +/*! + * @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) { + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + return glm_aabb_point(rawBox, point.raw); +} + +/*! + * @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]) { + 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 /* cglms_boxs_h */ diff --git a/libs/cglm/include/cglm/struct/cam.h b/libs/cglm/include/cglm/struct/cam.h new file mode 100644 index 0000000..2a92af7 --- /dev/null +++ b/libs/cglm/include/cglm/struct/cam.h @@ -0,0 +1,646 @@ +/* + * 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 nearZ, float farZ) + CGLM_INLINE mat4s glms_ortho(float left, float right, + float bottom, float top, + float nearZ, float farZ) + 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 nearZ, + float farZ) + 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 *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 *farZ) + CGLM_INLINE void glms_persp_decomp_near(mat4s proj, float *nearZ) + 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" + +#ifndef CGLM_CLIPSPACE_INCLUDE_ALL +# if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO +# include "clipspace/ortho_lh_zo.h" +# include "clipspace/persp_lh_zo.h" +# include "clipspace/view_lh_zo.h" +# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO +# include "clipspace/ortho_lh_no.h" +# include "clipspace/persp_lh_no.h" +# include "clipspace/view_lh_no.h" +# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO +# include "clipspace/ortho_rh_zo.h" +# include "clipspace/persp_rh_zo.h" +# include "clipspace/view_rh_zo.h" +# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO +# include "clipspace/ortho_rh_no.h" +# include "clipspace/persp_rh_no.h" +# include "clipspace/view_rh_no.h" +# endif +#else +# include "clipspace/ortho_lh_zo.h" +# include "clipspace/persp_lh_zo.h" +# include "clipspace/ortho_lh_no.h" +# include "clipspace/persp_lh_no.h" +# include "clipspace/ortho_rh_zo.h" +# include "clipspace/persp_rh_zo.h" +# include "clipspace/ortho_rh_no.h" +# include "clipspace/persp_rh_no.h" +# include "clipspace/view_lh_zo.h" +# include "clipspace/view_lh_no.h" +# include "clipspace/view_rh_zo.h" +# include "clipspace/view_rh_no.h" +#endif + +/*! + * @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] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_frustum(float left, float right, + float bottom, float top, + float nearZ, float farZ) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_frustum_lh_zo(left, right, bottom, top, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_frustum_lh_no(left, right, bottom, top, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_frustum_rh_zo(left, right, bottom, top, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_frustum_rh_no(left, right, bottom, top, nearZ, farZ); +#endif +} + +/*! + * @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] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho(float left, float right, + float bottom, float top, + float nearZ, float farZ) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_ortho_lh_zo(left, right, bottom, top, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_ortho_lh_no(left, right, bottom, top, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_ortho_rh_zo(left, right, bottom, top, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_ortho_rh_no(left, right, bottom, top, nearZ, farZ); +#endif +} + +/*! + * @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]) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_ortho_aabb_lh_zo(box); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_ortho_aabb_lh_no(box); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_ortho_aabb_rh_zo(box); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_ortho_aabb_rh_no(box); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_ortho_aabb_p_lh_zo(box, padding); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_ortho_aabb_p_lh_no(box, padding); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_ortho_aabb_p_rh_zo(box, padding); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_ortho_aabb_p_rh_no(box, padding); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_ortho_aabb_pz_lh_zo(box, padding); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_ortho_aabb_pz_lh_no(box, padding); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_ortho_aabb_pz_rh_zo(box, padding); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_ortho_aabb_pz_rh_no(box, padding); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_ortho_default_lh_zo(aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_ortho_default_lh_no(aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_ortho_default_rh_zo(aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_ortho_default_rh_no(aspect); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_ortho_default_s_lh_zo(aspect, size); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_ortho_default_s_lh_no(aspect, size); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_ortho_default_s_rh_zo(aspect, size); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_ortho_default_s_rh_no(aspect, size); +#endif +} + +/*! + * @brief set up perspective projection matrix + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective(float fovy, float aspect, float nearZ, float farZ) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_perspective_lh_zo(fovy, aspect, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_perspective_lh_no(fovy, aspect, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_perspective_rh_zo(fovy, aspect, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_perspective_rh_no(fovy, aspect, nearZ, farZ); +#endif +} + +/*! + * @brief extend perspective projection matrix's far distance + * + * NOTE: if you dodn't want to create new matrix then use array api on struct.raw + * like glm_persp_move_far(prooj.raw, deltaFar) to avoid create new mat4 + * each time + * + * 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 +mat4s +glms_persp_move_far(mat4s proj, float deltaFar) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_persp_move_far_lh_zo(proj, deltaFar); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_persp_move_far_lh_no(proj, deltaFar); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_persp_move_far_rh_zo(proj, deltaFar); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_persp_move_far_rh_no(proj, deltaFar); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_perspective_default_lh_zo(aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_perspective_default_lh_no(aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_perspective_default_rh_zo(aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_perspective_default_rh_no(aspect); +#endif +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * reized + * + * NOTE: if you dodn't want to create new matrix then use array api on struct.raw + * like glms_perspective_resize(proj.raw, aspect) to avoid create new mat4 + * each time + * + * @param[in, out] proj perspective projection matrix + * @param[in] aspect aspect ratio ( width / height ) + */ +CGLM_INLINE +mat4s +glms_perspective_resize(mat4s proj, float aspect) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_perspective_resize_lh_zo(proj, aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_perspective_resize_lh_no(proj, aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_perspective_resize_rh_zo(proj, aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_perspective_resize_rh_no(proj, aspect); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_lookat_lh_zo(eye, center, up); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_lookat_lh_no(eye, center, up); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_lookat_rh_zo(eye, center, up); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_lookat_rh_no(eye, center, up); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_look_lh_zo(eye, dir, up); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_look_lh_no(eye, dir, up); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_look_rh_zo(eye, dir, up); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_look_rh_no(eye, dir, up); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_look_anyup_lh_zo(eye, dir); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_look_anyup_lh_no(eye, dir); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_look_anyup_rh_zo(eye, dir); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_look_anyup_rh_no(eye, dir); +#endif +} + +/*! + * @brief decomposes frustum values of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ 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 nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decomp_lh_zo(proj, nearZ, farZ, top, bottom, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decomp_lh_no(proj, nearZ, farZ, top, bottom, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decomp_rh_zo(proj, nearZ, farZ, top, bottom, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decomp_rh_no(proj, nearZ, farZ, top, bottom, left, right); +#endif +} + +/*! + * @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]) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decompv_lh_zo(proj, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decompv_lh_no(proj, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decompv_rh_zo(proj, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decompv_rh_no(proj, dest); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decomp_x_lh_zo(proj, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decomp_x_lh_no(proj, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decomp_x_rh_zo(proj, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decomp_x_rh_no(proj, left, right); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decomp_y_lh_zo(proj, top, bottom); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decomp_y_lh_no(proj, top, bottom); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decomp_y_rh_zo(proj, top, bottom); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decomp_y_rh_no(proj, top, bottom); +#endif +} + +/*! + * @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] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_z(mat4s proj, + float * __restrict nearZ, + float * __restrict farZ) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decomp_z_lh_zo(proj, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decomp_z_lh_no(proj, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decomp_z_rh_zo(proj, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decomp_z_rh_no(proj, nearZ, farZ); +#endif +} + +/*! + * @brief decomposes far value of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_far(mat4s proj, float * __restrict farZ) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decomp_far_lh_zo(proj, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decomp_far_lh_no(proj, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decomp_far_rh_zo(proj, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decomp_far_rh_no(proj, farZ); +#endif +} + +/*! + * @brief decomposes near value of perspective projection. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glms_persp_decomp_near(mat4s proj, float * __restrict nearZ) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decomp_near_lh_zo(proj, nearZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decomp_near_lh_no(proj, nearZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decomp_near_rh_zo(proj, nearZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decomp_near_rh_no(proj, nearZ); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_persp_fovy_lh_zo(proj); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_persp_fovy_lh_no(proj); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_persp_fovy_rh_zo(proj); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_persp_fovy_rh_no(proj); +#endif +} + +/*! + * @brief returns aspect ratio of perspective projection + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_aspect(mat4s proj) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_persp_aspect_lh_zo(proj); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_persp_aspect_lh_no(proj); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_persp_aspect_rh_zo(proj); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_persp_aspect_rh_no(proj); +#endif +} + +/*! + * @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) { +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_persp_sizes_lh_zo(proj, fovy); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_persp_sizes_lh_no(proj, fovy); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_persp_sizes_rh_zo(proj, fovy); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_persp_sizes_rh_no(proj, fovy); +#endif +} + +#endif /* cglms_cam_h */ diff --git a/libs/cglm/include/cglm/struct/clipspace/ortho_lh_no.h b/libs/cglm/include/cglm/struct/clipspace/ortho_lh_no.h new file mode 100644 index 0000000..9a22ff5 --- /dev/null +++ b/libs/cglm/include/cglm/struct/clipspace/ortho_lh_no.h @@ -0,0 +1,152 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_ortho_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_ortho_aabb_lh_no(vec3s box[2]); + CGLM_INLINE mat4s glms_ortho_aabb_p_lh_no(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_aabb_pz_lh_no(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_default_lh_no(float aspect) + CGLM_INLINE mat4s glms_ortho_default_s_lh_no(float aspect, float size) + */ + +#ifndef cglms_ortho_lh_no_h +#define cglms_ortho_lh_no_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up orthographic projection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_ortho_lh_no(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_lh_no(vec3s box[2]) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_lh_no(rawBox, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_lh_no(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_p_lh_no(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_lh_no(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_pz_lh_no(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up unit orthographic projection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_lh_no(float aspect) { + mat4s dest; + glm_ortho_default_lh_no(aspect, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_s_lh_no(float aspect, float size) { + mat4s dest; + glm_ortho_default_s_lh_no(aspect, size, dest.raw); + return dest; +} + +#endif /* cglms_ortho_lh_no_h */ diff --git a/libs/cglm/include/cglm/struct/clipspace/ortho_lh_zo.h b/libs/cglm/include/cglm/struct/clipspace/ortho_lh_zo.h new file mode 100644 index 0000000..09f4731 --- /dev/null +++ b/libs/cglm/include/cglm/struct/clipspace/ortho_lh_zo.h @@ -0,0 +1,152 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_ortho_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_ortho_aabb_lh_zo(vec3s box[2]); + CGLM_INLINE mat4s glms_ortho_aabb_p_lh_zo(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_aabb_pz_lh_zo(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_default_lh_zo(float aspect) + CGLM_INLINE mat4s glms_ortho_default_s_lh_zo(float aspect, float size) + */ + +#ifndef cglms_ortho_lh_zo_h +#define cglms_ortho_lh_zo_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up orthographic projection matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_ortho_lh_zo(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_lh_zo(vec3s box[2]) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_lh_zo(rawBox, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * 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_lh_zo(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_p_lh_zo(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * 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_lh_zo(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_pz_lh_zo(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up unit orthographic projection matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_lh_zo(float aspect) { + mat4s dest; + glm_ortho_default_lh_zo(aspect, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_s_lh_zo(float aspect, float size) { + mat4s dest; + glm_ortho_default_s_lh_zo(aspect, size, dest.raw); + return dest; +} + +#endif /* cglms_ortho_lh_zo_h */ diff --git a/libs/cglm/include/cglm/struct/clipspace/ortho_rh_no.h b/libs/cglm/include/cglm/struct/clipspace/ortho_rh_no.h new file mode 100644 index 0000000..28bd275 --- /dev/null +++ b/libs/cglm/include/cglm/struct/clipspace/ortho_rh_no.h @@ -0,0 +1,152 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_ortho_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_ortho_aabb_rh_no(vec3s box[2]); + CGLM_INLINE mat4s glms_ortho_aabb_p_rh_no(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_aabb_pz_rh_no(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_default_rh_no(float aspect) + CGLM_INLINE mat4s glms_ortho_default_s_rh_no(float aspect, float size) + */ + +#ifndef cglms_ortho_rh_no_h +#define cglms_ortho_rh_no_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up orthographic projection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_ortho_rh_no(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_rh_no(vec3s box[2]) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_rh_no(rawBox, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_rh_no(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_p_rh_no(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_rh_no(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_pz_rh_no(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up unit orthographic projection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_rh_no(float aspect) { + mat4s dest; + glm_ortho_default_rh_no(aspect, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_s_rh_no(float aspect, float size) { + mat4s dest; + glm_ortho_default_s_rh_no(aspect, size, dest.raw); + return dest; +} + +#endif /* cglms_ortho_rh_no_h */ diff --git a/libs/cglm/include/cglm/struct/clipspace/ortho_rh_zo.h b/libs/cglm/include/cglm/struct/clipspace/ortho_rh_zo.h new file mode 100644 index 0000000..0758d62 --- /dev/null +++ b/libs/cglm/include/cglm/struct/clipspace/ortho_rh_zo.h @@ -0,0 +1,152 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_ortho_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_ortho_aabb_rh_zo(vec3s box[2]); + CGLM_INLINE mat4s glms_ortho_aabb_p_rh_zo(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_aabb_pz_rh_zo(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_default_rh_zo(float aspect) + CGLM_INLINE mat4s glms_ortho_default_s_rh_zo(float aspect, float size) + */ + +#ifndef cglms_ortho_rh_zo_h +#define cglms_ortho_rh_zo_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up orthographic projection matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_ortho_rh_zo(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_rh_zo(vec3s box[2]) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_rh_zo(rawBox, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * 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_rh_zo(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_p_rh_zo(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * 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_rh_zo(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_pz_rh_zo(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up unit orthographic projection matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_rh_zo(float aspect) { + mat4s dest; + glm_ortho_default_rh_zo(aspect, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_s_rh_zo(float aspect, float size) { + mat4s dest; + glm_ortho_default_s_rh_zo(aspect, size, dest.raw); + return dest; +} + +#endif /* cglms_ortho_rh_zo_h */ diff --git a/libs/cglm/include/cglm/struct/clipspace/persp_lh_no.h b/libs/cglm/include/cglm/struct/clipspace/persp_lh_no.h new file mode 100644 index 0000000..1c1bb68 --- /dev/null +++ b/libs/cglm/include/cglm/struct/clipspace/persp_lh_no.h @@ -0,0 +1,311 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_frustum_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_perspective_lh_no(float fovy, + float aspect, + float nearZ, + float farZ) + CGLM_INLINE void glms_persp_move_far_lh_no(mat4s proj, float deltaFar) + CGLM_INLINE mat4s glms_perspective_default_lh_no(float aspect) + CGLM_INLINE void glms_perspective_resize_lh_no(mat4s proj, float aspect) + CGLM_INLINE void glms_persp_decomp_lh_no(mat4s proj, + float *nearv, float *farv, + float *top, float *bottom, + float *left, float *right) + CGLM_INLINE void glms_persp_decompv_lh_no(mat4s proj, float dest[6]) + CGLM_INLINE void glms_persp_decomp_x_lh_no(mat4s proj, float *left, float *right) + CGLM_INLINE void glms_persp_decomp_y_lh_no(mat4s proj, float *top, float *bottom) + CGLM_INLINE void glms_persp_decomp_z_lh_no(mat4s proj, float *nearv, float *farv) + CGLM_INLINE void glms_persp_decomp_far_lh_no(mat4s proj, float *farZ) + CGLM_INLINE void glms_persp_decomp_near_lh_no(mat4s proj, float *nearZ) + CGLM_INLINE float glms_persp_fovy_lh_no(mat4s proj) + CGLM_INLINE float glms_persp_aspect_lh_no(mat4s proj) + CGLM_INLINE vec4s glms_persp_sizes_lh_no(mat4s proj, float fovy) + */ + +#ifndef cglms_persp_lh_no_h +#define cglms_persp_lh_no_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up perspective peprojection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_frustum_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_frustum_lh_no(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up perspective projection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_lh_no(float fovy, float aspect, float nearZ, float farZ) { + mat4s dest; + glm_perspective_lh_no(fovy, aspect, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief extend perspective projection matrix's far distance + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * NOTE: if you dodn't want to create new matrix then use array api on struct.raw + * like glms_persp_move_far_lh_no(prooj.raw, deltaFar) to avoid create new mat4 + * each time + * + * 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 +mat4s +glms_persp_move_far_lh_no(mat4s proj, float deltaFar) { + mat4s dest; + dest = proj; + glm_persp_move_far_lh_no(dest.raw, deltaFar); + return dest; +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_default_lh_no(float aspect) { + mat4s dest; + glm_perspective_default_lh_no(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 with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * NOTE: if you dodn't want to create new matrix then use array api on struct.raw + * like glm_perspective_resize_lh_no(proj.raw, aspect) to avoid create new mat4 + * each time + * + * @param[in, out] proj perspective projection matrix + * @param[in] aspect aspect ratio ( width / height ) + */ +CGLM_INLINE +mat4s +glms_perspective_resize_lh_no(mat4s proj, float aspect) { + mat4s dest; + dest = proj; + glm_perspective_resize_lh_no(aspect, dest.raw); + return dest; +} + +/*! + * @brief decomposes frustum values of perspective projection. + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_lh_no(mat4s proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_lh_no(proj.raw, nearZ, farZ, top, bottom, left, right); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * this makes easy to get all values at once + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glms_persp_decompv_lh_no(mat4s proj, float dest[6]) { + glm_persp_decompv_lh_no(proj.raw, dest); +} + +/*! + * @brief decomposes left and right values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * 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_lh_no(mat4s proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_lh_no(proj.raw, left, right); +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * 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_lh_no(mat4s proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_lh_no(proj.raw, top, bottom); +} + +/*! + * @brief decomposes near and far values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_z_lh_no(mat4s proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_lh_no(proj.raw, nearZ, farZ); +} + +/*! + * @brief decomposes far value of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_far_lh_no(mat4s proj, float * __restrict farZ) { + glm_persp_decomp_far_lh_no(proj.raw, farZ); +} + +/*! + * @brief decomposes near value of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glms_persp_decomp_near_lh_no(mat4s proj, float * __restrict nearZ) { + glm_persp_decomp_near_lh_no(proj.raw, nearZ); +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_lh_no(mat4s proj) { + return glm_persp_fovy_lh_no(proj.raw); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_aspect_lh_no(mat4s proj) { + return glm_persp_aspect_lh_no(proj.raw); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @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_lh_no(mat4s proj, float fovy) { + vec4s dest; + glm_persp_sizes_lh_no(proj.raw, fovy, dest.raw); + return dest; +} + +#endif /* cglms_persp_lh_no_h */ diff --git a/libs/cglm/include/cglm/struct/clipspace/persp_lh_zo.h b/libs/cglm/include/cglm/struct/clipspace/persp_lh_zo.h new file mode 100644 index 0000000..230301f --- /dev/null +++ b/libs/cglm/include/cglm/struct/clipspace/persp_lh_zo.h @@ -0,0 +1,311 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_frustum_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_perspective_lh_zo(float fovy, + float aspect, + float nearZ, + float farZ) + CGLM_INLINE void glms_persp_move_far_lh_zo(mat4s proj, float deltaFar) + CGLM_INLINE mat4s glms_perspective_default_lh_zo(float aspect) + CGLM_INLINE void glms_perspective_resize_lh_zo(mat4s proj, float aspect) + CGLM_INLINE void glms_persp_decomp_lh_zo(mat4s proj, + float *nearv, float *farv, + float *top, float *bottom, + float *left, float *right) + CGLM_INLINE void glms_persp_decompv_lh_zo(mat4s proj, float dest[6]) + CGLM_INLINE void glms_persp_decomp_x_lh_zo(mat4s proj, float *left, float *right) + CGLM_INLINE void glms_persp_decomp_y_lh_zo(mat4s proj, float *top, float *bottom) + CGLM_INLINE void glms_persp_decomp_z_lh_zo(mat4s proj, float *nearv, float *farv) + CGLM_INLINE void glms_persp_decomp_far_lh_zo(mat4s proj, float *farZ) + CGLM_INLINE void glms_persp_decomp_near_lh_zo(mat4s proj, float *nearZ) + CGLM_INLINE float glms_persp_fovy_lh_zo(mat4s proj) + CGLM_INLINE float glms_persp_aspect_lh_zo(mat4s proj) + CGLM_INLINE vec4s glms_persp_sizes_lh_zo(mat4s proj, float fovy) + */ + +#ifndef cglms_persp_lh_zo_h +#define cglms_persp_lh_zo_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up perspective peprojection matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_frustum_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_frustum_lh_zo(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up perspective projection matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_lh_zo(float fovy, float aspect, float nearZ, float farZ) { + mat4s dest; + glm_perspective_lh_zo(fovy, aspect, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief extend perspective projection matrix's far distance + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * NOTE: if you dodn't want to create new matrix then use array api on struct.raw + * like glms_persp_move_far_lh_zo(prooj.raw, deltaFar) to avoid create new mat4 + * each time + * + * 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 +mat4s +glms_persp_move_far_lh_zo(mat4s proj, float deltaFar) { + mat4s dest; + dest = proj; + glm_persp_move_far_lh_zo(dest.raw, deltaFar); + return dest; +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_default_lh_zo(float aspect) { + mat4s dest; + glm_perspective_default_lh_zo(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 with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * NOTE: if you dodn't want to create new matrix then use array api on struct.raw + * like glms_perspective_resize_lh_zo(proj.raw, aspect) to avoid create new mat4 + * each time + * + * @param[in, out] proj perspective projection matrix + * @param[in] aspect aspect ratio ( width / height ) + */ +CGLM_INLINE +mat4s +glms_perspective_resize_lh_zo(mat4s proj, float aspect) { + mat4s dest; + dest = proj; + glm_perspective_resize_lh_zo(aspect, dest.raw); + return dest; +} + +/*! + * @brief decomposes frustum values of perspective projection. + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_lh_zo(mat4s proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_lh_zo(proj.raw, nearZ, farZ, top, bottom, left, right); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * this makes easy to get all values at once + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glms_persp_decompv_lh_zo(mat4s proj, float dest[6]) { + glm_persp_decompv_lh_zo(proj.raw, dest); +} + +/*! + * @brief decomposes left and right values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * 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_lh_zo(mat4s proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_lh_zo(proj.raw, left, right); +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * 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_lh_zo(mat4s proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_lh_zo(proj.raw, top, bottom); +} + +/*! + * @brief decomposes near and far values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_z_lh_zo(mat4s proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_lh_zo(proj.raw, nearZ, farZ); +} + +/*! + * @brief decomposes far value of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_far_lh_zo(mat4s proj, float * __restrict farZ) { + glm_persp_decomp_far_lh_zo(proj.raw, farZ); +} + +/*! + * @brief decomposes near value of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glms_persp_decomp_near_lh_zo(mat4s proj, float * __restrict nearZ) { + glm_persp_decomp_near_lh_zo(proj.raw, nearZ); +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * 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_lh_zo(mat4s proj) { + return glm_persp_fovy_lh_zo(proj.raw); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_aspect_lh_zo(mat4s proj) { + return glm_persp_aspect_lh_zo(proj.raw); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @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_lh_zo(mat4s proj, float fovy) { + vec4s dest; + glm_persp_sizes_lh_zo(proj.raw, fovy, dest.raw); + return dest; +} + +#endif /* cglms_persp_lh_zo_h */ diff --git a/libs/cglm/include/cglm/struct/clipspace/persp_rh_no.h b/libs/cglm/include/cglm/struct/clipspace/persp_rh_no.h new file mode 100644 index 0000000..7170e9a --- /dev/null +++ b/libs/cglm/include/cglm/struct/clipspace/persp_rh_no.h @@ -0,0 +1,311 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_frustum_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_perspective_rh_no(float fovy, + float aspect, + float nearZ, + float farZ) + CGLM_INLINE void glms_persp_move_far_rh_no(mat4s proj, float deltaFar) + CGLM_INLINE mat4s glms_perspective_default_rh_no(float aspect) + CGLM_INLINE void glms_perspective_resize_rh_no(mat4s proj, float aspect) + CGLM_INLINE void glms_persp_decomp_rh_no(mat4s proj, + float *nearv, float *farv, + float *top, float *bottom, + float *left, float *right) + CGLM_INLINE void glms_persp_decompv_rh_no(mat4s proj, float dest[6]) + CGLM_INLINE void glms_persp_decomp_x_rh_no(mat4s proj, float *left, float *right) + CGLM_INLINE void glms_persp_decomp_y_rh_no(mat4s proj, float *top, float *bottom) + CGLM_INLINE void glms_persp_decomp_z_rh_no(mat4s proj, float *nearv, float *farv) + CGLM_INLINE void glms_persp_decomp_far_rh_no(mat4s proj, float *farZ) + CGLM_INLINE void glms_persp_decomp_near_rh_no(mat4s proj, float *nearZ) + CGLM_INLINE float glms_persp_fovy_rh_no(mat4s proj) + CGLM_INLINE float glms_persp_aspect_rh_no(mat4s proj) + CGLM_INLINE vec4s glms_persp_sizes_rh_no(mat4s proj, float fovy) + */ + +#ifndef cglms_persp_rh_no_h +#define cglms_persp_rh_no_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up perspective peprojection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_frustum_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_frustum_rh_no(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up perspective projection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_rh_no(float fovy, float aspect, float nearZ, float farZ) { + mat4s dest; + glm_perspective_rh_no(fovy, aspect, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief extend perspective projection matrix's far distance + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * NOTE: if you dodn't want to create new matrix then use array api on struct.raw + * like glms_persp_move_far_rh_no(prooj.raw, deltaFar) to avoid create new mat4 + * each time + * s + * 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 +mat4s +glms_persp_move_far_rh_no(mat4s proj, float deltaFar) { + mat4s dest; + dest = proj; + glm_persp_move_far_rh_no(dest.raw, deltaFar); + return dest; +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_default_rh_no(float aspect) { + mat4s dest; + glm_perspective_default_rh_no(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 with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * NOTE: if you dodn't want to create new matrix then use array api on struct.raw + * like glm_perspective_resize_rh_no(proj.raw, aspect) to avoid create new mat4 + * each time + * + * @param[in, out] proj perspective projection matrix + * @param[in] aspect aspect ratio ( width / height ) + */ +CGLM_INLINE +mat4s +glms_perspective_resize_rh_no(mat4s proj, float aspect) { + mat4s dest; + dest = proj; + glm_perspective_resize_rh_no(aspect, dest.raw); + return dest; +} + +/*! + * @brief decomposes frustum values of perspective projection. + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_rh_no(mat4s proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_rh_no(proj.raw, nearZ, farZ, top, bottom, left, right); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * this makes easy to get all values at once + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glms_persp_decompv_rh_no(mat4s proj, float dest[6]) { + glm_persp_decompv_rh_no(proj.raw, dest); +} + +/*! + * @brief decomposes left and right values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * 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_rh_no(mat4s proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_rh_no(proj.raw, left, right); +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * 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_rh_no(mat4s proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_rh_no(proj.raw, top, bottom); +} + +/*! + * @brief decomposes near and far values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_z_rh_no(mat4s proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_rh_no(proj.raw, nearZ, farZ); +} + +/*! + * @brief decomposes far value of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_far_rh_no(mat4s proj, float * __restrict farZ) { + glm_persp_decomp_far_rh_no(proj.raw, farZ); +} + +/*! + * @brief decomposes near value of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glms_persp_decomp_near_rh_no(mat4s proj, float * __restrict nearZ) { + glm_persp_decomp_near_rh_no(proj.raw, nearZ); +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_rh_no(mat4s proj) { + return glm_persp_fovy_rh_no(proj.raw); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_aspect_rh_no(mat4s proj) { + return glm_persp_aspect_rh_no(proj.raw); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @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_rh_no(mat4s proj, float fovy) { + vec4s dest; + glm_persp_sizes_rh_no(proj.raw, fovy, dest.raw); + return dest; +} + +#endif /* cglms_persp_rh_no_h */ diff --git a/libs/cglm/include/cglm/struct/clipspace/persp_rh_zo.h b/libs/cglm/include/cglm/struct/clipspace/persp_rh_zo.h new file mode 100644 index 0000000..ff4d8de --- /dev/null +++ b/libs/cglm/include/cglm/struct/clipspace/persp_rh_zo.h @@ -0,0 +1,311 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_frustum_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_perspective_rh_zo(float fovy, + float aspect, + float nearZ, + float farZ) + CGLM_INLINE void glms_persp_move_far_rh_zo(mat4s proj, float deltaFar) + CGLM_INLINE mat4s glms_perspective_default_rh_zo(float aspect) + CGLM_INLINE void glms_perspective_resize_rh_zo(mat4s proj, float aspect) + CGLM_INLINE void glms_persp_decomp_rh_zo(mat4s proj, + float *nearv, float *farv, + float *top, float *bottom, + float *left, float *right) + CGLM_INLINE void glms_persp_decompv_rh_zo(mat4s proj, float dest[6]) + CGLM_INLINE void glms_persp_decomp_x_rh_zo(mat4s proj, float *left, float *right) + CGLM_INLINE void glms_persp_decomp_y_rh_zo(mat4s proj, float *top, float *bottom) + CGLM_INLINE void glms_persp_decomp_z_rh_zo(mat4s proj, float *nearv, float *farv) + CGLM_INLINE void glms_persp_decomp_far_rh_zo(mat4s proj, float *farZ) + CGLM_INLINE void glms_persp_decomp_near_rh_zo(mat4s proj, float *nearZ) + CGLM_INLINE float glms_persp_fovy_rh_zo(mat4s proj) + CGLM_INLINE float glms_persp_aspect_rh_zo(mat4s proj) + CGLM_INLINE vec4s glms_persp_sizes_rh_zo(mat4s proj, float fovy) + */ + +#ifndef cglms_persp_rh_zo_h +#define cglms_persp_rh_zo_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up perspective peprojection matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_frustum_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_frustum_rh_zo(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up perspective projection matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_rh_zo(float fovy, float aspect, float nearZ, float farZ) { + mat4s dest; + glm_perspective_rh_zo(fovy, aspect, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief extend perspective projection matrix's far distance + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * NOTE: if you dodn't want to create new matrix then use array api on struct.raw + * like glms_persp_move_far_rh_zo(prooj.raw, deltaFar) to avoid create new mat4 + * each time + * + * 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 +mat4s +glms_persp_move_far_rh_zo(mat4s proj, float deltaFar) { + mat4s dest; + dest = proj; + glm_persp_move_far_rh_zo(dest.raw, deltaFar); + return dest; +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_default_rh_zo(float aspect) { + mat4s dest; + glm_perspective_default_rh_zo(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 with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * NOTE: if you dodn't want to create new matrix then use array api on struct.raw + * like glm_perspective_resize_rh_zo(proj.raw, aspect) to avoid create new mat4 + * each time + * + * @param[in, out] proj perspective projection matrix + * @param[in] aspect aspect ratio ( width / height ) + */ +CGLM_INLINE +mat4s +glms_perspective_resize_rh_zo(mat4s proj, float aspect) { + mat4s dest; + dest = proj; + glm_perspective_resize_rh_zo(aspect, dest.raw); + return dest; +} + +/*! + * @brief decomposes frustum values of perspective projection. + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_rh_zo(mat4s proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_rh_zo(proj.raw, nearZ, farZ, top, bottom, left, right); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * this makes easy to get all values at once + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glms_persp_decompv_rh_zo(mat4s proj, float dest[6]) { + glm_persp_decompv_rh_zo(proj.raw, dest); +} + +/*! + * @brief decomposes left and right values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * 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_rh_zo(mat4s proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_rh_zo(proj.raw, left, right); +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * 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_rh_zo(mat4s proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_rh_zo(proj.raw, top, bottom); +} + +/*! + * @brief decomposes near and far values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_z_rh_zo(mat4s proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_rh_zo(proj.raw, nearZ, farZ); +} + +/*! + * @brief decomposes far value of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_far_rh_zo(mat4s proj, float * __restrict farZ) { + glm_persp_decomp_far_rh_zo(proj.raw, farZ); +} + +/*! + * @brief decomposes near value of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glms_persp_decomp_near_rh_zo(mat4s proj, float * __restrict nearZ) { + glm_persp_decomp_near_rh_zo(proj.raw, nearZ); +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * 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_rh_zo(mat4s proj) { + return glm_persp_fovy_rh_zo(proj.raw); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_aspect_rh_zo(mat4s proj) { + return glm_persp_aspect_rh_zo(proj.raw); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @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_rh_zo(mat4s proj, float fovy) { + vec4s dest; + glm_persp_sizes_rh_zo(proj.raw, fovy, dest.raw); + return dest; +} + +#endif /* cglms_persp_rh_zo_h */ diff --git a/libs/cglm/include/cglm/struct/clipspace/view_lh_no.h b/libs/cglm/include/cglm/struct/clipspace/view_lh_no.h new file mode 100644 index 0000000..bb5eed6 --- /dev/null +++ b/libs/cglm/include/cglm/struct/clipspace/view_lh_no.h @@ -0,0 +1,88 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_lookat_lh_no(vec3s eye, vec3s center, vec3s up) + CGLM_INLINE mat4s glms_look_lh_no(vec3s eye, vec3s dir, vec3s up) + CGLM_INLINE mat4s glms_look_anyup_lh_no(vec3s eye, vec3s dir) + */ + +#ifndef cglms_view_lh_no_h +#define cglms_view_lh_no_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up view matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_lh_no(vec3s eye, vec3s center, vec3s up) { + mat4s dest; + glm_lookat_lh_no(eye.raw, center.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_lh_no(vec3s eye, vec3s dir, vec3s up) { + mat4s dest; + glm_look_lh_no(eye.raw, dir.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_lh_no(vec3s eye, vec3s dir) { + mat4s dest; + glm_look_anyup_lh_no(eye.raw, dir.raw, dest.raw); + return dest; +} + +#endif /* cglms_view_lh_no_h */ diff --git a/libs/cglm/include/cglm/struct/clipspace/view_lh_zo.h b/libs/cglm/include/cglm/struct/clipspace/view_lh_zo.h new file mode 100644 index 0000000..322fdf6 --- /dev/null +++ b/libs/cglm/include/cglm/struct/clipspace/view_lh_zo.h @@ -0,0 +1,88 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_lookat_lh_zo(vec3s eye, vec3s center, vec3s up) + CGLM_INLINE mat4s glms_look_lh_zo(vec3s eye, vec3s dir, vec3s up) + CGLM_INLINE mat4s glms_look_anyup_lh_zo(vec3s eye, vec3s dir) + */ + +#ifndef cglms_view_lh_zo_h +#define cglms_view_lh_zo_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up view matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * 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_lh_zo(vec3s eye, vec3s center, vec3s up) { + mat4s dest; + glm_lookat_lh_zo(eye.raw, center.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * 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_lh_zo(vec3s eye, vec3s dir, vec3s up) { + mat4s dest; + glm_look_lh_zo(eye.raw, dir.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * 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_lh_zo(vec3s eye, vec3s dir) { + mat4s dest; + glm_look_anyup_lh_zo(eye.raw, dir.raw, dest.raw); + return dest; +} + +#endif /* cglms_view_lh_zo_h */ diff --git a/libs/cglm/include/cglm/struct/clipspace/view_rh_no.h b/libs/cglm/include/cglm/struct/clipspace/view_rh_no.h new file mode 100644 index 0000000..df82b1d --- /dev/null +++ b/libs/cglm/include/cglm/struct/clipspace/view_rh_no.h @@ -0,0 +1,88 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_lookat_rh_no(vec3s eye, vec3s center, vec3s up) + CGLM_INLINE mat4s glms_look_rh_no(vec3s eye, vec3s dir, vec3s up) + CGLM_INLINE mat4s glms_look_anyup_rh_no(vec3s eye, vec3s dir) + */ + +#ifndef cglms_view_rh_no_h +#define cglms_view_rh_no_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up view matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_rh_no(vec3s eye, vec3s center, vec3s up) { + mat4s dest; + glm_lookat_rh_no(eye.raw, center.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_rh_no(vec3s eye, vec3s dir, vec3s up) { + mat4s dest; + glm_look_rh_no(eye.raw, dir.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * 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_rh_no(vec3s eye, vec3s dir) { + mat4s dest; + glm_look_anyup_rh_no(eye.raw, dir.raw, dest.raw); + return dest; +} + +#endif /* cglms_view_rh_no_h */ diff --git a/libs/cglm/include/cglm/struct/clipspace/view_rh_zo.h b/libs/cglm/include/cglm/struct/clipspace/view_rh_zo.h new file mode 100644 index 0000000..5097bc8 --- /dev/null +++ b/libs/cglm/include/cglm/struct/clipspace/view_rh_zo.h @@ -0,0 +1,88 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_lookat_rh_zo(vec3s eye, vec3s center, vec3s up) + CGLM_INLINE mat4s glms_look_rh_zo(vec3s eye, vec3s dir, vec3s up) + CGLM_INLINE mat4s glms_look_anyup_rh_zo(vec3s eye, vec3s dir) + */ + +#ifndef cglms_view_rh_zo_h +#define cglms_view_rh_zo_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up view matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * 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_rh_zo(vec3s eye, vec3s center, vec3s up) { + mat4s dest; + glm_lookat_rh_zo(eye.raw, center.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * 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_rh_zo(vec3s eye, vec3s dir, vec3s up) { + mat4s dest; + glm_look_rh_zo(eye.raw, dir.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * 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_rh_zo(vec3s eye, vec3s dir) { + mat4s dest; + glm_look_anyup_rh_zo(eye.raw, dir.raw, dest.raw); + return dest; +} + +#endif /* cglms_view_rh_zo_h */ diff --git a/libs/cglm/include/cglm/struct/color.h b/libs/cglm/include/cglm/struct/color.h new file mode 100644 index 0000000..3ce78da --- /dev/null +++ b/libs/cglm/include/cglm/struct/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 cglms_colors_h +#define cglms_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 /* cglms_colors_h */ diff --git a/libs/cglm/include/cglm/struct/curve.h b/libs/cglm/include/cglm/struct/curve.h new file mode 100644 index 0000000..53ea359 --- /dev/null +++ b/libs/cglm/include/cglm/struct/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 cglms_curves_h +#define cglms_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 /* cglms_curves_h */ diff --git a/libs/cglm/include/cglm/struct/euler.h b/libs/cglm/include/cglm/struct/euler.h new file mode 100644 index 0000000..6575930 --- /dev/null +++ b/libs/cglm/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_seq + + 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_seq 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_seq ord) { + mat4s dest; + glm_euler_by_order(angles.raw, ord, dest.raw); + return dest; +} + +#endif /* cglms_euler_h */ diff --git a/libs/cglm/include/cglm/struct/frustum.h b/libs/cglm/include/cglm/struct/frustum.h new file mode 100644 index 0000000..2c51d6d --- /dev/null +++ b/libs/cglm/include/cglm/struct/frustum.h @@ -0,0 +1,155 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglms_frustums_h +#define cglms_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]) { + vec4 rawDest[6]; + glm_frustum_planes(m.raw, rawDest); + glms_vec4_pack(dest, rawDest, 6); +} + +/*! + * @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]) { + vec4 rawDest[8]; + glm_frustum_corners(invMat.raw, rawDest); + glms_vec4_pack(dest, rawDest, 8); +} + +/*! + * @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]) { + vec4 rawCorners[8]; + vec4s r; + + glms_vec4_unpack(rawCorners, corners, 8); + glm_frustum_center(rawCorners, r.raw); + return r; +} + +/*! + * @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]) { + 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); +} + +/*! + * @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]) { + 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); +} + +#endif /* cglms_frustums_h */ diff --git a/libs/cglm/include/cglm/struct/io.h b/libs/cglm/include/cglm/struct/io.h new file mode 100644 index 0000000..ec28129 --- /dev/null +++ b/libs/cglm/include/cglm/struct/io.h @@ -0,0 +1,82 @@ +/* + * 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 cglms_ios_h +#define cglms_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) { + vec3 rawBbox[2]; + + glms_vec3_unpack(rawBbox, bbox, 2); + glm_aabb_print(rawBbox, tag, ostream); +} + +#endif /* cglms_ios_h */ diff --git a/libs/cglm/include/cglm/struct/mat2.h b/libs/cglm/include/cglm/struct/mat2.h new file mode 100644 index 0000000..a8ee27f --- /dev/null +++ b/libs/cglm/include/cglm/struct/mat2.h @@ -0,0 +1,258 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLM_MAT2_IDENTITY_INIT + GLM_MAT2_ZERO_INIT + GLM_MAT2_IDENTITY + GLM_MAT2_ZERO + + Functions: + CGLM_INLINE void glms_mat2_identity(mat2 mat) + CGLM_INLINE void glms_mat2_identity_array(mat2 * restrict mat, size_t count) + CGLM_INLINE void glms_mat2_zero(mat2 mat) + CGLM_INLINE void glms_mat2_mul(mat2 m1, mat2 m2, mat2 dest) + CGLM_INLINE void glms_mat2_transpose_to(mat2 m, mat2 dest) + CGLM_INLINE void glms_mat2_transpose(mat2 m) + CGLM_INLINE void glms_mat2_mulv(mat2 m, vec2 v, vec2 dest) + CGLM_INLINE float glms_mat2_trace(mat2 m) + CGLM_INLINE void glms_mat2_scale(mat2 m, float s) + CGLM_INLINE float glms_mat2_det(mat2 mat) + CGLM_INLINE void glms_mat2_inv(mat2 mat, mat2 dest) + CGLM_INLINE void glms_mat2_swap_col(mat2 mat, int col1, int col2) + CGLM_INLINE void glms_mat2_swap_row(mat2 mat, int row1, int row2) + CGLM_INLINE float glms_mat2_rmc(vec2 r, mat2 m, vec2 c) + */ + +#ifndef cglms_mat2_h +#define cglms_mat2_h + +#include "../common.h" +#include "../types-struct.h" +#include "../mat2.h" + +#define GLMS_MAT2_IDENTITY_INIT {GLM_MAT2_IDENTITY_INIT} +#define GLMS_MAT2_ZERO_INIT {GLM_MAT2_ZERO_INIT} + +/* for C only */ +#define GLMS_MAT2_IDENTITY ((mat3s)GLMS_MAT2_IDENTITY_INIT) +#define GLMS_MAT2_ZERO ((mat3s)GLMS_MAT2_ZERO_INIT) + +/*! + * @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_mat2_identity(aStruct->aMatrix); + * + * @code + * glm_mat2_copy(GLM_MAT2_IDENTITY, mat); // C only + * + * // or + * mat2 mat = GLM_MAT2_IDENTITY_INIT; + * @endcode + * + * @returns identity matrix + */ +CGLM_INLINE +mat2s +glms_mat2_identity(void) { + mat2s r; + glm_mat2_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) + * if alignment is not disabled) + * + * @param[in] count count of matrices + */ +CGLM_INLINE +void +glms_mat2_identity_array(mat2s * __restrict mat, size_t count) { + CGLM_ALIGN_MAT mat2s t = GLMS_MAT2_IDENTITY_INIT; + size_t i; + + for (i = 0; i < count; i++) { + glm_mat2_copy(t.raw, mat[i].raw); + } +} + +/*! + * @brief make given matrix zero. + * + * @returns matrix + */ +CGLM_INLINE +mat2s +glms_mat2_zero(void) { + mat2s r; + glm_mat2_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 + * mat2 m = GLM_MAT2_IDENTITY_INIT; + * glm_mat2_mul(m, m, m); + * @endcode + * + * @param[in] m1 left matrix + * @param[in] m2 right matrix + * + * @returns matrix + */ +CGLM_INLINE +mat2s +glms_mat2_mul(mat2s m1, mat2s m2) { + mat2s r; + glm_mat2_mul(m1.raw, m2.raw, r.raw); + return r; +} + +/*! + * @brief transpose mat2 + * + * @param[in] m matrix to transpose + * + * @returns transposed matrix + */ +CGLM_INLINE +mat2s +glms_mat2_transpose(mat2s m) { + glm_mat2_transpose(m.raw); + return m; +} + +/*! + * @brief multiply mat2 with vec2 (column vector) and store in dest vector + * + * @param[in] m mat2 (left) + * @param[in] v vec2 (right, column vector) + * @returns vec2 (result, column vector) + */ +CGLM_INLINE +vec2s +glms_mat2_mulv(mat2s m, vec2s v) { + vec2s r; + glm_mat2_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_mat2_trace(mat2s m) { + return glm_mat2_trace(m.raw); +} + +/*! + * @brief scale (multiply with scalar) matrix + * + * multiply matrix with scalar + * + * @param[in, out] m matrix + * @param[in] s scalar + * @returns matrix + */ +CGLM_INLINE +mat2s +glms_mat2_scale(mat2s m, float s) { + glm_mat2_scale(m.raw, s); + return m; +} + +/*! + * @brief mat2 determinant + * + * @param[in] mat matrix + * + * @return determinant + */ +CGLM_INLINE +float +glms_mat2_det(mat2s mat) { + return glm_mat2_det(mat.raw); +} + +/*! + * @brief inverse mat2 and store in dest + * + * @param[in] mat matrix + * @returns matrix + */ +CGLM_INLINE +mat2s +glms_mat2_inv(mat2s mat) { + mat2s r; + glm_mat2_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 +mat2s +glms_mat2_swap_col(mat2s mat, int col1, int col2) { + glm_mat2_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 +mat2s +glms_mat2_swap_row(mat2s mat, int row1, int row2) { + glm_mat2_swap_row(mat.raw, row1, row2); + return mat; +} + +/*! + * @brief helper for R (row vector) * M (matrix) * C (column vector) + * + * rmc stands for Row * Matrix * Column + * + * the result is scalar because R * M = Matrix1x2 (row vector), + * then Matrix1x2 * Vec2 (column vector) = Matrix1x1 (Scalar) + * + * @param[in] r row vector or matrix1x2 + * @param[in] m matrix2x2 + * @param[in] c column vector or matrix2x1 + * + * @return scalar value e.g. Matrix1x1 + */ +CGLM_INLINE +float +glms_mat2_rmc(vec2s r, mat2s m, vec2s c) { + return glm_mat2_rmc(r.raw, m.raw, c.raw); +} + +#endif /* cglms_mat2_h */ diff --git a/libs/cglm/include/cglm/struct/mat3.h b/libs/cglm/include/cglm/struct/mat3.h new file mode 100644 index 0000000..53a7273 --- /dev/null +++ b/libs/cglm/include/cglm/struct/mat3.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 + */ + +/* + Macros: + GLMS_MAT3_IDENTITY_INIT + GLMS_MAT3_ZERO_INIT + GLMS_MAT3_IDENTITY + GLMS_MAT3_ZERO + + Functions: + CGLM_INLINE mat3s glms_mat3_copy(mat3s mat); + CGLM_INLINE mat3s glms_mat3_identity(void); + CGLM_INLINE void glms_mat3_identity_array(mat3s * __restrict mat, size_t count); + CGLM_INLINE mat3s glms_mat3_zero(void); + CGLM_INLINE mat3s glms_mat3_mul(mat3s m1, mat3s m2); + 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 cglms_mat3s_h +#define cglms_mat3s_h + +#include "../common.h" +#include "../types-struct.h" +#include "../mat3.h" +#include "vec3.h" + +#define GLMS_MAT3_IDENTITY_INIT {GLM_MAT3_IDENTITY_INIT} +#define GLMS_MAT3_ZERO_INIT {GLM_MAT3_ZERO_INIT} + +/* 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(void) { + 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(void) { + 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 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) + */ +CGLM_INLINE +vec3s +glms_mat3_mulv(mat3s m, vec3s v) { + vec3s r; + 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) + * + * 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, mat3s m, vec3s c) { + return glm_mat3_rmc(r.raw, m.raw, c.raw); +} + +#endif /* cglms_mat3s_h */ diff --git a/libs/cglm/include/cglm/struct/mat4.h b/libs/cglm/include/cglm/struct/mat4.h new file mode 100644 index 0000000..28f80a3 --- /dev/null +++ b/libs/cglm/include/cglm/struct/mat4.h @@ -0,0 +1,459 @@ +/* + * 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 + */ + +/* + Macros: + GLMS_MAT4_IDENTITY_INIT + GLMS_MAT4_ZERO_INIT + GLMS_MAT4_IDENTITY + GLMS_MAT4_ZERO + + Functions: + CGLM_INLINE mat4s glms_mat4_ucopy(mat4s mat); + CGLM_INLINE mat4s glms_mat4_copy(mat4s mat); + CGLM_INLINE mat4s glms_mat4_identity(void); + CGLM_INLINE void glms_mat4_identity_array(mat4s * __restrict mat, size_t count); + CGLM_INLINE mat4s glms_mat4_zero(void); + CGLM_INLINE mat3s glms_mat4_pick3(mat4s mat); + CGLM_INLINE mat3s glms_mat4_pick3t(mat4s mat); + CGLM_INLINE mat4s glms_mat4_ins3(mat3s mat); + CGLM_INLINE mat4s glms_mat4_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(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 cglms_mat4s_h +#define cglms_mat4s_h + +#include "../common.h" +#include "../types-struct.h" +#include "../mat4.h" +#include "vec4.h" +#include "vec3.h" + +#define GLMS_MAT4_IDENTITY_INIT {GLM_MAT4_IDENTITY_INIT} +#define GLMS_MAT4_ZERO_INIT {GLM_MAT4_ZERO_INIT} + +/* for C only */ +#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] + * + * 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(void) { + 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 mat4s t = GLMS_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(void) { + 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; + * + * 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 matrix + */ +CGLM_INLINE +mat4s +glms_mat4_mulN(mat4s * __restrict matrices[], uint32_t len) { + CGLM_ALIGN_MAT mat4s r = GLMS_MAT4_IDENTITY_INIT; + size_t i; + + for (i = 0; i < len; i++) { + r = glms_mat4_mul(r, *matrices[i]); + } + + 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) + */ +CGLM_INLINE +vec4s +glms_mat4_mulv(mat4s m, vec4s v) { + vec4s r; + 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; +} + +/*! + * @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(mat4s m, vec3s v, float last) { + vec3s r; + glm_mat4_mulv3(m.raw, v.raw, last, 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) + * + * 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, mat4s m, vec4s c) { + return glm_mat4_rmc(r.raw, m.raw, c.raw); +} + +#endif /* cglms_mat4s_h */ diff --git a/libs/cglm/include/cglm/struct/plane.h b/libs/cglm/include/cglm/struct/plane.h new file mode 100644 index 0000000..6a84ac7 --- /dev/null +++ b/libs/cglm/include/cglm/struct/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 cglms_planes_h +#define cglms_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 /* cglms_planes_h */ diff --git a/libs/cglm/include/cglm/struct/project.h b/libs/cglm/include/cglm/struct/project.h new file mode 100644 index 0000000..00f76ff --- /dev/null +++ b/libs/cglm/include/cglm/struct/project.h @@ -0,0 +1,120 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglms_projects_h +#define cglms_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] + * @returns 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; +} + +/*! + * @brief define a picking region + * + * @param[in] center center [x, y] of a picking region in window coordinates + * @param[in] size size [width, height] of the picking region in window coordinates + * @param[in] vp viewport as [x, y, width, height] + * @returns projected coordinates + */ +CGLM_INLINE +mat4s +glms_pickmatrix(vec2s center, vec2s size, vec4s vp) { + mat4s res; + glm_pickmatrix(center.raw, size.raw, vp.raw, res.raw); + return res; +} + +#endif /* cglms_projects_h */ diff --git a/libs/cglm/include/cglm/struct/quat.h b/libs/cglm/include/cglm/struct/quat.h new file mode 100644 index 0000000..d69675b --- /dev/null +++ b/libs/cglm/include/cglm/struct/quat.h @@ -0,0 +1,565 @@ +/* + * 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(void) + 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 versors glms_quat_from_vecs(vec3s a, vec3s b) + 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_lerpc(versors from, versors to, float t) + CGLM_INLINE versors glms_quat_nlerp(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(void) { + 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 compute quaternion rotating vector A to vector B + * + * @param[in] a vec3 (must have unit length) + * @param[in] b vec3 (must have unit length) + * @returns quaternion (of unit length) + */ +CGLM_INLINE +versors +glms_quat_from_vecs(vec3s a, vec3s b) { + versors dest; + glm_quat_from_vecs(a.raw, b.raw, dest.raw); + return dest; +} + +/*! + * @brief returns norm (magnitude) of quaternion + * + * @param[in] 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.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) + * @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 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_lerpc(versors from, versors to, float t) { + versors dest; + glm_quat_lerpc(from.raw, to.raw, t, dest.raw); + return dest; +} + +/*! + * @brief interpolates between two quaternions + * taking the shortest rotation path using + * normalized linear interpolation (NLERP) + * + * @param[in] from from + * @param[in] to to + * @param[in] t interpolant (amount) + * @returns result quaternion + */ +CGLM_INLINE +versors +glms_quat_nlerp(versors from, versors to, float t) { + versors dest; + glm_quat_nlerp(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] up up vector + * @returns destination quaternion + */ +CGLM_INLINE +versors +glms_quat_for(vec3s dir, vec3s up) { + versors dest; + glm_quat_for(dir.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] up up vector + * @returns destination quaternion + */ +CGLM_INLINE +versors +glms_quat_forp(vec3s from, vec3s to, vec3s up) { + versors dest; + glm_quat_forp(from.raw, to.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/libs/cglm/include/cglm/struct/sphere.h b/libs/cglm/include/cglm/struct/sphere.h new file mode 100644 index 0000000..9859c72 --- /dev/null +++ b/libs/cglm/include/cglm/struct/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 cglms_spheres_h +#define cglms_spheres_h + +#include "../common.h" +#include "../types-struct.h" +#include "../sphere.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 + */ + +/*! + * @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, mat4s m) { + vec4s r; + glm_sphere_transform(s.raw, m.raw, 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 /* cglms_spheres_h */ diff --git a/libs/cglm/include/cglm/struct/vec2-ext.h b/libs/cglm/include/cglm/struct/vec2-ext.h new file mode 100644 index 0000000..5d6682d --- /dev/null +++ b/libs/cglm/include/cglm/struct/vec2-ext.h @@ -0,0 +1,239 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/*! + * @brief SIMD like functions + */ + +/* + Functions: + CGLM_INLINE vec2s glms_vec2_fill(float val) + CGLM_INLINE bool glms_vec2_eq(vec2s v, float val) + CGLM_INLINE bool glms_vec2_eq_eps(vec2s v, float val) + CGLM_INLINE bool glms_vec2_eq_all(vec2s v) + CGLM_INLINE bool glms_vec2_eqv(vec2s a, vec2s b) + CGLM_INLINE bool glms_vec2_eqv_eps(vec2s a, vec2s b) + CGLM_INLINE float glms_vec2_max(vec2s v) + CGLM_INLINE float glms_vec2_min(vec2s v) + CGLM_INLINE bool glms_vec2_isnan(vec2s v) + CGLM_INLINE bool glms_vec2_isinf(vec2s v) + CGLM_INLINE bool glms_vec2_isvalid(vec2s v) + CGLM_INLINE vec2s glms_vec2_sign(vec2s v) + CGLM_INLINE vec2s glms_vec2_sqrt(vec2s v) + */ + +#ifndef cglms_vec2s_ext_h +#define cglms_vec2s_ext_h + +#include "../common.h" +#include "../types-struct.h" +#include "../util.h" +#include "../vec2-ext.h" + +/*! + * @brief fill a vector with specified value + * + * @param[in] val value + * @returns dest + */ +CGLM_INLINE +vec2s +glms_vec2_fill(float val) { + vec2s r; + glm_vec2_fill(r.raw, 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_vec2_eq(vec2s v, float val) { + return glm_vec2_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_vec2_eq_eps(vec2s v, float val) { + return glm_vec2_eq_eps(v.raw, val); +} + +/*! + * @brief check if vectors members are equal (without epsilon) + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glms_vec2_eq_all(vec2s v) { + return glm_vec2_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_vec2_eqv(vec2s a, vec2s b) { + return glm_vec2_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_vec2_eqv_eps(vec2s a, vec2s b) { + return glm_vec2_eqv_eps(a.raw, b.raw); +} + +/*! + * @brief max value of vector + * + * @param[in] v vector + */ +CGLM_INLINE +float +glms_vec2_max(vec2s v) { + return glm_vec2_max(v.raw); +} + +/*! + * @brief min value of vector + * + * @param[in] v vector + */ +CGLM_INLINE +float +glms_vec2_min(vec2s v) { + return glm_vec2_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_vec2_isnan(vec2s v) { + return glm_vec2_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_vec2_isinf(vec2s v) { + return glm_vec2_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_vec2_isvalid(vec2s v) { + return glm_vec2_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 +vec2s +glms_vec2_sign(vec2s v) { + vec2s r; + glm_vec2_sign(v.raw, r.raw); + return r; +} + +/*! + * @brief square root of each vector item + * + * @param[in] v vector + * @returns destination vector + */ +CGLM_INLINE +vec2s +glms_vec2_sqrt(vec2s v) { + vec2s r; + glm_vec2_sqrt(v.raw, r.raw); + return r; +} + +/*! + * @brief treat vectors as complex numbers and multiply them as such. + * + * @param[in] a left number + * @param[in] b right number + * @param[out] dest destination number + */ +CGLM_INLINE +vec2s +glms_vec2_complex_mul(vec2s a, vec2s b, vec2s dest) { + glm_vec2_complex_mul(a.raw, b.raw, dest.raw); + return dest; +} + +/*! + * @brief treat vectors as complex numbers and divide them as such. + * + * @param[in] a left number (numerator) + * @param[in] b right number (denominator) + * @param[out] dest destination number + */ +CGLM_INLINE +vec2s +glms_vec2_complex_div(vec2s a, vec2s b, vec2s dest) { + glm_vec2_complex_div(a.raw, b.raw, dest.raw); + return dest; +} + +/*! + * @brief treat the vector as a complex number and conjugate it as such. + * + * @param[in] a the number + * @param[out] dest destination number + */ +CGLM_INLINE +vec2s +glms_vec2_complex_conjugate(vec2s a, vec2s dest) { + glm_vec2_complex_conjugate(a.raw, dest.raw); + return dest; +} + +#endif /* cglms_vec2s_ext_h */ diff --git a/libs/cglm/include/cglm/struct/vec2.h b/libs/cglm/include/cglm/struct/vec2.h new file mode 100644 index 0000000..60f66d3 --- /dev/null +++ b/libs/cglm/include/cglm/struct/vec2.h @@ -0,0 +1,561 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLMS_VEC2_ONE_INIT + GLMS_VEC2_ZERO_INIT + GLMS_VEC2_ONE + GLMS_VEC2_ZERO + + Functions: + CGLM_INLINE vec2s glms_vec2(vec3s v3) + CGLM_INLINE void glms_vec2_pack(vec2s dst[], vec2 src[], size_t len) + CGLM_INLINE void glms_vec2_unpack(vec2 dst[], vec2s src[], size_t len) + CGLM_INLINE vec2s glms_vec2_zero(void) + CGLM_INLINE vec2s glms_vec2_one(void) + CGLM_INLINE float glms_vec2_dot(vec2s a, vec2s b) + CGLM_INLINE float glms_vec2_cross(vec2s a, vec2s b) + CGLM_INLINE float glms_vec2_norm2(vec2s v) + CGLM_INLINE float glms_vec2_norm(vec2s v) + CGLM_INLINE vec2s glms_vec2_add(vec2s a, vec2s b) + CGLM_INLINE vec2s glms_vec2_adds(vec2s a, float s) + CGLM_INLINE vec2s glms_vec2_sub(vec2s a, vec2s b) + CGLM_INLINE vec2s glms_vec2_subs(vec2s a, float s) + CGLM_INLINE vec2s glms_vec2_mul(vec2s a, vec2s b) + CGLM_INLINE vec2s glms_vec2_scale(vec2s v, float s) + CGLM_INLINE vec2s glms_vec2_scale_as(vec2s v, float s) + CGLM_INLINE vec2s glms_vec2_div(vec2s a, vec2s b) + CGLM_INLINE vec2s glms_vec2_divs(vec2s a, float s) + CGLM_INLINE vec2s glms_vec2_addadd(vec2s a, vec2s b, vec2s dest) + CGLM_INLINE vec2s glms_vec2_subadd(vec2s a, vec2s b, vec2s dest) + CGLM_INLINE vec2s glms_vec2_muladd(vec2s a, vec2s b, vec2s dest) + CGLM_INLINE vec2s glms_vec2_muladds(vec2s a, float s, vec2s dest) + CGLM_INLINE vec2s glms_vec2_maxadd(vec2s a, vec2s b, vec2s dest) + CGLM_INLINE vec2s glms_vec2_minadd(vec2s a, vec2s b, vec2s dest) + CGLM_INLINE vec2s glms_vec2_negate(vec2s v) + CGLM_INLINE vec2s glms_vec2_normalize(vec2s v) + CGLM_INLINE vec2s glms_vec2_rotate(vec2s v, float angle, vec2s axis) + CGLM_INLINE float glms_vec2_distance(vec2s a, vec2s b) + CGLM_INLINE float glms_vec2_distance2(vec2s a, vec2s b) + CGLM_INLINE vec2s glms_vec2_maxv(vec2s a, vec2s b) + CGLM_INLINE vec2s glms_vec2_minv(vec2s a, vec2s b) + CGLM_INLINE vec2s glms_vec2_clamp(vec2s v, float minVal, float maxVal) + CGLM_INLINE vec2s glms_vec2_lerp(vec2s from, vec2s to, float t) + */ + +#ifndef cglms_vec2s_h +#define cglms_vec2s_h + +#include "../common.h" +#include "../types-struct.h" +#include "../util.h" +#include "../vec2.h" +#include "vec2-ext.h" + +#define GLMS_VEC2_ONE_INIT {GLM_VEC2_ONE_INIT} +#define GLMS_VEC2_ZERO_INIT {GLM_VEC2_ZERO_INIT} + +#define GLMS_VEC2_ONE ((vec2s)GLMS_VEC2_ONE_INIT) +#define GLMS_VEC2_ZERO ((vec2s)GLMS_VEC2_ZERO_INIT) + +/*! + * @brief init vec2 using vec2 + * + * @param[in] v3 vector3 + * @returns destination + */ +CGLM_INLINE +vec2s +glms_vec2(vec3s v3) { + vec2s r; + glm_vec2(v3.raw, r.raw); + return r; +} + +/*! + * @brief pack an array of vec2 into an array of vec2s + * + * @param[out] dst array of vec2 + * @param[in] src array of vec2s + * @param[in] len number of elements + */ +CGLM_INLINE +void +glms_vec2_pack(vec2s dst[], vec2 src[], size_t len) { + size_t i; + + for (i = 0; i < len; i++) { + glm_vec2_copy(src[i], dst[i].raw); + } +} + +/*! + * @brief unpack an array of vec2s into an array of vec2 + * + * @param[out] dst array of vec2s + * @param[in] src array of vec2 + * @param[in] len number of elements + */ +CGLM_INLINE +void +glms_vec2_unpack(vec2 dst[], vec2s src[], size_t len) { + size_t i; + + for (i = 0; i < len; i++) { + glm_vec2_copy(src[i].raw, dst[i]); + } +} + +/*! + * @brief make vector zero + * + * @returns zero vector + */ +CGLM_INLINE +vec2s +glms_vec2_zero(void) { + vec2s r; + glm_vec2_zero(r.raw); + return r; +} + +/*! + * @brief make vector one + * + * @returns one vector + */ +CGLM_INLINE +vec2s +glms_vec2_one(void) { + vec2s r; + glm_vec2_one(r.raw); + return r; +} + +/*! + * @brief vec2 dot product + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ +CGLM_INLINE +float +glms_vec2_dot(vec2s a, vec2s b) { + return glm_vec2_dot(a.raw, b.raw); +} + +/*! + * @brief vec2 cross product + * + * REF: http://allenchou.net/2013/07/cross-product-of-2d-vectors/ + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return Z component of cross product + */ +CGLM_INLINE +float +glms_vec2_cross(vec2s a, vec2s b) { + return glm_vec2_cross(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_vec2_norm2(vec2s v) { + return glm_vec2_norm2(v.raw); +} + +/*! + * @brief norm (magnitude) of vec2 + * + * @param[in] v vector + * + * @return norm + */ +CGLM_INLINE +float +glms_vec2_norm(vec2s v) { + return glm_vec2_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 +vec2s +glms_vec2_add(vec2s a, vec2s b) { + vec2s r; + glm_vec2_add(a.raw, b.raw, r.raw); + return r; +} + +/*! + * @brief add scalar to v vector store result in dest (d = v + s) + * + * @param[in] a vector + * @param[in] s scalar + * @returns destination vector + */ +CGLM_INLINE +vec2s +glms_vec2_adds(vec2s a, float s) { + vec2s r; + glm_vec2_adds(a.raw, s, r.raw); + 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 +vec2s +glms_vec2_sub(vec2s a, vec2s b) { + vec2s r; + glm_vec2_sub(a.raw, b.raw, r.raw); + return r; +} + +/*! + * @brief subtract scalar from v vector store result in dest (d = v - s) + * + * @param[in] a vector + * @param[in] s scalar + * @returns destination vector + */ +CGLM_INLINE +vec2s +glms_vec2_subs(vec2s a, float s) { + vec2s r; + glm_vec2_subs(a.raw, s, r.raw); + 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 +vec2s +glms_vec2_mul(vec2s a, vec2s b) { + vec2s r; + glm_vec2_mul(a.raw, b.raw, r.raw); + return r; +} + +/*! + * @brief multiply/scale vec2 vector with scalar: result = v * s + * + * @param[in] v vector + * @param[in] s scalar + * @returns destination vector + */ +CGLM_INLINE +vec2s +glms_vec2_scale(vec2s v, float s) { + vec2s r; + glm_vec2_scale(v.raw, s, r.raw); + return r; +} + +/*! + * @brief make vec2 vector scale as specified: result = unit(v) * s + * + * @param[in] v vector + * @param[in] s scalar + * @returns destination vector + */ +CGLM_INLINE +vec2s +glms_vec2_scale_as(vec2s v, float s) { + vec2s r; + glm_vec2_scale_as(v.raw, s, r.raw); + 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 +vec2s +glms_vec2_div(vec2s a, vec2s b) { + vec2s r; + glm_vec2_div(a.raw, b.raw, r.raw); + return r; +} + +/*! + * @brief div vector with scalar: d = v / s + * + * @param[in] a vector + * @param[in] s scalar + * @returns result = (a[0]/s, a[1]/s, a[2]/s) + */ +CGLM_INLINE +vec2s +glms_vec2_divs(vec2s a, float s) { + vec2s r; + glm_vec2_divs(a.raw, s, r.raw); + 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 +vec2s +glms_vec2_addadd(vec2s a, vec2s b, vec2s dest) { + glm_vec2_addadd(a.raw, b.raw, dest.raw); + 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 +vec2s +glms_vec2_subadd(vec2s a, vec2s b, vec2s dest) { + glm_vec2_subadd(a.raw, b.raw, dest.raw); + 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 +vec2s +glms_vec2_muladd(vec2s a, vec2s b, vec2s dest) { + glm_vec2_muladd(a.raw, b.raw, dest.raw); + 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 +vec2s +glms_vec2_muladds(vec2s a, float s, vec2s dest) { + glm_vec2_muladds(a.raw, s, dest.raw); + 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 +vec2s +glms_vec2_maxadd(vec2s a, vec2s b, vec2s dest) { + glm_vec2_maxadd(a.raw, b.raw, dest.raw); + 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 +vec2s +glms_vec2_minadd(vec2s a, vec2s b, vec2s dest) { + glm_vec2_minadd(a.raw, b.raw, dest.raw); + return dest; +} + +/*! + * @brief negate vector components + * + * @param[in] v vector + * @returns negated vector + */ +CGLM_INLINE +vec2s +glms_vec2_negate(vec2s v) { + glm_vec2_negate(v.raw); + return v; +} + +/*! + * @brief normalize vec2 and store result in same vec + * + * @param[in] v vector + * @returns normalized vector + */ +CGLM_INLINE +vec2s +glms_vec2_normalize(vec2s v) { + glm_vec2_normalize(v.raw); + return v; +} + +/*! + * @brief rotate vec2 by angle using Rodrigues' rotation formula + * + * @param[in] v vector + * @param[in] angle angle by radians + * @returns rotated vector + */ +CGLM_INLINE +vec2s +glms_vec2_rotate(vec2s v, float angle) { + vec2s r; + glm_vec2_rotate(v.raw, angle, r.raw); + return r; +} + +/** + * @brief distance between two vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @return distance + */ +CGLM_INLINE +float +glms_vec2_distance(vec2s a, vec2s b) { + return glm_vec2_distance(a.raw, b.raw); +} + +/** + * @brief squared distance between two vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @return squared distance (distance * distance) + */ +CGLM_INLINE +float +glms_vec2_distance2(vec2s a, vec2s b) { + return glm_vec2_distance2(a.raw, b.raw); +} + +/*! + * @brief max values of vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns destination + */ +CGLM_INLINE +vec2s +glms_vec2_maxv(vec2s a, vec2s b) { + vec2s r; + glm_vec2_maxv(a.raw, b.raw, r.raw); + return r; +} + +/*! + * @brief min values of vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns destination + */ +CGLM_INLINE +vec2s +glms_vec2_minv(vec2s a, vec2s b) { + vec2s r; + glm_vec2_minv(a.raw, b.raw, r.raw); + 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 +vec2s +glms_vec2_clamp(vec2s v, float minVal, float maxVal) { + glm_vec2_clamp(v.raw, minVal, maxVal); + return v; +} + +/*! + * @brief linear interpolation between two vectors + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @returns destination + */ +CGLM_INLINE +vec2s +glms_vec2_lerp(vec2s from, vec2s to, float t) { + vec2s r; + glm_vec2_lerp(from.raw, to.raw, t, r.raw); + return r; +} + +#endif /* cglms_vec2s_h */ diff --git a/libs/cglm/include/cglm/struct/vec3-ext.h b/libs/cglm/include/cglm/struct/vec3-ext.h new file mode 100644 index 0000000..8e5ca70 --- /dev/null +++ b/libs/cglm/include/cglm/struct/vec3-ext.h @@ -0,0 +1,257 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/*! + * @brief SIMD like functions + */ + +/* + Functions: + CGLM_INLINE vec3s glms_vec3_broadcast(float val); + CGLM_INLINE vec3s glms_vec3_fill(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_abs(vec3s v); + CGLM_INLINE vec3s glms_vec3_fract(vec3s v); + CGLM_INLINE float glms_vec3_hadd(vec3s v); + CGLM_INLINE vec3s glms_vec3_sqrt(vec3s v); + */ + +#ifndef cglms_vec3s_ext_h +#define cglms_vec3s_ext_h + +#include "../common.h" +#include "../types-struct.h" +#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) { + vec3s r; + glm_vec3_broadcast(val, r.raw); + return r; +} + +/*! + * @brief fill a vector with specified value + * + * @param[in] val value + * @returns dest + */ +CGLM_INLINE +vec3s +glms_vec3_fill(float val) { + vec3s r; + glm_vec3_fill(r.raw, 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) { + vec3s r; + glm_vec3_sign(v.raw, r.raw); + return r; +} + +/*! + * @brief absolute value of each vector item + * + * @param[in] v vector + * @return destination vector + */ +CGLM_INLINE +vec3s +glms_vec3_abs(vec3s v) { + vec3s r; + glm_vec3_abs(v.raw, r.raw); + return r; +} + +/*! + * @brief fractional part of each vector item + * + * @param[in] v vector + * @return dest destination vector + */ +CGLM_INLINE +vec3s +glms_vec3_fract(vec3s v) { + vec3s r; + glm_vec3_fract(v.raw, r.raw); + return r; +} + +/*! + * @brief vector reduction by summation + * @warning could overflow + * + * @param[in] v vector + * @return sum of all vector's elements + */ +CGLM_INLINE +float +glms_vec3_hadd(vec3s v) { + return glm_vec3_hadd(v.raw); +} + +/*! + * @brief square root of each vector item + * + * @param[in] v vector + * @returns destination vector + */ +CGLM_INLINE +vec3s +glms_vec3_sqrt(vec3s v) { + vec3s r; + glm_vec3_sqrt(v.raw, r.raw); + return r; +} + +#endif /* cglms_vec3s_ext_h */ diff --git a/libs/cglm/include/cglm/struct/vec3.h b/libs/cglm/include/cglm/struct/vec3.h new file mode 100644 index 0000000..7fa5b06 --- /dev/null +++ b/libs/cglm/include/cglm/struct/vec3.h @@ -0,0 +1,970 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * 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 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(void); + CGLM_INLINE vec3s glms_vec3_one(void); + 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 float glms_vec3_norm_one(vec3s v); + CGLM_INLINE float glms_vec3_norm_inf(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_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_distance(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_lerpc(vec3s from, vec3s to, float t); + CGLM_INLINE vec3s glms_vec3_mix(vec3s from, vec3s to, float t); + CGLM_INLINE vec3s glms_vec3_mixc(vec3s from, vec3s to, float t); + CGLM_INLINE vec3s glms_vec3_step_uni(float edge, vec3s x); + CGLM_INLINE vec3s glms_vec3_step(vec3s edge, vec3s x); + CGLM_INLINE vec3s glms_vec3_smoothstep_uni(float edge0, float edge1, vec3s x); + CGLM_INLINE vec3s glms_vec3_smoothstep(vec3s edge0, vec3s edge1, vec3s x); + CGLM_INLINE vec3s glms_vec3_smoothinterp(vec3s from, vec3s to, float t); + CGLM_INLINE vec3s glms_vec3_smoothinterpc(vec3s from, vec3s to, float t); + CGLM_INLINE vec3s glms_vec3_swizzle(vec3s v, int mask); + + 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 cglms_vec3s_h +#define cglms_vec3s_h + +#include "../common.h" +#include "../types-struct.h" +#include "../util.h" +#include "../vec3.h" +#include "vec3-ext.h" + +#define GLMS_VEC3_ONE_INIT {GLM_VEC3_ONE_INIT} +#define GLMS_VEC3_ZERO_INIT {GLM_VEC3_ZERO_INIT} + +#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}}) + +/*! + * @brief init vec3 using vec4 + * + * @param[in] v4 vector4 + * @returns destination + */ +CGLM_INLINE +vec3s +glms_vec3(vec4s v4) { + vec3s r; + glm_vec3(v4.raw, r.raw); + 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) { + size_t i; + + for (i = 0; i < len; i++) { + glm_vec3_copy(src[i], dst[i].raw); + } +} + +/*! + * @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) { + size_t i; + + for (i = 0; i < len; i++) { + glm_vec3_copy(src[i].raw, dst[i]); + } +} + +/*! + * @brief make vector zero + * + * @returns zero vector + */ +CGLM_INLINE +vec3s +glms_vec3_zero(void) { + vec3s r; + glm_vec3_zero(r.raw); + return r; +} + +/*! + * @brief make vector one + * + * @returns one vector + */ +CGLM_INLINE +vec3s +glms_vec3_one(void) { + vec3s r; + glm_vec3_one(r.raw); + 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 L1 norm of vec3 + * Also known as Manhattan Distance or Taxicab norm. + * L1 Norm is the sum of the magnitudes of the vectors in a space. + * It is calculated as the sum of the absolute values of the vector components. + * In this norm, all the components of the vector are weighted equally. + * + * This computes: + * R = |v[0]| + |v[1]| + |v[2]| + * + * @param[in] v vector + * + * @return L1 norm + */ +CGLM_INLINE +float +glms_vec3_norm_one(vec3s v) { + return glm_vec3_norm_one(v.raw); +} + +/*! + * @brief Infinity norm of vec3 + * Also known as Maximum norm. + * Infinity Norm is the largest magnitude among each element of a vector. + * It is calculated as the maximum of the absolute values of the vector components. + * + * This computes: + * inf norm = max(|v[0]|, |v[1]|, |v[2]|) + * + * @param[in] v vector + * + * @return Infinity norm + */ +CGLM_INLINE +float +glms_vec3_norm_inf(vec3s v) { + return glm_vec3_norm_inf(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) { + vec3s r; + glm_vec3_add(a.raw, b.raw, r.raw); + return r; +} + +/*! + * @brief add scalar to v vector store result in dest (d = v + s) + * + * @param[in] a vector + * @param[in] s scalar + * @returns destination vector + */ +CGLM_INLINE +vec3s +glms_vec3_adds(vec3s a, float s) { + vec3s r; + glm_vec3_adds(a.raw, s, r.raw); + 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) { + vec3s r; + glm_vec3_sub(a.raw, b.raw, r.raw); + return r; +} + +/*! + * @brief subtract scalar from v vector store result in dest (d = v - s) + * + * @param[in] a vector + * @param[in] s scalar + * @returns destination vector + */ +CGLM_INLINE +vec3s +glms_vec3_subs(vec3s a, float s) { + vec3s r; + glm_vec3_subs(a.raw, s, r.raw); + 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) { + vec3s r; + glm_vec3_mul(a.raw, b.raw, r.raw); + 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) { + vec3s r; + glm_vec3_scale(v.raw, s, r.raw); + 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) { + vec3s r; + glm_vec3_scale_as(v.raw, s, r.raw); + 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) { + vec3s r; + glm_vec3_div(a.raw, b.raw, r.raw); + return r; +} + +/*! + * @brief div vector with scalar: d = v / s + * + * @param[in] a 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) { + vec3s r; + glm_vec3_divs(a.raw, s, r.raw); + 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) { + glm_vec3_addadd(a.raw, b.raw, dest.raw); + 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) { + glm_vec3_subadd(a.raw, b.raw, dest.raw); + 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) { + glm_vec3_muladd(a.raw, b.raw, dest.raw); + 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) { + glm_vec3_muladds(a.raw, s, dest.raw); + 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) { + glm_vec3_maxadd(a.raw, b.raw, dest.raw); + 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) { + glm_vec3_minadd(a.raw, b.raw, dest.raw); + 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) { + glm_vec3_flipsign(v.raw); + return v; +} + +/*! + * @brief negate vector components + * + * @param[in] v vector + * @returns negated vector + */ +CGLM_INLINE +vec3s +glms_vec3_negate(vec3s v) { + glm_vec3_negate(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) { + glm_vec3_normalize(v.raw); + 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) { + vec3s r; + glm_vec3_cross(a.raw, b.raw, r.raw); + 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) { + vec3s r; + glm_vec3_crossn(a.raw, b.raw, r.raw); + return r; +} + +/*! + * @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) { + glm_vec3_rotate(v.raw, angle, axis.raw); + 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) { + vec3s r; + glm_vec3_rotate_m4(m.raw, v.raw, r.raw); + 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) { + vec3s r; + glm_vec3_rotate_m3(m.raw, v.raw, r.raw); + 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) { + vec3s r; + glm_vec3_proj(a.raw, b.raw, r.raw); + 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) { + vec3s r; + glm_vec3_center(a.raw, b.raw, r.raw); + return r; +} + +/** + * @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 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 max values of vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @returns destination + */ +CGLM_INLINE +vec3s +glms_vec3_maxv(vec3s a, vec3s b) { + vec3s r; + glm_vec3_maxv(a.raw, b.raw, r.raw); + 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) { + vec3s r; + glm_vec3_minv(a.raw, b.raw, r.raw); + return r; +} + +/*! + * @brief possible orthogonal/perpendicular vector + * + * @param[in] v vector + * @returns orthogonal/perpendicular vector + */ +CGLM_INLINE +vec3s +glms_vec3_ortho(vec3s v) { + vec3s r; + glm_vec3_ortho(v.raw, r.raw); + 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) { + glm_vec3_clamp(v.raw, minVal, maxVal); + return v; +} + +/*! + * @brief linear interpolation between two vectors + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @returns destination + */ +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; +} + +/*! + * @brief linear interpolation between two vectors (clamped) + * + * 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_lerpc(vec3s from, vec3s to, float t) { + vec3s r; + glm_vec3_lerpc(from.raw, to.raw, t, r.raw); + return r; +} + +/*! + * @brief linear interpolation between two vectors + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @returns destination + */ +CGLM_INLINE +vec3s +glms_vec3_mix(vec3s from, vec3s to, float t) { + vec3s r; + glm_vec3_mix(from.raw, to.raw, t, r.raw); + return r; +} + +/*! + * @brief linear interpolation between two vectors (clamped) + * + * 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_mixc(vec3s from, vec3s to, float t) { + vec3s r; + glm_vec3_mixc(from.raw, to.raw, t, r.raw); + return r; +} + +/*! + * @brief threshold function (unidimensional) + * + * @param[in] edge threshold + * @param[in] x value to test against threshold + * @returns 0.0 if x < edge, else 1.0 + */ +CGLM_INLINE +vec3s +glms_vec3_step_uni(float edge, vec3s x) { + vec3s r; + glm_vec3_step_uni(edge, x.raw, r.raw); + return r; +} + +/*! + * @brief threshold function + * + * @param[in] edge threshold + * @param[in] x value to test against threshold + * @returns 0.0 if x < edge, else 1.0 + */ +CGLM_INLINE +vec3s +glms_vec3_step(vec3s edge, vec3s x) { + vec3s r; + glm_vec3_step(edge.raw, x.raw, r.raw); + return r; +} + +/*! + * @brief threshold function with a smooth transition (unidimensional) + * + * @param[in] edge0 low threshold + * @param[in] edge1 high threshold + * @param[in] x value to test against threshold + * @returns destination + */ +CGLM_INLINE +vec3s +glms_vec3_smoothstep_uni(float edge0, float edge1, vec3s x) { + vec3s r; + glm_vec3_smoothstep_uni(edge0, edge1, x.raw, r.raw); + return r; +} + +/*! + * @brief threshold function with a smooth transition + * + * @param[in] edge0 low threshold + * @param[in] edge1 high threshold + * @param[in] x value to test against threshold + * @returns destination + */ +CGLM_INLINE +vec3s +glms_vec3_smoothstep(vec3s edge0, vec3s edge1, vec3s x) { + vec3s r; + glm_vec3_smoothstep(edge0.raw, edge1.raw, x.raw, r.raw); + return r; +} + +/*! + * @brief smooth Hermite interpolation between two vectors + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @returns destination + */ +CGLM_INLINE +vec3s +glms_vec3_smoothinterp(vec3s from, vec3s to, float t) { + vec3s r; + glm_vec3_smoothinterp(from.raw, to.raw, t, r.raw); + return r; +} + +/*! + * @brief smooth Hermite interpolation between two vectors (clamped) + * + * 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_smoothinterpc(vec3s from, vec3s to, float t) { + vec3s r; + glm_vec3_smoothinterpc(from.raw, to.raw, t, r.raw); + 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) { + vec3s r; + glm_cross(a.raw, b.raw, r.raw); + 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) { + glm_normalize(v.raw); + return v; +} + +/*! + * @brief swizzle vector components + * + * you can use existin masks e.g. GLM_XXX, GLM_ZYX + * + * @param[in] v source + * @param[in] mask mask + * @returns swizzled vector + */ +CGLM_INLINE +vec3s +glms_vec3_swizzle(vec3s v, int mask) { + vec3s dest; + glm_vec3_swizzle(v.raw, mask, dest.raw); + return dest; +} + +#endif /* cglms_vec3s_h */ diff --git a/libs/cglm/include/cglm/struct/vec4-ext.h b/libs/cglm/include/cglm/struct/vec4-ext.h new file mode 100644 index 0000000..d5cddec --- /dev/null +++ b/libs/cglm/include/cglm/struct/vec4-ext.h @@ -0,0 +1,257 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/*! + * @brief SIMD like functions + */ + +/* + Functions: + CGLM_INLINE vec4s glms_vec4_broadcast(float val); + CGLM_INLINE vec4s glms_vec4_fill(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_abs(vec4s v); + CGLM_INLINE vec4s glms_vec4_fract(vec4s v); + CGLM_INLINE float glms_vec4_hadd(vec4s v); + CGLM_INLINE vec4s glms_vec4_sqrt(vec4s v); + */ + +#ifndef cglms_vec4s_ext_h +#define cglms_vec4s_ext_h + +#include "../common.h" +#include "../types-struct.h" +#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) { + vec4s r; + glm_vec4_broadcast(val, r.raw); + return r; +} + +/*! + * @brief fill a vector with specified value + * + * @param val value + * @returns dest + */ +CGLM_INLINE +vec4s +glms_vec4_fill(float val) { + vec4s r; + glm_vec4_fill(r.raw, 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) { + vec4s r; + glm_vec4_sign(v.raw, r.raw); + return r; +} + +/*! + * @brief absolute value of each vector item + * + * @param[in] v vector + * @returns destination vector + */ +CGLM_INLINE +vec4s +glms_vec4_abs(vec4s v) { + vec4s r; + glm_vec4_abs(v.raw, r.raw); + return r; +} + +/*! + * @brief fractional part of each vector item + * + * @param[in] v vector + * @returns dest destination vector + */ +CGLM_INLINE +vec4s +glms_vec4_fract(vec4s v) { + vec4s r; + glm_vec4_fract(v.raw, r.raw); + return r; +} + +/*! + * @brief vector reduction by summation + * @warning could overflow + * + * @param[in] v vector + * @return sum of all vector's elements + */ +CGLM_INLINE +float +glms_vec4_hadd(vec4s v) { + return glm_vec4_hadd(v.raw); +} + +/*! + * @brief square root of each vector item + * + * @param[in] v vector + * @returns destination vector + */ +CGLM_INLINE +vec4s +glms_vec4_sqrt(vec4s v) { + vec4s r; + glm_vec4_sqrt(v.raw, r.raw); + return r; +} + +#endif /* cglms_vec4s_ext_h */ diff --git a/libs/cglm/include/cglm/struct/vec4.h b/libs/cglm/include/cglm/struct/vec4.h new file mode 100644 index 0000000..4469cb2 --- /dev/null +++ b/libs/cglm/include/cglm/struct/vec4.h @@ -0,0 +1,814 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLMS_VEC4_ONE_INIT + GLMS_VEC4_BLACK_INIT + GLMS_VEC4_ZERO_INIT + GLMS_VEC4_ONE + GLMS_VEC4_BLACK + GLMS_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 float glms_vec4_norm_one(vec4s v); + CGLM_INLINE float glms_vec4_norm_inf(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 float glms_vec4_distance2(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_lerpc(vec4s from, vec4s to, float t); + CGLM_INLINE vec4s glms_vec4_mix(vec4s from, vec4s to, float t); + CGLM_INLINE vec4s glms_vec4_mixc(vec4s from, vec4s to, float t); + CGLM_INLINE vec4s glms_vec4_step_uni(float edge, vec4s x); + CGLM_INLINE vec4s glms_vec4_step(vec4s edge, vec4s x); + CGLM_INLINE vec4s glms_vec4_smoothstep_uni(float edge0, float edge1, vec4s x); + CGLM_INLINE vec4s glms_vec4_smoothstep(vec4s edge0, vec4s edge1, vec4s x); + CGLM_INLINE vec4s glms_vec4_smoothinterp(vec4s from, vec4s to, float t); + CGLM_INLINE vec4s glms_vec4_smoothinterpc(vec4s from, vec4s to, float t); + CGLM_INLINE vec4s glms_vec4_cubic(float s); + CGLM_INLINE vec4s glms_vec4_swizzle(vec4s v, int mask); + */ + +#ifndef cglms_vec4s_h +#define cglms_vec4s_h + +#include "../common.h" +#include "../types-struct.h" +#include "../util.h" +#include "../vec4.h" +#include "vec4-ext.h" + +#define GLMS_VEC4_ONE_INIT {GLM_VEC4_ONE_INIT} +#define GLMS_VEC4_BLACK_INIT {GLM_VEC4_BLACK_INIT} +#define GLMS_VEC4_ZERO_INIT {GLM_VEC4_ZERO_INIT} + +#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) + +/*! + * @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) { + vec4s r; + glm_vec4(v3.raw, last, r.raw); + return r; +} + +/*! + * @brief copy first 3 members of [a] to [dest] + * + * @param[in] v source + * @returns vec3 + */ +CGLM_INLINE +vec3s +glms_vec4_copy3(vec4s v) { + vec3s r; + glm_vec4_copy3(v.raw, r.raw); + return r; +} + +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] v source + * @returns destination + */ +CGLM_INLINE +vec4s +glms_vec4_copy(vec4s v) { + vec4s r; + glm_vec4_copy(v.raw, r.raw); + 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) { + vec4s r; + glm_vec4_ucopy(v.raw, r.raw); + 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) { + size_t i; + + for (i = 0; i < len; i++) { + glm_vec4_copy(src[i], dst[i].raw); + } +} + +/*! + * @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) { + size_t i; + + for (i = 0; i < len; i++) { + glm_vec4_copy(src[i].raw, dst[i]); + } +} + +/*! + * @brief make vector zero + * + * @returns zero vector + */ +CGLM_INLINE +vec4s +glms_vec4_zero(void) { + vec4s r; + glm_vec4_zero(r.raw); + return r; +} + +/*! + * @brief make vector one + * + * @returns one vector + */ +CGLM_INLINE +vec4s +glms_vec4_one(void) { + 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 L1 norm of vec4 + * Also known as Manhattan Distance or Taxicab norm. + * L1 Norm is the sum of the magnitudes of the vectors in a space. + * It is calculated as the sum of the absolute values of the vector components. + * In this norm, all the components of the vector are weighted equally. + * + * This computes: + * R = |v[0]| + |v[1]| + |v[2]| + |v[3]| + * + * @param[in] v vector + * + * @return L1 norm + */ +CGLM_INLINE +float +glms_vec4_norm_one(vec4s v) { + return glm_vec4_norm_one(v.raw); +} + +/*! + * @brief Infinity norm of vec4 + * Also known as Maximum norm. + * Infinity Norm is the largest magnitude among each element of a vector. + * It is calculated as the maximum of the absolute values of the vector components. + * + * This computes: + * inf norm = max(|v[0]|, |v[1]|, |v[2]|, |v[3]|) + * + * @param[in] v vector + * + * @return Infinity norm + */ +CGLM_INLINE +float +glms_vec4_norm_inf(vec4s v) { + return glm_vec4_norm_inf(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) { + vec4s r; + glm_vec4_add(a.raw, b.raw, r.raw); + 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) { + vec4s r; + glm_vec4_adds(v.raw, s, r.raw); + 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) { + vec4s r; + glm_vec4_sub(a.raw, b.raw, r.raw); + 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) { + vec4s r; + glm_vec4_subs(v.raw, s, r.raw); + 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) { + vec4s r; + glm_vec4_mul(a.raw, b.raw, r.raw); + 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) { + vec4s r; + glm_vec4_scale(v.raw, s, r.raw); + 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) { + vec4s r; + glm_vec4_scale_as(v.raw, s, r.raw); + 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) { + vec4s r; + glm_vec4_div(a.raw, b.raw, r.raw); + 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) { + vec4s r; + glm_vec4_divs(v.raw, s, r.raw); + 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) { + glm_vec4_addadd(a.raw, b.raw, dest.raw); + 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) { + glm_vec4_subadd(a.raw, b.raw, dest.raw); + 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) { + glm_vec4_muladd(a.raw, b.raw, dest.raw); + 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) { + glm_vec4_muladds(a.raw, s, dest.raw); + 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) { + glm_vec4_maxadd(a.raw, b.raw, dest.raw); + 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) { + glm_vec4_minadd(a.raw, b.raw, dest.raw); + 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) { + glm_vec4_negate(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) { + glm_vec4_normalize(v.raw); + 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 squared distance between two vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @return returns squared distance + */ +CGLM_INLINE +float +glms_vec4_distance2(vec4s a, vec4s b) { + return glm_vec4_distance2(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) { + vec4s r; + glm_vec4_maxv(a.raw, b.raw, r.raw); + 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) { + vec4s r; + glm_vec4_minv(a.raw, b.raw, r.raw); + 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) { + glm_vec4_clamp(v.raw, minVal, maxVal); + return v; +} + +/*! + * @brief linear interpolation between two vectors + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @returns destination + */ +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; +} + +/*! + * @brief linear interpolation between two vectors (clamped) + * + * 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_lerpc(vec4s from, vec4s to, float t) { + vec4s r; + glm_vec4_lerpc(from.raw, to.raw, t, r.raw); + return r; +} + +/*! + * @brief linear interpolation between two vectors + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @returns destination + */ +CGLM_INLINE +vec4s +glms_vec4_mix(vec4s from, vec4s to, float t) { + vec4s r; + glm_vec4_mix(from.raw, to.raw, t, r.raw); + return r; +} + +/*! + * @brief linear interpolation between two vectors (clamped) + * + * 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_mixc(vec4s from, vec4s to, float t) { + vec4s r; + glm_vec4_mixc(from.raw, to.raw, t, r.raw); + return r; +} + +/*! + * @brief threshold function (unidimensional) + * + * @param[in] edge threshold + * @param[in] x value to test against threshold + * @returns 0.0 if x < edge, else 1.0 + */ +CGLM_INLINE +vec4s +glms_vec4_step_uni(float edge, vec4s x) { + vec4s r; + glm_vec4_step_uni(edge, x.raw, r.raw); + return r; +} + +/*! + * @brief threshold function + * + * @param[in] edge threshold + * @param[in] x value to test against threshold + * @returns 0.0 if x < edge, else 1.0 + */ +CGLM_INLINE +vec4s +glms_vec4_step(vec4s edge, vec4s x) { + vec4s r; + glm_vec4_step(edge.raw, x.raw, r.raw); + return r; +} + +/*! + * @brief threshold function with a smooth transition (unidimensional) + * + * @param[in] edge0 low threshold + * @param[in] edge1 high threshold + * @param[in] x value to test against threshold + * @returns destination + */ +CGLM_INLINE +vec4s +glms_vec4_smoothstep_uni(float edge0, float edge1, vec4s x) { + vec4s r; + glm_vec4_smoothstep_uni(edge0, edge1, x.raw, r.raw); + return r; +} + +/*! + * @brief threshold function with a smooth transition + * + * @param[in] edge0 low threshold + * @param[in] edge1 high threshold + * @param[in] x value to test against threshold + * @returns destination + */ +CGLM_INLINE +vec4s +glms_vec4_smoothstep(vec4s edge0, vec4s edge1, vec4s x) { + vec4s r; + glm_vec4_smoothstep(edge0.raw, edge1.raw, x.raw, r.raw); + return r; +} + +/*! + * @brief smooth Hermite interpolation between two vectors + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @returns destination + */ +CGLM_INLINE +vec4s +glms_vec4_smoothinterp(vec4s from, vec4s to, float t) { + vec4s r; + glm_vec4_smoothinterp(from.raw, to.raw, t, r.raw); + return r; +} + +/*! + * @brief smooth Hermite interpolation between two vectors (clamped) + * + * 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_smoothinterpc(vec4s from, vec4s to, float t) { + vec4s r; + glm_vec4_smoothinterpc(from.raw, to.raw, t, r.raw); + 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) { + vec4s r; + glm_vec4_cubic(s, r.raw); + return r; +} + +/*! + * @brief swizzle vector components + * + * you can use existin masks e.g. GLM_XXXX, GLM_WZYX + * + * @param[in] v source + * @param[in] mask mask + * @returns swizzled vector + */ +CGLM_INLINE +vec4s +glms_vec4_swizzle(vec4s v, int mask) { + vec4s dest; + glm_vec4_swizzle(v.raw, mask, dest.raw); + return dest; +} + +#endif /* cglms_vec4s_h */ diff --git a/libs/cglm/include/cglm/types-struct.h b/libs/cglm/include/cglm/types-struct.h new file mode 100644 index 0000000..1d91097 --- /dev/null +++ b/libs/cglm/include/cglm/types-struct.h @@ -0,0 +1,218 @@ +/* + * 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" + +/* + * Anonymous structs are available since C11, but we'd like to be compatible + * with C99 and C89 too. So let's figure out if we should be using them or not. + * It's simply a convenience feature, you can e.g. build the library with + * anonymous structs and your application without them and they'll still be + * compatible, cglm doesn't use the anonymous structs internally. + */ +#ifndef CGLM_USE_ANONYMOUS_STRUCT + /* If the user doesn't explicitly specify if they want anonymous structs or + * not, then we'll try to intuit an appropriate choice. */ +# if defined(CGLM_NO_ANONYMOUS_STRUCT) + /* The user has defined CGLM_NO_ANONYMOUS_STRUCT. This used to be the + * only #define governing the use of anonymous structs, so for backward + * compatibility, we still honor that choice and disable them. */ +# define CGLM_USE_ANONYMOUS_STRUCT 0 +# elif __STDC_VERSION__ >= 20112L || defined(_MSVC_VER) + /* We're compiling for C11 or this is the MSVC compiler. In either + * case, anonymous structs are available, so use them. */ +# define CGLM_USE_ANONYMOUS_STRUCT 1 +# elif defined(_MSC_VER) && (_MSC_VER >= 1900) /* Visual Studio 2015 */ + /* We can support anonymous structs + * since Visual Studio 2015 or 2017 (1910) maybe? */ +# define CGLM_USE_ANONYMOUS_STRUCT 1 +# else + /* Otherwise, we're presumably building for C99 or C89 and can't rely + * on anonymous structs being available. Turn them off. */ +# define CGLM_USE_ANONYMOUS_STRUCT 0 +# endif +#endif + +typedef union vec2s { + vec2 raw; +#if CGLM_USE_ANONYMOUS_STRUCT + struct { + float x; + float y; + }; + + struct { + float r; + float i; + }; + + struct { + float u; + float v; + }; + + struct { + float s; + float t; + }; +#endif +} vec2s; + +typedef union vec3s { + vec3 raw; +#if CGLM_USE_ANONYMOUS_STRUCT + struct { + float x; + float y; + float z; + }; + + struct { + float r; + float g; + float b; + }; +#endif +} vec3s; + +typedef union ivec2s { + ivec2 raw; +#if CGLM_USE_ANONYMOUS_STRUCT + struct { + int x; + int y; + }; + + struct { + int r; + int i; + }; + + struct { + int u; + int v; + }; + + struct { + int s; + int t; + }; +#endif +} ivec2s; + +typedef union ivec3s { + ivec3 raw; +#if CGLM_USE_ANONYMOUS_STRUCT + struct { + int x; + int y; + int z; + }; + + struct { + int r; + int g; + int b; + }; +#endif +} ivec3s; + +typedef union ivec4s { + ivec4 raw; +#if CGLM_USE_ANONYMOUS_STRUCT + struct { + int x; + int y; + int z; + int w; + }; + + struct { + int r; + int g; + int b; + int a; + }; +#endif +} ivec4s; + +typedef union CGLM_ALIGN_IF(16) vec4s { + vec4 raw; +#if CGLM_USE_ANONYMOUS_STRUCT + struct { + float x; + float y; + float z; + float w; + }; + + struct { + float r; + float g; + float b; + float a; + }; +#endif +} vec4s; + +typedef union CGLM_ALIGN_IF(16) versors { + vec4 raw; +#if CGLM_USE_ANONYMOUS_STRUCT + struct { + float x; + float y; + float z; + float w; + }; + + struct { + vec3s imag; + float real; + }; +#endif +} versors; + +typedef union mat2s { + mat2 raw; + vec2s col[2]; +#if CGLM_USE_ANONYMOUS_STRUCT + struct { + float m00, m01; + float m10, m11; + }; +#endif +} mat2s; + +typedef union mat3s { + mat3 raw; + vec3s col[3]; +#if CGLM_USE_ANONYMOUS_STRUCT + struct { + float m00, m01, m02; + float m10, m11, m12; + float m20, m21, m22; + }; +#endif +} mat3s; + +typedef union CGLM_ALIGN_MAT mat4s { + mat4 raw; + vec4s col[4]; +#if CGLM_USE_ANONYMOUS_STRUCT + struct { + float m00, m01, m02, m03; + float m10, m11, m12, m13; + float m20, m21, m22, m23; + float m30, m31, m32, m33; + }; +#endif +} mat4s; + +#endif /* cglm_types_struct_h */ diff --git a/libs/cglm/include/cglm/types.h b/libs/cglm/include/cglm/types.h new file mode 100644 index 0000000..a671c5a --- /dev/null +++ b/libs/cglm/include/cglm/types.h @@ -0,0 +1,95 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_types_h +#define cglm_types_h + +#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 +#else +# define CGLM_ALIGN(X) __attribute((aligned(X))) +#endif + +#ifndef CGLM_ALL_UNALIGNED +# define CGLM_ALIGN_IF(X) CGLM_ALIGN(X) +#else +# 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 + +#ifdef __GNUC__ +# define CGLM_ASSUME_ALIGNED(expr, alignment) \ + __builtin_assume_aligned((expr), (alignment)) +#else +# define CGLM_ASSUME_ALIGNED(expr, alignment) (expr) +#endif + +#define CGLM_CASTPTR_ASSUME_ALIGNED(expr, type) \ + ((type*)CGLM_ASSUME_ALIGNED((expr), __alignof__(type))) + +typedef int ivec2[2]; +typedef int ivec3[3]; +typedef int ivec4[4]; + +typedef float vec2[2]; +typedef float vec3[3]; +typedef CGLM_ALIGN_IF(16) float vec4[4]; +typedef vec4 versor; /* |x, y, z, w| -> w is the last */ +typedef vec3 mat3[3]; +typedef CGLM_ALIGN_IF(16) vec2 mat2[2]; +typedef CGLM_ALIGN_MAT vec4 mat4[4]; + +/* + 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. +*/ + +#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) +#define GLM_LOG10Ef ((float)GLM_LOG10E) +#define GLM_LN2f ((float)GLM_LN2) +#define GLM_LN10f ((float)GLM_LN10) +#define GLM_PIf ((float)GLM_PI) +#define GLM_PI_2f ((float)GLM_PI_2) +#define GLM_PI_4f ((float)GLM_PI_4) +#define GLM_1_PIf ((float)GLM_1_PI) +#define GLM_2_PIf ((float)GLM_2_PI) +#define GLM_2_SQRTPIf ((float)GLM_2_SQRTPI) +#define GLM_SQRT2f ((float)GLM_SQRT2) +#define GLM_SQRT1_2f ((float)GLM_SQRT1_2) + +/* DEPRECATED! use GLM_PI and friends */ +#define CGLM_PI GLM_PIf +#define CGLM_PI_2 GLM_PI_2f +#define CGLM_PI_4 GLM_PI_4f + +#endif /* cglm_types_h */ diff --git a/libs/cglm/include/cglm/util.h b/libs/cglm/include/cglm/util.h new file mode 100644 index 0000000..53b1ed5 --- /dev/null +++ b/libs/cglm/include/cglm/util.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 int glm_sign(int val); + CGLM_INLINE float glm_signf(float val); + CGLM_INLINE float glm_rad(float deg); + CGLM_INLINE float glm_deg(float rad); + CGLM_INLINE void glm_make_rad(float *deg); + CGLM_INLINE void glm_make_deg(float *rad); + CGLM_INLINE float glm_pow2(float x); + CGLM_INLINE float glm_min(float a, float b); + CGLM_INLINE float glm_max(float a, float b); + CGLM_INLINE float glm_clamp(float val, float minVal, float maxVal); + CGLM_INLINE float glm_clamp_zo(float val, float minVal, float maxVal); + CGLM_INLINE float glm_lerp(float from, float to, float t); + CGLM_INLINE float glm_lerpc(float from, float to, float t); + CGLM_INLINE float glm_step(float edge, float x); + CGLM_INLINE float glm_smooth(float t); + CGLM_INLINE float glm_smoothstep(float edge0, float edge1, float x); + CGLM_INLINE float glm_smoothinterp(float from, float to, float t); + CGLM_INLINE float glm_smoothinterpc(float from, float to, float t); + CGLM_INLINE bool glm_eq(float a, float b); + CGLM_INLINE float glm_percent(float from, float to, float current); + CGLM_INLINE float glm_percentc(float from, float to, float current); + */ + +#ifndef cglm_util_h +#define cglm_util_h + +#include "common.h" + +#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 + * + * Important: It returns 0 for zero input + * + * @param val integer value + */ +CGLM_INLINE +int +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 (float)((val > 0.0f) - (val < 0.0f)); +} + +/*! + * @brief convert degree to radians + * + * @param[in] deg angle in degrees + */ +CGLM_INLINE +float +glm_rad(float deg) { + return deg * GLM_PIf / 180.0f; +} + +/*! + * @brief convert radians to degree + * + * @param[in] rad angle in radians + */ +CGLM_INLINE +float +glm_deg(float rad) { + return rad * 180.0f / GLM_PIf; +} + +/*! + * @brief convert exsisting degree to radians. this will override degrees value + * + * @param[in, out] deg pointer to angle in degrees + */ +CGLM_INLINE +void +glm_make_rad(float *deg) { + *deg = *deg * GLM_PIf / 180.0f; +} + +/*! + * @brief convert exsisting radians to degree. this will override radians value + * + * @param[in, out] rad pointer to angle in radians + */ +CGLM_INLINE +void +glm_make_deg(float *rad) { + *rad = *rad * 180.0f / GLM_PIf; +} + +/*! + * @brief multiplies given parameter with itself = x * x or powf(x, 2) + * + * @param[in] x x + */ +CGLM_INLINE +float +glm_pow2(float x) { + return x * x; +} + +/*! + * @brief find minimum of given two values + * + * @param[in] a number 1 + * @param[in] b number 2 + */ +CGLM_INLINE +float +glm_min(float a, float b) { + if (a < b) + return a; + return b; +} + +/*! + * @brief find maximum of given two values + * + * @param[in] a number 1 + * @param[in] b number 2 + */ +CGLM_INLINE +float +glm_max(float a, float b) { + if (a > b) + return a; + 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); +} + +/*! + * @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 numbers + * + * formula: from + t * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + */ +CGLM_INLINE +float +glm_lerp(float from, float to, float t) { + return from + t * (to - from); +} + +/*! + * @brief clamped linear interpolation between two numbers + * + * formula: from + t * (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_lerpc(float from, float to, float t) { + return glm_lerp(from, to, glm_clamp_zo(t)); +} + +/*! + * @brief threshold function + * + * @param[in] edge threshold + * @param[in] x value to test against threshold + * @return returns 0.0 if x < edge, else 1.0 + */ +CGLM_INLINE +float +glm_step(float edge, float x) { + /* branching - no type conversion */ + return (x < edge) ? 0.0f : 1.0f; + /* + * An alternative implementation without branching + * but with type conversion could be: + * return !(x < edge); + */ +} + +/*! + * @brief smooth Hermite interpolation + * + * formula: t^2 * (3-2t) + * + * @param[in] t interpolant (amount) + */ +CGLM_INLINE +float +glm_smooth(float t) { + return t * t * (3.0f - 2.0f * t); +} + +/*! + * @brief threshold function with a smooth transition (according to OpenCL specs) + * + * formula: t^2 * (3-2t) + * + * @param[in] edge0 low threshold + * @param[in] edge1 high threshold + * @param[in] x interpolant (amount) + */ +CGLM_INLINE +float +glm_smoothstep(float edge0, float edge1, float x) { + float t; + t = glm_clamp_zo((x - edge0) / (edge1 - edge0)); + return glm_smooth(t); +} + +/*! + * @brief smoothstep interpolation between two numbers + * + * formula: from + smoothstep(t) * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + */ +CGLM_INLINE +float +glm_smoothinterp(float from, float to, float t) { + return from + glm_smooth(t) * (to - from); +} + +/*! + * @brief clamped smoothstep interpolation between two numbers + * + * formula: from + smoothstep(t) * (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_smoothinterpc(float from, float to, float t) { + return glm_smoothinterp(from, to, glm_clamp_zo(t)); +} + +/*! + * @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) <= GLM_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] current current value + */ +CGLM_INLINE +float +glm_percent(float from, float to, float current) { + float t; + + if ((t = to - from) == 0.0f) + return 1.0f; + + return (current - from) / t; +} + +/*! + * @brief clamped percentage of current value between start and end value + * + * @param[in] from from value + * @param[in] to to value + * @param[in] current current value + */ +CGLM_INLINE +float +glm_percentc(float from, float to, float current) { + return glm_clamp_zo(glm_percent(from, to, current)); +} + +/*! +* @brief swap two float values +* +* @param[in] a float value 1 (pointer) +* @param[in] b float value 2 (pointer) +*/ +CGLM_INLINE +void +glm_swapf(float * __restrict a, float * __restrict b) { + float t; + t = *a; + *a = *b; + *b = t; +} + +#endif /* cglm_util_h */ diff --git a/libs/cglm/include/cglm/vec2-ext.h b/libs/cglm/include/cglm/vec2-ext.h new file mode 100644 index 0000000..388c5e2 --- /dev/null +++ b/libs/cglm/include/cglm/vec2-ext.h @@ -0,0 +1,241 @@ +/* + * 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_vec2_fill(vec2 v, float val) + CGLM_INLINE bool glm_vec2_eq(vec2 v, float val); + CGLM_INLINE bool glm_vec2_eq_eps(vec2 v, float val); + CGLM_INLINE bool glm_vec2_eq_all(vec2 v); + CGLM_INLINE bool glm_vec2_eqv(vec2 a, vec2 b); + CGLM_INLINE bool glm_vec2_eqv_eps(vec2 a, vec2 b); + CGLM_INLINE float glm_vec2_max(vec2 v); + CGLM_INLINE float glm_vec2_min(vec2 v); + CGLM_INLINE bool glm_vec2_isnan(vec2 v); + CGLM_INLINE bool glm_vec2_isinf(vec2 v); + CGLM_INLINE bool glm_vec2_isvalid(vec2 v); + CGLM_INLINE void glm_vec2_sign(vec2 v, vec2 dest); + CGLM_INLINE void glm_vec2_sqrt(vec2 v, vec2 dest); + CGLM_INLINE void glm_vec2_complex_mul(vec2 a, vec2 b, vec2 dest) + CGLM_INLINE void glm_vec2_complex_div(vec2 a, vec2 b, vec2 dest) + CGLM_INLINE void glm_vec2_complex_conjugate(vec2 a, vec2 dest) + */ + +#ifndef cglm_vec2_ext_h +#define cglm_vec2_ext_h + +#include "common.h" +#include "util.h" + +/*! + * @brief fill a vector with specified value + * + * @param[out] v dest + * @param[in] val value + */ +CGLM_INLINE +void +glm_vec2_fill(vec2 v, float val) { + v[0] = v[1] = val; +} + +/*! + * @brief check if vector is equal to value (without epsilon) + * + * @param[in] v vector + * @param[in] val value + */ +CGLM_INLINE +bool +glm_vec2_eq(vec2 v, float val) { + return v[0] == val && v[0] == v[1]; +} + +/*! + * @brief check if vector is equal to value (with epsilon) + * + * @param[in] v vector + * @param[in] val value + */ +CGLM_INLINE +bool +glm_vec2_eq_eps(vec2 v, float val) { + return fabsf(v[0] - val) <= GLM_FLT_EPSILON + && fabsf(v[1] - val) <= GLM_FLT_EPSILON; +} + +/*! + * @brief check if vectors members are equal (without epsilon) + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec2_eq_all(vec2 v) { + return glm_vec2_eq_eps(v, v[0]); +} + +/*! + * @brief check if vector is equal to another (without epsilon) + * + * @param[in] a vector + * @param[in] b vector + */ +CGLM_INLINE +bool +glm_vec2_eqv(vec2 a, vec2 b) { + return a[0] == b[0] && a[1] == b[1]; +} + +/*! + * @brief check if vector is equal to another (with epsilon) + * + * @param[in] a vector + * @param[in] b vector + */ +CGLM_INLINE +bool +glm_vec2_eqv_eps(vec2 a, vec2 b) { + return fabsf(a[0] - b[0]) <= GLM_FLT_EPSILON + && fabsf(a[1] - b[1]) <= GLM_FLT_EPSILON; +} + +/*! + * @brief max value of vector + * + * @param[in] v vector + */ +CGLM_INLINE +float +glm_vec2_max(vec2 v) { + return glm_max(v[0], v[1]); +} + +/*! + * @brief min value of vector + * + * @param[in] v vector + */ +CGLM_INLINE +float +glm_vec2_min(vec2 v) { + return glm_min(v[0], v[1]); +} + +/*! + * @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_vec2_isnan(vec2 v) { + return isnan(v[0]) || isnan(v[1]); +} + +/*! + * @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_vec2_isinf(vec2 v) { + return isinf(v[0]) || isinf(v[1]); +} + +/*! + * @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_vec2_isvalid(vec2 v) { + return !glm_vec2_isnan(v) && !glm_vec2_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_vec2_sign(vec2 v, vec2 dest) { + dest[0] = glm_signf(v[0]); + dest[1] = glm_signf(v[1]); +} + +/*! + * @brief square root of each vector item + * + * @param[in] v vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec2_sqrt(vec2 v, vec2 dest) { + dest[0] = sqrtf(v[0]); + dest[1] = sqrtf(v[1]); +} + +/*! + * @brief treat vectors as complex numbers and multiply them as such. + * + * @param[in] a left number + * @param[in] b right number + * @param[out] dest destination number + */ +CGLM_INLINE +void +glm_vec2_complex_mul(vec2 a, vec2 b, vec2 dest) { + float tr, ti; + tr = a[0] * b[0] - a[1] * b[1]; + ti = a[0] * b[1] + a[1] * b[0]; + dest[0] = tr; + dest[1] = ti; +} + +/*! + * @brief treat vectors as complex numbers and divide them as such. + * + * @param[in] a left number (numerator) + * @param[in] b right number (denominator) + * @param[out] dest destination number + */ +CGLM_INLINE +void +glm_vec2_complex_div(vec2 a, vec2 b, vec2 dest) { + float tr, ti; + float const ibnorm2 = 1.0f / (b[0] * b[0] + b[1] * b[1]); + tr = ibnorm2 * (a[0] * b[0] + a[1] * b[1]); + ti = ibnorm2 * (a[1] * b[0] - a[0] * b[1]); + dest[0] = tr; + dest[1] = ti; +} + +/*! + * @brief treat the vector as a complex number and conjugate it as such. + * + * @param[in] a the number + * @param[out] dest destination number + */ +CGLM_INLINE +void +glm_vec2_complex_conjugate(vec2 a, vec2 dest) { + dest[0] = a[0]; + dest[1] = -a[1]; +} + + +#endif /* cglm_vec2_ext_h */ diff --git a/libs/cglm/include/cglm/vec2.h b/libs/cglm/include/cglm/vec2.h new file mode 100644 index 0000000..73ecea9 --- /dev/null +++ b/libs/cglm/include/cglm/vec2.h @@ -0,0 +1,585 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLM_VEC2_ONE_INIT + GLM_VEC2_ZERO_INIT + GLM_VEC2_ONE + GLM_VEC2_ZERO + + Functions: + CGLM_INLINE void glm_vec2(float * __restrict v, vec2 dest) + CGLM_INLINE void glm_vec2_copy(vec2 a, vec2 dest) + CGLM_INLINE void glm_vec2_zero(vec2 v) + CGLM_INLINE void glm_vec2_one(vec2 v) + CGLM_INLINE float glm_vec2_dot(vec2 a, vec2 b) + CGLM_INLINE float glm_vec2_cross(vec2 a, vec2 b) + CGLM_INLINE float glm_vec2_norm2(vec2 v) + CGLM_INLINE float glm_vec2_norm(vec2 vec) + CGLM_INLINE void glm_vec2_add(vec2 a, vec2 b, vec2 dest) + CGLM_INLINE void glm_vec2_adds(vec2 v, float s, vec2 dest) + CGLM_INLINE void glm_vec2_sub(vec2 a, vec2 b, vec2 dest) + CGLM_INLINE void glm_vec2_subs(vec2 v, float s, vec2 dest) + CGLM_INLINE void glm_vec2_mul(vec2 a, vec2 b, vec2 d) + CGLM_INLINE void glm_vec2_scale(vec2 v, float s, vec2 dest) + CGLM_INLINE void glm_vec2_scale_as(vec2 v, float s, vec2 dest) + CGLM_INLINE void glm_vec2_div(vec2 a, vec2 b, vec2 dest) + CGLM_INLINE void glm_vec2_divs(vec2 v, float s, vec2 dest) + CGLM_INLINE void glm_vec2_addadd(vec2 a, vec2 b, vec2 dest) + CGLM_INLINE void glm_vec2_subadd(vec2 a, vec2 b, vec2 dest) + CGLM_INLINE void glm_vec2_muladd(vec2 a, vec2 b, vec2 dest) + CGLM_INLINE void glm_vec2_muladds(vec2 a, float s, vec2 dest) + CGLM_INLINE void glm_vec2_maxadd(vec2 a, vec2 b, vec2 dest) + CGLM_INLINE void glm_vec2_minadd(vec2 a, vec2 b, vec2 dest) + CGLM_INLINE void glm_vec2_negate_to(vec2 v, vec2 dest) + CGLM_INLINE void glm_vec2_negate(vec2 v) + CGLM_INLINE void glm_vec2_normalize(vec2 v) + CGLM_INLINE void glm_vec2_normalize_to(vec2 vec, vec2 dest) + CGLM_INLINE void glm_vec2_rotate(vec2 v, float angle, vec2 dest) + CGLM_INLINE float glm_vec2_distance2(vec2 a, vec2 b) + CGLM_INLINE float glm_vec2_distance(vec2 a, vec2 b) + CGLM_INLINE void glm_vec2_maxv(vec2 v1, vec2 v2, vec2 dest) + CGLM_INLINE void glm_vec2_minv(vec2 v1, vec2 v2, vec2 dest) + CGLM_INLINE void glm_vec2_clamp(vec2 v, float minVal, float maxVal) + CGLM_INLINE void glm_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest) + + */ + +#ifndef cglm_vec2_h +#define cglm_vec2_h + +#include "common.h" +#include "util.h" +#include "vec2-ext.h" + +#define GLM_VEC2_ONE_INIT {1.0f, 1.0f} +#define GLM_VEC2_ZERO_INIT {0.0f, 0.0f} + +#define GLM_VEC2_ONE ((vec2)GLM_VEC2_ONE_INIT) +#define GLM_VEC2_ZERO ((vec2)GLM_VEC2_ZERO_INIT) + +/*! + * @brief init vec2 using another vector + * + * @param[in] v a vector + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec2(float * __restrict v, vec2 dest) { + dest[0] = v[0]; + dest[1] = v[1]; +} + +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] a source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec2_copy(vec2 a, vec2 dest) { + dest[0] = a[0]; + dest[1] = a[1]; +} + +/*! + * @brief make vector zero + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec2_zero(vec2 v) { + v[0] = v[1] = 0.0f; +} + +/*! + * @brief make vector one + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec2_one(vec2 v) { + v[0] = v[1] = 1.0f; +} + +/*! + * @brief vec2 dot product + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ +CGLM_INLINE +float +glm_vec2_dot(vec2 a, vec2 b) { + return a[0] * b[0] + a[1] * b[1]; +} + +/*! + * @brief vec2 cross product + * + * REF: http://allenchou.net/2013/07/cross-product-of-2d-vectors/ + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return Z component of cross product + */ +CGLM_INLINE +float +glm_vec2_cross(vec2 a, vec2 b) { + /* just calculate the z-component */ + return a[0] * b[1] - a[1] * b[0]; +} + +/*! + * @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 +glm_vec2_norm2(vec2 v) { + return glm_vec2_dot(v, v); +} + +/*! + * @brief norm (magnitude) of vec2 + * + * @param[in] vec vector + * + * @return norm + */ +CGLM_INLINE +float +glm_vec2_norm(vec2 vec) { + return sqrtf(glm_vec2_norm2(vec)); +} + +/*! + * @brief add a vector to b vector store result in dest + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec2_add(vec2 a, vec2 b, vec2 dest) { + dest[0] = a[0] + b[0]; + dest[1] = a[1] + b[1]; +} + +/*! + * @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_vec2_adds(vec2 v, float s, vec2 dest) { + dest[0] = v[0] + s; + dest[1] = v[1] + s; +} + +/*! + * @brief subtract b vector from a vector store result in dest + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec2_sub(vec2 a, vec2 b, vec2 dest) { + dest[0] = a[0] - b[0]; + dest[1] = a[1] - b[1]; +} + +/*! + * @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_vec2_subs(vec2 v, float s, vec2 dest) { + dest[0] = v[0] - s; + dest[1] = v[1] - s; +} + +/*! + * @brief multiply two vector (component-wise multiplication) + * + * @param a v1 + * @param b v2 + * @param dest v3 = (a[0] * b[0], a[1] * b[1]) + */ +CGLM_INLINE +void +glm_vec2_mul(vec2 a, vec2 b, vec2 dest) { + dest[0] = a[0] * b[0]; + dest[1] = a[1] * b[1]; +} + +/*! + * @brief multiply/scale vector with scalar: result = v * s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec2_scale(vec2 v, float s, vec2 dest) { + dest[0] = v[0] * s; + dest[1] = v[1] * s; +} + +/*! + * @brief scale as vector specified: result = unit(v) * s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec2_scale_as(vec2 v, float s, vec2 dest) { + float norm; + norm = glm_vec2_norm(v); + + if (norm == 0.0f) { + glm_vec2_zero(dest); + return; + } + + glm_vec2_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]) + */ +CGLM_INLINE +void +glm_vec2_div(vec2 a, vec2 b, vec2 dest) { + dest[0] = a[0] / b[0]; + dest[1] = a[1] / b[1]; +} + +/*! + * @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) + */ +CGLM_INLINE +void +glm_vec2_divs(vec2 v, float s, vec2 dest) { + dest[0] = v[0] / s; + dest[1] = v[1] / 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_vec2_addadd(vec2 a, vec2 b, vec2 dest) { + dest[0] += a[0] + b[0]; + dest[1] += a[1] + b[1]; +} + +/*! + * @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_vec2_subadd(vec2 a, vec2 b, vec2 dest) { + dest[0] += a[0] - b[0]; + dest[1] += a[1] - b[1]; +} + +/*! + * @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_vec2_muladd(vec2 a, vec2 b, vec2 dest) { + dest[0] += a[0] * b[0]; + dest[1] += a[1] * b[1]; +} + +/*! + * @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_vec2_muladds(vec2 a, float s, vec2 dest) { + dest[0] += a[0] * s; + dest[1] += a[1] * 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_vec2_maxadd(vec2 a, vec2 b, vec2 dest) { + dest[0] += glm_max(a[0], b[0]); + dest[1] += glm_max(a[1], b[1]); +} + +/*! + * @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 + * @param[out] dest dest += min(a, b) + */ +CGLM_INLINE +void +glm_vec2_minadd(vec2 a, vec2 b, vec2 dest) { + dest[0] += glm_min(a[0], b[0]); + dest[1] += glm_min(a[1], b[1]); +} + +/*! + * @brief negate vector components and store result in dest + * + * @param[in] v vector + * @param[out] dest result vector + */ +CGLM_INLINE +void +glm_vec2_negate_to(vec2 v, vec2 dest) { + dest[0] = -v[0]; + dest[1] = -v[1]; +} + +/*! + * @brief negate vector components + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec2_negate(vec2 v) { + glm_vec2_negate_to(v, v); +} + +/*! + * @brief normalize vector and store result in same vec + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec2_normalize(vec2 v) { + float norm; + + norm = glm_vec2_norm(v); + + if (norm == 0.0f) { + v[0] = v[1] = 0.0f; + return; + } + + glm_vec2_scale(v, 1.0f / norm, v); +} + +/*! + * @brief normalize vector to dest + * + * @param[in] v source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec2_normalize_to(vec2 v, vec2 dest) { + float norm; + + norm = glm_vec2_norm(v); + + if (norm == 0.0f) { + glm_vec2_zero(dest); + return; + } + + glm_vec2_scale(v, 1.0f / norm, dest); +} + +/*! + * @brief rotate vec2 around origin by angle (CCW: counterclockwise) + * + * Formula: + * 𝑥2 = cos(a)𝑥1 − sin(a)𝑦1 + * 𝑦2 = sin(a)𝑥1 + cos(a)𝑦1 + * + * @param[in] v vector to rotate + * @param[in] angle angle by radians + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec2_rotate(vec2 v, float angle, vec2 dest) { + float c, s, x1, y1; + + c = cosf(angle); + s = sinf(angle); + + x1 = v[0]; + y1 = v[1]; + + dest[0] = c * x1 - s * y1; + dest[1] = s * x1 + c * y1; +} + +/** + * @brief squared distance between two vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @return returns squared distance (distance * distance) + */ +CGLM_INLINE +float +glm_vec2_distance2(vec2 a, vec2 b) { + return glm_pow2(b[0] - a[0]) + glm_pow2(b[1] - a[1]); +} + +/** + * @brief distance between two vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @return returns distance + */ +CGLM_INLINE +float +glm_vec2_distance(vec2 a, vec2 b) { + return sqrtf(glm_vec2_distance2(a, b)); +} + +/*! + * @brief max values of vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec2_maxv(vec2 a, vec2 b, vec2 dest) { + dest[0] = glm_max(a[0], b[0]); + dest[1] = glm_max(a[1], b[1]); +} + +/*! + * @brief min values of vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec2_minv(vec2 a, vec2 b, vec2 dest) { + dest[0] = glm_min(a[0], b[0]); + dest[1] = glm_min(a[1], b[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_vec2_clamp(vec2 v, float minval, float maxval) { + v[0] = glm_clamp(v[0], minval, maxval); + v[1] = glm_clamp(v[1], 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_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest) { + vec2 s, v; + + /* from + s * (to - from) */ + glm_vec2_fill(s, glm_clamp_zo(t)); + glm_vec2_sub(to, from, v); + glm_vec2_mul(s, v, v); + glm_vec2_add(from, v, dest); +} + +#endif /* cglm_vec2_h */ diff --git a/libs/cglm/include/cglm/vec3-ext.h b/libs/cglm/include/cglm/vec3-ext.h new file mode 100644 index 0000000..802f4cb --- /dev/null +++ b/libs/cglm/include/cglm/vec3-ext.h @@ -0,0 +1,272 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/*! + * @brief SIMD like functions + */ + +/* + Functions: + CGLM_INLINE void glm_vec3_broadcast(float val, vec3 d); + CGLM_INLINE void glm_vec3_fill(vec3 v, float val); + 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 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); + 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_abs(vec3 v, vec3 dest); + CGLM_INLINE void glm_vec3_fract(vec3 v, vec3 dest); + CGLM_INLINE float glm_vec3_hadd(vec3 v); + CGLM_INLINE void glm_vec3_sqrt(vec3 v, vec3 dest); + */ + +#ifndef cglm_vec3_ext_h +#define cglm_vec3_ext_h + +#include "common.h" +#include "util.h" + +/*! + * @brief fill a vector with specified value + * + * @param[in] val value + * @param[out] d dest + */ +CGLM_INLINE +void +glm_vec3_broadcast(float val, vec3 d) { + d[0] = d[1] = d[2] = val; +} + +/*! + * @brief fill a vector with specified value + * + * @param[out] v dest + * @param[in] val value + */ +CGLM_INLINE +void +glm_vec3_fill(vec3 v, float val) { + v[0] = v[1] = v[2] = val; +} + +/*! + * @brief check if vector is equal to value (without epsilon) + * + * @param[in] v vector + * @param[in] val value + */ +CGLM_INLINE +bool +glm_vec3_eq(vec3 v, float val) { + return v[0] == val && v[0] == v[1] && v[0] == v[2]; +} + +/*! + * @brief check if vector is equal to value (with epsilon) + * + * @param[in] v vector + * @param[in] val value + */ +CGLM_INLINE +bool +glm_vec3_eq_eps(vec3 v, float val) { + return fabsf(v[0] - val) <= GLM_FLT_EPSILON + && fabsf(v[1] - val) <= GLM_FLT_EPSILON + && fabsf(v[2] - val) <= GLM_FLT_EPSILON; +} + +/*! + * @brief check if vectors members are equal (without epsilon) + * + * @param[in] v vector + */ +CGLM_INLINE +bool +glm_vec3_eq_all(vec3 v) { + return glm_vec3_eq_eps(v, v[0]); +} + +/*! + * @brief check if vector is equal to another (without epsilon) + * + * @param[in] a vector + * @param[in] b vector + */ +CGLM_INLINE +bool +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] a vector + * @param[in] b vector + */ +CGLM_INLINE +bool +glm_vec3_eqv_eps(vec3 a, vec3 b) { + return fabsf(a[0] - b[0]) <= GLM_FLT_EPSILON + && fabsf(a[1] - b[1]) <= GLM_FLT_EPSILON + && fabsf(a[2] - b[2]) <= GLM_FLT_EPSILON; +} + +/*! + * @brief max value of vector + * + * @param[in] v vector + */ +CGLM_INLINE +float +glm_vec3_max(vec3 v) { + float max; + + max = v[0]; + if (v[1] > max) + max = v[1]; + if (v[2] > max) + max = v[2]; + + return max; +} + +/*! + * @brief min value of vector + * + * @param[in] v vector + */ +CGLM_INLINE +float +glm_vec3_min(vec3 v) { + float min; + + min = v[0]; + if (v[1] < min) + min = v[1]; + if (v[2] < min) + min = v[2]; + + 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_vec3_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_vec3_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_vec3_isvalid(vec3 v) { + return !glm_vec3_isnan(v) && !glm_vec3_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_vec3_sign(vec3 v, vec3 dest) { + dest[0] = glm_signf(v[0]); + dest[1] = glm_signf(v[1]); + dest[2] = glm_signf(v[2]); +} + +/*! + * @brief absolute value of each vector item + * + * @param[in] v vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec3_abs(vec3 v, vec3 dest) { + dest[0] = fabsf(v[0]); + dest[1] = fabsf(v[1]); + dest[2] = fabsf(v[2]); +} + +/*! + * @brief fractional part of each vector item + * + * @param[in] v vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec3_fract(vec3 v, vec3 dest) { + dest[0] = fminf(v[0] - floorf(v[0]), 0.999999940395355224609375f); + dest[1] = fminf(v[1] - floorf(v[1]), 0.999999940395355224609375f); + dest[2] = fminf(v[2] - floorf(v[2]), 0.999999940395355224609375f); +} + +/*! + * @brief vector reduction by summation + * @warning could overflow + * + * @param[in] v vector + * @return sum of all vector's elements + */ +CGLM_INLINE +float +glm_vec3_hadd(vec3 v) { + return v[0] + v[1] + v[2]; +} + +/*! + * @brief square root of each vector item + * + * @param[in] v vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec3_sqrt(vec3 v, vec3 dest) { + dest[0] = sqrtf(v[0]); + dest[1] = sqrtf(v[1]); + dest[2] = sqrtf(v[2]); +} + +#endif /* cglm_vec3_ext_h */ diff --git a/libs/cglm/include/cglm/vec3.h b/libs/cglm/include/cglm/vec3.h new file mode 100644 index 0000000..b9fff9c --- /dev/null +++ b/libs/cglm/include/cglm/vec3.h @@ -0,0 +1,1082 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Macros: + GLM_VEC3_ONE_INIT + GLM_VEC3_ZERO_INIT + GLM_VEC3_ONE + GLM_VEC3_ZERO + GLM_YUP + GLM_ZUP + GLM_XUP + + Functions: + CGLM_INLINE void glm_vec3(vec4 v4, 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 float glm_vec3_norm2(vec3 v); + CGLM_INLINE float glm_vec3_norm(vec3 v); + CGLM_INLINE float glm_vec3_norm_one(vec3 v); + CGLM_INLINE float glm_vec3_norm_inf(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); + 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_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); + 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 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_angle(vec3 a, vec3 b); + CGLM_INLINE void glm_vec3_rotate(vec3 v, float angle, vec3 axis); + CGLM_INLINE void glm_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest); + CGLM_INLINE void glm_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest); + CGLM_INLINE void glm_vec3_proj(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE void glm_vec3_center(vec3 a, vec3 b, vec3 dest); + CGLM_INLINE float glm_vec3_distance(vec3 a, vec3 b); + 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); + CGLM_INLINE void glm_vec3_lerpc(vec3 from, vec3 to, float t, vec3 dest); + CGLM_INLINE void glm_vec3_mix(vec3 from, vec3 to, float t, vec3 dest); + CGLM_INLINE void glm_vec3_mixc(vec3 from, vec3 to, float t, vec3 dest); + CGLM_INLINE void glm_vec3_step_uni(float edge, vec3 x, vec3 dest); + CGLM_INLINE void glm_vec3_step(vec3 edge, vec3 x, vec3 dest); + CGLM_INLINE void glm_vec3_smoothstep_uni(float edge0, float edge1, vec3 x, vec3 dest); + CGLM_INLINE void glm_vec3_smoothstep(vec3 edge0, vec3 edge1, vec3 x, vec3 dest); + CGLM_INLINE void glm_vec3_smoothinterp(vec3 from, vec3 to, float t, vec3 dest); + CGLM_INLINE void glm_vec3_smoothinterpc(vec3 from, vec3 to, float t, vec3 dest); + CGLM_INLINE void glm_vec3_swizzle(vec3 v, int mask, vec3 dest); + + 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_vec3_dup + glm_vec3_flipsign + glm_vec3_flipsign_to + glm_vec3_inv + glm_vec3_inv_to + glm_vec3_mulv + */ + +#ifndef cglm_vec3_h +#define cglm_vec3_h + +#include "common.h" +#include "vec4.h" +#include "vec3-ext.h" +#include "util.h" + +/* DEPRECATED! use _copy, _ucopy versions */ +#define glm_vec3_dup(v, dest) glm_vec3_copy(v, dest) +#define glm_vec3_flipsign(v) glm_vec3_negate(v) +#define glm_vec3_flipsign_to(v, dest) glm_vec3_negate_to(v, dest) +#define glm_vec3_inv(v) glm_vec3_negate(v) +#define glm_vec3_inv_to(v, dest) glm_vec3_negate_to(v, dest) +#define glm_vec3_mulv(a, b, d) glm_vec3_mul(a, b, d) + +#define GLM_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f} +#define GLM_VEC3_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}) +#define GLM_XUP ((vec3){1.0f, 0.0f, 0.0f}) +#define GLM_FORWARD ((vec3){0.0f, 0.0f, -1.0f}) + +#define GLM_XXX GLM_SHUFFLE3(0, 0, 0) +#define GLM_YYY GLM_SHUFFLE3(1, 1, 1) +#define GLM_ZZZ GLM_SHUFFLE3(2, 2, 2) +#define GLM_ZYX GLM_SHUFFLE3(0, 1, 2) + +/*! + * @brief init vec3 using vec4 + * + * @param[in] v4 vector4 + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3(vec4 v4, vec3 dest) { + dest[0] = v4[0]; + dest[1] = v4[1]; + dest[2] = v4[2]; +} + +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] a source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_copy(vec3 a, vec3 dest) { + dest[0] = a[0]; + dest[1] = a[1]; + dest[2] = a[2]; +} + +/*! + * @brief make vector zero + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec3_zero(vec3 v) { + v[0] = v[1] = v[2] = 0.0f; +} + +/*! + * @brief make vector one + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec3_one(vec3 v) { + v[0] = v[1] = v[2] = 1.0f; +} + +/*! + * @brief vec3 dot product + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ +CGLM_INLINE +float +glm_vec3_dot(vec3 a, vec3 b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; +} + +/*! + * @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 +glm_vec3_norm2(vec3 v) { + return glm_vec3_dot(v, v); +} + +/*! + * @brief euclidean norm (magnitude), also called L2 norm + * this will give magnitude of vector in euclidean space + * + * @param[in] v vector + * + * @return norm + */ +CGLM_INLINE +float +glm_vec3_norm(vec3 v) { + return sqrtf(glm_vec3_norm2(v)); +} + +/*! + * @brief L1 norm of vec3 + * Also known as Manhattan Distance or Taxicab norm. + * L1 Norm is the sum of the magnitudes of the vectors in a space. + * It is calculated as the sum of the absolute values of the vector components. + * In this norm, all the components of the vector are weighted equally. + * + * This computes: + * R = |v[0]| + |v[1]| + |v[2]| + * + * @param[in] v vector + * + * @return L1 norm + */ +CGLM_INLINE +float +glm_vec3_norm_one(vec3 v) { + vec3 t; + glm_vec3_abs(v, t); + return glm_vec3_hadd(t); +} + +/*! + * @brief infinity norm of vec3 + * Also known as Maximum norm. + * Infinity Norm is the largest magnitude among each element of a vector. + * It is calculated as the maximum of the absolute values of the vector components. + * + * This computes: + * inf norm = max(|v[0]|, |v[1]|, |v[2]|) + * + * @param[in] v vector + * + * @return infinity norm + */ +CGLM_INLINE +float +glm_vec3_norm_inf(vec3 v) { + vec3 t; + glm_vec3_abs(v, t); + return glm_vec3_max(t); +} + +/*! + * @brief add a vector to b vector store result in dest + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest destination vector + */ +CGLM_INLINE +void +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]; +} + +/*! + * @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_vec3_adds(vec3 v, float s, vec3 dest) { + dest[0] = v[0] + s; + dest[1] = v[1] + s; + dest[2] = v[2] + s; +} + +/*! + * @brief subtract b vector from a vector store result in dest + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest destination vector + */ +CGLM_INLINE +void +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]; +} + +/*! + * @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_vec3_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 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 dest) { + dest[0] = a[0] * b[0]; + dest[1] = a[1] * b[1]; + dest[2] = a[2] * b[2]; +} + +/*! + * @brief multiply/scale vec3 vector with scalar: result = v * s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec3_scale(vec3 v, float s, vec3 dest) { + dest[0] = v[0] * s; + dest[1] = v[1] * s; + dest[2] = v[2] * s; +} + +/*! + * @brief make vec3 vector scale as specified: result = unit(v) * s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec3_scale_as(vec3 v, float s, vec3 dest) { + float norm; + norm = glm_vec3_norm(v); + + if (norm == 0.0f) { + glm_vec3_zero(dest); + return; + } + + glm_vec3_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_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]; +} + +/*! + * @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_vec3_divs(vec3 v, float s, vec3 dest) { + dest[0] = v[0] / s; + dest[1] = v[1] / s; + 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_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]; +} + +/*! + * @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_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]; +} + +/*! + * @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_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]; +} + +/*! + * @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_vec3_muladds(vec3 a, float s, vec3 dest) { + dest[0] += a[0] * s; + dest[1] += a[1] * s; + 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 1 + * @param[in] b vector 2 + * @param[out] dest dest += min(a, b) + */ +CGLM_INLINE +void +glm_vec3_minadd(vec3 a, vec3 b, vec3 dest) { + dest[0] += glm_min(a[0], b[0]); + dest[1] += glm_min(a[1], b[1]); + dest[2] += glm_min(a[2], b[2]); +} + +/*! + * @brief negate vector components and store result in dest + * + * @param[in] v vector + * @param[out] dest result vector + */ +CGLM_INLINE +void +glm_vec3_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_vec3_negate(vec3 v) { + glm_vec3_negate_to(v, v); +} + +/*! + * @brief normalize vec3 and store result in same vec + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_vec3_normalize(vec3 v) { + float norm; + + norm = glm_vec3_norm(v); + + if (norm == 0.0f) { + v[0] = v[1] = v[2] = 0.0f; + return; + } + + glm_vec3_scale(v, 1.0f / norm, v); +} + +/*! + * @brief normalize vec3 to dest + * + * @param[in] v source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_normalize_to(vec3 v, vec3 dest) { + float norm; + + norm = glm_vec3_norm(v); + + if (norm == 0.0f) { + glm_vec3_zero(dest); + return; + } + + 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) { + vec3 c; + /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ + c[0] = a[1] * b[2] - a[2] * b[1]; + c[1] = a[2] * b[0] - a[0] * b[2]; + c[2] = a[0] * b[1] - a[1] * b[0]; + glm_vec3_copy(c, dest); +} + +/*! + * @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 + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return angle as radians + */ +CGLM_INLINE +float +glm_vec3_angle(vec3 a, vec3 b) { + float norm, dot; + + /* maybe compiler generate approximation instruction (rcp) */ + 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; + else if (dot < -1.0f) + return CGLM_PI; + + return acosf(dot); +} + +/*! + * @brief rotate vec3 around axis by angle using Rodrigues' rotation formula + * + * @param[in, out] v vector + * @param[in] axis axis vector (must be unit vector) + * @param[in] angle angle by radians + */ +CGLM_INLINE +void +glm_vec3_rotate(vec3 v, float angle, vec3 axis) { + vec3 v1, v2, k; + float c, s; + + c = cosf(angle); + s = sinf(angle); + + 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_vec3_scale(v, c, v1); + + glm_vec3_cross(k, v, v2); + glm_vec3_scale(v2, s, v2); + + glm_vec3_add(v1, v2, v1); + + glm_vec3_scale(k, glm_vec3_dot(k, v) * (1.0f - c), v2); + glm_vec3_add(v1, v2, 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 + * @param[out] dest rotated vector + */ +CGLM_INLINE +void +glm_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest) { + vec4 x, y, z, res; + + glm_vec4_normalize_to(m[0], x); + glm_vec4_normalize_to(m[1], y); + glm_vec4_normalize_to(m[2], z); + + glm_vec4_scale(x, v[0], res); + glm_vec4_muladds(y, v[1], res); + glm_vec4_muladds(z, v[2], res); + + 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_vec3_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(z, v[2], res); + + glm_vec3(res, dest); +} + +/*! + * @brief project a vector onto b vector + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest projected vector + */ +CGLM_INLINE +void +glm_vec3_proj(vec3 a, vec3 b, vec3 dest) { + glm_vec3_scale(b, + glm_vec3_dot(a, b) / glm_vec3_norm2(b), + dest); +} + +/** + * @brief find center point of two vector + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest center point + */ +CGLM_INLINE +void +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] a vector1 + * @param[in] b vector2 + * @return returns squared distance (distance * distance) + */ +CGLM_INLINE +float +glm_vec3_distance2(vec3 a, vec3 b) { + return glm_pow2(a[0] - b[0]) + + glm_pow2(a[1] - b[1]) + + glm_pow2(a[2] - b[2]); +} + +/** + * @brief distance between two vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @return returns distance + */ +CGLM_INLINE +float +glm_vec3_distance(vec3 a, vec3 b) { + return sqrtf(glm_vec3_distance2(a, b)); +} + +/*! + * @brief max values of vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest destination + */ +CGLM_INLINE +void +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] a vector1 + * @param[in] b vector2 + * @param[out] dest destination + */ +CGLM_INLINE +void +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]); +} + +/*! + * @brief possible orthogonal/perpendicular vector + * + * @param[in] v vector + * @param[out] dest orthogonal/perpendicular vector + */ +CGLM_INLINE +void +glm_vec3_ortho(vec3 v, vec3 dest) { + float ignore; + float f = modff(fabsf(v[0]) + 0.5f, &ignore); + vec3 result = {-v[1], v[0] - f * v[2], f * v[1]}; + glm_vec3_copy(result, dest); +} + +/*! + * @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_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); +} + +/*! + * @brief linear interpolation between two vectors + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) { + vec3 s, v; + + /* from + s * (to - from) */ + glm_vec3_broadcast(t, s); + glm_vec3_sub(to, from, v); + glm_vec3_mul(s, v, v); + glm_vec3_add(from, v, dest); +} + +/*! + * @brief linear interpolation between two vectors (clamped) + * + * 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_vec3_lerpc(vec3 from, vec3 to, float t, vec3 dest) { + glm_vec3_lerp(from, to, glm_clamp_zo(t), dest); +} + +/*! + * @brief linear interpolation between two vectors + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_mix(vec3 from, vec3 to, float t, vec3 dest) { + glm_vec3_lerp(from, to, t, dest); +} + +/*! + * @brief linear interpolation between two vectors (clamped) + * + * 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_vec3_mixc(vec3 from, vec3 to, float t, vec3 dest) { + glm_vec3_lerpc(from, to, t, dest); +} + +/*! + * @brief threshold function (unidimensional) + * + * @param[in] edge threshold + * @param[in] x value to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_step_uni(float edge, vec3 x, vec3 dest) { + dest[0] = glm_step(edge, x[0]); + dest[1] = glm_step(edge, x[1]); + dest[2] = glm_step(edge, x[2]); +} + +/*! + * @brief threshold function + * + * @param[in] edge threshold + * @param[in] x value to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_step(vec3 edge, vec3 x, vec3 dest) { + dest[0] = glm_step(edge[0], x[0]); + dest[1] = glm_step(edge[1], x[1]); + dest[2] = glm_step(edge[2], x[2]); +} + +/*! + * @brief threshold function with a smooth transition (unidimensional) + * + * @param[in] edge0 low threshold + * @param[in] edge1 high threshold + * @param[in] x value to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_smoothstep_uni(float edge0, float edge1, vec3 x, vec3 dest) { + dest[0] = glm_smoothstep(edge0, edge1, x[0]); + dest[1] = glm_smoothstep(edge0, edge1, x[1]); + dest[2] = glm_smoothstep(edge0, edge1, x[2]); +} + +/*! + * @brief threshold function with a smooth transition + * + * @param[in] edge0 low threshold + * @param[in] edge1 high threshold + * @param[in] x value to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_smoothstep(vec3 edge0, vec3 edge1, vec3 x, vec3 dest) { + dest[0] = glm_smoothstep(edge0[0], edge1[0], x[0]); + dest[1] = glm_smoothstep(edge0[1], edge1[1], x[1]); + dest[2] = glm_smoothstep(edge0[2], edge1[2], x[2]); +} + +/*! + * @brief smooth Hermite interpolation between two vectors + * + * formula: from + s * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_smoothinterp(vec3 from, vec3 to, float t, vec3 dest) { + vec3 s, v; + + /* from + s * (to - from) */ + glm_vec3_broadcast(glm_smooth(t), s); + glm_vec3_sub(to, from, v); + glm_vec3_mul(s, v, v); + glm_vec3_add(from, v, dest); +} + +/*! + * @brief smooth Hermite interpolation between two vectors (clamped) + * + * 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_vec3_smoothinterpc(vec3 from, vec3 to, float t, vec3 dest) { + glm_vec3_smoothinterp(from, to, glm_clamp_zo(t), dest); +} + +/*! + * @brief swizzle vector components + * + * you can use existin masks e.g. GLM_XXX, GLM_ZYX + * + * @param[in] v source + * @param[in] mask mask + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec3_swizzle(vec3 v, int mask, vec3 dest) { + vec3 t; + + t[0] = v[(mask & (3 << 0))]; + t[1] = v[(mask & (3 << 2)) >> 2]; + t[2] = v[(mask & (3 << 4)) >> 4]; + + glm_vec3_copy(t, dest); +} + +/*! + * @brief vec3 cross product + * + * this is just convenient wrapper + * + * @param[in] a source 1 + * @param[in] b source 2 + * @param[out] d destination + */ +CGLM_INLINE +void +glm_cross(vec3 a, vec3 b, vec3 d) { + glm_vec3_cross(a, b, d); +} + +/*! + * @brief vec3 dot product + * + * this is just convenient wrapper + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ +CGLM_INLINE +float +glm_dot(vec3 a, vec3 b) { + return glm_vec3_dot(a, b); +} + +/*! + * @brief normalize vec3 and store result in same vec + * + * this is just convenient wrapper + * + * @param[in, out] v vector + */ +CGLM_INLINE +void +glm_normalize(vec3 v) { + glm_vec3_normalize(v); +} + +/*! + * @brief normalize vec3 to dest + * + * this is just convenient wrapper + * + * @param[in] v source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_normalize_to(vec3 v, vec3 dest) { + glm_vec3_normalize_to(v, dest); +} + +#endif /* cglm_vec3_h */ diff --git a/libs/cglm/include/cglm/vec4-ext.h b/libs/cglm/include/cglm/vec4-ext.h new file mode 100644 index 0000000..e4e20cb --- /dev/null +++ b/libs/cglm/include/cglm/vec4-ext.h @@ -0,0 +1,313 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/*! + * @brief SIMD like functions + */ + +/* + Functions: + CGLM_INLINE void glm_vec4_broadcast(float val, vec4 d); + CGLM_INLINE void glm_vec4_fill(vec4 v, float val); + CGLM_INLINE bool glm_vec4_eq(vec4 v, float val); + CGLM_INLINE bool glm_vec4_eq_eps(vec4 v, float val); + CGLM_INLINE bool glm_vec4_eq_all(vec4 v); + 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); + 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_abs(vec4 v, vec4 dest); + CGLM_INLINE void glm_vec4_fract(vec4 v, vec4 dest); + CGLM_INLINE float glm_vec4_hadd(vec4 v); + CGLM_INLINE void glm_vec4_sqrt(vec4 v, vec4 dest); + */ + +#ifndef cglm_vec4_ext_h +#define cglm_vec4_ext_h + +#include "common.h" +#include "vec3-ext.h" + +/*! + * @brief fill a vector with specified value + * + * @param val value + * @param d dest + */ +CGLM_INLINE +void +glm_vec4_broadcast(float val, vec4 d) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glmm_store(d, _mm_set1_ps(val)); +#else + d[0] = d[1] = d[2] = d[3] = val; +#endif +} + +/*! + * @brief fill a vector with specified value + * + * @param v dest + * @param val value + */ +CGLM_INLINE +void +glm_vec4_fill(vec4 v, float val) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glmm_store(v, _mm_set1_ps(val)); +#else + v[0] = v[1] = v[2] = v[3] = val; +#endif +} + +/*! + * @brief check if vector is equal to value (without epsilon) + * + * @param v vector + * @param val value + */ +CGLM_INLINE +bool +glm_vec4_eq(vec4 v, float val) { + return v[0] == val + && v[0] == v[1] + && v[0] == v[2] + && v[0] == v[3]; +} + +/*! + * @brief check if vector is equal to value (with epsilon) + * + * @param v vector + * @param val value + */ +CGLM_INLINE +bool +glm_vec4_eq_eps(vec4 v, float val) { + return fabsf(v[0] - val) <= GLM_FLT_EPSILON + && fabsf(v[1] - val) <= GLM_FLT_EPSILON + && fabsf(v[2] - val) <= GLM_FLT_EPSILON + && fabsf(v[3] - val) <= GLM_FLT_EPSILON; +} + +/*! + * @brief check if vectors members are equal (without epsilon) + * + * @param v vector + */ +CGLM_INLINE +bool +glm_vec4_eq_all(vec4 v) { + return glm_vec4_eq_eps(v, v[0]); +} + +/*! + * @brief check if vector is equal to another (without epsilon) + * + * @param a vector + * @param b vector + */ +CGLM_INLINE +bool +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 a vector + * @param b vector + */ +CGLM_INLINE +bool +glm_vec4_eqv_eps(vec4 a, vec4 b) { + return fabsf(a[0] - b[0]) <= GLM_FLT_EPSILON + && fabsf(a[1] - b[1]) <= GLM_FLT_EPSILON + && fabsf(a[2] - b[2]) <= GLM_FLT_EPSILON + && fabsf(a[3] - b[3]) <= GLM_FLT_EPSILON; +} + +/*! + * @brief max value of vector + * + * @param v vector + */ +CGLM_INLINE +float +glm_vec4_max(vec4 v) { + float max; + + max = glm_vec3_max(v); + if (v[3] > max) + max = v[3]; + + return max; +} + +/*! + * @brief min value of vector + * + * @param v vector + */ +CGLM_INLINE +float +glm_vec4_min(vec4 v) { + float min; + + min = glm_vec3_min(v); + if (v[3] < min) + min = v[3]; + + return min; +} + +/*! + * @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 +glm_vec4_isnan(vec4 v) { + return isnan(v[0]) || isnan(v[1]) || isnan(v[2]) || isnan(v[3]); +} + +/*! + * @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 +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); +} + +/*! + * @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 = glmm_load(v); + x1 = _mm_set_ps(0.0f, 0.0f, 1.0f, -1.0f); + x2 = glmm_splat(x1, 2); + + x3 = _mm_and_ps(_mm_cmpgt_ps(x0, x2), glmm_splat(x1, 1)); + x4 = _mm_and_ps(_mm_cmplt_ps(x0, x2), glmm_splat(x1, 0)); + + glmm_store(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 +} + +/*! + * @brief absolute value of each vector item + * + * @param[in] v vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_abs(vec4 v, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glmm_store(dest, glmm_abs(glmm_load(v))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vabsq_f32(vld1q_f32(v))); +#else + dest[0] = fabsf(v[0]); + dest[1] = fabsf(v[1]); + dest[2] = fabsf(v[2]); + dest[3] = fabsf(v[3]); +#endif +} + +/*! + * @brief fractional part of each vector item + * + * @param[in] v vector + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_fract(vec4 v, vec4 dest) { + dest[0] = fminf(v[0] - floorf(v[0]), 0.999999940395355224609375f); + dest[1] = fminf(v[1] - floorf(v[1]), 0.999999940395355224609375f); + dest[2] = fminf(v[2] - floorf(v[2]), 0.999999940395355224609375f); + dest[3] = fminf(v[3] - floorf(v[3]), 0.999999940395355224609375f); +} + +/*! + * @brief vector reduction by summation + * @warning could overflow + * + * @param[in] v vector + * @return sum of all vector's elements + */ +CGLM_INLINE +float +glm_vec4_hadd(vec4 v) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + return glmm_hadd(glmm_load(v)); +#else + return v[0] + v[1] + v[2] + v[3]; +#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__ ) + glmm_store(dest, _mm_sqrt_ps(glmm_load(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 */ diff --git a/libs/cglm/include/cglm/vec4.h b/libs/cglm/include/cglm/vec4.h new file mode 100644 index 0000000..8e95ec5 --- /dev/null +++ b/libs/cglm/include/cglm/vec4.h @@ -0,0 +1,1066 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * 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 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 v); + CGLM_INLINE float glm_vec4_norm_one(vec4 v); + CGLM_INLINE float glm_vec4_norm_inf(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); + 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_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); + 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 a, vec4 b); + CGLM_INLINE float glm_vec4_distance2(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); + CGLM_INLINE void glm_vec4_lerpc(vec4 from, vec4 to, float t, vec4 dest); + CGLM_INLINE void glm_vec4_step_uni(float edge, vec4 x, vec4 dest); + CGLM_INLINE void glm_vec4_step(vec4 edge, vec4 x, vec4 dest); + CGLM_INLINE void glm_vec4_smoothstep_uni(float edge0, float edge1, vec4 x, vec4 dest); + CGLM_INLINE void glm_vec4_smoothstep(vec4 edge0, vec4 edge1, vec4 x, vec4 dest); + CGLM_INLINE void glm_vec4_smoothinterp(vec4 from, vec4 to, float t, vec4 dest); + CGLM_INLINE void glm_vec4_smoothinterpc(vec4 from, vec4 to, float t, vec4 dest); + CGLM_INLINE void glm_vec4_swizzle(vec4 v, int mask, vec4 dest); + + DEPRECATED: + glm_vec4_dup + glm_vec4_flipsign + glm_vec4_flipsign_to + glm_vec4_inv + glm_vec4_inv_to + glm_vec4_mulv + */ + +#ifndef cglm_vec4_h +#define cglm_vec4_h + +#include "common.h" +#include "vec4-ext.h" +#include "util.h" + +/* 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_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} +#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_XXXX GLM_SHUFFLE4(0, 0, 0, 0) +#define GLM_YYYY GLM_SHUFFLE4(1, 1, 1, 1) +#define GLM_ZZZZ GLM_SHUFFLE4(2, 2, 2, 2) +#define GLM_WWWW GLM_SHUFFLE4(3, 3, 3, 3) +#define GLM_WZYX GLM_SHUFFLE4(0, 1, 2, 3) + +/*! + * @brief init vec4 using vec3 + * + * @param[in] v3 vector3 + * @param[in] last last item + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4(vec3 v3, float last, vec4 dest) { + dest[0] = v3[0]; + dest[1] = v3[1]; + dest[2] = v3[2]; + dest[3] = last; +} + +/*! + * @brief copy first 3 members of [a] to [dest] + * + * @param[in] a source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_copy3(vec4 a, vec3 dest) { + dest[0] = a[0]; + dest[1] = a[1]; + dest[2] = a[2]; +} + +/*! + * @brief copy all members of [a] to [dest] + * + * @param[in] v source + * @param[out] dest destination + */ +CGLM_INLINE +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]; + dest[2] = v[2]; + dest[3] = v[3]; +#endif +} + +/*! + * @brief copy all members of [a] to [dest] + * + * alignment is not required + * + * @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 + * + * @param[in, out] v vector + */ +CGLM_INLINE +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; + 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__ ) + 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; + v[2] = 1.0f; + v[3] = 1.0f; +#endif +} + +/*! + * @brief vec4 dot product + * + * @param[in] a vector1 + * @param[in] b vector2 + * + * @return dot product + */ +CGLM_INLINE +float +glm_vec4_dot(vec4 a, vec4 b) { +#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 +} + +/*! + * @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 +glm_vec4_norm2(vec4 v) { + return glm_vec4_dot(v, v); +} + +/*! + * @brief euclidean norm (magnitude), also called L2 norm + * this will give magnitude of vector in euclidean space + * + * @param[in] v vector + * + * @return norm + */ +CGLM_INLINE +float +glm_vec4_norm(vec4 v) { +#if defined(CGLM_SIMD) + return glmm_norm(glmm_load(v)); +#else + return sqrtf(glm_vec4_dot(v, v)); +#endif +} + +/*! + * @brief L1 norm of vec4 + * Also known as Manhattan Distance or Taxicab norm. + * L1 Norm is the sum of the magnitudes of the vectors in a space. + * It is calculated as the sum of the absolute values of the vector components. + * In this norm, all the components of the vector are weighted equally. + * + * This computes: + * L1 norm = |v[0]| + |v[1]| + |v[2]| + |v[3]| + * + * @param[in] v vector + * + * @return L1 norm + */ +CGLM_INLINE +float +glm_vec4_norm_one(vec4 v) { +#if defined(CGLM_SIMD) + return glmm_norm_one(glmm_load(v)); +#else + vec4 t; + glm_vec4_abs(v, t); + return glm_vec4_hadd(t); +#endif +} + +/*! + * @brief infinity norm of vec4 + * Also known as Maximum norm. + * Infinity Norm is the largest magnitude among each element of a vector. + * It is calculated as the maximum of the absolute values of the vector components. + * + * This computes: + * inf norm = max(|v[0]|, |v[1]|, |v[2]|, |v[3]|) + * + * @param[in] v vector + * + * @return infinity norm + */ +CGLM_INLINE +float +glm_vec4_norm_inf(vec4 v) { +#if defined(CGLM_SIMD) + return glmm_norm_inf(glmm_load(v)); +#else + vec4 t; + glm_vec4_abs(v, t); + return glm_vec4_max(t); +#endif +} + +/*! + * @brief add b vector to a vector store result in dest + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest destination vector + */ +CGLM_INLINE +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]; + dest[2] = a[2] + b[2]; + dest[3] = a[3] + b[3]; +#endif +} + +/*! + * @brief add scalar to 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_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; + dest[2] = v[2] + s; + dest[3] = v[3] + s; +#endif +} + +/*! + * @brief subtract b vector from a vector store result in dest (d = a - b) + * + * @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__ ) + 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]; + 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__ ) + 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; + dest[2] = v[2] - s; + dest[3] = v[3] - s; +#endif +} + +/*! + * @brief multiply two vector (component-wise multiplication) + * + * @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 +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]; + dest[2] = a[2] * b[2]; + dest[3] = a[3] * b[3]; +#endif +} + +/*! + * @brief multiply/scale vec4 vector with scalar: result = v * s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +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; + dest[2] = v[2] * s; + dest[3] = v[3] * s; +#endif +} + +/*! + * @brief make vec4 vector scale as specified: result = unit(v) * s + * + * @param[in] v vector + * @param[in] s scalar + * @param[out] dest destination vector + */ +CGLM_INLINE +void +glm_vec4_scale_as(vec4 v, float s, vec4 dest) { + float norm; + norm = glm_vec4_norm(v); + + if (norm == 0.0f) { + glm_vec4_zero(dest); + return; + } + + glm_vec4_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], a[3]/b[3]) + */ +CGLM_INLINE +void +glm_vec4_div(vec4 a, vec4 b, vec4 dest) { +#if defined(CGLM_SIMD) + glmm_store(dest, glmm_div(glmm_load(a), glmm_load(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__ ) + glmm_store(dest, _mm_div_ps(glmm_load(v), _mm_set1_ps(s))); +#else + glm_vec4_scale(v, 1.0f / s, 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__ ) + 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]; + 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__ ) + 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]; + 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(CGLM_SIMD) + glmm_store(dest, glmm_fmadd(glmm_load(a), glmm_load(b), glmm_load(dest))); +#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 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(CGLM_SIMD) + glmm_store(dest, glmm_fmadd(glmm_load(a), glmm_set1(s), glmm_load(dest))); +#else + dest[0] += a[0] * s; + dest[1] += a[1] * s; + dest[2] += a[2] * s; + dest[3] += a[3] * s; +#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)))); +#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]); + 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 1 + * @param[in] b vector 2 + * @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)))); +#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]); + dest[2] += glm_min(a[2], b[2]); + dest[3] += glm_min(a[3], b[3]); +#endif +} + +/*! + * @brief negate vector components and store result in dest + * + * @param[in] v vector + * @param[out] dest result vector + */ +CGLM_INLINE +void +glm_vec4_negate_to(vec4 v, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + glmm_store(dest, _mm_xor_ps(glmm_load(v), _mm_set1_ps(-0.0f))); +#elif defined(CGLM_NEON_FP) + vst1q_f32(dest, vnegq_f32(vld1q_f32(v))); +#else + dest[0] = -v[0]; + dest[1] = -v[1]; + dest[2] = -v[2]; + dest[3] = -v[3]; +#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 normalize vec4 to dest + * + * @param[in] v source + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_normalize_to(vec4 v, vec4 dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + __m128 xdot, x0; + float dot; + + x0 = glmm_load(v); + xdot = glmm_vdot(x0, x0); + dot = _mm_cvtss_f32(xdot); + + if (dot == 0.0f) { + glmm_store(dest, _mm_setzero_ps()); + return; + } + + glmm_store(dest, _mm_div_ps(x0, _mm_sqrt_ps(xdot))); +#else + float norm; + + norm = glm_vec4_norm(v); + + if (norm == 0.0f) { + glm_vec4_zero(dest); + return; + } + + glm_vec4_scale(v, 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); +} + +/** + * @brief distance between two vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @return returns distance + */ +CGLM_INLINE +float +glm_vec4_distance(vec4 a, vec4 b) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + return glmm_norm(_mm_sub_ps(glmm_load(a), glmm_load(b))); +#elif defined(CGLM_NEON_FP) + return glmm_norm(vsubq_f32(glmm_load(a), glmm_load(b))); +#else + return sqrtf(glm_pow2(a[0] - b[0]) + + glm_pow2(a[1] - b[1]) + + glm_pow2(a[2] - b[2]) + + glm_pow2(a[3] - b[3])); +#endif +} + +/** + * @brief squared distance between two vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @return returns squared distance + */ +CGLM_INLINE +float +glm_vec4_distance2(vec4 a, vec4 b) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + return glmm_norm2(_mm_sub_ps(glmm_load(a), glmm_load(b))); +#elif defined(CGLM_NEON_FP) + return glmm_norm2(vsubq_f32(glmm_load(a), glmm_load(b))); +#else + return glm_pow2(a[0] - b[0]) + + glm_pow2(a[1] - b[1]) + + glm_pow2(a[2] - b[2]) + + glm_pow2(a[3] - b[3]); +#endif +} + +/*! + * @brief max values of vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest destination + */ +CGLM_INLINE +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]); + dest[2] = glm_max(a[2], b[2]); + dest[3] = glm_max(a[3], b[3]); +#endif +} + +/*! + * @brief min values of vectors + * + * @param[in] a vector1 + * @param[in] b vector2 + * @param[out] dest destination + */ +CGLM_INLINE +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]); + dest[2] = glm_min(a[2], b[2]); + dest[3] = glm_min(a[3], b[3]); +#endif +} + +/*! + * @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) { +#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); + v[2] = glm_clamp(v[2], minVal, maxVal); + v[3] = glm_clamp(v[3], minVal, maxVal); +#endif +} + +/*! + * @brief linear interpolation between two vectors + * + * formula: from + t * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @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(t, s); + glm_vec4_sub(to, from, v); + glm_vec4_mul(s, v, v); + glm_vec4_add(from, v, dest); +} + +/*! + * @brief linear interpolation between two vectors (clamped) + * + * formula: from + t * (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_lerpc(vec4 from, vec4 to, float t, vec4 dest) { + glm_vec4_lerp(from, to, glm_clamp_zo(t), dest); +} + +/*! + * @brief linear interpolation between two vectors + * + * formula: from + t * (to - from) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_mix(vec4 from, vec4 to, float t, vec4 dest) { + glm_vec4_lerp(from, to, t, dest); +} + +/*! + * @brief linear interpolation between two vectors (clamped) + * + * formula: from + t * (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_mixc(vec4 from, vec4 to, float t, vec4 dest) { + glm_vec4_lerpc(from, to, t, dest); +} + +/*! + * @brief threshold function (unidimensional) + * + * @param[in] edge threshold + * @param[in] x value to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_step_uni(float edge, vec4 x, vec4 dest) { + dest[0] = glm_step(edge, x[0]); + dest[1] = glm_step(edge, x[1]); + dest[2] = glm_step(edge, x[2]); + dest[3] = glm_step(edge, x[3]); +} + +/*! + * @brief threshold function + * + * @param[in] edge threshold + * @param[in] x value to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_step(vec4 edge, vec4 x, vec4 dest) { + dest[0] = glm_step(edge[0], x[0]); + dest[1] = glm_step(edge[1], x[1]); + dest[2] = glm_step(edge[2], x[2]); + dest[3] = glm_step(edge[3], x[3]); +} + +/*! + * @brief threshold function with a smooth transition (unidimensional) + * + * @param[in] edge0 low threshold + * @param[in] edge1 high threshold + * @param[in] x value to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_smoothstep_uni(float edge0, float edge1, vec4 x, vec4 dest) { + dest[0] = glm_smoothstep(edge0, edge1, x[0]); + dest[1] = glm_smoothstep(edge0, edge1, x[1]); + dest[2] = glm_smoothstep(edge0, edge1, x[2]); + dest[3] = glm_smoothstep(edge0, edge1, x[3]); +} + +/*! + * @brief threshold function with a smooth transition + * + * @param[in] edge0 low threshold + * @param[in] edge1 high threshold + * @param[in] x value to test against threshold + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_smoothstep(vec4 edge0, vec4 edge1, vec4 x, vec4 dest) { + dest[0] = glm_smoothstep(edge0[0], edge1[0], x[0]); + dest[1] = glm_smoothstep(edge0[1], edge1[1], x[1]); + dest[2] = glm_smoothstep(edge0[2], edge1[2], x[2]); + dest[3] = glm_smoothstep(edge0[3], edge1[3], x[3]); +} + +/*! + * @brief smooth Hermite interpolation between two vectors + * + * formula: t^2 * (3 - 2*t) + * + * @param[in] from from value + * @param[in] to to value + * @param[in] t interpolant (amount) + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_smoothinterp(vec4 from, vec4 to, float t, vec4 dest) { + vec4 s, v; + + /* from + smoothstep * (to - from) */ + glm_vec4_broadcast(glm_smooth(t), s); + glm_vec4_sub(to, from, v); + glm_vec4_mul(s, v, v); + glm_vec4_add(from, v, dest); +} + +/*! + * @brief smooth Hermite interpolation between two vectors (clamped) + * + * formula: t^2 * (3 - 2*t) + * + * @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_smoothinterpc(vec4 from, vec4 to, float t, vec4 dest) { + glm_vec4_smoothinterp(from, to, glm_clamp_zo(t), 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] = ss * s; + dest[1] = ss; + dest[2] = s; + dest[3] = 1.0f; +} + +/*! + * @brief swizzle vector components + * + * you can use existin masks e.g. GLM_XXXX, GLM_WZYX + * + * @param[in] v source + * @param[in] mask mask + * @param[out] dest destination + */ +CGLM_INLINE +void +glm_vec4_swizzle(vec4 v, int mask, vec4 dest) { + vec4 t; + + t[0] = v[(mask & (3 << 0))]; + t[1] = v[(mask & (3 << 2)) >> 2]; + t[2] = v[(mask & (3 << 4)) >> 4]; + t[3] = v[(mask & (3 << 6)) >> 6]; + + glm_vec4_copy(t, dest); +} + +#endif /* cglm_vec4_h */ diff --git a/libs/cglm/include/cglm/version.h b/libs/cglm/include/cglm/version.h new file mode 100644 index 0000000..b31eae6 --- /dev/null +++ b/libs/cglm/include/cglm/version.h @@ -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 + */ + +#ifndef cglm_version_h +#define cglm_version_h + +#define CGLM_VERSION_MAJOR 0 +#define CGLM_VERSION_MINOR 8 +#define CGLM_VERSION_PATCH 6 + +#endif /* cglm_version_h */ diff --git a/libs/cglm/include/module.modulemap b/libs/cglm/include/module.modulemap new file mode 100644 index 0000000..40b8b9f --- /dev/null +++ b/libs/cglm/include/module.modulemap @@ -0,0 +1,14 @@ +module cglm { + header "cglm/cglm.h" + header "cglm/struct.h" + + export * +} + +module cglmc { + header "cglm/cglm.h" + header "cglm/struct.h" + header "cglm/call.h" + + export * +} diff --git a/libs/cglm/meson.build b/libs/cglm/meson.build new file mode 100644 index 0000000..8f9cdc4 --- /dev/null +++ b/libs/cglm/meson.build @@ -0,0 +1,129 @@ +project('cglm', 'c', + version : '0.8.6', + license : 'mit', + default_options : [ + 'c_std=c11', + 'werror=true', + 'warning_level=2', + 'buildtype=release' + ] +) + +cc = meson.get_compiler('c') + +cglm_install = get_option('install') +cglm_deps = cc.find_library('m', required : false) + +cglm_args = [] +build_args = [] + +if get_option('default_library') == 'static' + cglm_args = '-DCGLM_STATIC' +endif + +if host_machine.system() == 'windows' + build_args = '-DCGLM_EXPORTS' +endif + +cglm_inc = include_directories('include') + +cglm_src = files( + 'src/affine.c', + 'src/affine2d.c', + 'src/bezier.c', + 'src/box.c', + 'src/cam.c', + 'src/curve.c', + 'src/ease.c', + 'src/euler.c', + 'src/frustum.c', + 'src/io.c', + 'src/mat2.c', + 'src/mat3.c', + 'src/mat4.c', + 'src/plane.c', + 'src/project.c', + 'src/quat.c', + 'src/ray.c', + 'src/sphere.c', + 'src/vec2.c', + 'src/vec3.c', + 'src/vec4.c', + 'src/ivec2.c', + 'src/ivec3.c', + 'src/ivec4.c', + 'src/clipspace/ortho_lh_no.c', + 'src/clipspace/ortho_lh_zo.c', + 'src/clipspace/ortho_rh_no.c', + 'src/clipspace/ortho_rh_zo.c', + 'src/clipspace/persp_lh_no.c', + 'src/clipspace/persp_lh_zo.c', + 'src/clipspace/persp_rh_no.c', + 'src/clipspace/persp_rh_zo.c', + 'src/clipspace/view_lh_no.c', + 'src/clipspace/view_lh_zo.c', + 'src/clipspace/view_rh_no.c', + 'src/clipspace/view_rh_zo.c', +) + +cglm_lib = library('cglm', + cglm_src, + install : cglm_install, + dependencies : cglm_deps, + c_args : [ build_args, cglm_args ], + version : meson.project_version(), + soversion : '0' +) + +cglm_dep = declare_dependency( + link_with : cglm_lib, + dependencies : cglm_deps, + compile_args : cglm_args, + include_directories : cglm_inc, + version : meson.project_version() +) + +if meson.version().version_compare('>= 0.54.0') + meson.override_dependency('cglm', cglm_dep) +endif + +if cglm_install + install_subdir('include/cglm', install_dir : get_option('includedir')) + + pkg = import('pkgconfig') + pkg.generate( + name : 'cglm', + libraries : cglm_lib, + extra_cflags : cglm_args, + version : meson.project_version(), + url : 'https://github.com/recp/cglm', + description : 'OpenGL Mathematics (glm) for C' + ) +endif + +if get_option('build_tests') == true + +test_src = files( + 'test/runner.c', + 'test/src/test_bezier.c', + 'test/src/test_cam.c', + 'test/src/test_cam_lh_no.c', + 'test/src/test_cam_lh_zo.c', + 'test/src/test_cam_rh_no.c', + 'test/src/test_cam_rh_zo.c', + 'test/src/test_clamp.c', + 'test/src/test_common.c', + 'test/src/test_euler.c', + 'test/src/tests.c', + 'test/src/test_struct.c', +) + +test_exe = executable('tests', + test_src, + dependencies : cglm_dep, + c_args : '-DGLM_TESTS_NO_COLORFUL_OUTPUT' +) + +test('cglm.tests', test_exe) + +endif diff --git a/libs/cglm/meson_options.txt b/libs/cglm/meson_options.txt new file mode 100644 index 0000000..fb3ced8 --- /dev/null +++ b/libs/cglm/meson_options.txt @@ -0,0 +1,2 @@ +option('build_tests', type : 'boolean', value : false, description : 'Build tests') +option('install', type : 'boolean', value : true, description : 'Include the library, headers, and pkg-config file in the install target') diff --git a/libs/cglm/src/affine.c b/libs/cglm/src/affine.c new file mode 100644 index 0000000..a818bd1 --- /dev/null +++ b/libs/cglm/src/affine.c @@ -0,0 +1,153 @@ +/* + * 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_translate_make(mat4 m, vec3 v) { + glm_translate_make(m, v); +} + +CGLM_EXPORT +void +glmc_translate_to(mat4 m, vec3 v, mat4 dest) { + glm_translate_to(m, v, dest); +} + +CGLM_EXPORT +void +glmc_translate(mat4 m, vec3 v) { + glm_translate(m, v); +} + +CGLM_EXPORT +void +glmc_translate_x(mat4 m, float to) { + glm_translate_x(m, to); +} + +CGLM_EXPORT +void +glmc_translate_y(mat4 m, float to) { + glm_translate_y(m, to); +} + +CGLM_EXPORT +void +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) { + glm_scale_to(m, v, dest); +} + +CGLM_EXPORT +void +glmc_scale(mat4 m, vec3 v) { + glm_scale(m, v); +} + +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) { + glm_rotate_x(m, rad, dest); +} + +CGLM_EXPORT +void +glmc_rotate_y(mat4 m, float rad, mat4 dest) { + glm_rotate_y(m, rad, dest); +} + +CGLM_EXPORT +void +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, vec3 axis) { + glm_rotate_make(m, angle, axis); +} + +CGLM_EXPORT +void +glmc_rotate(mat4 m, float angle, vec3 axis) { + glm_rotate(m, angle, axis); +} + +CGLM_EXPORT +void +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 +void +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) { + glm_decompose_rs(m, r, s); +} + +CGLM_EXPORT +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/libs/cglm/src/affine2d.c b/libs/cglm/src/affine2d.c new file mode 100644 index 0000000..6e5913e --- /dev/null +++ b/libs/cglm/src/affine2d.c @@ -0,0 +1,81 @@ +/* + * 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_translate2d_make(mat3 m, vec2 v) { + glm_translate2d_make(m, v); +} + +CGLM_EXPORT +void +glmc_translate2d_to(mat3 m, vec2 v, mat3 dest) { + glm_translate2d_to(m, v, dest); +} + +CGLM_EXPORT +void +glmc_translate2d(mat3 m, vec2 v) { + glm_translate2d(m, v); +} + +CGLM_EXPORT +void +glmc_translate2d_x(mat3 m, float to) { + glm_translate2d_x(m, to); +} + +CGLM_EXPORT +void +glmc_translate2d_y(mat3 m, float to) { + glm_translate2d_y(m, to); +} + +CGLM_EXPORT +void +glmc_scale2d_to(mat3 m, vec2 v, mat3 dest) { + glm_scale2d_to(m, v, dest); +} + +CGLM_EXPORT +void +glmc_scale2d_make(mat3 m, vec2 v) { + glm_scale2d_make(m, v); +} + +CGLM_EXPORT +void +glmc_scale2d(mat3 m, vec2 v) { + glm_scale2d(m, v); +} + +CGLM_EXPORT +void +glmc_scale2d_uni(mat3 m, float s) { + glm_scale2d_uni(m, s); +} + +CGLM_EXPORT +void +glmc_rotate2d_make(mat3 m, float angle) { + glm_rotate2d_make(m, angle); +} + +CGLM_EXPORT +void +glmc_rotate2d(mat3 m, float angle) { + glm_rotate2d(m, angle); +} + +CGLM_EXPORT +void +glmc_rotate2d_to(mat3 m, float angle, mat3 dest) { + glm_rotate2d_to(m, angle, dest); +} diff --git a/libs/cglm/src/bezier.c b/libs/cglm/src/bezier.c new file mode 100644 index 0000000..21e6495 --- /dev/null +++ b/libs/cglm/src/bezier.c @@ -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 + */ + +#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); +} + +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) { + return glm_decasteljau(prm, p0, c0, c1, p1); +} diff --git a/libs/cglm/src/box.c b/libs/cglm/src/box.c new file mode 100644 index 0000000..fd639ea --- /dev/null +++ b/libs/cglm/src/box.c @@ -0,0 +1,96 @@ +/* + * 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_aabb_transform(vec3 box[2], 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]) { + glm_aabb_merge(box1, box2, dest); +} + +CGLM_EXPORT +void +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(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(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); +} + +CGLM_EXPORT +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 s) { + return glm_aabb_sphere(box, s); +} diff --git a/libs/cglm/src/cam.c b/libs/cglm/src/cam.c new file mode 100644 index 0000000..40db351 --- /dev/null +++ b/libs/cglm/src/cam.c @@ -0,0 +1,171 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +void +glmc_frustum(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_frustum(left, right, bottom, top, nearZ, farZ, dest); +} + +CGLM_EXPORT +void +glmc_ortho(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_ortho(left, right, bottom, top, nearZ, farZ, 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, float aspect, float nearZ, float farZ, mat4 dest) { + glm_perspective(fovy, aspect, nearZ, farZ, 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) { + 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, vec3 center, vec3 up, mat4 dest) { + glm_lookat(eye, center, up, dest); +} + +CGLM_EXPORT +void +glmc_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look(eye, dir, up, dest); +} + +CGLM_EXPORT +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 nearZ, + float * __restrict farZ, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp(proj, nearZ, farZ, 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 nearZ, + float * __restrict farZ) { + glm_persp_decomp_z(proj, nearZ, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_far(mat4 proj, float * __restrict farZ) { + glm_persp_decomp_far(proj, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_near(mat4 proj, float * __restrict nearZ) { + glm_persp_decomp_near(proj, nearZ); +} + +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/libs/cglm/src/clipspace/ortho_lh_no.c b/libs/cglm/src/clipspace/ortho_lh_no.c new file mode 100644 index 0000000..839926a --- /dev/null +++ b/libs/cglm/src/clipspace/ortho_lh_no.c @@ -0,0 +1,51 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../../include/cglm/clipspace/ortho_lh_no.h" +#include "../../include/cglm/call/clipspace/ortho_lh_no.h" + +CGLM_EXPORT +void +glmc_ortho_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_ortho_lh_no(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_lh_no(vec3 box[2], mat4 dest) { + glm_ortho_aabb_lh_no(box, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_p_lh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_p_lh_no(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_lh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_pz_lh_no(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_lh_no(float aspect, mat4 dest) { + glm_ortho_default_lh_no(aspect, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_s_lh_no(float aspect, float size, mat4 dest) { + glm_ortho_default_s_lh_no(aspect, size, dest); +} diff --git a/libs/cglm/src/clipspace/ortho_lh_zo.c b/libs/cglm/src/clipspace/ortho_lh_zo.c new file mode 100644 index 0000000..88291ac --- /dev/null +++ b/libs/cglm/src/clipspace/ortho_lh_zo.c @@ -0,0 +1,51 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../../include/cglm/clipspace/ortho_lh_zo.h" +#include "../../include/cglm/call/clipspace/ortho_lh_zo.h" + +CGLM_EXPORT +void +glmc_ortho_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_ortho_lh_zo(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_lh_zo(vec3 box[2], mat4 dest) { + glm_ortho_aabb_lh_zo(box, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_p_lh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_p_lh_zo(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_lh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_pz_lh_zo(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_lh_zo(float aspect, mat4 dest) { + glm_ortho_default_lh_zo(aspect, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_s_lh_zo(float aspect, float size, mat4 dest) { + glm_ortho_default_s_lh_zo(aspect, size, dest); +} diff --git a/libs/cglm/src/clipspace/ortho_rh_no.c b/libs/cglm/src/clipspace/ortho_rh_no.c new file mode 100644 index 0000000..ca30e82 --- /dev/null +++ b/libs/cglm/src/clipspace/ortho_rh_no.c @@ -0,0 +1,51 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../../include/cglm/clipspace/ortho_rh_no.h" +#include "../../include/cglm/call/clipspace/ortho_rh_no.h" + +CGLM_EXPORT +void +glmc_ortho_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_ortho_rh_no(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_rh_no(vec3 box[2], mat4 dest) { + glm_ortho_aabb_rh_no(box, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_p_rh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_p_rh_no(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_rh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_pz_rh_no(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_rh_no(float aspect, mat4 dest) { + glm_ortho_default_rh_no(aspect, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_s_rh_no(float aspect, float size, mat4 dest) { + glm_ortho_default_s_rh_no(aspect, size, dest); +} diff --git a/libs/cglm/src/clipspace/ortho_rh_zo.c b/libs/cglm/src/clipspace/ortho_rh_zo.c new file mode 100644 index 0000000..06d119b --- /dev/null +++ b/libs/cglm/src/clipspace/ortho_rh_zo.c @@ -0,0 +1,51 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../../include/cglm/clipspace/ortho_rh_zo.h" +#include "../../include/cglm/call/clipspace/ortho_rh_zo.h" + +CGLM_EXPORT +void +glmc_ortho_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_ortho_rh_zo(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_rh_zo(vec3 box[2], mat4 dest) { + glm_ortho_aabb_rh_zo(box, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_p_rh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_p_rh_zo(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_rh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_pz_rh_zo(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_rh_zo(float aspect, mat4 dest) { + glm_ortho_default_rh_zo(aspect, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_s_rh_zo(float aspect, float size, mat4 dest) { + glm_ortho_default_s_rh_zo(aspect, size, dest); +} diff --git a/libs/cglm/src/clipspace/persp_lh_no.c b/libs/cglm/src/clipspace/persp_lh_no.c new file mode 100644 index 0000000..8d6db76 --- /dev/null +++ b/libs/cglm/src/clipspace/persp_lh_no.c @@ -0,0 +1,110 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../../include/cglm/clipspace/persp_lh_no.h" +#include "../../include/cglm/call/clipspace/persp_lh_no.h" + +CGLM_EXPORT +void +glmc_frustum_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_frustum_lh_no(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_perspective_lh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + glm_perspective_lh_no(fovy, + aspect, + nearVal, + farVal, + dest); +} + +CGLM_EXPORT +void +glmc_persp_move_far_lh_no(mat4 proj, float deltaFar) { + glm_persp_move_far_lh_no(proj, deltaFar); +} + +CGLM_EXPORT +void +glmc_persp_decomp_lh_no(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_lh_no(proj, nearZ, farZ, top, bottom, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decompv_lh_no(mat4 proj, float dest[6]) { + glm_persp_decompv_lh_no(proj, dest); +} + +CGLM_EXPORT +void +glmc_persp_decomp_x_lh_no(mat4 proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_lh_no(proj, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decomp_y_lh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_lh_no(proj, top, bottom); +} + +CGLM_EXPORT +void +glmc_persp_decomp_z_lh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_lh_no(proj, nearZ, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_far_lh_no(mat4 proj, float * __restrict farZ) { + glm_persp_decomp_far_lh_no(proj, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_near_lh_no(mat4 proj, float * __restrict nearZ) { + glm_persp_decomp_near_lh_no(proj, nearZ); +} + +CGLM_EXPORT +void +glmc_persp_sizes_lh_no(mat4 proj, float fovy, vec4 dest) { + glm_persp_sizes_lh_no(proj, fovy, dest); +} + +CGLM_EXPORT +float +glmc_persp_fovy_lh_no(mat4 proj) { + return glm_persp_fovy_lh_no(proj); +} + +CGLM_EXPORT +float +glmc_persp_aspect_lh_no(mat4 proj) { + return glm_persp_aspect_lh_no(proj); +} diff --git a/libs/cglm/src/clipspace/persp_lh_zo.c b/libs/cglm/src/clipspace/persp_lh_zo.c new file mode 100644 index 0000000..d9fec0c --- /dev/null +++ b/libs/cglm/src/clipspace/persp_lh_zo.c @@ -0,0 +1,110 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../../include/cglm/clipspace/persp_lh_zo.h" +#include "../../include/cglm/call/clipspace/persp_lh_zo.h" + +CGLM_EXPORT +void +glmc_frustum_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_frustum_lh_zo(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_perspective_lh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + glm_perspective_lh_zo(fovy, + aspect, + nearVal, + farVal, + dest); +} + +CGLM_EXPORT +void +glmc_persp_move_far_lh_zo(mat4 proj, float deltaFar) { + glm_persp_move_far_lh_zo(proj, deltaFar); +} + +CGLM_EXPORT +void +glmc_persp_decomp_lh_zo(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_lh_zo(proj, nearZ, farZ, top, bottom, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decompv_lh_zo(mat4 proj, float dest[6]) { + glm_persp_decompv_lh_zo(proj, dest); +} + +CGLM_EXPORT +void +glmc_persp_decomp_x_lh_zo(mat4 proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_lh_zo(proj, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decomp_y_lh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_lh_zo(proj, top, bottom); +} + +CGLM_EXPORT +void +glmc_persp_decomp_z_lh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_lh_zo(proj, nearZ, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_far_lh_zo(mat4 proj, float * __restrict farZ) { + glm_persp_decomp_far_lh_zo(proj, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_near_lh_zo(mat4 proj, float * __restrict nearZ) { + glm_persp_decomp_near_lh_zo(proj, nearZ); +} + +CGLM_EXPORT +void +glmc_persp_sizes_lh_zo(mat4 proj, float fovy, vec4 dest) { + glm_persp_sizes_lh_zo(proj, fovy, dest); +} + +CGLM_EXPORT +float +glmc_persp_fovy_lh_zo(mat4 proj) { + return glm_persp_fovy_lh_zo(proj); +} + +CGLM_EXPORT +float +glmc_persp_aspect_lh_zo(mat4 proj) { + return glm_persp_aspect_lh_zo(proj); +} diff --git a/libs/cglm/src/clipspace/persp_rh_no.c b/libs/cglm/src/clipspace/persp_rh_no.c new file mode 100644 index 0000000..8fc7735 --- /dev/null +++ b/libs/cglm/src/clipspace/persp_rh_no.c @@ -0,0 +1,110 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../../include/cglm/clipspace/persp_rh_no.h" +#include "../../include/cglm/call/clipspace/persp_rh_no.h" + +CGLM_EXPORT +void +glmc_frustum_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_frustum_rh_no(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_perspective_rh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + glm_perspective_rh_no(fovy, + aspect, + nearVal, + farVal, + dest); +} + +CGLM_EXPORT +void +glmc_persp_move_far_rh_no(mat4 proj, float deltaFar) { + glm_persp_move_far_rh_no(proj, deltaFar); +} + +CGLM_EXPORT +void +glmc_persp_decomp_rh_no(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_rh_no(proj, nearZ, farZ, top, bottom, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decompv_rh_no(mat4 proj, float dest[6]) { + glm_persp_decompv_rh_no(proj, dest); +} + +CGLM_EXPORT +void +glmc_persp_decomp_x_rh_no(mat4 proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_rh_no(proj, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decomp_y_rh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_rh_no(proj, top, bottom); +} + +CGLM_EXPORT +void +glmc_persp_decomp_z_rh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_rh_no(proj, nearZ, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_far_rh_no(mat4 proj, float * __restrict farZ) { + glm_persp_decomp_far_rh_no(proj, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_near_rh_no(mat4 proj, float * __restrict nearZ) { + glm_persp_decomp_near_rh_no(proj, nearZ); +} + +CGLM_EXPORT +void +glmc_persp_sizes_rh_no(mat4 proj, float fovy, vec4 dest) { + glm_persp_sizes_rh_no(proj, fovy, dest); +} + +CGLM_EXPORT +float +glmc_persp_fovy_rh_no(mat4 proj) { + return glm_persp_fovy_rh_no(proj); +} + +CGLM_EXPORT +float +glmc_persp_aspect_rh_no(mat4 proj) { + return glm_persp_aspect_rh_no(proj); +} diff --git a/libs/cglm/src/clipspace/persp_rh_zo.c b/libs/cglm/src/clipspace/persp_rh_zo.c new file mode 100644 index 0000000..50190f2 --- /dev/null +++ b/libs/cglm/src/clipspace/persp_rh_zo.c @@ -0,0 +1,110 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../../include/cglm/clipspace/persp_rh_zo.h" +#include "../../include/cglm/call/clipspace/persp_rh_zo.h" + +CGLM_EXPORT +void +glmc_frustum_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_frustum_rh_zo(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_perspective_rh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + glm_perspective_rh_zo(fovy, + aspect, + nearVal, + farVal, + dest); +} + +CGLM_EXPORT +void +glmc_persp_move_far_rh_zo(mat4 proj, float deltaFar) { + glm_persp_move_far_rh_zo(proj, deltaFar); +} + +CGLM_EXPORT +void +glmc_persp_decomp_rh_zo(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_rh_zo(proj, nearZ, farZ, top, bottom, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decompv_rh_zo(mat4 proj, float dest[6]) { + glm_persp_decompv_rh_zo(proj, dest); +} + +CGLM_EXPORT +void +glmc_persp_decomp_x_rh_zo(mat4 proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_rh_zo(proj, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decomp_y_rh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_rh_zo(proj, top, bottom); +} + +CGLM_EXPORT +void +glmc_persp_decomp_z_rh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_rh_zo(proj, nearZ, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_far_rh_zo(mat4 proj, float * __restrict farZ) { + glm_persp_decomp_far_rh_zo(proj, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_near_rh_zo(mat4 proj, float * __restrict nearZ) { + glm_persp_decomp_near_rh_zo(proj, nearZ); +} + +CGLM_EXPORT +void +glmc_persp_sizes_rh_zo(mat4 proj, float fovy, vec4 dest) { + glm_persp_sizes_rh_zo(proj, fovy, dest); +} + +CGLM_EXPORT +float +glmc_persp_fovy_rh_zo(mat4 proj) { + return glm_persp_fovy_rh_zo(proj); +} + +CGLM_EXPORT +float +glmc_persp_aspect_rh_zo(mat4 proj) { + return glm_persp_aspect_rh_zo(proj); +} diff --git a/libs/cglm/src/clipspace/project_no.c b/libs/cglm/src/clipspace/project_no.c new file mode 100644 index 0000000..8352cba --- /dev/null +++ b/libs/cglm/src/clipspace/project_no.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/clipspace/project_no.h" +#include "../../include/cglm/call/clipspace/project_no.h" + +CGLM_EXPORT +void +glmc_unprojecti_no(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { + glm_unprojecti_no(pos, invMat, vp, dest); +} + +CGLM_EXPORT +void +glmc_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest) { + glm_project_no(pos, m, vp, dest); +} diff --git a/libs/cglm/src/clipspace/project_zo.c b/libs/cglm/src/clipspace/project_zo.c new file mode 100644 index 0000000..bc480a0 --- /dev/null +++ b/libs/cglm/src/clipspace/project_zo.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/clipspace/project_zo.h" +#include "../../include/cglm/call/clipspace/project_zo.h" + +CGLM_EXPORT +void +glmc_unprojecti_zo(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { + glm_unprojecti_zo(pos, invMat, vp, dest); +} + +CGLM_EXPORT +void +glmc_project_zo(vec3 pos, mat4 m, vec4 vp, vec3 dest) { + glm_project_zo(pos, m, vp, dest); +} diff --git a/libs/cglm/src/clipspace/view_lh_no.c b/libs/cglm/src/clipspace/view_lh_no.c new file mode 100644 index 0000000..39f2a9d --- /dev/null +++ b/libs/cglm/src/clipspace/view_lh_no.c @@ -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 + */ + +#include "../../include/cglm/clipspace/view_lh_no.h" +#include "../../include/cglm/call/clipspace/view_lh_no.h" + +CGLM_EXPORT +void +glmc_lookat_lh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_lh_no(eye, center, up, dest); +} + +CGLM_EXPORT +void +glmc_look_lh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_lh_no(eye, dir, up, dest); +} + +CGLM_EXPORT +void +glmc_look_anyup_lh_no(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_lh_no(eye, dir, dest); +} diff --git a/libs/cglm/src/clipspace/view_lh_zo.c b/libs/cglm/src/clipspace/view_lh_zo.c new file mode 100644 index 0000000..a8680d9 --- /dev/null +++ b/libs/cglm/src/clipspace/view_lh_zo.c @@ -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 + */ + +#include "../../include/cglm/clipspace/view_lh_zo.h" +#include "../../include/cglm/call/clipspace/view_lh_zo.h" + +CGLM_EXPORT +void +glmc_lookat_lh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_lh_zo(eye, center, up, dest); +} + +CGLM_EXPORT +void +glmc_look_lh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_lh_zo(eye, dir, up, dest); +} + +CGLM_EXPORT +void +glmc_look_anyup_lh_zo(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_lh_zo(eye, dir, dest); +} diff --git a/libs/cglm/src/clipspace/view_rh_no.c b/libs/cglm/src/clipspace/view_rh_no.c new file mode 100644 index 0000000..6d60c08 --- /dev/null +++ b/libs/cglm/src/clipspace/view_rh_no.c @@ -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 + */ + +#include "../../include/cglm/clipspace/view_rh_no.h" +#include "../../include/cglm/call/clipspace/view_rh_no.h" + +CGLM_EXPORT +void +glmc_lookat_rh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_rh_no(eye, center, up, dest); +} + +CGLM_EXPORT +void +glmc_look_rh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_rh_no(eye, dir, up, dest); +} + +CGLM_EXPORT +void +glmc_look_anyup_rh_no(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_rh_no(eye, dir, dest); +} diff --git a/libs/cglm/src/clipspace/view_rh_zo.c b/libs/cglm/src/clipspace/view_rh_zo.c new file mode 100644 index 0000000..5133fda --- /dev/null +++ b/libs/cglm/src/clipspace/view_rh_zo.c @@ -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 + */ + +#include "../../include/cglm/clipspace/view_rh_zo.h" +#include "../../include/cglm/call/clipspace/view_rh_zo.h" + +CGLM_EXPORT +void +glmc_lookat_rh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_rh_zo(eye, center, up, dest); +} + +CGLM_EXPORT +void +glmc_look_rh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_rh_zo(eye, dir, up, dest); +} + +CGLM_EXPORT +void +glmc_look_anyup_rh_zo(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_rh_zo(eye, dir, dest); +} diff --git a/libs/cglm/src/config.h b/libs/cglm/src/config.h new file mode 100644 index 0000000..ddec761 --- /dev/null +++ b/libs/cglm/src/config.h @@ -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 + */ + +#ifndef cglm__config__h_ +#define cglm__config__h_ + +#if defined(_WIN32) || defined(WIN32) + +/* Exclude rarely-used stuff from Windows headers */ +# define WIN32_LEAN_AND_MEAN +# include + +/* Windows Header Files: */ +# include + +#endif + +#endif /* cglm__config__h_ */ diff --git a/libs/cglm/src/curve.c b/libs/cglm/src/curve.c new file mode 100644 index 0000000..74d4702 --- /dev/null +++ b/libs/cglm/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/libs/cglm/src/ease.c b/libs/cglm/src/ease.c new file mode 100644 index 0000000..702dfce --- /dev/null +++ b/libs/cglm/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); +} diff --git a/libs/cglm/src/euler.c b/libs/cglm/src/euler.c new file mode 100644 index 0000000..a59b1df --- /dev/null +++ b/libs/cglm/src/euler.c @@ -0,0 +1,63 @@ +/* + * 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_euler_angles(mat4 m, vec3 dest) { + glm_euler_angles(m, dest); +} + +CGLM_EXPORT +void +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) { + glm_euler_zyx(angles, dest); +} + +CGLM_EXPORT +void +glmc_euler_zxy(vec3 angles, mat4 dest) { + glm_euler_zxy(angles, dest); +} + +CGLM_EXPORT +void +glmc_euler_xzy(vec3 angles, mat4 dest) { + glm_euler_xzy(angles, dest); +} + +CGLM_EXPORT +void +glmc_euler_yzx(vec3 angles, mat4 dest) { + glm_euler_yzx(angles, dest); +} + +CGLM_EXPORT +void +glmc_euler_yxz(vec3 angles, mat4 dest) { + glm_euler_yxz(angles, dest); +} + +CGLM_EXPORT +void +glmc_euler_by_order(vec3 angles, glm_euler_seq axis, mat4 dest) { + glm_euler_by_order(angles, axis, dest); +} diff --git a/libs/cglm/src/frustum.c b/libs/cglm/src/frustum.c new file mode 100644 index 0000000..312c3d3 --- /dev/null +++ b/libs/cglm/src/frustum.c @@ -0,0 +1,42 @@ +/* + * 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_frustum_planes(mat4 m, vec4 dest[6]) { + glm_frustum_planes(m, dest); +} + +CGLM_EXPORT +void +glmc_frustum_corners(mat4 invMat, vec4 dest[8]) { + glm_frustum_corners(invMat, dest); +} + +CGLM_EXPORT +void +glmc_frustum_center(vec4 corners[8], vec4 dest) { + glm_frustum_center(corners, dest); +} + +CGLM_EXPORT +void +glmc_frustum_box(vec4 corners[8], 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]) { + glm_frustum_corners_at(corners, splitDist, farDist, planeCorners); +} diff --git a/libs/cglm/src/io.c b/libs/cglm/src/io.c new file mode 100644 index 0000000..fd81dac --- /dev/null +++ b/libs/cglm/src/io.c @@ -0,0 +1,46 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#define CGLM_LIB_SRC + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +void +glmc_mat4_print(mat4 matrix, + FILE * __restrict ostream) { + glm_mat4_print(matrix, ostream); +} + +CGLM_EXPORT +void +glmc_mat3_print(mat3 matrix, + FILE * __restrict ostream) { + glm_mat3_print(matrix, ostream); +} + +CGLM_EXPORT +void +glmc_vec4_print(vec4 vec, + FILE * __restrict ostream) { + glm_vec4_print(vec, ostream); +} + +CGLM_EXPORT +void +glmc_vec3_print(vec3 vec, + FILE * __restrict ostream) { + glm_vec3_print(vec, ostream); +} + +CGLM_EXPORT +void +glmc_versor_print(versor vec, + FILE * __restrict ostream) { + glm_versor_print(vec, ostream); +} diff --git a/libs/cglm/src/ivec2.c b/libs/cglm/src/ivec2.c new file mode 100644 index 0000000..1162c22 --- /dev/null +++ b/libs/cglm/src/ivec2.c @@ -0,0 +1,99 @@ +/* + * 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_ivec2(int * __restrict v, ivec2 dest) { + glm_ivec2(v, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_copy(ivec2 a, ivec2 dest) { + glm_ivec2_copy(a, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_zero(ivec2 v) { + glm_ivec2_zero(v); +} + +CGLM_EXPORT +void +glmc_ivec2_one(ivec2 v) { + glm_ivec2_one(v); +} + +CGLM_EXPORT +void +glmc_ivec2_add(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_add(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_adds(ivec2 v, int s, ivec2 dest) { + glm_ivec2_adds(v, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_sub(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_sub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_subs(ivec2 v, int s, ivec2 dest) { + glm_ivec2_subs(v, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_mul(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_mul(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_scale(ivec2 v, int s, ivec2 dest) { + glm_ivec2_scale(v, s, dest); +} + +CGLM_EXPORT +int +glmc_ivec2_distance2(ivec2 a, ivec2 b) { + return glm_ivec2_distance2(a, b); +} + +CGLM_EXPORT +float +glmc_ivec2_distance(ivec2 a, ivec2 b) { + return glm_ivec2_distance(a, b); +} + +CGLM_EXPORT +void +glmc_ivec2_maxv(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_maxv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_minv(ivec2 a, ivec2 b, ivec2 dest) { + glm_ivec2_minv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec2_clamp(ivec2 v, int minVal, int maxVal) { + glm_ivec2_clamp(v, minVal, maxVal); +} diff --git a/libs/cglm/src/ivec3.c b/libs/cglm/src/ivec3.c new file mode 100644 index 0000000..1e14dd3 --- /dev/null +++ b/libs/cglm/src/ivec3.c @@ -0,0 +1,99 @@ +/* + * 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_ivec3(ivec4 v4, ivec3 dest) { + glm_ivec3(v4, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_copy(ivec3 a, ivec3 dest) { + glm_ivec3_copy(a, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_zero(ivec3 v) { + glm_ivec3_zero(v); +} + +CGLM_EXPORT +void +glmc_ivec3_one(ivec3 v) { + glm_ivec3_one(v); +} + +CGLM_EXPORT +void +glmc_ivec3_add(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_add(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_adds(ivec3 v, int s, ivec3 dest) { + glm_ivec3_adds(v, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_sub(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_sub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_subs(ivec3 v, int s, ivec3 dest) { + glm_ivec3_subs(v, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_mul(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_mul(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_scale(ivec3 v, int s, ivec3 dest) { + glm_ivec3_scale(v, s, dest); +} + +CGLM_EXPORT +int +glmc_ivec3_distance2(ivec3 a, ivec3 b) { + return glm_ivec3_distance2(a, b); +} + +CGLM_EXPORT +float +glmc_ivec3_distance(ivec3 a, ivec3 b) { + return glm_ivec3_distance(a, b); +} + +CGLM_EXPORT +void +glmc_ivec3_maxv(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_maxv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_minv(ivec3 a, ivec3 b, ivec3 dest) { + glm_ivec3_minv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec3_clamp(ivec3 v, int minVal, int maxVal) { + glm_ivec3_clamp(v, minVal, maxVal); +} diff --git a/libs/cglm/src/ivec4.c b/libs/cglm/src/ivec4.c new file mode 100644 index 0000000..ea69042 --- /dev/null +++ b/libs/cglm/src/ivec4.c @@ -0,0 +1,99 @@ +/* + * 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_ivec4(ivec3 v3, int last, ivec4 dest) { + glm_ivec4(v3, last, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_copy(ivec4 a, ivec4 dest) { + glm_ivec4_copy(a, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_zero(ivec4 v) { + glm_ivec4_zero(v); +} + +CGLM_EXPORT +void +glmc_ivec4_one(ivec4 v) { + glm_ivec4_one(v); +} + +CGLM_EXPORT +void +glmc_ivec4_add(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_add(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_adds(ivec4 v, int s, ivec4 dest) { + glm_ivec4_adds(v, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_sub(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_sub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_subs(ivec4 v, int s, ivec4 dest) { + glm_ivec4_subs(v, s, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_mul(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_mul(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_scale(ivec4 v, int s, ivec4 dest) { + glm_ivec4_scale(v, s, dest); +} + +CGLM_EXPORT +int +glmc_ivec4_distance2(ivec4 a, ivec4 b) { + return glm_ivec4_distance2(a, b); +} + +CGLM_EXPORT +float +glmc_ivec4_distance(ivec4 a, ivec4 b) { + return glm_ivec4_distance(a, b); +} + +CGLM_EXPORT +void +glmc_ivec4_maxv(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_maxv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_minv(ivec4 a, ivec4 b, ivec4 dest) { + glm_ivec4_minv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_ivec4_clamp(ivec4 v, int minVal, int maxVal) { + glm_ivec4_clamp(v, minVal, maxVal); +} diff --git a/libs/cglm/src/mat2.c b/libs/cglm/src/mat2.c new file mode 100644 index 0000000..99a282d --- /dev/null +++ b/libs/cglm/src/mat2.c @@ -0,0 +1,99 @@ +/* + * 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_mat2_copy(mat2 mat, mat2 dest) { + glm_mat2_copy(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat2_identity(mat2 mat) { + glm_mat2_identity(mat); +} + +CGLM_EXPORT +void +glmc_mat2_identity_array(mat2 * __restrict mat, size_t count) { + glm_mat2_identity_array(mat, count); +} + +CGLM_EXPORT +void +glmc_mat2_zero(mat2 mat) { + glm_mat2_zero(mat); +} + +CGLM_EXPORT +void +glmc_mat2_mul(mat2 m1, mat2 m2, mat2 dest) { + glm_mat2_mul(m1, m2, dest); +} + +CGLM_EXPORT +void +glmc_mat2_transpose_to(mat2 m, mat2 dest) { + glm_mat2_transpose_to(m, dest); +} + +CGLM_EXPORT +void +glmc_mat2_transpose(mat2 m) { + glm_mat2_transpose(m); +} + +CGLM_EXPORT +void +glmc_mat2_mulv(mat2 m, vec2 v, vec2 dest) { + glm_mat2_mulv(m, v, dest); +} + +CGLM_EXPORT +float +glmc_mat2_trace(mat2 m) { + return glm_mat2_trace(m); +} + +CGLM_EXPORT +void +glmc_mat2_scale(mat2 m, float s) { + glm_mat2_scale(m, s); +} + +CGLM_EXPORT +float +glmc_mat2_det(mat2 mat) { + return glm_mat2_det(mat); +} + +CGLM_EXPORT +void +glmc_mat2_inv(mat2 mat, mat2 dest) { + glm_mat2_inv(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat2_swap_col(mat2 mat, int col1, int col2) { + glm_mat2_swap_col(mat, col1, col2); +} + +CGLM_EXPORT +void +glmc_mat2_swap_row(mat2 mat, int row1, int row2) { + glm_mat2_swap_row(mat, row1, row2); +} + +CGLM_EXPORT +float +glmc_mat2_rmc(vec2 r, mat2 m, vec2 c) { + return glm_mat2_rmc(r, m, c); +} diff --git a/libs/cglm/src/mat3.c b/libs/cglm/src/mat3.c new file mode 100644 index 0000000..1286bd9 --- /dev/null +++ b/libs/cglm/src/mat3.c @@ -0,0 +1,105 @@ +/* + * 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_mat3_copy(mat3 mat, mat3 dest) { + glm_mat3_copy(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat3_identity(mat3 mat) { + glm_mat3_identity(mat); +} + +CGLM_EXPORT +void +glmc_mat3_zero(mat3 mat) { + glm_mat3_zero(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) { + glm_mat3_mul(m1, m2, dest); +} + +CGLM_EXPORT +void +glmc_mat3_transpose_to(mat3 m, mat3 dest) { + glm_mat3_transpose_to(m, dest); +} + +CGLM_EXPORT +void +glmc_mat3_transpose(mat3 m) { + glm_mat3_transpose(m); +} + +CGLM_EXPORT +void +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) { + glm_mat3_quat(m, dest); +} + +CGLM_EXPORT +void +glmc_mat3_scale(mat3 m, float s) { + glm_mat3_scale(m, s); +} + +CGLM_EXPORT +float +glmc_mat3_det(mat3 mat) { + return glm_mat3_det(mat); +} + +CGLM_EXPORT +void +glmc_mat3_inv(mat3 mat, mat3 dest) { + glm_mat3_inv(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat3_swap_col(mat3 mat, int col1, int col2) { + glm_mat3_swap_col(mat, col1, col2); +} + +CGLM_EXPORT +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); +} diff --git a/libs/cglm/src/mat4.c b/libs/cglm/src/mat4.c new file mode 100644 index 0000000..a9f39c6 --- /dev/null +++ b/libs/cglm/src/mat4.c @@ -0,0 +1,165 @@ +/* + * 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_mat4_ucopy(mat4 mat, mat4 dest) { + glm_mat4_copy(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat4_copy(mat4 mat, mat4 dest) { + glm_mat4_copy(mat, dest); +} + +CGLM_EXPORT +void +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_zero(mat4 mat) { + glm_mat4_zero(mat); +} + +CGLM_EXPORT +void +glmc_mat4_pick3(mat4 mat, mat3 dest) { + glm_mat4_pick3(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat4_pick3t(mat4 mat, mat3 dest) { + glm_mat4_pick3t(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat4_ins3(mat3 mat, mat4 dest) { + glm_mat4_ins3(mat, dest); +} + +CGLM_EXPORT +void +glmc_mat4_mul(mat4 m1, mat4 m2, mat4 dest) { + glm_mat4_mul(m1, m2, dest); +} + +CGLM_EXPORT +void +glmc_mat4_mulN(mat4 * __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) { + 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 +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) { + glm_mat4_quat(m, dest); +} + +CGLM_EXPORT +void +glmc_mat4_transpose_to(mat4 m, mat4 dest) { + glm_mat4_transpose_to(m, dest); +} + +CGLM_EXPORT +void +glmc_mat4_transpose(mat4 m) { + glm_mat4_transpose(m); +} + +CGLM_EXPORT +void +glmc_mat4_scale_p(mat4 m, float s) { + glm_mat4_scale_p(m, s); +} + +CGLM_EXPORT +void +glmc_mat4_scale(mat4 m, float s) { + glm_mat4_scale(m, s); +} + +CGLM_EXPORT +float +glmc_mat4_det(mat4 mat) { + return glm_mat4_det(mat); +} + +CGLM_EXPORT +void +glmc_mat4_inv(mat4 mat, mat4 dest) { + glm_mat4_inv(mat, dest); +} + +CGLM_EXPORT +void +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) { + glm_mat4_swap_col(mat, col1, col2); +} + +CGLM_EXPORT +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); +} diff --git a/libs/cglm/src/plane.c b/libs/cglm/src/plane.c new file mode 100644 index 0000000..7ee0c0f --- /dev/null +++ b/libs/cglm/src/plane.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 +void +glmc_plane_normalize(vec4 plane) { + glm_plane_normalize(plane); +} diff --git a/libs/cglm/src/project.c b/libs/cglm/src/project.c new file mode 100644 index 0000000..3e09ac6 --- /dev/null +++ b/libs/cglm/src/project.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 +void +glmc_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { + glm_unprojecti(pos, invMat, vp, dest); +} + +CGLM_EXPORT +void +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); +} + +CGLM_EXPORT +void +glmc_pickmatrix(vec2 center, vec2 size, vec4 vp, mat4 dest) { + glm_pickmatrix(center, size, vp, dest); +} diff --git a/libs/cglm/src/quat.c b/libs/cglm/src/quat.c new file mode 100644 index 0000000..415269a --- /dev/null +++ b/libs/cglm/src/quat.c @@ -0,0 +1,231 @@ +/* + * 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_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) { + glm_quat_init(q, x, y, z, w); +} + +CGLM_EXPORT +void +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 axis) { + glm_quatv(q, angle, axis); +} + +CGLM_EXPORT +void +glmc_quat_copy(versor q, versor dest) { + glm_quat_copy(q, dest); +} + +CGLM_EXPORT +void +glmc_quat_from_vecs(vec3 a, vec3 b, versor dest) { + glm_quat_from_vecs(a, b, dest); +} + +CGLM_EXPORT +float +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); +} + +CGLM_EXPORT +float +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, vec3 dest) { + glm_quat_axis(q, dest); +} + +CGLM_EXPORT +void +glmc_quat_mul(versor p, versor q, versor dest) { + glm_quat_mul(p, q, dest); +} + +CGLM_EXPORT +void +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) { + glm_quat_mat3(q, dest); +} + +CGLM_EXPORT +void +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_lerpc(versor from, versor to, float t, versor dest) { + glm_quat_lerpc(from, to, t, dest); +} + +CGLM_EXPORT +void +glmc_quat_nlerp(versor from, versor to, float t, versor dest) { + glm_quat_nlerp(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 up, versor dest) { + glm_quat_for(dir, up, dest); +} + +CGLM_EXPORT +void +glmc_quat_forp(vec3 from, vec3 to, vec3 up, versor dest) { + glm_quat_forp(from, to, 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); +} + +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); +} diff --git a/libs/cglm/src/ray.c b/libs/cglm/src/ray.c new file mode 100644 index 0000000..973c059 --- /dev/null +++ b/libs/cglm/src/ray.c @@ -0,0 +1,13 @@ +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +bool +glmc_ray_triangle(vec3 origin, + vec3 direction, + vec3 v0, + vec3 v1, + vec3 v2, + float *d) { + return glm_ray_triangle(origin, direction, v0, v1, v2, d); +} diff --git a/libs/cglm/src/sphere.c b/libs/cglm/src/sphere.c new file mode 100644 index 0000000..003ef87 --- /dev/null +++ b/libs/cglm/src/sphere.c @@ -0,0 +1,39 @@ +/* + * 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); +} + +CGLM_EXPORT +bool +glmc_sphere_point(vec4 s, vec3 point) { + return glm_sphere_point(s, point); +} diff --git a/libs/cglm/src/swift/empty.c b/libs/cglm/src/swift/empty.c new file mode 100644 index 0000000..7c27d40 --- /dev/null +++ b/libs/cglm/src/swift/empty.c @@ -0,0 +1 @@ +// This empty file is needed to trick swiftpm to build the header-only version of cglm as swiftpm itself does not support C targets that have no source code files \ No newline at end of file diff --git a/libs/cglm/src/vec2.c b/libs/cglm/src/vec2.c new file mode 100644 index 0000000..a75f3f0 --- /dev/null +++ b/libs/cglm/src/vec2.c @@ -0,0 +1,231 @@ +/* + * 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_vec2(float * __restrict v, vec2 dest) { + glm_vec2(v, dest); +} + +CGLM_EXPORT +void +glmc_vec2_copy(vec2 a, vec2 dest) { + glm_vec2_copy(a, dest); +} + +CGLM_EXPORT +void +glmc_vec2_zero(vec2 v) { + glm_vec2_zero(v); +} + +CGLM_EXPORT +void +glmc_vec2_one(vec2 v) { + glm_vec2_one(v); +} + +CGLM_EXPORT +float +glmc_vec2_dot(vec2 a, vec2 b) { + return glm_vec2_dot(a, b); +} + +CGLM_EXPORT +float +glmc_vec2_cross(vec2 a, vec2 b) { + return glm_vec2_cross(a, b); +} + +CGLM_EXPORT +float +glmc_vec2_norm2(vec2 v) { + return glm_vec2_norm2(v); +} + +CGLM_EXPORT +float +glmc_vec2_norm(vec2 v) { + return glm_vec2_norm(v); +} + +CGLM_EXPORT +void +glmc_vec2_add(vec2 a, vec2 b, vec2 dest) { + glm_vec2_add(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_adds(vec2 v, float s, vec2 dest) { + glm_vec2_adds(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec2_sub(vec2 a, vec2 b, vec2 dest) { + glm_vec2_sub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_subs(vec2 v, float s, vec2 dest) { + glm_vec2_subs(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec2_mul(vec2 a, vec2 b, vec2 dest) { + glm_vec2_mul(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_scale(vec2 v, float s, vec2 dest) { + glm_vec2_scale(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec2_scale_as(vec2 v, float s, vec2 dest) { + glm_vec2_scale_as(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec2_div(vec2 a, vec2 b, vec2 dest) { + glm_vec2_div(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_divs(vec2 v, float s, vec2 dest) { + glm_vec2_divs(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec2_addadd(vec2 a, vec2 b, vec2 dest) { + glm_vec2_addadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_subadd(vec2 a, vec2 b, vec2 dest) { + glm_vec2_subadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_muladd(vec2 a, vec2 b, vec2 dest) { + glm_vec2_muladd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_muladds(vec2 a, float s, vec2 dest) { + glm_vec2_muladds(a, s, dest); +} + +CGLM_EXPORT +void +glmc_vec2_maxadd(vec2 a, vec2 b, vec2 dest) { + glm_vec2_maxadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_minadd(vec2 a, vec2 b, vec2 dest) { + glm_vec2_minadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_negate_to(vec2 v, vec2 dest) { + glm_vec2_negate_to(v, dest); +} + +CGLM_EXPORT +void +glmc_vec2_negate(vec2 v) { + glm_vec2_negate(v); +} + +CGLM_EXPORT +void +glmc_vec2_normalize(vec2 v) { + glm_vec2_normalize(v); +} + +CGLM_EXPORT +void +glmc_vec2_normalize_to(vec2 v, vec2 dest) { + glm_vec2_normalize_to(v, dest); +} + +CGLM_EXPORT +void +glmc_vec2_rotate(vec2 v, float angle, vec2 dest) { + glm_vec2_rotate(v, angle, dest); +} + +CGLM_EXPORT +float +glmc_vec2_distance2(vec2 a, vec2 b) { + return glm_vec2_distance2(a, b); +} + +CGLM_EXPORT +float +glmc_vec2_distance(vec2 a, vec2 b) { + return glm_vec2_distance(a, b); +} + +CGLM_EXPORT +void +glmc_vec2_maxv(vec2 a, vec2 b, vec2 dest) { + glm_vec2_maxv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_minv(vec2 a, vec2 b, vec2 dest) { + glm_vec2_minv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_clamp(vec2 v, float minval, float maxval) { + glm_vec2_clamp(v, minval, maxval); +} + +CGLM_EXPORT +void +glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest) { + glm_vec2_lerp(from, to, t, dest); +} + +CGLM_EXPORT +void +glmc_vec2_complex_mul(vec2 a, vec2 b, vec2 dest) { + glm_vec2_complex_mul(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_complex_div(vec2 a, vec2 b, vec2 dest) { + glm_vec2_complex_div(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec2_complex_conjugate(vec2 a, vec2 dest) { + glm_vec2_complex_conjugate(a, dest); +} diff --git a/libs/cglm/src/vec3.c b/libs/cglm/src/vec3.c new file mode 100644 index 0000000..a09a2ef --- /dev/null +++ b/libs/cglm/src/vec3.c @@ -0,0 +1,419 @@ +/* + * 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_vec3(vec4 v4, vec3 dest) { + glm_vec3(v4, dest); +} + +CGLM_EXPORT +void +glmc_vec3_copy(vec3 a, vec3 dest) { + glm_vec3_copy(a, dest); +} + +CGLM_EXPORT +void +glmc_vec3_zero(vec3 v) { + glm_vec3_zero(v); +} + +CGLM_EXPORT +void +glmc_vec3_one(vec3 v) { + glm_vec3_one(v); +} + +CGLM_EXPORT +float +glmc_vec3_dot(vec3 a, vec3 b) { + return glm_vec3_dot(a, b); +} + +CGLM_EXPORT +void +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 +float +glmc_vec3_norm(vec3 v) { + return glm_vec3_norm(v); +} + +CGLM_EXPORT +void +glmc_vec3_normalize_to(vec3 v, vec3 dest) { + glm_vec3_normalize_to(v, dest); +} + +CGLM_EXPORT +void +glmc_vec3_normalize(vec3 v) { + glm_vec3_normalize(v); +} + +CGLM_EXPORT +float +glmc_vec3_norm2(vec3 v) { + return glm_vec3_norm2(v); +} + +CGLM_EXPORT +float +glmc_vec3_norm_one(vec3 v) { + return glm_vec3_norm_one(v); +} + +CGLM_EXPORT +float +glmc_vec3_norm_inf(vec3 v) { + return glm_vec3_norm_inf(v); +} + +CGLM_EXPORT +void +glmc_vec3_add(vec3 a, vec3 b, vec3 dest) { + glm_vec3_add(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec3_adds(vec3 v, float s, vec3 dest) { + glm_vec3_adds(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec3_sub(vec3 a, vec3 b, vec3 dest) { + glm_vec3_sub(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec3_subs(vec3 v, float s, vec3 dest) { + glm_vec3_subs(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec3_mul(vec3 a, vec3 b, vec3 d) { + glm_vec3_mul(a, b, d); +} + +CGLM_EXPORT +void +glmc_vec3_scale(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) { + glm_vec3_scale_as(v, s, dest); +} + +CGLM_EXPORT +void +glmc_vec3_div(vec3 a, vec3 b, vec3 dest) { + glm_vec3_div(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec3_divs(vec3 a, float s, vec3 dest) { + glm_vec3_divs(a, s, dest); +} + +CGLM_EXPORT +void +glmc_vec3_addadd(vec3 a, vec3 b, vec3 dest) { + glm_vec3_addadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec3_subadd(vec3 a, vec3 b, vec3 dest) { + glm_vec3_subadd(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec3_muladd(vec3 a, vec3 b, vec3 dest) { + glm_vec3_muladd(a, b, dest); +} + +CGLM_EXPORT +void +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) { + glm_vec3_negate(v); +} + +CGLM_EXPORT +void +glmc_vec3_negate_to(vec3 v, vec3 dest) { + glm_vec3_negate_to(v, dest); +} + +CGLM_EXPORT +float +glmc_vec3_angle(vec3 a, vec3 b) { + return glm_vec3_angle(a, b); +} + +CGLM_EXPORT +void +glmc_vec3_rotate(vec3 v, float angle, vec3 axis) { + glm_vec3_rotate(v, angle, axis); +} + +CGLM_EXPORT +void +glmc_vec3_rotate_m4(mat4 m, vec3 v, vec3 dest) { + glm_vec3_rotate_m4(m, v, dest); +} + +CGLM_EXPORT +void +glmc_vec3_rotate_m3(mat3 m, vec3 v, vec3 dest) { + glm_vec3_rotate_m3(m, v, dest); +} + +CGLM_EXPORT +void +glmc_vec3_proj(vec3 a, vec3 b, vec3 dest) { + glm_vec3_proj(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec3_center(vec3 a, vec3 b, vec3 dest) { + glm_vec3_center(a, b, dest); +} + +CGLM_EXPORT +float +glmc_vec3_distance(vec3 a, vec3 b) { + return glm_vec3_distance(a, b); +} + +CGLM_EXPORT +float +glmc_vec3_distance2(vec3 a, vec3 b) { + return glm_vec3_distance2(a, b); +} + +CGLM_EXPORT +void +glmc_vec3_maxv(vec3 a, vec3 b, vec3 dest) { + glm_vec3_maxv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec3_minv(vec3 a, vec3 b, vec3 dest) { + glm_vec3_minv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec3_clamp(vec3 v, float minVal, float maxVal) { + glm_vec3_clamp(v, minVal, maxVal); +} + +CGLM_EXPORT +void +glmc_vec3_ortho(vec3 v, vec3 dest) { + glm_vec3_ortho(v, dest); +} + +CGLM_EXPORT +void +glmc_vec3_lerp(vec3 from, vec3 to, float t, vec3 dest) { + glm_vec3_lerp(from, to, t, dest); +} + +CGLM_EXPORT +void +glmc_vec3_lerpc(vec3 from, vec3 to, float t, vec3 dest) { + glm_vec3_lerpc(from, to, t, dest); +} + +CGLM_EXPORT +void +glmc_vec3_step_uni(float edge, vec3 x, vec3 dest) { + glm_vec3_step_uni(edge, x, dest); +} + +CGLM_EXPORT +void +glmc_vec3_step(vec3 edge, vec3 x, vec3 dest) { + glm_vec3_step(edge, x, dest); +} + +CGLM_EXPORT +void +glmc_vec3_smoothstep_uni(float edge0, float edge1, vec3 x, vec3 dest) { + glm_vec3_smoothstep_uni(edge0, edge1, x, dest); +} + +CGLM_EXPORT +void +glmc_vec3_smoothstep(vec3 edge0, vec3 edge1, vec3 x, vec3 dest) { + glm_vec3_smoothstep(edge0, edge1, x, dest); +} + +CGLM_EXPORT +void +glmc_vec3_smoothinterp(vec3 from, vec3 to, float t, vec3 dest) { + glm_vec3_smoothinterp(from, to, t, dest); +} + +CGLM_EXPORT +void +glmc_vec3_smoothinterpc(vec3 from, vec3 to, float t, vec3 dest) { + glm_vec3_smoothinterpc(from, to, t, dest); +} + +/* ext */ + +CGLM_EXPORT +void +glmc_vec3_mulv(vec3 a, vec3 b, vec3 d) { + glm_vec3_mulv(a, b, d); +} + +CGLM_EXPORT +void +glmc_vec3_broadcast(float val, vec3 d) { + glm_vec3_broadcast(val, d); +} + +CGLM_EXPORT +void +glmc_vec3_fill(vec3 v, float val) { + glm_vec3_fill(v, val); +} + +CGLM_EXPORT +bool +glmc_vec3_eq(vec3 v, float val) { + return glm_vec3_eq(v, val); +} + +CGLM_EXPORT +bool +glmc_vec3_eq_eps(vec3 v, float val) { + return glm_vec3_eq_eps(v, val); +} + +CGLM_EXPORT +bool +glmc_vec3_eq_all(vec3 v) { + return glm_vec3_eq_all(v); +} + +CGLM_EXPORT +bool +glmc_vec3_eqv(vec3 a, vec3 b) { + return glm_vec3_eqv(a, b); +} + +CGLM_EXPORT +bool +glmc_vec3_eqv_eps(vec3 a, vec3 b) { + return glm_vec3_eqv_eps(a, b); +} + +CGLM_EXPORT +float +glmc_vec3_max(vec3 v) { + return glm_vec3_max(v); +} + +CGLM_EXPORT +float +glmc_vec3_min(vec3 v) { + return glm_vec3_min(v); +} + +CGLM_EXPORT +bool +glmc_vec3_isnan(vec3 v) { + return glm_vec3_isnan(v); +} + +CGLM_EXPORT +bool +glmc_vec3_isinf(vec3 v) { + return glm_vec3_isinf(v); +} + +CGLM_EXPORT +bool +glmc_vec3_isvalid(vec3 v) { + return glm_vec3_isvalid(v); +} + +CGLM_EXPORT +void +glmc_vec3_sign(vec3 v, vec3 dest) { + glm_vec3_sign(v, dest); +} + +CGLM_EXPORT +void +glmc_vec3_abs(vec3 v, vec3 dest) { + glm_vec3_abs(v, dest); +} + +CGLM_EXPORT +void +glmc_vec3_fract(vec3 v, vec3 dest) { + glm_vec3_fract(v, dest); +} + +CGLM_EXPORT +float +glmc_vec3_hadd(vec3 v) { + return glm_vec3_hadd(v); +} + +CGLM_EXPORT +void +glmc_vec3_sqrt(vec3 v, vec3 dest) { + glm_vec3_sqrt(v, dest); +} diff --git a/libs/cglm/src/vec4.c b/libs/cglm/src/vec4.c new file mode 100644 index 0000000..60c3a25 --- /dev/null +++ b/libs/cglm/src/vec4.c @@ -0,0 +1,383 @@ +/* + * 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_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 v, vec3 dest) { + glm_vec4_copy3(v, dest); +} + +CGLM_EXPORT +void +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) { + return glm_vec4_dot(a, b); +} + +CGLM_EXPORT +float +glmc_vec4_norm(vec4 v) { + return glm_vec4_norm(v); +} + +CGLM_EXPORT +void +glmc_vec4_normalize_to(vec4 v, vec4 dest) { + glm_vec4_normalize_to(v, dest); +} + +CGLM_EXPORT +void +glmc_vec4_normalize(vec4 v) { + glm_vec4_normalize(v); +} + +CGLM_EXPORT +float +glmc_vec4_norm2(vec4 v) { + return glm_vec4_norm2(v); +} + +CGLM_EXPORT +float +glmc_vec4_norm_one(vec4 v) { + return glm_vec4_norm_one(v); +} + +CGLM_EXPORT +float +glmc_vec4_norm_inf(vec4 v) { + return glm_vec4_norm_inf(v); +} + +CGLM_EXPORT +void +glmc_vec4_add(vec4 a, vec4 b, vec4 dest) { + glm_vec4_add(a, b, dest); +} + +CGLM_EXPORT +void +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 +void +glmc_vec4_scale(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) { + 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_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_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) { + glm_vec4_negate(v); +} + +CGLM_EXPORT +void +glmc_vec4_negate_to(vec4 v, vec4 dest) { + glm_vec4_negate_to(v, dest); +} + +CGLM_EXPORT +float +glmc_vec4_distance(vec4 a, vec4 b) { + return glm_vec4_distance(a, b); +} + +CGLM_EXPORT +float +glmc_vec4_distance2(vec4 a, vec4 b) { + return glm_vec4_distance2(a, b); +} + +CGLM_EXPORT +void +glmc_vec4_maxv(vec4 a, vec4 b, vec4 dest) { + glm_vec4_maxv(a, b, dest); +} + +CGLM_EXPORT +void +glmc_vec4_minv(vec4 a, vec4 b, vec4 dest) { + glm_vec4_minv(a, b, dest); +} + +CGLM_EXPORT +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); +} + +CGLM_EXPORT +void +glmc_vec4_lerpc(vec4 from, vec4 to, float t, vec4 dest) { + glm_vec4_lerpc(from, to, t, dest); +} + +CGLM_EXPORT +void +glmc_vec4_step_uni(float edge, vec4 x, vec4 dest) { + glm_vec4_step_uni(edge, x, dest); +} + +CGLM_EXPORT +void +glmc_vec4_step(vec4 edge, vec4 x, vec4 dest) { + glm_vec4_step(edge, x, dest); +} + +CGLM_EXPORT +void +glmc_vec4_smoothstep_uni(float edge0, float edge1, vec4 x, vec4 dest) { + glm_vec4_smoothstep_uni(edge0, edge1, x, dest); +} + +CGLM_EXPORT +void +glmc_vec4_smoothstep(vec4 edge0, vec4 edge1, vec4 x, vec4 dest) { + glm_vec4_smoothstep(edge0, edge1, x, dest); +} + +CGLM_EXPORT +void +glmc_vec4_smoothinterp(vec4 from, vec4 to, float t, vec4 dest) { + glm_vec4_smoothinterp(from, to, t, dest); +} + +CGLM_EXPORT +void +glmc_vec4_smoothinterpc(vec4 from, vec4 to, float t, vec4 dest) { + glm_vec4_smoothinterpc(from, to, t, dest); +} + +CGLM_EXPORT +void +glmc_vec4_cubic(float s, vec4 dest) { + glm_vec4_cubic(s, 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 +void +glmc_vec4_fill(vec4 v, float val) { + glm_vec4_fill(v, val); +} + +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 a, vec4 b) { + return glm_vec4_eqv(a, b); +} + +CGLM_EXPORT +bool +glmc_vec4_eqv_eps(vec4 a, vec4 b) { + return glm_vec4_eqv_eps(a, b); +} + +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_abs(vec4 v, vec4 dest) { + glm_vec4_abs(v, dest); +} + +CGLM_EXPORT +void +glmc_vec4_fract(vec4 v, vec4 dest) { + glm_vec4_fract(v, dest); +} + +CGLM_EXPORT +float +glmc_vec4_hadd(vec4 v) { + return glm_vec4_hadd(v); +} + +CGLM_EXPORT +void +glmc_vec4_sqrt(vec4 v, vec4 dest) { + glm_vec4_sqrt(v, dest); +} diff --git a/libs/cglm/test/CMakeLists.txt b/libs/cglm/test/CMakeLists.txt new file mode 100644 index 0000000..26fef9c --- /dev/null +++ b/libs/cglm/test/CMakeLists.txt @@ -0,0 +1,48 @@ +cmake_minimum_required(VERSION 3.8.2) + +# List all files containing tests. (Change as needed) +set(TESTFILES + runner.c + src/test_euler.c + src/test_bezier.c + src/test_cam.c + src/test_cam_lh_zo.c + src/test_cam_rh_zo.c + src/test_cam_lh_no.c + src/test_cam_rh_no.c + src/test_struct.c + src/test_clamp.c + src/test_common.c + src/tests.c + ) + +set(TEST_MAIN tests) +set(TEST_RUNNER_PARAMS "") + +add_executable(${TEST_MAIN} ${TESTFILES}) +target_compile_definitions(${TEST_MAIN} PRIVATE CGLM_DEFINE_PRINTS=1) + +if(NOT MSVC) + target_link_libraries(${TEST_MAIN} PRIVATE m) +endif() + +target_link_libraries(${TEST_MAIN} PRIVATE cglm) +target_include_directories(${TEST_MAIN} PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/include + ${CMAKE_CURRENT_LIST_DIR}/src + ) + +set_target_properties(${TEST_MAIN} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) + +if(LDFLAGS) + target_compile_options(${TEST_MAIN} PRIVATE ${LDFLAGS}) +endif() + +add_test( + NAME cglm.${TEST_MAIN} + COMMAND ${TEST_MAIN} ${TEST_RUNNER_PARAMS}) + +add_custom_target(check + make + COMMAND ${CMAKE_CTEST_COMMAND} -V + DEPENDS cglm) diff --git a/libs/cglm/test/include/common.h b/libs/cglm/test/include/common.h new file mode 100644 index 0000000..2eb2e83 --- /dev/null +++ b/libs/cglm/test/include/common.h @@ -0,0 +1,159 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef tests_common_h +#define tests_common_h + +#ifndef _USE_MATH_DEFINES +# define _USE_MATH_DEFINES /* for windows */ +#endif + +#ifndef _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS /* for windows */ +#endif + +#ifndef _GNU_SOURCE +# define _GNU_SOURCE /* for drand48() */ +#endif + +#ifndef CGLM_CLIPSPACE_INCLUDE_ALL +# define CGLM_CLIPSPACE_INCLUDE_ALL +#endif + +#include +#include +#include + +#include +#include +#include + +typedef struct test_status_t { + const char *msg; + int status; +} test_status_t; + +typedef test_status_t (*fntest)(void); + +typedef struct test_entry_t { + char *name; + fntest entry; + int ret; + int show_output; +} test_entry_t; + +#ifndef GLM_TESTS_NO_COLORFUL_OUTPUT + +#define RESET "\033[0m" +#define BLACK "\033[30m" /* Black */ +#define RED "\033[31m" /* Red */ +#define GREEN "\033[32m" /* Green */ +#define YELLOW "\033[33m" /* Yellow */ +#define BLUE "\033[34m" /* Blue */ +#define MAGENTA "\033[35m" /* Magenta */ +#define CYAN "\033[36m" /* Cyan */ +#define WHITE "\033[37m" /* White */ +#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ +#define BOLDRED "\033[1m\033[31m" /* Bold Red */ +#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ +#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ +#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ +#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ +#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ +#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ + +#else + +#define RESET +#define BLACK +#define RED +#define GREEN +#define YELLOW +#define BLUE +#define MAGENTA +#define CYAN +#define WHITE +#define BOLDBLACK +#define BOLDRED +#define BOLDGREEN +#define BOLDYELLOW +#define BOLDBLUE +#define BOLDMAGENTA +#define BOLDCYAN +#define BOLDWHITE + +#endif + +#define TEST_DECLARE(FUN) test_status_t test_ ## FUN(void); +#define TEST_ENTRY(FUN) { #FUN, test_ ## FUN, 0, 0 }, +#define TEST_LIST static test_entry_t tests[] = + +/* __VA_ARGS__ workaround for MSVC: https://stackoverflow.com/a/5134656 */ +#define EXPAND(x) x + +#define TEST_OK 1 +#define TEST_SUCCESS return (test_status_t){NULL, TEST_OK}; + +#define TEST_IMPL_ARG1(FUN) \ + test_status_t test_ ## FUN (void); \ + test_status_t test_ ## FUN() + +#define TEST_IMPL_ARG2(PREFIX, FUN) TEST_IMPL_ARG1(PREFIX ## FUN) +#define TEST_IMPL_ARG3(arg1, arg2, arg3, ...) arg3 + +#define TEST_IMPL_CHOOSER(...) \ + EXPAND(TEST_IMPL_ARG3(__VA_ARGS__, TEST_IMPL_ARG2, TEST_IMPL_ARG1)) + +#define TEST_IMPL(...) EXPAND(TEST_IMPL_CHOOSER(__VA_ARGS__)(__VA_ARGS__)) + +#define ASSERT_EXT(expr, msg) \ + if (!(expr)) { \ + fprintf(stderr, \ + RED " assert fail" RESET \ + " in " BOLDCYAN "%s " RESET \ + "on " BOLDMAGENTA "line %d" RESET \ + " : " BOLDWHITE " ASSERT(%s)\n" RESET, \ + __FILE__, \ + __LINE__, \ + #expr); \ + return (test_status_t){msg, 0}; \ + } + +#define ASSERT_ARG1(expr) ASSERT_EXT(expr, NULL) +#define ASSERT_ARG2(expr, msg) ASSERT_EXT(expr, msg) +#define ASSERT_ARG3(arg1, arg2, arg3, ...) arg3 + +#define ASSERT_CHOOSER(...) ASSERT_ARG3(__VA_ARGS__, ASSERT_ARG2, ASSERT_ARG1) +#define ASSERT(...) do { ASSERT_CHOOSER(__VA_ARGS__)(__VA_ARGS__) } while(0); +#define ASSERTIFY(expr) do { \ + test_status_t ts; \ + ts = expr; \ + if (ts.status != TEST_OK) { \ + fprintf(stderr, \ + RED " assert fail" RESET \ + " in " BOLDCYAN "%s " RESET \ + "on " BOLDMAGENTA "line %d" RESET \ + " : " BOLDWHITE " ASSERTIFY(%s)\n" RESET, \ + __FILE__, \ + __LINE__, \ + #expr); \ + return (test_status_t){ts.msg, 0}; \ + } \ + } while(0); + +#if defined(_WIN32) +# define drand48() ((float)(rand() / (RAND_MAX + 1.0))) +# define OK_TEXT "ok:" +# define FAIL_TEXT "fail:" +# define FINAL_TEXT "^_^" +#else +# define OK_TEXT "✔︎" +# define FAIL_TEXT "𐄂" +# define FINAL_TEXT "🎉" +#endif + +#endif /* common_h */ diff --git a/libs/cglm/test/runner.c b/libs/cglm/test/runner.c new file mode 100644 index 0000000..e74d5e7 --- /dev/null +++ b/libs/cglm/test/runner.c @@ -0,0 +1,98 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "include/common.h" +#include "tests.h" + +#include +#include +#include + +int +main(int argc, const char * argv[]) { + test_entry_t *entry; + test_status_t st; + int32_t i, count, passed, failed, maxlen; + double start, end, elapsed, total; + (void)argc; + (void)argv; + + passed = failed = maxlen = 0; + total = 0.0; + count = sizeof(tests) / sizeof(tests[0]); + + fprintf(stderr, CYAN "\nWelcome to cglm tests\n\n" RESET); + + srand((unsigned int)time(NULL)); + + for (i = 0; i < count; i++) { + int32_t len; + + entry = tests + i; + len = (int32_t)strlen(entry->name); + + maxlen = GLM_MAX(maxlen, len); + } + + maxlen += 5; + + fprintf(stderr, + BOLDWHITE " %-*s %-*s\n", + maxlen, "Test Name", maxlen, "Elapsed Time"); + + for (i = 0; i < count; i++) { + entry = tests + i; + start = clock(); + st = entry->entry(); + end = clock(); + elapsed = (end - start) / CLOCKS_PER_SEC; + total += elapsed; + + if (!st.status) { + fprintf(stderr, + BOLDRED " " FAIL_TEXT BOLDWHITE " %s " RESET, entry->name); + if (st.msg) { + fprintf(stderr, + YELLOW "- %s" RESET, + st.msg); + } + + fprintf(stderr, "\n"); + + failed++; + } else { + fprintf(stderr, GREEN " " OK_TEXT RESET " %-*s ", maxlen, entry->name); + + if (elapsed > 0.01) + fprintf(stderr, YELLOW "%.2fs", elapsed); + else + fprintf(stderr, "0"); + + fprintf(stderr, "\n" RESET); + passed++; + } + } + + if (failed == 0) { + fprintf(stderr, + BOLDGREEN "\n All tests passed " FINAL_TEXT "\n" RESET); + } + + fprintf(stderr, + CYAN "\ncglm test results (%0.2fs):\n" RESET + "--------------------------\n" + + MAGENTA "%d" RESET " tests ran, " + GREEN "%d" RESET " passed, " + RED "%d" RESET " failed\n\n" RESET, + total, + count, + passed, + failed); + + return failed; +} diff --git a/libs/cglm/test/src/test_affine.h b/libs/cglm/test/src/test_affine.h new file mode 100644 index 0000000..2199a43 --- /dev/null +++ b/libs/cglm/test/src/test_affine.h @@ -0,0 +1,634 @@ +/* + * 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" + +TEST_IMPL(GLM_PREFIX, translate) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(translate)(m1, (vec3){13.0f, 11.0f, 7.0f}); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 14.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 10.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(translate)(m1, (vec3){1.0f, -1.0f, -5.0f}); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 12.0f)) + ASSERT(test_eq(v2[2], 5.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate_to) { + mat4 m1, m2; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(translate_to)(m1, (vec3){13.0f, 11.0f, 7.0f}, m2); + glm_mat4_mulv(m2, v1, v2); + + ASSERT(test_eq(v2[0], 14.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 10.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(translate_to)(m1, (vec3){1.0f, -1.0f, -5.0f}, m2); + glm_mat4_mulv(m2, v2, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 12.0f)) + ASSERT(test_eq(v2[2], 5.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate_x) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(translate_x)(m1, 13.0f); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 14.0f)) + ASSERT(test_eq(v2[1], 2.0f)) + ASSERT(test_eq(v2[2], 3.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(translate_x)(m1, -1.0f); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], 2.0f)) + ASSERT(test_eq(v2[2], 3.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate_y) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(translate_y)(m1, 11.0f); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 3.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(translate_y)(m1, -1.0f); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 12.0f)) + ASSERT(test_eq(v2[2], 3.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate_z) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(translate_z)(m1, 7.0f); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 2.0f)) + ASSERT(test_eq(v2[2], 10.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(translate_z)(m1, -5.0f); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 2.0f)) + ASSERT(test_eq(v2[2], 5.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate_make) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(translate_make)(m1, (vec3){13.0f, 11.0f, 7.0f}); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 14.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 10.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(translate_make)(m1, (vec3){1.0f, -1.0f, -5.0f}); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 12.0f)) + ASSERT(test_eq(v2[2], 5.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale_to) { + mat4 m1, m2; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(scale_to)(m1, (vec3){13.0f, 11.0f, 7.0f}, m2); + glm_mat4_mulv(m2, v1, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], 22.0f)) + ASSERT(test_eq(v2[2], 21.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(scale_to)(m1, (vec3){1.0f, -1.0f, -5.0f}, m2); + glm_mat4_mulv(m2, v2, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], -22.0f)) + ASSERT(test_eq(v2[2], -105.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale_make) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + GLM(scale_make)(m1, (vec3){13.0f, 11.0f, 7.0f}); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], 22.0f)) + ASSERT(test_eq(v2[2], 21.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + GLM(scale_make)(m1, (vec3){1.0f, -1.0f, -5.0f}); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], -22.0f)) + ASSERT(test_eq(v2[2], -105.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(scale)(m1, (vec3){13.0f, 11.0f, 7.0f}); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], 22.0f)) + ASSERT(test_eq(v2[2], 21.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(scale)(m1, (vec3){1.0f, -1.0f, -5.0f}); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], -22.0f)) + ASSERT(test_eq(v2[2], -105.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale_uni) { + mat4 m1; + vec4 v1 = {1.0f, 2.0f, 3.0f, 1.0f}, v2; + + glm_mat4_identity(m1); + GLM(scale_uni)(m1, 13.0f); + glm_mat4_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 13.0f)) + ASSERT(test_eq(v2[1], 26.0f)) + ASSERT(test_eq(v2[2], 39.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + glm_mat4_identity(m1); + GLM(scale_uni)(m1, -5.0f); + glm_mat4_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], -65.0f)) + ASSERT(test_eq(v2[1], -130.0f)) + ASSERT(test_eq(v2[2], -195.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate_x) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {0.0f, 1.0f, 0.0f, 1.0f}, v2 = {0.0f, 1.0f, 0.0f, 1.0f}; + + GLM(rotate_x)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate_x)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate_x)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate_y) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}, v2 = {1.0f, 0.0f, 0.0f, 1.0f}; + + GLM(rotate_y)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate_y)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate_y)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate_z) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {0.0f, 1.0f, 0.0f, 1.0f}, v2 = {0.0f, 1.0f, 0.0f, 1.0f}; + + GLM(rotate_z)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate_z)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate_z)(m1, GLM_PI_2f, m1); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate_make) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + /* rotate X around Y = -Z */ + GLM(rotate_make)(m1, GLM_PI_2f, GLM_YUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + /* rotate -Z around X = Y */ + GLM(rotate_make)(m1, GLM_PI_2f, GLM_XUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate Y around X = +Z */ + GLM(rotate_make)(m1, GLM_PI_2f, GLM_XUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT, m2 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + /* 360 deg */ + glm_rotate(m1, GLM_PI_2f, GLM_YUP); + glm_rotate(m1, GLM_PI_2f, GLM_YUP); + glm_rotate(m1, GLM_PI_2f, GLM_YUP); + glm_rotate(m1, GLM_PI_2f, GLM_YUP); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + + /* rotate X around Y = -Z */ + GLM(rotate)(m1, GLM_PI_2f, GLM_YUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + glm_mat4_identity(m1); + + /* rotate -Z around X = Y */ + GLM(rotate)(m1, GLM_PI_2f, GLM_XUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + glm_mat4_identity(m1); + + /* rotate Y around X = +Z */ + GLM(rotate)(m1, GLM_PI_2f, GLM_XUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate_at) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + GLM(rotate_at)(m1, (vec3){0.5f, 0.0f, 0.0f}, GLM_PI_2f, GLM_YUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.5f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -0.5f)) + + glm_mat4_identity(m1); + + GLM(rotate_at)(m1, GLM_VEC3_ZERO, GLM_PI_2f, GLM_ZUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.5f)) + ASSERT(test_eq(v1[2], -0.5f)) + + glm_mat4_identity(m1); + + v1[0] = 1.0f; + v1[1] = 1.0f; + v1[2] = 1.0f; + + GLM(rotate_at)(m1, GLM_VEC3_ZERO, GLM_PI_2f, GLM_XUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate_atm) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + GLM(rotate_atm)(m1, (vec3){0.5f, 0.0f, 0.0f}, GLM_PI_2f, GLM_YUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.5f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -0.5f)) + + GLM(rotate_atm)(m1, GLM_VEC3_ZERO, GLM_PI_2f, GLM_ZUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.5f)) + ASSERT(test_eq(v1[2], -0.5f)) + + v1[0] = 1.0f; + v1[1] = 1.0f; + v1[2] = 1.0f; + + GLM(rotate_atm)(m1, GLM_VEC3_ZERO, GLM_PI_2f, GLM_XUP); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, decompose_scalev) { + mat4 m1; + vec3 s1; + + GLM(scale_make)(m1, (vec3){7.0f, 8.0f, 9.0f}); + GLM(decompose_scalev)(m1, s1); + + ASSERT(test_eq(s1[0], 7.0f)) + ASSERT(test_eq(s1[1], 8.0f)) + ASSERT(test_eq(s1[2], 9.0f)) + + GLM(scale)(m1, (vec3){7.0f, 8.0f, 9.0f}); + GLM(decompose_scalev)(m1, s1); + + ASSERT(test_eq(s1[0], 49.0f)) + ASSERT(test_eq(s1[1], 64.0f)) + ASSERT(test_eq(s1[2], 81.0f)) + + glm_rotate(m1, GLM_PI_4f, (vec3){23.0f, 45.0f, 66.0f}); + ASSERT(test_eq(s1[0], 49.0f)) + ASSERT(test_eq(s1[1], 64.0f)) + ASSERT(test_eq(s1[2], 81.0f)) + + glm_translate(m1, (vec3){4.0f, 5.0f, 6.0f}); + ASSERT(test_eq(s1[0], 49.0f)) + ASSERT(test_eq(s1[1], 64.0f)) + ASSERT(test_eq(s1[2], 81.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, uniscaled) { + mat4 m1; + + GLM(scale_make)(m1, (vec3){7.0f, 8.0f, 9.0f}); + ASSERT(!GLM(uniscaled)(m1)) + + GLM(scale_make)(m1, (vec3){7.0f, 7.0f, 7.0f}); + ASSERT(GLM(uniscaled)(m1)) + + glm_rotate(m1, GLM_PI_4f, (vec3){23.0f, 45.0f, 66.0f}); + ASSERT(GLM(uniscaled)(m1)) + + glm_translate(m1, (vec3){4.0f, 5.0f, 6.0f}); + ASSERT(GLM(uniscaled)(m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, decompose_rs) { + mat4 m1, m2, r; + vec3 s1; + + GLM(scale_make)(m1, (vec3){7.0f, 8.0f, 9.0f}); + GLM(decompose_rs)(m1, r, s1); + + ASSERT(test_eq(s1[0], 7.0f)) + ASSERT(test_eq(s1[1], 8.0f)) + ASSERT(test_eq(s1[2], 9.0f)) + ASSERTIFY(test_assert_mat4_eq_identity(r)); + + GLM(scale)(m1, (vec3){7.0f, 8.0f, 9.0f}); + GLM(decompose_rs)(m1, r, s1); + + ASSERT(test_eq(s1[0], 49.0f)) + ASSERT(test_eq(s1[1], 64.0f)) + ASSERT(test_eq(s1[2], 81.0f)) + ASSERTIFY(test_assert_mat4_eq_identity(r)); + + glm_rotate(m1, GLM_PI_4f, (vec3){23.0f, 45.0f, 66.0f}); + ASSERT(test_eq(s1[0], 49.0f)) + ASSERT(test_eq(s1[1], 64.0f)) + ASSERT(test_eq(s1[2], 81.0f)) + GLM(decompose_rs)(m1, r, s1); + + glm_mat4_identity(m2); + glm_mat4_mul(m2, r, m2); + glm_scale(m2, s1); + + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.00001f)); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, decompose) { + mat4 m1, m2, r; + vec4 t; + vec3 s; + + GLM(scale_make)(m1, (vec3){7.0f, 8.0f, 9.0f}); + GLM(decompose)(m1, t, r, s); + + ASSERT(test_eq(s[0], 7.0f)) + ASSERT(test_eq(s[1], 8.0f)) + ASSERT(test_eq(s[2], 9.0f)) + ASSERTIFY(test_assert_mat4_eq_identity(r)); + + GLM(scale)(m1, (vec3){7.0f, 8.0f, 9.0f}); + GLM(decompose)(m1, t, r, s); + + ASSERT(test_eq(s[0], 49.0f)) + ASSERT(test_eq(s[1], 64.0f)) + ASSERT(test_eq(s[2], 81.0f)) + ASSERTIFY(test_assert_mat4_eq_identity(r)); + + glm_rotate(m1, GLM_PI_4f, (vec3){23.0f, 45.0f, 66.0f}); + ASSERT(test_eq(s[0], 49.0f)) + ASSERT(test_eq(s[1], 64.0f)) + ASSERT(test_eq(s[2], 81.0f)) + GLM(decompose)(m1, t, r, s); + + glm_mat4_identity(m2); + glm_mat4_mul(m2, r, m2); + glm_scale(m2, s); + + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.00001f)); + + glm_mat4_identity(m1); + glm_translate(m1, (vec3){56.0f, 13.0f, 90.0f}); + glm_rotate(m1, GLM_PI_4f, (vec3){23.0f, 45.0f, 66.0f}); + glm_scale(m1, (vec3){12.0f, 34.0f, 23.0f}); + + GLM(decompose)(m1, t, r, s); + + ASSERT(test_eq(t[0], 56.0f)) + ASSERT(test_eq(t[1], 13.0f)) + ASSERT(test_eq(t[2], 90.0f)) + + ASSERT(test_eq(s[0], 12.0f)) + ASSERT(test_eq(s[1], 34.0f)) + ASSERT(test_eq(s[2], 23.0f)) + + glm_mat4_identity(m2); + glm_translate(m2, t); + glm_mat4_mul(m2, r, m2); + glm_scale(m2, s); + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.00001f)); + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_affine2d.h b/libs/cglm/test/src/test_affine2d.h new file mode 100644 index 0000000..8828661 --- /dev/null +++ b/libs/cglm/test/src/test_affine2d.h @@ -0,0 +1,310 @@ +/* + * 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" + +TEST_IMPL(GLM_PREFIX, translate2d) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(translate2d)(m1, (vec2){13.0f, 11.0f}); + glm_mat3_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 14.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(translate2d)(m1, (vec2){1.0f, -1.0f}); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 16.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate2d_to) { + mat3 m1, m2; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(translate2d_to)(m1, (vec2){13.0f, 11.0f}, m2); + glm_mat3_mulv(m2, v1, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 14.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(translate2d_to)(m1, (vec2){1.0f, -1.0f}, m2); + glm_mat3_mulv(m2, v2, v2); + + ASSERT(test_eq(v2[0], 16.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate2d_x) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(translate2d_x)(m1, 13.0f); + glm_mat3_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 3.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(translate2d_x)(m1, -1.0f); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 14.0f)) + ASSERT(test_eq(v2[1], 3.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate2d_y) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(translate2d_y)(m1, 11.0f); + glm_mat3_mulv(m1, v1, v2); + + + ASSERT(test_eq(v2[0], 2.0f)) + ASSERT(test_eq(v2[1], 14.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(translate2d_y)(m1, -1.0f); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 2.0f)) + ASSERT(test_eq(v2[1], 13.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, translate2d_make) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(translate2d_make)(m1, (vec2){13.0f, 11.0f}); + glm_mat3_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 15.0f)) + ASSERT(test_eq(v2[1], 14.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(translate2d_make)(m1, (vec2){-1.0f, -5.0f}); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], 14.0f)) + ASSERT(test_eq(v2[1], 9.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale2d_to) { + mat3 m1, m2; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(scale2d_to)(m1, (vec2){13.0f, 11.0f}, m2); + glm_mat3_mulv(m2, v1, v2); + + ASSERT(test_eq(v2[0], 26.0f)) + ASSERT(test_eq(v2[1], 33.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(scale2d_to)(m1, (vec2){-1.0f, -5.0f}, m2); + glm_mat3_mulv(m2, v2, v2); + + ASSERT(test_eq(v2[0], -26.0f)) + ASSERT(test_eq(v2[1], -165.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale2d_make) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + GLM(scale2d_make)(m1, (vec2){13.0f, 11.0f}); + glm_mat3_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 26.0f)) + ASSERT(test_eq(v2[1], 33.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + GLM(scale2d_make)(m1, (vec3){-1.0f, -5.0f}); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], -26.0f)) + ASSERT(test_eq(v2[1], -165.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale2d) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(scale2d)(m1, (vec2){13.0f, 11.0f}); + glm_mat3_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 26.0f)) + ASSERT(test_eq(v2[1], 33.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(scale2d)(m1, (vec2){-1.0f, -5.0f}); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], -26.0f)) + ASSERT(test_eq(v2[1], -165.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, scale2d_uni) { + mat3 m1; + vec3 v1 = {2.0f, 3.0f, 1.0f}, v2; + + glm_mat3_identity(m1); + GLM(scale2d_uni)(m1, 13.0f); + glm_mat3_mulv(m1, v1, v2); + + ASSERT(test_eq(v2[0], 26.0f)) + ASSERT(test_eq(v2[1], 39.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + glm_mat3_identity(m1); + GLM(scale2d_uni)(m1, -5.0f); + glm_mat3_mulv(m1, v2, v2); + + ASSERT(test_eq(v2[0], -130.0f)) + ASSERT(test_eq(v2[1], -195.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate2d_make) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT; + vec3 v1 = {0.0f, 1.0f, 1.0f}, v2 = {0.0f, 1.0f, 1.0f}; + + GLM(rotate2d_make)(m1, GLM_PI_2f); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate2d_make)(m1, -GLM_PI_2f); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate2d_make)(m1, GLM_PIf); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate2d) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT; + vec3 v1 = {0.0f, 1.0f, 1.0f}, v2 = {0.0f, 1.0f, 1.0f}; + + GLM(rotate2d)(m1, GLM_PI_2f); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate2d)(m1, GLM_PI_2f); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate2d)(m1, GLM_PI_2f); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, rotate2d_to) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT, m2; + vec3 v1 = {0.0f, 1.0f, 1.0f}, v2 = {0.0f, 1.0f, 1.0f}; + + GLM(rotate2d_to)(m1, GLM_PI_2f, m1); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate2d_to)(m1, GLM_PI_2f, m2); + glm_mat3_mulv(m2, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + glm_vec3_copy(v2, v1); + + GLM(rotate2d_to)(m2, GLM_PI_2f, m1); + glm_mat3_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_affine_mat.h b/libs/cglm/test/src/test_affine_mat.h new file mode 100644 index 0000000..e928f8e --- /dev/null +++ b/libs/cglm/test/src/test_affine_mat.h @@ -0,0 +1,112 @@ +/* + * 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" + +#ifndef glm_affine_mat_test_guard +#define glm_affine_mat_test_guard +CGLM_INLINE +void +glm_inv_tr_raw(mat4 mat) { + CGLM_ALIGN_MAT mat3 r; + CGLM_ALIGN(8) vec3 t; + + /* rotate */ + glm_mat4_pick3t(mat, r); + glm_mat4_ins3(r, mat); + + /* translate */ + glm_mat3_mulv(r, mat[3], t); + glm_vec3_negate(t); + glm_vec3_copy(t, mat[3]); +} +#endif + +TEST_IMPL(GLM_PREFIX, mul) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + mat4 m2 = GLM_MAT4_IDENTITY_INIT; + mat4 m3; + mat4 m4 = GLM_MAT4_ZERO_INIT; + int i, j, k; + + test_rand_mat4(m1); + test_rand_mat4(m2); + + GLM(mul)(m1, m2, m3); + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) + /* column-major */ + m4[i][j] += m1[k][j] * m2[i][k]; + } + } + + ASSERTIFY(test_assert_mat4_eq(m3, m4)) + + /* test pre compiled */ + GLM(mul)(m1, m2, m3); + ASSERTIFY(test_assert_mat4_eq(m3, m4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mul_rot) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + mat4 m2 = GLM_MAT4_IDENTITY_INIT; + mat4 m3; + mat4 m4 = GLM_MAT4_ZERO_INIT; + int i, j, k; + + glm_rotate(m1, drand48(), (vec3){drand48(), drand48(), drand48()}); + glm_rotate(m2, drand48(), (vec3){drand48(), drand48(), drand48()}); + + GLM(mul_rot)(m1, m2, m3); + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) + /* column-major */ + m4[i][j] += m1[k][j] * m2[i][k]; + } + } + + ASSERTIFY(test_assert_mat4_eq(m3, m4)) + + /* test pre compiled */ + GLM(mul_rot)(m1, m2, m3); + ASSERTIFY(test_assert_mat4_eq(m3, m4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, inv_tr) { + mat4 m1, m2; + int i; + + for (i = 0; i < 10000; i++) { + test_rand_mat4(m1); + + glm_mat4_copy(m1, m2); + + /* test inverse precise */ + GLM(inv_tr)(m1); + GLM(inv_tr)(m1); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + + /* test inverse precise */ + GLM(mat4_inv)(m1, m2); + GLM(inv_tr)(m2); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + + /* test with raw */ + glm_mat4_copy(m1, m2); + glm_inv_tr_raw(m2); + GLM(inv_tr)(m1); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + } + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_bezier.c b/libs/cglm/test/src/test_bezier.c new file mode 100644 index 0000000..3089dd5 --- /dev/null +++ b/libs/cglm/test/src/test_bezier.c @@ -0,0 +1,66 @@ +/* + * 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; +} + +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); +} + +TEST_IMPL(bezier) { + 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(); + + /* 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); + + ASSERT(test_eq(Bs, Bs_plain)); + ASSERTIFY(test_assert_eqf(smc, Bs_plain)) + ASSERTIFY(test_assert_eqf(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(test_eq(Bs, Bs_plain)); + ASSERT(test_eq(smc, Bs_plain)); + ASSERT(test_eq(Bs, smc)); + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_cam.c b/libs/cglm/test/src/test_cam.c new file mode 100644 index 0000000..b5fbf2b --- /dev/null +++ b/libs/cglm/test/src/test_cam.c @@ -0,0 +1,55 @@ +/* + * 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" + +TEST_IMPL(camera_lookat) { + mat4 view1, view2; + vec3 center, + eye = {0.024f, 14.6f, 67.04f}, + dir = {0.0f, 0.0f, -1.0f}, + up = {0.0f, 1.0f, 0.0f}; + + glm_vec3_add(eye, dir, center); + glm_lookat(eye, center, up, view1); + + glm_look(eye, dir, up, view2); + + ASSERTIFY(test_assert_mat4_eq(view1, view2)) + + TEST_SUCCESS +} + +TEST_IMPL(camera_decomp) { + mat4 proj, proj2; + vec4 sizes; + float aspect, fovy, nearZ, farZ; + + aspect = 0.782f; + fovy = glm_rad(49.984f); + nearZ = 0.1f; + farZ = 100.0f; + + glm_perspective(fovy, aspect, nearZ, farZ, proj); + ASSERT(fabsf(aspect - glm_persp_aspect(proj)) < GLM_FLT_EPSILON) + ASSERT(fabsf(fovy - glm_persp_fovy(proj)) < GLM_FLT_EPSILON) + ASSERT(fabsf(49.984f - glm_deg(glm_persp_fovy(proj))) < GLM_FLT_EPSILON) + + glm_persp_sizes(proj, fovy, sizes); + + glm_frustum(-sizes[0] * 0.5f, + sizes[0] * 0.5f, + -sizes[1] * 0.5f, + sizes[1] * 0.5f, + nearZ, + farZ, + proj2); + + ASSERTIFY(test_assert_mat4_eq(proj, proj2)) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_cam_lh_no.c b/libs/cglm/test/src/test_cam_lh_no.c new file mode 100644 index 0000000..33a285a --- /dev/null +++ b/libs/cglm/test/src/test_cam_lh_no.c @@ -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 + */ + +#include "test_common.h" + +TEST_IMPL(perspective_lh_no) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float zNearVal = 0.1f; + const float zFarVal = 100.0f; + + glm_perspective_lh_no(fovy, aspect, zNearVal, zFarVal, dst); + + /* Sanity mk. I: longhand version */ + ASSERT(test_eq(dst[0][0], 1.0f / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1.0f / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], (zFarVal + zNearVal) / (zFarVal - zNearVal))) + ASSERT(test_eq(dst[2][3], 1.0f)) + ASSERT(test_eq(dst[3][2], -2 * zFarVal * zNearVal / (zFarVal - zNearVal))) + + /* Sanity mk. II */ + /*reference test data for glm_perspective_lh_no*/ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = 1.0020020f; + cmp[2][3] = 1.0000000f; + cmp[3][2] = -0.2002002f; + + return test_assert_mat4_eq(dst, cmp); +} diff --git a/libs/cglm/test/src/test_cam_lh_zo.c b/libs/cglm/test/src/test_cam_lh_zo.c new file mode 100644 index 0000000..f5f50af --- /dev/null +++ b/libs/cglm/test/src/test_cam_lh_zo.c @@ -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 + */ + +#include "test_common.h" + +TEST_IMPL(perspective_lh_zo) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float zNearVal = 0.1f; + const float zFarVal = 100.0f; + + glm_perspective_lh_zo(fovy, aspect, zNearVal, zFarVal, dst); + + /* Sanity mk. I: longhand version */ + ASSERT(test_eq(dst[0][0], 1.0f / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1.0f / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], zFarVal / (zFarVal - zNearVal))) + ASSERT(test_eq(dst[2][3], 1.0f)) + ASSERT(test_eq(dst[3][2], -1 * zFarVal * zNearVal / (zFarVal - zNearVal))) + + /* Sanity mk. II */ + /* "Reference values" generated by GLM's glm::perspectiveLH_ZO */ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = 1.0010010f; + cmp[2][3] = 1.0000000f; + cmp[3][2] = -0.1001001f; + + return test_assert_mat4_eq(dst, cmp); +} diff --git a/libs/cglm/test/src/test_cam_rh_no.c b/libs/cglm/test/src/test_cam_rh_no.c new file mode 100644 index 0000000..2bcadcd --- /dev/null +++ b/libs/cglm/test/src/test_cam_rh_no.c @@ -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 + */ + +#include "test_common.h" + +TEST_IMPL(perspective_rh_no) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float zNearVal = 0.1f; + const float zFarVal = 100.0f; + + glm_perspective_rh_no(fovy, aspect, zNearVal, zFarVal, dst); + + /* Sanity mk. I: longhand version */ + ASSERT(test_eq(dst[0][0], 1.0f / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1.0f / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], -1.0f * (zFarVal + zNearVal) / (zFarVal - zNearVal))) + ASSERT(test_eq(dst[2][3], -1.0f)) + ASSERT(test_eq(dst[3][2], -2 * zFarVal * zNearVal / (zFarVal - zNearVal))) + + /* Sanity mk. II */ + /*reference test data for glm_perspective_rh_no*/ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = -1.0020020f; + cmp[2][3] = -1.0000000f; + cmp[3][2] = -0.2002002f; + + return test_assert_mat4_eq(dst, cmp); +} diff --git a/libs/cglm/test/src/test_cam_rh_zo.c b/libs/cglm/test/src/test_cam_rh_zo.c new file mode 100644 index 0000000..95281a7 --- /dev/null +++ b/libs/cglm/test/src/test_cam_rh_zo.c @@ -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 + */ + +#include "test_common.h" + +TEST_IMPL(perspective_rh_zo) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float zNearVal = 0.1f; + const float zFarVal = 100.0f; + + glm_perspective_rh_zo(fovy, aspect, zNearVal, zFarVal, dst); + + /* Sanity mk. I: longhand version */ + ASSERT(test_eq(dst[0][0], 1 / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1 / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], zFarVal / (zNearVal - zFarVal))) + ASSERT(test_eq(dst[2][3], -1.0f)) + ASSERT(test_eq(dst[3][2], -1 * zFarVal * zNearVal / (zFarVal - zNearVal))) + + /* Sanity mk. II */ + /*reference test data for glm_perspective_rh_zo*/ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = -1.0010010f; + cmp[2][3] = -1.0000000f; + cmp[3][2] = -0.1001001f; + + return test_assert_mat4_eq(dst, cmp); +} diff --git a/libs/cglm/test/src/test_camera.h b/libs/cglm/test/src/test_camera.h new file mode 100644 index 0000000..fb1075a --- /dev/null +++ b/libs/cglm/test/src/test_camera.h @@ -0,0 +1,68 @@ +/* + * 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" + +TEST_IMPL(GLM_PREFIX, frustum) { + mat4 proj; + vec4 vp = {0.0f, 0.0f, 800.0f, 600.0f}; + float left, right, top, bottom, znear, zfar; + + znear = 0.1f; + zfar = 100.0f; + left = -100.0f; + right = 100.0f; + bottom = -100.0f; + top = 100.0f; + + GLM(frustum)(left, right, bottom, top, znear, zfar, proj); + + ASSERT(test_eq(proj[0][1], 0.0f)) + ASSERT(test_eq(proj[0][2], 0.0f)) + ASSERT(test_eq(proj[0][3], 0.0f)) + + ASSERT(test_eq(proj[1][0], 0.0f)) + ASSERT(test_eq(proj[1][2], 0.0f)) + ASSERT(test_eq(proj[1][3], 0.0f)) + + ASSERT(test_eq(proj[2][3], -1.0f)) + + ASSERT(test_eq(proj[3][0], 0.0f)) + ASSERT(test_eq(proj[3][1], 0.0f)) + ASSERT(test_eq(proj[3][3], 0.0f)) + + vec4 v1 = {1.0f, 20.0f, znear}; + vec4 v2 = {1.0f, 20.0f, zfar}; + vec4 v3, v4; + + /* perspective test */ + GLM(mat4_mulv)(proj, v1, v3); + GLM(project)(v3, proj, vp, v3); + + ASSERT(v3[0] > v1[0]) + ASSERT(v3[1] > v1[1]) + + GLM(mat4_mulv)(proj, v2, v4); + GLM(project)(v4, proj, vp, v4); + + ASSERT(v4[0] < v3[0]) + ASSERT(v4[1] < v3[1]) + + /* not infinity */ + ASSERT(!GLM(vec4_isinf)(proj[0])) + ASSERT(!GLM(vec4_isinf)(proj[1])) + ASSERT(!GLM(vec4_isinf)(proj[2])) + ASSERT(!GLM(vec4_isinf)(proj[3])) + + /* not NaN */ + ASSERT(!GLM(vec4_isnan)(proj[0])) + ASSERT(!GLM(vec4_isnan)(proj[1])) + ASSERT(!GLM(vec4_isnan)(proj[2])) + ASSERT(!GLM(vec4_isnan)(proj[3])) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_clamp.c b/libs/cglm/test/src/test_clamp.c new file mode 100644 index 0000000..1d1c0c2 --- /dev/null +++ b/libs/cglm/test/src/test_clamp.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" + +TEST_IMPL(clamp) { + vec3 v3 = {15.07f, 0.4f, 17.3f}; + vec4 v4 = {5.07f, 2.3f, 1.3f, 1.4f}; + + ASSERT(glm_clamp(1.6f, 0.0f, 1.0f) == 1.0f) + ASSERT(glm_clamp(-1.6f, 0.0f, 1.0f) == 0.0f) + ASSERT(glm_clamp(0.6f, 0.0f, 1.0f) == 0.6f) + + glm_vec3_clamp(v3, 0.0, 1.0); + glm_vec4_clamp(v4, 1.5, 3.0); + + ASSERT(v3[0] == 1.0f) + ASSERT(v3[1] == 0.4f) + ASSERT(v3[2] == 1.0f) + + ASSERT(v4[0] == 3.0f) + ASSERT(v4[1] == 2.3f) + ASSERT(v4[2] == 1.5f) + ASSERT(v4[3] == 1.5f) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_common.c b/libs/cglm/test/src/test_common.c new file mode 100644 index 0000000..46b6e63 --- /dev/null +++ b/libs/cglm/test/src/test_common.c @@ -0,0 +1,341 @@ +/* + * Copyright (c), Recep Aslantas. + * MIT License (MIT), http://opensource.org/licenses/MIT + */ + +#include "test_common.h" +#include + +void +test_rand_mat4(mat4 dest) { + glm_mat4_copy(GLM_MAT4_IDENTITY, dest); + + /* random position */ + dest[3][0] = drand48(); + dest[3][1] = drand48(); + dest[3][2] = drand48(); + + /* random rotatation around random axis with random angle */ + glm_rotate(dest, drand48(), (vec3){drand48(), drand48(), drand48()}); + + /* random scale */ + /* glm_scale(dest, (vec3){drand48(), drand48(), drand48()}); */ +} + +void +test_rand_mat3(mat3 dest) { + mat4 m4; + + /* 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_mat2(mat2 dest) { + dest[0][0] = drand48(); + dest[0][1] = drand48(); + dest[1][0] = drand48(); + dest[1][1] = drand48(); +} + +void +test_rand_vec3(vec3 dest) { + dest[0] = drand48(); + dest[1] = drand48(); + dest[2] = drand48(); +} + +vec3s +test_rand_vec3s(void) { + vec3s r; + test_rand_vec3(r.raw); + return r; +} + +void +test_rand_vec4(vec4 dest) { + dest[0] = drand48(); + dest[1] = drand48(); + dest[2] = drand48(); + dest[3] = drand48(); +} + +vec4s +test_rand_vec4s(void) { + vec4s r; + test_rand_vec4(r.raw); + return r; +} + +float +test_rand(void) { + return drand48(); +} + +void +test_rand_quat(versor q) { + glm_quat(q, drand48(), drand48(), drand48(), drand48()); + glm_quat_normalize(q); +} + +test_status_t +test_assert_mat4_eq(mat4 m1, mat4 m2) { + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009) + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat4_eqt(mat4 m1, mat4 m2) { + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009) + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps) { + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + ASSERT(fabsf(m1[i][j] - m2[i][j]) <= eps); + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat2_eqt(mat2 m1, mat2 m2) { + int i, j; + + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009); + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat2_eq(mat2 m1, mat2 m2) { + int i, j; + + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009); + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat2_eq_identity(mat2 m2) { + int i, j; + + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + if (i == j) { + ASSERT(test_eq(m2[i][j], 1.0f)) + } else { + ASSERT(test_eq(m2[i][j], 0.0f)) + } + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat2_eq_zero(mat2 m2) { + int i, j; + + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + ASSERT(test_eq(m2[i][j], 0.0f)) + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat3_eq(mat3 m1, mat3 m2) { + int i, j; + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009); + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat3_eqt(mat3 m1, mat3 m2) { + int i, j; + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009); + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat3_eq_identity(mat3 m3) { + int i, j; + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + if (i == j) { + ASSERT(test_eq(m3[i][j], 1.0f)) + } else { + ASSERT(test_eq(m3[i][j], 0.0f)) + } + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat3_eq_zero(mat3 m3) { + int i, j; + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + ASSERT(test_eq(m3[i][j], 0.0f)) + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat4_eq_identity(mat4 m4) { + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + if (i == j) { + ASSERT(test_eq(m4[i][j], 1.0f)) + } else { + ASSERT(test_eq(m4[i][j], 0.0f)) + } + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_mat4_eq_zero(mat4 m4) { + int i, j; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + ASSERT(test_eq(m4[i][j], 0.0f)) + } + } + + TEST_SUCCESS +} + +test_status_t +test_assert_eqf(float a, float b) { + ASSERT(fabsf(a - b) <= 0.000009); /* rounding errors */ + + TEST_SUCCESS +} + +test_status_t +test_assert_vec2_eq(vec2 v1, vec2 v2) { + ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ + ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009); + + TEST_SUCCESS +} + +test_status_t +test_assert_vec3_eq(vec3 v1, vec3 v2) { + ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ + ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009); + ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009); + + TEST_SUCCESS +} + +test_status_t +test_assert_vec3s_eq(vec3s v1, vec3s v2) { + test_assert_vec3_eq(v1.raw, v2.raw); + + TEST_SUCCESS +} + +test_status_t +test_assert_vec4_eq(vec4 v1, vec4 v2) { + ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ + ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009); + ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009); + ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009); + + TEST_SUCCESS +} + +test_status_t +test_assert_vec4s_eq(vec4s v1, vec4s v2) { + test_assert_vec4_eq(v1.raw, v2.raw); + + TEST_SUCCESS +} + +test_status_t +test_assert_quat_eq_abs(versor v1, versor v2) { + ASSERT(fabsf(fabsf(v1[0]) - fabsf(v2[0])) <= 0.0009); /* rounding errors */ + ASSERT(fabsf(fabsf(v1[1]) - fabsf(v2[1])) <= 0.0009); + ASSERT(fabsf(fabsf(v1[2]) - fabsf(v2[2])) <= 0.0009); + ASSERT(fabsf(fabsf(v1[3]) - fabsf(v2[3])) <= 0.0009); + + TEST_SUCCESS +} + +test_status_t +test_assert_quat_eq(versor v1, versor v2) { + ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */ + ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009); + ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009); + ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009); + + TEST_SUCCESS +} + +test_status_t +test_assert_quat_eq_identity(versor q) { + versor p = GLM_QUAT_IDENTITY_INIT; + + ASSERT(fabsf(q[0] - p[0]) <= 0.000009); /* rounding errors */ + ASSERT(fabsf(q[1] - p[1]) <= 0.000009); + ASSERT(fabsf(q[2] - p[2]) <= 0.000009); + ASSERT(fabsf(q[3] - p[3]) <= 0.000009); + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_common.h b/libs/cglm/test/src/test_common.h new file mode 100644 index 0000000..9162a8d --- /dev/null +++ b/libs/cglm/test/src/test_common.h @@ -0,0 +1,118 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef test_common_h +#define test_common_h + +#include "../include/common.h" + +void +test_rand_mat4(mat4 dest); + +void +test_rand_mat3(mat3 dest); + +void +test_rand_mat2(mat2 dest); + +test_status_t +test_assert_eqf(float a, float b); + +test_status_t +test_assert_mat4_eq(mat4 m1, mat4 m2); + +test_status_t +test_assert_mat4_eqt(mat4 m1, mat4 m2); + +test_status_t +test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps); + +test_status_t +test_assert_mat4_eq_identity(mat4 m4); + +test_status_t +test_assert_mat4_eq_zero(mat4 m4); + +test_status_t +test_assert_mat2_eqt(mat2 m1, mat2 m2); + +test_status_t +test_assert_mat2_eq(mat2 m1, mat2 m2); + +test_status_t +test_assert_mat2_eq_identity(mat2 m2); + +test_status_t +test_assert_mat2_eq_zero(mat2 m2); + +test_status_t +test_assert_mat3_eq(mat3 m1, mat3 m2); + +test_status_t +test_assert_vec2_eq(vec2 v1, vec2 v2); + +test_status_t +test_assert_mat3_eqt(mat3 m1, mat3 m2); + +test_status_t +test_assert_mat3_eq_identity(mat3 m3); + +test_status_t +test_assert_mat3_eq_zero(mat3 m3); + +test_status_t +test_assert_vec3_eq(vec3 v1, vec3 v2); + +test_status_t +test_assert_vec3s_eq(vec3s v1, vec3s v2); + +test_status_t +test_assert_vec4_eq(vec4 v1, vec4 v2); + +test_status_t +test_assert_vec4s_eq(vec4s v1, vec4s v2); + +test_status_t +test_assert_quat_eq(versor v1, versor v2); + +test_status_t +test_assert_quat_eq_identity(versor q) ; + +test_status_t +test_assert_quat_eq_abs(versor v1, versor v2); + +void +test_rand_vec3(vec3 dest); + +vec3s +test_rand_vec3s(void); + +void +test_rand_vec4(vec4 dest); + +vec4s +test_rand_vec4s(void); + +float +test_rand(void); + +void +test_rand_quat(versor q); + +CGLM_INLINE +bool +test_eq(float a, float b) { + return fabsf(a - b) <= GLM_FLT_EPSILON * 10; +} + +CGLM_INLINE +bool +test_eq_th(float a, float b, float th) { + return fabsf(a - b) <= th; +} + +#endif /* test_common_h */ diff --git a/libs/cglm/test/src/test_euler.c b/libs/cglm/test/src/test_euler.c new file mode 100644 index 0000000..b71e0f0 --- /dev/null +++ b/libs/cglm/test/src/test_euler.c @@ -0,0 +1,45 @@ +/* + * 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" + +TEST_IMPL(euler) { + 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 */ + ASSERTIFY(test_assert_vec3_eq(inAngles, outAngles)) + + /* matrices must be equal */ + glmc_euler_xyz(outAngles, rot2); + ASSERTIFY(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); + ASSERTIFY(test_assert_mat4_eq(rot1, rot2)) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_ivec2.h b/libs/cglm/test/src/test_ivec2.h new file mode 100644 index 0000000..5374688 --- /dev/null +++ b/libs/cglm/test/src/test_ivec2.h @@ -0,0 +1,189 @@ +/* + * 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" + +TEST_IMPL(GLM_PREFIX, ivec2) { + ivec4 v4 = {2, 3, 5, 7}; + ivec3 v3 = {11, 13, 17}; + ivec2 v2; + + GLM(ivec2)(v4, v2); + ASSERT(v2[0] == 2) + ASSERT(v2[1] == 3) + + GLM(ivec2)(v3, v2); + ASSERT(v2[0] == 11) + ASSERT(v2[1] == 13) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_copy) { + ivec2 src = {7, 5}; + ivec2 dst = {99, 99}; + + GLM(ivec2_copy)(src, dst); + ASSERT(dst[0] == 7) + ASSERT(dst[1] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_zero) { + ivec2 v = {2, 3}; + + GLM(ivec2_zero)(v); + ASSERT(v[0] == 0) + ASSERT(v[1] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_one) { + ivec2 v = {-2, 9}; + + GLM(ivec2_one)(v); + ASSERT(v[0] == 1) + ASSERT(v[1] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_add) { + ivec2 a = {14, 3}; + ivec2 b = {-3, 2}; + ivec2 v = {99, 99}; + + GLM(ivec2_add)(a, b, v); + ASSERT(v[0] == 11) + ASSERT(v[1] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_adds) { + ivec2 a = {-3, 1}; + ivec2 v = {99, 99}; + int s = 2; + + GLM(ivec2_adds)(a, s, v); + ASSERT(v[0] == -1) + ASSERT(v[1] == 3) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_sub) { + ivec2 a = {-2, 9}; + ivec2 b = {3, 2}; + ivec2 v = {99, 99}; + + GLM(ivec2_sub)(a, b, v); + ASSERT(v[0] == -5) + ASSERT(v[1] == 7) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_subs) { + ivec2 a = {5, -2}; + ivec2 v = {99, 99}; + int s = -3; + + GLM(ivec2_subs)(a, s, v); + ASSERT(v[0] == 8) + ASSERT(v[1] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_mul) { + ivec2 a = {3, 4}; + ivec2 b = {-2, 3}; + ivec2 v = {99, 99}; + + GLM(ivec2_mul)(a, b, v); + ASSERT(v[0] == -6) + ASSERT(v[1] == 12) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_scale) { + ivec2 a = {-9, 2}; + ivec2 v = {99, 99}; + int s = -2; + + GLM(ivec2_scale)(a, s, v); + ASSERT(v[0] == 18) + ASSERT(v[1] == -4) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_distance2) { + ivec2 a = {-1, 3}; + ivec2 b = {5, 4}; + int v; + + v = GLM(ivec2_distance2)(a, b); + ASSERT(v == 37) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_distance) { + ivec2 a = {3, 2}; + ivec2 b = {-2, 5}; + float v; + + v = GLM(ivec2_distance)(a, b); + ASSERT(test_eq(v, 5.8309518948)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_maxv) { + ivec2 a = {9, -20}; + ivec2 b = {8, -1}; + ivec2 v = {99, 99}; + + GLM(ivec2_maxv)(a, b, v); + ASSERT(v[0] == 9) + ASSERT(v[1] == -1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_minv) { + ivec2 a = {16, 0}; + ivec2 b = {-15, 10}; + ivec2 v = {99, 99}; + + GLM(ivec2_minv)(a, b, v); + ASSERT(v[0] == -15) + ASSERT(v[1] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec2_clamp) { + ivec2 v = {3, -1}; + + GLM(ivec2_clamp)(v, -2, 4); + ASSERT(v[0] == 3) + ASSERT(v[1] == -1) + + v[0] = -15; + v[1] = 4; + GLM(ivec2_clamp)(v, -9, 3); + ASSERT(v[0] == -9) + ASSERT(v[1] == 3) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_ivec3.h b/libs/cglm/test/src/test_ivec3.h new file mode 100644 index 0000000..dfa8794 --- /dev/null +++ b/libs/cglm/test/src/test_ivec3.h @@ -0,0 +1,199 @@ +/* + * 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" + +TEST_IMPL(GLM_PREFIX, ivec3) { + ivec4 v4 = {2, 3, 5, 7}; + ivec3 v3 = {99, 99, 99}; + + GLM(ivec3)(v4, v3); + ASSERT(v3[0] == 2) + ASSERT(v3[1] == 3) + ASSERT(v3[2] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_copy) { + ivec3 src = {7, 5, 2}; + ivec3 dst = {99, 99, 99}; + + GLM(ivec3_copy)(src, dst); + ASSERT(dst[0] == 7) + ASSERT(dst[1] == 5) + ASSERT(dst[2] == 2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_zero) { + ivec3 v = {2, 3, 5}; + + GLM(ivec3_zero)(v); + ASSERT(v[0] == 0) + ASSERT(v[1] == 0) + ASSERT(v[2] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_one) { + ivec3 v = {-2, 9, 12}; + + GLM(ivec3_one)(v); + ASSERT(v[0] == 1) + ASSERT(v[1] == 1) + ASSERT(v[2] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_add) { + ivec3 a = {14, 3, 2}; + ivec3 b = {-3, 2, 1}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_add)(a, b, v); + ASSERT(v[0] == 11) + ASSERT(v[1] == 5) + ASSERT(v[2] == 3) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_adds) { + ivec3 a = {-3, 1, 4}; + ivec3 v = {99, 99, 99}; + int s = 2; + + GLM(ivec3_adds)(a, s, v); + ASSERT(v[0] == -1) + ASSERT(v[1] == 3) + ASSERT(v[2] == 6) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_sub) { + ivec3 a = {-2, 9, 1}; + ivec3 b = {3, 2, -1}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_sub)(a, b, v); + ASSERT(v[0] == -5) + ASSERT(v[1] == 7) + ASSERT(v[2] == 2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_subs) { + ivec3 a = {5, -2, 6}; + ivec3 v = {99, 99, 99}; + int s = -3; + + GLM(ivec3_subs)(a, s, v); + ASSERT(v[0] == 8) + ASSERT(v[1] == 1) + ASSERT(v[2] == 9) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_mul) { + ivec3 a = {3, 4, 5}; + ivec3 b = {-2, 3, 1}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_mul)(a, b, v); + ASSERT(v[0] == -6) + ASSERT(v[1] == 12) + ASSERT(v[2] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_scale) { + ivec3 a = {-9, 2, 3}; + ivec3 v = {99, 99, 99}; + int s = -2; + + GLM(ivec3_scale)(a, s, v); + ASSERT(v[0] == 18) + ASSERT(v[1] == -4) + ASSERT(v[2] == -6) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_distance2) { + ivec3 a = {-1, 3, 0}; + ivec3 b = {5, 4, 2}; + int v; + + v = GLM(ivec3_distance2)(a, b); + ASSERT(v == 41) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_distance) { + ivec3 a = {3, 2, 4}; + ivec3 b = {-2, 5, 2}; + float v; + + v = GLM(ivec3_distance)(a, b); + ASSERT(test_eq(v, 6.1644140029)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_maxv) { + ivec3 a = {9, -20, 5}; + ivec3 b = {8, -1, 2}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_maxv)(a, b, v); + ASSERT(v[0] == 9) + ASSERT(v[1] == -1) + ASSERT(v[2] == 5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_minv) { + ivec3 a = {16, 0, 4}; + ivec3 b = {-15, 10, 8}; + ivec3 v = {99, 99, 99}; + + GLM(ivec3_minv)(a, b, v); + ASSERT(v[0] == -15) + ASSERT(v[1] == 0) + ASSERT(v[2] == 4) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec3_clamp) { + ivec3 v = {3, -1, 10}; + + GLM(ivec3_clamp)(v, -2, 4); + ASSERT(v[0] == 3) + ASSERT(v[1] == -1) + ASSERT(v[2] == 4) + + v[0] = -15; + v[1] = 4; + v[2] = 1; + GLM(ivec3_clamp)(v, -9, 3); + ASSERT(v[0] == -9) + ASSERT(v[1] == 3) + ASSERT(v[2] == 1) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_ivec4.h b/libs/cglm/test/src/test_ivec4.h new file mode 100644 index 0000000..dd2d606 --- /dev/null +++ b/libs/cglm/test/src/test_ivec4.h @@ -0,0 +1,214 @@ +/* + * 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" + +TEST_IMPL(GLM_PREFIX, ivec4) { + ivec3 v3 = {2, 3, 5}; + ivec4 v4; + + GLM(ivec4)(v3, 7, v4); + ASSERT(test_eq(v4[0], 2)) + ASSERT(test_eq(v4[1], 3)) + ASSERT(test_eq(v4[2], 5)) + ASSERT(test_eq(v4[3], 7)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_copy) { + ivec4 src = {7, 5, 2, 11}; + ivec4 dst = {99, 99, 99, 99}; + + GLM(ivec4_copy)(src, dst); + ASSERT(dst[0] == 7) + ASSERT(dst[1] == 5) + ASSERT(dst[2] == 2) + ASSERT(dst[3] == 11) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_zero) { + ivec4 v = {2, 3, 5, 7}; + + GLM(ivec4_zero)(v); + ASSERT(v[0] == 0) + ASSERT(v[1] == 0) + ASSERT(v[2] == 0) + ASSERT(v[3] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_one) { + ivec4 v = {-2, 9, 12, 7}; + + GLM(ivec4_one)(v); + ASSERT(v[0] == 1) + ASSERT(v[1] == 1) + ASSERT(v[2] == 1) + ASSERT(v[3] == 1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_add) { + ivec4 a = {14, 3, 2, -4}; + ivec4 b = {-3, 2, 1, -1}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_add)(a, b, v); + ASSERT(v[0] == 11) + ASSERT(v[1] == 5) + ASSERT(v[2] == 3) + ASSERT(v[3] == -5) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_adds) { + ivec4 a = {-3, 1, 4, 2}; + ivec4 v = {99, 99, 99, 99}; + int s = -2; + + GLM(ivec4_adds)(a, s, v); + ASSERT(v[0] == -5) + ASSERT(v[1] == -1) + ASSERT(v[2] == 2) + ASSERT(v[3] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_sub) { + ivec4 a = {-2, 9, 1, 5}; + ivec4 b = {3, 2, -1, 2}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_sub)(a, b, v); + ASSERT(v[0] == -5) + ASSERT(v[1] == 7) + ASSERT(v[2] == 2) + ASSERT(v[3] == 3) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_subs) { + ivec4 a = {5, -2, 6, 1}; + ivec4 v = {99, 99, 99, 99}; + int s = 2; + + GLM(ivec4_subs)(a, s, v); + ASSERT(v[0] == 3) + ASSERT(v[1] == -4) + ASSERT(v[2] == 4) + ASSERT(v[3] == -1) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_mul) { + ivec4 a = {3, 4, 5, -3}; + ivec4 b = {-2, 3, 1, 2}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_mul)(a, b, v); + ASSERT(v[0] == -6) + ASSERT(v[1] == 12) + ASSERT(v[2] == 5) + ASSERT(v[3] == -6) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_scale) { + ivec4 a = {-9, 2, 3, 0}; + ivec4 v = {99, 99, 99, 99}; + int s = -2; + + GLM(ivec4_scale)(a, s, v); + ASSERT(v[0] == 18) + ASSERT(v[1] == -4) + ASSERT(v[2] == -6) + ASSERT(v[3] == 0) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_distance2) { + ivec4 a = {-1, 3, 0, 4}; + ivec4 b = {5, 4, 2, 6}; + int v; + + v = GLM(ivec4_distance2)(a, b); + ASSERT(v == 45) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_distance) { + ivec4 a = {3, 2, 4, -1}; + ivec4 b = {-2, 5, 2, 4}; + float v; + + v = GLM(ivec4_distance)(a, b); + ASSERT(test_eq(v, 7.9372539331)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_maxv) { + ivec4 a = {9, -20, 5, -3}; + ivec4 b = {8, -1, 2, 2}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_maxv)(a, b, v); + ASSERT(v[0] == 9) + ASSERT(v[1] == -1) + ASSERT(v[2] == 5) + ASSERT(v[3] == 2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_minv) { + ivec4 a = {16, 0, 4, 5}; + ivec4 b = {-15, 10, 8, 2}; + ivec4 v = {99, 99, 99, 99}; + + GLM(ivec4_minv)(a, b, v); + ASSERT(v[0] == -15) + ASSERT(v[1] == 0) + ASSERT(v[2] == 4) + ASSERT(v[3] == 2) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, ivec4_clamp) { + ivec4 v = {3, -1, 10, -100}; + + GLM(ivec4_clamp)(v, -2, 4); + ASSERT(v[0] == 3) + ASSERT(v[1] == -1) + ASSERT(v[2] == 4) + ASSERT(v[3] == -2) + + v[0] = -15; + v[1] = 4; + v[2] = 1; + v[3] = 0; + GLM(ivec4_clamp)(v, -9, 3); + ASSERT(v[0] == -9) + ASSERT(v[1] == 3) + ASSERT(v[2] == 1) + ASSERT(v[3] == 0) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_mat2.h b/libs/cglm/test/src/test_mat2.h new file mode 100644 index 0000000..9141caf --- /dev/null +++ b/libs/cglm/test/src/test_mat2.h @@ -0,0 +1,286 @@ +/* + * 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 A_MATRIX2x2 {{1,2},{5,6}} + +#ifndef CGLM_TEST_MAT2_ONCE +#define CGLM_TEST_MAT2_ONCE + +TEST_IMPL(MACRO_GLM_MAT2_IDENTITY_INIT) { + mat2 m = GLM_MAT2_IDENTITY_INIT; + + ASSERT(test_eq(m[0][0], 1.0f)) + ASSERT(test_eq(m[0][1], 0.0f)) + ASSERT(test_eq(m[1][0], 0.0f)) + ASSERT(test_eq(m[1][1], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_MAT2_ZERO_INIT) { + mat2 m = GLM_MAT2_ZERO_INIT; + + ASSERT(test_eq(m[0][0], 0.0f)) + ASSERT(test_eq(m[0][1], 0.0f)) + ASSERT(test_eq(m[1][0], 0.0f)) + ASSERT(test_eq(m[1][1], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_MAT2_IDENTITY) { + ASSERT(test_eq(GLM_MAT2_IDENTITY[0][0], 1.0f)) + ASSERT(test_eq(GLM_MAT2_IDENTITY[0][1], 0.0f)) + ASSERT(test_eq(GLM_MAT2_IDENTITY[1][0], 0.0f)) + ASSERT(test_eq(GLM_MAT2_IDENTITY[1][1], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_MAT2_ZERO) { + ASSERT(test_eq(GLM_MAT2_ZERO[0][0], 0.0f)) + ASSERT(test_eq(GLM_MAT2_ZERO[0][1], 0.0f)) + ASSERT(test_eq(GLM_MAT2_ZERO[1][0], 0.0f)) + ASSERT(test_eq(GLM_MAT2_ZERO[1][1], 0.0f)) + + TEST_SUCCESS +} + +#endif /* CGLM_TEST_MAT2_ONCE */ + +TEST_IMPL(GLM_PREFIX, mat2_copy) { + mat2 m1 = A_MATRIX2x2; + mat2 m2 = GLM_MAT2_IDENTITY_INIT; + + GLM(mat2_copy)(m1, m2); + + test_assert_mat2_eq(m1, m2); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_identity) { + mat2 m1 = GLM_MAT2_IDENTITY_INIT; + mat2 m2 = GLM_MAT2_IDENTITY_INIT; + mat2 m3; + + GLM(mat2_identity)(m3); + + ASSERTIFY(test_assert_mat2_eq_identity(m1)) + ASSERTIFY(test_assert_mat2_eq_identity(m2)) + ASSERTIFY(test_assert_mat2_eq_identity(m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_identity_array) { + int i, count; + mat2 matrices[4] = { + A_MATRIX2x2, + A_MATRIX2x2, + A_MATRIX2x2, + A_MATRIX2x2 + }; + + count = 4; + + GLM(mat2_identity_array)(matrices, count); + + for (i = 0; i < count; i++) { + ASSERTIFY(test_assert_mat2_eq_identity(matrices[i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_zero) { + mat2 m1 = GLM_MAT2_ZERO_INIT; + mat2 m2 = GLM_MAT2_ZERO_INIT; + mat2 m3; + + GLM(mat2_zero)(m3); + + ASSERTIFY(test_assert_mat2_eq_zero(m1)) + ASSERTIFY(test_assert_mat2_eq_zero(m2)) + ASSERTIFY(test_assert_mat2_eq_zero(m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_mul) { + mat2 m1 = GLM_MAT2_IDENTITY_INIT; + mat2 m2 = GLM_MAT2_IDENTITY_INIT; + mat2 m3; + mat2 m4 = GLM_MAT2_ZERO_INIT; + int i, j, k; + + /* test random matrices */ + /* random matrices */ + test_rand_mat2(m1); + test_rand_mat2(m2); + + GLM(mat2_mul)(m1, m2, m3); + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + for (k = 0; k < 2; k++) + /* column-major */ + m4[i][j] += m1[k][j] * m2[i][k]; + } + } + + ASSERTIFY(test_assert_mat2_eq(m3, m4)) + + /* test pre compiled */ + GLM(mat2_mul)(m1, m2, m3); + ASSERTIFY(test_assert_mat2_eq(m3, m4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_transpose_to) { + mat2 mat = A_MATRIX2x2; + mat2 m1; + + GLM(mat2_transpose_to)(mat, m1); + + ASSERTIFY(test_assert_mat2_eqt(mat, m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_transpose) { + mat2 mat = A_MATRIX2x2; + mat2 m1; + + GLM(mat2_copy)(mat, m1); + GLM(mat2_transpose)(m1); + + ASSERTIFY(test_assert_mat2_eqt(mat, m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_mulv) { + vec2 res; + mat2 mat = A_MATRIX2x2; + vec2 v = {11.0f, 21.0f}; + int i; + + GLM(mat2_mulv)(mat, v, res); + + for (i = 0; i < 2; i++) { + ASSERT(test_eq(res[i], v[0] * mat[0][i] + v[1] * mat[1][i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_trace) { + mat2 mat = A_MATRIX2x2; + float trace; + + trace = GLM(mat2_trace)(mat); + + ASSERT(test_eq(trace, mat[0][0] + mat[1][1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_scale) { + mat2 m1 = A_MATRIX2x2; + mat2 m2 = A_MATRIX2x2; + int i, j, scale; + + scale = rand() % 100; + + GLM(mat2_scale)(m1, (float)scale); + + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + ASSERT(test_eq(m1[i][j], m2[i][j] * scale)) + } + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_det) { + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_inv) { + mat2 m1 = GLM_MAT2_IDENTITY_INIT; + mat2 m2 = GLM_MAT2_IDENTITY_INIT; + mat2 m3; + int i; + + m1[0][0] = 41.0f; + m1[0][1] = 0.0f; + m1[1][0] = 0.0f; + m1[1][1] = 70.0f; + + for (i = 0; i < 10000; i++) { + /* test inverse precise */ + GLM(mat2_inv)(m1, m2); + GLM(mat2_inv)(m2, m3); + + ASSERTIFY(test_assert_mat2_eq(m1, m3)) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_swap_col) { + mat2 m1 = A_MATRIX2x2; + mat2 m2 = A_MATRIX2x2; + + GLM(mat2_swap_col)(m1, 0, 1); + + ASSERTIFY(test_assert_vec2_eq(m1[0], m2[1])) + ASSERTIFY(test_assert_vec2_eq(m1[1], m2[0])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_swap_row) { + mat2 m1 = A_MATRIX2x2; + mat2 m2 = A_MATRIX2x2; + + GLM(mat2_swap_row)(m1, 0, 1); + + ASSERT(test_eq(m1[0][0], m2[0][1])) + ASSERT(test_eq(m1[0][1], m2[0][0])) + + ASSERT(test_eq(m1[1][0], m2[1][1])) + ASSERT(test_eq(m1[1][1], m2[1][0])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat2_rmc) { + mat2 mat = A_MATRIX2x2; + vec2 v = {11.0f, 12.0f}; + vec2 v1; + float r1, r2; + int i; + + r1 = GLM(mat2_rmc)(v, mat, v); + + for (i = 0; i < 2; i++) { + v1[i] = v[0] * mat[i][0] + v[1] * mat[i][1]; + } + + r2 = v[0] * v1[0] + v[1] * v1[1]; + + ASSERT(test_eq(r1, r2)) + + TEST_SUCCESS +} + +#undef A_MATRIX2x2 diff --git a/libs/cglm/test/src/test_mat3.h b/libs/cglm/test/src/test_mat3.h new file mode 100644 index 0000000..76b1786 --- /dev/null +++ b/libs/cglm/test/src/test_mat3.h @@ -0,0 +1,311 @@ +/* + * 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 A_MATRIX {{1,2,3},{5,6,7},{9,10,11}} + +TEST_IMPL(GLM_PREFIX, mat3_copy) { + mat3 m1 = A_MATRIX; + mat3 m2 = GLM_MAT3_IDENTITY_INIT; + + GLM(mat3_copy)(m1, m2); + + test_assert_mat3_eq(m1, m2); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_identity) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT; + mat3 m2 = GLM_MAT3_IDENTITY_INIT; + mat3 m3; + + GLM(mat3_identity)(m3); + + ASSERTIFY(test_assert_mat3_eq_identity(m1)) + ASSERTIFY(test_assert_mat3_eq_identity(m2)) + ASSERTIFY(test_assert_mat3_eq_identity(m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_identity_array) { + int i, count; + mat3 matrices[4] = { + A_MATRIX, + A_MATRIX, + A_MATRIX, + A_MATRIX + }; + + count = 4; + + GLM(mat3_identity_array)(matrices, count); + + for (i = 0; i < count; i++) { + ASSERTIFY(test_assert_mat3_eq_identity(matrices[i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_zero) { + mat3 m1 = GLM_MAT3_ZERO_INIT; + mat3 m2 = GLM_MAT3_ZERO_INIT; + mat3 m3; + + GLM(mat3_zero)(m3); + + ASSERTIFY(test_assert_mat3_eq_zero(m1)) + ASSERTIFY(test_assert_mat3_eq_zero(m2)) + ASSERTIFY(test_assert_mat3_eq_zero(m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_mul) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT; + mat3 m2 = GLM_MAT3_IDENTITY_INIT; + mat3 m3; + mat3 m4 = GLM_MAT3_ZERO_INIT; + int i, j, k; + + /* test random matrices */ + /* random matrices */ + test_rand_mat3(m1); + test_rand_mat3(m2); + + GLM(mat3_mul)(m1, m2, m3); + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + for (k = 0; k < 3; k++) + /* column-major */ + m4[i][j] += m1[k][j] * m2[i][k]; + } + } + + ASSERTIFY(test_assert_mat3_eq(m3, m4)) + + /* test pre compiled */ + GLM(mat3_mul)(m1, m2, m3); + ASSERTIFY(test_assert_mat3_eq(m3, m4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_mulv) { + vec4 res; + mat3 mat = A_MATRIX; + vec4 v = {1.0f, 2.0f, 3.0f, 4.0f}; + int i; + + GLM(mat3_mulv)(mat, v, res); + + for (i = 0; i < 3; i++) { + ASSERT(test_eq(res[i], + v[0] * mat[0][i] + + v[1] * mat[1][i] + + v[2] * mat[2][i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_trace) { + mat3 mat = A_MATRIX; + float trace; + + trace = GLM(mat3_trace)(mat); + + ASSERT(test_eq(trace, mat[0][0] + mat[1][1] + mat[2][2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_quat) { + mat3 m1, m3; + mat4 m2; + versor q1, q2, q3; + vec3 axis1; + vec3 axis2 = {1.9f, 2.3f, 4.5f}; + + GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); + GLM(quat_mat3)(q1, m1); + GLM(mat3_quat)(m1, q2); + + GLM(rotate_make)(m2, GLM_PI_4f, axis2); + GLM(mat3_quat)(m1, q3); + + GLM(quat_axis)(q3, axis1); + + GLM(vec3_normalize)(axis1); + GLM(vec3_normalize)(axis2); + + GLM(mat4_pick3)(m2, m3); + + ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f)) + ASSERTIFY(test_assert_vec3_eq(axis1, axis2)) + ASSERTIFY(test_assert_vec4_eq(q1, q2)) + ASSERTIFY(test_assert_mat3_eq(m1, m3)) + ASSERTIFY(test_assert_vec4_eq(q1, q3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_transpose_to) { + mat3 mat = A_MATRIX; + mat3 m1; + + GLM(mat3_transpose_to)(mat, m1); + + ASSERTIFY(test_assert_mat3_eqt(mat, m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_transpose) { + mat3 mat = A_MATRIX; + mat3 m1; + + GLM(mat3_copy)(mat, m1); + GLM(mat3_transpose)(m1); + + ASSERTIFY(test_assert_mat3_eqt(mat, m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_scale) { + mat3 m1 = A_MATRIX; + mat3 m2 = A_MATRIX; + int i, j, k, scale; + + scale = rand() % 100; + + GLM(mat3_scale)(m1, (float)scale); + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + for (k = 0; k < 3; k++) + ASSERT(test_eq(m1[i][j], m2[i][j] * scale)) + } + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_det) { + mat3 mat; + float a, b, c, + d, e, f, + g, h, i; + float det1, det2; + + test_rand_mat3(mat); + + 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]; + + det1 = a * (e * i - h * f) - d * (b * i - c * h) + g * (b * f - c * e); + det2 = GLM(mat3_det)(mat); + + ASSERT(test_eq(det1, det2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_inv) { + mat3 m1 = GLM_MAT3_IDENTITY_INIT; + mat3 m2 = GLM_MAT3_IDENTITY_INIT; + mat3 m3; + int i; + + for (i = 0; i < 100000; i++) { + test_rand_mat3(m1); + test_rand_mat3(m2); + + /* test inverse precise */ + GLM(mat3_inv)(m1, m2); + GLM(mat3_inv)(m2, m3); + ASSERTIFY(test_assert_mat3_eq(m1, m3)) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_swap_col) { + mat3 m1 = A_MATRIX; + mat3 m2 = A_MATRIX; + + GLM(mat3_swap_col)(m1, 0, 1); + + ASSERTIFY(test_assert_vec3_eq(m1[0], m2[1])) + ASSERTIFY(test_assert_vec3_eq(m1[1], m2[0])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_swap_row) { + mat3 m1 = A_MATRIX; + mat3 m2 = A_MATRIX; + + GLM(mat3_swap_row)(m1, 0, 1); + + ASSERT(test_eq(m1[0][0], m2[0][1])) + ASSERT(test_eq(m1[0][1], m2[0][0])) + ASSERT(test_eq(m1[0][2], m2[0][2])) + + ASSERT(test_eq(m1[1][0], m2[1][1])) + ASSERT(test_eq(m1[1][1], m2[1][0])) + ASSERT(test_eq(m1[1][2], m2[1][2])) + + ASSERT(test_eq(m1[2][0], m2[2][1])) + ASSERT(test_eq(m1[2][1], m2[2][0])) + ASSERT(test_eq(m1[2][2], m2[2][2])) + + GLM(mat3_swap_row)(m1, 1, 2); + + ASSERT(test_eq(m1[0][0], m2[0][1])) + ASSERT(test_eq(m1[0][1], m2[0][2])) + ASSERT(test_eq(m1[0][2], m2[0][0])) + + ASSERT(test_eq(m1[1][0], m2[1][1])) + ASSERT(test_eq(m1[1][1], m2[1][2])) + ASSERT(test_eq(m1[1][2], m2[1][0])) + + ASSERT(test_eq(m1[2][0], m2[2][1])) + ASSERT(test_eq(m1[2][1], m2[2][2])) + ASSERT(test_eq(m1[2][2], m2[2][0])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat3_rmc) { + mat3 mat = A_MATRIX; + vec3 v = {11.0f, 12.0f, 13.0f}; + vec3 v1; + float r1, r2; + int i; + + r1 = GLM(mat3_rmc)(v, mat, v); + + for (i = 0; i < 3; i++) { + v1[i] = v[0] * mat[i][0] + + v[1] * mat[i][1] + + v[2] * mat[i][2]; + } + + r2 = v[0] * v1[0] + v[1] * v1[1] + v[2] * v1[2]; + + ASSERT(test_eq(r1, r2)) + + TEST_SUCCESS +} + +#undef A_MATRIX diff --git a/libs/cglm/test/src/test_mat4.h b/libs/cglm/test/src/test_mat4.h new file mode 100644 index 0000000..d42e457 --- /dev/null +++ b/libs/cglm/test/src/test_mat4.h @@ -0,0 +1,488 @@ +/* + * 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 A_MATRIX {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}} +#define A_MATRIX3 {{1,2,3},{5,6,7},{9,10,11}} + +TEST_IMPL(GLM_PREFIX, mat4_ucopy) { + mat4 m1 = A_MATRIX; + mat4 m2 = GLM_MAT4_IDENTITY_INIT; + + GLM(mat4_ucopy)(m1, m2); + + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_copy) { + mat4 m1 = A_MATRIX; + mat4 m2 = GLM_MAT4_IDENTITY_INIT; + + GLM(mat4_copy)(m1, m2); + + test_assert_mat4_eq(m1, m2); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_identity) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + mat4 m2 = GLM_MAT4_IDENTITY_INIT; + mat4 m3; + + GLM(mat4_identity)(m3); + + ASSERTIFY(test_assert_mat4_eq_identity(m1)) + ASSERTIFY(test_assert_mat4_eq_identity(m2)) + ASSERTIFY(test_assert_mat4_eq_identity(m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_identity_array) { + int i, count; + mat4 matrices[4] = { + A_MATRIX, + A_MATRIX, + A_MATRIX, + A_MATRIX + }; + + count = 4; + + GLM(mat4_identity_array)(matrices, count); + + for (i = 0; i < count; i++) { + ASSERTIFY(test_assert_mat4_eq_identity(matrices[i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_zero) { + mat4 m1 = GLM_MAT4_ZERO_INIT; + mat4 m2 = GLM_MAT4_ZERO_INIT; + mat4 m3; + + GLM(mat4_zero)(m3); + + ASSERTIFY(test_assert_mat4_eq_zero(m1)) + ASSERTIFY(test_assert_mat4_eq_zero(m2)) + ASSERTIFY(test_assert_mat4_eq_zero(m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_pick3) { + mat4 m1 = A_MATRIX; + mat3 m2 = GLM_MAT3_ZERO_INIT; + mat3 m3 = A_MATRIX3; + + GLM(mat4_pick3)(m1, m2); + + ASSERTIFY(test_assert_mat3_eq(m2, m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_pick3t) { + mat4 m1 = A_MATRIX; + mat3 m2 = GLM_MAT3_ZERO_INIT; + mat3 m3 = A_MATRIX3; + + GLM(mat4_pick3t)(m1, m2); + + ASSERTIFY(test_assert_mat3_eqt(m2, m3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_ins3) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + mat3 m2 = A_MATRIX3; + int i, j; + + GLM(mat4_ins3)(m2, m1); + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + ASSERT(m1[i][j] == m2[i][j]) + } + } + + ASSERT(test_eq(m1[3][0], 0.0f)) + ASSERT(test_eq(m1[3][1], 0.0f)) + ASSERT(test_eq(m1[3][2], 0.0f)) + ASSERT(test_eq(m1[3][3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_mul) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + mat4 m2 = GLM_MAT4_IDENTITY_INIT; + mat4 m3; + mat4 m4 = GLM_MAT4_ZERO_INIT; + int i, j, k; + + /* test random matrices */ + /* random matrices */ + test_rand_mat4(m1); + test_rand_mat4(m2); + + GLM(mat4_mul)(m1, m2, m3); + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) + /* column-major */ + m4[i][j] += m1[k][j] * m2[i][k]; + } + } + + ASSERTIFY(test_assert_mat4_eq(m3, m4)) + + /* test pre compiled */ + GLM(mat4_mul)(m1, m2, m3); + ASSERTIFY(test_assert_mat4_eq(m3, m4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_mulN) { + mat4 res1, res2; + mat4 m1 = A_MATRIX; + mat4 m2 = A_MATRIX; + mat4 m3 = A_MATRIX; + + mat4 *matrices[] = { + &m1, &m2, &m3 + }; + + GLM(mat4_mulN)(matrices, sizeof(matrices) / sizeof(matrices[0]), res1); + + GLM(mat4_mul)(*matrices[0], *matrices[1], res2); + GLM(mat4_mul)(res2, *matrices[2], res2); + + ASSERTIFY(test_assert_mat4_eq(res1, res1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_mulv) { + vec4 res; + mat4 mat = A_MATRIX; + vec4 v = {1.0f, 2.0f, 3.0f, 4.0f}; + int i; + + GLM(mat4_mulv)(mat, v, res); + + for (i = 0; i < 4; i++) { + ASSERT(test_eq(res[i], + v[0] * mat[0][i] + + v[1] * mat[1][i] + + v[2] * mat[2][i] + + v[3] * mat[3][i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_mulv3) { + vec4 res; + mat4 mat = A_MATRIX; + vec3 v = {1.0f, 2.0f, 3.0f}; + float last; + int i; + + last = 1.0f; + + GLM(mat4_mulv3)(mat, v, last, res); + + for (i = 0; i < 3; i++) { + ASSERT(test_eq(res[i], + v[0] * mat[0][i] + + v[1] * mat[1][i] + + v[2] * mat[2][i] + + last * mat[3][i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_trace) { + mat4 mat = A_MATRIX; + float trace; + + trace = GLM(mat4_trace)(mat); + + ASSERT(test_eq(trace, mat[0][0] + mat[1][1] + mat[2][2] + mat[3][3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_trace3) { + mat4 mat = A_MATRIX; + float trace; + + trace = GLM(mat4_trace3)(mat); + + ASSERT(test_eq(trace, mat[0][0] + mat[1][1] + mat[2][2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_quat) { + mat4 m1, m2; + versor q1, q2, q3; + vec3 axis1; + vec3 axis2 = {1.9f, 2.3f, 4.5f}; + + GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); + GLM(quat_mat4)(q1, m1); + GLM(mat4_quat)(m1, q2); + + GLM(rotate_make)(m2, GLM_PI_4f, axis2); + GLM(mat4_quat)(m1, q3); + + GLM(quat_axis)(q3, axis1); + + GLM(vec3_normalize)(axis1); + GLM(vec3_normalize)(axis2); + + ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f)) + ASSERTIFY(test_assert_vec3_eq(axis1, axis2)) + ASSERTIFY(test_assert_vec4_eq(q1, q2)) + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + ASSERTIFY(test_assert_vec4_eq(q1, q3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_transpose_to) { + mat4 mat = A_MATRIX; + mat4 m1; + + GLM(mat4_transpose_to)(mat, m1); + + ASSERTIFY(test_assert_mat4_eqt(mat, m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_transpose) { + mat4 mat = A_MATRIX; + mat4 m1; + + GLM(mat4_copy)(mat, m1); + GLM(mat4_transpose)(m1); + + ASSERTIFY(test_assert_mat4_eqt(mat, m1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_scale_p) { + mat4 m1 = A_MATRIX; + mat4 m2 = A_MATRIX; + int i, j, k, scale; + + scale = rand() % 100; + + GLM(mat4_scale_p)(m1, (float)scale); + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) + ASSERT(test_eq(m1[i][j], m2[i][j] * scale)) + } + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_scale) { + mat4 m1 = A_MATRIX; + mat4 m2 = A_MATRIX; + int i, j, k, scale; + + scale = rand() % 100; + + GLM(mat4_scale)(m1, (float)scale); + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) + ASSERT(test_eq(m1[i][j], m2[i][j] * scale)) + } + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_det) { + mat4 mat = GLM_MAT4_IDENTITY_INIT; + float t[6]; + float a, b, c, d, + e, f, g, h, + i, j, k, l, + m, n, o, p; + float det1, det2; + + test_rand_mat4(mat); + + a = mat[0][0]; b = mat[0][1]; c = mat[0][2]; d = mat[0][3]; + e = mat[1][0]; f = mat[1][1]; g = mat[1][2]; h = mat[1][3]; + i = mat[2][0]; j = mat[2][1]; k = mat[2][2]; l = mat[2][3]; + m = mat[3][0]; n = mat[3][1]; o = mat[3][2]; p = mat[3][3]; + + t[0] = k * p - o * l; + t[1] = j * p - n * l; + t[2] = j * o - n * k; + t[3] = i * p - m * l; + t[4] = i * o - m * k; + t[5] = i * n - m * j; + + det1 = a * (f * t[0] - g * t[1] + h * t[2]) + - b * (e * t[0] - g * t[3] + h * t[4]) + + c * (e * t[1] - f * t[3] + h * t[5]) + - d * (e * t[2] - f * t[4] + g * t[5]); + + det2 = GLM(mat4_det(mat)); + + ASSERT(test_eq(det1, det2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_inv) { + mat4 m1, m2, m3; + int i; + + for (i = 0; i < 100000; i++) { + test_rand_mat4(m1); + test_rand_mat4(m2); + + /* test inverse precise */ + GLM(mat4_inv)(m1, m2); + GLM(mat4_inv)(m2, m3); + ASSERTIFY(test_assert_mat4_eq(m1, m3)) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_inv_precise) { + mat4 m1, m2, m3; + mat4 m4, m5, m6; + int i; + + for (i = 0; i < 100000; i++) { + test_rand_mat4(m1); + test_rand_mat4(m2); + + glm_mat4_inv_precise(m1, m2); + glm_mat4_inv_precise(m2, m3); + ASSERTIFY(test_assert_mat4_eq(m1, m3)) + + test_rand_mat4(m4); + test_rand_mat4(m5); + + glmc_mat4_inv_precise(m4, m5); + glmc_mat4_inv_precise(m5, m6); + ASSERTIFY(test_assert_mat4_eq(m4, m6)) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_inv_fast) { + mat4 m1, m2, m3; + int i; + + for (i = 0; i < 100000; i++) { + test_rand_mat4(m1); + test_rand_mat4(m2); + + /* test inverse precise */ + GLM(mat4_inv_fast)(m1, m2); + GLM(mat4_inv_fast)(m2, m3); + ASSERTIFY(test_assert_mat4_eq2(m1, m3, 0.0009f)) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_swap_col) { + mat4 m1 = A_MATRIX; + mat4 m2 = A_MATRIX; + + GLM(mat4_swap_col)(m1, 0, 1); + GLM(mat4_swap_col)(m1, 2, 3); + + ASSERTIFY(test_assert_vec4_eq(m1[0], m2[1])) + ASSERTIFY(test_assert_vec4_eq(m1[1], m2[0])) + ASSERTIFY(test_assert_vec4_eq(m1[2], m2[3])) + ASSERTIFY(test_assert_vec4_eq(m1[3], m2[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_swap_row) { + mat4 m1 = A_MATRIX; + mat4 m2 = A_MATRIX; + + GLM(mat4_swap_row)(m1, 0, 1); + GLM(mat4_swap_row)(m1, 2, 3); + + ASSERT(test_eq(m1[0][0], m2[0][1])) + ASSERT(test_eq(m1[0][1], m2[0][0])) + ASSERT(test_eq(m1[0][2], m2[0][3])) + ASSERT(test_eq(m1[0][3], m2[0][2])) + ASSERT(test_eq(m1[1][0], m2[1][1])) + ASSERT(test_eq(m1[1][1], m2[1][0])) + ASSERT(test_eq(m1[1][2], m2[1][3])) + ASSERT(test_eq(m1[1][3], m2[1][2])) + ASSERT(test_eq(m1[2][0], m2[2][1])) + ASSERT(test_eq(m1[2][1], m2[2][0])) + ASSERT(test_eq(m1[2][2], m2[2][3])) + ASSERT(test_eq(m1[2][3], m2[2][2])) + ASSERT(test_eq(m1[3][0], m2[3][1])) + ASSERT(test_eq(m1[3][1], m2[3][0])) + ASSERT(test_eq(m1[3][2], m2[3][3])) + ASSERT(test_eq(m1[3][3], m2[3][2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, mat4_rmc) { + mat4 mat = A_MATRIX; + vec4 v = {1.0f, 2.0f, 3.0f, 4.0f}; + vec4 v1; + float r1, r2; + int i; + + r1 = GLM(mat4_rmc)(v, mat, v); + + for (i = 0; i < 4; i++) { + v1[i] = v[0] * mat[i][0] + + v[1] * mat[i][1] + + v[2] * mat[i][2] + + v[3] * mat[i][3]; + } + + r2 = v[0] * v1[0] + v[1] * v1[1] + v[2] * v1[2] + v[3] * v1[3]; + + ASSERT(test_eq(r1, r2)) + + TEST_SUCCESS +} + +#undef A_MATRIX +#undef A_MATRIX3 diff --git a/libs/cglm/test/src/test_plane.h b/libs/cglm/test/src/test_plane.h new file mode 100644 index 0000000..896c8b5 --- /dev/null +++ b/libs/cglm/test/src/test_plane.h @@ -0,0 +1,39 @@ +/* + * 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" + +TEST_IMPL(GLM_PREFIX, plane_normalize) { + vec4 p1 = {2.0f, -3.0f, 4.0f, 5.0f}, p2 = {2.0f, -3.0f, 4.0f, 5.0f}; + float s = 1.0f; + float norm; + + GLM(plane_normalize)(p2); + + norm = sqrtf(p1[0] * p1[0] + p1[1] * p1[1] + p1[2] * p1[2]); + if (norm == 0.0f) { + ASSERT(test_eq(p1[0], 0.0f)) + ASSERT(test_eq(p1[1], 0.0f)) + ASSERT(test_eq(p1[2], 0.0f)) + ASSERT(test_eq(p1[3], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(p1[0] * norm, p2[0])) + ASSERT(test_eq(p1[1] * norm, p2[1])) + ASSERT(test_eq(p1[2] * norm, p2[2])) + ASSERT(test_eq(p1[3] * norm, p2[3])) + + glm_vec4_zero(p1); + GLM(plane_normalize)(p1); + ASSERTIFY(test_assert_vec4_eq(p1, GLM_VEC4_ZERO)) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_project.h b/libs/cglm/test/src/test_project.h new file mode 100644 index 0000000..41bdecd --- /dev/null +++ b/libs/cglm/test/src/test_project.h @@ -0,0 +1,92 @@ +/* + * 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" + +TEST_IMPL(GLM_PREFIX, unprojecti) { + 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); + + GLM(project)(pos, mvp, viewport, projected); + + glm_mat4_inv(mvp, mvp); + GLM(unprojecti)(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(fabsf(pos[0] - unprojected[0]) < 0.01) + ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01) + ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, unproject) { + 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); + + GLM(project)(pos, mvp, viewport, projected); + GLM(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(fabsf(pos[0] - unprojected[0]) < 0.01) + ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01) + ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, project) { + 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); + + GLM(project)(pos, mvp, viewport, projected); + GLM(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(fabsf(pos[0] - unprojected[0]) < 0.01) + ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01) + ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01) + + /* test with no projection */ + glm_mat4_identity(mvp); + + GLM(project)(pos, mvp, viewport, projected); + GLM(unproject)(projected, mvp, viewport, unprojected); + + ASSERT(test_eq(pos[0], unprojected[0])) + ASSERT(test_eq(pos[1], unprojected[1])) + ASSERT(test_eq(pos[2], unprojected[2])) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_quat.h b/libs/cglm/test/src/test_quat.h new file mode 100644 index 0000000..ab85b19 --- /dev/null +++ b/libs/cglm/test/src/test_quat.h @@ -0,0 +1,1086 @@ +/* + * 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" + +#ifndef CGLM_TEST_QUAT_ONCE +#define CGLM_TEST_QUAT_ONCE + +/* Macros */ + +TEST_IMPL(MACRO_GLM_QUAT_IDENTITY_INIT) { + versor v = GLM_QUAT_IDENTITY_INIT; + + ASSERT(test_eq(v[0], 0.0f)) + ASSERT(test_eq(v[1], 0.0f)) + ASSERT(test_eq(v[2], 0.0f)) + ASSERT(test_eq(v[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_QUAT_IDENTITY) { + ASSERT(test_eq(GLM_QUAT_IDENTITY[0], 0.0f)) + ASSERT(test_eq(GLM_QUAT_IDENTITY[1], 0.0f)) + ASSERT(test_eq(GLM_QUAT_IDENTITY[2], 0.0f)) + ASSERT(test_eq(GLM_QUAT_IDENTITY[3], 1.0f)) + + TEST_SUCCESS +} + +#endif /* CGLM_TEST_QUAT_ONCE */ + +TEST_IMPL(GLM_PREFIX, quat_identity) { + versor a = GLM_QUAT_IDENTITY_INIT; + versor b = GLM_QUAT_IDENTITY_INIT; + versor c; + mat4 r; + + GLM(quat_identity)(c); + + ASSERTIFY(test_assert_quat_eq_identity(a)) + ASSERTIFY(test_assert_quat_eq_identity(b)) + ASSERTIFY(test_assert_quat_eq_identity(c)) + + glm_quat_identity(c); + ASSERT(test_eq(glm_quat_real(c), cosf(glm_rad(0.0f) * 0.5f))) + + glm_quat_mat4(c, r); + ASSERTIFY(test_assert_mat4_eq2(r, GLM_MAT4_IDENTITY, 0.000009f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_identity_array) { + int i, count; + versor quats[4] = { + {1.0f, 2.0f, 3.0f, 4.0f}, + {1.0f, 2.0f, 3.0f, 4.0f}, + {1.0f, 2.0f, 3.0f, 4.0f}, + {1.0f, 2.0f, 3.0f, 4.0f}, + }; + + count = 4; + + GLM(quat_identity_array)(quats, count); + + for (i = 0; i < count; i++) { + ASSERTIFY(test_assert_quat_eq_identity(quats[i])) + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_init) { + versor q1 = {1.0f, 2.0f, 3.0f, 4.0f}; + versor q2 = {1.0f, 2.0f, 3.0f, 4.0f}; + versor q3 = {1.0f, 2.0f, 3.0f, 4.0f}; + + GLM(quat_init)(q1, 10.0f, 11.0f, 12.0f, 13.0f); + GLM(quat_init)(q2, 100.0f, 110.0f, 120.0f, 130.0f); + GLM(quat_init)(q3, 1000.0f, 1100.0f, 1200.0f, 1300.0f); + + ASSERT(q1[0] == 10.0f) + ASSERT(q1[1] == 11.0f) + ASSERT(q1[2] == 12.0f) + ASSERT(q1[3] == 13.0f) + + ASSERT(q2[0] == 100.0f) + ASSERT(q2[1] == 110.0f) + ASSERT(q2[2] == 120.0f) + ASSERT(q2[3] == 130.0f) + + ASSERT(q3[0] == 1000.0f) + ASSERT(q3[1] == 1100.0f) + ASSERT(q3[2] == 1200.0f) + ASSERT(q3[3] == 1300.0f) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quatv) { + versor q1 = {1.0f, 2.0f, 3.0f, 4.0f}; + vec3 v1, v2; + float a1; + + test_rand_vec3(v1); + GLM(quatv)(q1, glm_rad(60.0f), v1); + + glm_quat_axis(q1, v2); + a1 = glm_quat_angle(q1); + + ASSERT(test_eq(a1, glm_rad(60.0f))) + + glm_vec3_normalize(v1); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat) { + versor q1 = {1.0f, 2.0f, 3.0f, 4.0f}; + vec3 v1, v2; + float a1; + + test_rand_vec3(v1); + GLM(quat)(q1, glm_rad(60.0f), v1[0], v1[1], v1[2]); + + glm_quat_axis(q1, v2); + a1 = glm_quat_angle(q1); + + ASSERT(test_eq(a1, glm_rad(60.0f))) + + glm_vec3_normalize(v1); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_copy) { + versor v1 = {10.0f, 9.0f, 8.0f, 78.0f}; + versor v2 = {1.0f, 2.0f, 3.0f, 4.0f}; + + GLM(quat_copy)(v1, v2); + + ASSERTIFY(test_assert_vec4_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_from_vecs) { + versor q1, q2, q3, q4, q5, q6, q7; + vec3 v1 = {1.f, 0.f, 0.f}, v2 = {1.f, 0.f, 0.f}; /* parallel */ + vec3 v3 = {0.f, 1.f, 0.f}, v4 = {1.f, 0.f, 0.f}; /* perpendicular */ + vec3 v5 = {0.f, 0.f, 1.f}, v6 = {0.f, 0.f, -1.f}; /* straight */ + vec3 v7, v8; /* random */ + vec3 v9 = {0.57735026f, 0.57735026f, 0.57735026f}, /* acute */ + v10 = {0.70710678f, 0.70710678f, 0.f}; + vec3 v11 = {0.87287156f, 0.21821789f, 0.43643578f}, /* obtuse */ + v12 = {-0.87287156f, 0.21821789f, 0.43643578f}; + vec3 v13 = GLM_VEC3_ZERO_INIT; /* zero */ + + GLM(quat_from_vecs)(v1, v2, q1); + ASSERTIFY(test_assert_quat_eq_identity(q1)) + + GLM(quat_from_vecs)(v3, v4, q2); + GLM(quat_rotatev)(q2, v3, v3); + ASSERT(test_eq(GLM(vec3_dot)(v3, v4), 1.f)) + ASSERT(test_eq(q2[0], 0.f)) + ASSERT(test_eq(q2[1], 0.f)) + ASSERT(test_eq(q2[2], -0.707106781187f)) + ASSERT(test_eq(q2[3], 0.707106781187f)) + + GLM(quat_from_vecs)(v5, v6, q3); + GLM(quat_rotatev)(q3, v5, v5); + ASSERT(test_eq(GLM(vec3_dot)(v5, v6), 1.f)) + ASSERT(test_eq(q3[0], 0.f)) + ASSERT(test_eq(q3[1], -1.f)) + ASSERT(test_eq(q3[2], 0.f)) + ASSERT(test_eq(q3[3], 0.f)) + + test_rand_vec3(v7); + test_rand_vec3(v8); + GLM(vec3_normalize(v7)); + GLM(vec3_normalize(v8)); + GLM(quat_from_vecs)(v7, v8, q4); + GLM(quat_rotatev)(q4, v7, v7); + ASSERT(test_eq(GLM(vec3_dot)(v7, v8), 1.f)) + + GLM(quat_from_vecs)(v9, v10, q5); + GLM(quat_rotatev)(q5, v9, v9); + ASSERT(test_eq(GLM(vec3_dot)(v9, v10), 1.f)) + + GLM(quat_from_vecs)(v11, v12, q6); + GLM(quat_rotatev)(q6, v11, v11); + ASSERT(test_eq(GLM(vec3_dot)(v11, v12), 1.f)) + + GLM(quat_from_vecs)(v13, v1, q7); + ASSERTIFY(test_assert_quat_eq_identity(q7)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_norm) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + float n1, n2; + + n1 = GLM(quat_norm)(a); + n2 = sqrtf(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_normalize_to) { + versor v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2; + float s = 1.0f; + float norm; + + GLM(quat_normalize_to)(v1, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]); + if (norm <= 0.0f) { + ASSERTIFY(test_assert_quat_eq_identity(v1)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + ASSERT(test_eq(v1[3] * norm, v2[3])) + + glm_vec4_zero(v1); + GLM(quat_normalize_to)(v1, v2); + ASSERTIFY(test_assert_quat_eq_identity(v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_normalize) { + versor v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2 = {2.0f, -3.0f, 4.0f, 5.0f}; + float s = 1.0f; + float norm; + + GLM(quat_normalize)(v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]); + if (norm <= 0.0f) { + ASSERTIFY(test_assert_quat_eq_identity(v1)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + ASSERT(test_eq(v1[3] * norm, v2[3])) + + glm_vec4_zero(v1); + GLM(quat_normalize)(v1); + ASSERTIFY(test_assert_quat_eq_identity(v1)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_dot) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + float dot1, dot2; + + dot1 = GLM(quat_dot)(a, b); + dot2 = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; + + ASSERT(test_eq(dot1, dot2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_conjugate) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + versor d, e; + + GLM(quat_conjugate)(a, d); + GLM(quat_conjugate)(b, e); + + ASSERT(test_eq(d[0], -a[0])) + ASSERT(test_eq(d[1], -a[1])) + ASSERT(test_eq(d[2], -a[2])) + ASSERT(test_eq(d[3], a[3])) + + ASSERT(test_eq(e[0], -b[0])) + ASSERT(test_eq(e[1], -b[1])) + ASSERT(test_eq(e[2], -b[2])) + ASSERT(test_eq(e[3], b[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_inv) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + versor d, e; + float n1, n2; + + n1 = 1.0f / glm_vec4_norm2(a); + n2 = 1.0f / glm_vec4_norm2(b); + + GLM(quat_inv)(a, d); + GLM(quat_inv)(b, e); + + ASSERT(test_eq(d[0], -a[0] * n1)) + ASSERT(test_eq(d[1], -a[1] * n1)) + ASSERT(test_eq(d[2], -a[2] * n1)) + ASSERT(test_eq(d[3], a[3] * n1)) + + ASSERT(test_eq(e[0], -b[0] * n2)) + ASSERT(test_eq(e[1], -b[1] * n2)) + ASSERT(test_eq(e[2], -b[2] * n2)) + ASSERT(test_eq(e[3], b[3] * n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_add) { + versor a = {-10.0f, 9.0f, -8.0f, 56.0f}; + versor b = {12.0f, 19.0f, -18.0f, 1.0f}; + versor c, d; + + c[0] = a[0] + b[0]; + c[1] = a[1] + b[1]; + c[2] = a[2] + b[2]; + c[3] = a[3] + b[3]; + + GLM(quat_add)(a, b, d); + + ASSERTIFY(test_assert_quat_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_sub) { + vec4 a = {-10.0f, 9.0f, -8.0f, 56.0f}; + vec4 b = {12.0f, 19.0f, -18.0f, 1.0f}; + vec4 c, d; + + c[0] = a[0] - b[0]; + c[1] = a[1] - b[1]; + c[2] = a[2] - b[2]; + c[3] = a[3] - b[3]; + + GLM(quat_sub)(a, b, d); + + ASSERTIFY(test_assert_quat_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_real) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + + ASSERT(test_eq(GLM(quat_real)(a), 78.0f)) + ASSERT(test_eq(GLM(quat_real)(b), 4.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_imag) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + vec3 d, e; + + GLM(quat_imag)(a, d); + GLM(quat_imag)(b, e); + + ASSERT(test_eq(d[0], a[0])) + ASSERT(test_eq(d[1], a[1])) + ASSERT(test_eq(d[2], a[2])) + + ASSERT(test_eq(e[0], b[0])) + ASSERT(test_eq(e[1], b[1])) + ASSERT(test_eq(e[2], b[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_imagn) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + vec3 d, e; + + GLM(quat_imagn)(a, d); + GLM(quat_imagn)(b, e); + + glm_vec3_normalize(a); + glm_vec3_normalize(b); + glm_vec3_normalize(d); + glm_vec3_normalize(e); + + ASSERT(test_eq(d[0], a[0])) + ASSERT(test_eq(d[1], a[1])) + ASSERT(test_eq(d[2], a[2])) + + ASSERT(test_eq(e[0], b[0])) + ASSERT(test_eq(e[1], b[1])) + ASSERT(test_eq(e[2], b[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_imaglen) { + versor a = {10.0f, 9.0f, 8.0f, 78.0f}; + versor b = {1.0f, 2.0f, 3.0f, 4.0f}; + + ASSERT(test_eq(GLM(quat_imaglen)(a), glm_vec3_norm(a))); + ASSERT(test_eq(GLM(quat_imaglen)(b), glm_vec3_norm(b))); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_angle) { + versor q1 = {1.0f, 2.0f, 3.0f, 4.0f}, q2, q3; + vec3 v1; + float a1, a2, a3; + + test_rand_vec3(v1); + GLM(quatv)(q1, glm_rad(60.140f), v1); + GLM(quatv)(q2, glm_rad(160.04f), v1); + GLM(quatv)(q3, glm_rad(20.350f), v1); + + a1 = GLM(quat_angle)(q1); + a2 = GLM(quat_angle)(q2); + a3 = GLM(quat_angle)(q3); + + ASSERT(test_eq(a1, glm_rad(60.140f))) + ASSERT(test_eq(a2, glm_rad(160.04f))) + ASSERT(test_eq(a3, glm_rad(20.350f))) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_axis) { + versor q1 = {1.0f, 2.0f, 3.0f, 4.0f}, q2, q3; + vec3 v1, v2; + + test_rand_vec3(v1); + GLM(quatv)(q1, glm_rad(60.0f), v1); + + glm_quat_axis(q1, v2); + glm_vec3_normalize(v1); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + test_rand_vec3(v1); + GLM(quatv)(q2, glm_rad(60.0f), v1); + + glm_quat_axis(q2, v2); + glm_vec3_normalize(v1); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + test_rand_vec3(v1); + GLM(quatv)(q3, glm_rad(60.0f), v1); + + glm_quat_axis(q3, v2); + glm_vec3_normalize(v1); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_mul) { + versor q1 = {2.0f, 3.0f, 4.0f, 5.0f}; + versor q2 = {6.0f, 7.0f, 8.0f, 9.0f}; + versor q3; + versor q4; + vec3 v1 = {1.5f, 2.5f, 3.5f}; + + GLM(quat_mul)(q1, q2, q3); + + ASSERT(test_eq(q3[0], q1[3] * q2[0] + q1[0] * q2[3] + q1[1] * q2[2] - q1[2] * q2[1])) + ASSERT(test_eq(q3[1], q1[3] * q2[1] - q1[0] * q2[2] + q1[1] * q2[3] + q1[2] * q2[0])) + ASSERT(test_eq(q3[2], q1[3] * q2[2] + q1[0] * q2[1] - q1[1] * q2[0] + q1[2] * q2[3])) + ASSERT(test_eq(q3[3], q1[3] * q2[3] - q1[0] * q2[0] - q1[1] * q2[1] - q1[2] * q2[2])) + + glm_quatv(q1, glm_rad(30.0f), v1); + glm_quatv(q2, glm_rad(20.0f), v1); + glm_quatv(q3, glm_rad(50.0f), v1); + + GLM(quat_mul)(q1, q2, q4); + + ASSERTIFY(test_assert_quat_eq(q3, q4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_mat4) { + mat4 m1, m2; + versor q1, q2, q3; + vec3 axis1; + vec3 axis2 = {1.9f, 2.3f, 4.5f}; + int i; + + GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); + GLM(quat_mat4)(q1, m1); + GLM(mat4_quat)(m1, q2); + + GLM(rotate_make)(m2, GLM_PI_4f, axis2); + GLM(mat4_quat)(m1, q3); + + GLM(quat_axis)(q3, axis1); + + GLM(vec3_normalize)(axis1); + GLM(vec3_normalize)(axis2); + + ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f)) + ASSERTIFY(test_assert_vec3_eq(axis1, axis2)) + ASSERTIFY(test_assert_vec4_eq(q1, q2)) + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + ASSERTIFY(test_assert_vec4_eq(q1, q3)) + + /* 1. test quat to mat and mat to quat */ + for (i = 0; i < 1000; i++) { + test_rand_quat(q1); + + GLM(quat_mat4)(q1, m1); + GLM(mat4_quat)(m1, q2); + GLM(quat_mat4)(q2, m2); + + /* 2. test first quat and generated one equality */ + ASSERTIFY(test_assert_quat_eq_abs(q1, q2)); + + /* 3. test first rot and second rotation */ + /* almost equal */ + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f)); + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_mat4t) { + mat4 m1, m2; + versor q1, q2, q3; + vec3 axis1; + vec3 axis2 = {1.9f, 2.3f, 4.5f}; + int i; + + GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); + + GLM(quat_mat4t)(q1, m1); + glm_mat4_transpose(m1); + + GLM(mat4_quat)(m1, q2); + + GLM(rotate_make)(m2, GLM_PI_4f, axis2); + GLM(mat4_quat)(m1, q3); + + GLM(quat_axis)(q3, axis1); + + GLM(vec3_normalize)(axis1); + GLM(vec3_normalize)(axis2); + + ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f)) + ASSERTIFY(test_assert_vec3_eq(axis1, axis2)) + ASSERTIFY(test_assert_vec4_eq(q1, q2)) + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + ASSERTIFY(test_assert_vec4_eq(q1, q3)) + + /* 1. test quat to mat and mat to quat */ + for (i = 0; i < 1000; i++) { + test_rand_quat(q1); + + GLM(quat_mat4t)(q1, m1); + glm_mat4_transpose(m1); + + GLM(mat4_quat)(m1, q2); + + GLM(quat_mat4t)(q2, m2); + glm_mat4_transpose(m2); + + /* 2. test first quat and generated one equality */ + ASSERTIFY(test_assert_quat_eq_abs(q1, q2)); + + /* 3. test first rot and second rotation */ + /* almost equal */ + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f)); + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_mat3) { + mat4 m1, m2; + mat3 m3; + versor q1, q2, q3; + vec3 axis1; + vec3 axis2 = {1.9f, 2.3f, 4.5f}; + int i; + + GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); + GLM(quat_mat3)(q1, m3); + glm_mat4_identity(m1); + glm_mat4_ins3(m3, m1); + + GLM(mat4_quat)(m1, q2); + + GLM(rotate_make)(m2, GLM_PI_4f, axis2); + GLM(mat4_quat)(m1, q3); + + GLM(quat_axis)(q3, axis1); + + GLM(vec3_normalize)(axis1); + GLM(vec3_normalize)(axis2); + + ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f)) + ASSERTIFY(test_assert_vec3_eq(axis1, axis2)) + ASSERTIFY(test_assert_vec4_eq(q1, q2)) + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + ASSERTIFY(test_assert_vec4_eq(q1, q3)) + + /* 1. test quat to mat and mat to quat */ + for (i = 0; i < 1000; i++) { + test_rand_quat(q1); + + GLM(quat_mat3)(q1, m3); + glm_mat4_identity(m1); + glm_mat4_ins3(m3, m1); + + GLM(mat4_quat)(m1, q2); + + GLM(quat_mat3)(q2, m3); + glm_mat4_identity(m2); + glm_mat4_ins3(m3, m2); + + /* 2. test first quat and generated one equality */ + ASSERTIFY(test_assert_quat_eq_abs(q1, q2)); + + /* 3. test first rot and second rotation */ + /* almost equal */ + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f)); + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_mat3t) { + mat4 m1, m2; + mat3 m3; + versor q1, q2, q3; + vec3 axis1; + vec3 axis2 = {1.9f, 2.3f, 4.5f}; + int i; + + GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f); + + GLM(quat_mat3t)(q1, m3); + glm_mat3_transpose(m3); + glm_mat4_identity(m1); + glm_mat4_ins3(m3, m1); + + GLM(mat4_quat)(m1, q2); + + GLM(rotate_make)(m2, GLM_PI_4f, axis2); + GLM(mat4_quat)(m1, q3); + + GLM(quat_axis)(q3, axis1); + + GLM(vec3_normalize)(axis1); + GLM(vec3_normalize)(axis2); + + ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f)) + ASSERTIFY(test_assert_vec3_eq(axis1, axis2)) + ASSERTIFY(test_assert_vec4_eq(q1, q2)) + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + ASSERTIFY(test_assert_vec4_eq(q1, q3)) + + /* 1. test quat to mat and mat to quat */ + for (i = 0; i < 1000; i++) { + test_rand_quat(q1); + + GLM(quat_mat3t)(q1, m3); + glm_mat3_transpose(m3); + glm_mat4_identity(m1); + glm_mat4_ins3(m3, m1); + + GLM(mat4_quat)(m1, q2); + + GLM(quat_mat3t)(q2, m3); + glm_mat3_transpose(m3); + glm_mat4_identity(m2); + glm_mat4_ins3(m3, m2); + + /* 2. test first quat and generated one equality */ + ASSERTIFY(test_assert_quat_eq_abs(q1, q2)); + + /* 3. test first rot and second rotation */ + /* almost equal */ + ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f)); + } + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_lerp) { + versor v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + versor v2 = {100.0f, 200.0f, 10.0f, 10.0f}; + versor v3; + + GLM(quat_lerp)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + ASSERT(test_eq(v3[3], 0.0f)) + + GLM(quat_lerp)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_lerpc) { + versor v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + versor v2 = {100.0f, 200.0f, 10.0f, 10.0f}; + versor v3; + + GLM(quat_lerpc)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + ASSERT(test_eq(v3[3], 0.0f)) + + GLM(quat_lerpc)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + GLM(quat_lerpc)(v1, v2, -1.75f, v3); + ASSERT(test_eq(v3[0], -100.0f)) + ASSERT(test_eq(v3[1], -200.0f)) + ASSERT(test_eq(v3[2], -10.0f)) + ASSERT(test_eq(v3[3], -10.0f)) + + GLM(quat_lerpc)(v1, v2, 1.75f, v3); + ASSERT(test_eq(v3[0], 100.0f)) + ASSERT(test_eq(v3[1], 200.0f)) + ASSERT(test_eq(v3[2], 10.0f)) + ASSERT(test_eq(v3[3], 10.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_nlerp) { + versor q1, q2, q3, q4; + vec3 v1 = {10.0f, 0.0f, 0.0f}, v2; + + glm_quatv(q1, glm_rad(30.0f), v1); + glm_quatv(q2, glm_rad(90.0f), v1); + + GLM(quat_nlerp)(q1, q2, 1.0f, q3); + glm_quat_normalize(q2); + ASSERTIFY(test_assert_quat_eq(q2, q3)); + + glm_quatv(q1, glm_rad(30.001f), v1); + glm_quatv(q2, glm_rad(30.002f), v1); + GLM(quat_nlerp)(q1, q2, 0.7f, q3); + glm_quat_lerp(q1, q2, 0.7f, q4); + ASSERTIFY(test_assert_quat_eq(q3, q4)); + + glm_quatv(q1, glm_rad(30.0f), v1); + glm_quatv(q2, glm_rad(90.0f), v1); + GLM(quat_nlerp)(q1, q2, 0.5f, q3); + + glm_quat_axis(q3, v2); + glm_vec3_normalize(v1); + glm_vec3_normalize(v2); + + ASSERT(glm_quat_angle(q3) > glm_rad(30.0f)); + ASSERT(glm_quat_angle(q3) < glm_rad(90.0f)); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_slerp) { + versor q1, q2, q3, q4; + vec3 v1 = {10.0f, 0.0f, 0.0f}, v2; + + glm_quatv(q1, glm_rad(30.0f), v1); + glm_quatv(q2, glm_rad(90.0f), v1); + + q1[0] = 10.0f; + GLM(quat_slerp)(q1, q2, 1.0f, q3); + ASSERTIFY(test_assert_quat_eq(q1, q3)); + + glm_quatv(q1, glm_rad(30.001f), v1); + glm_quatv(q2, glm_rad(30.002f), v1); + GLM(quat_slerp)(q1, q2, 0.7f, q3); + glm_quat_lerp(q1, q2, 0.7f, q4); + ASSERTIFY(test_assert_quat_eq(q3, q4)); + + glm_quatv(q1, glm_rad(30.0f), v1); + glm_quatv(q2, glm_rad(90.0f), v1); + GLM(quat_slerp)(q1, q2, 0.5f, q3); + + glm_quat_axis(q3, v2); + glm_vec3_normalize(v1); + glm_vec3_normalize(v2); + + ASSERT(glm_quat_angle(q3) > glm_rad(30.0f)); + ASSERT(glm_quat_angle(q3) < glm_rad(90.0f)); + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_look) { + versor q1; + vec3 v1 = {0.0f, 1.0f, 0.0f}; + mat4 m1, m2; + + glm_quat(q1, glm_rad(90.0f), 0.0f, 1.0f, 0.0f); + GLM(quat_look)(v1, q1, m1); + + glm_look(v1, (vec3){-1.0f, 0.0f, 0.0f}, GLM_YUP, m2); + ASSERTIFY(test_assert_mat4_eq(m1, m2)); + + glm_quat(q1, glm_rad(180.0f), 1.0f, 0.0f, 0.0f); + GLM(quat_look)(v1, q1, m1); + + glm_look(v1, (vec3){0.0f, 0.0f, 1.0f}, (vec3){0.0f, -1.0f, 0.0f}, m2); + + ASSERTIFY(test_assert_mat4_eq(m1, m2)); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_for) { + versor q1, q2; + + glm_quat(q1, glm_rad(90.0f), 0.0f, 1.0f, 0.0f); + GLM(quat_for)((vec3){-1.0f, 0.0f, 0.0f}, (vec3){0.0f, 1.0f, 0.0f}, q2); + ASSERTIFY(test_assert_quat_eq(q1, q2)); + + glm_quat(q2, glm_rad(90.0f), 1.0f, 0.0f, 0.0f); + GLM(quat_for)((vec3){0.0f, 1.0f, 0.0f}, (vec3){0.0f, 0.0f, 1.0f}, q1); + ASSERTIFY(test_assert_quat_eq(q1, q2)); + + glm_quat(q2, glm_rad(180.0f), 1.0f, 0.0f, 0.0f); + GLM(quat_for)((vec3){0.0f, 0.0f, 1.0f}, (vec3){0.0f, -1.0f, 0.0f}, q1); + ASSERTIFY(test_assert_quat_eq(q1, q2)); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_forp) { + versor q1, q2; + + glm_quat(q1, glm_rad(90.0f), 0.0f, 1.0f, 0.0f); + GLM(quat_forp)((vec3){2.0f, 0.0f, 0.0f}, + (vec3){1.0f, 0.0f, 0.0f}, + (vec3){0.0f, 1.0f, 0.0f}, + q2); + ASSERTIFY(test_assert_quat_eq(q1, q2)); + + glm_quat(q2, glm_rad(90.0f), 1.0f, 0.0f, 0.0f); + GLM(quat_forp)((vec3){0.0f, 1.0f, 0.0f}, + (vec3){0.0f, 2.0f, 0.0f}, + (vec3){0.0f, 0.0f, 1.0f}, + q1); + ASSERTIFY(test_assert_quat_eq(q1, q2)); + + glm_quat(q2, glm_rad(180.0f), 1.0f, 0.0f, 0.0f); + GLM(quat_forp)((vec3){0.0f, 1.0f, 1.0f}, + (vec3){0.0f, 1.0f, 2.0f}, + (vec3){0.0f, -1.0f, 0.0f}, + q1); + ASSERTIFY(test_assert_quat_eq(q1, q2)); + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_rotatev) { + vec3 v1 = {1.0f, 0.0f, 0.0f}, v2 = {1.0f, 1.0f, 1.0f}; + versor q; + + /* rotate X around Y = -Z */ + glm_quatv(q, GLM_PI_2f, GLM_YUP); + GLM(quat_rotatev)(q, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + /* rotate -Z around X = Y */ + glm_quatv(q, GLM_PI_2f, GLM_XUP); + GLM(quat_rotatev)(q, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate Y around Z = -X */ + glm_quatv(q, GLM_PI_2f, GLM_ZUP); + GLM(quat_rotatev)(q, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate v2 around Y by 90deg */ + glm_quatv(q, GLM_PI_2f, GLM_YUP); + GLM(quat_rotatev)(q, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + glm_quatv(q, GLM_PI_2f, GLM_YUP); + GLM(quat_rotatev)(q, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + glm_quatv(q, GLM_PI_2f, GLM_YUP); + GLM(quat_rotatev)(q, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around X by 90deg */ + glm_quatv(q, GLM_PI_2f, GLM_XUP); + GLM(quat_rotatev)(q, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around Z by 90deg */ + glm_quatv(q, GLM_PI_2f, GLM_ZUP); + GLM(quat_rotatev)(q, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_rotate) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT, m2; + versor q1; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + /* rotate X around Y = -Z */ + glm_quatv(q1, GLM_PI_2f, GLM_YUP); + GLM(quat_rotate)(m1, q1, m1); + glm_rotate_make(m2, GLM_PI_2f, GLM_YUP); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + glm_mat4_identity(m1); + glm_mat4_identity(m2); + + /* rotate -Z around X = Y */ + glm_quatv(q1, GLM_PI_2f, GLM_XUP); + GLM(quat_rotate)(m1, q1, m1); + glm_rotate(m2, GLM_PI_2f, GLM_XUP); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + glm_mat4_identity(m1); + glm_mat4_identity(m2); + + /* rotate Y around X = +Z */ + glm_quatv(q1, GLM_PI_2f, GLM_XUP); + GLM(quat_rotate)(m1, q1, m1); + glm_rotate(m2, GLM_PI_2f, GLM_XUP); + ASSERTIFY(test_assert_mat4_eq(m1, m2)) + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_rotate_at) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + versor q1; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + glm_quatv(q1, GLM_PI_2f, GLM_YUP); + GLM(quat_rotate_at)(m1, q1, (vec3){0.5f, 0.0f, 0.0f}); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.5f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -0.5f)) + + glm_mat4_identity(m1); + + glm_quatv(q1, GLM_PI_2f, GLM_ZUP); + GLM(quat_rotate_at)(m1, q1, (vec3){0.0f, 0.0f, 0.0f}); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.5f)) + ASSERT(test_eq(v1[2], -0.5f)) + + glm_mat4_identity(m1); + + v1[0] = 1.0f; + v1[1] = 1.0f; + v1[2] = 1.0f; + + glm_quatv(q1, GLM_PI_2f, GLM_XUP); + GLM(quat_rotate_at)(m1, q1, GLM_VEC3_ZERO); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, quat_rotate_atm) { + mat4 m1 = GLM_MAT4_IDENTITY_INIT; + versor q1; + vec4 v1 = {1.0f, 0.0f, 0.0f, 1.0f}; + + glm_quatv(q1, GLM_PI_2f, GLM_YUP); + GLM(quat_rotate_atm)(m1, q1, (vec3){0.5f, 0.0f, 0.0f}); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.5f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -0.5f)) + + glm_quatv(q1, GLM_PI_2f, GLM_ZUP); + GLM(quat_rotate_atm)(m1, q1, (vec3){0.0f, 0.0f, 0.0f}); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.5f)) + ASSERT(test_eq(v1[2], -0.5f)) + + v1[0] = 1.0f; + v1[1] = 1.0f; + v1[2] = 1.0f; + + glm_quatv(q1, GLM_PI_2f, GLM_XUP); + GLM(quat_rotate_atm)(m1, q1, GLM_VEC3_ZERO); + glm_mat4_mulv(m1, v1, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + ASSERT(test_eq(v1[2], 1.0f)) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_ray.h b/libs/cglm/test/src/test_ray.h new file mode 100644 index 0000000..c1b0281 --- /dev/null +++ b/libs/cglm/test/src/test_ray.h @@ -0,0 +1,34 @@ +/* + * 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" + +TEST_IMPL(GLM_PREFIX, ray_triangle) { + /* Check whether a simple hit is recognized with the right distance */ + vec3 origin = { 0.0f, 0.0f, 0.0f}; + vec3 direction = { 1.0f, 0.0f, 0.0f}; + vec3 opposite = {-1.0f, 0.0f, 0.0f}; + vec3 v0 = { 5.0f, -1.0f, 1.0f}; + vec3 v1 = { 5.0f, -1.0f, -1.0f}; + vec3 v2 = { 5.0f, 1.0f, 0.0f}; + float d; + bool hit; + + hit = GLM(ray_triangle)(origin, direction, v0, v1, v2, &d); + ASSERT(hit); + ASSERT(fabsf(d - 5.0f) <= 0.0000009); + + /* Check whether a simple miss works */ + hit = GLM(ray_triangle)(origin, opposite, v0, v1, v2, &d); + ASSERT(!hit); + + /* Check that we can disregard distance and pass NULL pointer instead */ + hit = GLM(ray_triangle)(origin, direction, v0, v1, v2, NULL); + ASSERT(hit); + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_struct.c b/libs/cglm/test/src/test_struct.c new file mode 100644 index 0000000..ce79356 --- /dev/null +++ b/libs/cglm/test/src/test_struct.c @@ -0,0 +1,78 @@ +/* + * 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" + +TEST_IMPL(mat3s_identity_init) { + mat3s mat3_identity = GLMS_MAT3_IDENTITY_INIT; + mat3 mat3_identity_a = GLM_MAT3_IDENTITY_INIT; + test_assert_mat3_eq(mat3_identity.raw, mat3_identity_a); + TEST_SUCCESS +} + +TEST_IMPL(mat3s_zero_init) { + mat3s mat3_zero = GLMS_MAT3_ZERO_INIT; + mat3 mat3_zero_a = GLM_MAT3_ZERO_INIT; + test_assert_mat3_eq(mat3_zero.raw, mat3_zero_a); + TEST_SUCCESS +} + +TEST_IMPL(mat4s_identity_init) { + mat4s mat4_identity = GLMS_MAT4_IDENTITY_INIT; + mat4 mat4_identity_a = GLM_MAT4_IDENTITY_INIT; + test_assert_mat4_eq(mat4_identity.raw, mat4_identity_a); + TEST_SUCCESS +} + +TEST_IMPL(mat4s_zero_init) { + mat4s mat4_zero = GLMS_MAT4_ZERO_INIT; + mat4 mat4_zero_a = GLM_MAT4_ZERO_INIT; + test_assert_mat4_eq(mat4_zero.raw, mat4_zero_a); + TEST_SUCCESS +} + +TEST_IMPL(quats_zero_init) { + versors quat_zero = GLMS_QUAT_IDENTITY_INIT; + versor quat_zero_a = GLM_QUAT_IDENTITY_INIT; + test_assert_quat_eq(quat_zero.raw, quat_zero_a); + TEST_SUCCESS +} + +TEST_IMPL(vec3s_one_init) { + vec3s vec3_one = GLMS_VEC3_ONE_INIT; + vec3 vec3_one_a = GLM_VEC3_ONE_INIT; + test_assert_vec3_eq(vec3_one.raw, vec3_one_a); + TEST_SUCCESS +} + +TEST_IMPL(vec3s_zero_init) { + vec3s vec3_zero = GLMS_VEC3_ZERO_INIT; + vec3 vec3_zero_a = GLM_VEC3_ZERO_INIT; + test_assert_vec3_eq(vec3_zero.raw, vec3_zero_a); + TEST_SUCCESS +} + +TEST_IMPL(vec4s_black_init) { + vec4s vec4_black = GLMS_VEC4_BLACK_INIT; + vec4 vec4_black_a = GLM_VEC4_BLACK_INIT; + test_assert_vec4_eq(vec4_black.raw, vec4_black_a); + TEST_SUCCESS +} + +TEST_IMPL(vec4s_one_init) { + vec4s vec4_one = GLMS_VEC4_ONE_INIT; + vec4 vec4_one_a = GLM_VEC4_ONE_INIT; + test_assert_vec4_eq(vec4_one.raw, vec4_one_a); + TEST_SUCCESS +} + +TEST_IMPL(vec4s_zero_init) { + vec4s vec4_zero = GLMS_VEC4_ZERO_INIT; + vec4 vec4_zero_a = GLM_VEC4_ZERO_INIT; + test_assert_vec4_eq(vec4_zero.raw, vec4_zero_a); + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_vec2.h b/libs/cglm/test/src/test_vec2.h new file mode 100644 index 0000000..9e53f72 --- /dev/null +++ b/libs/cglm/test/src/test_vec2.h @@ -0,0 +1,625 @@ +/* + * 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" + +#ifndef CGLM_TEST_VEC2_ONCE +#define CGLM_TEST_VEC2_ONCE + +/* Macros */ + +TEST_IMPL(MACRO_GLM_VEC2_ONE_INIT) { + vec2 v = GLM_VEC2_ONE_INIT; + + ASSERT(test_eq(v[0], 1.0f)) + ASSERT(test_eq(v[1], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC2_ZERO_INIT) { + vec2 v = GLM_VEC2_ZERO_INIT; + + ASSERT(test_eq(v[0], 0.0f)) + ASSERT(test_eq(v[1], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC2_ONE) { + ASSERT(test_eq(GLM_VEC2_ONE[0], 1.0f)) + ASSERT(test_eq(GLM_VEC2_ONE[1], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC2_ZERO) { + ASSERT(test_eq(GLM_VEC2_ZERO[0], 0.0f)) + ASSERT(test_eq(GLM_VEC2_ZERO[0], 0.0f)) + + TEST_SUCCESS +} + +#endif /* CGLM_TEST_VEC2_ONCE */ + +TEST_IMPL(GLM_PREFIX, vec2) { + vec4 v4 = {10.0f, 9.0f, 8.0f, 7.0f}; + vec3 v3 = {11.0f, 12.0f, 13.0f}; + vec2 v2; + + GLM(vec2)(v4, v2); + ASSERT(test_eq(v2[0], v4[0])) + ASSERT(test_eq(v2[1], v4[1])) + + GLM(vec2)(v3, v2); + ASSERT(test_eq(v2[0], v3[0])) + ASSERT(test_eq(v2[1], v3[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_copy) { + vec2 v1 = {10.0f, 9.0f}; + vec2 v2 = {1.0f, 2.0f}; + + GLM(vec2_copy)(v1, v2); + + ASSERTIFY(test_assert_vec2_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_zero) { + vec2 v1 = {10.0f, 9.0f}; + vec2 v2 = {1.0f, 2.0f}; + + GLM(vec2_zero)(v1); + GLM(vec2_zero)(v2); + + ASSERTIFY(test_assert_vec2_eq(v1, GLM_VEC2_ZERO)) + ASSERTIFY(test_assert_vec2_eq(v2, GLM_VEC2_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_one) { + vec2 v1 = {10.0f, 9.0f}; + vec2 v2 = {1.0f, 2.0f}; + + GLM(vec2_one)(v1); + GLM(vec2_one)(v2); + + ASSERTIFY(test_assert_vec2_eq(v1, GLM_VEC2_ONE)) + ASSERTIFY(test_assert_vec2_eq(v2, GLM_VEC2_ONE)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_dot) { + vec2 a = {10.0f, 9.0f}; + vec2 b = {1.0f, 2.0f}; + float dot1, dot2; + + dot1 = GLM(vec2_dot)(a, b); + dot2 = a[0] * b[0] + a[1] * b[1]; + + ASSERT(test_eq(dot1, dot2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_cross) { + vec2 a = {10.0f, 9.0f}; + vec2 b = {1.0f, 2.0f}; + float cprod; + + cprod = a[0] * b[1] - a[1] * b[0]; + + ASSERT(test_eq(glm_vec2_cross(a, b), cprod)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_norm2) { + vec2 a = {10.0f, 9.0f}; + float n1, n2; + + n1 = GLM(vec2_norm2)(a); + n2 = a[0] * a[0] + a[1] * a[1]; + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_norm) { + vec2 a = {10.0f, 9.0f}; + float n1, n2; + + n1 = GLM(vec2_norm)(a); + n2 = sqrtf(a[0] * a[0] + a[1] * a[1]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_add) { + vec2 a = {-10.0f, 9.0f}; + vec2 b = {12.0f, 19.0f}; + vec2 c, d; + + c[0] = a[0] + b[0]; + c[1] = a[1] + b[1]; + + GLM(vec2_add)(a, b, d); + + ASSERTIFY(test_assert_vec2_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_adds) { + vec4 a = {-10.0f, 9.0f}; + vec4 c, d; + float s = 7.0f; + + c[0] = a[0] + s; + c[1] = a[1] + s; + + GLM(vec2_adds)(a, s, d); + + ASSERTIFY(test_assert_vec2_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_sub) { + vec2 a = {-10.0f, 9.0f}; + vec2 b = {12.0f, 19.0f}; + vec2 c, d; + + c[0] = a[0] - b[0]; + c[1] = a[1] - b[1]; + + GLM(vec2_sub)(a, b, d); + + ASSERTIFY(test_assert_vec2_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_subs) { + vec2 a = {-10.0f, 9.0f}; + vec2 c, d; + float s = 7.0f; + + c[0] = a[0] - s; + c[1] = a[1] - s; + + GLM(vec2_subs)(a, s, d); + + ASSERTIFY(test_assert_vec2_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_mul) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3; + + GLM(vec2_mul)(v1, v2, v3); + + ASSERT(test_eq(v1[0] * v2[0], v3[0])) + ASSERT(test_eq(v1[1] * v2[1], v3[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_scale) { + vec2 v1 = {2.0f, -3.0f}, v2; + float s = 7.0f; + + GLM(vec2_scale)(v1, s, v2); + + ASSERT(test_eq(v1[0] * s, v2[0])) + ASSERT(test_eq(v1[1] * s, v2[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_scale_as) { + vec2 v1 = {2.0f, -3.0f}, v2; + float s = 7.0f; + float norm; + + GLM(vec2_scale_as)(v1, s, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_div) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3; + + GLM(vec2_div)(v1, v2, v3); + + ASSERT(test_eq(v1[0] / v2[0], v3[0])) + ASSERT(test_eq(v1[1] / v2[1], v3[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_divs) { + vec2 v1 = {2.0f, -3.0f}, v2; + float s = 7.0f; + + GLM(vec2_divs)(v1, s, v2); + + ASSERT(test_eq(v1[0] / s, v2[0])) + ASSERT(test_eq(v1[1] / s, v2[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_addadd) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3 = {1.0f, 2.0f}, + v4 = {1.0f, 2.0f}; + + GLM(vec2_addadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] + v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] + v2[1], v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_subadd) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3 = {1.0f, 2.0f}, + v4 = {1.0f, 2.0f}; + + GLM(vec2_subadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] - v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] - v2[1], v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_muladd) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3 = {1.0f, 2.0f}, + v4 = {1.0f, 2.0f}; + + GLM(vec2_muladd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] * v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] * v2[1], v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_muladds) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {1.0f, 2.0f}, + v3 = {1.0f, 2.0f}; + float s = 9.0f; + + GLM(vec2_muladds)(v1, s, v3); + + ASSERT(test_eq(v2[0] + v1[0] * s, v3[0])) + ASSERT(test_eq(v2[1] + v1[1] * s, v3[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_maxadd) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3 = {1.0f, 2.0f}, + v4 = {1.0f, 2.0f}; + + GLM(vec2_maxadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + glm_max(v1[0], v2[0]), v4[0])) + ASSERT(test_eq(v3[1] + glm_max(v1[1], v2[1]), v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_minadd) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3 = {1.0f, 2.0f}, + v4 = {1.0f, 2.0f}; + + GLM(vec2_minadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + glm_min(v1[0], v2[0]), v4[0])) + ASSERT(test_eq(v3[1] + glm_min(v1[1], v2[1]), v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_negate_to) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3, v4; + + GLM(vec2_negate_to)(v1, v3); + GLM(vec2_negate_to)(v2, v4); + + ASSERT(test_eq(-v1[0], v3[0])) + ASSERT(test_eq(-v1[1], v3[1])) + + ASSERT(test_eq(-v2[0], v4[0])) + ASSERT(test_eq(-v2[1], v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_negate) { + vec2 v1 = {2.0f, -3.0f}, + v2 = {-3.0f, 4.0f}, + v3 = {2.0f, -3.0f}, + v4 = {-3.0f, 4.0f}; + + GLM(vec2_negate)(v1); + GLM(vec2_negate)(v2); + + ASSERT(test_eq(-v1[0], v3[0])) + ASSERT(test_eq(-v1[1], v3[1])) + + ASSERT(test_eq(-v2[0], v4[0])) + ASSERT(test_eq(-v2[1], v4[1])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_normalize) { + vec2 v1 = {2.0f, -3.0f}, v2 = {2.0f, -3.0f}; + float s = 1.0f; + float norm; + + GLM(vec2_normalize)(v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + + glm_vec2_zero(v1); + GLM(vec2_normalize)(v1); + ASSERTIFY(test_assert_vec2_eq(v1, GLM_VEC2_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_normalize_to) { + vec2 v1 = {2.0f, -3.0f}, v2; + float s = 1.0f; + float norm; + + GLM(vec2_normalize_to)(v1, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + + glm_vec2_zero(v1); + GLM(vec2_normalize_to)(v1, v2); + ASSERTIFY(test_assert_vec2_eq(v2, GLM_VEC2_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_rotate) { + vec2 v1 = {1.0f, 0.0f}; + + GLM(vec2_rotate)(v1, GLM_PI_2f, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + + GLM(vec2_rotate)(v1, GLM_PI_2f, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + + GLM(vec2_rotate)(v1, GLM_PI_2f, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], -1.0f)) + + GLM(vec2_rotate)(v1, GLM_PI_2f, v1); + + ASSERT(test_eq(v1[0], 1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_distance2) { + vec2 v1 = {30.0f, 0.0f}, + v2 = {0.0f, 0.0f}, + v3 = {3.0f, 10.0f}, + v4 = {0.46f, 4.0f}; + float d; + + d = GLM(vec2_distance2)(v1, v2); + ASSERT(test_eq(d, 30.0f * 30.0f)) + + d = GLM(vec2_distance2)(v3, v4); + ASSERT(test_eq(powf(v3[0] - v4[0], 2.0f) + + powf(v3[1] - v4[1], 2.0f), d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_distance) { + vec2 v1 = {30.0f, 0.0f}, + v2 = {0.0f, 0.0f}, + v3 = {3.0f, 10.0f}, + v4 = {0.46f, 4.0f}; + float d; + + d = GLM(vec2_distance)(v1, v2); + ASSERT(test_eq(d, 30.0f)) + + d = GLM(vec2_distance)(v3, v4); + ASSERT(test_eq(sqrtf(powf(v3[0] - v4[0], 2.0f) + + powf(v3[1] - v4[1], 2.0f)), d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_maxv) { + vec2 v1, v2, v3; + vec2 v5 = {-1.456f, -1.456f}; + vec2 v6 = {11.0f, 11.0f}; + vec2 v7 = {78.0f, -78.0f}; + + GLM(vec2_maxv)(v5, v6, v1); + GLM(vec2_maxv)(v5, v7, v2); + GLM(vec2_maxv)(v6, v7, v3); + + ASSERT(test_eq(v1[0], 11.0f)) + ASSERT(test_eq(v1[1], 11.0f)) + + ASSERT(test_eq(v2[0], 78.0f)) + ASSERT(test_eq(v2[1], -1.456f)) + + ASSERT(test_eq(v3[0], 78.0f)) + ASSERT(test_eq(v3[1], 11.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_minv) { + vec2 v1, v2, v3; + vec2 v5 = {-1.456f, -1.456f}; + vec2 v6 = {11.0f, 11.0f}; + vec2 v7 = {78.0f, -78.0f}; + + GLM(vec2_minv)(v5, v6, v1); + GLM(vec2_minv)(v5, v7, v2); + GLM(vec2_minv)(v6, v7, v3); + + ASSERT(test_eq(v1[0], -1.456f)) + ASSERT(test_eq(v1[1], -1.456f)) + + ASSERT(test_eq(v2[0], -1.456f)) + ASSERT(test_eq(v2[1], -78.0f)) + + ASSERT(test_eq(v3[0], 11.0f)) + ASSERT(test_eq(v3[1], -78.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_clamp) { + vec2 v1 = {-1.456f, -11.456f}; + vec2 v2 = {0.110f, 111.0f}; + vec2 v3 = {78.0f, 32.0f}; + + GLM(vec2_clamp)(v1, -1.03f, 30.0f); + GLM(vec2_clamp)(v2, 0.11f, 111.0f); + GLM(vec2_clamp)(v3, -88.0f, 70.0f); + + ASSERT(test_eq(v1[0], -1.03f)) + ASSERT(test_eq(v1[1], -1.03f)) + + ASSERT(test_eq(v2[0], 0.11f)) + ASSERT(test_eq(v2[1], 111.0f)) + + ASSERT(test_eq(v3[0], 70.0f)) + ASSERT(test_eq(v3[1], 32.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_lerp) { + vec2 v1 = {-100.0f, -200.0f}; + vec2 v2 = {100.0f, 200.0f}; + vec2 v3; + + GLM(vec2_lerp)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + + GLM(vec2_lerp)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_complex_mul) { + vec2 v1 = { 3.0f, 5.0f }, + v2 = { 7.0f, 11.0f }, + v3 = { cosf(M_PI/4.0f), sinf(M_PI/4.0f) }; + + GLM(vec2_complex_mul)(v1, v2, v2); + ASSERTIFY(test_assert_vec2_eq(v2, (vec2){ -34, 68 })) + + GLM(vec2_complex_mul)(v3, v3, v3); + ASSERTIFY(test_assert_vec2_eq(v3, (vec2){ 0.0f, 1.0f })) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec2_complex_div) { + vec2 v1 = { -34.0f, 68.0f }, + v2 = { 3.0f, 5.0f }, + v3 = { cosf(M_PI/4.0f), sinf(M_PI/4.0f) }, + v4 = { cosf(M_PI/4.0f), -sinf(M_PI/4.0f) }; + + GLM(vec2_complex_div)(v1, v2, v2); + ASSERTIFY(test_assert_vec2_eq(v2, (vec2){ 7.0f, 11.0f })) + + GLM(vec2_complex_div)(v3, v4, v4); + ASSERTIFY(test_assert_vec2_eq(v4, (vec2){ 0.0f, 1.0f })) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_vec3.h b/libs/cglm/test/src/test_vec3.h new file mode 100644 index 0000000..44a9847 --- /dev/null +++ b/libs/cglm/test/src/test_vec3.h @@ -0,0 +1,1731 @@ +/* + * 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 TEST_GLM_SHUFFLE3(z, y, x) (((z) << 4) | ((y) << 2) | (x)) + +#ifndef CGLM_TEST_VEC3_ONCE +#define CGLM_TEST_VEC3_ONCE + +/* Macros */ + +TEST_IMPL(MACRO_GLM_VEC3_ONE_INIT) { + vec3 v = GLM_VEC3_ONE_INIT; + + ASSERT(test_eq(v[0], 1.0f)) + ASSERT(test_eq(v[1], 1.0f)) + ASSERT(test_eq(v[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC3_ZERO_INIT) { + vec3 v = GLM_VEC3_ZERO_INIT; + + ASSERT(test_eq(v[0], 0.0f)) + ASSERT(test_eq(v[1], 0.0f)) + ASSERT(test_eq(v[2], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC3_ONE) { + ASSERT(test_eq(GLM_VEC3_ONE[0], 1.0f)) + ASSERT(test_eq(GLM_VEC3_ONE[1], 1.0f)) + ASSERT(test_eq(GLM_VEC3_ONE[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC3_ZERO) { + ASSERT(test_eq(GLM_VEC3_ZERO[0], 0.0f)) + ASSERT(test_eq(GLM_VEC3_ZERO[1], 0.0f)) + ASSERT(test_eq(GLM_VEC3_ZERO[2], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_YUP) { + ASSERT(test_eq(GLM_YUP[0], 0.0f)) + ASSERT(test_eq(GLM_YUP[1], 1.0f)) + ASSERT(test_eq(GLM_YUP[2], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_ZUP) { + ASSERT(test_eq(GLM_ZUP[0], 0.0f)) + ASSERT(test_eq(GLM_ZUP[1], 0.0f)) + ASSERT(test_eq(GLM_ZUP[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_XUP) { + ASSERT(test_eq(GLM_XUP[0], 1.0f)) + ASSERT(test_eq(GLM_XUP[1], 0.0f)) + ASSERT(test_eq(GLM_XUP[2], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_FORWARD_RH) { + ASSERT(test_eq(GLM_FORWARD[0], 0.0f)) + ASSERT(test_eq(GLM_FORWARD[1], 0.0f)) + ASSERT(test_eq(GLM_FORWARD[2], -1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_SHUFFLE3) { + ASSERT(TEST_GLM_SHUFFLE3(1, 0, 0) == GLM_SHUFFLE3(1, 0, 0)) + ASSERT(TEST_GLM_SHUFFLE3(0, 1, 0) == GLM_SHUFFLE3(0, 1, 0)) + ASSERT(TEST_GLM_SHUFFLE3(0, 0, 1) == GLM_SHUFFLE3(0, 0, 1)) + ASSERT(TEST_GLM_SHUFFLE3(1, 0, 0) == GLM_SHUFFLE3(1, 0, 0)) + ASSERT(TEST_GLM_SHUFFLE3(1, 0, 1) == GLM_SHUFFLE3(1, 0, 1)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_XXX) { + ASSERT(TEST_GLM_SHUFFLE3(0, 0, 0) == GLM_XXX) + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_YYY) { + ASSERT(TEST_GLM_SHUFFLE3(1, 1, 1) == GLM_YYY) + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_ZZZ) { + ASSERT(TEST_GLM_SHUFFLE3(2, 2, 2) == GLM_ZZZ) + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_ZYX) { + ASSERT(TEST_GLM_SHUFFLE3(0, 1, 2) == GLM_ZYX) + TEST_SUCCESS +} + +/* Deprecated */ + +TEST_IMPL(MACRO_glm_vec3_dup) { + vec3 v1 = {13.0f, 12.0f, 11.0f}, v2; + + glm_vec3_dup(v1, v2); + + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec3_flipsign) { + vec3 v1 = {13.0f, -12.0f, 11.0f}, + v2 = {13.0f, -12.0f, 11.0f}, + v3 = {-13.0f, 12.0f, -11.0f}; + + glm_vec3_flipsign(v1); + glmc_vec3_flipsign(v2); + + ASSERTIFY(test_assert_vec3_eq(v1, v3)) + ASSERTIFY(test_assert_vec3_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec3_flipsign_to) { + vec3 v1 = {13.0f, -12.0f, 11.0f}, + v2 = {-13.0f, 12.0f, -11.0f}, + v3, v4; + + glm_vec3_flipsign_to(v1, v3); + glmc_vec3_flipsign_to(v1, v4); + + ASSERTIFY(test_assert_vec3_eq(v2, v3)) + ASSERTIFY(test_assert_vec3_eq(v2, v4)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec3_inv) { + vec3 v1 = {13.0f, -12.0f, 11.0f}, + v2 = {13.0f, -12.0f, 11.0f}, + v3 = {-13.0f, 12.0f, -11.0f}; + + glm_vec3_inv(v1); + glmc_vec3_inv(v2); + + ASSERTIFY(test_assert_vec3_eq(v1, v3)) + ASSERTIFY(test_assert_vec3_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec3_inv_to) { + vec3 v1 = {13.0f, -12.0f, 11.0f}, + v2 = {-13.0f, 12.0f, -11.0f}, + v3, v4; + + glm_vec3_inv_to(v1, v3); + glmc_vec3_inv_to(v1, v4); + + ASSERTIFY(test_assert_vec3_eq(v3, v4)) + ASSERTIFY(test_assert_vec3_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec3_mulv) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3, v4; + + glm_vec3_mulv(v1, v2, v3); + glmc_vec3_mulv(v1, v2, v4); + + ASSERTIFY(test_assert_vec3_eq(v3, v4)) + + ASSERT(test_eq(v1[0] * v2[0], v3[0])) + ASSERT(test_eq(v1[1] * v2[1], v3[1])) + ASSERT(test_eq(v1[2] * v2[2], v3[2])) + + TEST_SUCCESS +} + +#endif /* CGLM_TEST_VEC3_ONCE */ + +/* --- */ + +TEST_IMPL(GLM_PREFIX, vec3) { + vec4 v4 = {10.0f, 9.0f, 8.0f, 7.0f}; + vec3 v3; + + GLM(vec3)(v4, v3); + + ASSERT(test_eq(v3[0], v4[0])) + ASSERT(test_eq(v3[1], v4[1])) + ASSERT(test_eq(v3[2], v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_copy) { + vec3 v1 = {10.0f, 9.0f, 8.0f}; + vec3 v2 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_copy)(v1, v2); + + ASSERTIFY(test_assert_vec3_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_zero) { + vec3 v1 = {10.0f, 9.0f, 8.0f}; + vec3 v2 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_zero)(v1); + GLM(vec3_zero)(v2); + + ASSERTIFY(test_assert_vec3_eq(v1, GLM_VEC3_ZERO)) + ASSERTIFY(test_assert_vec3_eq(v2, GLM_VEC3_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_one) { + vec3 v1 = {10.0f, 9.0f, 8.0f}; + vec3 v2 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_one)(v1); + GLM(vec3_one)(v2); + + ASSERTIFY(test_assert_vec3_eq(v1, GLM_VEC3_ONE)) + ASSERTIFY(test_assert_vec3_eq(v1, GLM_VEC3_ONE)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_dot) { + vec3 a = {10.0f, 9.0f, 8.0f}; + vec3 b = {1.0f, 2.0f, 3.0f}; + float dot1, dot2; + + dot1 = GLM(vec3_dot)(a, b); + dot2 = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; + + ASSERT(test_eq(dot1, dot2)) + + TEST_SUCCESS +} + + +TEST_IMPL(GLM_PREFIX, dot) { + /* SAME AS VEC3_DOT */ + + vec3 a = {10.0f, 9.0f, 8.0f}; + vec3 b = {1.0f, 2.0f, 3.0f}; + float dot1, dot2; + + dot1 = GLM(vec3_dot)(a, b); + dot2 = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; + + ASSERT(test_eq(dot1, dot2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_norm2) { + vec3 a = {10.0f, 9.0f, 8.0f}; + float n1, n2; + + n1 = GLM(vec3_norm2)(a); + n2 = a[0] * a[0] + a[1] * a[1] + a[2] * a[2]; + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_norm) { + vec3 a = {10.0f, 9.0f, 8.0f}; + float n1, n2; + + n1 = GLM(vec3_norm)(a); + n2 = sqrtf(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_norm_one) { + vec3 a = {-10.0f, 9.0f, -8.0f}; + float n1, n2; + + n1 = GLM(vec3_norm_one)(a); + n2 = fabsf(a[0]) + fabsf(a[1]) + fabsf(a[2]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_norm_inf) { + vec3 a = {-10.0f, 9.0f, -8.0f}; + float n1, n2; + + n1 = GLM(vec3_norm_inf)(a); + n2 = fabsf(a[0]); + + if (n2 < fabsf(a[1])) + n2 = fabsf(a[1]); + + if (n2 < fabsf(a[2])) + n2 = fabsf(a[2]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_add) { + vec3 a = {-10.0f, 9.0f, -8.0f}; + vec3 b = {12.0f, 19.0f, -18.0f}; + vec3 c, d; + + c[0] = a[0] + b[0]; + c[1] = a[1] + b[1]; + c[2] = a[2] + b[2]; + + GLM(vec3_add)(a, b, d); + + ASSERTIFY(test_assert_vec3_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_adds) { + vec3 a = {-10.0f, 9.0f, -8.0f}; + vec3 c, d; + float s = 7.0f; + + c[0] = a[0] + s; + c[1] = a[1] + s; + c[2] = a[2] + s; + + GLM(vec3_adds)(a, s, d); + + ASSERTIFY(test_assert_vec3_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_sub) { + vec3 a = {-10.0f, 9.0f, -8.0f}; + vec3 b = {12.0f, 19.0f, -18.0f}; + vec3 c, d; + + c[0] = a[0] - b[0]; + c[1] = a[1] - b[1]; + c[2] = a[2] - b[2]; + + GLM(vec3_sub)(a, b, d); + + ASSERTIFY(test_assert_vec3_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_subs) { + vec3 a = {-10.0f, 9.0f, -8.0f}; + vec3 c, d; + float s = 7.0f; + + c[0] = a[0] - s; + c[1] = a[1] - s; + c[2] = a[2] - s; + + GLM(vec3_subs)(a, s, d); + + ASSERTIFY(test_assert_vec3_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_mul) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3; + + GLM(vec3_mul)(v1, v2, v3); + + ASSERT(test_eq(v1[0] * v2[0], v3[0])) + ASSERT(test_eq(v1[1] * v2[1], v3[1])) + ASSERT(test_eq(v1[2] * v2[2], v3[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_scale) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2; + float s = 7.0f; + + GLM(vec3_scale)(v1, s, v2); + + ASSERT(test_eq(v1[0] * s, v2[0])) + ASSERT(test_eq(v1[1] * s, v2[1])) + ASSERT(test_eq(v1[2] * s, v2[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_scale_as) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2; + float s = 7.0f; + float norm; + + GLM(vec3_scale_as)(v1, s, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_div) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3; + + GLM(vec3_div)(v1, v2, v3); + + ASSERT(test_eq(v1[0] / v2[0], v3[0])) + ASSERT(test_eq(v1[1] / v2[1], v3[1])) + ASSERT(test_eq(v1[2] / v2[2], v3[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_divs) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2; + float s = 7.0f; + + GLM(vec3_divs)(v1, s, v2); + + ASSERT(test_eq(v1[0] / s, v2[0])) + ASSERT(test_eq(v1[1] / s, v2[1])) + ASSERT(test_eq(v1[2] / s, v2[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_addadd) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3 = {1.0f, 2.0f, 3.0f}, + v4 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_addadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] + v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] + v2[1], v4[1])) + ASSERT(test_eq(v3[2] + v1[2] + v2[2], v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_subadd) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3 = {1.0f, 2.0f, 3.0f}, + v4 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_subadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] - v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] - v2[1], v4[1])) + ASSERT(test_eq(v3[2] + v1[2] - v2[2], v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_muladd) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3 = {1.0f, 2.0f, 3.0f}, + v4 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_muladd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] * v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] * v2[1], v4[1])) + ASSERT(test_eq(v3[2] + v1[2] * v2[2], v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_muladds) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {1.0f, 2.0f, 3.0f}, + v3 = {1.0f, 2.0f, 3.0f}; + float s = 9.0f; + + GLM(vec3_muladds)(v1, s, v3); + + ASSERT(test_eq(v2[0] + v1[0] * s, v3[0])) + ASSERT(test_eq(v2[1] + v1[1] * s, v3[1])) + ASSERT(test_eq(v2[2] + v1[2] * s, v3[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_maxadd) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3 = {1.0f, 2.0f, 3.0f}, + v4 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_maxadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + glm_max(v1[0], v2[0]), v4[0])) + ASSERT(test_eq(v3[1] + glm_max(v1[1], v2[1]), v4[1])) + ASSERT(test_eq(v3[2] + glm_max(v1[2], v2[2]), v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_minadd) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3 = {1.0f, 2.0f, 3.0f}, + v4 = {1.0f, 2.0f, 3.0f}; + + GLM(vec3_minadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + glm_min(v1[0], v2[0]), v4[0])) + ASSERT(test_eq(v3[1] + glm_min(v1[1], v2[1]), v4[1])) + ASSERT(test_eq(v3[2] + glm_min(v1[2], v2[2]), v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_negate_to) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3, v4; + + GLM(vec3_negate_to)(v1, v3); + GLM(vec3_negate_to)(v2, v4); + + ASSERT(test_eq(-v1[0], v3[0])) + ASSERT(test_eq(-v1[1], v3[1])) + ASSERT(test_eq(-v1[2], v3[2])) + + ASSERT(test_eq(-v2[0], v4[0])) + ASSERT(test_eq(-v2[1], v4[1])) + ASSERT(test_eq(-v2[2], v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_negate) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f}, + v3 = {2.0f, -3.0f, 4.0f}, + v4 = {-3.0f, 4.0f, -5.0f}; + + GLM(vec3_negate)(v1); + GLM(vec3_negate)(v2); + + ASSERT(test_eq(-v1[0], v3[0])) + ASSERT(test_eq(-v1[1], v3[1])) + ASSERT(test_eq(-v1[2], v3[2])) + + ASSERT(test_eq(-v2[0], v4[0])) + ASSERT(test_eq(-v2[1], v4[1])) + ASSERT(test_eq(-v2[2], v4[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_normalize) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2 = {2.0f, -3.0f, 4.0f}; + float s = 1.0f; + float norm; + + GLM(vec3_normalize)(v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + + glm_vec3_zero(v1); + GLM(vec3_normalize)(v1); + ASSERTIFY(test_assert_vec3_eq(v1, GLM_VEC3_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_normalize_to) { + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2; + float s = 1.0f; + float norm; + + GLM(vec3_normalize_to)(v1, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + + glm_vec3_zero(v1); + GLM(vec3_normalize_to)(v1, v2); + ASSERTIFY(test_assert_vec3_eq(v2, GLM_VEC3_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, normalize) { + /* SAME AS VEC3_NORMALIZE */ + + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2 = {2.0f, -3.0f, 4.0f}; + float s = 1.0f; + float norm; + + GLM(vec3_normalize)(v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + + glm_vec3_zero(v1); + GLM(vec3_normalize)(v1); + ASSERTIFY(test_assert_vec3_eq(v1, GLM_VEC3_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, normalize_to) { + /* SAME AS VEC3_NORMALIZE_TO */ + + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2; + float s = 1.0f; + float norm; + + GLM(vec3_normalize_to)(v1, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + + glm_vec3_zero(v1); + GLM(vec3_normalize_to)(v1, v2); + ASSERTIFY(test_assert_vec3_eq(v2, GLM_VEC3_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_cross) { + /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2 = {12.0f, -31.0f, 43.0f}, v3, v4; + + GLM(vec3_cross)(v1, v2, v3); + + v4[0] = v1[1] * v2[2] - v1[2] * v2[1]; + v4[1] = v1[2] * v2[0] - v1[0] * v2[2]; + v4[2] = v1[0] * v2[1] - v1[1] * v2[0]; + + ASSERTIFY(test_assert_vec3_eq(v3, v4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_crossn) { + /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2 = {12.0f, -31.0f, 43.0f}, v3, v4; + + GLM(vec3_crossn)(v1, v2, v3); + + v4[0] = v1[1] * v2[2] - v1[2] * v2[1]; + v4[1] = v1[2] * v2[0] - v1[0] * v2[2]; + v4[2] = v1[0] * v2[1] - v1[1] * v2[0]; + + glm_normalize(v4); + + ASSERTIFY(test_assert_vec3_eq(v3, v4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, cross) { + /* SAME AS VEC3_CROSS */ + + /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ + vec3 v1 = {2.0f, -3.0f, 4.0f}, v2 = {12.0f, -31.0f, 43.0f}, v3, v4; + + GLM(vec3_cross)(v1, v2, v3); + + v4[0] = v1[1] * v2[2] - v1[2] * v2[1]; + v4[1] = v1[2] * v2[0] - v1[0] * v2[2]; + v4[2] = v1[0] * v2[1] - v1[1] * v2[0]; + + ASSERTIFY(test_assert_vec3_eq(v3, v4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_angle) { + vec3 v1 = {1.0f, 0.0f, 0.0f}, + v2 = {1.0f, 0.0f, 1.0f}, + v3 = {0.0f, 1.0f, 0.0f}; + float a; + + a = GLM(vec3_angle)(v1, v1); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, 0.0f)) + + a = GLM(vec3_angle)(v1, v2); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, GLM_PI_4f)) + + a = GLM(vec3_angle)(v1, v3); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, GLM_PI_2f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_rotate) { + vec3 v1 = {1.0f, 0.0f, 0.0f}, v2 = {1.0f, 1.0f, 1.0f}; + + /* rotate X around Y = -Z */ + GLM(vec3_rotate)(v1, GLM_PI_2f, GLM_YUP); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + /* rotate -Z around X = Y */ + GLM(vec3_rotate)(v1, GLM_PI_2f, GLM_XUP); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate Y around Z = -X */ + GLM(vec3_rotate)(v1, GLM_PI_2f, GLM_ZUP); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate)(v2, GLM_PI_2f, GLM_YUP); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate)(v2, GLM_PI_2f, GLM_YUP); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate)(v2, GLM_PI_2f, GLM_YUP); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around X by 90deg */ + GLM(vec3_rotate)(v2, GLM_PI_2f, GLM_XUP); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around Z by 90deg */ + GLM(vec3_rotate)(v2, GLM_PI_2f, GLM_ZUP); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_rotate_m4) { + vec3 v1 = {1.0f, 0.0f, 0.0f}, v2 = {1.0f, 1.0f, 1.0f}; + mat4 x, y, z; + + glm_rotate_make(x, GLM_PI_2f, GLM_XUP); + glm_rotate_make(y, GLM_PI_2f, GLM_YUP); + glm_rotate_make(z, GLM_PI_2f, GLM_ZUP); + + /* rotate X around Y = -Z */ + GLM(vec3_rotate_m4)(y, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + /* rotate -Z around X = Y */ + GLM(vec3_rotate_m4)(x, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate Y around X = -X */ + GLM(vec3_rotate_m4)(z, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate_m4)(y, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate_m4)(y, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate_m4)(y, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around X by 90deg */ + GLM(vec3_rotate_m4)(x, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around Z by 90deg */ + GLM(vec3_rotate_m4)(z, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_rotate_m3) { + vec3 v1 = {1.0f, 0.0f, 0.0f}, v2 = {1.0f, 1.0f, 1.0f}; + mat4 x0, y0, z0; + mat3 x, y, z; + + glm_rotate_make(x0, GLM_PI_2f, GLM_XUP); + glm_rotate_make(y0, GLM_PI_2f, GLM_YUP); + glm_rotate_make(z0, GLM_PI_2f, GLM_ZUP); + + glm_mat4_pick3(x0, x); + glm_mat4_pick3(y0, y); + glm_mat4_pick3(z0, z); + + /* rotate X around Y = -Z */ + GLM(vec3_rotate_m3)(y, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], -1.0f)) + + /* rotate -Z around X = Y */ + GLM(vec3_rotate_m3)(x, v1, v1); + + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 1.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate Y around Z = -X */ + GLM(vec3_rotate_m3)(z, v1, v1); + + ASSERT(test_eq(v1[0], -1.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate_m3)(y, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate_m3)(y, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], -1.0f)) + + /* rotate v2 around Y by 90deg */ + GLM(vec3_rotate_m3)(y, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around X by 90deg */ + GLM(vec3_rotate_m3)(x, v2, v2); + + ASSERT(test_eq(v2[0], -1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + /* rotate v2 around Z by 90deg */ + GLM(vec3_rotate_m3)(z, v2, v2); + + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], -1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_proj) { + vec3 v1 = {3.0f, 4.0f, 0.0f}, + v2 = {10.0f, 0.0f, 0.0f}, + v3 = {0.0f, 10.0f, 0.0f}, + v4 = {3.0f, 0.0f, 0.0f}, + v5 = {0.0f, 4.0f, 0.0f}, + v6; + + GLM(vec3_proj)(v1, v2, v6); + ASSERTIFY(test_assert_vec3_eq(v4, v6)) + + GLM(vec3_proj)(v1, v3, v6); + ASSERTIFY(test_assert_vec3_eq(v5, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_center) { + vec3 v1 = {30.0f, 0.0f, 0.0f}, + v2 = {0.0f, 0.0f, 0.0f}, + v3 = {15.0f, 0.0f, 0.0f}, + v4 = {3.0f, 10.0f, 120.0f}, + v5 = {0.46f, 4.0f, 14.0f}, + v6; + + GLM(vec3_center)(v1, v2, v6); + ASSERTIFY(test_assert_vec3_eq(v3, v6)) + + GLM(vec3_center)(v4, v5, v6); + ASSERT(test_eq((v4[0] + v5[0]) * 0.5f, v6[0])) + ASSERT(test_eq((v4[1] + v5[1]) * 0.5f, v6[1])) + ASSERT(test_eq((v4[2] + v5[2]) * 0.5f, v6[2])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_distance2) { + vec3 v1 = {30.0f, 0.0f, 0.0f}, + v2 = {0.0f, 0.0f, 0.0f}, + v3 = {3.0f, 10.0f, 120.0f}, + v4 = {0.46f, 4.0f, 14.0f}; + float d; + + d = GLM(vec3_distance2)(v1, v2); + ASSERT(test_eq(d, 30.0f * 30.0f)) + + d = GLM(vec3_distance2)(v3, v4); + ASSERT(test_eq(powf(v3[0] - v4[0], 2.0f) + + powf(v3[1] - v4[1], 2.0f) + + powf(v3[2] - v4[2], 2.0f), d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_distance) { + vec3 v1 = {30.0f, 0.0f, 0.0f}, + v2 = {0.0f, 0.0f, 0.0f}, + v3 = {3.0f, 10.0f, 120.0f}, + v4 = {0.46f, 4.0f, 14.0f}; + float d; + + d = GLM(vec3_distance)(v1, v2); + ASSERT(test_eq(d, 30.0f)) + + d = GLM(vec3_distance)(v3, v4); + ASSERT(test_eq(sqrtf(powf(v3[0] - v4[0], 2.0f) + + powf(v3[1] - v4[1], 2.0f) + + powf(v3[2] - v4[2], 2.0f)), d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_maxv) { + vec3 v1, v2, v3; + vec3 v5 = {-1.456f, -1.456f, 241.456f}; + vec3 v6 = {11.0f, 11.0f, 11.0f}; + vec3 v7 = {78.0f, -78.0f, 7.0f}; + + GLM(vec3_maxv)(v5, v6, v1); + GLM(vec3_maxv)(v5, v7, v2); + GLM(vec3_maxv)(v6, v7, v3); + + ASSERT(test_eq(v1[0], 11.0f)) + ASSERT(test_eq(v1[1], 11.0f)) + ASSERT(test_eq(v1[2], 241.456f)) + + ASSERT(test_eq(v2[0], 78.0f)) + ASSERT(test_eq(v2[1], -1.456f)) + ASSERT(test_eq(v2[2], 241.456f)) + + ASSERT(test_eq(v3[0], 78.0f)) + ASSERT(test_eq(v3[1], 11.0f)) + ASSERT(test_eq(v3[2], 11.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_minv) { + vec3 v1, v2, v3; + vec3 v5 = {-1.456f, -1.456f, 241.456f}; + vec3 v6 = {11.0f, 11.0f, 11.0f}; + vec3 v7 = {78.0f, -78.0f, 7.0f}; + + GLM(vec3_minv)(v5, v6, v1); + GLM(vec3_minv)(v5, v7, v2); + GLM(vec3_minv)(v6, v7, v3); + + ASSERT(test_eq(v1[0], -1.456f)) + ASSERT(test_eq(v1[1], -1.456f)) + ASSERT(test_eq(v1[2], 11.0f)) + + ASSERT(test_eq(v2[0], -1.456f)) + ASSERT(test_eq(v2[1], -78.0f)) + ASSERT(test_eq(v2[2], 7.0f)) + + ASSERT(test_eq(v3[0], 11.0f)) + ASSERT(test_eq(v3[1], -78.0f)) + ASSERT(test_eq(v3[2], 7.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_ortho) { + vec3 v1, v2, v3, v4 = {1.f, 1.f, 1.f}; + vec3 v5, v6, v7, v8; + float a; + + test_rand_vec3(v1); + test_rand_vec3(v2); + test_rand_vec3(v3); + + GLM(vec3_ortho)(v1, v5); + GLM(vec3_ortho)(v2, v6); + GLM(vec3_ortho)(v3, v7); + GLM(vec3_ortho)(v4, v8); + + a = glm_vec3_angle(v1, v5); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, GLM_PI_2f)) + + a = glm_vec3_angle(v2, v6); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, GLM_PI_2f)) + + a = glm_vec3_angle(v3, v7); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, GLM_PI_2f)) + + a = glm_vec3_angle(v4, v8); + ASSERT(!isinf(a)) + ASSERT(!isnan(a)) + ASSERT(test_eq(a, GLM_PI_2f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_clamp) { + vec3 v1 = {-1.456f, -11.456f, 31.456f}; + vec3 v2 = {0.110f, 111.0f, 11.0f}; + vec3 v3 = {78.0f, 32.0f, -78.0f}; + + GLM(vec3_clamp)(v1, -1.03f, 30.0f); + GLM(vec3_clamp)(v2, 0.11f, 111.0f); + GLM(vec3_clamp)(v3, -88.0f, 70.0f); + + ASSERT(test_eq(v1[0], -1.03f)) + ASSERT(test_eq(v1[1], -1.03f)) + ASSERT(test_eq(v1[2], 30.0f)) + + ASSERT(test_eq(v2[0], 0.11f)) + ASSERT(test_eq(v2[1], 111.0f)) + ASSERT(test_eq(v2[2], 11.0f)) + + ASSERT(test_eq(v3[0], 70.0f)) + ASSERT(test_eq(v3[1], 32.0f)) + ASSERT(test_eq(v3[2], -78.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_lerp) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 v2 = {100.0f, 200.0f, 10.0f}; + vec3 v3; + + GLM(vec3_lerp)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + + GLM(vec3_lerp)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_lerpc) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 v2 = {100.0f, 200.0f, 10.0f}; + vec3 v3; + + GLM(vec3_lerpc)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + + GLM(vec3_lerpc)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + + GLM(vec3_lerpc)(v1, v2, -1.75f, v3); + ASSERT(test_eq(v3[0], -100.0f)) + ASSERT(test_eq(v3[1], -200.0f)) + ASSERT(test_eq(v3[2], -10.0f)) + + GLM(vec3_lerpc)(v1, v2, 1.75f, v3); + ASSERT(test_eq(v3[0], 100.0f)) + ASSERT(test_eq(v3[1], 200.0f)) + ASSERT(test_eq(v3[2], 10.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_mix) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 v2 = {100.0f, 200.0f, 10.0f}; + vec3 v3; + + GLM(vec3_mix)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + + GLM(vec3_mix)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_mixc) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 v2 = {100.0f, 200.0f, 10.0f}; + vec3 v3; + + GLM(vec3_mixc)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + + GLM(vec3_mixc)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + + GLM(vec3_mixc)(v1, v2, -1.75f, v3); + ASSERT(test_eq(v3[0], -100.0f)) + ASSERT(test_eq(v3[1], -200.0f)) + ASSERT(test_eq(v3[2], -10.0f)) + + GLM(vec3_mixc)(v1, v2, 1.75f, v3); + ASSERT(test_eq(v3[0], 100.0f)) + ASSERT(test_eq(v3[1], 200.0f)) + ASSERT(test_eq(v3[2], 10.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_step_uni) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 v2; + + GLM(vec3_step_uni)(-2.5f, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 0.0f)) + + GLM(vec3_step_uni)(-10.0f, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + GLM(vec3_step_uni)(-1000.0f, v1, v2); + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_step) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 s1 = {-100.0f, 0.0f, 10.0f}; + vec3 s2 = {100.0f, -220.0f, -10.0f}; + vec3 s3 = {100.0f, 200.0f, 10.0f}; + vec3 v2; + + GLM(vec3_step)(s1, v1, v2); + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 0.0f)) + + GLM(vec3_step)(s2, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + + GLM(vec3_step)(s3, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_smoothstep_uni) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 v2; + + GLM(vec3_smoothstep_uni)(-200.0f, -100.0f, v1, v2); + ASSERT(test_eq_th(v2[0], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[2], 1.0f, 1e-5f)) + + GLM(vec3_smoothstep_uni)(-250.0f, -200.0f, v1, v2); + ASSERT(test_eq_th(v2[0], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[2], 1.0f, 1e-5f)) + + GLM(vec3_smoothstep_uni)(-200.0f, 200, v1, v2); + ASSERT(v2[0] > 0.0f && v2[0] < 0.25f) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(v2[2] > 0.0f && v2[2] < 0.5f) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_smoothstep) { + vec3 v1 = {-100.0f, -200.0f, -10.0f}; + vec3 e1_0 = {-100.0f, 0.0f, -11.0f}; + vec3 e1_1 = {50.0f, 10.0f, 20.0f}; + vec3 e2_0 = {-180.0f, -300.0f, -93.0f}; + vec3 e2_1 = {100.0f, 120.0f, -10.0f}; + vec3 e3_0 = {-12.0f, 100.0f, 0.0f}; + vec3 e3_1 = {100.0f, 200.0f, 10.0f}; + vec3 v2; + + GLM(vec3_smoothstep)(e1_0, e1_1, v1, v2); + ASSERT(test_eq_th(v2[0], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 0.0f, 1e-5f)) + ASSERT(v2[2] > 0.0f && v2[2] < 0.1f) + + GLM(vec3_smoothstep)(e2_0, e2_1, v1, v2); + ASSERT(v2[0] > 0.0f && v2[0] < 0.25f) + ASSERT(v2[1] > 0.0f && v2[1] < 0.15f) + ASSERT(test_eq_th(v2[2], 1.0f, 1e-5f)) + + GLM(vec3_smoothstep)(e3_0, e3_1, v1, v2); + ASSERT(test_eq_th(v2[0], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[2], 0.0f, 1e-5f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_smoothinterp) { + vec3 e1_0 = {-100.0f, 0.0f, -11.0f}; + vec3 e1_1 = {50.0f, 10.0f, 20.0f}; + vec3 e2_0 = {80.0f, -220.0f, -19.0f}; + vec3 e2_1 = {100.0f, -200.0f, -10.0f}; + vec3 e3_0 = {-12.0f, 100.0f, 0.0f}; + vec3 e3_1 = {100.0f, 200.0f, 10.0f}; + vec3 v2; + + GLM(vec3_smoothinterp)(e1_0, e1_1, 0.5f, v2); + ASSERT(v2[0] >= e1_0[0] && v2[0] <= e1_1[0]) + ASSERT(v2[1] >= e1_0[1] && v2[1] <= e1_1[1]) + ASSERT(v2[2] >= e1_0[2] && v2[2] <= e1_1[2]) + + GLM(vec3_smoothinterp)(e2_0, e2_1, 0.5, v2); + ASSERT(v2[0] >= e2_0[0] && v2[0] <= e2_1[0]) + ASSERT(v2[1] >= e2_0[1] && v2[1] <= e2_1[1]) + ASSERT(v2[2] >= e2_0[2] && v2[2] <= e2_1[2]) + + GLM(vec3_smoothinterp)(e3_0, e3_1, 1.0, v2); + ASSERT(v2[0] >= e3_0[0] && v2[0] <= e3_1[0]) + ASSERT(v2[1] >= e3_0[1] && v2[1] <= e3_1[1]) + ASSERT(v2[2] >= e3_0[2] && v2[2] <= e3_1[2]) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_smoothinterpc) { + vec3 e1_0 = {-100.0f, 0.0f, -11.0f}; + vec3 e1_1 = {50.0f, 10.0f, 20.0f}; + vec3 e2_0 = {80.0f, -220.0f, -19.0f}; + vec3 e2_1 = {100.0f, -200.0f, -10.0f}; + vec3 e3_0 = {-12.0f, 100.0f, 0.0f}; + vec3 e3_1 = {100.0f, 200.0f, 10.0f}; + vec3 v2; + + GLM(vec3_smoothinterpc)(e1_0, e1_1, -0.5f, v2); + ASSERT(v2[0] >= e1_0[0] && v2[0] <= e1_1[0]) + ASSERT(v2[1] >= e1_0[1] && v2[1] <= e1_1[1]) + ASSERT(v2[2] >= e1_0[2] && v2[2] <= e1_1[2]) + + GLM(vec3_smoothinterpc)(e2_0, e2_1, 0.5f, v2); + ASSERT(v2[0] >= e2_0[0] && v2[0] <= e2_1[0]) + ASSERT(v2[1] >= e2_0[1] && v2[1] <= e2_1[1]) + ASSERT(v2[2] >= e2_0[2] && v2[2] <= e2_1[2]) + + GLM(vec3_smoothinterpc)(e3_0, e3_1, 2.0f, v2); + ASSERT(v2[0] >= e3_0[0] && v2[0] <= e3_1[0]) + ASSERT(v2[1] >= e3_0[1] && v2[1] <= e3_1[1]) + ASSERT(v2[2] >= e3_0[2] && v2[2] <= e3_1[2]) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_swizzle) { + vec3 v; + + /* ZYX */ + v[0] = 1; + v[1] = 2; + v[2] = 3; + + glm_vec3_swizzle(v, GLM_ZYX, v); + ASSERTIFY(test_assert_vec3_eq(v, (vec3){3, 2, 1})) + + glm_vec3_swizzle(v, GLM_XXX, v); + ASSERTIFY(test_assert_vec3_eq(v, (vec3){3, 3, 3})) + + v[0] = 1; + v[1] = 2; + v[2] = 3; + + glm_vec3_swizzle(v, GLM_YYY, v); + ASSERTIFY(test_assert_vec3_eq(v, (vec3){2, 2, 2})) + + v[0] = 1; + v[1] = 2; + v[2] = 3; + + glm_vec3_swizzle(v, GLM_ZZZ, v); + ASSERTIFY(test_assert_vec3_eq(v, (vec3){3, 3, 3})) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_broadcast) { + vec3 v1, v2, v3; + vec3 v5 = {-1.456f, -1.456f, -1.456f}; + vec3 v6 = {11.0f, 11.0f, 11.0f}; + vec3 v7 = {78.0f, 78.0f, 78.0f}; + + GLM(vec3_broadcast)(-1.456f, v1); + GLM(vec3_broadcast)(11.0f, v2); + GLM(vec3_broadcast)(78.0f, v3); + + ASSERTIFY(test_assert_vec3_eq(v1, v5)) + ASSERTIFY(test_assert_vec3_eq(v2, v6)) + ASSERTIFY(test_assert_vec3_eq(v3, v7)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_fill) { + vec3 v1, v2, v3; + vec3 v5 = {-1.456f, -1.456f, -1.456f}; + vec3 v6 = {11.0f, 11.0f, 11.0f}; + vec3 v7 = {78.0f, 78.0f, 78.0f}; + + GLM(vec3_fill)(v1, -1.456f); + GLM(vec3_fill)(v2, 11.0f); + GLM(vec3_fill)(v3, 78.0f); + + ASSERTIFY(test_assert_vec3_eq(v1, v5)) + ASSERTIFY(test_assert_vec3_eq(v2, v6)) + ASSERTIFY(test_assert_vec3_eq(v3, v7)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_eq) { + vec3 v1, v2, v3; + + GLM(vec3_fill)(v1, -1.456f); + GLM(vec3_fill)(v2, 11.0f); + GLM(vec3_fill)(v3, 78.1f); + + ASSERT(GLM(vec3_eq)(v1, -1.456f)) + ASSERT(GLM(vec3_eq)(v2, 11.0f)) + ASSERT(!GLM(vec3_eq)(v3, 78.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_eq_eps) { + vec3 v1, v2, v3; + + GLM(vec3_fill)(v1, -1.456f); + GLM(vec3_fill)(v2, 11.0f); + GLM(vec3_fill)(v3, 78.1f); + + ASSERT(GLM(vec3_eq_eps)(v1, -1.456f)) + ASSERT(GLM(vec3_eq_eps)(v2, 11.0f)) + ASSERT(!GLM(vec3_eq_eps)(v3, 78.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_eq_all) { + vec3 v1, v2, v3; + vec3 v4 = {2.104f, -3.012f, -4.10f}; + vec3 v5 = {-12.35f, -31.140f, -43.502f}; + + GLM(vec3_fill)(v1, -1.456f); + GLM(vec3_fill)(v2, 11.0f); + GLM(vec3_fill)(v3, 78.0f); + + ASSERT(GLM(vec3_eq_all)(v1)) + ASSERT(GLM(vec3_eq_all)(v2)) + ASSERT(GLM(vec3_eq_all)(v3)) + ASSERT(!GLM(vec3_eq_all)(v4)) + ASSERT(!GLM(vec3_eq_all)(v5)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_eqv) { + vec3 v1, v2, v3, v4, v5; + vec3 v6 = {-1.456f, -1.456f, -1.456f}; + vec3 v7 = {11.0f, 11.0f, 11.0f}; + vec3 v8 = {78.0f, 78.0f, -43.502f}; + + GLM(vec3_fill)(v1, -1.456f); + GLM(vec3_fill)(v2, 11.0f); + GLM(vec3_fill)(v3, 78.0f); + + test_rand_vec3(v4); + test_rand_vec3(v5); + + ASSERT(GLM(vec3_eqv)(v1, v6)) + ASSERT(GLM(vec3_eqv)(v2, v7)) + ASSERT(!GLM(vec3_eqv)(v3, v8)) + ASSERT(!GLM(vec3_eqv)(v4, v5)) + ASSERT(GLM(vec3_eqv)(v5, v5)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_eqv_eps) { + vec3 v1, v2, v3, v4, v5; + vec3 v6 = {-1.456f, -1.456f, -1.456f}; + vec3 v7 = {11.0f, 11.0f, 11.0f}; + vec3 v8 = {78.0f, 78.0f, -43.502f}; + + GLM(vec3_fill)(v1, -1.456f); + GLM(vec3_fill)(v2, 11.0f); + GLM(vec3_fill)(v3, 78.0f); + + test_rand_vec3(v4); + test_rand_vec3(v5); + + ASSERT(GLM(vec3_eqv_eps)(v1, v6)) + ASSERT(GLM(vec3_eqv_eps)(v2, v7)) + ASSERT(!GLM(vec3_eqv_eps)(v3, v8)) + ASSERT(!GLM(vec3_eqv_eps)(v4, v5)) + ASSERT(GLM(vec3_eqv_eps)(v5, v5)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_max) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3 = {INFINITY, 0.0f, 0.0f}, v4 = {NAN, INFINITY, 2.0f}; + vec3 v5 = {NAN, -1.0f, -1.0f}, v6 = {-1.0f, -11.0f, 11.0f}; + + ASSERT(test_eq(GLM(vec3_max)(v1), 2.104f)) + ASSERT(test_eq(GLM(vec3_max)(v2), -12.35f)) + ASSERT(isinf(GLM(vec3_max)(v3))) + ASSERT(isnan(GLM(vec3_max)(v4))) + ASSERT(isnan(GLM(vec3_max)(v5))) + ASSERT(test_eq(GLM(vec3_max)(v6), 11.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_min) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3 = {INFINITY, 0.0f, 0.0f}, v4 = {NAN, INFINITY, 2.0f}; + vec3 v5 = {NAN, -1.0f, -1.0f}, v6 = {-1.0f, -11.0f, 11.0f}; + + ASSERT(test_eq(GLM(vec3_min)(v1), -4.10f)) + ASSERT(test_eq(GLM(vec3_min)(v2), -43.502f)) + ASSERT(test_eq(GLM(vec3_min)(v3), 0.0f)) + ASSERT(isnan(GLM(vec3_min)(v4))) + ASSERT(isnan(GLM(vec3_min)(v5))) + ASSERT(test_eq(GLM(vec3_min)(v6), -11.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_isnan) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3 = {INFINITY, 0.0f, 0.0f}, v4 = {NAN, INFINITY, 2.0f}; + vec3 v5 = {NAN, -1.0f, -1.0f}, v6 = {-1.0f, -1.0f, 11.0f}; + + ASSERT(!GLM(vec3_isnan)(v1)) + ASSERT(!GLM(vec3_isnan)(v2)) + ASSERT(!GLM(vec3_isnan)(v3)) + ASSERT(GLM(vec3_isnan)(v4)) + ASSERT(GLM(vec3_isnan)(v5)) + ASSERT(!GLM(vec3_isnan)(v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_isinf) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3 = {INFINITY, 0.0f, 0.0f}, v4 = {NAN, INFINITY, 2.0f}; + vec3 v5 = {NAN, -1.0f, -1.0f}, v6 = {-1.0f, -1.0f, 11.0f}; + + ASSERT(!GLM(vec3_isinf)(v1)) + ASSERT(!GLM(vec3_isinf)(v2)) + ASSERT(GLM(vec3_isinf)(v3)) + ASSERT(GLM(vec3_isinf)(v4)) + ASSERT(!GLM(vec3_isinf)(v5)) + ASSERT(!GLM(vec3_isinf)(v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_isvalid) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3 = {INFINITY, 0.0f, 0.0f}, v4 = {NAN, INFINITY, 2.0f}; + vec3 v5 = {NAN, -1.0f, -1.0f}, v6 = {-1.0f, -1.0f, 11.0f}; + + ASSERT(GLM(vec3_isvalid)(v1)) + ASSERT(GLM(vec3_isvalid)(v2)) + ASSERT(!GLM(vec3_isvalid)(v3)) + ASSERT(!GLM(vec3_isvalid)(v4)) + ASSERT(!GLM(vec3_isvalid)(v5)) + ASSERT(GLM(vec3_isvalid)(v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_sign) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3, v4; + vec3 v5 = {1.0f, -1.0f, -1.0f}, v6 = {-1.0f, -1.0f, -1.0f}; + + GLM(vec3_sign)(v1, v3); + GLM(vec3_sign)(v2, v4); + + ASSERTIFY(test_assert_vec3_eq(v3, v5)) + ASSERTIFY(test_assert_vec3_eq(v4, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_abs) { + vec3 v1 = {2.104f, -3.012f, -4.10f}, v2 = {-12.35f, -31.140f, -43.502f}; + vec3 v3, v4; + vec3 v5 = {2.104f, 3.012f, 4.10f}, v6 = {12.35f, 31.140f, 43.502f}; + + GLM(vec3_abs)(v1, v3); + GLM(vec3_abs)(v2, v4); + + ASSERTIFY(test_assert_vec3_eq(v3, v5)) + ASSERTIFY(test_assert_vec3_eq(v4, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_fract) { + vec3 v1 = {2.104f, 3.012f, 4.10f}, v2 = {12.35f, 31.140f, 43.502f}, v3, v4; + vec3 v5 = {0.104f, 0.012f, 0.10f}, v6 = {0.35f, 0.140f, 0.502f}; + + GLM(vec3_fract)(v1, v3); + GLM(vec3_fract)(v2, v4); + + ASSERTIFY(test_assert_vec3_eq(v3, v5)) + ASSERTIFY(test_assert_vec3_eq(v4, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_hadd) { + vec3 v1 = {2.0f, 3.0f, 4.0f}, v2 = {12.0f, 31.0f, 43.0f}; + float r1, r2, r3, r4; + + r1 = GLM(vec3_hadd)(v1); + r2 = GLM(vec3_hadd)(v2); + + r3 = v1[0] + v1[1] + v1[2]; + r4 = v2[0] + v2[1] + v2[2]; + + ASSERT(test_eq(r1, r3)) + ASSERT(test_eq(r2, r4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec3_sqrt) { + vec3 v1 = {2.0f, 3.0f, 4.0f}, v2 = {12.0f, 31.0f, 43.0f}, v3, v4; + + GLM(vec3_sqrt)(v1, v3); + GLM(vec3_sqrt)(v2, v4); + + ASSERT(test_eq(sqrtf(v1[0]), v3[0])) + ASSERT(test_eq(sqrtf(v1[1]), v3[1])) + ASSERT(test_eq(sqrtf(v1[2]), v3[2])) + + ASSERT(test_eq(sqrtf(v2[0]), v4[0])) + ASSERT(test_eq(sqrtf(v2[1]), v4[1])) + ASSERT(test_eq(sqrtf(v2[2]), v4[2])) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/test_vec4.h b/libs/cglm/test/src/test_vec4.h new file mode 100644 index 0000000..abb882f --- /dev/null +++ b/libs/cglm/test/src/test_vec4.h @@ -0,0 +1,1420 @@ +/* + * 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 TEST_GLM_SHUFFLE4(z, y, x, w) (((z) << 6) | ((y) << 4) | ((x) << 2)|(w)) + +#ifndef CGLM_TEST_VEC4_ONCE +#define CGLM_TEST_VEC4_ONCE + +/* Macros */ + +TEST_IMPL(MACRO_GLM_VEC4_ONE_INIT) { + vec4 v = GLM_VEC4_ONE_INIT; + + ASSERT(test_eq(v[0], 1.0f)) + ASSERT(test_eq(v[1], 1.0f)) + ASSERT(test_eq(v[2], 1.0f)) + ASSERT(test_eq(v[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC4_ZERO_INIT) { + vec4 v = GLM_VEC4_ZERO_INIT; + + ASSERT(test_eq(v[0], 0.0f)) + ASSERT(test_eq(v[1], 0.0f)) + ASSERT(test_eq(v[2], 0.0f)) + ASSERT(test_eq(v[3], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC4_ONE) { + ASSERT(test_eq(GLM_VEC4_ONE[0], 1.0f)) + ASSERT(test_eq(GLM_VEC4_ONE[1], 1.0f)) + ASSERT(test_eq(GLM_VEC4_ONE[2], 1.0f)) + ASSERT(test_eq(GLM_VEC4_ONE[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_VEC4_ZERO) { + ASSERT(test_eq(GLM_VEC4_ZERO[0], 0.0f)) + ASSERT(test_eq(GLM_VEC4_ZERO[1], 0.0f)) + ASSERT(test_eq(GLM_VEC4_ZERO[2], 0.0f)) + ASSERT(test_eq(GLM_VEC4_ZERO[3], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_XXXX) { + ASSERT(TEST_GLM_SHUFFLE4(0, 0, 0, 0) == GLM_XXXX) + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_YYYY) { + ASSERT(TEST_GLM_SHUFFLE4(1, 1, 1, 1) == GLM_YYYY) + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_ZZZZ) { + ASSERT(TEST_GLM_SHUFFLE4(2, 2, 2, 2) == GLM_ZZZZ) + TEST_SUCCESS +} + +TEST_IMPL(MACRO_GLM_WZYX) { + ASSERT(TEST_GLM_SHUFFLE4(0, 1, 2, 3) == GLM_WZYX) + TEST_SUCCESS +} + +/* Deprecated */ + +TEST_IMPL(MACRO_glm_vec4_dup) { + vec4 v1 = {13.0f, 12.0f, 11.0f, 56.0f}, v2; + + glm_vec4_dup(v1, v2); + + ASSERTIFY(test_assert_vec4_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec4_flipsign) { + vec4 v1 = {13.0f, -12.0f, 11.0f, 56.0f}, + v2 = {13.0f, -12.0f, 11.0f, 56.0f}, + v3 = {-13.0f, 12.0f, -11.0f, -56.0f}; + + glm_vec4_flipsign(v1); + glmc_vec4_flipsign(v2); + + ASSERTIFY(test_assert_vec4_eq(v1, v3)) + ASSERTIFY(test_assert_vec4_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec4_flipsign_to) { + vec4 v1 = {13.0f, -12.0f, 11.0f, 56.0f}, + v2 = {-13.0f, 12.0f, -11.0f, -56.0f}, + v3, v4; + + glm_vec4_flipsign_to(v1, v3); + glmc_vec4_flipsign_to(v1, v4); + + ASSERTIFY(test_assert_vec4_eq(v2, v3)) + ASSERTIFY(test_assert_vec4_eq(v2, v4)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec4_inv) { + vec4 v1 = {13.0f, -12.0f, 11.0f, 56.0f}, + v2 = {13.0f, -12.0f, 11.0f, 56.0f}, + v3 = {-13.0f, 12.0f, -11.0f, -56.0f}; + + glm_vec4_inv(v1); + glmc_vec4_inv(v2); + + ASSERTIFY(test_assert_vec4_eq(v1, v3)) + ASSERTIFY(test_assert_vec4_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec4_inv_to) { + vec4 v1 = {13.0f, -12.0f, 11.0f, 56.0f}, + v2 = {-13.0f, 12.0f, -11.0f, -56.0f}, + v3, v4; + + glm_vec4_inv_to(v1, v3); + glmc_vec4_inv_to(v1, v4); + + ASSERTIFY(test_assert_vec4_eq(v3, v4)) + ASSERTIFY(test_assert_vec4_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(MACRO_glm_vec4_mulv) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 56.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 56.0f}, + v3, v4; + + glm_vec4_mulv(v1, v2, v3); + glmc_vec4_mulv(v1, v2, v4); + + ASSERTIFY(test_assert_vec4_eq(v3, v4)) + + ASSERT(test_eq(v1[0] * v2[0], v3[0])) + ASSERT(test_eq(v1[1] * v2[1], v3[1])) + ASSERT(test_eq(v1[2] * v2[2], v3[2])) + ASSERT(test_eq(v1[3] * v2[3], v3[3])) + + TEST_SUCCESS +} + +#endif /* CGLM_TEST_VEC4_ONCE */ + +/* --- */ + +TEST_IMPL(GLM_PREFIX, vec4) { + vec4 v1 = {10.0f, 9.0f, 8.0f}; + vec4 v2 = {10.0f, 9.0f, 8.0f, 7.0f}; + vec4 v3; + + GLM(vec4)(v1, 7.0f, v3); + + ASSERTIFY(test_assert_vec4_eq(v2, v3)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_copy3) { + vec4 v4 = {10.0f, 9.0f, 8.0f, 7.0f}; + vec3 v3; + + GLM(vec4_copy3)(v4, v3); + + ASSERTIFY(test_assert_vec3_eq(v3, v4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_copy) { + vec4 v1 = {10.0f, 9.0f, 8.0f, 78.0f}; + vec4 v2 = {1.0f, 2.0f, 3.0f, 4.0f}; + + GLM(vec4_copy)(v1, v2); + + ASSERTIFY(test_assert_vec4_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_ucopy) { + vec4 v1 = {10.0f, 9.0f, 8.0f, 78.0f}; + vec4 v2 = {1.0f, 2.0f, 3.0f, 4.0f}; + + GLM(vec4_ucopy)(v1, v2); + + ASSERTIFY(test_assert_vec4_eq(v1, v2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_zero) { + vec4 v1 = {10.0f, 9.0f, 8.0f, 78.0f}; + vec4 v2 = {1.0f, 2.0f, 3.0f, 4.0f}; + + GLM(vec4_zero)(v1); + GLM(vec4_zero)(v2); + + ASSERTIFY(test_assert_vec4_eq(v1, GLM_VEC4_ZERO)) + ASSERTIFY(test_assert_vec4_eq(v2, GLM_VEC4_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_one) { + vec4 v1 = {10.0f, 9.0f, 8.0f, 78.0f}; + vec4 v2 = {1.0f, 2.0f, 3.0f, 4.0f}; + + GLM(vec4_one)(v1); + GLM(vec4_one)(v2); + + ASSERTIFY(test_assert_vec4_eq(v1, GLM_VEC4_ONE)) + ASSERTIFY(test_assert_vec4_eq(v2, GLM_VEC4_ONE)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_dot) { + vec4 a = {10.0f, 9.0f, 8.0f, 78.0f}; + vec4 b = {1.0f, 2.0f, 3.0f, 4.0f}; + float dot1, dot2; + + dot1 = GLM(vec4_dot)(a, b); + dot2 = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; + + ASSERT(test_eq(dot1, dot2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_norm2) { + vec4 a = {10.0f, 9.0f, 8.0f, 78.0f}; + float n1, n2; + + n1 = GLM(vec4_norm2)(a); + n2 = a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3]; + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_norm) { + vec4 a = {10.0f, 9.0f, 8.0f, 78.0f}; + float n1, n2; + + n1 = GLM(vec4_norm)(a); + n2 = sqrtf(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_norm_one) { + vec4 a = {-10.0f, 9.0f, -8.0f, 78.0f}; + float n1, n2; + + n1 = GLM(vec4_norm_one)(a); + n2 = fabsf(a[0]) + fabsf(a[1]) + fabsf(a[2]) + fabsf(a[3]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_norm_inf) { + vec4 a = {-10.0f, 9.0f, -8.0f, 78.0f}; + float n1, n2; + + n1 = GLM(vec4_norm_inf)(a); + n2 = fabsf(a[0]); + + if (n2 < fabsf(a[1])) + n2 = fabsf(a[1]); + + if (n2 < fabsf(a[2])) + n2 = fabsf(a[2]); + + if (n2 < fabsf(a[3])) + n2 = fabsf(a[3]); + + ASSERT(test_eq(n1, n2)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_add) { + vec4 a = {-10.0f, 9.0f, -8.0f, 56.0f}; + vec4 b = {12.0f, 19.0f, -18.0f, 1.0f}; + vec4 c, d; + + c[0] = a[0] + b[0]; + c[1] = a[1] + b[1]; + c[2] = a[2] + b[2]; + c[3] = a[3] + b[3]; + + GLM(vec4_add)(a, b, d); + + ASSERTIFY(test_assert_vec4_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_adds) { + vec4 a = {-10.0f, 9.0f, -8.0f, 56.0f}; + vec4 c, d; + float s = 7.0f; + + c[0] = a[0] + s; + c[1] = a[1] + s; + c[2] = a[2] + s; + c[3] = a[3] + s; + + GLM(vec4_adds)(a, s, d); + + ASSERTIFY(test_assert_vec4_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_sub) { + vec4 a = {-10.0f, 9.0f, -8.0f, 56.0f}; + vec4 b = {12.0f, 19.0f, -18.0f, 1.0f}; + vec4 c, d; + + c[0] = a[0] - b[0]; + c[1] = a[1] - b[1]; + c[2] = a[2] - b[2]; + c[3] = a[3] - b[3]; + + GLM(vec4_sub)(a, b, d); + + ASSERTIFY(test_assert_vec4_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_subs) { + vec4 a = {-10.0f, 9.0f, -8.0f, 74.0f}; + vec4 c, d; + float s = 7.0f; + + c[0] = a[0] - s; + c[1] = a[1] - s; + c[2] = a[2] - s; + c[3] = a[3] - s; + + GLM(vec4_subs)(a, s, d); + + ASSERTIFY(test_assert_vec4_eq(c, d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_mul) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 56.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 46.0f}, + v3; + + GLM(vec4_mul)(v1, v2, v3); + + ASSERT(test_eq(v1[0] * v2[0], v3[0])) + ASSERT(test_eq(v1[1] * v2[1], v3[1])) + ASSERT(test_eq(v1[2] * v2[2], v3[2])) + ASSERT(test_eq(v1[3] * v2[3], v3[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_scale) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2; + float s = 7.0f; + + GLM(vec4_scale)(v1, s, v2); + + ASSERT(test_eq(v1[0] * s, v2[0])) + ASSERT(test_eq(v1[1] * s, v2[1])) + ASSERT(test_eq(v1[2] * s, v2[2])) + ASSERT(test_eq(v1[3] * s, v2[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_scale_as) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2; + float s = 7.0f; + float norm; + + GLM(vec4_scale_as)(v1, s, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + ASSERT(test_eq(v1[3], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + ASSERT(test_eq(v1[3] * norm, v2[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_div) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 40.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 2.0f}, + v3; + + GLM(vec4_div)(v1, v2, v3); + + ASSERT(test_eq(v1[0] / v2[0], v3[0])) + ASSERT(test_eq(v1[1] / v2[1], v3[1])) + ASSERT(test_eq(v1[2] / v2[2], v3[2])) + ASSERT(test_eq(v1[3] / v2[3], v3[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_divs) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 40.0f}, v2; + float s = 7.0f; + + GLM(vec4_divs)(v1, s, v2); + + ASSERT(test_eq(v1[0] / s, v2[0])) + ASSERT(test_eq(v1[1] / s, v2[1])) + ASSERT(test_eq(v1[2] / s, v2[2])) + ASSERT(test_eq(v1[3] / s, v2[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_addadd) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 20.0f}, + v3 = {1.0f, 2.0f, 3.0f, 130.0f}, + v4 = {1.0f, 2.0f, 3.0f, 130.0f}; + + GLM(vec4_addadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] + v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] + v2[1], v4[1])) + ASSERT(test_eq(v3[2] + v1[2] + v2[2], v4[2])) + ASSERT(test_eq(v3[3] + v1[3] + v2[3], v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_subadd) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 20.0f}, + v3 = {1.0f, 2.0f, 3.0f, 130.0f}, + v4 = {1.0f, 2.0f, 3.0f, 130.0f}; + + GLM(vec4_subadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] - v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] - v2[1], v4[1])) + ASSERT(test_eq(v3[2] + v1[2] - v2[2], v4[2])) + ASSERT(test_eq(v3[3] + v1[3] - v2[3], v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_muladd) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 20.0f}, + v3 = {1.0f, 2.0f, 3.0f, 130.0f}, + v4 = {1.0f, 2.0f, 3.0f, 130.0f}; + + GLM(vec4_muladd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + v1[0] * v2[0], v4[0])) + ASSERT(test_eq(v3[1] + v1[1] * v2[1], v4[1])) + ASSERT(test_eq(v3[2] + v1[2] * v2[2], v4[2])) + ASSERT(test_eq(v3[3] + v1[3] * v2[3], v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_muladds) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 20.0f}, + v3 = {-3.0f, 4.0f, -5.0f, 20.0f}; + float s = 9.0f; + + GLM(vec4_muladds)(v1, s, v3); + + ASSERT(test_eq(v2[0] + v1[0] * s, v3[0])) + ASSERT(test_eq(v2[1] + v1[1] * s, v3[1])) + ASSERT(test_eq(v2[2] + v1[2] * s, v3[2])) + ASSERT(test_eq(v2[3] + v1[3] * s, v3[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_maxadd) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 20.0f}, + v3 = {1.0f, 2.0f, 3.0f, 130.0f}, + v4 = {1.0f, 2.0f, 3.0f, 130.0f}; + + GLM(vec4_maxadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + glm_max(v1[0], v2[0]), v4[0])) + ASSERT(test_eq(v3[1] + glm_max(v1[1], v2[1]), v4[1])) + ASSERT(test_eq(v3[2] + glm_max(v1[2], v2[2]), v4[2])) + ASSERT(test_eq(v3[3] + glm_max(v1[3], v2[3]), v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_minadd) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 4.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 20.0f}, + v3 = {1.0f, 2.0f, 3.0f, 130.0f}, + v4 = {1.0f, 2.0f, 3.0f, 130.0f}; + + GLM(vec4_minadd)(v1, v2, v4); + + ASSERT(test_eq(v3[0] + glm_min(v1[0], v2[0]), v4[0])) + ASSERT(test_eq(v3[1] + glm_min(v1[1], v2[1]), v4[1])) + ASSERT(test_eq(v3[2] + glm_min(v1[2], v2[2]), v4[2])) + ASSERT(test_eq(v3[3] + glm_min(v1[3], v2[3]), v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_negate_to) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 60.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 34.0f}, + v3, v4; + + GLM(vec4_negate_to)(v1, v3); + GLM(vec4_negate_to)(v2, v4); + + ASSERT(test_eq(-v1[0], v3[0])) + ASSERT(test_eq(-v1[1], v3[1])) + ASSERT(test_eq(-v1[2], v3[2])) + ASSERT(test_eq(-v1[3], v3[3])) + + ASSERT(test_eq(-v2[0], v4[0])) + ASSERT(test_eq(-v2[1], v4[1])) + ASSERT(test_eq(-v2[2], v4[2])) + ASSERT(test_eq(-v2[3], v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_negate) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 60.0f}, + v2 = {-3.0f, 4.0f, -5.0f, 34.0f}, + v3 = {2.0f, -3.0f, 4.0f, 60.0f}, + v4 = {-3.0f, 4.0f, -5.0f, 34.0f}; + + GLM(vec4_negate)(v1); + GLM(vec4_negate)(v2); + + ASSERT(test_eq(-v1[0], v3[0])) + ASSERT(test_eq(-v1[1], v3[1])) + ASSERT(test_eq(-v1[2], v3[2])) + ASSERT(test_eq(-v1[3], v3[3])) + + ASSERT(test_eq(-v2[0], v4[0])) + ASSERT(test_eq(-v2[1], v4[1])) + ASSERT(test_eq(-v2[2], v4[2])) + ASSERT(test_eq(-v2[3], v4[3])) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_normalize) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2 = {2.0f, -3.0f, 4.0f, 5.0f}; + float s = 1.0f; + float norm; + + GLM(vec4_normalize)(v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + ASSERT(test_eq(v1[3], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + ASSERT(test_eq(v1[3] * norm, v2[3])) + + glm_vec4_zero(v1); + GLM(vec4_normalize)(v1); + ASSERTIFY(test_assert_vec4_eq(v1, GLM_VEC4_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_normalize_to) { + vec4 v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2; + float s = 1.0f; + float norm; + + GLM(vec4_normalize_to)(v1, v2); + + norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]); + if (norm == 0.0f) { + ASSERT(test_eq(v1[0], 0.0f)) + ASSERT(test_eq(v1[1], 0.0f)) + ASSERT(test_eq(v1[2], 0.0f)) + ASSERT(test_eq(v1[3], 0.0f)) + + TEST_SUCCESS + } + + norm = s / norm; + + ASSERT(test_eq(v1[0] * norm, v2[0])) + ASSERT(test_eq(v1[1] * norm, v2[1])) + ASSERT(test_eq(v1[2] * norm, v2[2])) + ASSERT(test_eq(v1[3] * norm, v2[3])) + + glm_vec4_zero(v1); + GLM(vec4_normalize_to)(v1, v2); + ASSERTIFY(test_assert_vec4_eq(v2, GLM_VEC4_ZERO)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_distance2) { + vec4 v1 = {30.0f, 0.0f, 0.0f, 0.0f}, + v2 = {0.0f, 0.0f, 0.0f, 0.0f}, + v3 = {3.0f, 10.0f, 120.0f, 140.0f}, + v4 = {0.46f, 4.0f, 14.0f, 10.0f}; + float d; + + d = GLM(vec4_distance2)(v1, v2); + ASSERT(test_eq(d, 30.0f * 30.0f)) + + d = GLM(vec4_distance2)(v3, v4); + ASSERT(test_eq(powf(v3[0] - v4[0], 2.0f) + + powf(v3[1] - v4[1], 2.0f) + + powf(v3[2] - v4[2], 2.0f) + + powf(v3[3] - v4[3], 2.0f), d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_distance) { + vec4 v1 = {30.0f, 0.0f, 0.0f, 0.0f}, + v2 = {0.0f, 0.0f, 0.0f, 0.0f}, + v3 = {3.0f, 10.0f, 120.0f, 140.0f}, + v4 = {0.46f, 4.0f, 14.0f, 10.0f}; + float d; + + d = GLM(vec4_distance)(v1, v2); + ASSERT(test_eq(d, 30.0f)) + + d = GLM(vec4_distance)(v3, v4); + ASSERT(test_eq(sqrtf(powf(v3[0] - v4[0], 2.0f) + + powf(v3[1] - v4[1], 2.0f) + + powf(v3[2] - v4[2], 2.0f) + + powf(v3[3] - v4[3], 2.0f)), d)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_maxv) { + vec4 v1, v2, v3; + vec4 v5 = {-1.456f, -1.456f, 241.456f, 10.0f}; + vec4 v6 = {11.0f, 11.0f, 11.0f, 90.0f}; + vec4 v7 = {78.0f, -78.0f, 7.0f, 5.0f}; + + GLM(vec4_maxv)(v5, v6, v1); + GLM(vec4_maxv)(v5, v7, v2); + GLM(vec4_maxv)(v6, v7, v3); + + ASSERT(test_eq(v1[0], 11.0f)) + ASSERT(test_eq(v1[1], 11.0f)) + ASSERT(test_eq(v1[2], 241.456f)) + ASSERT(test_eq(v1[3], 90.0f)) + + ASSERT(test_eq(v2[0], 78.0f)) + ASSERT(test_eq(v2[1], -1.456f)) + ASSERT(test_eq(v2[2], 241.456f)) + ASSERT(test_eq(v2[3], 10.0f)) + + ASSERT(test_eq(v3[0], 78.0f)) + ASSERT(test_eq(v3[1], 11.0f)) + ASSERT(test_eq(v3[2], 11.0f)) + ASSERT(test_eq(v3[3], 90.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_minv) { + vec4 v1, v2, v3; + vec4 v5 = {-1.456f, -1.456f, 241.456f, 10.0f}; + vec4 v6 = {11.0f, 11.0f, 11.0f, 90.0f}; + vec4 v7 = {78.0f, -78.0f, 7.0f, 5.0f}; + + GLM(vec4_minv)(v5, v6, v1); + GLM(vec4_minv)(v5, v7, v2); + GLM(vec4_minv)(v6, v7, v3); + + ASSERT(test_eq(v1[0], -1.456f)) + ASSERT(test_eq(v1[1], -1.456f)) + ASSERT(test_eq(v1[2], 11.0f)) + ASSERT(test_eq(v1[3], 10.0f)) + + ASSERT(test_eq(v2[0], -1.456f)) + ASSERT(test_eq(v2[1], -78.0f)) + ASSERT(test_eq(v2[2], 7.0f)) + ASSERT(test_eq(v2[3], 5.0f)) + + ASSERT(test_eq(v3[0], 11.0f)) + ASSERT(test_eq(v3[1], -78.0f)) + ASSERT(test_eq(v3[2], 7.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_clamp) { + vec4 v1 = {-1.456f, -11.456f, 31.456f, 67.04f}; + vec4 v2 = {0.110f, 111.0f, 11.0f, 90.0f}; + vec4 v3 = {78.0f, 32.0f, -78.0f, 3.0f}; + + GLM(vec4_clamp)(v1, -1.03f, 30.0f); + GLM(vec4_clamp)(v2, 0.11f, 111.0f); + GLM(vec4_clamp)(v3, -88.0f, 70.0f); + + ASSERT(test_eq(v1[0], -1.03f)) + ASSERT(test_eq(v1[1], -1.03f)) + ASSERT(test_eq(v1[2], 30.0f)) + ASSERT(test_eq(v1[3], 30.0f)) + + ASSERT(test_eq(v2[0], 0.11f)) + ASSERT(test_eq(v2[1], 111.0f)) + ASSERT(test_eq(v2[2], 11.0f)) + ASSERT(test_eq(v2[3], 90.0f)) + + ASSERT(test_eq(v3[0], 70.0f)) + ASSERT(test_eq(v3[1], 32.0f)) + ASSERT(test_eq(v3[2], -78.0f)) + ASSERT(test_eq(v3[3], 3.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_lerp) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 v2 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v3; + + GLM(vec4_lerp)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + ASSERT(test_eq(v3[3], 0.0f)) + + GLM(vec4_lerp)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_lerpc) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 v2 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v3; + + GLM(vec4_lerpc)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + ASSERT(test_eq(v3[3], 0.0f)) + + GLM(vec4_lerpc)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + GLM(vec4_lerpc)(v1, v2, -1.75f, v3); + ASSERT(test_eq(v3[0], -100.0f)) + ASSERT(test_eq(v3[1], -200.0f)) + ASSERT(test_eq(v3[2], -10.0f)) + ASSERT(test_eq(v3[3], -10.0f)) + + GLM(vec4_lerpc)(v1, v2, 1.75f, v3); + ASSERT(test_eq(v3[0], 100.0f)) + ASSERT(test_eq(v3[1], 200.0f)) + ASSERT(test_eq(v3[2], 10.0f)) + ASSERT(test_eq(v3[3], 10.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_mix) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 v2 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v3; + + GLM(vec4_mix)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + ASSERT(test_eq(v3[3], 0.0f)) + + GLM(vec4_mix)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_mixc) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 v2 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v3; + + GLM(vec4_mixc)(v1, v2, 0.5f, v3); + ASSERT(test_eq(v3[0], 0.0f)) + ASSERT(test_eq(v3[1], 0.0f)) + ASSERT(test_eq(v3[2], 0.0f)) + ASSERT(test_eq(v3[3], 0.0f)) + + GLM(vec4_mixc)(v1, v2, 0.75f, v3); + ASSERT(test_eq(v3[0], 50.0f)) + ASSERT(test_eq(v3[1], 100.0f)) + ASSERT(test_eq(v3[2], 5.0f)) + ASSERT(test_eq(v3[3], 5.0f)) + + GLM(vec4_mixc)(v1, v2, -1.75f, v3); + ASSERT(test_eq(v3[0], -100.0f)) + ASSERT(test_eq(v3[1], -200.0f)) + ASSERT(test_eq(v3[2], -10.0f)) + ASSERT(test_eq(v3[3], -10.0f)) + + GLM(vec4_mixc)(v1, v2, 1.75f, v3); + ASSERT(test_eq(v3[0], 100.0f)) + ASSERT(test_eq(v3[1], 200.0f)) + ASSERT(test_eq(v3[2], 10.0f)) + ASSERT(test_eq(v3[3], 10.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_step_uni) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 v2; + + GLM(vec4_step_uni)(-2.5f, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 0.0f)) + ASSERT(test_eq(v2[3], 0.0f)) + + GLM(vec4_step_uni)(-10.0f, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + GLM(vec4_step_uni)(-1000.0f, v1, v2); + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_step) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 s1 = {-100.0f, 0.0f, 10.0f, 10.0f}; + vec4 s2 = {100.0f, -220.0f, -10.0f, -10.0f}; + vec4 s3 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v2; + + GLM(vec4_step)(s1, v1, v2); + ASSERT(test_eq(v2[0], 1.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 0.0f)) + ASSERT(test_eq(v2[3], 0.0f)) + + GLM(vec4_step)(s2, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 1.0f)) + ASSERT(test_eq(v2[2], 1.0f)) + ASSERT(test_eq(v2[3], 1.0f)) + + GLM(vec4_step)(s3, v1, v2); + ASSERT(test_eq(v2[0], 0.0f)) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(test_eq(v2[2], 0.0f)) + ASSERT(test_eq(v2[3], 0.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_smoothstep_uni) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 v2; + + GLM(vec4_smoothstep_uni)(-200.0f, -100.0f, v1, v2); + ASSERT(test_eq_th(v2[0], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[2], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[3], 1.0f, 1e-5f)) + + GLM(vec4_smoothstep_uni)(-250.0f, -200.0f, v1, v2); + ASSERT(test_eq_th(v2[0], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[2], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[3], 1.0f, 1e-5f)) + + GLM(vec4_smoothstep_uni)(-200.0f, 200.0f, v1, v2); + ASSERT(v2[0] > 0.0f && v2[0] < 0.25f) + ASSERT(test_eq(v2[1], 0.0f)) + ASSERT(v2[2] > 0.0f && v2[2] < 0.5f) + ASSERT(v2[3] > 0.0f && v2[3] < 0.5f) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_smoothstep) { + vec4 v1 = {-100.0f, -200.0f, -10.0f, -10.0f}; + vec4 e1_0 = {-100.0f, 0.0f, -11.0f, -11.0f}; + vec4 e1_1 = {50.0f, 10.0f, 20.0f, 20.0f}; + vec4 e2_0 = {-180.0f, -300.0f, -93.0f, -93.0f}; + vec4 e2_1 = {100.0f, 120.0f, -10.0f, -10.0f}; + vec4 e3_0 = {-12.0f, 100.0f, 0.0f, 0.0f}; + vec4 e3_1 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v2; + + GLM(vec4_smoothstep)(e1_0, e1_1, v1, v2); + ASSERT(test_eq_th(v2[0], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 0.0f, 1e-5f)) + ASSERT(v2[2] > 0.0f && v2[2] < 0.1f) + ASSERT(v2[3] > 0.0f && v2[3] < 0.1f) + + GLM(vec4_smoothstep)(e2_0, e2_1, v1, v2); + ASSERT(v2[0] > 0.0f && v2[0] < 0.25f) + ASSERT(v2[1] > 0.0f && v2[1] < 0.15f) + ASSERT(test_eq_th(v2[2], 1.0f, 1e-5f)) + ASSERT(test_eq_th(v2[3], 1.0f, 1e-5f)) + + GLM(vec4_smoothstep)(e3_0, e3_1, v1, v2); + ASSERT(test_eq_th(v2[0], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[1], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[2], 0.0f, 1e-5f)) + ASSERT(test_eq_th(v2[3], 0.0f, 1e-5f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_smoothinterp) { + vec4 e1_0 = {-100.0f, 0.0f, -11.0f, -11.0f}; + vec4 e1_1 = {50.0f, 10.0f, 20.0f, 20.0f}; + vec4 e2_0 = {80.0f, -220.0f, -19.0f, -19.0f}; + vec4 e2_1 = {100.0f, -200.0f, -10.0f, -10.0f}; + vec4 e3_0 = {-12.0f, 100.0f, 0.0f, 0.0f}; + vec4 e3_1 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v2; + + GLM(vec4_smoothinterp)(e1_0, e1_1, 0.5f, v2); + ASSERT(v2[0] >= e1_0[0] && v2[0] <= e1_1[0]) + ASSERT(v2[1] >= e1_0[1] && v2[1] <= e1_1[1]) + ASSERT(v2[2] >= e1_0[2] && v2[2] <= e1_1[2]) + ASSERT(v2[3] >= e1_0[3] && v2[3] <= e1_1[3]) + + GLM(vec4_smoothinterp)(e2_0, e2_1, 0.5f, v2); + ASSERT(v2[0] >= e2_0[0] && v2[0] <= e2_1[0]) + ASSERT(v2[1] >= e2_0[1] && v2[1] <= e2_1[1]) + ASSERT(v2[2] >= e2_0[2] && v2[2] <= e2_1[2]) + ASSERT(v2[3] >= e2_0[3] && v2[3] <= e2_1[3]) + + GLM(vec4_smoothinterp)(e3_0, e3_1, 1.0f, v2); + ASSERT(v2[0] >= e3_0[0] && v2[0] <= e3_1[0]) + ASSERT(v2[1] >= e3_0[1] && v2[1] <= e3_1[1]) + ASSERT(v2[2] >= e3_0[2] && v2[2] <= e3_1[2]) + ASSERT(v2[3] >= e3_0[3] && v2[3] <= e3_1[3]) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_smoothinterpc) { + vec4 e1_0 = {-100.0f, 0.0f, -11.0f, -11.0f}; + vec4 e1_1 = {50.0f, 10.0f, 20.0f, 20.0f}; + vec4 e2_0 = {80.0f, -220.0f, -19.0f, -19.0f}; + vec4 e2_1 = {100.0f, -200.0f, -10.0f, -10.0f}; + vec4 e3_0 = {-12.0f, 100.0f, 0.0f, 0.0f}; + vec4 e3_1 = {100.0f, 200.0f, 10.0f, 10.0f}; + vec4 v2; + + GLM(vec4_smoothinterpc)(e1_0, e1_1, -0.5f, v2); + ASSERT(v2[0] >= e1_0[0] && v2[0] <= e1_1[0]) + ASSERT(v2[1] >= e1_0[1] && v2[1] <= e1_1[1]) + ASSERT(v2[2] >= e1_0[2] && v2[2] <= e1_1[2]) + ASSERT(v2[3] >= e1_0[3] && v2[3] <= e1_1[3]) + + GLM(vec4_smoothinterpc)(e2_0, e2_1, 0.5f, v2); + ASSERT(v2[0] >= e2_0[0] && v2[0] <= e2_1[0]) + ASSERT(v2[1] >= e2_0[1] && v2[1] <= e2_1[1]) + ASSERT(v2[2] >= e2_0[2] && v2[2] <= e2_1[2]) + ASSERT(v2[3] >= e2_0[3] && v2[3] <= e2_1[3]) + + GLM(vec4_smoothinterpc)(e3_0, e3_1, 2.0f, v2); + ASSERT(v2[0] >= e3_0[0] && v2[0] <= e3_1[0]) + ASSERT(v2[1] >= e3_0[1] && v2[1] <= e3_1[1]) + ASSERT(v2[2] >= e3_0[2] && v2[2] <= e3_1[2]) + ASSERT(v2[3] >= e3_0[3] && v2[3] <= e3_1[3]) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_cubic) { + vec4 v1 = {125.0f, 25.0f, 5.0f, 1.0f}; + vec4 v2 = {216.0f, 36.0f, 6.0f, 1.0f}; + vec4 v3, v4; + + ASSERT(test_eq(v1[0], v1[2] * v1[2] * v1[2])) + ASSERT(test_eq(v1[1], v1[2] * v1[2])) + ASSERT(test_eq(v1[3], 1.0f)) + + ASSERT(test_eq(v2[0], v2[2] * v2[2] * v2[2])) + ASSERT(test_eq(v2[1], v2[2] * v2[2])) + ASSERT(test_eq(v2[3], 1.0f)) + + GLM(vec4_cubic)(test_rand(), v3); + ASSERT(test_eq(v3[0], v3[2] * v3[2] * v3[2])) + ASSERT(test_eq(v3[1], v3[2] * v3[2])) + ASSERT(test_eq(v3[3], 1.0f)) + + GLM(vec4_cubic)(test_rand(), v4); + ASSERT(test_eq(v4[0], v4[2] * v4[2] * v4[2])) + ASSERT(test_eq(v4[1], v4[2] * v4[2])) + ASSERT(test_eq(v4[3], 1.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_swizzle) { + vec4 v; + + /* ZYX */ + v[0] = 1; + v[1] = 2; + v[2] = 3; + v[3] = 4; + + glm_vec4_swizzle(v, GLM_WZYX, v); + ASSERTIFY(test_assert_vec4_eq(v, (vec4){4, 3, 2, 1})) + + glm_vec4_swizzle(v, GLM_XXXX, v); + ASSERTIFY(test_assert_vec4_eq(v, (vec4){4, 4, 4, 4})) + + v[0] = 1; + v[1] = 2; + v[2] = 3; + v[3] = 4; + + glm_vec4_swizzle(v, GLM_YYYY, v); + ASSERTIFY(test_assert_vec4_eq(v, (vec4){2, 2, 2, 2})) + + v[0] = 1; + v[1] = 2; + v[2] = 3; + v[3] = 4; + + glm_vec4_swizzle(v, GLM_ZZZZ, v); + ASSERTIFY(test_assert_vec4_eq(v, (vec4){3, 3, 3, 3})) + + v[0] = 1; + v[1] = 2; + v[2] = 3; + v[3] = 4; + + glm_vec4_swizzle(v, GLM_WWWW, v); + ASSERTIFY(test_assert_vec4_eq(v, (vec4){4, 4, 4, 4})) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_broadcast) { + vec4 v1, v2, v3; + vec4 v5 = {-1.456f, -1.456f, -1.456f, -1.456f}; + vec4 v6 = {11.0f, 11.0f, 11.0f, 11.0f}; + vec4 v7 = {78.0f, 78.0f, 78.0f, 78.0f}; + + GLM(vec4_broadcast)(-1.456f, v1); + GLM(vec4_broadcast)(11.0f, v2); + GLM(vec4_broadcast)(78.0f, v3); + + ASSERTIFY(test_assert_vec4_eq(v1, v5)) + ASSERTIFY(test_assert_vec4_eq(v2, v6)) + ASSERTIFY(test_assert_vec4_eq(v3, v7)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_fill) { + vec4 v1, v2, v3; + vec4 v5 = {-1.456f, -1.456f, -1.456f, -1.456f}; + vec4 v6 = {11.0f, 11.0f, 11.0f, 11.0f}; + vec4 v7 = {78.0f, 78.0f, 78.0f, 78.0f}; + + GLM(vec4_fill)(v1, -1.456f); + GLM(vec4_fill)(v2, 11.0f); + GLM(vec4_fill)(v3, 78.0f); + + ASSERTIFY(test_assert_vec4_eq(v1, v5)) + ASSERTIFY(test_assert_vec4_eq(v2, v6)) + ASSERTIFY(test_assert_vec4_eq(v3, v7)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_eq) { + vec4 v1, v2, v3; + + GLM(vec4_fill)(v1, -1.456f); + GLM(vec4_fill)(v2, 11.0f); + GLM(vec4_fill)(v3, 78.1f); + + ASSERT(GLM(vec4_eq)(v1, -1.456f)) + ASSERT(GLM(vec4_eq)(v2, 11.0f)) + ASSERT(!GLM(vec4_eq)(v3, 78.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_eq_eps) { + vec4 v1, v2, v3; + + GLM(vec4_fill)(v1, -1.456f); + GLM(vec4_fill)(v2, 11.0f); + GLM(vec4_fill)(v3, 78.1f); + + ASSERT(GLM(vec4_eq_eps)(v1, -1.456f)) + ASSERT(GLM(vec4_eq_eps)(v2, 11.0f)) + ASSERT(!GLM(vec4_eq_eps)(v3, 78.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_eq_all) { + vec4 v1, v2, v3; + vec4 v4 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v5 = {-12.35f, -31.140f, -43.502f, -43.502f}; + + GLM(vec4_fill)(v1, -1.456f); + GLM(vec4_fill)(v2, 11.0f); + GLM(vec4_fill)(v3, 78.0f); + + ASSERT(GLM(vec4_eq_all)(v1)) + ASSERT(GLM(vec4_eq_all)(v2)) + ASSERT(GLM(vec4_eq_all)(v3)) + ASSERT(!GLM(vec4_eq_all)(v4)) + ASSERT(!GLM(vec4_eq_all)(v5)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_eqv) { + vec4 v1, v2, v3, v4, v5; + vec4 v6 = {-1.456f, -1.456f, -1.456f, -1.456f}; + vec4 v7 = {11.0f, 11.0f, 11.0f, 11.0f}; + vec4 v8 = {78.0f, 78.0f, -43.502f, -43.502f}; + + GLM(vec4_fill)(v1, -1.456f); + GLM(vec4_fill)(v2, 11.0f); + GLM(vec4_fill)(v3, 78.0f); + + test_rand_vec4(v4); + test_rand_vec4(v5); + + ASSERT(GLM(vec4_eqv)(v1, v6)) + ASSERT(GLM(vec4_eqv)(v2, v7)) + ASSERT(!GLM(vec4_eqv)(v3, v8)) + ASSERT(!GLM(vec4_eqv)(v4, v5)) + ASSERT(GLM(vec4_eqv)(v5, v5)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_eqv_eps) { + vec4 v1, v2, v3, v4, v5; + vec4 v6 = {-1.456f, -1.456f, -1.456f, -1.456f}; + vec4 v7 = {11.0f, 11.0f, 11.0f, 11.0f}; + vec4 v8 = {78.0f, 78.0f, -43.502f, -43.502f}; + + GLM(vec4_fill)(v1, -1.456f); + GLM(vec4_fill)(v2, 11.0f); + GLM(vec4_fill)(v3, 78.0f); + + test_rand_vec4(v4); + test_rand_vec4(v5); + + ASSERT(GLM(vec4_eqv_eps)(v1, v6)) + ASSERT(GLM(vec4_eqv_eps)(v2, v7)) + ASSERT(!GLM(vec4_eqv_eps)(v3, v8)) + ASSERT(!GLM(vec4_eqv_eps)(v4, v5)) + ASSERT(GLM(vec4_eqv_eps)(v5, v5)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_max) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3 = {INFINITY, 0.0f, 0.0f, 0.0f}; + vec4 v4 = {NAN, INFINITY, 2.0f, 2.0f}; + vec4 v5 = {NAN, -1.0f, -1.0f, -1.0f}; + vec4 v6 = {-1.0f, -11.0f, 11.0f, 11.0f}; + + ASSERT(test_eq(GLM(vec4_max)(v1), 2.104f)) + ASSERT(test_eq(GLM(vec4_max)(v2), -12.35f)) + ASSERT(isinf(GLM(vec4_max)(v3))) + ASSERT(isnan(GLM(vec4_max)(v4))) + ASSERT(isnan(GLM(vec4_max)(v5))) + ASSERT(test_eq(GLM(vec4_max)(v6), 11.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_min) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3 = {INFINITY, 0.0f, 0.0f, 0.0f}; + vec4 v4 = {NAN, INFINITY, 2.0f, 2.0f}; + vec4 v5 = {NAN, -1.0f, -1.0f, -1.0f}; + vec4 v6 = {-1.0f, -11.0f, 11.0f, 11.0f}; + + ASSERT(test_eq(GLM(vec4_min)(v1), -4.10f)) + ASSERT(test_eq(GLM(vec4_min)(v2), -43.502f)) + ASSERT(test_eq(GLM(vec4_min)(v3), 0.0f)) + ASSERT(isnan(GLM(vec4_min)(v4))) + ASSERT(isnan(GLM(vec4_min)(v5))) + ASSERT(test_eq(GLM(vec4_min)(v6), -11.0f)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_isnan) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3 = {INFINITY, 0.0f, 0.0f, 0.0f}; + vec4 v4 = {NAN, INFINITY, 2.0f, 2.0f}; + vec4 v5 = {NAN, -1.0f, -1.0f, -1.0f}; + vec4 v6 = {-1.0f, -1.0f, 11.0f, 11.0f}; + + ASSERT(!GLM(vec4_isnan)(v1)) + ASSERT(!GLM(vec4_isnan)(v2)) + ASSERT(!GLM(vec4_isnan)(v3)) + ASSERT(GLM(vec4_isnan)(v4)) + ASSERT(GLM(vec4_isnan)(v5)) + ASSERT(!GLM(vec4_isnan)(v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_isinf) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3 = {INFINITY, 0.0f, 0.0f, 0.0f}; + vec4 v4 = {NAN, INFINITY, 2.0f, 2.0f}; + vec4 v5 = {NAN, -1.0f, -1.0f, -1.0f}; + vec4 v6 = {-1.0f, -1.0f, 11.0f, 11.0f}; + + ASSERT(!GLM(vec4_isinf)(v1)) + ASSERT(!GLM(vec4_isinf)(v2)) + ASSERT(GLM(vec4_isinf)(v3)) + ASSERT(GLM(vec4_isinf)(v4)) + ASSERT(!GLM(vec4_isinf)(v5)) + ASSERT(!GLM(vec4_isinf)(v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_isvalid) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3 = {INFINITY, 0.0f, 0.0f, 0.0f}; + vec4 v4 = {NAN, INFINITY, 2.0f, 2.0f}; + vec4 v5 = {NAN, -1.0f, -1.0f, -1.0f}; + vec4 v6 = {-1.0f, -1.0f, 11.0f, 11.0f}; + + ASSERT(GLM(vec4_isvalid)(v1)) + ASSERT(GLM(vec4_isvalid)(v2)) + ASSERT(!GLM(vec4_isvalid)(v3)) + ASSERT(!GLM(vec4_isvalid)(v4)) + ASSERT(!GLM(vec4_isvalid)(v5)) + ASSERT(GLM(vec4_isvalid)(v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_sign) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3, v4; + vec4 v5 = {1.0f, -1.0f, -1.0f, -1.0f}; + vec4 v6 = {-1.0f, -1.0f, -1.0f, -1.0f}; + + GLM(vec4_sign)(v1, v3); + GLM(vec4_sign)(v2, v4); + + ASSERTIFY(test_assert_vec4_eq(v3, v5)) + ASSERTIFY(test_assert_vec4_eq(v4, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_abs) { + vec4 v1 = {2.104f, -3.012f, -4.10f, -4.10f}; + vec4 v2 = {-12.35f, -31.140f, -43.502f, -43.502f}; + vec4 v3, v4; + vec4 v5 = {2.104f, 3.012f, 4.10f, 4.10f}; + vec4 v6 = {12.35f, 31.140f, 43.502f, 43.502f}; + + GLM(vec4_abs)(v1, v3); + GLM(vec4_abs)(v2, v4); + + ASSERTIFY(test_assert_vec4_eq(v3, v5)) + ASSERTIFY(test_assert_vec4_eq(v4, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_fract) { + vec4 v1 = {2.104f, 3.012f, 4.10f, 4.10f}; + vec4 v2 = {12.35f, 31.140f, 43.502f, 43.502f}; + vec4 v3, v4; + vec4 v5 = {0.104f, 0.012f, 0.10f, 0.10f}; + vec4 v6 = {0.35f, 0.140f, 0.502f, 0.502f}; + + GLM(vec4_fract)(v1, v3); + GLM(vec4_fract)(v2, v4); + + ASSERTIFY(test_assert_vec4_eq(v3, v5)) + ASSERTIFY(test_assert_vec4_eq(v4, v6)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_hadd) { + vec4 v1 = {2.0f, 3.0f, 4.0f, 4.0f}, v2 = {12.0f, 31.0f, 43.0f, 43.0f}; + float r1, r2, r3, r4; + + r1 = GLM(vec4_hadd)(v1); + r2 = GLM(vec4_hadd)(v2); + + r3 = v1[0] + v1[1] + v1[2] + v1[3]; + r4 = v2[0] + v2[1] + v2[2] + v2[3]; + + ASSERT(test_eq(r1, r3)) + ASSERT(test_eq(r2, r4)) + + TEST_SUCCESS +} + +TEST_IMPL(GLM_PREFIX, vec4_sqrt) { + vec4 v1 = {2.0f, 3.0f, 4.0f, 4.0f}, v2 = {12.0f, 31.0f, 43.0f, 43.0f}; + vec4 v3, v4; + + GLM(vec4_sqrt)(v1, v3); + GLM(vec4_sqrt)(v2, v4); + + ASSERT(test_eq(sqrtf(v1[0]), v3[0])) + ASSERT(test_eq(sqrtf(v1[1]), v3[1])) + ASSERT(test_eq(sqrtf(v1[2]), v3[2])) + ASSERT(test_eq(sqrtf(v1[3]), v3[3])) + + ASSERT(test_eq(sqrtf(v2[0]), v4[0])) + ASSERT(test_eq(sqrtf(v2[1]), v4[1])) + ASSERT(test_eq(sqrtf(v2[2]), v4[2])) + ASSERT(test_eq(sqrtf(v2[3]), v4[3])) + + TEST_SUCCESS +} diff --git a/libs/cglm/test/src/tests.c b/libs/cglm/test/src/tests.c new file mode 100644 index 0000000..1505e32 --- /dev/null +++ b/libs/cglm/test/src/tests.c @@ -0,0 +1,63 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* test inline */ +/*---------------------------------------------------------------------------*/ + + +#define GLM_PREFIX glm_ +#define GLM(X) (glm_ ## X) + +#include "test_vec2.h" +#include "test_vec3.h" +#include "test_vec4.h" +#include "test_ivec2.h" +#include "test_ivec3.h" +#include "test_ivec4.h" +#include "test_mat2.h" +#include "test_mat3.h" +#include "test_mat4.h" +#include "test_quat.h" +#include "test_project.h" +#include "test_plane.h" +#include "test_affine.h" +#include "test_affine2d.h" +#include "test_affine_mat.h" +#include "test_ray.h" +#include "test_camera.h" + +#undef GLM +#undef GLM_PREFIX + +/* test pre-compiled */ +/*---------------------------------------------------------------------------*/ + +#define GLM_PREFIX glmc_ +#define GLM(X) (glmc_ ## X) + +#include "test_vec2.h" +#include "test_vec3.h" +#include "test_vec4.h" +#include "test_ivec2.h" +#include "test_ivec3.h" +#include "test_ivec4.h" +#include "test_mat2.h" +#include "test_mat3.h" +#include "test_mat4.h" +#include "test_quat.h" +#include "test_project.h" +#include "test_plane.h" +#include "test_affine.h" +#include "test_affine2d.h" +#include "test_affine_mat.h" +#include "test_ray.h" +#include "test_camera.h" + +#undef GLM +#undef GLM_PREFIX + +/*---------------------------------------------------------------------------*/ diff --git a/libs/cglm/test/tests.h b/libs/cglm/test/tests.h new file mode 100644 index 0000000..361b485 --- /dev/null +++ b/libs/cglm/test/tests.h @@ -0,0 +1,1672 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef tests_h +#define tests_h + +#include "include/common.h" + +/* + * To register a test: + * 1. use TEST_DECLARE() to forward declare test + * 2. use TEST_ENTRY() to add test to list + */ + +/* affine mat */ +TEST_DECLARE(glm_mul) +TEST_DECLARE(glm_mul) +TEST_DECLARE(glm_inv_tr) + +TEST_DECLARE(glmc_mul) +TEST_DECLARE(glmc_mul_rot) +TEST_DECLARE(glmc_inv_tr) + +/* affine */ +TEST_DECLARE(glm_translate) +TEST_DECLARE(glm_translate_to) +TEST_DECLARE(glm_translate_x) +TEST_DECLARE(glm_translate_y) +TEST_DECLARE(glm_translate_z) +TEST_DECLARE(glm_translate_make) +TEST_DECLARE(glm_scale_to) +TEST_DECLARE(glm_scale_make) +TEST_DECLARE(glm_scale) +TEST_DECLARE(glm_scale_uni) +TEST_DECLARE(glm_rotate_x) +TEST_DECLARE(glm_rotate_y) +TEST_DECLARE(glm_rotate_z) +TEST_DECLARE(glm_rotate_make) +TEST_DECLARE(glm_rotate) +TEST_DECLARE(glm_rotate_at) +TEST_DECLARE(glm_rotate_atm) +TEST_DECLARE(glm_decompose_scalev) +TEST_DECLARE(glm_uniscaled) +TEST_DECLARE(glm_decompose_rs) +TEST_DECLARE(glm_decompose) + +TEST_DECLARE(glmc_translate) +TEST_DECLARE(glmc_translate_to) +TEST_DECLARE(glmc_translate_x) +TEST_DECLARE(glmc_translate_y) +TEST_DECLARE(glmc_translate_z) +TEST_DECLARE(glmc_translate_make) +TEST_DECLARE(glmc_scale_to) +TEST_DECLARE(glmc_scale_make) +TEST_DECLARE(glmc_scale) +TEST_DECLARE(glmc_scale_uni) +TEST_DECLARE(glmc_rotate_x) +TEST_DECLARE(glmc_rotate_y) +TEST_DECLARE(glmc_rotate_z) +TEST_DECLARE(glmc_rotate_make) +TEST_DECLARE(glmc_rotate) +TEST_DECLARE(glmc_rotate_at) +TEST_DECLARE(glmc_rotate_atm) +TEST_DECLARE(glmc_decompose_scalev) +TEST_DECLARE(glmc_uniscaled) +TEST_DECLARE(glmc_decompose_rs) +TEST_DECLARE(glmc_decompose) + +/* affine 2d */ +TEST_DECLARE(glm_translate2d) +TEST_DECLARE(glm_translate2d_to) +TEST_DECLARE(glm_translate2d_x) +TEST_DECLARE(glm_translate2d_y) +TEST_DECLARE(glm_translate2d_make) +TEST_DECLARE(glm_scale2d_to) +TEST_DECLARE(glm_scale2d_make) +TEST_DECLARE(glm_scale2d) +TEST_DECLARE(glm_scale2d_uni) +TEST_DECLARE(glm_rotate2d_make) +TEST_DECLARE(glm_rotate2d) +TEST_DECLARE(glm_rotate2d_to) + +TEST_DECLARE(glmc_translate2d) +TEST_DECLARE(glmc_translate2d_to) +TEST_DECLARE(glmc_translate2d_x) +TEST_DECLARE(glmc_translate2d_y) +TEST_DECLARE(glmc_translate2d_make) +TEST_DECLARE(glmc_scale2d_to) +TEST_DECLARE(glmc_scale2d_make) +TEST_DECLARE(glmc_scale2d) +TEST_DECLARE(glmc_scale2d_uni) +TEST_DECLARE(glmc_rotate2d_make) +TEST_DECLARE(glmc_rotate2d) +TEST_DECLARE(glmc_rotate2d_to) + +/* mat4 */ +TEST_DECLARE(glm_mat4_ucopy) +TEST_DECLARE(glm_mat4_copy) +TEST_DECLARE(glm_mat4_identity) +TEST_DECLARE(glm_mat4_identity_array) +TEST_DECLARE(glm_mat4_zero) +TEST_DECLARE(glm_mat4_pick3) +TEST_DECLARE(glm_mat4_pick3t) +TEST_DECLARE(glm_mat4_ins3) +TEST_DECLARE(glm_mat4_mul) +TEST_DECLARE(glm_mat4_mulN) +TEST_DECLARE(glm_mat4_mulv) +TEST_DECLARE(glm_mat4_mulv3) +TEST_DECLARE(glm_mat4_trace) +TEST_DECLARE(glm_mat4_trace3) +TEST_DECLARE(glm_mat4_quat) +TEST_DECLARE(glm_mat4_transpose_to) +TEST_DECLARE(glm_mat4_transpose) +TEST_DECLARE(glm_mat4_scale_p) +TEST_DECLARE(glm_mat4_scale) +TEST_DECLARE(glm_mat4_det) +TEST_DECLARE(glm_mat4_inv) +TEST_DECLARE(glm_mat4_inv_fast) +TEST_DECLARE(glm_mat4_inv_precise) +TEST_DECLARE(glm_mat4_swap_col) +TEST_DECLARE(glm_mat4_swap_row) +TEST_DECLARE(glm_mat4_rmc) + +TEST_DECLARE(glmc_mat4_ucopy) +TEST_DECLARE(glmc_mat4_copy) +TEST_DECLARE(glmc_mat4_identity) +TEST_DECLARE(glmc_mat4_identity_array) +TEST_DECLARE(glmc_mat4_zero) +TEST_DECLARE(glmc_mat4_pick3) +TEST_DECLARE(glmc_mat4_pick3t) +TEST_DECLARE(glmc_mat4_ins3) +TEST_DECLARE(glmc_mat4_mul) +TEST_DECLARE(glmc_mat4_mulN) +TEST_DECLARE(glmc_mat4_mulv) +TEST_DECLARE(glmc_mat4_mulv3) +TEST_DECLARE(glmc_mat4_trace) +TEST_DECLARE(glmc_mat4_trace3) +TEST_DECLARE(glmc_mat4_quat) +TEST_DECLARE(glmc_mat4_transpose_to) +TEST_DECLARE(glmc_mat4_transpose) +TEST_DECLARE(glmc_mat4_scale_p) +TEST_DECLARE(glmc_mat4_scale) +TEST_DECLARE(glmc_mat4_det) +TEST_DECLARE(glmc_mat4_inv) +TEST_DECLARE(glmc_mat4_inv_fast) +TEST_DECLARE(glmc_mat4_swap_col) +TEST_DECLARE(glmc_mat4_swap_row) +TEST_DECLARE(glmc_mat4_rmc) + +/* mat3 */ +TEST_DECLARE(glm_mat3_copy) +TEST_DECLARE(glm_mat3_identity) +TEST_DECLARE(glm_mat3_identity_array) +TEST_DECLARE(glm_mat3_zero) +TEST_DECLARE(glm_mat3_mul) +TEST_DECLARE(glm_mat3_mulv) +TEST_DECLARE(glm_mat3_trace) +TEST_DECLARE(glm_mat3_quat) +TEST_DECLARE(glm_mat3_transpose_to) +TEST_DECLARE(glm_mat3_transpose) +TEST_DECLARE(glm_mat3_scale) +TEST_DECLARE(glm_mat3_det) +TEST_DECLARE(glm_mat3_inv) +TEST_DECLARE(glm_mat3_swap_col) +TEST_DECLARE(glm_mat3_swap_row) +TEST_DECLARE(glm_mat3_rmc) + +TEST_DECLARE(glmc_mat3_copy) +TEST_DECLARE(glmc_mat3_identity) +TEST_DECLARE(glmc_mat3_identity_array) +TEST_DECLARE(glmc_mat3_zero) +TEST_DECLARE(glmc_mat3_mul) +TEST_DECLARE(glmc_mat3_mulv) +TEST_DECLARE(glmc_mat3_trace) +TEST_DECLARE(glmc_mat3_quat) +TEST_DECLARE(glmc_mat3_transpose_to) +TEST_DECLARE(glmc_mat3_transpose) +TEST_DECLARE(glmc_mat3_scale) +TEST_DECLARE(glmc_mat3_det) +TEST_DECLARE(glmc_mat3_inv) +TEST_DECLARE(glmc_mat3_swap_col) +TEST_DECLARE(glmc_mat3_swap_row) +TEST_DECLARE(glmc_mat3_rmc) + +TEST_DECLARE(MACRO_GLM_MAT2_IDENTITY_INIT) +TEST_DECLARE(MACRO_GLM_MAT2_ZERO_INIT) +TEST_DECLARE(MACRO_GLM_MAT2_IDENTITY) +TEST_DECLARE(MACRO_GLM_MAT2_ZERO) +TEST_DECLARE(glm_mat2_copy) +TEST_DECLARE(glm_mat2_identity) +TEST_DECLARE(glm_mat2_identity_array) +TEST_DECLARE(glm_mat2_zero) +TEST_DECLARE(glm_mat2_mul) +TEST_DECLARE(glm_mat2_transpose_to) +TEST_DECLARE(glm_mat2_transpose) +TEST_DECLARE(glm_mat2_mulv) +TEST_DECLARE(glm_mat2_trace) +TEST_DECLARE(glm_mat2_scale) +TEST_DECLARE(glm_mat2_det) +TEST_DECLARE(glm_mat2_inv) +TEST_DECLARE(glm_mat2_swap_col) +TEST_DECLARE(glm_mat2_swap_row) +TEST_DECLARE(glm_mat2_rmc) + +TEST_DECLARE(glmc_mat2_copy) +TEST_DECLARE(glmc_mat2_identity) +TEST_DECLARE(glmc_mat2_identity_array) +TEST_DECLARE(glmc_mat2_zero) +TEST_DECLARE(glmc_mat2_mul) +TEST_DECLARE(glmc_mat2_transpose_to) +TEST_DECLARE(glmc_mat2_transpose) +TEST_DECLARE(glmc_mat2_mulv) +TEST_DECLARE(glmc_mat2_trace) +TEST_DECLARE(glmc_mat2_scale) +TEST_DECLARE(glmc_mat2_det) +TEST_DECLARE(glmc_mat2_inv) +TEST_DECLARE(glmc_mat2_swap_col) +TEST_DECLARE(glmc_mat2_swap_row) +TEST_DECLARE(glmc_mat2_rmc) + +/* camera (incl [LR]H cross [NZ]O) */ +TEST_DECLARE(perspective_lh_zo) +TEST_DECLARE(perspective_rh_zo) +TEST_DECLARE(perspective_lh_no) +TEST_DECLARE(perspective_rh_no) +TEST_DECLARE(camera_lookat) +TEST_DECLARE(camera_decomp) + +TEST_DECLARE(glm_frustum) + +TEST_DECLARE(glmc_frustum) + +/* project */ +TEST_DECLARE(glm_unprojecti) +TEST_DECLARE(glm_unproject) +TEST_DECLARE(glm_project) + +TEST_DECLARE(glmc_unprojecti) +TEST_DECLARE(glmc_unproject) +TEST_DECLARE(glmc_project) + +/* plane */ +TEST_DECLARE(glm_plane_normalize) +TEST_DECLARE(glmc_plane_normalize) + +/* utils */ +TEST_DECLARE(clamp) + +/* euler */ +TEST_DECLARE(euler) + +/* ray */ +TEST_DECLARE(glm_ray_triangle) +TEST_DECLARE(glmc_ray_triangle) + +/* quat */ +TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY_INIT) +TEST_DECLARE(MACRO_GLM_QUAT_IDENTITY) + +TEST_DECLARE(glm_quat_identity) +TEST_DECLARE(glm_quat_identity_array) +TEST_DECLARE(glm_quat_init) +TEST_DECLARE(glm_quatv) +TEST_DECLARE(glm_quat) +TEST_DECLARE(glm_quat_copy) +TEST_DECLARE(glm_quat_norm) +TEST_DECLARE(glm_quat_normalize_to) +TEST_DECLARE(glm_quat_normalize) +TEST_DECLARE(glm_quat_dot) +TEST_DECLARE(glm_quat_conjugate) +TEST_DECLARE(glm_quat_inv) +TEST_DECLARE(glm_quat_add) +TEST_DECLARE(glm_quat_sub) +TEST_DECLARE(glm_quat_real) +TEST_DECLARE(glm_quat_imag) +TEST_DECLARE(glm_quat_imagn) +TEST_DECLARE(glm_quat_imaglen) +TEST_DECLARE(glm_quat_angle) +TEST_DECLARE(glm_quat_axis) +TEST_DECLARE(glm_quat_mul) +TEST_DECLARE(glm_quat_mat4) +TEST_DECLARE(glm_quat_mat4t) +TEST_DECLARE(glm_quat_mat3) +TEST_DECLARE(glm_quat_mat3t) +TEST_DECLARE(glm_quat_lerp) +TEST_DECLARE(glm_quat_lerpc) +TEST_DECLARE(glm_quat_nlerp) +TEST_DECLARE(glm_quat_slerp) +TEST_DECLARE(glm_quat_look) +TEST_DECLARE(glm_quat_for) +TEST_DECLARE(glm_quat_forp) +TEST_DECLARE(glm_quat_rotatev) +TEST_DECLARE(glm_quat_rotate) +TEST_DECLARE(glm_quat_rotate_at) +TEST_DECLARE(glm_quat_rotate_atm) +TEST_DECLARE(glm_quat_from_vecs) + +TEST_DECLARE(glmc_quat_identity) +TEST_DECLARE(glmc_quat_identity_array) +TEST_DECLARE(glmc_quat_init) +TEST_DECLARE(glmc_quatv) +TEST_DECLARE(glmc_quat) +TEST_DECLARE(glmc_quat_copy) +TEST_DECLARE(glmc_quat_norm) +TEST_DECLARE(glmc_quat_normalize_to) +TEST_DECLARE(glmc_quat_normalize) +TEST_DECLARE(glmc_quat_dot) +TEST_DECLARE(glmc_quat_conjugate) +TEST_DECLARE(glmc_quat_inv) +TEST_DECLARE(glmc_quat_add) +TEST_DECLARE(glmc_quat_sub) +TEST_DECLARE(glmc_quat_real) +TEST_DECLARE(glmc_quat_imag) +TEST_DECLARE(glmc_quat_imagn) +TEST_DECLARE(glmc_quat_imaglen) +TEST_DECLARE(glmc_quat_angle) +TEST_DECLARE(glmc_quat_axis) +TEST_DECLARE(glmc_quat_mul) +TEST_DECLARE(glmc_quat_mat4) +TEST_DECLARE(glmc_quat_mat4t) +TEST_DECLARE(glmc_quat_mat3) +TEST_DECLARE(glmc_quat_mat3t) +TEST_DECLARE(glmc_quat_lerp) +TEST_DECLARE(glmc_quat_lerpc) +TEST_DECLARE(glmc_quat_nlerp) +TEST_DECLARE(glmc_quat_slerp) +TEST_DECLARE(glmc_quat_look) +TEST_DECLARE(glmc_quat_for) +TEST_DECLARE(glmc_quat_forp) +TEST_DECLARE(glmc_quat_rotatev) +TEST_DECLARE(glmc_quat_rotate) +TEST_DECLARE(glmc_quat_rotate_at) +TEST_DECLARE(glmc_quat_rotate_atm) +TEST_DECLARE(glmc_quat_from_vecs) + +/* bezier */ +TEST_DECLARE(bezier) + +/* vec2 */ +TEST_DECLARE(MACRO_GLM_VEC2_ONE_INIT) +TEST_DECLARE(MACRO_GLM_VEC2_ZERO_INIT) +TEST_DECLARE(MACRO_GLM_VEC2_ONE) +TEST_DECLARE(MACRO_GLM_VEC2_ZERO) + +TEST_DECLARE(glm_vec2) +TEST_DECLARE(glm_vec2_copy) +TEST_DECLARE(glm_vec2_zero) +TEST_DECLARE(glm_vec2_one) +TEST_DECLARE(glm_vec2_dot) +TEST_DECLARE(glm_vec2_cross) +TEST_DECLARE(glm_vec2_norm2) +TEST_DECLARE(glm_vec2_norm) +TEST_DECLARE(glm_vec2_add) +TEST_DECLARE(glm_vec2_adds) +TEST_DECLARE(glm_vec2_sub) +TEST_DECLARE(glm_vec2_subs) +TEST_DECLARE(glm_vec2_mul) +TEST_DECLARE(glm_vec2_scale) +TEST_DECLARE(glm_vec2_scale_as) +TEST_DECLARE(glm_vec2_div) +TEST_DECLARE(glm_vec2_divs) +TEST_DECLARE(glm_vec2_addadd) +TEST_DECLARE(glm_vec2_subadd) +TEST_DECLARE(glm_vec2_muladd) +TEST_DECLARE(glm_vec2_muladds) +TEST_DECLARE(glm_vec2_maxadd) +TEST_DECLARE(glm_vec2_minadd) +TEST_DECLARE(glm_vec2_negate_to) +TEST_DECLARE(glm_vec2_negate) +TEST_DECLARE(glm_vec2_normalize) +TEST_DECLARE(glm_vec2_normalize_to) +TEST_DECLARE(glm_vec2_rotate) +TEST_DECLARE(glm_vec2_distance2) +TEST_DECLARE(glm_vec2_distance) +TEST_DECLARE(glm_vec2_maxv) +TEST_DECLARE(glm_vec2_minv) +TEST_DECLARE(glm_vec2_clamp) +TEST_DECLARE(glm_vec2_lerp) +TEST_DECLARE(glm_vec2_complex_mul) +TEST_DECLARE(glm_vec2_complex_div) + +TEST_DECLARE(glmc_vec2) +TEST_DECLARE(glmc_vec2_copy) +TEST_DECLARE(glmc_vec2_zero) +TEST_DECLARE(glmc_vec2_one) +TEST_DECLARE(glmc_vec2_dot) +TEST_DECLARE(glmc_vec2_cross) +TEST_DECLARE(glmc_vec2_norm2) +TEST_DECLARE(glmc_vec2_norm) +TEST_DECLARE(glmc_vec2_add) +TEST_DECLARE(glmc_vec2_adds) +TEST_DECLARE(glmc_vec2_sub) +TEST_DECLARE(glmc_vec2_subs) +TEST_DECLARE(glmc_vec2_mul) +TEST_DECLARE(glmc_vec2_scale) +TEST_DECLARE(glmc_vec2_scale_as) +TEST_DECLARE(glmc_vec2_div) +TEST_DECLARE(glmc_vec2_divs) +TEST_DECLARE(glmc_vec2_addadd) +TEST_DECLARE(glmc_vec2_subadd) +TEST_DECLARE(glmc_vec2_muladd) +TEST_DECLARE(glmc_vec2_muladds) +TEST_DECLARE(glmc_vec2_maxadd) +TEST_DECLARE(glmc_vec2_minadd) +TEST_DECLARE(glmc_vec2_negate_to) +TEST_DECLARE(glmc_vec2_negate) +TEST_DECLARE(glmc_vec2_normalize) +TEST_DECLARE(glmc_vec2_normalize_to) +TEST_DECLARE(glmc_vec2_rotate) +TEST_DECLARE(glmc_vec2_distance2) +TEST_DECLARE(glmc_vec2_distance) +TEST_DECLARE(glmc_vec2_maxv) +TEST_DECLARE(glmc_vec2_minv) +TEST_DECLARE(glmc_vec2_clamp) +TEST_DECLARE(glmc_vec2_lerp) +TEST_DECLARE(glmc_vec2_complex_mul) +TEST_DECLARE(glmc_vec2_complex_div) + +/* vec3 */ +TEST_DECLARE(MACRO_GLM_VEC3_ONE_INIT) +TEST_DECLARE(MACRO_GLM_VEC3_ZERO_INIT) +TEST_DECLARE(MACRO_GLM_VEC3_ONE) +TEST_DECLARE(MACRO_GLM_VEC3_ZERO) +TEST_DECLARE(MACRO_GLM_YUP) +TEST_DECLARE(MACRO_GLM_ZUP) +TEST_DECLARE(MACRO_GLM_XUP) +TEST_DECLARE(MACRO_GLM_FORWARD_RH) +TEST_DECLARE(MACRO_GLM_SHUFFLE3) +TEST_DECLARE(MACRO_GLM_XXX) +TEST_DECLARE(MACRO_GLM_YYY) +TEST_DECLARE(MACRO_GLM_ZZZ) +TEST_DECLARE(MACRO_GLM_ZYX) + +TEST_DECLARE(MACRO_glm_vec3_dup) +TEST_DECLARE(MACRO_glm_vec3_flipsign) +TEST_DECLARE(MACRO_glm_vec3_flipsign_to) +TEST_DECLARE(MACRO_glm_vec3_inv) +TEST_DECLARE(MACRO_glm_vec3_inv_to) +TEST_DECLARE(MACRO_glm_vec3_mulv) + +TEST_DECLARE(glm_vec3) +TEST_DECLARE(glm_vec3_copy) +TEST_DECLARE(glm_vec3_zero) +TEST_DECLARE(glm_vec3_one) +TEST_DECLARE(glm_vec3_dot) +TEST_DECLARE(glm_dot) +TEST_DECLARE(glm_vec3_norm2) +TEST_DECLARE(glm_vec3_norm) +TEST_DECLARE(glm_vec3_norm_one) +TEST_DECLARE(glm_vec3_norm_inf) +TEST_DECLARE(glm_vec3_add) +TEST_DECLARE(glm_vec3_adds) +TEST_DECLARE(glm_vec3_sub) +TEST_DECLARE(glm_vec3_subs) +TEST_DECLARE(glm_vec3_mul) +TEST_DECLARE(glm_vec3_scale) +TEST_DECLARE(glm_vec3_scale_as) +TEST_DECLARE(glm_vec3_div) +TEST_DECLARE(glm_vec3_divs) +TEST_DECLARE(glm_vec3_addadd) +TEST_DECLARE(glm_vec3_subadd) +TEST_DECLARE(glm_vec3_muladd) +TEST_DECLARE(glm_vec3_muladds) +TEST_DECLARE(glm_vec3_maxadd) +TEST_DECLARE(glm_vec3_minadd) +TEST_DECLARE(glm_vec3_negate_to) +TEST_DECLARE(glm_vec3_negate) +TEST_DECLARE(glm_vec3_normalize) +TEST_DECLARE(glm_vec3_normalize_to) +TEST_DECLARE(glm_normalize) +TEST_DECLARE(glm_normalize_to) +TEST_DECLARE(glm_vec3_cross) +TEST_DECLARE(glm_vec3_crossn) +TEST_DECLARE(glm_cross) +TEST_DECLARE(glm_vec3_angle) +TEST_DECLARE(glm_vec3_rotate) +TEST_DECLARE(glm_vec3_rotate_m4) +TEST_DECLARE(glm_vec3_rotate_m3) +TEST_DECLARE(glm_vec3_proj) +TEST_DECLARE(glm_vec3_center) +TEST_DECLARE(glm_vec3_distance2) +TEST_DECLARE(glm_vec3_distance) +TEST_DECLARE(glm_vec3_maxv) +TEST_DECLARE(glm_vec3_minv) +TEST_DECLARE(glm_vec3_ortho) +TEST_DECLARE(glm_vec3_clamp) +TEST_DECLARE(glm_vec3_mix) +TEST_DECLARE(glm_vec3_mixc) +TEST_DECLARE(glm_vec3_step_uni) +TEST_DECLARE(glm_vec3_step) +TEST_DECLARE(glm_vec3_smoothstep_uni) +TEST_DECLARE(glm_vec3_smoothstep) +TEST_DECLARE(glm_vec3_smoothinterp) +TEST_DECLARE(glm_vec3_smoothinterpc) +TEST_DECLARE(glm_vec3_swizzle) +TEST_DECLARE(glm_vec3_broadcast) +TEST_DECLARE(glm_vec3_fill) +TEST_DECLARE(glm_vec3_eq) +TEST_DECLARE(glm_vec3_eq_eps) +TEST_DECLARE(glm_vec3_eq_all) +TEST_DECLARE(glm_vec3_eqv) +TEST_DECLARE(glm_vec3_eqv_eps) +TEST_DECLARE(glm_vec3_max) +TEST_DECLARE(glm_vec3_min) +TEST_DECLARE(glm_vec3_isnan) +TEST_DECLARE(glm_vec3_isinf) +TEST_DECLARE(glm_vec3_isvalid) +TEST_DECLARE(glm_vec3_sign) +TEST_DECLARE(glm_vec3_abs) +TEST_DECLARE(glm_vec3_fract) +TEST_DECLARE(glm_vec3_hadd) +TEST_DECLARE(glm_vec3_sqrt) + +TEST_DECLARE(glmc_vec3) +TEST_DECLARE(glmc_vec3_copy) +TEST_DECLARE(glmc_vec3_zero) +TEST_DECLARE(glmc_vec3_one) +TEST_DECLARE(glmc_vec3_dot) +TEST_DECLARE(glmc_vec3_norm2) +TEST_DECLARE(glmc_vec3_norm) +TEST_DECLARE(glmc_vec3_norm_one) +TEST_DECLARE(glmc_vec3_norm_inf) +TEST_DECLARE(glmc_vec3_add) +TEST_DECLARE(glmc_vec3_adds) +TEST_DECLARE(glmc_vec3_sub) +TEST_DECLARE(glmc_vec3_subs) +TEST_DECLARE(glmc_vec3_mul) +TEST_DECLARE(glmc_vec3_scale) +TEST_DECLARE(glmc_vec3_scale_as) +TEST_DECLARE(glmc_vec3_div) +TEST_DECLARE(glmc_vec3_divs) +TEST_DECLARE(glmc_vec3_addadd) +TEST_DECLARE(glmc_vec3_subadd) +TEST_DECLARE(glmc_vec3_muladd) +TEST_DECLARE(glmc_vec3_muladds) +TEST_DECLARE(glmc_vec3_maxadd) +TEST_DECLARE(glmc_vec3_minadd) +TEST_DECLARE(glmc_vec3_negate_to) +TEST_DECLARE(glmc_vec3_negate) +TEST_DECLARE(glmc_vec3_normalize) +TEST_DECLARE(glmc_vec3_normalize_to) +TEST_DECLARE(glmc_vec3_cross) +TEST_DECLARE(glmc_vec3_crossn) +TEST_DECLARE(glmc_vec3_angle) +TEST_DECLARE(glmc_vec3_rotate) +TEST_DECLARE(glmc_vec3_rotate_m4) +TEST_DECLARE(glmc_vec3_rotate_m3) +TEST_DECLARE(glmc_vec3_proj) +TEST_DECLARE(glmc_vec3_center) +TEST_DECLARE(glmc_vec3_distance2) +TEST_DECLARE(glmc_vec3_distance) +TEST_DECLARE(glmc_vec3_maxv) +TEST_DECLARE(glmc_vec3_minv) +TEST_DECLARE(glmc_vec3_ortho) +TEST_DECLARE(glmc_vec3_clamp) +TEST_DECLARE(glmc_vec3_mix) +TEST_DECLARE(glmc_vec3_mixc) +TEST_DECLARE(glmc_vec3_step_uni) +TEST_DECLARE(glmc_vec3_step) +TEST_DECLARE(glmc_vec3_smoothstep_uni) +TEST_DECLARE(glmc_vec3_smoothstep) +TEST_DECLARE(glmc_vec3_smoothinterp) +TEST_DECLARE(glmc_vec3_smoothinterpc) +TEST_DECLARE(glmc_vec3_swizzle) +TEST_DECLARE(glmc_vec3_broadcast) +TEST_DECLARE(glmc_vec3_fill) +TEST_DECLARE(glmc_vec3_eq) +TEST_DECLARE(glmc_vec3_eq_eps) +TEST_DECLARE(glmc_vec3_eq_all) +TEST_DECLARE(glmc_vec3_eqv) +TEST_DECLARE(glmc_vec3_eqv_eps) +TEST_DECLARE(glmc_vec3_max) +TEST_DECLARE(glmc_vec3_min) +TEST_DECLARE(glmc_vec3_isnan) +TEST_DECLARE(glmc_vec3_isinf) +TEST_DECLARE(glmc_vec3_isvalid) +TEST_DECLARE(glmc_vec3_sign) +TEST_DECLARE(glmc_vec3_abs) +TEST_DECLARE(glmc_vec3_fract) +TEST_DECLARE(glmc_vec3_hadd) +TEST_DECLARE(glmc_vec3_sqrt) + +/* vec4 */ +TEST_DECLARE(MACRO_GLM_VEC4_ONE_INIT) +TEST_DECLARE(MACRO_GLM_VEC4_ZERO_INIT) +TEST_DECLARE(MACRO_GLM_VEC4_ONE) +TEST_DECLARE(MACRO_GLM_VEC4_ZERO) +TEST_DECLARE(MACRO_GLM_XXXX) +TEST_DECLARE(MACRO_GLM_YYYY) +TEST_DECLARE(MACRO_GLM_ZZZZ) +TEST_DECLARE(MACRO_GLM_WZYX) +TEST_DECLARE(MACRO_glm_vec4_dup) +TEST_DECLARE(MACRO_glm_vec4_flipsign) +TEST_DECLARE(MACRO_glm_vec4_flipsign_to) +TEST_DECLARE(MACRO_glm_vec4_inv) +TEST_DECLARE(MACRO_glm_vec4_inv_to) +TEST_DECLARE(MACRO_glm_vec4_mulv) + +TEST_DECLARE(glm_vec4) +TEST_DECLARE(glm_vec4_copy3) +TEST_DECLARE(glm_vec4_copy) +TEST_DECLARE(glm_vec4_ucopy) +TEST_DECLARE(glm_vec4_zero) +TEST_DECLARE(glm_vec4_one) +TEST_DECLARE(glm_vec4_dot) +TEST_DECLARE(glm_vec4_norm2) +TEST_DECLARE(glm_vec4_norm) +TEST_DECLARE(glm_vec4_norm_one) +TEST_DECLARE(glm_vec4_norm_inf) +TEST_DECLARE(glm_vec4_add) +TEST_DECLARE(glm_vec4_adds) +TEST_DECLARE(glm_vec4_sub) +TEST_DECLARE(glm_vec4_subs) +TEST_DECLARE(glm_vec4_mul) +TEST_DECLARE(glm_vec4_scale) +TEST_DECLARE(glm_vec4_scale_as) +TEST_DECLARE(glm_vec4_div) +TEST_DECLARE(glm_vec4_divs) +TEST_DECLARE(glm_vec4_addadd) +TEST_DECLARE(glm_vec4_subadd) +TEST_DECLARE(glm_vec4_muladd) +TEST_DECLARE(glm_vec4_muladds) +TEST_DECLARE(glm_vec4_maxadd) +TEST_DECLARE(glm_vec4_minadd) +TEST_DECLARE(glm_vec4_negate_to) +TEST_DECLARE(glm_vec4_negate) +TEST_DECLARE(glm_vec4_normalize) +TEST_DECLARE(glm_vec4_normalize_to) +TEST_DECLARE(glm_vec4_distance2) +TEST_DECLARE(glm_vec4_distance) +TEST_DECLARE(glm_vec4_maxv) +TEST_DECLARE(glm_vec4_minv) +TEST_DECLARE(glm_vec4_clamp) +TEST_DECLARE(glm_vec4_lerp) +TEST_DECLARE(glm_vec4_lerpc) +TEST_DECLARE(glm_vec4_mix) +TEST_DECLARE(glm_vec4_mixc) +TEST_DECLARE(glm_vec4_step_uni) +TEST_DECLARE(glm_vec4_step) +TEST_DECLARE(glm_vec4_smoothstep_uni) +TEST_DECLARE(glm_vec4_smoothstep) +TEST_DECLARE(glm_vec4_smoothinterp) +TEST_DECLARE(glm_vec4_smoothinterpc) +TEST_DECLARE(glm_vec4_cubic) +TEST_DECLARE(glm_vec4_swizzle) +TEST_DECLARE(glm_vec4_broadcast) +TEST_DECLARE(glm_vec4_fill) +TEST_DECLARE(glm_vec4_eq) +TEST_DECLARE(glm_vec4_eq_eps) +TEST_DECLARE(glm_vec4_eq_all) +TEST_DECLARE(glm_vec4_eqv) +TEST_DECLARE(glm_vec4_eqv_eps) +TEST_DECLARE(glm_vec4_max) +TEST_DECLARE(glm_vec4_min) +TEST_DECLARE(glm_vec4_isnan) +TEST_DECLARE(glm_vec4_isinf) +TEST_DECLARE(glm_vec4_isvalid) +TEST_DECLARE(glm_vec4_sign) +TEST_DECLARE(glm_vec4_abs) +TEST_DECLARE(glm_vec4_fract) +TEST_DECLARE(glm_vec4_hadd) +TEST_DECLARE(glm_vec4_sqrt) + +TEST_DECLARE(glmc_vec4) +TEST_DECLARE(glmc_vec4_copy3) +TEST_DECLARE(glmc_vec4_copy) +TEST_DECLARE(glmc_vec4_ucopy) +TEST_DECLARE(glmc_vec4_zero) +TEST_DECLARE(glmc_vec4_one) +TEST_DECLARE(glmc_vec4_dot) +TEST_DECLARE(glmc_vec4_norm2) +TEST_DECLARE(glmc_vec4_norm) +TEST_DECLARE(glmc_vec4_norm_one) +TEST_DECLARE(glmc_vec4_norm_inf) +TEST_DECLARE(glmc_vec4_add) +TEST_DECLARE(glmc_vec4_adds) +TEST_DECLARE(glmc_vec4_sub) +TEST_DECLARE(glmc_vec4_subs) +TEST_DECLARE(glmc_vec4_mul) +TEST_DECLARE(glmc_vec4_scale) +TEST_DECLARE(glmc_vec4_scale_as) +TEST_DECLARE(glmc_vec4_div) +TEST_DECLARE(glmc_vec4_divs) +TEST_DECLARE(glmc_vec4_addadd) +TEST_DECLARE(glmc_vec4_subadd) +TEST_DECLARE(glmc_vec4_muladd) +TEST_DECLARE(glmc_vec4_muladds) +TEST_DECLARE(glmc_vec4_maxadd) +TEST_DECLARE(glmc_vec4_minadd) +TEST_DECLARE(glmc_vec4_negate_to) +TEST_DECLARE(glmc_vec4_negate) +TEST_DECLARE(glmc_vec4_normalize) +TEST_DECLARE(glmc_vec4_normalize_to) +TEST_DECLARE(glmc_vec4_distance2) +TEST_DECLARE(glmc_vec4_distance) +TEST_DECLARE(glmc_vec4_maxv) +TEST_DECLARE(glmc_vec4_minv) +TEST_DECLARE(glmc_vec4_clamp) +TEST_DECLARE(glmc_vec4_lerp) +TEST_DECLARE(glmc_vec4_lerpc) +TEST_DECLARE(glmc_vec4_mix) +TEST_DECLARE(glmc_vec4_mixc) +TEST_DECLARE(glmc_vec4_step_uni) +TEST_DECLARE(glmc_vec4_step) +TEST_DECLARE(glmc_vec4_smoothstep_uni) +TEST_DECLARE(glmc_vec4_smoothstep) +TEST_DECLARE(glmc_vec4_smoothinterp) +TEST_DECLARE(glmc_vec4_smoothinterpc) +TEST_DECLARE(glmc_vec4_cubic) +TEST_DECLARE(glmc_vec4_swizzle) +TEST_DECLARE(glmc_vec4_broadcast) +TEST_DECLARE(glmc_vec4_fill) +TEST_DECLARE(glmc_vec4_eq) +TEST_DECLARE(glmc_vec4_eq_eps) +TEST_DECLARE(glmc_vec4_eq_all) +TEST_DECLARE(glmc_vec4_eqv) +TEST_DECLARE(glmc_vec4_eqv_eps) +TEST_DECLARE(glmc_vec4_max) +TEST_DECLARE(glmc_vec4_min) +TEST_DECLARE(glmc_vec4_isnan) +TEST_DECLARE(glmc_vec4_isinf) +TEST_DECLARE(glmc_vec4_isvalid) +TEST_DECLARE(glmc_vec4_sign) +TEST_DECLARE(glmc_vec4_abs) +TEST_DECLARE(glmc_vec4_fract) +TEST_DECLARE(glmc_vec4_hadd) +TEST_DECLARE(glmc_vec4_sqrt) + +/* ivec2 */ +TEST_DECLARE(glm_ivec2) +TEST_DECLARE(glm_ivec2_copy) +TEST_DECLARE(glm_ivec2_zero) +TEST_DECLARE(glm_ivec2_one) +TEST_DECLARE(glm_ivec2_add) +TEST_DECLARE(glm_ivec2_adds) +TEST_DECLARE(glm_ivec2_sub) +TEST_DECLARE(glm_ivec2_subs) +TEST_DECLARE(glm_ivec2_mul) +TEST_DECLARE(glm_ivec2_scale) +TEST_DECLARE(glm_ivec2_distance2) +TEST_DECLARE(glm_ivec2_distance) +TEST_DECLARE(glm_ivec2_maxv) +TEST_DECLARE(glm_ivec2_minv) +TEST_DECLARE(glm_ivec2_clamp) + +TEST_DECLARE(glmc_ivec2) +TEST_DECLARE(glmc_ivec2_copy) +TEST_DECLARE(glmc_ivec2_zero) +TEST_DECLARE(glmc_ivec2_one) +TEST_DECLARE(glmc_ivec2_add) +TEST_DECLARE(glmc_ivec2_adds) +TEST_DECLARE(glmc_ivec2_sub) +TEST_DECLARE(glmc_ivec2_subs) +TEST_DECLARE(glmc_ivec2_mul) +TEST_DECLARE(glmc_ivec2_scale) +TEST_DECLARE(glmc_ivec2_distance2) +TEST_DECLARE(glmc_ivec2_distance) +TEST_DECLARE(glmc_ivec2_maxv) +TEST_DECLARE(glmc_ivec2_minv) +TEST_DECLARE(glmc_ivec2_clamp) + +/* ivec3 */ +TEST_DECLARE(glm_ivec3) +TEST_DECLARE(glm_ivec3_copy) +TEST_DECLARE(glm_ivec3_zero) +TEST_DECLARE(glm_ivec3_one) +TEST_DECLARE(glm_ivec3_add) +TEST_DECLARE(glm_ivec3_adds) +TEST_DECLARE(glm_ivec3_sub) +TEST_DECLARE(glm_ivec3_subs) +TEST_DECLARE(glm_ivec3_mul) +TEST_DECLARE(glm_ivec3_scale) +TEST_DECLARE(glm_ivec3_distance2) +TEST_DECLARE(glm_ivec3_distance) +TEST_DECLARE(glm_ivec3_maxv) +TEST_DECLARE(glm_ivec3_minv) +TEST_DECLARE(glm_ivec3_clamp) + +TEST_DECLARE(glmc_ivec3) +TEST_DECLARE(glmc_ivec3_copy) +TEST_DECLARE(glmc_ivec3_zero) +TEST_DECLARE(glmc_ivec3_one) +TEST_DECLARE(glmc_ivec3_add) +TEST_DECLARE(glmc_ivec3_adds) +TEST_DECLARE(glmc_ivec3_sub) +TEST_DECLARE(glmc_ivec3_subs) +TEST_DECLARE(glmc_ivec3_mul) +TEST_DECLARE(glmc_ivec3_scale) +TEST_DECLARE(glmc_ivec3_distance2) +TEST_DECLARE(glmc_ivec3_distance) +TEST_DECLARE(glmc_ivec3_maxv) +TEST_DECLARE(glmc_ivec3_minv) +TEST_DECLARE(glmc_ivec3_clamp) + +/* ivec4 */ +TEST_DECLARE(glm_ivec4) +TEST_DECLARE(glm_ivec4_copy) +TEST_DECLARE(glm_ivec4_zero) +TEST_DECLARE(glm_ivec4_one) +TEST_DECLARE(glm_ivec4_add) +TEST_DECLARE(glm_ivec4_adds) +TEST_DECLARE(glm_ivec4_sub) +TEST_DECLARE(glm_ivec4_subs) +TEST_DECLARE(glm_ivec4_mul) +TEST_DECLARE(glm_ivec4_scale) +TEST_DECLARE(glm_ivec4_distance2) +TEST_DECLARE(glm_ivec4_distance) +TEST_DECLARE(glm_ivec4_maxv) +TEST_DECLARE(glm_ivec4_minv) +TEST_DECLARE(glm_ivec4_clamp) + +TEST_DECLARE(glmc_ivec4) +TEST_DECLARE(glmc_ivec4_copy) +TEST_DECLARE(glmc_ivec4_zero) +TEST_DECLARE(glmc_ivec4_one) +TEST_DECLARE(glmc_ivec4_add) +TEST_DECLARE(glmc_ivec4_adds) +TEST_DECLARE(glmc_ivec4_sub) +TEST_DECLARE(glmc_ivec4_subs) +TEST_DECLARE(glmc_ivec4_mul) +TEST_DECLARE(glmc_ivec4_scale) +TEST_DECLARE(glmc_ivec4_distance2) +TEST_DECLARE(glmc_ivec4_distance) +TEST_DECLARE(glmc_ivec4_maxv) +TEST_DECLARE(glmc_ivec4_minv) +TEST_DECLARE(glmc_ivec4_clamp) + +/* structs */ +TEST_DECLARE(mat3s_identity_init) +TEST_DECLARE(mat3s_zero_init) +TEST_DECLARE(mat4s_identity_init) +TEST_DECLARE(mat4s_zero_init) +TEST_DECLARE(quats_zero_init) +TEST_DECLARE(vec3s_one_init) +TEST_DECLARE(vec3s_zero_init) +TEST_DECLARE(vec4s_black_init) +TEST_DECLARE(vec4s_one_init) +TEST_DECLARE(vec4s_zero_init) + +/*****************************************************************************/ + +TEST_LIST { + /* affine mat */ + TEST_ENTRY(glm_mul) + TEST_ENTRY(glm_mul) + TEST_ENTRY(glm_inv_tr) + + TEST_ENTRY(glmc_mul) + TEST_ENTRY(glmc_mul_rot) + TEST_ENTRY(glmc_inv_tr) + + /* affine */ + TEST_ENTRY(glm_translate) + TEST_ENTRY(glm_translate_to) + TEST_ENTRY(glm_translate_x) + TEST_ENTRY(glm_translate_y) + TEST_ENTRY(glm_translate_z) + TEST_ENTRY(glm_translate_make) + TEST_ENTRY(glm_scale_to) + TEST_ENTRY(glm_scale_make) + TEST_ENTRY(glm_scale) + TEST_ENTRY(glm_scale_uni) + TEST_ENTRY(glm_rotate_x) + TEST_ENTRY(glm_rotate_y) + TEST_ENTRY(glm_rotate_z) + TEST_ENTRY(glm_rotate_make) + TEST_ENTRY(glm_rotate) + TEST_ENTRY(glm_rotate_at) + TEST_ENTRY(glm_rotate_atm) + TEST_ENTRY(glm_decompose_scalev) + TEST_ENTRY(glm_uniscaled) + TEST_ENTRY(glm_decompose_rs) + TEST_ENTRY(glm_decompose) + + TEST_ENTRY(glmc_translate) + TEST_ENTRY(glmc_translate_to) + TEST_ENTRY(glmc_translate_x) + TEST_ENTRY(glmc_translate_y) + TEST_ENTRY(glmc_translate_z) + TEST_ENTRY(glmc_translate_make) + TEST_ENTRY(glmc_scale_to) + TEST_ENTRY(glmc_scale_make) + TEST_ENTRY(glmc_scale) + TEST_ENTRY(glmc_scale_uni) + TEST_ENTRY(glmc_rotate_x) + TEST_ENTRY(glmc_rotate_y) + TEST_ENTRY(glmc_rotate_z) + TEST_ENTRY(glmc_rotate_make) + TEST_ENTRY(glmc_rotate) + TEST_ENTRY(glmc_rotate_at) + TEST_ENTRY(glmc_rotate_atm) + TEST_ENTRY(glmc_decompose_scalev) + TEST_ENTRY(glmc_uniscaled) + TEST_ENTRY(glmc_decompose_rs) + TEST_ENTRY(glmc_decompose) + + /* affine 2d */ + TEST_ENTRY(glm_translate2d) + TEST_ENTRY(glm_translate2d_to) + TEST_ENTRY(glm_translate2d_x) + TEST_ENTRY(glm_translate2d_y) + TEST_ENTRY(glm_translate2d_make) + TEST_ENTRY(glm_scale2d_to) + TEST_ENTRY(glm_scale2d_make) + TEST_ENTRY(glm_scale2d) + TEST_ENTRY(glm_scale2d_uni) + TEST_ENTRY(glm_rotate2d_make) + TEST_ENTRY(glm_rotate2d) + TEST_ENTRY(glm_rotate2d_to) + + TEST_ENTRY(glmc_translate2d) + TEST_ENTRY(glmc_translate2d_to) + TEST_ENTRY(glmc_translate2d_x) + TEST_ENTRY(glmc_translate2d_y) + TEST_ENTRY(glmc_translate2d_make) + TEST_ENTRY(glmc_scale2d_to) + TEST_ENTRY(glmc_scale2d_make) + TEST_ENTRY(glmc_scale2d) + TEST_ENTRY(glmc_scale2d_uni) + TEST_ENTRY(glmc_rotate2d_make) + TEST_ENTRY(glmc_rotate2d) + TEST_ENTRY(glmc_rotate2d_to) + + /* mat4 */ + TEST_ENTRY(glm_mat4_ucopy) + TEST_ENTRY(glm_mat4_copy) + TEST_ENTRY(glm_mat4_identity) + TEST_ENTRY(glm_mat4_identity_array) + TEST_ENTRY(glm_mat4_zero) + TEST_ENTRY(glm_mat4_pick3) + TEST_ENTRY(glm_mat4_pick3t) + TEST_ENTRY(glm_mat4_ins3) + TEST_ENTRY(glm_mat4_mul) + TEST_ENTRY(glm_mat4_mulN) + TEST_ENTRY(glm_mat4_mulv) + TEST_ENTRY(glm_mat4_mulv3) + TEST_ENTRY(glm_mat4_trace) + TEST_ENTRY(glm_mat4_trace3) + TEST_ENTRY(glm_mat4_quat) + TEST_ENTRY(glm_mat4_transpose_to) + TEST_ENTRY(glm_mat4_transpose) + TEST_ENTRY(glm_mat4_scale_p) + TEST_ENTRY(glm_mat4_scale) + TEST_ENTRY(glm_mat4_det) + TEST_ENTRY(glm_mat4_inv) + TEST_ENTRY(glm_mat4_inv_fast) + TEST_ENTRY(glm_mat4_inv_precise) + TEST_ENTRY(glm_mat4_swap_col) + TEST_ENTRY(glm_mat4_swap_row) + TEST_ENTRY(glm_mat4_rmc) + + TEST_ENTRY(glmc_mat4_ucopy) + TEST_ENTRY(glmc_mat4_copy) + TEST_ENTRY(glmc_mat4_identity) + TEST_ENTRY(glmc_mat4_identity_array) + TEST_ENTRY(glmc_mat4_zero) + TEST_ENTRY(glmc_mat4_pick3) + TEST_ENTRY(glmc_mat4_pick3t) + TEST_ENTRY(glmc_mat4_ins3) + TEST_ENTRY(glmc_mat4_mul) + TEST_ENTRY(glmc_mat4_mulN) + TEST_ENTRY(glmc_mat4_mulv) + TEST_ENTRY(glmc_mat4_mulv3) + TEST_ENTRY(glmc_mat4_trace) + TEST_ENTRY(glmc_mat4_trace3) + TEST_ENTRY(glmc_mat4_quat) + TEST_ENTRY(glmc_mat4_transpose_to) + TEST_ENTRY(glmc_mat4_transpose) + TEST_ENTRY(glmc_mat4_scale_p) + TEST_ENTRY(glmc_mat4_scale) + TEST_ENTRY(glmc_mat4_det) + TEST_ENTRY(glmc_mat4_inv) + TEST_ENTRY(glmc_mat4_inv_fast) + TEST_ENTRY(glmc_mat4_swap_col) + TEST_ENTRY(glmc_mat4_swap_row) + TEST_ENTRY(glmc_mat4_rmc) + + /* mat3 */ + TEST_ENTRY(glm_mat3_copy) + TEST_ENTRY(glm_mat3_identity) + TEST_ENTRY(glm_mat3_identity_array) + TEST_ENTRY(glm_mat3_zero) + TEST_ENTRY(glm_mat3_mul) + TEST_ENTRY(glm_mat3_mulv) + TEST_ENTRY(glm_mat3_trace) + TEST_ENTRY(glm_mat3_quat) + TEST_ENTRY(glm_mat3_transpose_to) + TEST_ENTRY(glm_mat3_transpose) + TEST_ENTRY(glm_mat3_scale) + TEST_ENTRY(glm_mat3_det) + TEST_ENTRY(glm_mat3_inv) + TEST_ENTRY(glm_mat3_swap_col) + TEST_ENTRY(glm_mat3_swap_row) + TEST_ENTRY(glm_mat3_rmc) + + TEST_ENTRY(glmc_mat3_copy) + TEST_ENTRY(glmc_mat3_identity) + TEST_ENTRY(glmc_mat3_identity_array) + TEST_ENTRY(glmc_mat3_zero) + TEST_ENTRY(glmc_mat3_mul) + TEST_ENTRY(glmc_mat3_mulv) + TEST_ENTRY(glmc_mat3_trace) + TEST_ENTRY(glmc_mat3_quat) + TEST_ENTRY(glmc_mat3_transpose_to) + TEST_ENTRY(glmc_mat3_transpose) + TEST_ENTRY(glmc_mat3_scale) + TEST_ENTRY(glmc_mat3_det) + TEST_ENTRY(glmc_mat3_inv) + TEST_ENTRY(glmc_mat3_swap_col) + TEST_ENTRY(glmc_mat3_swap_row) + TEST_ENTRY(glmc_mat3_rmc) + + TEST_ENTRY(MACRO_GLM_MAT2_IDENTITY_INIT) + TEST_ENTRY(MACRO_GLM_MAT2_ZERO_INIT) + TEST_ENTRY(MACRO_GLM_MAT2_IDENTITY) + TEST_ENTRY(MACRO_GLM_MAT2_ZERO) + TEST_ENTRY(glm_mat2_copy) + TEST_ENTRY(glm_mat2_identity) + TEST_ENTRY(glm_mat2_identity_array) + TEST_ENTRY(glm_mat2_zero) + TEST_ENTRY(glm_mat2_mul) + TEST_ENTRY(glm_mat2_transpose_to) + TEST_ENTRY(glm_mat2_transpose) + TEST_ENTRY(glm_mat2_mulv) + TEST_ENTRY(glm_mat2_trace) + TEST_ENTRY(glm_mat2_scale) + TEST_ENTRY(glm_mat2_det) + TEST_ENTRY(glm_mat2_inv) + TEST_ENTRY(glm_mat2_swap_col) + TEST_ENTRY(glm_mat2_swap_row) + TEST_ENTRY(glm_mat2_rmc) + + TEST_ENTRY(glmc_mat2_copy) + TEST_ENTRY(glmc_mat2_identity) + TEST_ENTRY(glmc_mat2_identity_array) + TEST_ENTRY(glmc_mat2_zero) + TEST_ENTRY(glmc_mat2_mul) + TEST_ENTRY(glmc_mat2_transpose_to) + TEST_ENTRY(glmc_mat2_transpose) + TEST_ENTRY(glmc_mat2_mulv) + TEST_ENTRY(glmc_mat2_trace) + TEST_ENTRY(glmc_mat2_scale) + TEST_ENTRY(glmc_mat2_det) + TEST_ENTRY(glmc_mat2_inv) + TEST_ENTRY(glmc_mat2_swap_col) + TEST_ENTRY(glmc_mat2_swap_row) + TEST_ENTRY(glmc_mat2_rmc) + + /* camera (incl [LR]H cross [NZ]O) */ + TEST_ENTRY(perspective_lh_zo) + TEST_ENTRY(perspective_rh_zo) + TEST_ENTRY(perspective_lh_no) + TEST_ENTRY(perspective_rh_no) + TEST_ENTRY(camera_lookat) + TEST_ENTRY(camera_decomp) + + TEST_ENTRY(glm_frustum) + + TEST_ENTRY(glmc_frustum) + + /* project */ + TEST_ENTRY(glm_unprojecti) + TEST_ENTRY(glm_unproject) + TEST_ENTRY(glm_project) + + TEST_ENTRY(glmc_unprojecti) + TEST_ENTRY(glmc_unproject) + TEST_ENTRY(glmc_project) + + /* plane */ + TEST_ENTRY(glm_plane_normalize) + TEST_ENTRY(glmc_plane_normalize) + + /* utils */ + TEST_ENTRY(clamp) + + /* euler */ + TEST_ENTRY(euler) + + /* ray */ + TEST_ENTRY(glm_ray_triangle) + TEST_ENTRY(glmc_ray_triangle) + + /* quat */ + TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY_INIT) + TEST_ENTRY(MACRO_GLM_QUAT_IDENTITY) + + TEST_ENTRY(glm_quat_identity) + TEST_ENTRY(glm_quat_identity_array) + TEST_ENTRY(glm_quat_init) + TEST_ENTRY(glm_quatv) + TEST_ENTRY(glm_quat) + TEST_ENTRY(glm_quat_copy) + TEST_ENTRY(glm_quat_norm) + TEST_ENTRY(glm_quat_normalize_to) + TEST_ENTRY(glm_quat_normalize) + TEST_ENTRY(glm_quat_dot) + TEST_ENTRY(glm_quat_conjugate) + TEST_ENTRY(glm_quat_inv) + TEST_ENTRY(glm_quat_add) + TEST_ENTRY(glm_quat_sub) + TEST_ENTRY(glm_quat_real) + TEST_ENTRY(glm_quat_imag) + TEST_ENTRY(glm_quat_imagn) + TEST_ENTRY(glm_quat_imaglen) + TEST_ENTRY(glm_quat_angle) + TEST_ENTRY(glm_quat_axis) + TEST_ENTRY(glm_quat_mul) + TEST_ENTRY(glm_quat_mat4) + TEST_ENTRY(glm_quat_mat4t) + TEST_ENTRY(glm_quat_mat3) + TEST_ENTRY(glm_quat_mat3t) + TEST_ENTRY(glm_quat_lerp) + TEST_ENTRY(glm_quat_lerpc) + TEST_ENTRY(glm_quat_nlerp) + TEST_ENTRY(glm_quat_slerp) + TEST_ENTRY(glm_quat_look) + TEST_ENTRY(glm_quat_for) + TEST_ENTRY(glm_quat_forp) + TEST_ENTRY(glm_quat_rotatev) + TEST_ENTRY(glm_quat_rotate) + TEST_ENTRY(glm_quat_rotate_at) + TEST_ENTRY(glm_quat_rotate_atm) + TEST_ENTRY(glm_quat_from_vecs) + + TEST_ENTRY(glmc_quat_identity) + TEST_ENTRY(glmc_quat_identity_array) + TEST_ENTRY(glmc_quat_init) + TEST_ENTRY(glmc_quatv) + TEST_ENTRY(glmc_quat) + TEST_ENTRY(glmc_quat_copy) + TEST_ENTRY(glmc_quat_norm) + TEST_ENTRY(glmc_quat_normalize_to) + TEST_ENTRY(glmc_quat_normalize) + TEST_ENTRY(glmc_quat_dot) + TEST_ENTRY(glmc_quat_conjugate) + TEST_ENTRY(glmc_quat_inv) + TEST_ENTRY(glmc_quat_add) + TEST_ENTRY(glmc_quat_sub) + TEST_ENTRY(glmc_quat_real) + TEST_ENTRY(glmc_quat_imag) + TEST_ENTRY(glmc_quat_imagn) + TEST_ENTRY(glmc_quat_imaglen) + TEST_ENTRY(glmc_quat_angle) + TEST_ENTRY(glmc_quat_axis) + TEST_ENTRY(glmc_quat_mul) + TEST_ENTRY(glmc_quat_mat4) + TEST_ENTRY(glmc_quat_mat4t) + TEST_ENTRY(glmc_quat_mat3) + TEST_ENTRY(glmc_quat_mat3t) + TEST_ENTRY(glmc_quat_lerp) + TEST_ENTRY(glmc_quat_lerpc) + TEST_ENTRY(glmc_quat_nlerp) + TEST_ENTRY(glmc_quat_slerp) + TEST_ENTRY(glmc_quat_look) + TEST_ENTRY(glmc_quat_for) + TEST_ENTRY(glmc_quat_forp) + TEST_ENTRY(glmc_quat_rotatev) + TEST_ENTRY(glmc_quat_rotate) + TEST_ENTRY(glmc_quat_rotate_at) + TEST_ENTRY(glmc_quat_rotate_atm) + TEST_ENTRY(glmc_quat_from_vecs) + + /* bezier */ + TEST_ENTRY(bezier) + + /* vec2 */ + TEST_ENTRY(MACRO_GLM_VEC2_ONE_INIT) + TEST_ENTRY(MACRO_GLM_VEC2_ZERO_INIT) + TEST_ENTRY(MACRO_GLM_VEC2_ONE) + TEST_ENTRY(MACRO_GLM_VEC2_ZERO) + + TEST_ENTRY(glm_vec2) + TEST_ENTRY(glm_vec2_copy) + TEST_ENTRY(glm_vec2_zero) + TEST_ENTRY(glm_vec2_one) + TEST_ENTRY(glm_vec2_dot) + TEST_ENTRY(glm_vec2_cross) + TEST_ENTRY(glm_vec2_norm2) + TEST_ENTRY(glm_vec2_norm) + TEST_ENTRY(glm_vec2_add) + TEST_ENTRY(glm_vec2_adds) + TEST_ENTRY(glm_vec2_sub) + TEST_ENTRY(glm_vec2_subs) + TEST_ENTRY(glm_vec2_mul) + TEST_ENTRY(glm_vec2_scale) + TEST_ENTRY(glm_vec2_scale_as) + TEST_ENTRY(glm_vec2_div) + TEST_ENTRY(glm_vec2_divs) + TEST_ENTRY(glm_vec2_addadd) + TEST_ENTRY(glm_vec2_subadd) + TEST_ENTRY(glm_vec2_muladd) + TEST_ENTRY(glm_vec2_muladds) + TEST_ENTRY(glm_vec2_maxadd) + TEST_ENTRY(glm_vec2_minadd) + TEST_ENTRY(glm_vec2_negate_to) + TEST_ENTRY(glm_vec2_negate) + TEST_ENTRY(glm_vec2_normalize) + TEST_ENTRY(glm_vec2_normalize_to) + TEST_ENTRY(glm_vec2_rotate) + TEST_ENTRY(glm_vec2_distance2) + TEST_ENTRY(glm_vec2_distance) + TEST_ENTRY(glm_vec2_maxv) + TEST_ENTRY(glm_vec2_minv) + TEST_ENTRY(glm_vec2_clamp) + TEST_ENTRY(glm_vec2_lerp) + TEST_ENTRY(glm_vec2_complex_mul) + TEST_ENTRY(glm_vec2_complex_div) + + TEST_ENTRY(glmc_vec2) + TEST_ENTRY(glmc_vec2_copy) + TEST_ENTRY(glmc_vec2_zero) + TEST_ENTRY(glmc_vec2_one) + TEST_ENTRY(glmc_vec2_dot) + TEST_ENTRY(glmc_vec2_cross) + TEST_ENTRY(glmc_vec2_norm2) + TEST_ENTRY(glmc_vec2_norm) + TEST_ENTRY(glmc_vec2_add) + TEST_ENTRY(glmc_vec2_adds) + TEST_ENTRY(glmc_vec2_sub) + TEST_ENTRY(glmc_vec2_subs) + TEST_ENTRY(glmc_vec2_mul) + TEST_ENTRY(glmc_vec2_scale) + TEST_ENTRY(glmc_vec2_scale_as) + TEST_ENTRY(glmc_vec2_div) + TEST_ENTRY(glmc_vec2_divs) + TEST_ENTRY(glmc_vec2_addadd) + TEST_ENTRY(glmc_vec2_subadd) + TEST_ENTRY(glmc_vec2_muladd) + TEST_ENTRY(glmc_vec2_muladds) + TEST_ENTRY(glmc_vec2_maxadd) + TEST_ENTRY(glmc_vec2_minadd) + TEST_ENTRY(glmc_vec2_negate_to) + TEST_ENTRY(glmc_vec2_negate) + TEST_ENTRY(glmc_vec2_normalize) + TEST_ENTRY(glmc_vec2_normalize_to) + TEST_ENTRY(glmc_vec2_rotate) + TEST_ENTRY(glmc_vec2_distance2) + TEST_ENTRY(glmc_vec2_distance) + TEST_ENTRY(glmc_vec2_maxv) + TEST_ENTRY(glmc_vec2_minv) + TEST_ENTRY(glmc_vec2_clamp) + TEST_ENTRY(glmc_vec2_lerp) + TEST_ENTRY(glmc_vec2_complex_mul) + TEST_ENTRY(glmc_vec2_complex_div) + + /* vec3 */ + TEST_ENTRY(MACRO_GLM_VEC3_ONE_INIT) + TEST_ENTRY(MACRO_GLM_VEC3_ZERO_INIT) + TEST_ENTRY(MACRO_GLM_VEC3_ONE) + TEST_ENTRY(MACRO_GLM_VEC3_ZERO) + TEST_ENTRY(MACRO_GLM_YUP) + TEST_ENTRY(MACRO_GLM_ZUP) + TEST_ENTRY(MACRO_GLM_XUP) + TEST_ENTRY(MACRO_GLM_FORWARD_RH) + TEST_ENTRY(MACRO_GLM_SHUFFLE3) + TEST_ENTRY(MACRO_GLM_XXX) + TEST_ENTRY(MACRO_GLM_YYY) + TEST_ENTRY(MACRO_GLM_ZZZ) + TEST_ENTRY(MACRO_GLM_ZYX) + TEST_ENTRY(MACRO_glm_vec3_dup) + TEST_ENTRY(MACRO_glm_vec3_flipsign) + TEST_ENTRY(MACRO_glm_vec3_flipsign_to) + TEST_ENTRY(MACRO_glm_vec3_inv) + TEST_ENTRY(MACRO_glm_vec3_inv_to) + TEST_ENTRY(MACRO_glm_vec3_mulv) + + TEST_ENTRY(glm_vec3) + TEST_ENTRY(glm_vec3_copy) + TEST_ENTRY(glm_vec3_zero) + TEST_ENTRY(glm_vec3_one) + TEST_ENTRY(glm_vec3_dot) + TEST_ENTRY(glm_dot) + TEST_ENTRY(glm_vec3_norm2) + TEST_ENTRY(glm_vec3_norm) + TEST_ENTRY(glm_vec3_norm_one) + TEST_ENTRY(glm_vec3_norm_inf) + TEST_ENTRY(glm_vec3_add) + TEST_ENTRY(glm_vec3_adds) + TEST_ENTRY(glm_vec3_sub) + TEST_ENTRY(glm_vec3_subs) + TEST_ENTRY(glm_vec3_mul) + TEST_ENTRY(glm_vec3_scale) + TEST_ENTRY(glm_vec3_scale_as) + TEST_ENTRY(glm_vec3_div) + TEST_ENTRY(glm_vec3_divs) + TEST_ENTRY(glm_vec3_addadd) + TEST_ENTRY(glm_vec3_subadd) + TEST_ENTRY(glm_vec3_muladd) + TEST_ENTRY(glm_vec3_muladds) + TEST_ENTRY(glm_vec3_maxadd) + TEST_ENTRY(glm_vec3_minadd) + TEST_ENTRY(glm_vec3_negate_to) + TEST_ENTRY(glm_vec3_negate) + TEST_ENTRY(glm_vec3_normalize) + TEST_ENTRY(glm_vec3_normalize_to) + TEST_ENTRY(glm_normalize) + TEST_ENTRY(glm_normalize_to) + TEST_ENTRY(glm_vec3_cross) + TEST_ENTRY(glm_vec3_crossn) + TEST_ENTRY(glm_cross) + TEST_ENTRY(glm_vec3_angle) + TEST_ENTRY(glm_vec3_rotate) + TEST_ENTRY(glm_vec3_rotate_m4) + TEST_ENTRY(glm_vec3_rotate_m3) + TEST_ENTRY(glm_vec3_proj) + TEST_ENTRY(glm_vec3_center) + TEST_ENTRY(glmc_vec3_distance2) + TEST_ENTRY(glmc_vec3_distance) + TEST_ENTRY(glm_vec3_maxv) + TEST_ENTRY(glm_vec3_minv) + TEST_ENTRY(glm_vec3_ortho) + TEST_ENTRY(glm_vec3_clamp) + TEST_ENTRY(glm_vec3_mix) + TEST_ENTRY(glm_vec3_mixc) + TEST_ENTRY(glm_vec3_step_uni) + TEST_ENTRY(glm_vec3_step) + TEST_ENTRY(glm_vec3_smoothstep_uni) + TEST_ENTRY(glm_vec3_smoothstep) + TEST_ENTRY(glm_vec3_smoothinterp) + TEST_ENTRY(glm_vec3_smoothinterpc) + TEST_ENTRY(glm_vec3_swizzle) + TEST_ENTRY(glm_vec3_broadcast) + TEST_ENTRY(glm_vec3_fill) + TEST_ENTRY(glm_vec3_eq) + TEST_ENTRY(glm_vec3_eq_eps) + TEST_ENTRY(glm_vec3_eq_all) + TEST_ENTRY(glm_vec3_eqv) + TEST_ENTRY(glm_vec3_eqv_eps) + TEST_ENTRY(glm_vec3_max) + TEST_ENTRY(glm_vec3_min) + TEST_ENTRY(glm_vec3_isnan) + TEST_ENTRY(glm_vec3_isinf) + TEST_ENTRY(glm_vec3_isvalid) + TEST_ENTRY(glm_vec3_sign) + TEST_ENTRY(glm_vec3_abs) + TEST_ENTRY(glm_vec3_fract) + TEST_ENTRY(glm_vec3_hadd) + TEST_ENTRY(glm_vec3_sqrt) + + TEST_ENTRY(glmc_vec3) + TEST_ENTRY(glmc_vec3_copy) + TEST_ENTRY(glmc_vec3_zero) + TEST_ENTRY(glmc_vec3_one) + TEST_ENTRY(glmc_vec3_dot) + TEST_ENTRY(glmc_vec3_norm2) + TEST_ENTRY(glmc_vec3_norm) + TEST_ENTRY(glmc_vec3_norm_one) + TEST_ENTRY(glmc_vec3_norm_inf) + TEST_ENTRY(glmc_vec3_add) + TEST_ENTRY(glmc_vec3_adds) + TEST_ENTRY(glmc_vec3_sub) + TEST_ENTRY(glmc_vec3_subs) + TEST_ENTRY(glmc_vec3_mul) + TEST_ENTRY(glmc_vec3_scale) + TEST_ENTRY(glmc_vec3_scale_as) + TEST_ENTRY(glmc_vec3_div) + TEST_ENTRY(glmc_vec3_divs) + TEST_ENTRY(glmc_vec3_addadd) + TEST_ENTRY(glmc_vec3_subadd) + TEST_ENTRY(glmc_vec3_muladd) + TEST_ENTRY(glmc_vec3_muladds) + TEST_ENTRY(glmc_vec3_maxadd) + TEST_ENTRY(glmc_vec3_minadd) + TEST_ENTRY(glmc_vec3_negate_to) + TEST_ENTRY(glmc_vec3_negate) + TEST_ENTRY(glmc_vec3_normalize) + TEST_ENTRY(glmc_vec3_normalize_to) + TEST_ENTRY(glmc_vec3_cross) + TEST_ENTRY(glmc_vec3_crossn) + TEST_ENTRY(glmc_vec3_angle) + TEST_ENTRY(glmc_vec3_rotate) + TEST_ENTRY(glmc_vec3_rotate_m4) + TEST_ENTRY(glmc_vec3_rotate_m3) + TEST_ENTRY(glmc_vec3_proj) + TEST_ENTRY(glmc_vec3_center) + TEST_ENTRY(glmc_vec3_distance2) + TEST_ENTRY(glmc_vec3_distance) + TEST_ENTRY(glmc_vec3_maxv) + TEST_ENTRY(glmc_vec3_minv) + TEST_ENTRY(glmc_vec3_ortho) + TEST_ENTRY(glmc_vec3_clamp) + TEST_ENTRY(glmc_vec3_mix) + TEST_ENTRY(glmc_vec3_mixc) + TEST_ENTRY(glmc_vec3_step_uni) + TEST_ENTRY(glmc_vec3_step) + TEST_ENTRY(glmc_vec3_smoothstep_uni) + TEST_ENTRY(glmc_vec3_smoothstep) + TEST_ENTRY(glmc_vec3_smoothinterp) + TEST_ENTRY(glmc_vec3_smoothinterpc) + TEST_ENTRY(glmc_vec3_swizzle) + TEST_ENTRY(glmc_vec3_broadcast) + TEST_ENTRY(glmc_vec3_fill) + TEST_ENTRY(glmc_vec3_eq) + TEST_ENTRY(glmc_vec3_eq_eps) + TEST_ENTRY(glmc_vec3_eq_all) + TEST_ENTRY(glmc_vec3_eqv) + TEST_ENTRY(glmc_vec3_eqv_eps) + TEST_ENTRY(glmc_vec3_max) + TEST_ENTRY(glmc_vec3_min) + TEST_ENTRY(glmc_vec3_isnan) + TEST_ENTRY(glmc_vec3_isinf) + TEST_ENTRY(glmc_vec3_isvalid) + TEST_ENTRY(glmc_vec3_sign) + TEST_ENTRY(glmc_vec3_abs) + TEST_ENTRY(glmc_vec3_fract) + TEST_ENTRY(glmc_vec3_hadd) + TEST_ENTRY(glmc_vec3_sqrt) + + /* vec4 */ + TEST_ENTRY(MACRO_GLM_VEC4_ONE_INIT) + TEST_ENTRY(MACRO_GLM_VEC4_ZERO_INIT) + TEST_ENTRY(MACRO_GLM_VEC4_ONE) + TEST_ENTRY(MACRO_GLM_VEC4_ZERO) + TEST_ENTRY(MACRO_GLM_XXXX) + TEST_ENTRY(MACRO_GLM_YYYY) + TEST_ENTRY(MACRO_GLM_ZZZZ) + TEST_ENTRY(MACRO_GLM_WZYX) + TEST_ENTRY(MACRO_glm_vec4_dup) + TEST_ENTRY(MACRO_glm_vec4_flipsign) + TEST_ENTRY(MACRO_glm_vec4_flipsign_to) + TEST_ENTRY(MACRO_glm_vec4_inv) + TEST_ENTRY(MACRO_glm_vec4_inv_to) + TEST_ENTRY(MACRO_glm_vec4_mulv) + + TEST_ENTRY(glm_vec4) + TEST_ENTRY(glm_vec4_copy3) + TEST_ENTRY(glm_vec4_copy) + TEST_ENTRY(glm_vec4_ucopy) + TEST_ENTRY(glm_vec4_zero) + TEST_ENTRY(glm_vec4_one) + TEST_ENTRY(glm_vec4_dot) + TEST_ENTRY(glm_vec4_norm2) + TEST_ENTRY(glm_vec4_norm) + TEST_ENTRY(glm_vec4_norm_one) + TEST_ENTRY(glm_vec4_norm_inf) + TEST_ENTRY(glm_vec4_add) + TEST_ENTRY(glm_vec4_adds) + TEST_ENTRY(glm_vec4_sub) + TEST_ENTRY(glm_vec4_subs) + TEST_ENTRY(glm_vec4_mul) + TEST_ENTRY(glm_vec4_scale) + TEST_ENTRY(glm_vec4_scale_as) + TEST_ENTRY(glm_vec4_div) + TEST_ENTRY(glm_vec4_divs) + TEST_ENTRY(glm_vec4_addadd) + TEST_ENTRY(glm_vec4_subadd) + TEST_ENTRY(glm_vec4_muladd) + TEST_ENTRY(glm_vec4_muladds) + TEST_ENTRY(glm_vec4_maxadd) + TEST_ENTRY(glm_vec4_minadd) + TEST_ENTRY(glm_vec4_negate_to) + TEST_ENTRY(glm_vec4_negate) + TEST_ENTRY(glm_vec4_normalize) + TEST_ENTRY(glm_vec4_normalize_to) + TEST_ENTRY(glm_vec4_distance2) + TEST_ENTRY(glm_vec4_distance) + TEST_ENTRY(glm_vec4_maxv) + TEST_ENTRY(glm_vec4_minv) + TEST_ENTRY(glm_vec4_clamp) + TEST_ENTRY(glm_vec4_lerp) + TEST_ENTRY(glm_vec4_lerpc) + TEST_ENTRY(glm_vec4_mix) + TEST_ENTRY(glm_vec4_mixc) + TEST_ENTRY(glm_vec4_step_uni) + TEST_ENTRY(glm_vec4_step) + TEST_ENTRY(glm_vec4_smoothstep_uni) + TEST_ENTRY(glm_vec4_smoothstep) + TEST_ENTRY(glm_vec4_smoothinterp) + TEST_ENTRY(glm_vec4_smoothinterpc) + TEST_ENTRY(glm_vec4_cubic) + TEST_ENTRY(glm_vec4_swizzle) + TEST_ENTRY(glm_vec4_broadcast) + TEST_ENTRY(glm_vec4_fill) + TEST_ENTRY(glm_vec4_eq) + TEST_ENTRY(glm_vec4_eq_eps) + TEST_ENTRY(glm_vec4_eq_all) + TEST_ENTRY(glm_vec4_eqv) + TEST_ENTRY(glm_vec4_eqv_eps) + TEST_ENTRY(glm_vec4_max) + TEST_ENTRY(glm_vec4_min) + TEST_ENTRY(glm_vec4_isnan) + TEST_ENTRY(glm_vec4_isinf) + TEST_ENTRY(glm_vec4_isvalid) + TEST_ENTRY(glm_vec4_sign) + TEST_ENTRY(glm_vec4_abs) + TEST_ENTRY(glm_vec4_fract) + TEST_ENTRY(glm_vec4_hadd) + TEST_ENTRY(glm_vec4_sqrt) + + TEST_ENTRY(glmc_vec4) + TEST_ENTRY(glmc_vec4_copy3) + TEST_ENTRY(glmc_vec4_copy) + TEST_ENTRY(glmc_vec4_ucopy) + TEST_ENTRY(glmc_vec4_zero) + TEST_ENTRY(glmc_vec4_one) + TEST_ENTRY(glmc_vec4_dot) + TEST_ENTRY(glmc_vec4_norm2) + TEST_ENTRY(glmc_vec4_norm) + TEST_ENTRY(glmc_vec4_norm_one) + TEST_ENTRY(glmc_vec4_norm_inf) + TEST_ENTRY(glmc_vec4_add) + TEST_ENTRY(glmc_vec4_adds) + TEST_ENTRY(glmc_vec4_sub) + TEST_ENTRY(glmc_vec4_subs) + TEST_ENTRY(glmc_vec4_mul) + TEST_ENTRY(glmc_vec4_scale) + TEST_ENTRY(glmc_vec4_scale_as) + TEST_ENTRY(glmc_vec4_div) + TEST_ENTRY(glmc_vec4_divs) + TEST_ENTRY(glmc_vec4_addadd) + TEST_ENTRY(glmc_vec4_subadd) + TEST_ENTRY(glmc_vec4_muladd) + TEST_ENTRY(glmc_vec4_muladds) + TEST_ENTRY(glmc_vec4_maxadd) + TEST_ENTRY(glmc_vec4_minadd) + TEST_ENTRY(glmc_vec4_negate_to) + TEST_ENTRY(glmc_vec4_negate) + TEST_ENTRY(glmc_vec4_normalize) + TEST_ENTRY(glmc_vec4_normalize_to) + TEST_ENTRY(glmc_vec4_distance2) + TEST_ENTRY(glmc_vec4_distance) + TEST_ENTRY(glmc_vec4_maxv) + TEST_ENTRY(glmc_vec4_minv) + TEST_ENTRY(glmc_vec4_clamp) + TEST_ENTRY(glmc_vec4_lerp) + TEST_ENTRY(glmc_vec4_lerpc) + TEST_ENTRY(glmc_vec4_mix) + TEST_ENTRY(glmc_vec4_mixc) + TEST_ENTRY(glmc_vec4_step_uni) + TEST_ENTRY(glmc_vec4_step) + TEST_ENTRY(glmc_vec4_smoothstep_uni) + TEST_ENTRY(glmc_vec4_smoothstep) + TEST_ENTRY(glmc_vec4_smoothinterp) + TEST_ENTRY(glmc_vec4_smoothinterpc) + TEST_ENTRY(glmc_vec4_cubic) + TEST_ENTRY(glmc_vec4_swizzle) + TEST_ENTRY(glmc_vec4_broadcast) + TEST_ENTRY(glmc_vec4_fill) + TEST_ENTRY(glmc_vec4_eq) + TEST_ENTRY(glmc_vec4_eq_eps) + TEST_ENTRY(glmc_vec4_eq_all) + TEST_ENTRY(glmc_vec4_eqv) + TEST_ENTRY(glmc_vec4_eqv_eps) + TEST_ENTRY(glmc_vec4_max) + TEST_ENTRY(glmc_vec4_min) + TEST_ENTRY(glmc_vec4_isnan) + TEST_ENTRY(glmc_vec4_isinf) + TEST_ENTRY(glmc_vec4_isvalid) + TEST_ENTRY(glmc_vec4_sign) + TEST_ENTRY(glmc_vec4_abs) + TEST_ENTRY(glmc_vec4_fract) + TEST_ENTRY(glmc_vec4_hadd) + TEST_ENTRY(glmc_vec4_sqrt) + + /* ivec2 */ + TEST_ENTRY(glm_ivec2) + TEST_ENTRY(glm_ivec2_copy) + TEST_ENTRY(glm_ivec2_zero) + TEST_ENTRY(glm_ivec2_one) + TEST_ENTRY(glm_ivec2_add) + TEST_ENTRY(glm_ivec2_adds) + TEST_ENTRY(glm_ivec2_sub) + TEST_ENTRY(glm_ivec2_subs) + TEST_ENTRY(glm_ivec2_mul) + TEST_ENTRY(glm_ivec2_scale) + TEST_ENTRY(glm_ivec2_distance2) + TEST_ENTRY(glm_ivec2_distance) + TEST_ENTRY(glm_ivec2_maxv) + TEST_ENTRY(glm_ivec2_minv) + TEST_ENTRY(glm_ivec2_clamp) + + TEST_ENTRY(glmc_ivec2) + TEST_ENTRY(glmc_ivec2_copy) + TEST_ENTRY(glmc_ivec2_zero) + TEST_ENTRY(glmc_ivec2_one) + TEST_ENTRY(glmc_ivec2_add) + TEST_ENTRY(glmc_ivec2_adds) + TEST_ENTRY(glmc_ivec2_sub) + TEST_ENTRY(glmc_ivec2_subs) + TEST_ENTRY(glmc_ivec2_mul) + TEST_ENTRY(glmc_ivec2_scale) + TEST_ENTRY(glmc_ivec2_distance2) + TEST_ENTRY(glmc_ivec2_distance) + TEST_ENTRY(glmc_ivec2_maxv) + TEST_ENTRY(glmc_ivec2_minv) + TEST_ENTRY(glmc_ivec2_clamp) + + /* ivec3 */ + TEST_ENTRY(glm_ivec3) + TEST_ENTRY(glm_ivec3_copy) + TEST_ENTRY(glm_ivec3_zero) + TEST_ENTRY(glm_ivec3_one) + TEST_ENTRY(glm_ivec3_add) + TEST_ENTRY(glm_ivec3_adds) + TEST_ENTRY(glm_ivec3_sub) + TEST_ENTRY(glm_ivec3_subs) + TEST_ENTRY(glm_ivec3_mul) + TEST_ENTRY(glm_ivec3_scale) + TEST_ENTRY(glm_ivec3_distance2) + TEST_ENTRY(glm_ivec3_distance) + TEST_ENTRY(glm_ivec3_maxv) + TEST_ENTRY(glm_ivec3_minv) + TEST_ENTRY(glm_ivec3_clamp) + + TEST_ENTRY(glmc_ivec3) + TEST_ENTRY(glmc_ivec3_copy) + TEST_ENTRY(glmc_ivec3_zero) + TEST_ENTRY(glmc_ivec3_one) + TEST_ENTRY(glmc_ivec3_add) + TEST_ENTRY(glmc_ivec3_adds) + TEST_ENTRY(glmc_ivec3_sub) + TEST_ENTRY(glmc_ivec3_subs) + TEST_ENTRY(glmc_ivec3_mul) + TEST_ENTRY(glmc_ivec3_scale) + TEST_ENTRY(glmc_ivec3_distance2) + TEST_ENTRY(glmc_ivec3_distance) + TEST_ENTRY(glmc_ivec3_maxv) + TEST_ENTRY(glmc_ivec3_minv) + TEST_ENTRY(glmc_ivec3_clamp) + + /* ivec4 */ + TEST_ENTRY(glm_ivec4) + TEST_ENTRY(glm_ivec4_copy) + TEST_ENTRY(glm_ivec4_zero) + TEST_ENTRY(glm_ivec4_one) + TEST_ENTRY(glm_ivec4_add) + TEST_ENTRY(glm_ivec4_adds) + TEST_ENTRY(glm_ivec4_sub) + TEST_ENTRY(glm_ivec4_subs) + TEST_ENTRY(glm_ivec4_mul) + TEST_ENTRY(glm_ivec4_scale) + TEST_ENTRY(glm_ivec4_distance2) + TEST_ENTRY(glm_ivec4_distance) + TEST_ENTRY(glm_ivec4_maxv) + TEST_ENTRY(glm_ivec4_minv) + TEST_ENTRY(glm_ivec4_clamp) + + TEST_ENTRY(glmc_ivec4) + TEST_ENTRY(glmc_ivec4_copy) + TEST_ENTRY(glmc_ivec4_zero) + TEST_ENTRY(glmc_ivec4_one) + TEST_ENTRY(glmc_ivec4_add) + TEST_ENTRY(glmc_ivec4_adds) + TEST_ENTRY(glmc_ivec4_sub) + TEST_ENTRY(glmc_ivec4_subs) + TEST_ENTRY(glmc_ivec4_mul) + TEST_ENTRY(glmc_ivec4_scale) + TEST_ENTRY(glmc_ivec4_distance2) + TEST_ENTRY(glmc_ivec4_distance) + TEST_ENTRY(glmc_ivec4_maxv) + TEST_ENTRY(glmc_ivec4_minv) + TEST_ENTRY(glmc_ivec4_clamp) + + /* structs */ + TEST_ENTRY(mat3s_identity_init) + TEST_ENTRY(mat3s_zero_init) + TEST_ENTRY(mat4s_identity_init) + TEST_ENTRY(mat4s_zero_init) + TEST_ENTRY(quats_zero_init) + TEST_ENTRY(vec3s_one_init) + TEST_ENTRY(vec3s_zero_init) + TEST_ENTRY(vec4s_black_init) + TEST_ENTRY(vec4s_one_init) + TEST_ENTRY(vec4s_zero_init) +}; + +#endif /* tests_h */ diff --git a/libs/cglm/win/.gitignore b/libs/cglm/win/.gitignore new file mode 100644 index 0000000..96c0a51 --- /dev/null +++ b/libs/cglm/win/.gitignore @@ -0,0 +1,9 @@ +!cglm.sln + +!cglm.vcxproj +!cglm.vcxproj.filters + +!cglm-test.vcxproj +!cglm-test.vcxproj.filters + +!packages.config diff --git a/libs/cglm/win/build.bat b/libs/cglm/win/build.bat new file mode 100644 index 0000000..a2f0bf0 --- /dev/null +++ b/libs/cglm/win/build.bat @@ -0,0 +1 @@ +msbuild cglm.vcxproj /p:Configuration=Release diff --git a/libs/cglm/win/cglm-test.vcxproj b/libs/cglm/win/cglm-test.vcxproj new file mode 100644 index 0000000..43969b5 --- /dev/null +++ b/libs/cglm/win/cglm-test.vcxproj @@ -0,0 +1,204 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {ca8bcaf9-cd25-4133-8f62-3d1449b5d2fc} + + + + 16.0 + {200E0DF1-7532-44E6-8273-84FB92C5557E} + Win32Proj + cglmtest + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + false + + + true + + + true + + + false + + + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ../include;%(AdditionalIncludeDirectories) + + + Console + true + true + true + %(AdditionalDependencies) + + + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ../include;%(AdditionalIncludeDirectories) + Default + + + Console + true + %(AdditionalDependencies) + + + + + + + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ../include;%(AdditionalIncludeDirectories) + Default + + + Console + true + %(AdditionalDependencies) + + + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ../include;%(AdditionalIncludeDirectories) + + + Console + true + true + true + %(AdditionalDependencies) + + + + + + \ No newline at end of file diff --git a/libs/cglm/win/cglm-test.vcxproj.filters b/libs/cglm/win/cglm-test.vcxproj.filters new file mode 100644 index 0000000..f517012 --- /dev/null +++ b/libs/cglm/win/cglm-test.vcxproj.filters @@ -0,0 +1,104 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + + + include + + + include + + + include + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + \ No newline at end of file diff --git a/libs/cglm/win/cglm.sln b/libs/cglm/win/cglm.sln new file mode 100644 index 0000000..04f08b4 --- /dev/null +++ b/libs/cglm/win/cglm.sln @@ -0,0 +1,41 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29123.88 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cglm", "cglm.vcxproj", "{CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cglm-test", "cglm-test.vcxproj", "{200E0DF1-7532-44E6-8273-84FB92C5557E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}.Debug|x64.ActiveCfg = Debug|x64 + {CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}.Debug|x64.Build.0 = Debug|x64 + {CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}.Debug|x86.ActiveCfg = Debug|Win32 + {CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}.Debug|x86.Build.0 = Debug|Win32 + {CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}.Release|x64.ActiveCfg = Release|x64 + {CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}.Release|x64.Build.0 = Release|x64 + {CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}.Release|x86.ActiveCfg = Release|Win32 + {CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}.Release|x86.Build.0 = Release|Win32 + {200E0DF1-7532-44E6-8273-84FB92C5557E}.Debug|x64.ActiveCfg = Debug|x64 + {200E0DF1-7532-44E6-8273-84FB92C5557E}.Debug|x64.Build.0 = Debug|x64 + {200E0DF1-7532-44E6-8273-84FB92C5557E}.Debug|x86.ActiveCfg = Debug|Win32 + {200E0DF1-7532-44E6-8273-84FB92C5557E}.Debug|x86.Build.0 = Debug|Win32 + {200E0DF1-7532-44E6-8273-84FB92C5557E}.Release|x64.ActiveCfg = Release|x64 + {200E0DF1-7532-44E6-8273-84FB92C5557E}.Release|x64.Build.0 = Release|x64 + {200E0DF1-7532-44E6-8273-84FB92C5557E}.Release|x86.ActiveCfg = Release|Win32 + {200E0DF1-7532-44E6-8273-84FB92C5557E}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2AEF23C9-433B-428B-BEBC-068BF3AC9A65} + EndGlobalSection +EndGlobal diff --git a/libs/cglm/win/cglm.vcxproj b/libs/cglm/win/cglm.vcxproj new file mode 100644 index 0000000..46779bd --- /dev/null +++ b/libs/cglm/win/cglm.vcxproj @@ -0,0 +1,345 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 15.0 + {CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC} + Win32Proj + cglm + 10.0.17763.0 + + + + DynamicLibrary + true + v141 + Unicode + + + DynamicLibrary + false + v141 + true + Unicode + + + DynamicLibrary + true + v141 + Unicode + + + DynamicLibrary + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + NativeRecommendedRules.ruleset + true + + + NativeRecommendedRules.ruleset + true + + + false + NativeRecommendedRules.ruleset + true + + + false + NativeRecommendedRules.ruleset + true + + + + NotUsing + Level3 + MaxSpeed + WIN32;_DEBUG;_WINDOWS;_USRDLL;CGLM_EXPORTS;%(PreprocessorDefinitions) + None + Default + + CompileAsC + true + true + + + Windows + + + + + Level3 + MaxSpeed + _DEBUG;_WINDOWS;_USRDLL;CGLM_EXPORTS;%(PreprocessorDefinitions) + AnySuitable + true + true + + CompileAsC + None + Default + true + + + Windows + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;CGLM_EXPORTS;%(PreprocessorDefinitions) + None + + CompileAsC + true + Default + + + Windows + true + true + + + + + Level3 + NotUsing + MaxSpeed + true + true + NDEBUG;_WINDOWS;_USRDLL;CGLM_EXPORTS;%(PreprocessorDefinitions) + None + + CompileAsC + true + Default + + + Windows + true + true + + + + + + \ No newline at end of file diff --git a/libs/cglm/win/cglm.vcxproj.filters b/libs/cglm/win/cglm.vcxproj.filters new file mode 100644 index 0000000..7eedf3e --- /dev/null +++ b/libs/cglm/win/cglm.vcxproj.filters @@ -0,0 +1,562 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {f46634e5-c098-41a0-afb3-45afb6a53593} + + + {b982cbd3-03d9-4557-bed8-8224e4d95945} + + + {6a2a4ebb-ac68-4ed6-a4a1-f6d2243814e9} + + + {4bcb64d3-e522-48f7-85ef-3ddfacf50874} + + + {ccf6244c-614c-4016-a5d9-8a78ffc7765a} + + + {8607b04c-6eb6-49af-8ac2-e534ba78bf76} + + + {fb97f276-fe14-47ba-8a9f-01032f065a19} + + + {0b5febe7-a88d-4330-94ae-305897a5e957} + + + {8044a657-123d-4a0e-8de1-f348fad7dadb} + + + {842a48fc-5c7e-4951-9623-64af96dfb95a} + + + {86101de1-0722-4c88-92a0-e6d71158354e} + + + {98a166bb-ba2d-4649-a20f-ba6bf4ce6383} + + + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src + + + src\clipspace + + + src\clipspace + + + src\clipspace + + + src\clipspace + + + src\clipspace + + + src\clipspace + + + src\clipspace + + + src\clipspace + + + src\clipspace + + + src\clipspace + + + src\clipspace + + + src\clipspace + + + src\clipspace + + + src\clipspace + + + + + src + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\call + + + include\cglm\simd\avx + + + include\cglm\simd\avx + + + include\cglm\simd\neon + + + include\cglm\simd\sse2 + + + include\cglm\simd\sse2 + + + include\cglm\simd\sse2 + + + include\cglm\simd\sse2 + + + include\cglm\simd + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm\call + + + include\cglm\call + + + include\cglm + + + include\cglm + + + include\cglm\call + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm\call + + + include\cglm\call + + + include\cglm + + + include\cglm\call + + + include\cglm + + + include\cglm + + + include\cglm\simd + + + include\cglm\simd + + + include\cglm\call + + + include\cglm + + + include\cglm + + + include\cglm\call + + + include\cglm + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm + + + include\cglm + + + include\cglm\call + + + include\cglm\call + + + include\cglm\struct + + + include\cglm + + + include\cglm + + + include\cglm + + + include\cglm\struct + + + include\cglm\struct + + + include\cglm\simd\sse2 + + + include\cglm\call + + + include\cglm + + + include\cglm\struct + + + include\cglm\simd\neon + + + include\cglm\simd\neon + + + include\cglm\simd\neon + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\call\clipspace + + + include\cglm\call\clipspace + + + include\cglm\call\clipspace + + + include\cglm\call\clipspace + + + include\cglm\call\clipspace + + + include\cglm\call\clipspace + + + include\cglm\call\clipspace + + + include\cglm\call\clipspace + + + include\cglm\call\clipspace + + + include\cglm\call\clipspace + + + include\cglm\call\clipspace + + + include\cglm\call\clipspace + + + include\cglm\struct\clipspace + + + include\cglm\struct\clipspace + + + include\cglm\struct\clipspace + + + include\cglm\struct\clipspace + + + include\cglm\struct\clipspace + + + include\cglm\struct\clipspace + + + include\cglm\struct\clipspace + + + include\cglm\struct\clipspace + + + include\cglm\struct\clipspace + + + include\cglm\struct\clipspace + + + include\cglm\struct\clipspace + + + include\cglm\struct\clipspace + + + include\cglm\clipspace + + + include\cglm\clipspace + + + include\cglm\call\clipspace + + + include\cglm\call\clipspace + + + \ No newline at end of file -- cgit v1.2.1