├── .gitattributes ├── .github ├── FUNDING.yml └── workflows │ ├── ci.yml │ ├── cmake-wasm.yml │ └── meson-wasm.yml ├── .gitignore ├── .readthedocs.yaml ├── .travis.yml ├── BUILDING.md ├── CMakeLists.txt ├── CONTRIBUTING.md ├── CREDITS ├── LICENSE ├── Makefile.am ├── Package.swift ├── README.md ├── _config.yml ├── autogen.sh ├── cglm.pc.in ├── cglm.png ├── cglm.podspec ├── configure.ac ├── docs ├── make.bat ├── requirements.txt └── source │ ├── aabb2d.rst │ ├── affine-common.rst │ ├── affine-mat.rst │ ├── affine-post.rst │ ├── affine-pre.rst │ ├── affine.rst │ ├── affine2d.rst │ ├── api.rst │ ├── api_call.rst │ ├── api_inline_array.rst │ ├── api_simd.rst │ ├── api_struct.rst │ ├── bezier.rst │ ├── box.rst │ ├── build.rst │ ├── call.rst │ ├── cam.rst │ ├── cglm-intro.png │ ├── color.rst │ ├── conf.py │ ├── curve.rst │ ├── euler.rst │ ├── features.rst │ ├── frustum.rst │ ├── getting_started.rst │ ├── index.rst │ ├── io.rst │ ├── ivec2.rst │ ├── ivec3.rst │ ├── ivec4.rst │ ├── mat2.rst │ ├── mat2x3.rst │ ├── mat2x4.rst │ ├── mat3.rst │ ├── mat3x2.rst │ ├── mat3x4.rst │ ├── mat4.rst │ ├── mat4x2.rst │ ├── mat4x3.rst │ ├── noise.rst │ ├── opengl.rst │ ├── opt.rst │ ├── plane.rst │ ├── project.rst │ ├── quat.rst │ ├── ray.rst │ ├── sphere.rst │ ├── sphinx-static │ └── theme_overrides.css │ ├── troubleshooting.rst │ ├── util.rst │ ├── vec2-ext.rst │ ├── vec2.rst │ ├── vec3-ext.rst │ ├── vec3.rst │ ├── vec4-ext.rst │ ├── vec4.rst │ └── version.rst ├── include ├── cglm │ ├── aabb2d.h │ ├── affine-mat.h │ ├── affine-post.h │ ├── affine-pre.h │ ├── affine.h │ ├── affine2d-post.h │ ├── affine2d.h │ ├── applesimd.h │ ├── bezier.h │ ├── box.h │ ├── call.h │ ├── call │ │ ├── aabb2d.h │ │ ├── affine.h │ │ ├── affine2d.h │ │ ├── bezier.h │ │ ├── box.h │ │ ├── cam.h │ │ ├── clipspace │ │ │ ├── ortho_lh_no.h │ │ │ ├── ortho_lh_zo.h │ │ │ ├── ortho_rh_no.h │ │ │ ├── ortho_rh_zo.h │ │ │ ├── persp_lh_no.h │ │ │ ├── persp_lh_zo.h │ │ │ ├── persp_rh_no.h │ │ │ ├── persp_rh_zo.h │ │ │ ├── project_no.h │ │ │ ├── project_zo.h │ │ │ ├── view_lh_no.h │ │ │ ├── view_lh_zo.h │ │ │ ├── view_rh_no.h │ │ │ └── view_rh_zo.h │ │ ├── curve.h │ │ ├── ease.h │ │ ├── euler.h │ │ ├── frustum.h │ │ ├── io.h │ │ ├── ivec2.h │ │ ├── ivec3.h │ │ ├── ivec4.h │ │ ├── mat2.h │ │ ├── mat2x3.h │ │ ├── mat2x4.h │ │ ├── mat3.h │ │ ├── mat3x2.h │ │ ├── mat3x4.h │ │ ├── mat4.h │ │ ├── mat4x2.h │ │ ├── mat4x3.h │ │ ├── noise.h │ │ ├── plane.h │ │ ├── project.h │ │ ├── quat.h │ │ ├── ray.h │ │ ├── sphere.h │ │ ├── vec2.h │ │ ├── vec3.h │ │ └── vec4.h │ ├── cam.h │ ├── cglm.h │ ├── clipspace │ │ ├── ortho_lh_no.h │ │ ├── ortho_lh_zo.h │ │ ├── ortho_rh_no.h │ │ ├── ortho_rh_zo.h │ │ ├── persp.h │ │ ├── persp_lh_no.h │ │ ├── persp_lh_zo.h │ │ ├── persp_rh_no.h │ │ ├── persp_rh_zo.h │ │ ├── project_no.h │ │ ├── project_zo.h │ │ ├── view_lh.h │ │ ├── view_lh_no.h │ │ ├── view_lh_zo.h │ │ ├── view_rh.h │ │ ├── view_rh_no.h │ │ └── view_rh_zo.h │ ├── color.h │ ├── common.h │ ├── curve.h │ ├── ease.h │ ├── euler.h │ ├── frustum.h │ ├── handed │ │ ├── euler_to_quat_lh.h │ │ └── euler_to_quat_rh.h │ ├── io.h │ ├── ivec2.h │ ├── ivec3.h │ ├── ivec4.h │ ├── mat2.h │ ├── mat2x3.h │ ├── mat2x4.h │ ├── mat3.h │ ├── mat3x2.h │ ├── mat3x4.h │ ├── mat4.h │ ├── mat4x2.h │ ├── mat4x3.h │ ├── noise.h │ ├── plane.h │ ├── project.h │ ├── quat.h │ ├── ray.h │ ├── simd │ │ ├── arm.h │ │ ├── avx │ │ │ ├── affine.h │ │ │ └── mat4.h │ │ ├── intrin.h │ │ ├── neon │ │ │ ├── affine.h │ │ │ ├── mat2.h │ │ │ ├── mat4.h │ │ │ └── quat.h │ │ ├── sse2 │ │ │ ├── affine.h │ │ │ ├── mat2.h │ │ │ ├── mat3.h │ │ │ ├── mat4.h │ │ │ └── quat.h │ │ ├── wasm.h │ │ ├── wasm │ │ │ ├── affine.h │ │ │ ├── mat2.h │ │ │ ├── mat3.h │ │ │ ├── mat4.h │ │ │ └── quat.h │ │ └── x86.h │ ├── sphere.h │ ├── struct.h │ ├── struct │ │ ├── aabb2d.h │ │ ├── affine-mat.h │ │ ├── affine-post.h │ │ ├── affine-pre.h │ │ ├── affine.h │ │ ├── affine2d.h │ │ ├── box.h │ │ ├── cam.h │ │ ├── clipspace │ │ │ ├── ortho_lh_no.h │ │ │ ├── ortho_lh_zo.h │ │ │ ├── ortho_rh_no.h │ │ │ ├── ortho_rh_zo.h │ │ │ ├── persp_lh_no.h │ │ │ ├── persp_lh_zo.h │ │ │ ├── persp_rh_no.h │ │ │ ├── persp_rh_zo.h │ │ │ ├── project_no.h │ │ │ ├── project_zo.h │ │ │ ├── view_lh_no.h │ │ │ ├── view_lh_zo.h │ │ │ ├── view_rh_no.h │ │ │ └── view_rh_zo.h │ │ ├── color.h │ │ ├── curve.h │ │ ├── euler.h │ │ ├── frustum.h │ │ ├── handed │ │ │ ├── euler_to_quat_lh.h │ │ │ └── euler_to_quat_rh.h │ │ ├── io.h │ │ ├── ivec2.h │ │ ├── ivec3.h │ │ ├── ivec4.h │ │ ├── mat2.h │ │ ├── mat2x3.h │ │ ├── mat2x4.h │ │ ├── mat3.h │ │ ├── mat3x2.h │ │ ├── mat3x4.h │ │ ├── mat4.h │ │ ├── mat4x2.h │ │ ├── mat4x3.h │ │ ├── noise.h │ │ ├── plane.h │ │ ├── project.h │ │ ├── quat.h │ │ ├── ray.h │ │ ├── sphere.h │ │ ├── vec2-ext.h │ │ ├── vec2.h │ │ ├── vec3-ext.h │ │ ├── vec3.h │ │ ├── vec4-ext.h │ │ └── vec4.h │ ├── types-struct.h │ ├── types.h │ ├── util.h │ ├── vec2-ext.h │ ├── vec2.h │ ├── vec3-ext.h │ ├── vec3.h │ ├── vec4-ext.h │ ├── vec4.h │ └── version.h └── module.modulemap ├── meson.build ├── meson_options.txt ├── src ├── aabb2d.c ├── affine.c ├── affine2d.c ├── bezier.c ├── box.c ├── cam.c ├── clipspace │ ├── ortho_lh_no.c │ ├── ortho_lh_zo.c │ ├── ortho_rh_no.c │ ├── ortho_rh_zo.c │ ├── persp_lh_no.c │ ├── persp_lh_zo.c │ ├── persp_rh_no.c │ ├── persp_rh_zo.c │ ├── project_no.c │ ├── project_zo.c │ ├── view_lh_no.c │ ├── view_lh_zo.c │ ├── view_rh_no.c │ └── view_rh_zo.c ├── config.h ├── curve.c ├── ease.c ├── euler.c ├── frustum.c ├── io.c ├── ivec2.c ├── ivec3.c ├── ivec4.c ├── mat2.c ├── mat2x3.c ├── mat2x4.c ├── mat3.c ├── mat3x2.c ├── mat3x4.c ├── mat4.c ├── mat4x2.c ├── mat4x3.c ├── noise.c ├── plane.c ├── project.c ├── quat.c ├── ray.c ├── sphere.c ├── swift │ └── empty.c ├── vec2.c ├── vec3.c └── vec4.c ├── test ├── CMakeLists.txt ├── include │ └── common.h ├── runner.c ├── src │ ├── test_aabb2d.h │ ├── test_affine.h │ ├── test_affine2d.h │ ├── test_affine2d_post.h │ ├── test_affine_mat.h │ ├── test_bezier.c │ ├── test_cam.h │ ├── test_cam_lh_no.h │ ├── test_cam_lh_zo.h │ ├── test_cam_rh_no.h │ ├── test_cam_rh_zo.h │ ├── test_clamp.c │ ├── test_common.c │ ├── test_common.h │ ├── test_euler.c │ ├── test_euler_to_quat_lh.h │ ├── test_euler_to_quat_rh.h │ ├── test_ivec2.h │ ├── test_ivec3.h │ ├── test_ivec4.h │ ├── test_mat2.h │ ├── test_mat2x3.h │ ├── test_mat2x4.h │ ├── test_mat3.h │ ├── test_mat3x2.h │ ├── test_mat3x4.h │ ├── test_mat4.h │ ├── test_mat4x2.h │ ├── test_mat4x3.h │ ├── test_noise.h │ ├── test_plane.h │ ├── test_project.h │ ├── test_quat.h │ ├── test_ray.h │ ├── test_struct.c │ ├── test_vec2.h │ ├── test_vec3.h │ ├── test_vec4.h │ └── tests.c └── tests.h └── win ├── .gitignore ├── build.bat ├── cglm-test.vcxproj ├── cglm-test.vcxproj.filters ├── cglm.sln ├── cglm.vcxproj └── cglm.vcxproj.filters /.gitattributes: -------------------------------------------------------------------------------- 1 | *.h linguist-language=C 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [recp] 4 | patreon: recp 5 | open_collective: cglm 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | custom: # Replace with a single custom sponsorship URL 9 | -------------------------------------------------------------------------------- /.github/workflows/meson-wasm.yml: -------------------------------------------------------------------------------- 1 | name: Meson WebAssembly 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | env: 10 | wasmtime_version: v7.0.0 11 | wasmer_version: v3.1.1 12 | 13 | jobs: 14 | build_emsdk: 15 | strategy: 16 | matrix: 17 | BUILD_TYPE: [debug, debugoptimized, release, minsize] 18 | C_FLAGS: ['', '-msimd128', '-msse -msse2 -msimd128', '-msse -msse2 -msse3 -msse4 -msimd128'] 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | - name: Setup emsdk 23 | uses: mymindstorm/setup-emsdk@v13 24 | 25 | - name: Verify emsdk 26 | run: emcc -v 27 | 28 | - name: Creating cross file 29 | run: | 30 | cat << EOF > ${{github.workspace}}/meson_cross_emsdk.txt 31 | [binaries] 32 | c = '`which emcc`' 33 | cpp = '`which em++`' 34 | ar = '`which emar`' 35 | 36 | [built-in options] 37 | 38 | c_args = ['-Wno-unused-parameter'] 39 | c_link_args = ['-s', 'STANDALONE_WASM'] 40 | cpp_args = ['-Wno-unused-parameter'] 41 | cpp_link_args = ['-s', 'STANDALONE_WASM'] 42 | 43 | [host_machine] 44 | 45 | system = 'emscripten' 46 | cpu_family = 'wasm32' 47 | cpu = 'wasm32' 48 | endian = 'little' 49 | 50 | EOF 51 | cat ${{github.workspace}}/meson_cross_emsdk.txt 52 | 53 | - uses: actions/setup-python@v4 54 | 55 | - name: Install meson 56 | run: | 57 | sudo python3 -m pip install meson ninja 58 | 59 | - name: Build with meson 60 | run: | 61 | meson setup build -Dbuildtype=${{matrix.BUILD_TYPE}} --cross-file ${{github.workspace}}/meson_cross_emsdk.txt --default-library=static -Dbuild_tests=true 62 | meson test -C build 63 | 64 | - name: Test with wasmtime 65 | run: | 66 | cd ${{github.workspace}} 67 | ls -lh ${{github.workspace}}/build/ 68 | wget --no-verbose https://github.com/bytecodealliance/wasmtime/releases/download/${{env.wasmtime_version}}/wasmtime-${{env.wasmtime_version}}-x86_64-linux.tar.xz 69 | tar xf wasmtime-${{env.wasmtime_version}}-x86_64-linux.tar.xz 70 | ./wasmtime-${{env.wasmtime_version}}-x86_64-linux/wasmtime run --wasm-features simd ${{github.workspace}}/build/tests.wasm 71 | 72 | - name: Test with wasmer 73 | run: | 74 | cd ${{github.workspace}} 75 | mkdir wasmer 76 | cd wasmer 77 | wget --no-verbose https://github.com/wasmerio/wasmer/releases/download/${{env.wasmer_version}}/wasmer-linux-amd64.tar.gz 78 | tar xf wasmer-linux-amd64.tar.gz 79 | ./bin/wasmer run --enable-simd ${{github.workspace}}/build/tests.wasm 80 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.xcodeproj 2 | *.xcworkspace 3 | *.sln 4 | *.vcxproj 5 | *.vcxproj.* 6 | *.suo 7 | *.sdf 8 | *.opensdf 9 | ipch/ 10 | Debug/ 11 | Release/ 12 | .DS_Store 13 | .vs 14 | *.nupkg 15 | *.opendb 16 | packages.config 17 | /aclocal.m4 18 | /ar-lib 19 | /autom4te.cache/ 20 | /compile 21 | /config.guess 22 | /config.log 23 | /config.status 24 | /config.sub 25 | /configure 26 | /depcomp 27 | /install-sh 28 | /ltmain.sh 29 | /missing 30 | /libtool 31 | /.libs/ 32 | .deps/ 33 | *.[oa] 34 | *.l[oa] 35 | Makefile 36 | Makefile.in 37 | m4/*.m4 38 | .buildstamp 39 | .dirstamp 40 | packages/ 41 | .anjuta/* 42 | *.anjuta* 43 | config.h.* 44 | /config.h 45 | stamp* 46 | COPYING 47 | .idea/* 48 | *.VC.db 49 | cscope.* 50 | *-git-ignored-file.* 51 | test/*.trs 52 | test/test_* 53 | *.log 54 | test/.libs/* 55 | test/tests 56 | cglm_arm/* 57 | cglm_test_ios/* 58 | cglm_test_iosTests/* 59 | docs/build/* 60 | win/cglm_test_* 61 | * copy.* 62 | *.o 63 | *.obj 64 | *codeanalysis.*.xml 65 | *codeanalysis.xml 66 | *.lib 67 | *.tlog 68 | win/x64 69 | win/x85 70 | win/Debug 71 | cglm-test-ios* 72 | /cglm.pc 73 | test-driver 74 | Default-568h@2x.png 75 | build/ 76 | conftest.dir/* 77 | confdefs.h 78 | *.xcuserdatad 79 | .idea 80 | cmake-build-debug 81 | *.o.tmp 82 | xcode/* 83 | .vscode 84 | .build 85 | *.swp 86 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # Read the Docs configuration file for Sphinx projects 2 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 3 | 4 | # Required 5 | version: 2 6 | 7 | # Set the OS, Python version and other tools you might need 8 | build: 9 | os: ubuntu-22.04 10 | tools: 11 | python: "3.12" 12 | # You can also specify other tool versions: 13 | # nodejs: "20" 14 | # rust: "1.70" 15 | # golang: "1.20" 16 | 17 | # Build documentation in the "docs/" directory with Sphinx 18 | sphinx: 19 | configuration: docs/source/conf.py 20 | # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs 21 | # builder: "dirhtml" 22 | # Fail on all warnings to avoid broken references 23 | # fail_on_warning: true 24 | 25 | # Optionally build your docs in additional formats such as PDF and ePub 26 | # formats: 27 | # - pdf 28 | # - epub 29 | 30 | # Optional but recommended, declare the Python requirements required 31 | # to build your documentation 32 | # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html 33 | # python: 34 | # install: 35 | # - requirements: docs/requirements.txt 36 | 37 | python: 38 | install: 39 | - requirements: docs/requirements.txt -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | os: 4 | - linux 5 | - osx 6 | 7 | arch: 8 | - amd64 9 | - ppc64le 10 | - s390x 11 | - arm64 12 | 13 | sudo: required 14 | dist: trusty 15 | 16 | compiler: 17 | - clang 18 | - gcc 19 | 20 | matrix: 21 | fast_finish: true 22 | exclude: 23 | # Skip GCC builds on macOS. 24 | - os: osx 25 | compiler: gcc 26 | include: 27 | # Additional GCC builds for code coverage. 28 | - os: linux 29 | compiler: gcc 30 | env: CODE_COVERAGE=ON 31 | 32 | cache: 33 | apt: true 34 | 35 | addons: 36 | apt: 37 | packages: 38 | - clang-3.6 39 | - lcov 40 | 41 | branches: 42 | only: 43 | - master 44 | 45 | script: 46 | - sh ./autogen.sh 47 | - if [[ "$CC" == "gcc" && "$CODE_COVERAGE" == "ON" ]]; then 48 | ./configure CFLAGS="-ftest-coverage -fprofile-arcs -coverage"; 49 | else 50 | ./configure; 51 | fi 52 | - make 53 | - make check 54 | 55 | after_success: 56 | - if [[ "$CC" == "gcc" && "$CODE_COVERAGE" == "ON" ]]; then 57 | pip install --user cpp-coveralls && 58 | coveralls 59 | --build-root . 60 | --exclude lib 61 | --exclude test 62 | --gcov-options '\-lp' 63 | --verbose && 64 | bash <(curl -s https://codecov.io/bash); 65 | fi 66 | 67 | # after_failure: 68 | # - cat ./test-suite.log 69 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # CONTRIBUTING 2 | 3 | Any contributions (code, documentation, ...) are welcome. 4 | 5 | # New Features 6 | - This library may not accept all new features, it is better to create an issue and get approval before coding 7 | - You must add test for every new feature 8 | - The feature must be compiled on both UNIX/POSIX systems (e.g. macos, linux...) and Windows 9 | 10 | # Code Style 11 | This library is written with C99, don't try to add C++ files (yes it can compiled into lib), 12 | if you have enough reason to add C++ files than create an issue and get approval before coding, 13 | 14 | - All functions must have `glm` prefix 15 | - Lines should be wrapped at 80 characters. 16 | - Don't invent new style for existing ones 17 | - Use C89 style comments (`/* comments */`) not C++ style comments (`// comments`) 18 | - Don't use TABs instead use 2 spaces for TABs 19 | - All indents must be 2 spaces, not 1 nor 4 space 20 | - All functions in `include` folder must be exported by `CGLM_EXPORT` and wrapped by `extern "C" {` for C++ 21 | - Crate new line for return type, attribs: 22 | 23 | ```C 24 | CGLM_INLINE 25 | void 26 | glm_mul(mat4 m1, mat4 m2, mat4 dest) 27 | ``` 28 | 29 | not acceptable: 30 | 31 | ```C 32 | CGLM_INLINE void glm_mul(mat4 m1, mat4 m2, mat4 dest) 33 | ``` 34 | - Variables must be declared at the top of a scope before usage: 35 | ```C 36 | int x; 37 | int y; 38 | 39 | x = y = 0; 40 | ``` 41 | 42 | not acceptable: 43 | 44 | ```C 45 | int x; 46 | 47 | x = 0; 48 | int y = 0; 49 | ``` 50 | 51 | - All files must retain same LICENSE statement 52 | - Code with warnings will not be accepted, please suppress them (not by disabling them) 53 | - Run code anaylysis before submitting pull requests, if you use Xcode you can enable Sanitizer in scheme, you can use valgrind in linux 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Recep Aslantas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.2 2 | 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "cglm", 7 | products: [ 8 | .library(name: "cglm", type: .static, targets: ["cglmHeader"]), 9 | .library(name: "cglmc", targets: ["cglmCompiled"]), 10 | ], 11 | dependencies: [], 12 | targets: [ 13 | .target( 14 | name: "cglmCompiled", 15 | path: "./", 16 | exclude: [ 17 | "./docs", 18 | "./src/swift", 19 | "./include", 20 | "./test", 21 | "./win", 22 | ], 23 | sources: [ 24 | "./src", 25 | ], 26 | publicHeadersPath: "./include" 27 | ), 28 | .target( 29 | name: "cglmHeader", 30 | path: "./", 31 | exclude: [ 32 | "./docs", 33 | "./include", 34 | "./test", 35 | "./win", 36 | ], 37 | sources: [ 38 | "./src/swift", 39 | ], 40 | publicHeadersPath: "./include" 41 | ), 42 | ], 43 | cLanguageStandard: .c11 44 | ) 45 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # Copyright (c), Recep Aslantas. 4 | # 5 | # MIT License (MIT), http://opensource.org/licenses/MIT 6 | # Full license can be found in the LICENSE file 7 | # 8 | 9 | cd $(dirname "$0") 10 | 11 | autoheader 12 | 13 | if [ "$(uname)" = "Darwin" ]; then 14 | glibtoolize 15 | else 16 | libtoolize 17 | fi 18 | 19 | aclocal -I m4 20 | autoconf 21 | automake --add-missing --copy 22 | -------------------------------------------------------------------------------- /cglm.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: @PACKAGE_NAME@ 7 | Description: OpenGL Mathematics (glm) for C 8 | URL: https://github.com/recp/cglm 9 | Version: @PACKAGE_VERSION@ 10 | Cflags: -I${includedir} 11 | Libs: -L${libdir} -lcglm @LIBS@ 12 | -------------------------------------------------------------------------------- /cglm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/recp/cglm/a311dbfe4ced3258b6946584e210a7c8195ae22d/cglm.png -------------------------------------------------------------------------------- /cglm.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | # Description 4 | s.name = "cglm" 5 | s.version = "0.9.5" 6 | s.summary = "📽 Highly Optimized Graphics Math (glm) for C" 7 | s.description = <<-DESC 8 | cglm is math library for graphics programming for C. See the documentation or README for all features. 9 | DESC 10 | 11 | s.documentation_url = "http://cglm.readthedocs.io" 12 | 13 | # Home 14 | s.homepage = "https://github.com/recp/cglm" 15 | s.license = { :type => "MIT", :file => "LICENSE" } 16 | s.author = { "Recep Aslantas" => "recp@acm.org" } 17 | 18 | # Sources 19 | s.source = { :git => "https://github.com/recp/cglm.git", :tag => "v#{s.version}" } 20 | s.source_files = "src", "include/cglm/**/*.h" 21 | s.public_header_files = "include", "include/cglm/**/*.h" 22 | s.exclude_files = "src/win/*", "src/dllmain.c", "src/**/*.h" 23 | s.preserve_paths = "include", "src" 24 | s.header_mappings_dir = "include" 25 | 26 | # Linking 27 | s.library = "m" 28 | 29 | # Configuration 30 | s.pod_target_xcconfig = { 31 | 'CLANG_ENABLE_MODULES' => 'NO', 32 | 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES', 33 | 'CLANG_WARN_DOCUMENTATION_COMMENTS' => 'NO', 34 | 'GCC_C_LANGUAGE_STANDARD' => 'gnu11', 35 | 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GLM_TESTS_NO_COLORFUL_OUTPUT' 36 | } 37 | end 38 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | #***************************************************************************** 2 | # Copyright (c), Recep Aslantas. * 3 | # * 4 | # MIT License (MIT), http://opensource.org/licenses/MIT * 5 | # Full license can be found in the LICENSE file * 6 | # * 7 | #***************************************************************************** 8 | 9 | AC_PREREQ([2.69]) 10 | AC_INIT([cglm], [0.9.6], [info@recp.me]) 11 | AM_INIT_AUTOMAKE([-Wall foreign subdir-objects serial-tests]) 12 | 13 | # Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am. 14 | : ${CFLAGS=""} 15 | 16 | AC_CONFIG_MACRO_DIR([m4]) 17 | AC_CONFIG_SRCDIR([src/]) 18 | AC_CONFIG_HEADERS([config.h]) 19 | 20 | # Dependencies for pkg-config. 21 | PKG_PROG_PKG_CONFIG 22 | # Ancient versions of pkg-config (such as the one used in Travis CI) 23 | # don't have this macro, so we need to do it manually. 24 | m4_ifdef([PKG_INSTALLDIR], [ 25 | PKG_INSTALLDIR 26 | ], [ 27 | AC_ARG_WITH([pkgconfigdir], 28 | [AS_HELP_STRING([--with-pkgconfigdir], 29 | [pkg-config installation directory ['${libdir}/pkgconfig']])],, 30 | [with_pkgconfigdir=]'${libdir}/pkgconfig') 31 | AC_SUBST([pkgconfigdir], [$with_pkgconfigdir]) 32 | ]) 33 | 34 | # Checks for programs. 35 | AC_PROG_CC 36 | AM_PROG_CC_C_O 37 | 38 | AC_PROG_INSTALL 39 | AM_PROG_AR 40 | 41 | AC_ENABLE_SHARED 42 | AC_ENABLE_STATIC 43 | 44 | LT_INIT 45 | 46 | # Checks for libraries. 47 | AC_CHECK_LIB([m], [floor]) 48 | 49 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 50 | AC_SYS_LARGEFILE 51 | 52 | # Checks for header files. 53 | AC_CHECK_HEADERS([limits.h \ 54 | stddef.h \ 55 | stdint.h \ 56 | stdlib.h \ 57 | string.h ]) 58 | 59 | # Checks for typedefs, structures, and compiler characteristics. 60 | AC_CHECK_HEADER_STDBOOL 61 | AC_C_INLINE 62 | AC_TYPE_INT32_T 63 | AC_TYPE_INT64_T 64 | AC_TYPE_SIZE_T 65 | AC_TYPE_UINT16_T 66 | AC_TYPE_UINT32_T 67 | AC_TYPE_UINT64_T 68 | AC_TYPE_UINT8_T 69 | 70 | # Checks for library functions. 71 | AC_FUNC_ERROR_AT_LINE 72 | 73 | AC_CONFIG_FILES([Makefile cglm.pc]) 74 | 75 | AC_OUTPUT 76 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=python -msphinx 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | set SPHINXPROJ=cglm 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The Sphinx module was not found. Make sure you have Sphinx installed, 20 | echo.then set the SPHINXBUILD environment variable to point to the full 21 | echo.path of the 'sphinx-build' executable. Alternatively you may add the 22 | echo.Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | # Defining the exact version will make sure things don't break 2 | sphinx==7.2.6 3 | sphinx_rtd_theme==2.0.0 4 | readthedocs-sphinx-search==0.3.2 5 | -------------------------------------------------------------------------------- /docs/source/api.rst: -------------------------------------------------------------------------------- 1 | 📚 API documentation 2 | ================================ 3 | 4 | **cglm** provides a few APIs for similar functions. 5 | 6 | * 📦 **Inline API**: All functions are inline. You can include **cglm/cglm.h** header 7 | to use this API. This is the default API. `glm_` is namespace/prefix for this API. 8 | * 📦 **Call API**: All functions are not inline. You need to build *cglm* and link it 9 | to your project. You can include **cglm/call.h** header to use this API. `glmc_` is namespace/prefix for this API. 10 | 11 | And also there are also sub categories: 12 | 13 | * 📦 **Array API**: Types are raw arrays and functions takes array as argument. You can include **cglm/cglm.h** header 14 | to use this API. This is the default API. `glm_` is namespace/prefix for this API. 15 | * 📦 **Struct API**: Types are union/struct and functions takes struct as argument and return structs if needed. You can include **cglm/struct.h** header 16 | to use this API. This also includes **cglm/cglm.h** header.`glms_` is namespace/prefix for this API but your can omit or change it, see struct api docs. 17 | * 📦 **SIMD API**: SIMD functions and helpers. `glmm_` is namespace/prefix for this API. 18 | 19 | 📌 Since struct api and call api are built top of inline array api, follow inline array api docs for individual functions. 20 | 21 | .. toctree:: 22 | :maxdepth: 1 23 | :caption: API documentations: 24 | 25 | api_inline_array 26 | api_struct 27 | api_call 28 | api_simd 29 | -------------------------------------------------------------------------------- /docs/source/api_call.rst: -------------------------------------------------------------------------------- 1 | Call API 2 | ================================ 3 | 4 | Call API is pre-built API for making calls from library. It is built on top of the array api. **glmc_** is the namespace for the call api. 5 | **c** stands for call. 6 | 7 | You need to built cglm to use call api. See build instructions (:doc:`build`) for more details. 8 | 9 | The functions except namespace **glmc_** are same as inline api. See ( :doc:`api_inline_array` ) for more details. 10 | 11 | 📌 In the future we can define option to forward inline functions or struct api to call api. -------------------------------------------------------------------------------- /docs/source/api_inline_array.rst: -------------------------------------------------------------------------------- 1 | Array API - Inline (Default) 2 | ======================================== 3 | 4 | This is the default API of *cglm*. All functions are forced to be inlined 5 | and struct api, call api uses this inline api to share implementation. 6 | 7 | 📌 Call api is also array api but it is not inlined. 8 | In the future there may be option to forward struct api to call api instead of inline api to reduce binary size if needed. 9 | 10 | 📌 **USE this API docs for similar functions in struct and call api** 11 | 12 | 📌 In struct api you can omit namespace e.g :code:`glms_vec3_dot` can be called as :code:`vec3_dot` in struct api, see :doc:`api_struct` to configure struct api for more details. 13 | 📌 In struct api functions can return struct/union 14 | 📌 In struct api you can access items like **.x**, **.y**, **.z**, **.w**, **.r**, **.g**, **.b**, **.a**, **.m00**, **m01**... 15 | 16 | Some functions may exist twice, once for their namespace and once for global namespace 17 | to make easier to write very common functions 18 | 19 | For instance, in general we use :code:`glm_vec3_dot` to get dot product 20 | of two **vec3**. Now we can also do this with :code:`glm_dot`, 21 | same for *_cross* and so on... 22 | 23 | The original function stays where it is, the function in global namespace 24 | of same name is just an alias, so there is no call version of those functions. 25 | e.g there is no func like :code:`glmc_dot` because *glm_dot* is just alias for 26 | :code:`glm_vec3_dot` 27 | 28 | By including **cglm/cglm.h** header you will include all inline version 29 | of functions. Since functions in this header[s] are inline you don't need to 30 | build or link *cglm* against your project. 31 | 32 | But by including **cglm/call.h** header you will include all *non-inline* 33 | version of functions. You need to build *cglm* and link it. 34 | Follow the :doc:`build` documentation for this 35 | 36 | .. toctree:: 37 | :maxdepth: 1 38 | :caption: API categories: 39 | 40 | affine 41 | affine-mat 42 | affine2d 43 | cam 44 | frustum 45 | box 46 | aabb2d 47 | quat 48 | euler 49 | mat2 50 | mat2x3 51 | mat2x4 52 | mat3 53 | mat3x2 54 | mat3x4 55 | mat4 56 | mat4x2 57 | mat4x3 58 | vec2 59 | vec2-ext 60 | vec3 61 | vec3-ext 62 | vec4 63 | vec4-ext 64 | ivec2 65 | ivec3 66 | ivec4 67 | color 68 | plane 69 | noise 70 | project 71 | util 72 | io 73 | call 74 | sphere 75 | curve 76 | bezier 77 | version 78 | ray 79 | -------------------------------------------------------------------------------- /docs/source/api_simd.rst: -------------------------------------------------------------------------------- 1 | SIMD API 2 | ================================ 3 | 4 | SIMD api is special api for SIMD operations. **glmm_** prefix is used for SIMD operations in cglm. It is used in many places in cglm. 5 | You can use it for your own SIMD operations too. In the future the api may be extended by time. 6 | 7 | Supported SIMD architectures ( may vary by time ) 8 | 9 | * SSE / SSE2 10 | * AVX 11 | * NEON 12 | * WASM 128 13 | -------------------------------------------------------------------------------- /docs/source/bezier.rst: -------------------------------------------------------------------------------- 1 | .. default-domain:: C 2 | 3 | Bezier 4 | ================================================================================ 5 | 6 | Header: cglm/bezier.h 7 | 8 | Common helpers for cubic bezier and similar curves. 9 | 10 | Table of contents (click to go): 11 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 | 13 | Functions: 14 | 15 | 1. :c:func:`glm_bezier` 16 | 2. :c:func:`glm_hermite` 17 | 3. :c:func:`glm_decasteljau` 18 | 19 | Functions documentation 20 | ~~~~~~~~~~~~~~~~~~~~~~~ 21 | 22 | .. c:function:: float glm_bezier(float s, float p0, float c0, float c1, float p1) 23 | 24 | | cubic bezier interpolation 25 | | formula: 26 | 27 | .. code-block:: text 28 | 29 | B(s) = P0*(1-s)^3 + 3*C0*s*(1-s)^2 + 3*C1*s^2*(1-s) + P1*s^3 30 | 31 | | similar result using matrix: 32 | 33 | .. code-block:: text 34 | 35 | B(s) = glm_smc(t, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}) 36 | 37 | | glm_eq(glm_smc(...), glm_bezier(...)) should return TRUE 38 | 39 | Parameters: 40 | | *[in]* **s** parameter between 0 and 1 41 | | *[in]* **p0** begin point 42 | | *[in]* **c0** control point 1 43 | | *[in]* **c1** control point 2 44 | | *[in]* **p1** end point 45 | 46 | Returns: 47 | B(s) 48 | 49 | .. c:function:: float glm_hermite(float s, float p0, float t0, float t1, float p1) 50 | 51 | | cubic hermite interpolation 52 | | formula: 53 | 54 | .. code-block:: text 55 | 56 | 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) 57 | 58 | | similar result using matrix: 59 | 60 | .. code-block:: text 61 | 62 | H(s) = glm_smc(t, GLM_HERMITE_MAT, (vec4){p0, p1, c0, c1}) 63 | 64 | | glm_eq(glm_smc(...), glm_hermite(...)) should return TRUE 65 | 66 | 67 | Parameters: 68 | | *[in]* **s** parameter between 0 and 1 69 | | *[in]* **p0** begin point 70 | | *[in]* **t0** tangent 1 71 | | *[in]* **t1** tangent 2 72 | | *[in]* **p1** end point 73 | 74 | Returns: 75 | B(s) 76 | 77 | .. c:function:: float glm_decasteljau(float prm, float p0, float c0, float c1, float p1) 78 | 79 | | iterative way to solve cubic equation 80 | 81 | Parameters: 82 | | *[in]* **prm** parameter between 0 and 1 83 | | *[in]* **p0** begin point 84 | | *[in]* **c0** control point 1 85 | | *[in]* **c1** control point 2 86 | | *[in]* **p1** end point 87 | 88 | Returns: 89 | parameter to use in cubic equation 90 | -------------------------------------------------------------------------------- /docs/source/call.rst: -------------------------------------------------------------------------------- 1 | .. default-domain:: C 2 | 3 | precompiled functions (call) 4 | ================================================================================ 5 | 6 | All functions in **glm_** namespace are forced to **inline**. 7 | Most functions also have pre-compiled version. 8 | 9 | Precompiled versions are in **glmc_** namespace. *c* in the namespace stands for 10 | "call". 11 | 12 | Since precompiled functions are just wrapper for inline versions, 13 | these functions are not documented individually. 14 | It would be duplicate documentation also it 15 | would be hard to sync documentation between inline and call version for me. 16 | 17 | By including **clgm/cglm.h** you include all inline versions. To get precompiled 18 | versions you need to include **cglm/call.h** header it also includes all 19 | call versions plus *clgm/cglm.h* (inline versions) 20 | -------------------------------------------------------------------------------- /docs/source/cglm-intro.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/recp/cglm/a311dbfe4ced3258b6946584e210a7c8195ae22d/docs/source/cglm-intro.png -------------------------------------------------------------------------------- /docs/source/color.rst: -------------------------------------------------------------------------------- 1 | .. default-domain:: C 2 | 3 | color 4 | ================================================================================ 5 | 6 | Header: cglm/color.h 7 | 8 | Table of contents (click to go): 9 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10 | 11 | Functions: 12 | 13 | 1. :c:func:`glm_luminance` 14 | 15 | Functions documentation 16 | ~~~~~~~~~~~~~~~~~~~~~~~ 17 | 18 | .. c:function:: float glm_luminance(vec3 rgb) 19 | 20 | | averages the color channels into one value 21 | 22 | This function uses formula in COLLADA 1.5 spec which is 23 | 24 | .. code-block:: text 25 | 26 | luminance = (color.r * 0.212671) + 27 | (color.g * 0.715160) + 28 | (color.b * 0.072169) 29 | 30 | It is based on the ISO/CIE color standards (see ITU-R Recommendation BT.709-4), 31 | that averages the color channels into one value 32 | 33 | Parameters: 34 | | *[in]* **rgb** RGB color 35 | -------------------------------------------------------------------------------- /docs/source/curve.rst: -------------------------------------------------------------------------------- 1 | .. default-domain:: C 2 | 3 | Curve 4 | ================================================================================ 5 | 6 | Header: cglm/curve.h 7 | 8 | Common helpers for common curves. For specific curve see its header/doc 9 | e.g bezier 10 | 11 | Table of contents (click to go): 12 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 13 | 14 | Functions: 15 | 16 | 1. :c:func:`glm_smc` 17 | 18 | Functions documentation 19 | ~~~~~~~~~~~~~~~~~~~~~~~ 20 | 21 | .. c:function:: float glm_smc(float s, mat4 m, vec4 c) 22 | 23 | | helper function to calculate **S** * **M** * **C** multiplication for curves 24 | 25 | | this function does not encourage you to use SMC, instead it is a helper if you use SMC. 26 | 27 | | if you want to specify S as vector then use more generic glm_mat4_rmc() func. 28 | 29 | | Example usage: 30 | 31 | .. code-block:: c 32 | 33 | Bs = glm_smc(s, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}) 34 | 35 | Parameters: 36 | | *[in]* **s** parameter between 0 and 1 (this will be [s3, s2, s, 1]) 37 | | *[in]* **m** basis matrix 38 | | *[out]* **c** position/control vector 39 | 40 | Returns: 41 | scalar value e.g. Bs 42 | -------------------------------------------------------------------------------- /docs/source/features.rst: -------------------------------------------------------------------------------- 1 | Features 2 | ================================================================================ 3 | 4 | * **scalar** and **simd** (sse, avx, neon, wasm...) optimizations 5 | * option to use different clipspaces e.g. Left Handed, Zero-to-One... (currently right handed negative-one is default) 6 | * array api and struct api, you can use arrays or structs. 7 | * general purpose matrix operations (mat4, mat3) 8 | * chain matrix multiplication (square only) 9 | * general purpose vector operations (cross, dot, rotate, proj, angle...) 10 | * affine transformations 11 | * matrix decomposition (extract rotation, scaling factor) 12 | * optimized affine transform matrices (mul, rigid-body inverse) 13 | * camera (lookat) 14 | * projections (ortho, perspective) 15 | * quaternions 16 | * euler angles / yaw-pitch-roll to matrix 17 | * extract euler angles 18 | * inline or pre-compiled function call 19 | * frustum (extract view frustum planes, corners...) 20 | * bounding box (AABB in Frustum (culling), crop, merge...) 21 | * 2d bounding box (crop, merge...) 22 | * bounding sphere 23 | * project, unproject 24 | * easing functions 25 | * curves 26 | * curve interpolation helpers (SMC, deCasteljau...) 27 | * helpers to convert cglm types to Apple's simd library to pass cglm types to Metal GL without packing them on both sides 28 | * ray intersection helpers 29 | * and others... 30 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. cglm documentation master file, created by 2 | sphinx-quickstart on Tue Jun 6 20:31:05 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | cglm Documentation 7 | ================================ 8 | 9 | **cglm** is an optimized 3D math library written in C99 (compatible with C89). 10 | It is similar to the original **glm** library, except **cglm** is mainly for 11 | **C**. 12 | 13 | **cglm** stores matrices as column-major order but in the future row-major is 14 | considered to be supported as optional. 15 | 16 | .. toctree:: 17 | :maxdepth: 2 18 | :caption: Getting Started: 19 | 20 | features 21 | build 22 | getting_started 23 | 24 | .. toctree:: 25 | :maxdepth: 2 26 | :caption: How To: 27 | 28 | opengl 29 | 30 | .. toctree:: 31 | :maxdepth: 3 32 | :caption: API: 33 | 34 | api 35 | 36 | .. toctree:: 37 | :maxdepth: 2 38 | :caption: Options: 39 | 40 | opt 41 | 42 | .. toctree:: 43 | :maxdepth: 2 44 | :caption: Troubleshooting: 45 | 46 | troubleshooting 47 | 48 | Indices and Tables: 49 | =================== 50 | 51 | * :ref:`genindex` 52 | * :ref:`modindex` 53 | * :ref:`search` 54 | -------------------------------------------------------------------------------- /docs/source/noise.rst: -------------------------------------------------------------------------------- 1 | .. default-domain:: C 2 | 3 | perlin 4 | ================================================================================ 5 | 6 | Header: cglm/noise.h 7 | 8 | Classic Perlin noise implementation. 9 | 10 | Based on the work of Stefan Gustavson and Ashima Arts on "webgl-noise": 11 | https://github.com/stegu/webgl-noise 12 | Following Stefan Gustavson's paper "Simplex noise demystified": 13 | http://www.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf 14 | 15 | Implementation based on glm::perlin function: 16 | https://github.com/g-truc/glm/blob/master/glm/gtc/noise.inl 17 | 18 | Table of contents (click to go): 19 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 20 | 21 | Functions: 22 | 23 | 1. :c:func:`glm_perlin_vec4` 24 | #. :c:func:`glm_perlin_vec3` 25 | #. :c:func:`glm_perlin_vec2` 26 | 27 | 28 | Functions documentation 29 | ~~~~~~~~~~~~~~~~~~~~~~~ 30 | 31 | .. c:function:: float glm_perlin_vec4(vec4 point) 32 | 33 | | Classic Perlin noise 34 | 35 | Parameters: 36 | | *[in]* **point** 4D point 37 | 38 | Returns: 39 | | noise value 40 | 41 | 42 | .. c:function:: float glm_perlin_vec3(vec3 point) 43 | 44 | | Classic Perlin noise 45 | 46 | Parameters: 47 | | *[in]* **point** 3D point 48 | 49 | Returns: 50 | | noise value 51 | 52 | .. c:function:: float glm_perlin_vec2(vec2 point) 53 | 54 | | Classic Perlin noise 55 | 56 | Parameters: 57 | | *[in]* **point** 2D point 58 | 59 | Returns: 60 | | noise value 61 | -------------------------------------------------------------------------------- /docs/source/opengl.rst: -------------------------------------------------------------------------------- 1 | How to send vector or matrix to OpenGL like API 2 | ================================================== 3 | 4 | *cglm*'s vector and matrix types are arrays. So you can send them directly to a 5 | function which accepts pointer. But you may got warnings for matrix because it is 6 | two dimensional array. 7 | 8 | Passing / Uniforming Matrix to OpenGL: 9 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10 | **glUniformMatrix4fv** accepts float pointer, you can pass matrix to that parameter 11 | and it should work but with warnings. "You can pass" doesn't mean that you must pass like that. 12 | 13 | **Correct options:** 14 | 15 | Correct doesn't mean correct way to use OpenGL it is just shows correct way to pass cglm type to it. 16 | 17 | 1. Pass first column 18 | --------------------- 19 | 20 | The goal is that pass address of matrix, first element of matrix is also address of matrix, 21 | because it is array of vectors and vector is array of floats. 22 | 23 | .. code-block:: c 24 | 25 | mat4 matrix; 26 | /* ... */ 27 | glUniformMatrix4fv(location, 1, GL_FALSE, matrix[0]); 28 | 29 | array of matrices: 30 | 31 | .. code-block:: c 32 | 33 | mat4 matrix; 34 | /* ... */ 35 | glUniformMatrix4fv(location, count, GL_FALSE, matrix[0][0]); 36 | 37 | 2. Cast matrix to pointer 38 | -------------------------- 39 | 40 | .. code-block:: c 41 | 42 | mat4 matrix; 43 | /* ... */ 44 | glUniformMatrix4fv(location, count, GL_FALSE, (float *)matrix); 45 | 46 | in this way, passing array of matrices is same 47 | 48 | Passing / Uniforming Vectors to OpenGL: 49 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 50 | 51 | You don't need to do extra thing when passing cglm vectors to OpengL or other APIs. 52 | Because a function like **glUniform4fv** accepts vector as pointer. cglm's vectors 53 | are array of floats. So you can pass it directly to those functions: 54 | 55 | .. code-block:: c 56 | 57 | vec4 vec; 58 | /* ... */ 59 | glUniform4fv(location, 1, vec); 60 | 61 | this show how to pass **vec4** others are same. 62 | -------------------------------------------------------------------------------- /docs/source/plane.rst: -------------------------------------------------------------------------------- 1 | .. default-domain:: C 2 | 3 | plane 4 | ================================================================================ 5 | 6 | Header: cglm/plane.h 7 | 8 | Plane extract functions are in frustum header and documented 9 | in :doc:`frustum` page. 10 | 11 | **Definition of plane:** 12 | 13 | Plane equation: **Ax + By + Cz + D = 0** 14 | 15 | Plan is stored in **vec4** as **[A, B, C, D]**. (A, B, C) is normal and D is distance 16 | 17 | Table of contents (click to go): 18 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 | 20 | Functions: 21 | 22 | 1. :c:func:`glm_plane_normalize` 23 | 24 | 25 | Functions documentation 26 | ~~~~~~~~~~~~~~~~~~~~~~~ 27 | 28 | .. c:function:: void glm_plane_normalize(vec4 plane) 29 | 30 | | normalizes a plane 31 | 32 | Parameters: 33 | | *[in, out]* **plane** pnale to normalize 34 | -------------------------------------------------------------------------------- /docs/source/ray.rst: -------------------------------------------------------------------------------- 1 | .. default-domain:: C 2 | 3 | ray 4 | ==== 5 | 6 | Header: cglm/ray.h 7 | 8 | This is for collision-checks used by ray-tracers and the like. 9 | 10 | Table of contents (click to go): 11 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 | 13 | Functions: 14 | 15 | 1. :c:func:`glm_ray_triangle` 16 | #. :c:func:`glm_ray_sphere` 17 | #. :c:func:`glm_ray_at` 18 | 19 | Functions documentation 20 | ~~~~~~~~~~~~~~~~~~~~~~~ 21 | 22 | .. c:function:: bool glm_ray_triangle(vec3 origin, vec3 direction, vec3 v0, vec3 v1, vec3 v2, float *d) 23 | 24 | Möller–Trumbore ray-triangle intersection algorithm 25 | 26 | Parameters: 27 | | *[in]* **origin** origin of ray 28 | | *[in]* **direction** direction of ray 29 | | *[in]* **v0** first vertex of triangle 30 | | *[in]* **v1** second vertex of triangle 31 | | *[in]* **v2** third vertex of triangle 32 | | *[in, out]* **d** float pointer to save distance to intersection 33 | | *[out]* **intersection** whether there is intersection 34 | 35 | .. c:function:: bool glm_ray_sphere(vec3 origin, vec3 dir, vec4 s, float * __restrict t1, float * __restrict t2) 36 | 37 | ray sphere intersection 38 | 39 | returns false if there is no intersection if true: 40 | 41 | - t1 > 0, t2 > 0: ray intersects the sphere at t1 and t2 both ahead of the origin 42 | - t1 < 0, t2 > 0: ray starts inside the sphere, exits at t2 43 | - t1 < 0, t2 < 0: no intersection ahead of the ray ( returns false ) 44 | - the caller can check if the intersection points (t1 and t2) fall within a 45 | specific range (for example, tmin < t1, t2 < tmax) to determine if the 46 | intersections are within a desired segment of the ray 47 | 48 | Parameters: 49 | | *[in]* **origin** ray origin 50 | | *[in]* **dir** normalized ray direction 51 | | *[in]* **s** sphere [center.x, center.y, center.z, radii] 52 | | *[out]* **t1** near point1 (closer to origin) 53 | | *[out]* **t2** far point2 (farther from origin) 54 | 55 | Return: 56 | | whether there is intersection 57 | 58 | .. c:function:: bool glm_ray_at(vec3 orig, vec3 dir, float t, vec3 point) 59 | 60 | point using t by 𝐏(𝑡)=𝐀+𝑡𝐛 61 | 62 | Parameters: 63 | | *[in]* **origin** ray origin 64 | | *[in]* **dir** ray direction 65 | | *[out]* **t** parameter 66 | | *[out]* **point** point at t 67 | 68 | Return: 69 | | point at t 70 | -------------------------------------------------------------------------------- /docs/source/sphere.rst: -------------------------------------------------------------------------------- 1 | .. default-domain:: C 2 | 3 | Sphere 4 | ================================================================================ 5 | 6 | Header: cglm/sphere.h 7 | 8 | **Definition of sphere:** 9 | 10 | Sphere Representation in cglm is *vec4*: **[center.x, center.y, center.z, radii]** 11 | 12 | You can call any vec3 function by passing sphere. Because first three elements 13 | defines center of sphere. 14 | 15 | Table of contents (click to go): 16 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 17 | 18 | Functions: 19 | 20 | 1. :c:func:`glm_sphere_radii` 21 | #. :c:func:`glm_sphere_transform` 22 | #. :c:func:`glm_sphere_merge` 23 | #. :c:func:`glm_sphere_sphere` 24 | #. :c:func:`glm_sphere_point` 25 | 26 | Functions documentation 27 | ~~~~~~~~~~~~~~~~~~~~~~~ 28 | 29 | .. c:function:: float glm_sphere_radii(vec4 s) 30 | 31 | | helper for getting sphere radius 32 | 33 | Parameters: 34 | | *[in]* **s** sphere 35 | 36 | Returns: 37 | returns radii 38 | 39 | .. c:function:: void glm_sphere_transform(vec4 s, mat4 m, vec4 dest) 40 | 41 | | apply transform to sphere, it is just wrapper for glm_mat4_mulv3 42 | 43 | Parameters: 44 | | *[in]* **s** sphere 45 | | *[in]* **m** transform matrix 46 | | *[out]* **dest** transformed sphere 47 | 48 | .. c:function:: void glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) 49 | 50 | | merges two spheres and creates a new one 51 | 52 | two sphere must be in same space, for instance if one in world space then 53 | the other must be in world space too, not in local space. 54 | 55 | Parameters: 56 | | *[in]* **s1** sphere 1 57 | | *[in]* **s2** sphere 2 58 | | *[out]* **dest** merged/extended sphere 59 | 60 | .. c:function:: bool glm_sphere_sphere(vec4 s1, vec4 s2) 61 | 62 | | check if two sphere intersects 63 | 64 | Parameters: 65 | | *[in]* **s1** sphere 66 | | *[in]* **s2** other sphere 67 | 68 | .. c:function:: bool glm_sphere_point(vec4 s, vec3 point) 69 | 70 | | check if sphere intersects with point 71 | 72 | Parameters: 73 | | *[in]* **s** sphere 74 | | *[in]* **point** point 75 | -------------------------------------------------------------------------------- /docs/source/sphinx-static/theme_overrides.css: -------------------------------------------------------------------------------- 1 | @media screen { 2 | /* content column 3 | * 4 | * RTD theme's default is 800px as max width for the content, but we have 5 | * tables with tons of columns, which need the full width of the view-port. 6 | * 7 | * Comment from yocto project theme_overrides.css 8 | */ 9 | 10 | .wy-nav-content{ max-width: none; } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /docs/source/version.rst: -------------------------------------------------------------------------------- 1 | .. default-domain:: C 2 | 3 | version 4 | ================================================================================ 5 | 6 | Header: cglm/version.h 7 | 8 | **cglm** uses semantic versioning (http://semver.org) which is MAJOR.MINOR.PATCH 9 | 10 | | **CGLM_VERSION_MAJOR** is major number of the version. 11 | | **CGLM_VERSION_MINOR** is minor number of the version. 12 | | **CGLM_VERSION_PATCH** is patch number of the version. 13 | 14 | every release increases these numbers. You can check existing version by 15 | including `cglm/version.h` 16 | -------------------------------------------------------------------------------- /include/cglm/call.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_call_h 9 | #define cglm_call_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "cglm.h" 15 | #include "call/vec2.h" 16 | #include "call/vec3.h" 17 | #include "call/vec4.h" 18 | #include "call/ivec2.h" 19 | #include "call/ivec3.h" 20 | #include "call/ivec4.h" 21 | #include "call/mat2.h" 22 | #include "call/mat2x3.h" 23 | #include "call/mat2x4.h" 24 | #include "call/mat3.h" 25 | #include "call/mat3x2.h" 26 | #include "call/mat3x4.h" 27 | #include "call/mat4.h" 28 | #include "call/mat4x2.h" 29 | #include "call/mat4x3.h" 30 | #include "call/affine.h" 31 | #include "call/cam.h" 32 | #include "call/quat.h" 33 | #include "call/euler.h" 34 | #include "call/plane.h" 35 | #include "call/noise.h" 36 | #include "call/frustum.h" 37 | #include "call/aabb2d.h" 38 | #include "call/box.h" 39 | #include "call/io.h" 40 | #include "call/project.h" 41 | #include "call/sphere.h" 42 | #include "call/ease.h" 43 | #include "call/curve.h" 44 | #include "call/bezier.h" 45 | #include "call/ray.h" 46 | #include "call/affine2d.h" 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | #endif /* cglm_call_h */ 52 | -------------------------------------------------------------------------------- /include/cglm/call/aabb2d.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_aabb2d_h 9 | #define cglmc_aabb2d_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | /* DEPRECATED! use _diag */ 17 | #define glmc_aabb2d_size(aabb) glmc_aabb2d_diag(aabb) 18 | 19 | CGLM_EXPORT 20 | void 21 | glmc_aabb2d_zero(vec2 aabb[2]); 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_aabb2d_copy(vec2 aabb[2], vec2 dest[2]); 26 | 27 | CGLM_EXPORT 28 | void 29 | glmc_aabb2d_transform(vec2 aabb[2], mat3 m, vec2 dest[2]); 30 | 31 | CGLM_EXPORT 32 | void 33 | glmc_aabb2d_merge(vec2 aabb1[2], vec2 aabb2[2], vec2 dest[2]); 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_aabb2d_crop(vec2 aabb[2], vec2 cropAabb[2], vec2 dest[2]); 38 | 39 | CGLM_EXPORT 40 | void 41 | glmc_aabb2d_crop_until(vec2 aabb[2], 42 | vec2 cropAabb[2], 43 | vec2 clampAabb[2], 44 | vec2 dest[2]); 45 | 46 | CGLM_EXPORT 47 | void 48 | glmc_aabb2d_invalidate(vec2 aabb[2]); 49 | 50 | CGLM_EXPORT 51 | bool 52 | glmc_aabb2d_isvalid(vec2 aabb[2]); 53 | 54 | CGLM_EXPORT 55 | float 56 | glmc_aabb2d_diag(vec2 aabb[2]); 57 | 58 | CGLM_EXPORT 59 | void 60 | glmc_aabb2d_sizev(vec2 aabb[2], vec2 dest); 61 | 62 | CGLM_EXPORT 63 | float 64 | glmc_aabb2d_radius(vec2 aabb[2]); 65 | 66 | CGLM_EXPORT 67 | void 68 | glmc_aabb2d_center(vec2 aabb[2], vec2 dest); 69 | 70 | CGLM_EXPORT 71 | bool 72 | glmc_aabb2d_aabb(vec2 aabb[2], vec2 other[2]); 73 | 74 | CGLM_EXPORT 75 | bool 76 | glmc_aabb2d_point(vec2 aabb[2], vec2 point); 77 | 78 | CGLM_EXPORT 79 | bool 80 | glmc_aabb2d_contains(vec2 aabb[2], vec2 other[2]); 81 | 82 | CGLM_EXPORT 83 | bool 84 | glmc_aabb2d_circle(vec2 aabb[2], vec3 s); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | #endif /* cglmc_aabb2d_h */ 90 | -------------------------------------------------------------------------------- /include/cglm/call/affine2d.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_affine2d_h 9 | #define cglmc_affine2d_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_translate2d_make(mat3 m, vec2 v); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_translate2d_to(mat3 m, vec2 v, mat3 dest); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_translate2d(mat3 m, vec2 v); 27 | 28 | CGLM_EXPORT 29 | void 30 | glmc_translate2d_x(mat3 m, float to); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_translate2d_y(mat3 m, float to); 35 | 36 | CGLM_EXPORT 37 | void 38 | glmc_scale2d_to(mat3 m, vec2 v, mat3 dest); 39 | 40 | CGLM_EXPORT 41 | void 42 | glmc_scale2d_make(mat3 m, vec2 v); 43 | 44 | CGLM_EXPORT 45 | void 46 | glmc_scale2d(mat3 m, vec2 v); 47 | 48 | CGLM_EXPORT 49 | void 50 | glmc_scale2d_uni(mat3 m, float s); 51 | 52 | CGLM_EXPORT 53 | void 54 | glmc_rotate2d_make(mat3 m, float angle); 55 | 56 | CGLM_EXPORT 57 | void 58 | glmc_rotate2d(mat3 m, float angle); 59 | 60 | CGLM_EXPORT 61 | void 62 | glmc_rotate2d_to(mat3 m, float angle, mat3 dest); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | #endif /* cglmc_affine2d_h */ 68 | -------------------------------------------------------------------------------- /include/cglm/call/bezier.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_bezier_h 9 | #define cglmc_bezier_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | float 18 | glmc_bezier(float s, float p0, float c0, float c1, float p1); 19 | 20 | CGLM_EXPORT 21 | float 22 | glmc_hermite(float s, float p0, float t0, float t1, float p1); 23 | 24 | CGLM_EXPORT 25 | float 26 | glmc_decasteljau(float prm, float p0, float c0, float c1, float p1); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | #endif /* cglmc_bezier_h */ 32 | -------------------------------------------------------------------------------- /include/cglm/call/box.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_box_h 9 | #define cglmc_box_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_aabb_merge(vec3 box1[2], vec3 box2[2], vec3 dest[2]); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_aabb_crop(vec3 box[2], vec3 cropBox[2], vec3 dest[2]); 27 | 28 | CGLM_EXPORT 29 | void 30 | glmc_aabb_crop_until(vec3 box[2], 31 | vec3 cropBox[2], 32 | vec3 clampBox[2], 33 | vec3 dest[2]); 34 | 35 | CGLM_EXPORT 36 | bool 37 | glmc_aabb_frustum(vec3 box[2], vec4 planes[6]); 38 | 39 | CGLM_EXPORT 40 | void 41 | glmc_aabb_invalidate(vec3 box[2]); 42 | 43 | CGLM_EXPORT 44 | bool 45 | glmc_aabb_isvalid(vec3 box[2]); 46 | 47 | CGLM_EXPORT 48 | float 49 | glmc_aabb_size(vec3 box[2]); 50 | 51 | CGLM_EXPORT 52 | float 53 | glmc_aabb_radius(vec3 box[2]); 54 | 55 | CGLM_EXPORT 56 | void 57 | glmc_aabb_center(vec3 box[2], vec3 dest); 58 | 59 | CGLM_EXPORT 60 | bool 61 | glmc_aabb_aabb(vec3 box[2], vec3 other[2]); 62 | 63 | CGLM_EXPORT 64 | bool 65 | glmc_aabb_point(vec3 box[2], vec3 point); 66 | 67 | CGLM_EXPORT 68 | bool 69 | glmc_aabb_contains(vec3 box[2], vec3 other[2]); 70 | 71 | CGLM_EXPORT 72 | bool 73 | glmc_aabb_sphere(vec3 box[2], vec4 s); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | #endif /* cglmc_box_h */ 79 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/ortho_lh_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_ortho_lh_no_h 9 | #define cglmc_ortho_lh_no_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_ortho_lh_no(float left, float right, 19 | float bottom, float top, 20 | float nearZ, float farZ, 21 | mat4 dest); 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_ortho_aabb_lh_no(vec3 box[2], mat4 dest); 26 | 27 | CGLM_EXPORT 28 | void 29 | glmc_ortho_aabb_p_lh_no(vec3 box[2], float padding, mat4 dest); 30 | 31 | CGLM_EXPORT 32 | void 33 | glmc_ortho_aabb_pz_lh_no(vec3 box[2], float padding, mat4 dest); 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_ortho_default_lh_no(float aspect, mat4 dest); 38 | 39 | CGLM_EXPORT 40 | void 41 | glmc_ortho_default_s_lh_no(float aspect, float size, mat4 dest); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | #endif /* cglmc_ortho_lh_no_h */ 47 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/ortho_lh_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_ortho_lh_zo_h 9 | #define cglmc_ortho_lh_zo_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_ortho_lh_zo(float left, float right, 19 | float bottom, float top, 20 | float nearZ, float farZ, 21 | mat4 dest); 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_ortho_aabb_lh_zo(vec3 box[2], mat4 dest); 26 | 27 | CGLM_EXPORT 28 | void 29 | glmc_ortho_aabb_p_lh_zo(vec3 box[2], float padding, mat4 dest); 30 | 31 | CGLM_EXPORT 32 | void 33 | glmc_ortho_aabb_pz_lh_zo(vec3 box[2], float padding, mat4 dest); 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_ortho_default_lh_zo(float aspect, mat4 dest); 38 | 39 | CGLM_EXPORT 40 | void 41 | glmc_ortho_default_s_lh_zo(float aspect, float size, mat4 dest); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | #endif /* cglmc_ortho_lh_zo_h */ 47 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/ortho_rh_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_ortho_rh_no_h 9 | #define cglmc_ortho_rh_no_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_ortho_rh_no(float left, float right, 19 | float bottom, float top, 20 | float nearZ, float farZ, 21 | mat4 dest); 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_ortho_aabb_rh_no(vec3 box[2], mat4 dest); 26 | 27 | CGLM_EXPORT 28 | void 29 | glmc_ortho_aabb_p_rh_no(vec3 box[2], float padding, mat4 dest); 30 | 31 | CGLM_EXPORT 32 | void 33 | glmc_ortho_aabb_pz_rh_no(vec3 box[2], float padding, mat4 dest); 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_ortho_default_rh_no(float aspect, mat4 dest); 38 | 39 | CGLM_EXPORT 40 | void 41 | glmc_ortho_default_s_rh_no(float aspect, float size, mat4 dest); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | #endif /* cglmc_ortho_rh_no_h */ 47 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/ortho_rh_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_ortho_rh_zo_h 9 | #define cglmc_ortho_rh_zo_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_ortho_rh_zo(float left, float right, 19 | float bottom, float top, 20 | float nearZ, float farZ, 21 | mat4 dest); 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_ortho_aabb_rh_zo(vec3 box[2], mat4 dest); 26 | 27 | CGLM_EXPORT 28 | void 29 | glmc_ortho_aabb_p_rh_zo(vec3 box[2], float padding, mat4 dest); 30 | 31 | CGLM_EXPORT 32 | void 33 | glmc_ortho_aabb_pz_rh_zo(vec3 box[2], float padding, mat4 dest); 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_ortho_default_rh_zo(float aspect, mat4 dest); 38 | 39 | CGLM_EXPORT 40 | void 41 | glmc_ortho_default_s_rh_zo(float aspect, float size, mat4 dest); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | #endif /* cglmc_ortho_rh_zo_h */ 47 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/persp_lh_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_persp_lh_no_h 9 | #define cglmc_persp_lh_no_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_frustum_lh_no(float left, float right, 19 | float bottom, float top, 20 | float nearZ, float farZ, 21 | mat4 dest); 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_perspective_lh_no(float fovy, 26 | float aspect, 27 | float nearVal, 28 | float farVal, 29 | mat4 dest); 30 | 31 | CGLM_EXPORT 32 | void 33 | glmc_persp_move_far_lh_no(mat4 proj, float deltaFar); 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_persp_decomp_lh_no(mat4 proj, 38 | float * __restrict nearZ, float * __restrict farZ, 39 | float * __restrict top, float * __restrict bottom, 40 | float * __restrict left, float * __restrict right); 41 | 42 | CGLM_EXPORT 43 | void 44 | glmc_persp_decompv_lh_no(mat4 proj, float dest[6]); 45 | 46 | CGLM_EXPORT 47 | void 48 | glmc_persp_decomp_x_lh_no(mat4 proj, 49 | float * __restrict left, 50 | float * __restrict right); 51 | 52 | CGLM_EXPORT 53 | void 54 | glmc_persp_decomp_y_lh_no(mat4 proj, 55 | float * __restrict top, 56 | float * __restrict bottom); 57 | 58 | CGLM_EXPORT 59 | void 60 | glmc_persp_decomp_z_lh_no(mat4 proj, 61 | float * __restrict nearZ, 62 | float * __restrict farZ); 63 | 64 | CGLM_EXPORT 65 | void 66 | glmc_persp_decomp_far_lh_no(mat4 proj, float * __restrict farZ); 67 | 68 | CGLM_EXPORT 69 | void 70 | glmc_persp_decomp_near_lh_no(mat4 proj, float * __restrict nearZ); 71 | 72 | CGLM_EXPORT 73 | void 74 | glmc_persp_sizes_lh_no(mat4 proj, float fovy, vec4 dest); 75 | 76 | CGLM_EXPORT 77 | float 78 | glmc_persp_fovy_lh_no(mat4 proj); 79 | 80 | CGLM_EXPORT 81 | float 82 | glmc_persp_aspect_lh_no(mat4 proj); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | #endif /* cglmc_persp_lh_no_h */ 88 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/persp_lh_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_persp_lh_zo_h 9 | #define cglmc_persp_lh_zo_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_frustum_lh_zo(float left, float right, 19 | float bottom, float top, 20 | float nearZ, float farZ, 21 | mat4 dest); 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_perspective_lh_zo(float fovy, 26 | float aspect, 27 | float nearVal, 28 | float farVal, 29 | mat4 dest); 30 | 31 | CGLM_EXPORT 32 | void 33 | glmc_persp_move_far_lh_zo(mat4 proj, float deltaFar); 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_persp_decomp_lh_zo(mat4 proj, 38 | float * __restrict nearZ, float * __restrict farZ, 39 | float * __restrict top, float * __restrict bottom, 40 | float * __restrict left, float * __restrict right); 41 | 42 | CGLM_EXPORT 43 | void 44 | glmc_persp_decompv_lh_zo(mat4 proj, float dest[6]); 45 | 46 | CGLM_EXPORT 47 | void 48 | glmc_persp_decomp_x_lh_zo(mat4 proj, 49 | float * __restrict left, 50 | float * __restrict right); 51 | 52 | CGLM_EXPORT 53 | void 54 | glmc_persp_decomp_y_lh_zo(mat4 proj, 55 | float * __restrict top, 56 | float * __restrict bottom); 57 | 58 | CGLM_EXPORT 59 | void 60 | glmc_persp_decomp_z_lh_zo(mat4 proj, 61 | float * __restrict nearZ, 62 | float * __restrict farZ); 63 | 64 | CGLM_EXPORT 65 | void 66 | glmc_persp_decomp_far_lh_zo(mat4 proj, float * __restrict farZ); 67 | 68 | CGLM_EXPORT 69 | void 70 | glmc_persp_decomp_near_lh_zo(mat4 proj, float * __restrict nearZ); 71 | 72 | CGLM_EXPORT 73 | void 74 | glmc_persp_sizes_lh_zo(mat4 proj, float fovy, vec4 dest); 75 | 76 | CGLM_EXPORT 77 | float 78 | glmc_persp_fovy_lh_zo(mat4 proj); 79 | 80 | CGLM_EXPORT 81 | float 82 | glmc_persp_aspect_lh_zo(mat4 proj); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | #endif /* cglmc_persp_lh_zo_h */ 88 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/persp_rh_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_persp_rh_no_h 9 | #define cglmc_persp_rh_no_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_frustum_rh_no(float left, float right, 19 | float bottom, float top, 20 | float nearZ, float farZ, 21 | mat4 dest); 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_perspective_rh_no(float fovy, 26 | float aspect, 27 | float nearVal, 28 | float farVal, 29 | mat4 dest); 30 | 31 | CGLM_EXPORT 32 | void 33 | glmc_persp_move_far_rh_no(mat4 proj, float deltaFar); 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_persp_decomp_rh_no(mat4 proj, 38 | float * __restrict nearZ, float * __restrict farZ, 39 | float * __restrict top, float * __restrict bottom, 40 | float * __restrict left, float * __restrict right); 41 | 42 | CGLM_EXPORT 43 | void 44 | glmc_persp_decompv_rh_no(mat4 proj, float dest[6]); 45 | 46 | CGLM_EXPORT 47 | void 48 | glmc_persp_decomp_x_rh_no(mat4 proj, 49 | float * __restrict left, 50 | float * __restrict right); 51 | 52 | CGLM_EXPORT 53 | void 54 | glmc_persp_decomp_y_rh_no(mat4 proj, 55 | float * __restrict top, 56 | float * __restrict bottom); 57 | 58 | CGLM_EXPORT 59 | void 60 | glmc_persp_decomp_z_rh_no(mat4 proj, 61 | float * __restrict nearZ, 62 | float * __restrict farZ); 63 | 64 | CGLM_EXPORT 65 | void 66 | glmc_persp_decomp_far_rh_no(mat4 proj, float * __restrict farZ); 67 | 68 | CGLM_EXPORT 69 | void 70 | glmc_persp_decomp_near_rh_no(mat4 proj, float * __restrict nearZ); 71 | 72 | CGLM_EXPORT 73 | void 74 | glmc_persp_sizes_rh_no(mat4 proj, float fovy, vec4 dest); 75 | 76 | CGLM_EXPORT 77 | float 78 | glmc_persp_fovy_rh_no(mat4 proj); 79 | 80 | CGLM_EXPORT 81 | float 82 | glmc_persp_aspect_rh_no(mat4 proj); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | #endif /* cglmc_persp_rh_no_h */ 88 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/persp_rh_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_persp_rh_zo_h 9 | #define cglmc_persp_rh_zo_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_frustum_rh_zo(float left, float right, 19 | float bottom, float top, 20 | float nearZ, float farZ, 21 | mat4 dest); 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_perspective_rh_zo(float fovy, 26 | float aspect, 27 | float nearVal, 28 | float farVal, 29 | mat4 dest); 30 | 31 | CGLM_EXPORT 32 | void 33 | glmc_persp_move_far_rh_zo(mat4 proj, float deltaFar); 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_persp_decomp_rh_zo(mat4 proj, 38 | float * __restrict nearZ, float * __restrict farZ, 39 | float * __restrict top, float * __restrict bottom, 40 | float * __restrict left, float * __restrict right); 41 | 42 | CGLM_EXPORT 43 | void 44 | glmc_persp_decompv_rh_zo(mat4 proj, float dest[6]); 45 | 46 | CGLM_EXPORT 47 | void 48 | glmc_persp_decomp_x_rh_zo(mat4 proj, 49 | float * __restrict left, 50 | float * __restrict right); 51 | 52 | CGLM_EXPORT 53 | void 54 | glmc_persp_decomp_y_rh_zo(mat4 proj, 55 | float * __restrict top, 56 | float * __restrict bottom); 57 | 58 | CGLM_EXPORT 59 | void 60 | glmc_persp_decomp_z_rh_zo(mat4 proj, 61 | float * __restrict nearZ, 62 | float * __restrict farZ); 63 | 64 | CGLM_EXPORT 65 | void 66 | glmc_persp_decomp_far_rh_zo(mat4 proj, float * __restrict farZ); 67 | 68 | CGLM_EXPORT 69 | void 70 | glmc_persp_decomp_near_rh_zo(mat4 proj, float * __restrict nearZ); 71 | 72 | CGLM_EXPORT 73 | void 74 | glmc_persp_sizes_rh_zo(mat4 proj, float fovy, vec4 dest); 75 | 76 | CGLM_EXPORT 77 | float 78 | glmc_persp_fovy_rh_zo(mat4 proj); 79 | 80 | CGLM_EXPORT 81 | float 82 | glmc_persp_aspect_rh_zo(mat4 proj); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | #endif /* cglmc_persp_rh_zo_h */ 88 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/project_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_project_no_h 9 | #define cglmc_project_no_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_unprojecti_no(vec3 pos, mat4 invMat, vec4 vp, vec3 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest); 23 | 24 | CGLM_EXPORT 25 | float 26 | glmc_project_z_no(vec3 pos, mat4 m); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | #endif /* cglmc_project_no_h */ 32 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/project_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_project_zo_h 9 | #define cglmc_project_zo_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_unprojecti_zo(vec3 pos, mat4 invMat, vec4 vp, vec3 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_project_zo(vec3 pos, mat4 m, vec4 vp, vec3 dest); 23 | 24 | CGLM_EXPORT 25 | float 26 | glmc_project_z_zo(vec3 pos, mat4 m); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | #endif /* cglmc_project_zo_h */ 32 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/view_lh_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_view_lh_no_h 9 | #define cglmc_view_lh_no_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_lookat_lh_no(vec3 eye, vec3 center, vec3 up, mat4 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_look_lh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_look_anyup_lh_no(vec3 eye, vec3 dir, mat4 dest); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | #endif /* cglmc_view_lh_no_h */ 32 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/view_lh_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_view_lh_zo_h 9 | #define cglmc_view_lh_zo_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_lookat_lh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_look_lh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_look_anyup_lh_zo(vec3 eye, vec3 dir, mat4 dest); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | #endif /* cglmc_view_lh_zo_h */ 32 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/view_rh_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_view_rh_no_h 9 | #define cglmc_view_rh_no_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_lookat_rh_no(vec3 eye, vec3 center, vec3 up, mat4 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_look_rh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_look_anyup_rh_no(vec3 eye, vec3 dir, mat4 dest); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | #endif /* cglmc_view_rh_no_h */ 32 | -------------------------------------------------------------------------------- /include/cglm/call/clipspace/view_rh_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_view_rh_zo_h 9 | #define cglmc_view_rh_zo_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_lookat_rh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_look_rh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_look_anyup_rh_zo(vec3 eye, vec3 dir, mat4 dest); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | #endif /* cglmc_view_rh_zo_h */ 32 | -------------------------------------------------------------------------------- /include/cglm/call/curve.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_curve_h 9 | #define cglmc_curve_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | float 18 | glmc_smc(float s, mat4 m, vec4 c); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | #endif /* cglmc_curve_h */ 24 | -------------------------------------------------------------------------------- /include/cglm/call/ease.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_ease_h 9 | #define cglmc_ease_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | float 18 | glmc_ease_linear(float t); 19 | 20 | CGLM_EXPORT 21 | float 22 | glmc_ease_sine_in(float t); 23 | 24 | CGLM_EXPORT 25 | float 26 | glmc_ease_sine_out(float t); 27 | 28 | CGLM_EXPORT 29 | float 30 | glmc_ease_sine_inout(float t); 31 | 32 | CGLM_EXPORT 33 | float 34 | glmc_ease_quad_in(float t); 35 | 36 | CGLM_EXPORT 37 | float 38 | glmc_ease_quad_out(float t); 39 | 40 | CGLM_EXPORT 41 | float 42 | glmc_ease_quad_inout(float t); 43 | 44 | CGLM_EXPORT 45 | float 46 | glmc_ease_cubic_in(float t); 47 | 48 | CGLM_EXPORT 49 | float 50 | glmc_ease_cubic_out(float t); 51 | 52 | CGLM_EXPORT 53 | float 54 | glmc_ease_cubic_inout(float t); 55 | 56 | CGLM_EXPORT 57 | float 58 | glmc_ease_quart_in(float t); 59 | 60 | CGLM_EXPORT 61 | float 62 | glmc_ease_quart_out(float t); 63 | 64 | CGLM_EXPORT 65 | float 66 | glmc_ease_quart_inout(float t); 67 | 68 | CGLM_EXPORT 69 | float 70 | glmc_ease_quint_in(float t); 71 | 72 | CGLM_EXPORT 73 | float 74 | glmc_ease_quint_out(float t); 75 | 76 | CGLM_EXPORT 77 | float 78 | glmc_ease_quint_inout(float t); 79 | 80 | CGLM_EXPORT 81 | float 82 | glmc_ease_exp_in(float t); 83 | 84 | CGLM_EXPORT 85 | float 86 | glmc_ease_exp_out(float t); 87 | 88 | CGLM_EXPORT 89 | float 90 | glmc_ease_exp_inout(float t); 91 | 92 | CGLM_EXPORT 93 | float 94 | glmc_ease_circ_in(float t); 95 | 96 | CGLM_EXPORT 97 | float 98 | glmc_ease_circ_out(float t); 99 | 100 | CGLM_EXPORT 101 | float 102 | glmc_ease_circ_inout(float t); 103 | 104 | CGLM_EXPORT 105 | float 106 | glmc_ease_back_in(float t); 107 | 108 | CGLM_EXPORT 109 | float 110 | glmc_ease_back_out(float t); 111 | 112 | CGLM_EXPORT 113 | float 114 | glmc_ease_back_inout(float t); 115 | 116 | CGLM_EXPORT 117 | float 118 | glmc_ease_elast_in(float t); 119 | 120 | CGLM_EXPORT 121 | float 122 | glmc_ease_elast_out(float t); 123 | 124 | CGLM_EXPORT 125 | float 126 | glmc_ease_elast_inout(float t); 127 | 128 | CGLM_EXPORT 129 | float 130 | glmc_ease_bounce_out(float t); 131 | 132 | CGLM_EXPORT 133 | float 134 | glmc_ease_bounce_in(float t); 135 | 136 | CGLM_EXPORT 137 | float 138 | glmc_ease_bounce_inout(float t); 139 | 140 | #ifdef __cplusplus 141 | } 142 | #endif 143 | #endif /* cglmc_ease_h */ 144 | -------------------------------------------------------------------------------- /include/cglm/call/euler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_euler_h 9 | #define cglmc_euler_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_euler_angles(mat4 m, vec3 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_euler(vec3 angles, mat4 dest); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_euler_xyz(vec3 angles, mat4 dest); 27 | 28 | CGLM_EXPORT 29 | void 30 | glmc_euler_zyx(vec3 angles, mat4 dest); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_euler_zxy(vec3 angles, mat4 dest); 35 | 36 | CGLM_EXPORT 37 | void 38 | glmc_euler_xzy(vec3 angles, mat4 dest); 39 | 40 | CGLM_EXPORT 41 | void 42 | glmc_euler_yzx(vec3 angles, mat4 dest); 43 | 44 | CGLM_EXPORT 45 | void 46 | glmc_euler_yxz(vec3 angles, mat4 dest); 47 | 48 | CGLM_EXPORT 49 | void 50 | glmc_euler_by_order(vec3 angles, glm_euler_seq axis, mat4 dest); 51 | 52 | CGLM_EXPORT 53 | void 54 | glmc_euler_xyz_quat(vec3 angles, versor dest); 55 | 56 | CGLM_EXPORT 57 | void 58 | glmc_euler_xzy_quat(vec3 angles, versor dest); 59 | 60 | CGLM_EXPORT 61 | void 62 | glmc_euler_yxz_quat(vec3 angles, versor dest); 63 | 64 | CGLM_EXPORT 65 | void 66 | glmc_euler_yzx_quat(vec3 angles, versor dest); 67 | 68 | CGLM_EXPORT 69 | void 70 | glmc_euler_zxy_quat(vec3 angles, versor dest); 71 | 72 | CGLM_EXPORT 73 | void 74 | glmc_euler_zyx_quat(vec3 angles, versor dest); 75 | 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | #endif /* cglmc_euler_h */ 81 | -------------------------------------------------------------------------------- /include/cglm/call/frustum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_frustum_h 9 | #define cglmc_frustum_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_frustum_planes(mat4 m, vec4 dest[6]); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_frustum_corners(mat4 invMat, vec4 dest[8]); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_frustum_center(vec4 corners[8], vec4 dest); 27 | 28 | CGLM_EXPORT 29 | void 30 | glmc_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_frustum_corners_at(vec4 corners[8], 35 | float splitDist, 36 | float farDist, 37 | vec4 planeCorners[4]); 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | #endif /* cglmc_frustum_h */ 42 | -------------------------------------------------------------------------------- /include/cglm/call/io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_io_h 9 | #define cglmc_io_h 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include "../cglm.h" 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_mat4_print(mat4 matrix, 20 | FILE * __restrict ostream); 21 | 22 | CGLM_EXPORT 23 | void 24 | glmc_mat3_print(mat3 matrix, 25 | FILE * __restrict ostream); 26 | 27 | CGLM_EXPORT 28 | void 29 | glmc_vec4_print(vec4 vec, 30 | FILE * __restrict ostream); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_vec3_print(vec3 vec, 35 | FILE * __restrict ostream); 36 | 37 | CGLM_EXPORT 38 | void 39 | glmc_versor_print(versor vec, 40 | FILE * __restrict ostream); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | #endif /* cglmc_io_h */ 46 | -------------------------------------------------------------------------------- /include/cglm/call/mat2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_mat2_h 9 | #define cglmc_mat2_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_mat2_make(const float * __restrict src, mat2 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_mat2_copy(mat2 mat, mat2 dest); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_mat2_identity(mat2 m); 27 | 28 | CGLM_EXPORT 29 | void 30 | glmc_mat2_identity_array(mat2 * __restrict mats, size_t count); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_mat2_zero(mat2 m); 35 | 36 | CGLM_EXPORT 37 | void 38 | glmc_mat2_mul(mat2 m1, mat2 m2, mat2 dest); 39 | 40 | CGLM_EXPORT 41 | void 42 | glmc_mat2_mulv(mat2 m, vec2 v, vec2 dest); 43 | 44 | CGLM_EXPORT 45 | void 46 | glmc_mat2_transpose_to(mat2 mat, mat2 dest); 47 | 48 | CGLM_EXPORT 49 | void 50 | glmc_mat2_transpose(mat2 m); 51 | 52 | CGLM_EXPORT 53 | void 54 | glmc_mat2_scale(mat2 m, float s); 55 | 56 | CGLM_EXPORT 57 | void 58 | glmc_mat2_inv(mat2 mat, mat2 dest); 59 | 60 | CGLM_EXPORT 61 | void 62 | glmc_mat2_swap_col(mat2 mat, int col1, int col2); 63 | 64 | CGLM_EXPORT 65 | void 66 | glmc_mat2_swap_row(mat2 mat, int row1, int row2); 67 | 68 | CGLM_EXPORT 69 | float 70 | glmc_mat2_trace(mat2 m); 71 | 72 | CGLM_EXPORT 73 | float 74 | glmc_mat2_det(mat2 m); 75 | 76 | CGLM_EXPORT 77 | float 78 | glmc_mat2_rmc(vec2 r, mat2 m, vec2 c); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | #endif /* cglmc_mat2_h */ 84 | -------------------------------------------------------------------------------- /include/cglm/call/mat2x3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_mat2x3_h 9 | #define cglmc_mat2x3_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_mat2x3_copy(mat2x3 src, mat2x3 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_mat2x3_zero(mat2x3 m); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_mat2x3_make(const float * __restrict src, mat2x3 dest); 27 | 28 | CGLM_EXPORT 29 | void 30 | glmc_mat2x3_mul(mat2x3 m1, mat3x2 m2, mat3 dest); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_mat2x3_mulv(mat2x3 m, vec2 v, vec3 dest); 35 | 36 | CGLM_EXPORT 37 | void 38 | glmc_mat2x3_transpose(mat2x3 src, mat3x2 dest); 39 | 40 | CGLM_EXPORT 41 | void 42 | glmc_mat2x3_scale(mat2x3 m, float s); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /* cglmc_mat2x3_h */ 48 | -------------------------------------------------------------------------------- /include/cglm/call/mat2x4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_mat2x4_h 9 | #define cglmc_mat2x4_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_mat2x4_copy(mat2x4 src, mat2x4 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_mat2x4_zero(mat2x4 m); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_mat2x4_make(const float * __restrict src, mat2x4 dest); 27 | 28 | CGLM_EXPORT 29 | void 30 | glmc_mat2x4_mul(mat2x4 m1, mat4x2 m2, mat4 dest); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_mat2x4_mulv(mat2x4 m, vec2 v, vec4 dest); 35 | 36 | CGLM_EXPORT 37 | void 38 | glmc_mat2x4_transpose(mat2x4 src, mat4x2 dest); 39 | 40 | CGLM_EXPORT 41 | void 42 | glmc_mat2x4_scale(mat2x4 m, float s); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /* cglmc_mat2x4_h */ 48 | -------------------------------------------------------------------------------- /include/cglm/call/mat3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_mat3_h 9 | #define cglmc_mat3_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | /* DEPRECATED! use _copy, _ucopy versions */ 17 | #define glmc_mat3_dup(mat, dest) glmc_mat3_copy(mat, dest) 18 | 19 | CGLM_EXPORT 20 | void 21 | glmc_mat3_copy(mat3 mat, mat3 dest); 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_mat3_identity(mat3 mat); 26 | 27 | CGLM_EXPORT 28 | void 29 | glmc_mat3_zero(mat3 mat); 30 | 31 | CGLM_EXPORT 32 | void 33 | glmc_mat3_identity_array(mat3 * __restrict mat, size_t count); 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest); 38 | 39 | CGLM_EXPORT 40 | void 41 | glmc_mat3_transpose_to(mat3 m, mat3 dest); 42 | 43 | CGLM_EXPORT 44 | void 45 | glmc_mat3_transpose(mat3 m); 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest); 50 | 51 | CGLM_EXPORT 52 | float 53 | glmc_mat3_trace(mat3 m); 54 | 55 | CGLM_EXPORT 56 | void 57 | glmc_mat3_quat(mat3 m, versor dest); 58 | 59 | CGLM_EXPORT 60 | void 61 | glmc_mat3_scale(mat3 m, float s); 62 | 63 | CGLM_EXPORT 64 | float 65 | glmc_mat3_det(mat3 mat); 66 | 67 | CGLM_EXPORT 68 | void 69 | glmc_mat3_inv(mat3 mat, mat3 dest); 70 | 71 | CGLM_EXPORT 72 | void 73 | glmc_mat3_swap_col(mat3 mat, int col1, int col2); 74 | 75 | CGLM_EXPORT 76 | void 77 | glmc_mat3_swap_row(mat3 mat, int row1, int row2); 78 | 79 | CGLM_EXPORT 80 | float 81 | glmc_mat3_rmc(vec3 r, mat3 m, vec3 c); 82 | 83 | CGLM_EXPORT 84 | void 85 | glmc_mat3_make(const float * __restrict src, mat3 dest); 86 | 87 | CGLM_EXPORT 88 | void 89 | glmc_mat3_textrans(float sx, float sy, float rot, float tx, float ty, mat3 dest); 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | #endif /* cglmc_mat3_h */ 95 | -------------------------------------------------------------------------------- /include/cglm/call/mat3x2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_mat3x2_h 9 | #define cglmc_mat3x2_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_mat3x2_copy(mat3x2 src, mat3x2 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_mat3x2_zero(mat3x2 m); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_mat3x2_make(const float * __restrict src, mat3x2 dest); 27 | 28 | CGLM_EXPORT 29 | void 30 | glmc_mat3x2_mul(mat3x2 m1, mat2x3 m2, mat2 dest); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_mat3x2_mulv(mat3x2 m, vec3 v, vec2 dest); 35 | 36 | CGLM_EXPORT 37 | void 38 | glmc_mat3x2_transpose(mat3x2 src, mat2x3 dest); 39 | 40 | CGLM_EXPORT 41 | void 42 | glmc_mat3x2_scale(mat3x2 m, float s); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /* cglmc_mat3x2_h */ 48 | -------------------------------------------------------------------------------- /include/cglm/call/mat3x4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_mat3x4_h 9 | #define cglmc_mat3x4_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_mat3x4_copy(mat3x4 src, mat3x4 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_mat3x4_zero(mat3x4 m); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_mat3x4_make(const float * __restrict src, mat3x4 dest); 27 | 28 | CGLM_EXPORT 29 | void 30 | glmc_mat3x4_mul(mat3x4 m1, mat4x3 m2, mat4 dest); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_mat3x4_mulv(mat3x4 m, vec3 v, vec4 dest); 35 | 36 | CGLM_EXPORT 37 | void 38 | glmc_mat3x4_transpose(mat3x4 src, mat4x3 dest); 39 | 40 | CGLM_EXPORT 41 | void 42 | glmc_mat3x4_scale(mat3x4 m, float s); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /* cglmc_mat3x4_h */ 48 | -------------------------------------------------------------------------------- /include/cglm/call/mat4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_mat_h 9 | #define cglmc_mat_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | /* DEPRECATED! use _copy, _ucopy versions */ 17 | #define glmc_mat4_udup(mat, dest) glmc_mat4_ucopy(mat, dest) 18 | #define glmc_mat4_dup(mat, dest) glmc_mat4_copy(mat, dest) 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_mat4_ucopy(mat4 mat, mat4 dest); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_mat4_copy(mat4 mat, mat4 dest); 27 | 28 | CGLM_EXPORT 29 | void 30 | glmc_mat4_identity(mat4 mat); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_mat4_identity_array(mat4 * __restrict mat, size_t count); 35 | 36 | CGLM_EXPORT 37 | void 38 | glmc_mat4_zero(mat4 mat); 39 | 40 | CGLM_EXPORT 41 | void 42 | glmc_mat4_pick3(mat4 mat, mat3 dest); 43 | 44 | CGLM_EXPORT 45 | void 46 | glmc_mat4_pick3t(mat4 mat, mat3 dest); 47 | 48 | CGLM_EXPORT 49 | void 50 | glmc_mat4_ins3(mat3 mat, mat4 dest); 51 | 52 | CGLM_EXPORT 53 | void 54 | glmc_mat4_mul(mat4 m1, mat4 m2, mat4 dest); 55 | 56 | CGLM_EXPORT 57 | void 58 | glmc_mat4_mulN(mat4 * __restrict matrices[], uint32_t len, mat4 dest); 59 | 60 | CGLM_EXPORT 61 | void 62 | glmc_mat4_mulv(mat4 m, vec4 v, vec4 dest); 63 | 64 | CGLM_EXPORT 65 | void 66 | glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest); 67 | 68 | CGLM_EXPORT 69 | float 70 | glmc_mat4_trace(mat4 m); 71 | 72 | CGLM_EXPORT 73 | float 74 | glmc_mat4_trace3(mat4 m); 75 | 76 | CGLM_EXPORT 77 | void 78 | glmc_mat4_quat(mat4 m, versor dest); 79 | 80 | CGLM_EXPORT 81 | void 82 | glmc_mat4_transpose_to(mat4 m, mat4 dest); 83 | 84 | CGLM_EXPORT 85 | void 86 | glmc_mat4_transpose(mat4 m); 87 | 88 | CGLM_EXPORT 89 | void 90 | glmc_mat4_scale_p(mat4 m, float s); 91 | 92 | CGLM_EXPORT 93 | void 94 | glmc_mat4_scale(mat4 m, float s); 95 | 96 | CGLM_EXPORT 97 | float 98 | glmc_mat4_det(mat4 mat); 99 | 100 | CGLM_EXPORT 101 | void 102 | glmc_mat4_inv(mat4 mat, mat4 dest); 103 | 104 | CGLM_EXPORT 105 | void 106 | glmc_mat4_inv_precise(mat4 mat, mat4 dest); 107 | 108 | CGLM_EXPORT 109 | void 110 | glmc_mat4_inv_fast(mat4 mat, mat4 dest); 111 | 112 | CGLM_EXPORT 113 | void 114 | glmc_mat4_swap_col(mat4 mat, int col1, int col2); 115 | 116 | CGLM_EXPORT 117 | void 118 | glmc_mat4_swap_row(mat4 mat, int row1, int row2); 119 | 120 | CGLM_EXPORT 121 | float 122 | glmc_mat4_rmc(vec4 r, mat4 m, vec4 c); 123 | 124 | CGLM_EXPORT 125 | void 126 | glmc_mat4_make(const float * __restrict src, mat4 dest); 127 | 128 | CGLM_EXPORT 129 | void 130 | glmc_mat4_textrans(float sx, float sy, float rot, float tx, float ty, mat4 dest); 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | #endif /* cglmc_mat_h */ 136 | -------------------------------------------------------------------------------- /include/cglm/call/mat4x2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_mat4x2_h 9 | #define cglmc_mat4x2_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_mat4x2_copy(mat4x2 src, mat4x2 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_mat4x2_zero(mat4x2 m); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_mat4x2_make(const float * __restrict src, mat4x2 dest); 27 | 28 | CGLM_EXPORT 29 | void 30 | glmc_mat4x2_mul(mat4x2 m1, mat2x4 m2, mat2 dest); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_mat4x2_mulv(mat4x2 m, vec4 v, vec2 dest); 35 | 36 | CGLM_EXPORT 37 | void 38 | glmc_mat4x2_transpose(mat4x2 src, mat2x4 dest); 39 | 40 | CGLM_EXPORT 41 | void 42 | glmc_mat4x2_scale(mat4x2 m, float s); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /* cglmc_mat4x2_h */ 48 | -------------------------------------------------------------------------------- /include/cglm/call/mat4x3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_mat4x3_h 9 | #define cglmc_mat4x3_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_mat4x3_copy(mat4x3 src, mat4x3 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_mat4x3_zero(mat4x3 m); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_mat4x3_make(const float * __restrict src, mat4x3 dest); 27 | 28 | CGLM_EXPORT 29 | void 30 | glmc_mat4x3_mul(mat4x3 m1, mat3x4 m2, mat3 dest); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_mat4x3_mulv(mat4x3 m, vec4 v, vec3 dest); 35 | 36 | CGLM_EXPORT 37 | void 38 | glmc_mat4x3_transpose(mat4x3 src, mat3x4 dest); 39 | 40 | CGLM_EXPORT 41 | void 42 | glmc_mat4x3_scale(mat4x3 m, float s); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /* cglmc_mat4x3_h */ 48 | -------------------------------------------------------------------------------- /include/cglm/call/noise.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_noise_h 9 | #define cglmc_noise_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | float 18 | glmc_perlin_vec4(vec4 point); 19 | 20 | CGLM_EXPORT 21 | float 22 | glmc_perlin_vec3(vec3 point); 23 | 24 | CGLM_EXPORT 25 | float 26 | glmc_perlin_vec2(vec2 point); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | #endif /* cglmc_noise_h */ 32 | -------------------------------------------------------------------------------- /include/cglm/call/plane.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_plane_h 9 | #define cglmc_plane_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_plane_normalize(vec4 plane); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | #endif /* cglmc_plane_h */ 24 | -------------------------------------------------------------------------------- /include/cglm/call/project.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_project_h 9 | #define cglmc_project_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | void 18 | glmc_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest); 27 | 28 | CGLM_EXPORT 29 | float 30 | glmc_project_z(vec3 pos, mat4 m); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_pickmatrix(vec2 center, vec2 size, vec4 vp, mat4 dest); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | #endif /* cglmc_project_h */ 40 | -------------------------------------------------------------------------------- /include/cglm/call/ray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_ray_h 9 | #define cglmc_ray_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | #include "../cglm.h" 14 | 15 | CGLM_EXPORT 16 | bool 17 | glmc_ray_triangle(vec3 origin, 18 | vec3 direction, 19 | vec3 v0, 20 | vec3 v1, 21 | vec3 v2, 22 | float *d); 23 | 24 | CGLM_EXPORT 25 | bool 26 | glmc_ray_sphere(vec3 origin, 27 | vec3 dir, 28 | vec4 s, 29 | float * __restrict t1, 30 | float * __restrict t2); 31 | 32 | CGLM_EXPORT 33 | void 34 | glmc_ray_at(vec3 orig, vec3 dir, float t, vec3 point); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | #endif /* cglmc_ray_h */ 40 | -------------------------------------------------------------------------------- /include/cglm/call/sphere.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglmc_sphere_h 9 | #define cglmc_sphere_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "../cglm.h" 15 | 16 | CGLM_EXPORT 17 | float 18 | glmc_sphere_radii(vec4 s); 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_sphere_transform(vec4 s, mat4 m, vec4 dest); 23 | 24 | CGLM_EXPORT 25 | void 26 | glmc_sphere_merge(vec4 s1, vec4 s2, vec4 dest); 27 | 28 | CGLM_EXPORT 29 | bool 30 | glmc_sphere_sphere(vec4 s1, vec4 s2); 31 | 32 | CGLM_EXPORT 33 | bool 34 | glmc_sphere_point(vec4 s, vec3 point); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | #endif /* cglmc_sphere_h */ 40 | -------------------------------------------------------------------------------- /include/cglm/cglm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_h 9 | #define cglm_h 10 | 11 | #include "common.h" 12 | #include "vec2.h" 13 | #include "vec3.h" 14 | #include "vec4.h" 15 | #include "ivec2.h" 16 | #include "ivec3.h" 17 | #include "ivec4.h" 18 | #include "mat4.h" 19 | #include "mat4x2.h" 20 | #include "mat4x3.h" 21 | #include "mat3.h" 22 | #include "mat3x2.h" 23 | #include "mat3x4.h" 24 | #include "mat2.h" 25 | #include "mat2x3.h" 26 | #include "mat2x4.h" 27 | #include "affine.h" 28 | #include "cam.h" 29 | #include "frustum.h" 30 | #include "quat.h" 31 | #include "euler.h" 32 | #include "plane.h" 33 | #include "noise.h" 34 | #include "aabb2d.h" 35 | #include "box.h" 36 | #include "color.h" 37 | #include "util.h" 38 | #include "io.h" 39 | #include "project.h" 40 | #include "sphere.h" 41 | #include "ease.h" 42 | #include "curve.h" 43 | #include "bezier.h" 44 | #include "ray.h" 45 | #include "affine2d.h" 46 | #include "affine2d-post.h" 47 | 48 | #endif /* cglm_h */ 49 | -------------------------------------------------------------------------------- /include/cglm/clipspace/persp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* 9 | Functions: 10 | CGLM_INLINE void glm_persp_decomp_far(mat4 proj, float *farZ) 11 | CGLM_INLINE float glm_persp_fovy(mat4 proj) 12 | CGLM_INLINE float glm_persp_aspect(mat4 proj) 13 | CGLM_INLINE void glm_persp_sizes(mat4 proj, float fovy, vec4 dest) 14 | */ 15 | 16 | #ifndef cglm_persp_h 17 | #define cglm_persp_h 18 | 19 | #include "../common.h" 20 | #include "../plane.h" 21 | #include "../mat4.h" 22 | 23 | /*! 24 | * @brief returns field of view angle along the Y-axis (in radians) 25 | * 26 | * if you need to degrees, use glm_deg to convert it or use this: 27 | * fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) 28 | * 29 | * @param[in] proj perspective projection matrix 30 | */ 31 | CGLM_INLINE 32 | float 33 | glm_persp_fovy(mat4 proj) { 34 | return 2.0f * atanf(1.0f / proj[1][1]); 35 | } 36 | 37 | /*! 38 | * @brief returns aspect ratio of perspective projection 39 | * 40 | * @param[in] proj perspective projection matrix 41 | */ 42 | CGLM_INLINE 43 | float 44 | glm_persp_aspect(mat4 proj) { 45 | return proj[1][1] / proj[0][0]; 46 | } 47 | 48 | #endif /* cglm_persp_h */ 49 | -------------------------------------------------------------------------------- /include/cglm/clipspace/view_lh_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* 9 | Functions: 10 | CGLM_INLINE void glm_lookat_lh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) 11 | CGLM_INLINE void glm_look_lh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) 12 | CGLM_INLINE void glm_look_anyup_lh_no(vec3 eye, vec3 dir, mat4 dest) 13 | */ 14 | 15 | #ifndef cglm_view_lh_no_h 16 | #define cglm_view_lh_no_h 17 | 18 | #include "../common.h" 19 | #include "view_lh.h" 20 | 21 | /*! 22 | * @brief set up view matrix with left handed coordinate system. 23 | * 24 | * NOTE: The UP vector must not be parallel to the line of sight from 25 | * the eye point to the reference point 26 | * 27 | * @param[in] eye eye vector 28 | * @param[in] center center vector 29 | * @param[in] up up vector 30 | * @param[out] dest result matrix 31 | */ 32 | CGLM_INLINE 33 | void 34 | glm_lookat_lh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) { 35 | glm_lookat_lh(eye, center, up, dest); 36 | } 37 | 38 | /*! 39 | * @brief set up view matrix with left handed coordinate system. 40 | * 41 | * convenient wrapper for lookat: if you only have direction not target self 42 | * then this might be useful. Because you need to get target from direction. 43 | * 44 | * NOTE: The UP vector must not be parallel to the line of sight from 45 | * the eye point to the reference point 46 | * 47 | * @param[in] eye eye vector 48 | * @param[in] dir direction vector 49 | * @param[in] up up vector 50 | * @param[out] dest result matrix 51 | */ 52 | CGLM_INLINE 53 | void 54 | glm_look_lh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) { 55 | glm_look_lh(eye, dir, up, dest); 56 | } 57 | 58 | /*! 59 | * @brief set up view matrix with left handed coordinate system. 60 | * 61 | * convenient wrapper for look: if you only have direction and if you don't 62 | * care what UP vector is then this might be useful to create view matrix 63 | * 64 | * @param[in] eye eye vector 65 | * @param[in] dir direction vector 66 | * @param[out] dest result matrix 67 | */ 68 | CGLM_INLINE 69 | void 70 | glm_look_anyup_lh_no(vec3 eye, vec3 dir, mat4 dest) { 71 | glm_look_anyup_lh(eye, dir, dest); 72 | } 73 | 74 | #endif /*cglm_view_lh_no_h*/ 75 | -------------------------------------------------------------------------------- /include/cglm/clipspace/view_lh_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* 9 | Functions: 10 | CGLM_INLINE void glm_lookat_lh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) 11 | CGLM_INLINE void glm_look_lh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) 12 | CGLM_INLINE void glm_look_anyup_lh_zo(vec3 eye, vec3 dir, mat4 dest) 13 | */ 14 | 15 | #ifndef cglm_view_lh_zo_h 16 | #define cglm_view_lh_zo_h 17 | 18 | #include "../common.h" 19 | #include "view_lh.h" 20 | 21 | /*! 22 | * @brief set up view matrix with left handed coordinate system. 23 | * 24 | * NOTE: The UP vector must not be parallel to the line of sight from 25 | * the eye point to the reference point 26 | * 27 | * @param[in] eye eye vector 28 | * @param[in] center center vector 29 | * @param[in] up up vector 30 | * @param[out] dest result matrix 31 | */ 32 | CGLM_INLINE 33 | void 34 | glm_lookat_lh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) { 35 | glm_lookat_lh(eye, center, up, dest); 36 | } 37 | 38 | /*! 39 | * @brief set up view matrix with left handed coordinate system. 40 | * 41 | * convenient wrapper for lookat: if you only have direction not target self 42 | * then this might be useful. Because you need to get target from direction. 43 | * 44 | * NOTE: The UP vector must not be parallel to the line of sight from 45 | * the eye point to the reference point 46 | * 47 | * @param[in] eye eye vector 48 | * @param[in] dir direction vector 49 | * @param[in] up up vector 50 | * @param[out] dest result matrix 51 | */ 52 | CGLM_INLINE 53 | void 54 | glm_look_lh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) { 55 | glm_look_lh(eye, dir, up, dest); 56 | } 57 | 58 | /*! 59 | * @brief set up view matrix with left handed coordinate system. 60 | * 61 | * convenient wrapper for look: if you only have direction and if you don't 62 | * care what UP vector is then this might be useful to create view matrix 63 | * 64 | * @param[in] eye eye vector 65 | * @param[in] dir direction vector 66 | * @param[out] dest result matrix 67 | */ 68 | CGLM_INLINE 69 | void 70 | glm_look_anyup_lh_zo(vec3 eye, vec3 dir, mat4 dest) { 71 | glm_look_anyup_lh(eye, dir, dest); 72 | } 73 | 74 | #endif /*cglm_view_lh_zo_h*/ 75 | -------------------------------------------------------------------------------- /include/cglm/clipspace/view_rh_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* 9 | Functions: 10 | CGLM_INLINE void glm_lookat_rh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) 11 | CGLM_INLINE void glm_look_rh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) 12 | CGLM_INLINE void glm_look_anyup_rh_no(vec3 eye, vec3 dir, mat4 dest) 13 | */ 14 | 15 | #ifndef cglm_view_rh_no_h 16 | #define cglm_view_rh_no_h 17 | 18 | #include "../common.h" 19 | #include "view_rh.h" 20 | 21 | /*! 22 | * @brief set up view matrix with right handed coordinate system. 23 | * 24 | * NOTE: The UP vector must not be parallel to the line of sight from 25 | * the eye point to the reference point 26 | * 27 | * @param[in] eye eye vector 28 | * @param[in] center center vector 29 | * @param[in] up up vector 30 | * @param[out] dest result matrix 31 | */ 32 | CGLM_INLINE 33 | void 34 | glm_lookat_rh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) { 35 | glm_lookat_rh(eye, center, up, dest); 36 | } 37 | 38 | /*! 39 | * @brief set up view matrix with right handed coordinate system. 40 | * 41 | * convenient wrapper for lookat: if you only have direction not target self 42 | * then this might be useful. Because you need to get target from direction. 43 | * 44 | * NOTE: The UP vector must not be parallel to the line of sight from 45 | * the eye point to the reference point 46 | * 47 | * @param[in] eye eye vector 48 | * @param[in] dir direction vector 49 | * @param[in] up up vector 50 | * @param[out] dest result matrix 51 | */ 52 | CGLM_INLINE 53 | void 54 | glm_look_rh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) { 55 | glm_look_rh(eye, dir, up, dest); 56 | } 57 | 58 | /*! 59 | * @brief set up view matrix with right handed coordinate system. 60 | * 61 | * convenient wrapper for look: if you only have direction and if you don't 62 | * care what UP vector is then this might be useful to create view matrix 63 | * 64 | * @param[in] eye eye vector 65 | * @param[in] dir direction vector 66 | * @param[out] dest result matrix 67 | */ 68 | CGLM_INLINE 69 | void 70 | glm_look_anyup_rh_no(vec3 eye, vec3 dir, mat4 dest) { 71 | glm_look_anyup_rh(eye, dir, dest); 72 | } 73 | 74 | #endif /*cglm_view_rh_no_h*/ 75 | -------------------------------------------------------------------------------- /include/cglm/clipspace/view_rh_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* 9 | Functions: 10 | CGLM_INLINE void glm_lookat_rh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) 11 | CGLM_INLINE void glm_look_rh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) 12 | CGLM_INLINE void glm_look_anyup_rh_zo(vec3 eye, vec3 dir, mat4 dest) 13 | */ 14 | 15 | #ifndef cglm_view_rh_zo_h 16 | #define cglm_view_rh_zo_h 17 | 18 | #include "../common.h" 19 | #include "view_rh.h" 20 | 21 | /*! 22 | * @brief set up view matrix with right handed coordinate system. 23 | * 24 | * NOTE: The UP vector must not be parallel to the line of sight from 25 | * the eye point to the reference point 26 | * 27 | * @param[in] eye eye vector 28 | * @param[in] center center vector 29 | * @param[in] up up vector 30 | * @param[out] dest result matrix 31 | */ 32 | CGLM_INLINE 33 | void 34 | glm_lookat_rh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) { 35 | glm_lookat_rh(eye, center, up, dest); 36 | } 37 | 38 | /*! 39 | * @brief set up view matrix with right handed coordinate system. 40 | * 41 | * convenient wrapper for lookat: if you only have direction not target self 42 | * then this might be useful. Because you need to get target from direction. 43 | * 44 | * NOTE: The UP vector must not be parallel to the line of sight from 45 | * the eye point to the reference point 46 | * 47 | * @param[in] eye eye vector 48 | * @param[in] dir direction vector 49 | * @param[in] up up vector 50 | * @param[out] dest result matrix 51 | */ 52 | CGLM_INLINE 53 | void 54 | glm_look_rh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) { 55 | glm_look_rh(eye, dir, up, dest); 56 | } 57 | 58 | /*! 59 | * @brief set up view matrix with right handed coordinate system. 60 | * 61 | * convenient wrapper for look: if you only have direction and if you don't 62 | * care what UP vector is then this might be useful to create view matrix 63 | * 64 | * @param[in] eye eye vector 65 | * @param[in] dir direction vector 66 | * @param[out] dest result matrix 67 | */ 68 | CGLM_INLINE 69 | void 70 | glm_look_anyup_rh_zo(vec3 eye, vec3 dir, mat4 dest) { 71 | glm_look_anyup_rh(eye, dir, dest); 72 | } 73 | 74 | #endif /*cglm_view_rh_zo_h*/ 75 | -------------------------------------------------------------------------------- /include/cglm/color.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_color_h 9 | #define cglm_color_h 10 | 11 | #include "common.h" 12 | #include "vec3.h" 13 | 14 | /*! 15 | * @brief averages the color channels into one value 16 | * 17 | * @param[in] rgb RGB color 18 | */ 19 | CGLM_INLINE 20 | float 21 | glm_luminance(vec3 rgb) { 22 | vec3 l = {0.212671f, 0.715160f, 0.072169f}; 23 | return glm_dot(rgb, l); 24 | } 25 | 26 | #endif /* cglm_color_h */ 27 | -------------------------------------------------------------------------------- /include/cglm/curve.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_curve_h 9 | #define cglm_curve_h 10 | 11 | #include "common.h" 12 | #include "vec4.h" 13 | #include "mat4.h" 14 | 15 | /*! 16 | * @brief helper function to calculate S*M*C multiplication for curves 17 | * 18 | * This function does not encourage you to use SMC, 19 | * instead it is a helper if you use SMC. 20 | * 21 | * if you want to specify S as vector then use more generic glm_mat4_rmc() func. 22 | * 23 | * Example usage: 24 | * B(s) = glm_smc(s, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}) 25 | * 26 | * @param[in] s parameter between 0 and 1 (this will be [s3, s2, s, 1]) 27 | * @param[in] m basis matrix 28 | * @param[in] c position/control vector 29 | * 30 | * @return B(s) 31 | */ 32 | CGLM_INLINE 33 | float 34 | glm_smc(float s, mat4 m, vec4 c) { 35 | vec4 vs; 36 | glm_vec4_cubic(s, vs); 37 | return glm_mat4_rmc(vs, m, c); 38 | } 39 | 40 | #endif /* cglm_curve_h */ 41 | -------------------------------------------------------------------------------- /include/cglm/plane.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_plane_h 9 | #define cglm_plane_h 10 | 11 | #include "common.h" 12 | #include "vec3.h" 13 | #include "vec4.h" 14 | 15 | /* 16 | Plane equation: Ax + By + Cz + D = 0; 17 | 18 | It stored in vec4 as [A, B, C, D]. (A, B, C) is normal and D is distance 19 | */ 20 | 21 | /* 22 | Functions: 23 | CGLM_INLINE void glm_plane_normalize(vec4 plane); 24 | */ 25 | 26 | /*! 27 | * @brief normalizes a plane 28 | * 29 | * @param[in, out] plane plane to normalize 30 | */ 31 | CGLM_INLINE 32 | void 33 | glm_plane_normalize(vec4 plane) { 34 | float norm; 35 | 36 | if (CGLM_UNLIKELY((norm = glm_vec3_norm(plane)) < FLT_EPSILON)) { 37 | glm_vec4_zero(plane); 38 | return; 39 | } 40 | 41 | glm_vec4_scale(plane, 1.0f / norm, plane); 42 | } 43 | 44 | #endif /* cglm_plane_h */ 45 | -------------------------------------------------------------------------------- /include/cglm/simd/avx/affine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_affine_mat_avx_h 9 | #define cglm_affine_mat_avx_h 10 | #ifdef __AVX__ 11 | 12 | #include "../../common.h" 13 | #include "../intrin.h" 14 | 15 | #include 16 | 17 | CGLM_INLINE 18 | void 19 | glm_mul_avx(mat4 m1, mat4 m2, mat4 dest) { 20 | /* D = R * L (Column-Major) */ 21 | 22 | __m256 y0, y1, y2, y3, y4, y5, y6, y7, y8, y9; 23 | 24 | y0 = glmm_load256(m2[0]); /* h g f e d c b a */ 25 | y1 = glmm_load256(m2[2]); /* p o n m l k j i */ 26 | 27 | y2 = glmm_load256(m1[0]); /* h g f e d c b a */ 28 | y3 = glmm_load256(m1[2]); /* p o n m l k j i */ 29 | 30 | /* 0x03: 0b00000011 */ 31 | y4 = _mm256_permute2f128_ps(y2, y2, 0x03); /* d c b a h g f e */ 32 | y5 = _mm256_permute2f128_ps(y3, y3, 0x03); /* l k j i p o n m */ 33 | 34 | /* f f f f a a a a */ 35 | /* h h h h c c c c */ 36 | /* e e e e b b b b */ 37 | /* g g g g d d d d */ 38 | y6 = _mm256_permutevar_ps(y0, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); 39 | y7 = _mm256_permutevar_ps(y0, _mm256_set_epi32(3, 3, 3, 3, 2, 2, 2, 2)); 40 | y8 = _mm256_permutevar_ps(y0, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); 41 | y9 = _mm256_permutevar_ps(y0, _mm256_set_epi32(2, 2, 2, 2, 3, 3, 3, 3)); 42 | 43 | glmm_store256(dest[0], 44 | _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), 45 | _mm256_mul_ps(y3, y7)), 46 | _mm256_add_ps(_mm256_mul_ps(y4, y8), 47 | _mm256_mul_ps(y5, y9)))); 48 | 49 | /* n n n n i i i i */ 50 | /* p p p p k k k k */ 51 | /* m m m m j j j j */ 52 | /* o o o o l l l l */ 53 | y6 = _mm256_permutevar_ps(y1, _mm256_set_epi32(1, 1, 1, 1, 0, 0, 0, 0)); 54 | y7 = _mm256_permutevar_ps(y1, _mm256_set_epi32(3, 3, 3, 3, 2, 2, 2, 2)); 55 | y8 = _mm256_permutevar_ps(y1, _mm256_set_epi32(0, 0, 0, 0, 1, 1, 1, 1)); 56 | y9 = _mm256_permutevar_ps(y1, _mm256_set_epi32(2, 2, 2, 2, 3, 3, 3, 3)); 57 | 58 | glmm_store256(dest[2], 59 | _mm256_add_ps(_mm256_add_ps(_mm256_mul_ps(y2, y6), 60 | _mm256_mul_ps(y3, y7)), 61 | _mm256_add_ps(_mm256_mul_ps(y4, y8), 62 | _mm256_mul_ps(y5, y9)))); 63 | } 64 | 65 | #endif 66 | #endif /* cglm_affine_mat_avx_h */ 67 | -------------------------------------------------------------------------------- /include/cglm/simd/neon/mat2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_mat2_neon_h 9 | #define cglm_mat2_neon_h 10 | #if defined(CGLM_NEON_FP) 11 | 12 | #include "../../common.h" 13 | #include "../intrin.h" 14 | 15 | CGLM_INLINE 16 | void 17 | glm_mat2_mul_neon(mat2 m1, mat2 m2, mat2 dest) { 18 | float32x4x2_t a1; 19 | glmm_128 x0, x1, x2; 20 | float32x2_t dc, ba; 21 | 22 | x1 = glmm_load(m1[0]); /* d c b a */ 23 | x2 = glmm_load(m2[0]); /* h g f e */ 24 | 25 | dc = vget_high_f32(x1); 26 | ba = vget_low_f32(x1); 27 | 28 | /* g g e e, h h f f */ 29 | a1 = vtrnq_f32(x2, x2); 30 | 31 | /* 32 | dest[0][0] = a * e + c * f; 33 | dest[0][1] = b * e + d * f; 34 | dest[1][0] = a * g + c * h; 35 | dest[1][1] = b * g + d * h; 36 | */ 37 | x0 = glmm_fmadd(vcombine_f32(ba, ba), a1.val[0], 38 | vmulq_f32(vcombine_f32(dc, dc), a1.val[1])); 39 | 40 | glmm_store(dest[0], x0); 41 | } 42 | 43 | #endif 44 | #endif /* cglm_mat2_neon_h */ 45 | -------------------------------------------------------------------------------- /include/cglm/simd/neon/quat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_quat_neon_h 9 | #define cglm_quat_neon_h 10 | #if defined(CGLM_NEON_FP) 11 | 12 | #include "../../common.h" 13 | #include "../intrin.h" 14 | 15 | CGLM_INLINE 16 | void 17 | glm_quat_mul_neon(versor p, versor q, versor dest) { 18 | /* 19 | + (a1 b2 + b1 a2 + c1 d2 − d1 c2)i 20 | + (a1 c2 − b1 d2 + c1 a2 + d1 b2)j 21 | + (a1 d2 + b1 c2 − c1 b2 + d1 a2)k 22 | a1 a2 − b1 b2 − c1 c2 − d1 d2 23 | */ 24 | 25 | glmm_128 xp, xq, xqr, r, x, y, z, s2, s3; 26 | glmm_128 s1 = glmm_float32x4_SIGNMASK_NPPN; 27 | 28 | float32x2_t qh, ql; 29 | 30 | xp = glmm_load(p); /* 3 2 1 0 */ 31 | xq = glmm_load(q); 32 | 33 | r = vmulq_f32(glmm_splat_w(xp), xq); 34 | x = glmm_splat_x(xp); 35 | y = glmm_splat_y(xp); 36 | z = glmm_splat_z(xp); 37 | 38 | ql = vget_high_f32(s1); 39 | s3 = vcombine_f32(ql, ql); 40 | s2 = vzipq_f32(s3, s3).val[0]; 41 | 42 | xqr = vrev64q_f32(xq); 43 | qh = vget_high_f32(xqr); 44 | ql = vget_low_f32(xqr); 45 | 46 | r = glmm_fmadd(glmm_xor(x, s3), vcombine_f32(qh, ql), r); 47 | 48 | r = glmm_fmadd(glmm_xor(y, s2), vcombine_f32(vget_high_f32(xq), 49 | vget_low_f32(xq)), r); 50 | 51 | r = glmm_fmadd(glmm_xor(z, s1), vcombine_f32(ql, qh), r); 52 | 53 | glmm_store(dest, r); 54 | } 55 | 56 | #endif 57 | #endif /* cglm_quat_neon_h */ 58 | -------------------------------------------------------------------------------- /include/cglm/simd/sse2/mat2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_mat2_sse_h 9 | #define cglm_mat2_sse_h 10 | #if defined( __SSE__ ) || defined( __SSE2__ ) 11 | 12 | #include "../../common.h" 13 | #include "../intrin.h" 14 | 15 | CGLM_INLINE 16 | void 17 | glm_mat2_mul_sse2(mat2 m1, mat2 m2, mat2 dest) { 18 | __m128 x0, x1, x2, x3, x4; 19 | 20 | x1 = glmm_load(m1[0]); /* d c b a */ 21 | x2 = glmm_load(m2[0]); /* h g f e */ 22 | 23 | x3 = glmm_shuff1(x2, 2, 2, 0, 0); 24 | x4 = glmm_shuff1(x2, 3, 3, 1, 1); 25 | x0 = _mm_movelh_ps(x1, x1); 26 | x2 = _mm_movehl_ps(x1, x1); 27 | 28 | /* 29 | dest[0][0] = a * e + c * f; 30 | dest[0][1] = b * e + d * f; 31 | dest[1][0] = a * g + c * h; 32 | dest[1][1] = b * g + d * h; 33 | */ 34 | x0 = glmm_fmadd(x0, x3, _mm_mul_ps(x2, x4)); 35 | 36 | glmm_store(dest[0], x0); 37 | } 38 | 39 | CGLM_INLINE 40 | void 41 | glm_mat2_transp_sse2(mat2 m, mat2 dest) { 42 | /* d c b a */ 43 | /* d b c a */ 44 | glmm_store(dest[0], glmm_shuff1(glmm_load(m[0]), 3, 1, 2, 0)); 45 | } 46 | 47 | #endif 48 | #endif /* cglm_mat2_sse_h */ 49 | -------------------------------------------------------------------------------- /include/cglm/simd/sse2/quat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_quat_simd_h 9 | #define cglm_quat_simd_h 10 | #if defined( __SSE__ ) || defined( __SSE2__ ) 11 | 12 | #include "../../common.h" 13 | #include "../intrin.h" 14 | 15 | CGLM_INLINE 16 | void 17 | glm_quat_mul_sse2(versor p, versor q, versor dest) { 18 | /* 19 | + (a1 b2 + b1 a2 + c1 d2 − d1 c2)i 20 | + (a1 c2 − b1 d2 + c1 a2 + d1 b2)j 21 | + (a1 d2 + b1 c2 − c1 b2 + d1 a2)k 22 | a1 a2 − b1 b2 − c1 c2 − d1 d2 23 | */ 24 | 25 | __m128 xp, xq, x1, x2, x3, r, x, y, z; 26 | 27 | xp = glmm_load(p); /* 3 2 1 0 */ 28 | xq = glmm_load(q); 29 | x1 = glmm_float32x4_SIGNMASK_NPNP; /* TODO: _mm_set1_ss() + shuff ? */ 30 | r = _mm_mul_ps(glmm_splat_w(xp), xq); 31 | 32 | x2 = _mm_unpackhi_ps(x1, x1); 33 | x3 = glmm_shuff1(x1, 3, 2, 0, 1); 34 | x = glmm_splat_x(xp); 35 | y = glmm_splat_y(xp); 36 | z = glmm_splat_z(xp); 37 | 38 | x = _mm_xor_ps(x, x1); 39 | y = _mm_xor_ps(y, x2); 40 | z = _mm_xor_ps(z, x3); 41 | 42 | x1 = glmm_shuff1(xq, 0, 1, 2, 3); 43 | x2 = glmm_shuff1(xq, 1, 0, 3, 2); 44 | x3 = glmm_shuff1(xq, 2, 3, 0, 1); 45 | 46 | r = glmm_fmadd(x, x1, r); 47 | r = glmm_fmadd(y, x2, r); 48 | r = glmm_fmadd(z, x3, r); 49 | 50 | glmm_store(dest, r); 51 | } 52 | 53 | #endif 54 | #endif /* cglm_quat_simd_h */ 55 | -------------------------------------------------------------------------------- /include/cglm/simd/wasm/mat2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_mat2_wasm_h 9 | #define cglm_mat2_wasm_h 10 | #if defined(__wasm__) && defined(__wasm_simd128__) 11 | 12 | #include "../../common.h" 13 | #include "../intrin.h" 14 | 15 | CGLM_INLINE 16 | void 17 | glm_mat2_mul_wasm(mat2 m1, mat2 m2, mat2 dest) { 18 | glmm_128 x0, x1, x2, x3, x4; 19 | 20 | x1 = glmm_load(m1[0]); /* d c b a */ 21 | x2 = glmm_load(m2[0]); /* h g f e */ 22 | 23 | x3 = glmm_shuff1(x2, 2, 2, 0, 0); 24 | x4 = glmm_shuff1(x2, 3, 3, 1, 1); 25 | /* x0 = _mm_movelh_ps(x1, x1); */ 26 | x0 = wasm_i32x4_shuffle(x1, x1, 0, 1, 4, 5); 27 | /* x2 = _mm_movehl_ps(x1, x1); */ 28 | x2 = wasm_i32x4_shuffle(x1, x1, 6, 7, 2, 3); 29 | 30 | /* 31 | dest[0][0] = a * e + c * f; 32 | dest[0][1] = b * e + d * f; 33 | dest[1][0] = a * g + c * h; 34 | dest[1][1] = b * g + d * h; 35 | */ 36 | x0 = glmm_fmadd(x0, x3, wasm_f32x4_mul(x2, x4)); 37 | 38 | glmm_store(dest[0], x0); 39 | } 40 | 41 | CGLM_INLINE 42 | void 43 | glm_mat2_transp_wasm(mat2 m, mat2 dest) { 44 | /* d c b a */ 45 | /* d b c a */ 46 | glmm_store(dest[0], glmm_shuff1(glmm_load(m[0]), 3, 1, 2, 0)); 47 | } 48 | 49 | #endif 50 | #endif /* cglm_mat2_wasm_h */ 51 | -------------------------------------------------------------------------------- /include/cglm/simd/wasm/quat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_quat_wasm_h 9 | #define cglm_quat_wasm_h 10 | #if defined(__wasm__) && defined(__wasm_simd128__) 11 | 12 | #include "../../common.h" 13 | #include "../intrin.h" 14 | 15 | CGLM_INLINE 16 | void 17 | glm_quat_mul_wasm(versor p, versor q, versor dest) { 18 | /* 19 | + (a1 b2 + b1 a2 + c1 d2 − d1 c2)i 20 | + (a1 c2 − b1 d2 + c1 a2 + d1 b2)j 21 | + (a1 d2 + b1 c2 − c1 b2 + d1 a2)k 22 | a1 a2 − b1 b2 − c1 c2 − d1 d2 23 | */ 24 | 25 | glmm_128 xp, xq, x1, x2, x3, r, x, y, z; 26 | 27 | xp = glmm_load(p); /* 3 2 1 0 */ 28 | xq = glmm_load(q); 29 | /* x1 = wasm_f32x4_const(0.f, -0.f, 0.f, -0.f); */ 30 | x1 = glmm_float32x4_SIGNMASK_PNPN; /* TODO: _mm_set1_ss() + shuff ? */ 31 | r = wasm_f32x4_mul(glmm_splat_w(xp), xq); 32 | /* x2 = _mm_unpackhi_ps(x1, x1); */ 33 | x2 = wasm_i32x4_shuffle(x1, x1, 2, 6, 3, 7); 34 | x3 = glmm_shuff1(x1, 3, 2, 0, 1); 35 | x = glmm_splat_x(xp); 36 | y = glmm_splat_y(xp); 37 | z = glmm_splat_z(xp); 38 | 39 | x = wasm_v128_xor(x, x1); 40 | y = wasm_v128_xor(y, x2); 41 | z = wasm_v128_xor(z, x3); 42 | 43 | x1 = glmm_shuff1(xq, 0, 1, 2, 3); 44 | x2 = glmm_shuff1(xq, 1, 0, 3, 2); 45 | x3 = glmm_shuff1(xq, 2, 3, 0, 1); 46 | 47 | r = glmm_fmadd(x, x1, r); 48 | r = glmm_fmadd(y, x2, r); 49 | r = glmm_fmadd(z, x3, r); 50 | 51 | glmm_store(dest, r); 52 | } 53 | 54 | #endif 55 | #endif /* cglm_quat_wasm_h */ 56 | -------------------------------------------------------------------------------- /include/cglm/sphere.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_sphere_h 9 | #define cglm_sphere_h 10 | 11 | #include "common.h" 12 | #include "mat4.h" 13 | 14 | /* 15 | Sphere Representation in cglm: [center.x, center.y, center.z, radii] 16 | 17 | You could use this representation or you can convert it to vec4 before call 18 | any function 19 | */ 20 | 21 | /*! 22 | * @brief helper for getting sphere radius 23 | * 24 | * @param[in] s sphere 25 | * 26 | * @return returns radii 27 | */ 28 | CGLM_INLINE 29 | float 30 | glm_sphere_radii(vec4 s) { 31 | return s[3]; 32 | } 33 | 34 | /*! 35 | * @brief apply transform to sphere, it is just wrapper for glm_mat4_mulv3 36 | * 37 | * @param[in] s sphere 38 | * @param[in] m transform matrix 39 | * @param[out] dest transformed sphere 40 | */ 41 | CGLM_INLINE 42 | void 43 | glm_sphere_transform(vec4 s, mat4 m, vec4 dest) { 44 | glm_mat4_mulv3(m, s, 1.0f, dest); 45 | dest[3] = s[3]; 46 | } 47 | 48 | /*! 49 | * @brief merges two spheres and creates a new one 50 | * 51 | * two sphere must be in same space, for instance if one in world space then 52 | * the other must be in world space too, not in local space. 53 | * 54 | * @param[in] s1 sphere 1 55 | * @param[in] s2 sphere 2 56 | * @param[out] dest merged/extended sphere 57 | */ 58 | CGLM_INLINE 59 | void 60 | glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { 61 | float dist, radii; 62 | 63 | dist = glm_vec3_distance(s1, s2); 64 | radii = dist + s1[3] + s2[3]; 65 | 66 | radii = glm_max(radii, s1[3]); 67 | radii = glm_max(radii, s2[3]); 68 | 69 | glm_vec3_center(s1, s2, dest); 70 | dest[3] = radii; 71 | } 72 | 73 | /*! 74 | * @brief check if two sphere intersects 75 | * 76 | * @param[in] s1 sphere 77 | * @param[in] s2 other sphere 78 | */ 79 | CGLM_INLINE 80 | bool 81 | glm_sphere_sphere(vec4 s1, vec4 s2) { 82 | return glm_vec3_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]); 83 | } 84 | 85 | /*! 86 | * @brief check if sphere intersects with point 87 | * 88 | * @param[in] s sphere 89 | * @param[in] point point 90 | */ 91 | CGLM_INLINE 92 | bool 93 | glm_sphere_point(vec4 s, vec3 point) { 94 | float rr; 95 | rr = s[3] * s[3]; 96 | return glm_vec3_distance2(point, s) <= rr; 97 | } 98 | 99 | #endif /* cglm_sphere_h */ 100 | -------------------------------------------------------------------------------- /include/cglm/struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_structs_h 9 | #define cglm_structs_h 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include "cglm.h" 15 | #include "types-struct.h" 16 | #include "struct/vec2.h" 17 | #include "struct/vec3.h" 18 | #include "struct/vec4.h" 19 | #include "struct/ivec2.h" 20 | #include "struct/ivec3.h" 21 | #include "struct/ivec4.h" 22 | #include "struct/mat2.h" 23 | #include "struct/mat2x3.h" 24 | #include "struct/mat2x4.h" 25 | #include "struct/mat3.h" 26 | #include "struct/mat3x2.h" 27 | #include "struct/mat3x4.h" 28 | #include "struct/mat4.h" 29 | #include "struct/mat4x2.h" 30 | #include "struct/mat4x3.h" 31 | #include "struct/affine.h" 32 | #include "struct/frustum.h" 33 | #include "struct/plane.h" 34 | #include "struct/noise.h" 35 | #include "struct/box.h" 36 | #include "struct/color.h" 37 | #include "struct/io.h" 38 | #include "struct/cam.h" 39 | #include "struct/quat.h" 40 | #include "struct/euler.h" 41 | #include "struct/project.h" 42 | #include "struct/sphere.h" 43 | #include "struct/curve.h" 44 | #include "struct/affine2d.h" 45 | #include "struct/ray.h" 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | #endif /* cglm_structs_h */ 51 | -------------------------------------------------------------------------------- /include/cglm/struct/affine-mat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* 9 | Functions: 10 | CGLM_INLINE mat4s glms_mul(mat4 m1, mat4 m2); 11 | CGLM_INLINE mat4s glms_mul_rot(mat4 m1, mat4 m2); 12 | CGLM_INLINE mat4s glms_inv_tr(); 13 | */ 14 | 15 | #ifndef cglms_affine_mat_h 16 | #define cglms_affine_mat_h 17 | 18 | #include "../common.h" 19 | #include "../types-struct.h" 20 | #include "../affine-mat.h" 21 | #include "vec3.h" 22 | #include "vec4.h" 23 | #include "mat4.h" 24 | 25 | /*! 26 | * @brief this is similar to glms_mat4_mul but specialized to affine transform 27 | * 28 | * Matrix format should be: 29 | * R R R X 30 | * R R R Y 31 | * R R R Z 32 | * 0 0 0 W 33 | * 34 | * this reduces some multiplications. It should be faster than mat4_mul. 35 | * if you are not sure about matrix format then DON'T use this! use mat4_mul 36 | * 37 | * @param[in] m1 affine matrix 1 38 | * @param[in] m2 affine matrix 2 39 | * @returns destination matrix 40 | */ 41 | CGLM_INLINE 42 | mat4s 43 | glms_mul(mat4s m1, mat4s m2){ 44 | mat4s r; 45 | glm_mul(m1.raw, m2.raw, r.raw); 46 | return r; 47 | } 48 | 49 | /*! 50 | * @brief this is similar to glm_mat4_mul but specialized to affine transform 51 | * 52 | * Right Matrix format should be: 53 | * R R R 0 54 | * R R R 0 55 | * R R R 0 56 | * 0 0 0 1 57 | * 58 | * this reduces some multiplications. It should be faster than mat4_mul. 59 | * if you are not sure about matrix format then DON'T use this! use mat4_mul 60 | * 61 | * @param[in] m1 affine matrix 1 62 | * @param[in] m2 affine matrix 2 63 | * @returns destination matrix 64 | */ 65 | CGLM_INLINE 66 | mat4s 67 | glms_mul_rot(mat4s m1, mat4s m2){ 68 | mat4s r; 69 | glm_mul_rot(m1.raw, m2.raw, r.raw); 70 | return r; 71 | } 72 | 73 | /*! 74 | * @brief inverse orthonormal rotation + translation matrix (ridig-body) 75 | * 76 | * @code 77 | * X = | R T | X' = | R' -R'T | 78 | * | 0 1 | | 0 1 | 79 | * @endcode 80 | * 81 | * @param[in] m matrix 82 | * @returns destination matrix 83 | */ 84 | CGLM_INLINE 85 | mat4s 86 | glms_inv_tr(mat4s m){ 87 | glm_inv_tr(m.raw); 88 | return m; 89 | } 90 | #endif /* cglms_affine_mat_h */ 91 | -------------------------------------------------------------------------------- /include/cglm/struct/clipspace/project_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* 9 | Functions: 10 | CGLM_INLINE vec3s glms_unprojecti_no(vec3s pos, mat4s invMat, vec4s vp) 11 | CGLM_INLINE vec3s glms_project_no(vec3s pos, mat4s m, vec4s vp) 12 | CGLM_INLINE float glms_project_z_no(vec3s v, mat4s m) 13 | */ 14 | 15 | #ifndef cglms_project_no_h 16 | #define cglms_project_no_h 17 | 18 | #include "../../common.h" 19 | #include "../../types-struct.h" 20 | #include "../../plane.h" 21 | #include "../../cam.h" 22 | #include "../../clipspace/project_no.h" 23 | 24 | /*! 25 | * @brief maps the specified viewport coordinates into specified space [1] 26 | * the matrix should contain projection matrix. 27 | * 28 | * if you don't have ( and don't want to have ) an inverse matrix then use 29 | * glm_unproject version. You may use existing inverse of matrix in somewhere 30 | * else, this is why glm_unprojecti exists to save save inversion cost 31 | * 32 | * [1] space: 33 | * 1- if m = invProj: View Space 34 | * 2- if m = invViewProj: World Space 35 | * 3- if m = invMVP: Object Space 36 | * 37 | * You probably want to map the coordinates into object space 38 | * so use invMVP as m 39 | * 40 | * Computing viewProj: 41 | * glm_mat4_mul(proj, view, viewProj); 42 | * glm_mat4_mul(viewProj, model, MVP); 43 | * glm_mat4_inv(viewProj, invMVP); 44 | * 45 | * @param[in] pos point/position in viewport coordinates 46 | * @param[in] invMat matrix (see brief) 47 | * @param[in] vp viewport as [x, y, width, height] 48 | * 49 | * @returns unprojected coordinates 50 | */ 51 | CGLM_INLINE 52 | vec3s 53 | glms_unprojecti_no(vec3s pos, mat4s invMat, vec4s vp) { 54 | vec3s dest; 55 | glm_unprojecti_no(pos.raw, invMat.raw, vp.raw, dest.raw); 56 | return dest; 57 | } 58 | 59 | /*! 60 | * @brief map object coordinates to window coordinates 61 | * 62 | * Computing MVP: 63 | * glm_mat4_mul(proj, view, viewProj); 64 | * glm_mat4_mul(viewProj, model, MVP); 65 | * 66 | * @param[in] pos object coordinates 67 | * @param[in] m MVP matrix 68 | * @param[in] vp viewport as [x, y, width, height] 69 | * 70 | * @returns projected coordinates 71 | */ 72 | CGLM_INLINE 73 | vec3s 74 | glms_project_no(vec3s pos, mat4s m, vec4s vp) { 75 | vec3s dest; 76 | glm_project_no(pos.raw, m.raw, vp.raw, dest.raw); 77 | return dest; 78 | } 79 | 80 | /*! 81 | * @brief map object's z coordinate to window coordinates 82 | * 83 | * Computing MVP: 84 | * glm_mat4_mul(proj, view, viewProj); 85 | * glm_mat4_mul(viewProj, model, MVP); 86 | * 87 | * @param[in] v object coordinates 88 | * @param[in] m MVP matrix 89 | * 90 | * @returns projected z coordinate 91 | */ 92 | CGLM_INLINE 93 | float 94 | glms_project_z_no(vec3s v, mat4s m) { 95 | return glm_project_z_no(v.raw, m.raw); 96 | } 97 | 98 | #endif /* cglms_project_rh_no_h */ 99 | -------------------------------------------------------------------------------- /include/cglm/struct/clipspace/project_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* 9 | Functions: 10 | CGLM_INLINE vec3s glms_unprojecti_no(vec3s pos, mat4s invMat, vec4s vp) 11 | CGLM_INLINE vec3s glms_project_no(vec3s pos, mat4s m, vec4s vp) 12 | CGLM_INLINE float glms_project_z_zo(vec3s v, mat4s m) 13 | */ 14 | 15 | #ifndef cglms_project_zo_h 16 | #define cglms_project_zo_h 17 | 18 | #include "../../common.h" 19 | #include "../../types-struct.h" 20 | #include "../../plane.h" 21 | #include "../../cam.h" 22 | #include "../../clipspace/project_zo.h" 23 | 24 | /*! 25 | * @brief maps the specified viewport coordinates into specified space [1] 26 | * the matrix should contain projection matrix. 27 | * 28 | * if you don't have ( and don't want to have ) an inverse matrix then use 29 | * glm_unproject version. You may use existing inverse of matrix in somewhere 30 | * else, this is why glm_unprojecti exists to save save inversion cost 31 | * 32 | * [1] space: 33 | * 1- if m = invProj: View Space 34 | * 2- if m = invViewProj: World Space 35 | * 3- if m = invMVP: Object Space 36 | * 37 | * You probably want to map the coordinates into object space 38 | * so use invMVP as m 39 | * 40 | * Computing viewProj: 41 | * glm_mat4_mul(proj, view, viewProj); 42 | * glm_mat4_mul(viewProj, model, MVP); 43 | * glm_mat4_inv(viewProj, invMVP); 44 | * 45 | * @param[in] pos point/position in viewport coordinates 46 | * @param[in] invMat matrix (see brief) 47 | * @param[in] vp viewport as [x, y, width, height] 48 | * 49 | * @returns unprojected coordinates 50 | */ 51 | CGLM_INLINE 52 | vec3s 53 | glms_unprojecti_zo(vec3s pos, mat4s invMat, vec4s vp) { 54 | vec3s dest; 55 | glm_unprojecti_zo(pos.raw, invMat.raw, vp.raw, dest.raw); 56 | return dest; 57 | } 58 | 59 | /*! 60 | * @brief map object coordinates to window coordinates 61 | * 62 | * Computing MVP: 63 | * glm_mat4_mul(proj, view, viewProj); 64 | * glm_mat4_mul(viewProj, model, MVP); 65 | * 66 | * @param[in] pos object coordinates 67 | * @param[in] m MVP matrix 68 | * @param[in] vp viewport as [x, y, width, height] 69 | * 70 | * @returns projected coordinates 71 | */ 72 | CGLM_INLINE 73 | vec3s 74 | glms_project_zo(vec3s pos, mat4s m, vec4s vp) { 75 | vec3s dest; 76 | glm_project_zo(pos.raw, m.raw, vp.raw, dest.raw); 77 | return dest; 78 | } 79 | 80 | /*! 81 | * @brief map object's z coordinate to window coordinates 82 | * 83 | * Computing MVP: 84 | * glm_mat4_mul(proj, view, viewProj); 85 | * glm_mat4_mul(viewProj, model, MVP); 86 | * 87 | * @param[in] v object coordinates 88 | * @param[in] m MVP matrix 89 | * 90 | * @returns projected z coordinate 91 | */ 92 | CGLM_INLINE 93 | float 94 | glms_project_z_zo(vec3s v, mat4s m) { 95 | return glm_project_z_zo(v.raw, m.raw); 96 | } 97 | 98 | #endif /* cglm_project_zo_h */ 99 | -------------------------------------------------------------------------------- /include/cglm/struct/clipspace/view_lh_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* 9 | Functions: 10 | CGLM_INLINE mat4s glms_lookat_lh_no(vec3s eye, vec3s center, vec3s up) 11 | CGLM_INLINE mat4s glms_look_lh_no(vec3s eye, vec3s dir, vec3s up) 12 | CGLM_INLINE mat4s glms_look_anyup_lh_no(vec3s eye, vec3s dir) 13 | */ 14 | 15 | #ifndef cglms_view_lh_no_h 16 | #define cglms_view_lh_no_h 17 | 18 | #include "../../common.h" 19 | #include "../../types-struct.h" 20 | #include "../../plane.h" 21 | #include "../../cam.h" 22 | #include "../../clipspace/view_lh_no.h" 23 | 24 | /*! 25 | * @brief set up view matrix 26 | * with a left-hand coordinate system and a 27 | * clip-space of [-1, 1]. 28 | * 29 | * NOTE: The UP vector must not be parallel to the line of sight from 30 | * the eye point to the reference point 31 | * 32 | * @param[in] eye eye vector 33 | * @param[in] center center vector 34 | * @param[in] up up vector 35 | * @returns result matrix 36 | */ 37 | CGLM_INLINE 38 | mat4s 39 | glms_lookat_lh_no(vec3s eye, vec3s center, vec3s up) { 40 | mat4s dest; 41 | glm_lookat_lh_no(eye.raw, center.raw, up.raw, dest.raw); 42 | return dest; 43 | } 44 | 45 | /*! 46 | * @brief set up view matrix 47 | * with a left-hand coordinate system and a 48 | * clip-space of [-1, 1]. 49 | * 50 | * convenient wrapper for lookat: if you only have direction not target self 51 | * then this might be useful. Because you need to get target from direction. 52 | * 53 | * NOTE: The UP vector must not be parallel to the line of sight from 54 | * the eye point to the reference point 55 | * 56 | * @param[in] eye eye vector 57 | * @param[in] dir direction vector 58 | * @param[in] up up vector 59 | * @returns result matrix 60 | */ 61 | CGLM_INLINE 62 | mat4s 63 | glms_look_lh_no(vec3s eye, vec3s dir, vec3s up) { 64 | mat4s dest; 65 | glm_look_lh_no(eye.raw, dir.raw, up.raw, dest.raw); 66 | return dest; 67 | } 68 | 69 | /*! 70 | * @brief set up view matrix 71 | * with a left-hand coordinate system and a 72 | * clip-space of [-1, 1]. 73 | * 74 | * convenient wrapper for look: if you only have direction and if you don't 75 | * care what UP vector is then this might be useful to create view matrix 76 | * 77 | * @param[in] eye eye vector 78 | * @param[in] dir direction vector 79 | * @returns result matrix 80 | */ 81 | CGLM_INLINE 82 | mat4s 83 | glms_look_anyup_lh_no(vec3s eye, vec3s dir) { 84 | mat4s dest; 85 | glm_look_anyup_lh_no(eye.raw, dir.raw, dest.raw); 86 | return dest; 87 | } 88 | 89 | #endif /* cglms_view_lh_no_h */ 90 | -------------------------------------------------------------------------------- /include/cglm/struct/clipspace/view_lh_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* 9 | Functions: 10 | CGLM_INLINE mat4s glms_lookat_lh_zo(vec3s eye, vec3s center, vec3s up) 11 | CGLM_INLINE mat4s glms_look_lh_zo(vec3s eye, vec3s dir, vec3s up) 12 | CGLM_INLINE mat4s glms_look_anyup_lh_zo(vec3s eye, vec3s dir) 13 | */ 14 | 15 | #ifndef cglms_view_lh_zo_h 16 | #define cglms_view_lh_zo_h 17 | 18 | #include "../../common.h" 19 | #include "../../types-struct.h" 20 | #include "../../plane.h" 21 | #include "../../cam.h" 22 | #include "../../clipspace/view_lh_zo.h" 23 | 24 | /*! 25 | * @brief set up view matrix 26 | * with a left-hand coordinate system and a 27 | * clip-space of [0, 1]. 28 | * 29 | * NOTE: The UP vector must not be parallel to the line of sight from 30 | * the eye point to the reference point 31 | * 32 | * @param[in] eye eye vector 33 | * @param[in] center center vector 34 | * @param[in] up up vector 35 | * @returns result matrix 36 | */ 37 | CGLM_INLINE 38 | mat4s 39 | glms_lookat_lh_zo(vec3s eye, vec3s center, vec3s up) { 40 | mat4s dest; 41 | glm_lookat_lh_zo(eye.raw, center.raw, up.raw, dest.raw); 42 | return dest; 43 | } 44 | 45 | /*! 46 | * @brief set up view matrix 47 | * with a left-hand coordinate system and a 48 | * clip-space of [0, 1]. 49 | * 50 | * convenient wrapper for lookat: if you only have direction not target self 51 | * then this might be useful. Because you need to get target from direction. 52 | * 53 | * NOTE: The UP vector must not be parallel to the line of sight from 54 | * the eye point to the reference point 55 | * 56 | * @param[in] eye eye vector 57 | * @param[in] dir direction vector 58 | * @param[in] up up vector 59 | * @returns result matrix 60 | */ 61 | CGLM_INLINE 62 | mat4s 63 | glms_look_lh_zo(vec3s eye, vec3s dir, vec3s up) { 64 | mat4s dest; 65 | glm_look_lh_zo(eye.raw, dir.raw, up.raw, dest.raw); 66 | return dest; 67 | } 68 | 69 | /*! 70 | * @brief set up view matrix 71 | * with a left-hand coordinate system and a 72 | * clip-space of [0, 1]. 73 | * 74 | * convenient wrapper for look: if you only have direction and if you don't 75 | * care what UP vector is then this might be useful to create view matrix 76 | * 77 | * @param[in] eye eye vector 78 | * @param[in] dir direction vector 79 | * @returns result matrix 80 | */ 81 | CGLM_INLINE 82 | mat4s 83 | glms_look_anyup_lh_zo(vec3s eye, vec3s dir) { 84 | mat4s dest; 85 | glm_look_anyup_lh_zo(eye.raw, dir.raw, dest.raw); 86 | return dest; 87 | } 88 | 89 | #endif /* cglms_view_lh_zo_h */ 90 | -------------------------------------------------------------------------------- /include/cglm/struct/clipspace/view_rh_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* 9 | Functions: 10 | CGLM_INLINE mat4s glms_lookat_rh_no(vec3s eye, vec3s center, vec3s up) 11 | CGLM_INLINE mat4s glms_look_rh_no(vec3s eye, vec3s dir, vec3s up) 12 | CGLM_INLINE mat4s glms_look_anyup_rh_no(vec3s eye, vec3s dir) 13 | */ 14 | 15 | #ifndef cglms_view_rh_no_h 16 | #define cglms_view_rh_no_h 17 | 18 | #include "../../common.h" 19 | #include "../../types-struct.h" 20 | #include "../../plane.h" 21 | #include "../../cam.h" 22 | #include "../../clipspace/view_rh_no.h" 23 | 24 | /*! 25 | * @brief set up view matrix 26 | * with a right-hand coordinate system and a 27 | * clip-space of [-1, 1]. 28 | * 29 | * NOTE: The UP vector must not be parallel to the line of sight from 30 | * the eye point to the reference point 31 | * 32 | * @param[in] eye eye vector 33 | * @param[in] center center vector 34 | * @param[in] up up vector 35 | * @returns result matrix 36 | */ 37 | CGLM_INLINE 38 | mat4s 39 | glms_lookat_rh_no(vec3s eye, vec3s center, vec3s up) { 40 | mat4s dest; 41 | glm_lookat_rh_no(eye.raw, center.raw, up.raw, dest.raw); 42 | return dest; 43 | } 44 | 45 | /*! 46 | * @brief set up view matrix 47 | * with a right-hand coordinate system and a 48 | * clip-space of [-1, 1]. 49 | * 50 | * convenient wrapper for lookat: if you only have direction not target self 51 | * then this might be useful. Because you need to get target from direction. 52 | * 53 | * NOTE: The UP vector must not be parallel to the line of sight from 54 | * the eye point to the reference point 55 | * 56 | * @param[in] eye eye vector 57 | * @param[in] dir direction vector 58 | * @param[in] up up vector 59 | * @returns result matrix 60 | */ 61 | CGLM_INLINE 62 | mat4s 63 | glms_look_rh_no(vec3s eye, vec3s dir, vec3s up) { 64 | mat4s dest; 65 | glm_look_rh_no(eye.raw, dir.raw, up.raw, dest.raw); 66 | return dest; 67 | } 68 | 69 | /*! 70 | * @brief set up view matrix 71 | * with a right-hand coordinate system and a 72 | * clip-space of [-1, 1]. 73 | * 74 | * convenient wrapper for look: if you only have direction and if you don't 75 | * care what UP vector is then this might be useful to create view matrix 76 | * 77 | * @param[in] eye eye vector 78 | * @param[in] dir direction vector 79 | * @returns result matrix 80 | */ 81 | CGLM_INLINE 82 | mat4s 83 | glms_look_anyup_rh_no(vec3s eye, vec3s dir) { 84 | mat4s dest; 85 | glm_look_anyup_rh_no(eye.raw, dir.raw, dest.raw); 86 | return dest; 87 | } 88 | 89 | #endif /* cglms_view_rh_no_h */ 90 | -------------------------------------------------------------------------------- /include/cglm/struct/clipspace/view_rh_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* 9 | Functions: 10 | CGLM_INLINE mat4s glms_lookat_rh_zo(vec3s eye, vec3s center, vec3s up) 11 | CGLM_INLINE mat4s glms_look_rh_zo(vec3s eye, vec3s dir, vec3s up) 12 | CGLM_INLINE mat4s glms_look_anyup_rh_zo(vec3s eye, vec3s dir) 13 | */ 14 | 15 | #ifndef cglms_view_rh_zo_h 16 | #define cglms_view_rh_zo_h 17 | 18 | #include "../../common.h" 19 | #include "../../types-struct.h" 20 | #include "../../plane.h" 21 | #include "../../cam.h" 22 | #include "../../clipspace/view_rh_zo.h" 23 | 24 | /*! 25 | * @brief set up view matrix 26 | * with a right-hand coordinate system and a 27 | * clip-space of [0, 1]. 28 | * 29 | * NOTE: The UP vector must not be parallel to the line of sight from 30 | * the eye point to the reference point 31 | * 32 | * @param[in] eye eye vector 33 | * @param[in] center center vector 34 | * @param[in] up up vector 35 | * @returns result matrix 36 | */ 37 | CGLM_INLINE 38 | mat4s 39 | glms_lookat_rh_zo(vec3s eye, vec3s center, vec3s up) { 40 | mat4s dest; 41 | glm_lookat_rh_zo(eye.raw, center.raw, up.raw, dest.raw); 42 | return dest; 43 | } 44 | 45 | /*! 46 | * @brief set up view matrix 47 | * with a right-hand coordinate system and a 48 | * clip-space of [0, 1]. 49 | * 50 | * convenient wrapper for lookat: if you only have direction not target self 51 | * then this might be useful. Because you need to get target from direction. 52 | * 53 | * NOTE: The UP vector must not be parallel to the line of sight from 54 | * the eye point to the reference point 55 | * 56 | * @param[in] eye eye vector 57 | * @param[in] dir direction vector 58 | * @param[in] up up vector 59 | * @returns result matrix 60 | */ 61 | CGLM_INLINE 62 | mat4s 63 | glms_look_rh_zo(vec3s eye, vec3s dir, vec3s up) { 64 | mat4s dest; 65 | glm_look_rh_zo(eye.raw, dir.raw, up.raw, dest.raw); 66 | return dest; 67 | } 68 | 69 | /*! 70 | * @brief set up view matrix 71 | * with a right-hand coordinate system and a 72 | * clip-space of [0, 1]. 73 | * 74 | * convenient wrapper for look: if you only have direction and if you don't 75 | * care what UP vector is then this might be useful to create view matrix 76 | * 77 | * @param[in] eye eye vector 78 | * @param[in] dir direction vector 79 | * @returns result matrix 80 | */ 81 | CGLM_INLINE 82 | mat4s 83 | glms_look_anyup_rh_zo(vec3s eye, vec3s dir) { 84 | mat4s dest; 85 | glm_look_anyup_rh_zo(eye.raw, dir.raw, dest.raw); 86 | return dest; 87 | } 88 | 89 | #endif /* cglms_view_rh_zo_h */ 90 | -------------------------------------------------------------------------------- /include/cglm/struct/color.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglms_colors_h 9 | #define cglms_colors_h 10 | 11 | #include "../common.h" 12 | #include "../types-struct.h" 13 | #include "../color.h" 14 | #include "vec3.h" 15 | 16 | /*! 17 | * @brief averages the color channels into one value 18 | * 19 | * @param[in] rgb RGB color 20 | */ 21 | CGLM_INLINE 22 | float 23 | glms_luminance(vec3s rgb) { 24 | return glm_luminance(rgb.raw); 25 | } 26 | 27 | #endif /* cglms_colors_h */ 28 | -------------------------------------------------------------------------------- /include/cglm/struct/curve.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglms_curves_h 9 | #define cglms_curves_h 10 | 11 | #include "../common.h" 12 | #include "../types-struct.h" 13 | #include "../curve.h" 14 | #include "vec4.h" 15 | #include "mat4.h" 16 | 17 | /*! 18 | * @brief helper function to calculate S*M*C multiplication for curves 19 | * 20 | * This function does not encourage you to use SMC, 21 | * instead it is a helper if you use SMC. 22 | * 23 | * if you want to specify S as vector then use more generic glm_mat4_rmc() func. 24 | * 25 | * Example usage: 26 | * B(s) = glm_smc(s, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}) 27 | * 28 | * @param[in] s parameter between 0 and 1 (this will be [s3, s2, s, 1]) 29 | * @param[in] m basis matrix 30 | * @param[in] c position/control vector 31 | * 32 | * @return B(s) 33 | */ 34 | CGLM_INLINE 35 | float 36 | glms_smc(float s, mat4s m, vec4s c) { 37 | return glm_smc(s, m.raw, c.raw); 38 | } 39 | 40 | #endif /* cglms_curves_h */ 41 | -------------------------------------------------------------------------------- /include/cglm/struct/noise.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglms_noises_h 9 | #define cglms_noises_h 10 | 11 | #include "../common.h" 12 | #include "../types-struct.h" 13 | #include "../noise.h" 14 | #include "vec4.h" 15 | 16 | /* 17 | Functions: 18 | CGLM_INLINE float glms_perlin_vec4(vec4s point); 19 | */ 20 | 21 | /*! 22 | * @brief Classic perlin noise 23 | * 24 | * @param[in] point 4D vector 25 | * @returns perlin noise value 26 | */ 27 | CGLM_INLINE 28 | float 29 | glms_perlin_vec4(vec4s point) { 30 | return glm_perlin_vec4(point.raw); 31 | } 32 | 33 | /*! 34 | * @brief Classic perlin noise 35 | * 36 | * @param[in] point 3D vector 37 | * @returns perlin noise value 38 | */ 39 | CGLM_INLINE 40 | float 41 | glms_perlin_vec3(vec3s point) { 42 | return glm_perlin_vec3(point.raw); 43 | } 44 | 45 | /*! 46 | * @brief Classic perlin noise 47 | * 48 | * @param[in] point 2D vector 49 | * @returns perlin noise value 50 | */ 51 | CGLM_INLINE 52 | float 53 | glms_perlin_vec2(vec2s point) { 54 | return glm_perlin_vec2(point.raw); 55 | } 56 | 57 | #endif /* cglms_noises_h */ 58 | -------------------------------------------------------------------------------- /include/cglm/struct/plane.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglms_planes_h 9 | #define cglms_planes_h 10 | 11 | #include "../common.h" 12 | #include "../types-struct.h" 13 | #include "../plane.h" 14 | #include "vec4.h" 15 | 16 | /* 17 | Plane equation: Ax + By + Cz + D = 0; 18 | 19 | It stored in vec4 as [A, B, C, D]. (A, B, C) is normal and D is distance 20 | */ 21 | 22 | /* 23 | Functions: 24 | CGLM_INLINE vec4s glms_plane_normalize(vec4s plane); 25 | */ 26 | 27 | /*! 28 | * @brief normalizes a plane 29 | * 30 | * @param[in] plane plane to normalize 31 | * @returns normalized plane 32 | */ 33 | CGLM_INLINE 34 | vec4s 35 | glms_plane_normalize(vec4s plane) { 36 | glm_plane_normalize(plane.raw); 37 | return plane; 38 | } 39 | 40 | #endif /* cglms_planes_h */ 41 | -------------------------------------------------------------------------------- /include/cglm/struct/ray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglms_ray_h 9 | #define cglms_ray_h 10 | 11 | #include "../common.h" 12 | #include "../types-struct.h" 13 | #include "../ray.h" 14 | 15 | /* api definition */ 16 | #define glms_ray_(NAME) CGLM_STRUCTAPI(ray, NAME) 17 | 18 | /*! 19 | * @brief Möller–Trumbore ray-triangle intersection algorithm 20 | * 21 | * @param[in] origin origin of ray 22 | * @param[in] direction direction of ray 23 | * @param[in] v0 first vertex of triangle 24 | * @param[in] v1 second vertex of triangle 25 | * @param[in] v2 third vertex of triangle 26 | * @param[in, out] d distance to intersection 27 | * @return whether there is intersection 28 | */ 29 | CGLM_INLINE 30 | bool 31 | glms_ray_(triangle)(vec3s origin, 32 | vec3s direction, 33 | vec3s v0, 34 | vec3s v1, 35 | vec3s v2, 36 | float *d) { 37 | return glm_ray_triangle(origin.raw, direction.raw, v0.raw, v1.raw, v2.raw, d); 38 | } 39 | 40 | /*! 41 | * @brief ray sphere intersection 42 | * 43 | * returns false if there is no intersection if true: 44 | * 45 | * - t1 > 0, t2 > 0: ray intersects the sphere at t1 and t2 both ahead of the origin 46 | * - t1 < 0, t2 > 0: ray starts inside the sphere, exits at t2 47 | * - t1 < 0, t2 < 0: no intersection ahead of the ray ( returns false ) 48 | * - the caller can check if the intersection points (t1 and t2) fall within a 49 | * specific range (for example, tmin < t1, t2 < tmax) to determine if the 50 | * intersections are within a desired segment of the ray 51 | * 52 | * @param[in] origin ray origin 53 | * @param[out] dir normalized ray direction 54 | * @param[in] s sphere [center.x, center.y, center.z, radii] 55 | * @param[in] t1 near point1 (closer to origin) 56 | * @param[in] t2 far point2 (farther from origin) 57 | * 58 | * @returns whether there is intersection 59 | */ 60 | CGLM_INLINE 61 | bool 62 | glms_ray_(sphere)(vec3s origin, 63 | vec3s dir, 64 | vec4s s, 65 | float * __restrict t1, 66 | float * __restrict t2) { 67 | return glm_ray_sphere(origin.raw, dir.raw, s.raw, t1, t2); 68 | } 69 | 70 | /*! 71 | * @brief point using t by 𝐏(𝑡)=𝐀+𝑡𝐛 72 | * 73 | * @param[in] orig origin of ray 74 | * @param[in] dir direction of ray 75 | * @param[in] t parameter 76 | * @returns point point at t 77 | */ 78 | CGLM_INLINE 79 | vec3s 80 | glms_ray_(at)(vec3s orig, vec3s dir, float t) { 81 | vec3s r; 82 | glm_ray_at(orig.raw, dir.raw, t, r.raw); 83 | return r; 84 | } 85 | 86 | #endif /* cglms_ray_h */ 87 | -------------------------------------------------------------------------------- /include/cglm/struct/sphere.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglms_spheres_h 9 | #define cglms_spheres_h 10 | 11 | #include "../common.h" 12 | #include "../types-struct.h" 13 | #include "../sphere.h" 14 | #include "mat4.h" 15 | 16 | /* 17 | Sphere Representation in cglm: [center.x, center.y, center.z, radii] 18 | 19 | You could use this representation or you can convert it to vec4 before call 20 | any function 21 | */ 22 | 23 | /*! 24 | * @brief helper for getting sphere radius 25 | * 26 | * @param[in] s sphere 27 | * 28 | * @return returns radii 29 | */ 30 | CGLM_INLINE 31 | float 32 | glms_sphere_radii(vec4s s) { 33 | return glm_sphere_radii(s.raw); 34 | } 35 | 36 | /*! 37 | * @brief apply transform to sphere, it is just wrapper for glm_mat4_mulv3 38 | * 39 | * @param[in] s sphere 40 | * @param[in] m transform matrix 41 | * @returns transformed sphere 42 | */ 43 | CGLM_INLINE 44 | vec4s 45 | glms_sphere_transform(vec4s s, mat4s m) { 46 | vec4s r; 47 | glm_sphere_transform(s.raw, m.raw, r.raw); 48 | return r; 49 | } 50 | 51 | /*! 52 | * @brief merges two spheres and creates a new one 53 | * 54 | * two sphere must be in same space, for instance if one in world space then 55 | * the other must be in world space too, not in local space. 56 | * 57 | * @param[in] s1 sphere 1 58 | * @param[in] s2 sphere 2 59 | * returns merged/extended sphere 60 | */ 61 | CGLM_INLINE 62 | vec4s 63 | glms_sphere_merge(vec4s s1, vec4s s2) { 64 | vec4s r; 65 | glm_sphere_merge(s1.raw, s2.raw, r.raw); 66 | return r; 67 | } 68 | 69 | /*! 70 | * @brief check if two sphere intersects 71 | * 72 | * @param[in] s1 sphere 73 | * @param[in] s2 other sphere 74 | */ 75 | CGLM_INLINE 76 | bool 77 | glms_sphere_sphere(vec4s s1, vec4s s2) { 78 | return glm_sphere_sphere(s1.raw, s2.raw); 79 | } 80 | 81 | /*! 82 | * @brief check if sphere intersects with point 83 | * 84 | * @param[in] s sphere 85 | * @param[in] point point 86 | */ 87 | CGLM_INLINE 88 | bool 89 | glms_sphere_point(vec4s s, vec3s point) { 90 | return glm_sphere_point(s.raw, point.raw); 91 | } 92 | 93 | #endif /* cglms_spheres_h */ 94 | -------------------------------------------------------------------------------- /include/cglm/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm_version_h 9 | #define cglm_version_h 10 | 11 | #define CGLM_VERSION_MAJOR 0 12 | #define CGLM_VERSION_MINOR 9 13 | #define CGLM_VERSION_PATCH 6 14 | 15 | #endif /* cglm_version_h */ 16 | -------------------------------------------------------------------------------- /include/module.modulemap: -------------------------------------------------------------------------------- 1 | module cglm { 2 | header "cglm/cglm.h" 3 | header "cglm/struct.h" 4 | 5 | export * 6 | } 7 | 8 | module cglmc { 9 | header "cglm/cglm.h" 10 | header "cglm/struct.h" 11 | header "cglm/call.h" 12 | 13 | export * 14 | } 15 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | option('build_tests', type : 'boolean', value : false, description : 'Build tests') 2 | option('install', type : 'boolean', value : true, description : 'Include the library, headers, and pkg-config file in the install target') 3 | -------------------------------------------------------------------------------- /src/aabb2d.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_aabb2d_zero(vec2 aabb[2]) { 14 | glm_aabb2d_zero(aabb); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_aabb2d_copy(vec2 aabb[2], vec2 dest[2]) { 20 | glm_aabb2d_copy(aabb, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_aabb2d_transform(vec2 aabb[2], mat3 m, vec2 dest[2]) { 26 | glm_aabb2d_transform(aabb, m, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_aabb2d_merge(vec2 aabb1[2], vec2 aabb2[2], vec2 dest[2]) { 32 | glm_aabb2d_merge(aabb1, aabb2, dest); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_aabb2d_crop(vec2 aabb[2], vec2 cropAabb[2], vec2 dest[2]) { 38 | glm_aabb2d_crop(aabb, cropAabb, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_aabb2d_crop_until(vec2 aabb[2], 44 | vec2 cropAabb[2], 45 | vec2 clampAabb[2], 46 | vec2 dest[2]) { 47 | glm_aabb2d_crop_until(aabb, cropAabb, clampAabb, dest); 48 | } 49 | 50 | CGLM_EXPORT 51 | void 52 | glmc_aabb2d_invalidate(vec2 aabb[2]) { 53 | glm_aabb2d_invalidate(aabb); 54 | } 55 | 56 | CGLM_EXPORT 57 | bool 58 | glmc_aabb2d_isvalid(vec2 aabb[2]) { 59 | return glm_aabb2d_isvalid(aabb); 60 | } 61 | 62 | CGLM_EXPORT 63 | float 64 | glmc_aabb2d_diag(vec2 aabb[2]) { 65 | return glm_aabb2d_diag(aabb); 66 | } 67 | 68 | CGLM_EXPORT 69 | void 70 | glmc_aabb2d_sizev(vec2 aabb[2], vec2 dest) { 71 | glm_aabb2d_sizev(aabb, dest); 72 | } 73 | 74 | CGLM_EXPORT 75 | float 76 | glmc_aabb2d_radius(vec2 aabb[2]) { 77 | return glm_aabb2d_radius(aabb); 78 | } 79 | 80 | CGLM_EXPORT 81 | void 82 | glmc_aabb2d_center(vec2 aabb[2], vec2 dest) { 83 | glm_aabb2d_center(aabb, dest); 84 | } 85 | 86 | CGLM_EXPORT 87 | bool 88 | glmc_aabb2d_aabb(vec2 aabb[2], vec2 other[2]) { 89 | return glm_aabb2d_aabb(aabb, other); 90 | } 91 | 92 | CGLM_EXPORT 93 | bool 94 | glmc_aabb2d_point(vec2 aabb[2], vec2 point) { 95 | return glm_aabb2d_point(aabb, point); 96 | } 97 | 98 | CGLM_EXPORT 99 | bool 100 | glmc_aabb2d_contains(vec2 aabb[2], vec2 other[2]) { 101 | return glm_aabb2d_contains(aabb, other); 102 | } 103 | 104 | CGLM_EXPORT 105 | bool 106 | glmc_aabb2d_circle(vec2 aabb[2], vec3 s) { 107 | return glm_aabb2d_circle(aabb, s); 108 | } 109 | -------------------------------------------------------------------------------- /src/affine2d.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_translate2d_make(mat3 m, vec2 v) { 14 | glm_translate2d_make(m, v); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_translate2d_to(mat3 m, vec2 v, mat3 dest) { 20 | glm_translate2d_to(m, v, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_translate2d(mat3 m, vec2 v) { 26 | glm_translate2d(m, v); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_translate2d_x(mat3 m, float to) { 32 | glm_translate2d_x(m, to); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_translate2d_y(mat3 m, float to) { 38 | glm_translate2d_y(m, to); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_scale2d_to(mat3 m, vec2 v, mat3 dest) { 44 | glm_scale2d_to(m, v, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_scale2d_make(mat3 m, vec2 v) { 50 | glm_scale2d_make(m, v); 51 | } 52 | 53 | CGLM_EXPORT 54 | void 55 | glmc_scale2d(mat3 m, vec2 v) { 56 | glm_scale2d(m, v); 57 | } 58 | 59 | CGLM_EXPORT 60 | void 61 | glmc_scale2d_uni(mat3 m, float s) { 62 | glm_scale2d_uni(m, s); 63 | } 64 | 65 | CGLM_EXPORT 66 | void 67 | glmc_rotate2d_make(mat3 m, float angle) { 68 | glm_rotate2d_make(m, angle); 69 | } 70 | 71 | CGLM_EXPORT 72 | void 73 | glmc_rotate2d(mat3 m, float angle) { 74 | glm_rotate2d(m, angle); 75 | } 76 | 77 | CGLM_EXPORT 78 | void 79 | glmc_rotate2d_to(mat3 m, float angle, mat3 dest) { 80 | glm_rotate2d_to(m, angle, dest); 81 | } 82 | -------------------------------------------------------------------------------- /src/bezier.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | float 13 | glmc_bezier(float s, float p0, float c0, float c1, float p1) { 14 | return glm_bezier(s, p0, c0, c1, p1); 15 | } 16 | 17 | CGLM_EXPORT 18 | float 19 | glmc_hermite(float s, float p0, float t0, float t1, float p1) { 20 | return glm_hermite(s, p0, t0, t1, p1); 21 | } 22 | 23 | CGLM_EXPORT 24 | float 25 | glmc_decasteljau(float prm, float p0, float c0, float c1, float p1) { 26 | return glm_decasteljau(prm, p0, c0, c1, p1); 27 | } 28 | -------------------------------------------------------------------------------- /src/box.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_aabb_transform(vec3 box[2], mat4 m, vec3 dest[2]) { 14 | glm_aabb_transform(box, m, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_aabb_merge(vec3 box1[2], vec3 box2[2], vec3 dest[2]) { 20 | glm_aabb_merge(box1, box2, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_aabb_crop(vec3 box[2], vec3 cropBox[2], vec3 dest[2]) { 26 | glm_aabb_crop(box, cropBox, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_aabb_crop_until(vec3 box[2], 32 | vec3 cropBox[2], 33 | vec3 clampBox[2], 34 | vec3 dest[2]) { 35 | glm_aabb_crop_until(box, cropBox, clampBox, dest); 36 | } 37 | 38 | CGLM_EXPORT 39 | bool 40 | glmc_aabb_frustum(vec3 box[2], vec4 planes[6]) { 41 | return glm_aabb_frustum(box, planes); 42 | } 43 | 44 | CGLM_EXPORT 45 | void 46 | glmc_aabb_invalidate(vec3 box[2]) { 47 | glm_aabb_invalidate(box); 48 | } 49 | 50 | CGLM_EXPORT 51 | bool 52 | glmc_aabb_isvalid(vec3 box[2]) { 53 | return glm_aabb_isvalid(box); 54 | } 55 | 56 | CGLM_EXPORT 57 | float 58 | glmc_aabb_size(vec3 box[2]) { 59 | return glm_aabb_size(box); 60 | } 61 | 62 | CGLM_EXPORT 63 | float 64 | glmc_aabb_radius(vec3 box[2]) { 65 | return glm_aabb_radius(box); 66 | } 67 | 68 | CGLM_EXPORT 69 | void 70 | glmc_aabb_center(vec3 box[2], vec3 dest) { 71 | glm_aabb_center(box, dest); 72 | } 73 | 74 | CGLM_EXPORT 75 | bool 76 | glmc_aabb_aabb(vec3 box[2], vec3 other[2]) { 77 | return glm_aabb_aabb(box, other); 78 | } 79 | 80 | CGLM_EXPORT 81 | bool 82 | glmc_aabb_point(vec3 box[2], vec3 point) { 83 | return glm_aabb_point(box, point); 84 | } 85 | 86 | CGLM_EXPORT 87 | bool 88 | glmc_aabb_contains(vec3 box[2], vec3 other[2]) { 89 | return glm_aabb_contains(box, other); 90 | } 91 | 92 | CGLM_EXPORT 93 | bool 94 | glmc_aabb_sphere(vec3 box[2], vec4 s) { 95 | return glm_aabb_sphere(box, s); 96 | } 97 | -------------------------------------------------------------------------------- /src/clipspace/ortho_lh_no.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../../include/cglm/clipspace/ortho_lh_no.h" 9 | #include "../../include/cglm/call/clipspace/ortho_lh_no.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_ortho_lh_no(float left, float right, 14 | float bottom, float top, 15 | float nearZ, float farZ, 16 | mat4 dest) { 17 | glm_ortho_lh_no(left, right, 18 | bottom, top, 19 | nearZ, farZ, 20 | dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_ortho_aabb_lh_no(vec3 box[2], mat4 dest) { 26 | glm_ortho_aabb_lh_no(box, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_ortho_aabb_p_lh_no(vec3 box[2], float padding, mat4 dest) { 32 | glm_ortho_aabb_p_lh_no(box, padding, dest); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_ortho_aabb_pz_lh_no(vec3 box[2], float padding, mat4 dest) { 38 | glm_ortho_aabb_pz_lh_no(box, padding, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_ortho_default_lh_no(float aspect, mat4 dest) { 44 | glm_ortho_default_lh_no(aspect, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_ortho_default_s_lh_no(float aspect, float size, mat4 dest) { 50 | glm_ortho_default_s_lh_no(aspect, size, dest); 51 | } 52 | -------------------------------------------------------------------------------- /src/clipspace/ortho_lh_zo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../../include/cglm/clipspace/ortho_lh_zo.h" 9 | #include "../../include/cglm/call/clipspace/ortho_lh_zo.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_ortho_lh_zo(float left, float right, 14 | float bottom, float top, 15 | float nearZ, float farZ, 16 | mat4 dest) { 17 | glm_ortho_lh_zo(left, right, 18 | bottom, top, 19 | nearZ, farZ, 20 | dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_ortho_aabb_lh_zo(vec3 box[2], mat4 dest) { 26 | glm_ortho_aabb_lh_zo(box, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_ortho_aabb_p_lh_zo(vec3 box[2], float padding, mat4 dest) { 32 | glm_ortho_aabb_p_lh_zo(box, padding, dest); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_ortho_aabb_pz_lh_zo(vec3 box[2], float padding, mat4 dest) { 38 | glm_ortho_aabb_pz_lh_zo(box, padding, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_ortho_default_lh_zo(float aspect, mat4 dest) { 44 | glm_ortho_default_lh_zo(aspect, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_ortho_default_s_lh_zo(float aspect, float size, mat4 dest) { 50 | glm_ortho_default_s_lh_zo(aspect, size, dest); 51 | } 52 | -------------------------------------------------------------------------------- /src/clipspace/ortho_rh_no.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../../include/cglm/clipspace/ortho_rh_no.h" 9 | #include "../../include/cglm/call/clipspace/ortho_rh_no.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_ortho_rh_no(float left, float right, 14 | float bottom, float top, 15 | float nearZ, float farZ, 16 | mat4 dest) { 17 | glm_ortho_rh_no(left, right, 18 | bottom, top, 19 | nearZ, farZ, 20 | dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_ortho_aabb_rh_no(vec3 box[2], mat4 dest) { 26 | glm_ortho_aabb_rh_no(box, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_ortho_aabb_p_rh_no(vec3 box[2], float padding, mat4 dest) { 32 | glm_ortho_aabb_p_rh_no(box, padding, dest); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_ortho_aabb_pz_rh_no(vec3 box[2], float padding, mat4 dest) { 38 | glm_ortho_aabb_pz_rh_no(box, padding, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_ortho_default_rh_no(float aspect, mat4 dest) { 44 | glm_ortho_default_rh_no(aspect, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_ortho_default_s_rh_no(float aspect, float size, mat4 dest) { 50 | glm_ortho_default_s_rh_no(aspect, size, dest); 51 | } 52 | -------------------------------------------------------------------------------- /src/clipspace/ortho_rh_zo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../../include/cglm/clipspace/ortho_rh_zo.h" 9 | #include "../../include/cglm/call/clipspace/ortho_rh_zo.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_ortho_rh_zo(float left, float right, 14 | float bottom, float top, 15 | float nearZ, float farZ, 16 | mat4 dest) { 17 | glm_ortho_rh_zo(left, right, 18 | bottom, top, 19 | nearZ, farZ, 20 | dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_ortho_aabb_rh_zo(vec3 box[2], mat4 dest) { 26 | glm_ortho_aabb_rh_zo(box, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_ortho_aabb_p_rh_zo(vec3 box[2], float padding, mat4 dest) { 32 | glm_ortho_aabb_p_rh_zo(box, padding, dest); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_ortho_aabb_pz_rh_zo(vec3 box[2], float padding, mat4 dest) { 38 | glm_ortho_aabb_pz_rh_zo(box, padding, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_ortho_default_rh_zo(float aspect, mat4 dest) { 44 | glm_ortho_default_rh_zo(aspect, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_ortho_default_s_rh_zo(float aspect, float size, mat4 dest) { 50 | glm_ortho_default_s_rh_zo(aspect, size, dest); 51 | } 52 | -------------------------------------------------------------------------------- /src/clipspace/project_no.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../../include/cglm/clipspace/project_no.h" 9 | #include "../../include/cglm/call/clipspace/project_no.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_unprojecti_no(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { 14 | glm_unprojecti_no(pos, invMat, vp, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest) { 20 | glm_project_no(pos, m, vp, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | float 25 | glmc_project_z_no(vec3 pos, mat4 m) { 26 | return glm_project_z_no(pos, m); 27 | } 28 | -------------------------------------------------------------------------------- /src/clipspace/project_zo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../../include/cglm/clipspace/project_zo.h" 9 | #include "../../include/cglm/call/clipspace/project_zo.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_unprojecti_zo(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { 14 | glm_unprojecti_zo(pos, invMat, vp, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_project_zo(vec3 pos, mat4 m, vec4 vp, vec3 dest) { 20 | glm_project_zo(pos, m, vp, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | float 25 | glmc_project_z_zo(vec3 pos, mat4 m) { 26 | return glm_project_z_zo(pos, m); 27 | } 28 | -------------------------------------------------------------------------------- /src/clipspace/view_lh_no.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../../include/cglm/clipspace/view_lh_no.h" 9 | #include "../../include/cglm/call/clipspace/view_lh_no.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_lookat_lh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) { 14 | glm_lookat_lh_no(eye, center, up, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_look_lh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) { 20 | glm_look_lh_no(eye, dir, up, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_look_anyup_lh_no(vec3 eye, vec3 dir, mat4 dest) { 26 | glm_look_anyup_lh_no(eye, dir, dest); 27 | } 28 | -------------------------------------------------------------------------------- /src/clipspace/view_lh_zo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../../include/cglm/clipspace/view_lh_zo.h" 9 | #include "../../include/cglm/call/clipspace/view_lh_zo.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_lookat_lh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) { 14 | glm_lookat_lh_zo(eye, center, up, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_look_lh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) { 20 | glm_look_lh_zo(eye, dir, up, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_look_anyup_lh_zo(vec3 eye, vec3 dir, mat4 dest) { 26 | glm_look_anyup_lh_zo(eye, dir, dest); 27 | } 28 | -------------------------------------------------------------------------------- /src/clipspace/view_rh_no.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../../include/cglm/clipspace/view_rh_no.h" 9 | #include "../../include/cglm/call/clipspace/view_rh_no.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_lookat_rh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) { 14 | glm_lookat_rh_no(eye, center, up, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_look_rh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) { 20 | glm_look_rh_no(eye, dir, up, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_look_anyup_rh_no(vec3 eye, vec3 dir, mat4 dest) { 26 | glm_look_anyup_rh_no(eye, dir, dest); 27 | } 28 | -------------------------------------------------------------------------------- /src/clipspace/view_rh_zo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../../include/cglm/clipspace/view_rh_zo.h" 9 | #include "../../include/cglm/call/clipspace/view_rh_zo.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_lookat_rh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) { 14 | glm_lookat_rh_zo(eye, center, up, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_look_rh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) { 20 | glm_look_rh_zo(eye, dir, up, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_look_anyup_rh_zo(vec3 eye, vec3 dir, mat4 dest) { 26 | glm_look_anyup_rh_zo(eye, dir, dest); 27 | } 28 | -------------------------------------------------------------------------------- /src/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #ifndef cglm__config__h_ 9 | #define cglm__config__h_ 10 | 11 | #if defined(_WIN32) || defined(WIN32) 12 | 13 | /* Exclude rarely-used stuff from Windows headers */ 14 | # define WIN32_LEAN_AND_MEAN 15 | # include 16 | 17 | /* Windows Header Files: */ 18 | # include 19 | 20 | #endif 21 | 22 | #endif /* cglm__config__h_ */ 23 | -------------------------------------------------------------------------------- /src/curve.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | float 13 | glmc_smc(float s, mat4 m, vec4 c) { 14 | return glm_smc(s, m, c); 15 | } 16 | -------------------------------------------------------------------------------- /src/euler.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_euler_angles(mat4 m, vec3 dest) { 14 | glm_euler_angles(m, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_euler(vec3 angles, mat4 dest) { 20 | glm_euler(angles, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_euler_xyz(vec3 angles, mat4 dest) { 26 | glm_euler_xyz(angles, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_euler_zyx(vec3 angles, mat4 dest) { 32 | glm_euler_zyx(angles, dest); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_euler_zxy(vec3 angles, mat4 dest) { 38 | glm_euler_zxy(angles, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_euler_xzy(vec3 angles, mat4 dest) { 44 | glm_euler_xzy(angles, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_euler_yzx(vec3 angles, mat4 dest) { 50 | glm_euler_yzx(angles, dest); 51 | } 52 | 53 | CGLM_EXPORT 54 | void 55 | glmc_euler_yxz(vec3 angles, mat4 dest) { 56 | glm_euler_yxz(angles, dest); 57 | } 58 | 59 | CGLM_EXPORT 60 | void 61 | glmc_euler_by_order(vec3 angles, glm_euler_seq axis, mat4 dest) { 62 | glm_euler_by_order(angles, axis, dest); 63 | } 64 | 65 | CGLM_EXPORT 66 | void 67 | glmc_euler_xyz_quat(vec3 angles, versor dest) { 68 | glm_euler_xyz_quat(angles, dest); 69 | } 70 | 71 | CGLM_EXPORT 72 | void 73 | glmc_euler_xzy_quat(vec3 angles, versor dest) { 74 | glm_euler_xzy_quat(angles, dest); 75 | } 76 | 77 | CGLM_EXPORT 78 | void 79 | glmc_euler_yxz_quat(vec3 angles, versor dest) { 80 | glm_euler_yxz_quat(angles, dest); 81 | } 82 | 83 | CGLM_EXPORT 84 | void 85 | glmc_euler_yzx_quat(vec3 angles, versor dest) { 86 | glm_euler_yzx_quat(angles, dest); 87 | } 88 | 89 | CGLM_EXPORT 90 | void 91 | glmc_euler_zxy_quat(vec3 angles, versor dest) { 92 | glm_euler_zxy_quat(angles, dest); 93 | } 94 | 95 | CGLM_EXPORT 96 | void 97 | glmc_euler_zyx_quat(vec3 angles, versor dest) { 98 | glm_euler_zyx_quat(angles, dest); 99 | } 100 | -------------------------------------------------------------------------------- /src/frustum.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_frustum_planes(mat4 m, vec4 dest[6]) { 14 | glm_frustum_planes(m, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_frustum_corners(mat4 invMat, vec4 dest[8]) { 20 | glm_frustum_corners(invMat, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_frustum_center(vec4 corners[8], vec4 dest) { 26 | glm_frustum_center(corners, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_frustum_box(vec4 corners[8], mat4 m, vec3 box[2]) { 32 | glm_frustum_box(corners, m, box); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_frustum_corners_at(vec4 corners[8], 38 | float splitDist, 39 | float farDist, 40 | vec4 planeCorners[4]) { 41 | glm_frustum_corners_at(corners, splitDist, farDist, planeCorners); 42 | } 43 | -------------------------------------------------------------------------------- /src/io.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #define CGLM_LIB_SRC 9 | 10 | #include "../include/cglm/cglm.h" 11 | #include "../include/cglm/call.h" 12 | 13 | CGLM_EXPORT 14 | void 15 | glmc_mat4_print(mat4 matrix, 16 | FILE * __restrict ostream) { 17 | glm_mat4_print(matrix, ostream); 18 | } 19 | 20 | CGLM_EXPORT 21 | void 22 | glmc_mat3_print(mat3 matrix, 23 | FILE * __restrict ostream) { 24 | glm_mat3_print(matrix, ostream); 25 | } 26 | 27 | CGLM_EXPORT 28 | void 29 | glmc_vec4_print(vec4 vec, 30 | FILE * __restrict ostream) { 31 | glm_vec4_print(vec, ostream); 32 | } 33 | 34 | CGLM_EXPORT 35 | void 36 | glmc_vec3_print(vec3 vec, 37 | FILE * __restrict ostream) { 38 | glm_vec3_print(vec, ostream); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_versor_print(versor vec, 44 | FILE * __restrict ostream) { 45 | glm_versor_print(vec, ostream); 46 | } 47 | -------------------------------------------------------------------------------- /src/mat2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_mat2_make(const float * __restrict src, mat2 dest) { 14 | glm_mat2_make(src, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_mat2_copy(mat2 mat, mat2 dest) { 20 | glm_mat2_copy(mat, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_mat2_identity(mat2 m) { 26 | glm_mat2_identity(m); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_mat2_identity_array(mat2 * __restrict mats, size_t count) { 32 | glm_mat2_identity_array(mats, count); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_mat2_zero(mat2 m) { 38 | glm_mat2_zero(m); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_mat2_mul(mat2 m1, mat2 m2, mat2 dest) { 44 | glm_mat2_mul(m1, m2, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_mat2_mulv(mat2 m, vec2 v, vec2 dest) { 50 | glm_mat2_mulv(m, v, dest); 51 | } 52 | 53 | CGLM_EXPORT 54 | void 55 | glmc_mat2_transpose_to(mat2 mat, mat2 dest) { 56 | glm_mat2_transpose_to(mat, dest); 57 | } 58 | 59 | CGLM_EXPORT 60 | void 61 | glmc_mat2_transpose(mat2 m) { 62 | glm_mat2_transpose(m); 63 | } 64 | 65 | CGLM_EXPORT 66 | void 67 | glmc_mat2_scale(mat2 m, float s) { 68 | glm_mat2_scale(m, s); 69 | } 70 | 71 | CGLM_EXPORT 72 | void 73 | glmc_mat2_inv(mat2 mat, mat2 dest) { 74 | glm_mat2_inv(mat, dest); 75 | } 76 | 77 | CGLM_EXPORT 78 | void 79 | glmc_mat2_swap_col(mat2 mat, int col1, int col2) { 80 | glm_mat2_swap_col(mat, col1, col2); 81 | } 82 | 83 | CGLM_EXPORT 84 | void 85 | glmc_mat2_swap_row(mat2 mat, int row1, int row2) { 86 | glm_mat2_swap_row(mat, row1, row2); 87 | } 88 | 89 | CGLM_EXPORT 90 | float 91 | glmc_mat2_det(mat2 m) { 92 | return glm_mat2_det(m); 93 | } 94 | 95 | CGLM_EXPORT 96 | float 97 | glmc_mat2_trace(mat2 m) { 98 | return glm_mat2_trace(m); 99 | } 100 | 101 | CGLM_EXPORT 102 | float 103 | glmc_mat2_rmc(vec2 r, mat2 m, vec2 c) { 104 | return glm_mat2_rmc(r, m, c); 105 | } 106 | -------------------------------------------------------------------------------- /src/mat2x3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_mat2x3_copy(mat2x3 src, mat2x3 dest) { 14 | glm_mat2x3_copy(src, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_mat2x3_zero(mat2x3 m) { 20 | glm_mat2x3_zero(m); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_mat2x3_make(const float * __restrict src, mat2x3 dest) { 26 | glm_mat2x3_make(src, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_mat2x3_mul(mat2x3 m1, mat3x2 m2, mat3 dest) { 32 | glm_mat2x3_mul(m1, m2, dest); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_mat2x3_mulv(mat2x3 m, vec2 v, vec3 dest) { 38 | glm_mat2x3_mulv(m, v, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_mat2x3_transpose(mat2x3 src, mat3x2 dest) { 44 | glm_mat2x3_transpose(src, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_mat2x3_scale(mat2x3 m, float s) { 50 | glm_mat2x3_scale(m, s); 51 | } 52 | -------------------------------------------------------------------------------- /src/mat2x4.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_mat2x4_copy(mat2x4 src, mat2x4 dest) { 14 | glm_mat2x4_copy(src, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_mat2x4_zero(mat2x4 m) { 20 | glm_mat2x4_zero(m); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_mat2x4_make(const float * __restrict src, mat2x4 dest) { 26 | glm_mat2x4_make(src, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_mat2x4_mul(mat2x4 m1, mat4x2 m2, mat4 dest) { 32 | glm_mat2x4_mul(m1, m2, dest); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_mat2x4_mulv(mat2x4 m, vec2 v, vec4 dest) { 38 | glm_mat2x4_mulv(m, v, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_mat2x4_transpose(mat2x4 src, mat4x2 dest) { 44 | glm_mat2x4_transpose(src, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_mat2x4_scale(mat2x4 m, float s) { 50 | glm_mat2x4_scale(m, s); 51 | } 52 | -------------------------------------------------------------------------------- /src/mat3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_mat3_copy(mat3 mat, mat3 dest) { 14 | glm_mat3_copy(mat, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_mat3_identity(mat3 mat) { 20 | glm_mat3_identity(mat); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_mat3_zero(mat3 mat) { 26 | glm_mat3_zero(mat); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_mat3_identity_array(mat3 * __restrict mat, size_t count) { 32 | glm_mat3_identity_array(mat, count); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_mat3_mul(mat3 m1, mat3 m2, mat3 dest) { 38 | glm_mat3_mul(m1, m2, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_mat3_transpose_to(mat3 m, mat3 dest) { 44 | glm_mat3_transpose_to(m, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_mat3_transpose(mat3 m) { 50 | glm_mat3_transpose(m); 51 | } 52 | 53 | CGLM_EXPORT 54 | void 55 | glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest) { 56 | glm_mat3_mulv(m, v, dest); 57 | } 58 | 59 | CGLM_EXPORT 60 | float 61 | glmc_mat3_trace(mat3 m) { 62 | return glm_mat3_trace(m); 63 | } 64 | 65 | CGLM_EXPORT 66 | void 67 | glmc_mat3_quat(mat3 m, versor dest) { 68 | glm_mat3_quat(m, dest); 69 | } 70 | 71 | CGLM_EXPORT 72 | void 73 | glmc_mat3_scale(mat3 m, float s) { 74 | glm_mat3_scale(m, s); 75 | } 76 | 77 | CGLM_EXPORT 78 | float 79 | glmc_mat3_det(mat3 mat) { 80 | return glm_mat3_det(mat); 81 | } 82 | 83 | CGLM_EXPORT 84 | void 85 | glmc_mat3_inv(mat3 mat, mat3 dest) { 86 | glm_mat3_inv(mat, dest); 87 | } 88 | 89 | CGLM_EXPORT 90 | void 91 | glmc_mat3_swap_col(mat3 mat, int col1, int col2) { 92 | glm_mat3_swap_col(mat, col1, col2); 93 | } 94 | 95 | CGLM_EXPORT 96 | void 97 | glmc_mat3_swap_row(mat3 mat, int row1, int row2) { 98 | glm_mat3_swap_row(mat, row1, row2); 99 | } 100 | 101 | CGLM_EXPORT 102 | float 103 | glmc_mat3_rmc(vec3 r, mat3 m, vec3 c) { 104 | return glm_mat3_rmc(r, m, c); 105 | } 106 | 107 | CGLM_EXPORT 108 | void 109 | glmc_mat3_make(const float * __restrict src, mat3 dest) { 110 | glm_mat3_make(src, dest); 111 | } 112 | 113 | CGLM_EXPORT 114 | void 115 | glmc_mat3_textrans(float sx, float sy, float rot, float tx, float ty, mat3 dest) { 116 | glm_mat3_textrans(sx, sy, rot, tx, ty, dest); 117 | } 118 | -------------------------------------------------------------------------------- /src/mat3x2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_mat3x2_copy(mat3x2 src, mat3x2 dest) { 14 | glm_mat3x2_copy(src, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_mat3x2_zero(mat3x2 m) { 20 | glm_mat3x2_zero(m); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_mat3x2_make(const float * __restrict src, mat3x2 dest) { 26 | glm_mat3x2_make(src, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_mat3x2_mul(mat3x2 m1, mat2x3 m2, mat2 dest) { 32 | glm_mat3x2_mul(m1, m2, dest); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_mat3x2_mulv(mat3x2 m, vec3 v, vec2 dest) { 38 | glm_mat3x2_mulv(m, v, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_mat3x2_transpose(mat3x2 src, mat2x3 dest) { 44 | glm_mat3x2_transpose(src, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_mat3x2_scale(mat3x2 m, float s) { 50 | glm_mat3x2_scale(m, s); 51 | } 52 | -------------------------------------------------------------------------------- /src/mat3x4.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_mat3x4_copy(mat3x4 src, mat3x4 dest) { 14 | glm_mat3x4_copy(src, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_mat3x4_zero(mat3x4 m) { 20 | glm_mat3x4_zero(m); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_mat3x4_make(const float * __restrict src, mat3x4 dest) { 26 | glm_mat3x4_make(src, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_mat3x4_mul(mat3x4 m1, mat4x3 m2, mat4 dest) { 32 | glm_mat3x4_mul(m1, m2, dest); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_mat3x4_mulv(mat3x4 m, vec3 v, vec4 dest) { 38 | glm_mat3x4_mulv(m, v, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_mat3x4_transpose(mat3x4 src, mat4x3 dest) { 44 | glm_mat3x4_transpose(src, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_mat3x4_scale(mat3x4 m, float s) { 50 | glm_mat3x4_scale(m, s); 51 | } 52 | -------------------------------------------------------------------------------- /src/mat4x2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_mat4x2_copy(mat4x2 src, mat4x2 dest) { 14 | glm_mat4x2_copy(src, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_mat4x2_zero(mat4x2 m) { 20 | glm_mat4x2_zero(m); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_mat4x2_make(const float * __restrict src, mat4x2 dest) { 26 | glm_mat4x2_make(src, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_mat4x2_mul(mat4x2 m1, mat2x4 m2, mat2 dest) { 32 | glm_mat4x2_mul(m1, m2, dest); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_mat4x2_mulv(mat4x2 m, vec4 v, vec2 dest) { 38 | glm_mat4x2_mulv(m, v, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_mat4x2_transpose(mat4x2 src, mat2x4 dest) { 44 | glm_mat4x2_transpose(src, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_mat4x2_scale(mat4x2 m, float s) { 50 | glm_mat4x2_scale(m, s); 51 | } 52 | -------------------------------------------------------------------------------- /src/mat4x3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_mat4x3_copy(mat4x3 src, mat4x3 dest) { 14 | glm_mat4x3_copy(src, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_mat4x3_zero(mat4x3 m) { 20 | glm_mat4x3_zero(m); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_mat4x3_make(const float * __restrict src, mat4x3 dest) { 26 | glm_mat4x3_make(src, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | void 31 | glmc_mat4x3_mul(mat4x3 m1, mat3x4 m2, mat3 dest) { 32 | glm_mat4x3_mul(m1, m2, dest); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_mat4x3_mulv(mat4x3 m, vec4 v, vec3 dest) { 38 | glm_mat4x3_mulv(m, v, dest); 39 | } 40 | 41 | CGLM_EXPORT 42 | void 43 | glmc_mat4x3_transpose(mat4x3 src, mat3x4 dest) { 44 | glm_mat4x3_transpose(src, dest); 45 | } 46 | 47 | CGLM_EXPORT 48 | void 49 | glmc_mat4x3_scale(mat4x3 m, float s) { 50 | glm_mat4x3_scale(m, s); 51 | } 52 | -------------------------------------------------------------------------------- /src/noise.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | float 13 | glmc_perlin_vec4(vec4 p) { 14 | return glm_perlin_vec4(p); 15 | } 16 | 17 | CGLM_EXPORT 18 | float 19 | glmc_perlin_vec3(vec3 p) { 20 | return glm_perlin_vec3(p); 21 | } 22 | 23 | CGLM_EXPORT 24 | float 25 | glmc_perlin_vec2(vec2 p) { 26 | return glm_perlin_vec2(p); 27 | } 28 | -------------------------------------------------------------------------------- /src/plane.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_plane_normalize(vec4 plane) { 14 | glm_plane_normalize(plane); 15 | } 16 | -------------------------------------------------------------------------------- /src/project.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | void 13 | glmc_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { 14 | glm_unprojecti(pos, invMat, vp, dest); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) { 20 | glm_unproject(pos, m, vp, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { 26 | glm_project(pos, m, vp, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | float 31 | glmc_project_z(vec3 pos, mat4 m) { 32 | return glm_project_z(pos, m); 33 | } 34 | 35 | CGLM_EXPORT 36 | void 37 | glmc_pickmatrix(vec2 center, vec2 size, vec4 vp, mat4 dest) { 38 | glm_pickmatrix(center, size, vp, dest); 39 | } 40 | -------------------------------------------------------------------------------- /src/ray.c: -------------------------------------------------------------------------------- 1 | #include "../include/cglm/cglm.h" 2 | #include "../include/cglm/call.h" 3 | 4 | CGLM_EXPORT 5 | bool 6 | glmc_ray_triangle(vec3 origin, 7 | vec3 direction, 8 | vec3 v0, 9 | vec3 v1, 10 | vec3 v2, 11 | float *d) { 12 | return glm_ray_triangle(origin, direction, v0, v1, v2, d); 13 | } 14 | 15 | CGLM_EXPORT 16 | bool 17 | glmc_ray_sphere(vec3 origin, 18 | vec3 dir, 19 | vec4 s, 20 | float * __restrict t1, 21 | float * __restrict t2) { 22 | return glm_ray_sphere(origin, dir, s, t1, t2); 23 | } 24 | 25 | CGLM_EXPORT 26 | void 27 | glmc_ray_at(vec3 orig, vec3 dir, float t, vec3 point) { 28 | glm_ray_at(orig, dir, t, point); 29 | } 30 | -------------------------------------------------------------------------------- /src/sphere.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "../include/cglm/cglm.h" 9 | #include "../include/cglm/call.h" 10 | 11 | CGLM_EXPORT 12 | float 13 | glmc_sphere_radii(vec4 s) { 14 | return glm_sphere_radii(s); 15 | } 16 | 17 | CGLM_EXPORT 18 | void 19 | glmc_sphere_transform(vec4 s, mat4 m, vec4 dest) { 20 | glm_sphere_transform(s, m, dest); 21 | } 22 | 23 | CGLM_EXPORT 24 | void 25 | glmc_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { 26 | glm_sphere_merge(s1, s2, dest); 27 | } 28 | 29 | CGLM_EXPORT 30 | bool 31 | glmc_sphere_sphere(vec4 s1, vec4 s2) { 32 | return glm_sphere_sphere(s1, s2); 33 | } 34 | 35 | CGLM_EXPORT 36 | bool 37 | glmc_sphere_point(vec4 s, vec3 point) { 38 | return glm_sphere_point(s, point); 39 | } 40 | -------------------------------------------------------------------------------- /src/swift/empty.c: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8.2) 2 | 3 | # List all files containing tests. (Change as needed) 4 | set(TESTFILES 5 | runner.c 6 | src/test_euler.c 7 | src/test_bezier.c 8 | src/test_struct.c 9 | src/test_clamp.c 10 | src/test_common.c 11 | src/tests.c 12 | ) 13 | 14 | set(TEST_MAIN tests) 15 | set(TEST_RUNNER_PARAMS "") 16 | 17 | add_executable(${TEST_MAIN} ${TESTFILES}) 18 | target_compile_definitions(${TEST_MAIN} PRIVATE CGLM_DEFINE_PRINTS=1) 19 | 20 | if(CMAKE_SYSTEM_NAME STREQUAL WASI) 21 | target_compile_definitions(${TEST_MAIN} PRIVATE _WASI_EMULATED_PROCESS_CLOCKS=1) 22 | target_link_options(${TEST_MAIN} PRIVATE "-lwasi-emulated-process-clocks") 23 | endif() 24 | 25 | if(NOT MSVC) 26 | target_link_libraries(${TEST_MAIN} PRIVATE m) 27 | endif() 28 | 29 | target_link_libraries(${TEST_MAIN} PRIVATE cglm) 30 | target_include_directories(${TEST_MAIN} PRIVATE 31 | ${CMAKE_CURRENT_LIST_DIR}/include 32 | ${CMAKE_CURRENT_LIST_DIR}/src 33 | ) 34 | 35 | set_target_properties(${TEST_MAIN} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) 36 | 37 | if(LDFLAGS) 38 | target_compile_options(${TEST_MAIN} PRIVATE ${LDFLAGS}) 39 | endif() 40 | 41 | add_test( 42 | NAME cglm.${TEST_MAIN} 43 | COMMAND ${TEST_MAIN} ${TEST_RUNNER_PARAMS}) 44 | 45 | add_custom_target(check 46 | make 47 | COMMAND ${CMAKE_CTEST_COMMAND} -V 48 | DEPENDS cglm) 49 | -------------------------------------------------------------------------------- /test/runner.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "include/common.h" 9 | #include "tests.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | int 16 | main(int argc, const char * argv[]) { 17 | test_entry_t *entry; 18 | test_status_t st; 19 | int32_t i, count, passed, failed, maxlen; 20 | clock_t start, end, elapsed, total; 21 | (void)argc; 22 | (void)argv; 23 | 24 | passed = failed = maxlen = 0; 25 | total = 0.0; 26 | count = sizeof(tests) / sizeof(tests[0]); 27 | 28 | fprintf(stderr, CYAN "\nWelcome to cglm tests ( " RESET); 29 | glm_arch_print(stderr); 30 | fprintf(stderr, CYAN " )\n\n" RESET); 31 | 32 | srand((unsigned int)time(NULL)); 33 | 34 | for (i = 0; i < count; i++) { 35 | int32_t len; 36 | 37 | entry = tests + i; 38 | len = (int32_t)strlen(entry->name); 39 | 40 | maxlen = GLM_MAX(maxlen, len); 41 | } 42 | 43 | maxlen += 5; 44 | 45 | fprintf(stderr, 46 | BOLDWHITE " %-*s %-*s\n", 47 | maxlen, "Test Name", maxlen, "Elapsed Time"); 48 | 49 | for (i = 0; i < count; i++) { 50 | entry = tests + i; 51 | start = clock(); 52 | st = entry->entry(); 53 | end = clock(); 54 | elapsed = (end - start) / CLOCKS_PER_SEC; 55 | total += elapsed; 56 | 57 | if (!st.status) { 58 | fprintf(stderr, 59 | BOLDRED " " FAIL_TEXT BOLDWHITE " %s " RESET, entry->name); 60 | if (st.msg) { 61 | fprintf(stderr, 62 | YELLOW "- %s" RESET, 63 | st.msg); 64 | } 65 | 66 | fprintf(stderr, "\n"); 67 | 68 | failed++; 69 | } else { 70 | fprintf(stderr, GREEN " " OK_TEXT RESET " %-*s ", maxlen, entry->name); 71 | 72 | if (elapsed > 0.01) 73 | fprintf(stderr, YELLOW "%.2lus", elapsed); 74 | else 75 | fprintf(stderr, "0"); 76 | 77 | fprintf(stderr, "\n" RESET); 78 | passed++; 79 | } 80 | } 81 | 82 | if (failed == 0) { 83 | fprintf(stderr, 84 | BOLDGREEN "\n All tests passed " FINAL_TEXT "\n" RESET); 85 | } 86 | 87 | fprintf(stderr, 88 | CYAN "\ncglm test results (%0.2lus):\n" RESET 89 | "--------------------------\n" 90 | 91 | MAGENTA "%d" RESET " tests ran, " 92 | GREEN "%d" RESET " passed, " 93 | RED "%d" RESET " failed\n\n" RESET, 94 | total, 95 | count, 96 | passed, 97 | failed); 98 | 99 | return failed; 100 | } 101 | -------------------------------------------------------------------------------- /test/src/test_aabb2d.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | 10 | #ifndef CGLM_TEST_AABB2D_ONCE 11 | #define CGLM_TEST_AABB2D_ONCE 12 | 13 | /* Macros */ 14 | /* Deprecated */ 15 | 16 | #endif /* CGLM_TEST_VEC4_ONCE */ 17 | 18 | /* --- */ 19 | TEST_IMPL(GLM_PREFIX, aabb2d_sizev) { 20 | vec2 a[2] = {{10.0f, 10.0f}, {20.0f, 20.0f}}; 21 | vec2 size = {0}; 22 | 23 | GLM(aabb2d_sizev)(a, size); 24 | 25 | ASSERTIFY(test_assert_vec2_eq(size, (vec2){10.0f, 10.0f})) 26 | 27 | TEST_SUCCESS 28 | } 29 | -------------------------------------------------------------------------------- /test/src/test_affine2d_post.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | 10 | TEST_IMPL(GLM_PREFIX, translated2d) { 11 | mat3 m1, m2, tmp; 12 | vec2 v = { 1.2f, 3.4f }; 13 | 14 | test_rand_transform2d(m1); 15 | glm_mat3_copy(m1, m2); 16 | GLM(translated2d)(m2, v); 17 | 18 | glm_translate2d_make(tmp, v); 19 | glm_mat3_mul(tmp, m1, m1); 20 | 21 | test_assert_mat3_eq(m1, m2); 22 | 23 | TEST_SUCCESS 24 | } 25 | 26 | TEST_IMPL(GLM_PREFIX, translated2d_x) { 27 | mat3 m1, m2, tmp; 28 | float x = test_rand(); 29 | 30 | test_rand_transform2d(m1); 31 | glm_mat3_copy(m1, m2); 32 | GLM(translated2d_x)(m2, x); 33 | 34 | glm_translate2d_make(tmp, (vec2) { x, 0.0f }); 35 | glm_mat3_mul(tmp, m1, m1); 36 | 37 | test_assert_mat3_eq(m1, m2); 38 | 39 | TEST_SUCCESS 40 | } 41 | 42 | TEST_IMPL(GLM_PREFIX, translated2d_y) { 43 | mat3 m1, m2, tmp; 44 | float y = test_rand(); 45 | 46 | test_rand_transform2d(m1); 47 | glm_mat3_copy(m1, m2); 48 | GLM(translated2d_y)(m2, y); 49 | 50 | glm_translate2d_make(tmp, (vec2) { 0.0f, y }); 51 | glm_mat3_mul(tmp, m1, m1); 52 | 53 | test_assert_mat3_eq(m1, m2); 54 | 55 | TEST_SUCCESS 56 | } 57 | 58 | TEST_IMPL(GLM_PREFIX, rotated2d) { 59 | mat3 m1, m2, tmp; 60 | float a = test_rand(); 61 | 62 | test_rand_transform2d(m1); 63 | glm_mat3_copy(m1, m2); 64 | GLM(rotated2d)(m2, a); 65 | 66 | glm_rotate2d_make(tmp, a); 67 | glm_mat3_mul(tmp, m1, m1); 68 | 69 | test_assert_mat3_eq(m1, m2); 70 | 71 | TEST_SUCCESS 72 | } 73 | 74 | TEST_IMPL(GLM_PREFIX, scaled2d) { 75 | mat3 m1, m2, tmp; 76 | vec2 v = { test_rand(), test_rand() }; 77 | 78 | test_rand_transform2d(m1); 79 | glm_mat3_copy(m1, m2); 80 | GLM(scaled2d)(m2, v); 81 | 82 | glm_scale2d_make(tmp, v); 83 | glm_mat3_mul(tmp, m1, m1); 84 | 85 | test_assert_mat3_eq(m1, m2); 86 | 87 | TEST_SUCCESS 88 | } 89 | 90 | TEST_IMPL(GLM_PREFIX, scaled2d_uni) { 91 | mat3 m1, m2, tmp; 92 | float s = test_rand(); 93 | 94 | test_rand_transform2d(m1); 95 | glm_mat3_copy(m1, m2); 96 | GLM(scaled2d_uni)(m2, s); 97 | 98 | glm_scale2d_make(tmp, (vec2) { s, s }); 99 | glm_mat3_mul(tmp, m1, m1); 100 | 101 | test_assert_mat3_eq(m1, m2); 102 | 103 | TEST_SUCCESS 104 | } 105 | -------------------------------------------------------------------------------- /test/src/test_affine_mat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | 10 | #ifndef glm_affine_mat_test_guard 11 | #define glm_affine_mat_test_guard 12 | CGLM_INLINE 13 | void 14 | glm_inv_tr_raw(mat4 mat) { 15 | CGLM_ALIGN_MAT mat3 r; 16 | CGLM_ALIGN(8) vec3 t; 17 | 18 | /* rotate */ 19 | glm_mat4_pick3t(mat, r); 20 | glm_mat4_ins3(r, mat); 21 | 22 | /* translate */ 23 | glm_mat3_mulv(r, mat[3], t); 24 | glm_vec3_negate(t); 25 | glm_vec3_copy(t, mat[3]); 26 | } 27 | #endif 28 | 29 | TEST_IMPL(GLM_PREFIX, mul) { 30 | mat4 m1 = GLM_MAT4_IDENTITY_INIT; 31 | mat4 m2 = GLM_MAT4_IDENTITY_INIT; 32 | mat4 m3; 33 | mat4 m4 = GLM_MAT4_ZERO_INIT; 34 | int i, j, k; 35 | 36 | test_rand_mat4(m1); 37 | test_rand_mat4(m2); 38 | 39 | GLM(mul)(m1, m2, m3); 40 | for (i = 0; i < 4; i++) { 41 | for (j = 0; j < 4; j++) { 42 | for (k = 0; k < 4; k++) 43 | /* column-major */ 44 | m4[i][j] += m1[k][j] * m2[i][k]; 45 | } 46 | } 47 | 48 | ASSERTIFY(test_assert_mat4_eq(m3, m4)) 49 | 50 | /* test pre compiled */ 51 | GLM(mul)(m1, m2, m3); 52 | ASSERTIFY(test_assert_mat4_eq(m3, m4)) 53 | 54 | TEST_SUCCESS 55 | } 56 | 57 | TEST_IMPL(GLM_PREFIX, mul_rot) { 58 | mat4 m1 = GLM_MAT4_IDENTITY_INIT; 59 | mat4 m2 = GLM_MAT4_IDENTITY_INIT; 60 | mat4 m3; 61 | mat4 m4 = GLM_MAT4_ZERO_INIT; 62 | int i, j, k; 63 | 64 | glm_rotate(m1, frand48(), (vec3){frand48(), frand48(), frand48()}); 65 | glm_rotate(m2, frand48(), (vec3){frand48(), frand48(), frand48()}); 66 | 67 | GLM(mul_rot)(m1, m2, m3); 68 | for (i = 0; i < 4; i++) { 69 | for (j = 0; j < 4; j++) { 70 | for (k = 0; k < 4; k++) 71 | /* column-major */ 72 | m4[i][j] += m1[k][j] * m2[i][k]; 73 | } 74 | } 75 | 76 | ASSERTIFY(test_assert_mat4_eq(m3, m4)) 77 | 78 | /* test pre compiled */ 79 | GLM(mul_rot)(m1, m2, m3); 80 | ASSERTIFY(test_assert_mat4_eq(m3, m4)) 81 | 82 | TEST_SUCCESS 83 | } 84 | 85 | TEST_IMPL(GLM_PREFIX, inv_tr) { 86 | mat4 m1, m2; 87 | int i; 88 | 89 | for (i = 0; i < 10000; i++) { 90 | test_rand_mat4(m1); 91 | 92 | glm_mat4_copy(m1, m2); 93 | 94 | /* test inverse precise */ 95 | GLM(inv_tr)(m1); 96 | GLM(inv_tr)(m1); 97 | ASSERTIFY(test_assert_mat4_eq(m1, m2)) 98 | 99 | /* test inverse precise */ 100 | GLM(mat4_inv)(m1, m2); 101 | GLM(inv_tr)(m2); 102 | ASSERTIFY(test_assert_mat4_eq(m1, m2)) 103 | 104 | /* test with raw */ 105 | glm_mat4_copy(m1, m2); 106 | glm_inv_tr_raw(m2); 107 | GLM(inv_tr)(m1); 108 | ASSERTIFY(test_assert_mat4_eq(m1, m2)) 109 | } 110 | 111 | TEST_SUCCESS 112 | } 113 | -------------------------------------------------------------------------------- /test/src/test_bezier.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | 10 | CGLM_INLINE 11 | float 12 | test_bezier_plain(float s, float p0, float c0, float c1, float p1) { 13 | float x, xx, xxx, ss, sss; 14 | 15 | x = 1.0f - s; 16 | xx = x * x; 17 | xxx = xx * x; 18 | ss = s * s; 19 | sss = ss * s; 20 | 21 | return p0 * xxx + 3.0f * (c0 * s * xx + c1 * ss * x) + p1 * sss; 22 | } 23 | 24 | CGLM_INLINE 25 | float 26 | test_hermite_plain(float s, float p0, float t0, float t1, float p1) { 27 | float ss, sss; 28 | 29 | ss = s * s; 30 | sss = ss * s; 31 | 32 | return p0 * (2.0f * sss - 3.0f * ss + 1.0f) 33 | + t0 * (sss - 2.0f * ss + s) 34 | + p1 * (-2.0f * sss + 3.0f * ss) 35 | + t1 * (sss - ss); 36 | } 37 | 38 | TEST_IMPL(bezier) { 39 | float s, p0, p1, c0, c1, smc, Bs, Bs_plain; 40 | 41 | s = test_rand(); 42 | p0 = test_rand(); 43 | p1 = test_rand(); 44 | c0 = test_rand(); 45 | c1 = test_rand(); 46 | 47 | /* test cubic bezier */ 48 | smc = glm_smc(s, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}); 49 | Bs = glm_bezier(s, p0, c0, c1, p1); 50 | Bs_plain = test_bezier_plain(s, p0, c0, c1, p1); 51 | 52 | ASSERT(test_eq(Bs, Bs_plain)); 53 | ASSERTIFY(test_assert_eqf(smc, Bs_plain)) 54 | ASSERTIFY(test_assert_eqf(Bs, smc)) 55 | 56 | /* test cubic hermite */ 57 | smc = glm_smc(s, GLM_HERMITE_MAT, (vec4){p0, p1, c0, c1}); 58 | Bs = glm_hermite(s, p0, c0, c1, p1); 59 | Bs_plain = test_hermite_plain(s, p0, c0, c1, p1); 60 | 61 | ASSERT(test_eq(Bs, Bs_plain)); 62 | ASSERT(test_eq(smc, Bs_plain)); 63 | ASSERT(test_eq(Bs, smc)); 64 | 65 | TEST_SUCCESS 66 | } 67 | -------------------------------------------------------------------------------- /test/src/test_cam_lh_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | #include "../../include/cglm/clipspace/persp_lh_no.h" 10 | #include "../../include/cglm/call/clipspace/persp_lh_no.h" 11 | 12 | TEST_IMPL(GLM_PREFIX, perspective_lh_no) { 13 | mat4 dst; 14 | const float fovy = glm_rad(45.0f); 15 | const float aspect = 640/480.0f; 16 | const float zNearVal = 0.1f; 17 | const float zFarVal = 100.0f; 18 | 19 | GLM(perspective_lh_no)(fovy, aspect, zNearVal, zFarVal, dst); 20 | 21 | /* Sanity mk. I: longhand version */ 22 | ASSERT(test_eq(dst[0][0], 1.0f / (tanf(fovy / 2) * aspect))) 23 | ASSERT(test_eq(dst[1][1], 1.0f / tanf(fovy / 2))) 24 | ASSERT(test_eq(dst[2][2], (zFarVal + zNearVal) / (zFarVal - zNearVal))) 25 | ASSERT(test_eq(dst[2][3], 1.0f)) 26 | ASSERT(test_eq(dst[3][2], -2 * zFarVal * zNearVal / (zFarVal - zNearVal))) 27 | 28 | /* Sanity mk. II */ 29 | /*reference test data for glm_perspective_lh_no*/ 30 | mat4 cmp = {0}; 31 | cmp[0][0] = 1.8106601f; 32 | cmp[1][1] = 2.4142134f; 33 | cmp[2][2] = 1.0020020f; 34 | cmp[2][3] = 1.0000000f; 35 | cmp[3][2] = -0.2002002f; 36 | 37 | return test_assert_mat4_eq(dst, cmp); 38 | } 39 | -------------------------------------------------------------------------------- /test/src/test_cam_lh_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | #include "../../include/cglm/clipspace/persp_lh_zo.h" 10 | #include "../../include/cglm/call/clipspace/persp_lh_zo.h" 11 | 12 | TEST_IMPL(GLM_PREFIX, perspective_lh_zo) { 13 | mat4 dst; 14 | const float fovy = glm_rad(45.0f); 15 | const float aspect = 640/480.0f; 16 | const float zNearVal = 0.1f; 17 | const float zFarVal = 100.0f; 18 | 19 | GLM(perspective_lh_zo)(fovy, aspect, zNearVal, zFarVal, dst); 20 | 21 | /* Sanity mk. I: longhand version */ 22 | ASSERT(test_eq(dst[0][0], 1.0f / (tanf(fovy / 2) * aspect))) 23 | ASSERT(test_eq(dst[1][1], 1.0f / tanf(fovy / 2))) 24 | ASSERT(test_eq(dst[2][2], zFarVal / (zFarVal - zNearVal))) 25 | ASSERT(test_eq(dst[2][3], 1.0f)) 26 | ASSERT(test_eq(dst[3][2], -1 * zFarVal * zNearVal / (zFarVal - zNearVal))) 27 | 28 | /* Sanity mk. II */ 29 | /* "Reference values" generated by GLM's glm::perspectiveLH_ZO */ 30 | mat4 cmp = {0}; 31 | cmp[0][0] = 1.8106601f; 32 | cmp[1][1] = 2.4142134f; 33 | cmp[2][2] = 1.0010010f; 34 | cmp[2][3] = 1.0000000f; 35 | cmp[3][2] = -0.1001001f; 36 | 37 | return test_assert_mat4_eq(dst, cmp); 38 | } 39 | -------------------------------------------------------------------------------- /test/src/test_cam_rh_no.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | #include "../../include/cglm/clipspace/persp_rh_no.h" 10 | #include "../../include/cglm/call/clipspace/persp_rh_no.h" 11 | 12 | TEST_IMPL(GLM_PREFIX, perspective_rh_no) { 13 | mat4 dst; 14 | const float fovy = glm_rad(45.0f); 15 | const float aspect = 640/480.0f; 16 | const float zNearVal = 0.1f; 17 | const float zFarVal = 100.0f; 18 | 19 | GLM(perspective_rh_no)(fovy, aspect, zNearVal, zFarVal, dst); 20 | 21 | /* Sanity mk. I: longhand version */ 22 | ASSERT(test_eq(dst[0][0], 1.0f / (tanf(fovy / 2) * aspect))) 23 | ASSERT(test_eq(dst[1][1], 1.0f / tanf(fovy / 2))) 24 | ASSERT(test_eq(dst[2][2], -1.0f * (zFarVal + zNearVal) / (zFarVal - zNearVal))) 25 | ASSERT(test_eq(dst[2][3], -1.0f)) 26 | ASSERT(test_eq(dst[3][2], -2 * zFarVal * zNearVal / (zFarVal - zNearVal))) 27 | 28 | /* Sanity mk. II */ 29 | /*reference test data for glm_perspective_rh_no*/ 30 | mat4 cmp = {0}; 31 | cmp[0][0] = 1.8106601f; 32 | cmp[1][1] = 2.4142134f; 33 | cmp[2][2] = -1.0020020f; 34 | cmp[2][3] = -1.0000000f; 35 | cmp[3][2] = -0.2002002f; 36 | 37 | return test_assert_mat4_eq(dst, cmp); 38 | } 39 | -------------------------------------------------------------------------------- /test/src/test_cam_rh_zo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | #include "../../include/cglm/clipspace/persp_rh_zo.h" 10 | #include "../../include/cglm/call/clipspace/persp_rh_zo.h" 11 | 12 | TEST_IMPL(GLM_PREFIX, perspective_rh_zo) { 13 | mat4 dst; 14 | const float fovy = glm_rad(45.0f); 15 | const float aspect = 640/480.0f; 16 | const float zNearVal = 0.1f; 17 | const float zFarVal = 100.0f; 18 | 19 | GLM(perspective_rh_zo)(fovy, aspect, zNearVal, zFarVal, dst); 20 | 21 | /* Sanity mk. I: longhand version */ 22 | ASSERT(test_eq(dst[0][0], 1 / (tanf(fovy / 2) * aspect))) 23 | ASSERT(test_eq(dst[1][1], 1 / tanf(fovy / 2))) 24 | ASSERT(test_eq(dst[2][2], zFarVal / (zNearVal - zFarVal))) 25 | ASSERT(test_eq(dst[2][3], -1.0f)) 26 | ASSERT(test_eq(dst[3][2], -1 * zFarVal * zNearVal / (zFarVal - zNearVal))) 27 | 28 | /* Sanity mk. II */ 29 | /*reference test data for glm_perspective_rh_zo*/ 30 | mat4 cmp = {0}; 31 | cmp[0][0] = 1.8106601f; 32 | cmp[1][1] = 2.4142134f; 33 | cmp[2][2] = -1.0010010f; 34 | cmp[2][3] = -1.0000000f; 35 | cmp[3][2] = -0.1001001f; 36 | 37 | return test_assert_mat4_eq(dst, cmp); 38 | } 39 | -------------------------------------------------------------------------------- /test/src/test_clamp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | 10 | TEST_IMPL(clamp) { 11 | vec3 v3 = {15.07f, 0.4f, 17.3f}; 12 | vec4 v4 = {5.07f, 2.3f, 1.3f, 1.4f}; 13 | 14 | ASSERT(glm_eq(glm_clamp(1.6f, 0.0f, 1.0f), 1.0f)) 15 | ASSERT(glm_eq(glm_clamp(-1.6f, 0.0f, 1.0f), 0.0f)) 16 | ASSERT(glm_eq(glm_clamp(0.6f, 0.0f, 1.0f), 0.6f)) 17 | 18 | glm_vec3_clamp(v3, 0.0, 1.0); 19 | glm_vec4_clamp(v4, 1.5, 3.0); 20 | 21 | ASSERT(glm_eq(v3[0], 1.0f)) 22 | ASSERT(glm_eq(v3[1], 0.4f)) 23 | ASSERT(glm_eq(v3[2], 1.0f)) 24 | 25 | ASSERT(glm_eq(v4[0], 3.0f)) 26 | ASSERT(glm_eq(v4[1], 2.3f)) 27 | ASSERT(glm_eq(v4[2], 1.5f)) 28 | ASSERT(glm_eq(v4[3], 1.5f)) 29 | 30 | TEST_SUCCESS 31 | } 32 | -------------------------------------------------------------------------------- /test/src/test_euler.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | 10 | TEST_IMPL(euler) { 11 | mat4 rot1, rot2; 12 | vec3 inAngles, outAngles; 13 | 14 | inAngles[0] = glm_rad(-45.0f); /* X angle */ 15 | inAngles[1] = glm_rad(88.0f); /* Y angle */ 16 | inAngles[2] = glm_rad(18.0f); /* Z angle */ 17 | 18 | glm_euler_xyz(inAngles, rot1); 19 | 20 | /* extract angles */ 21 | glmc_euler_angles(rot1, outAngles); 22 | 23 | /* angles must be equal in that range */ 24 | ASSERTIFY(test_assert_vec3_eq(inAngles, outAngles)) 25 | 26 | /* matrices must be equal */ 27 | glmc_euler_xyz(outAngles, rot2); 28 | ASSERTIFY(test_assert_mat4_eq(rot1, rot2)) 29 | 30 | /* change range */ 31 | inAngles[0] = glm_rad(-145.0f); /* X angle */ 32 | inAngles[1] = glm_rad(818.0f); /* Y angle */ 33 | inAngles[2] = glm_rad(181.0f); /* Z angle */ 34 | 35 | glm_euler_xyz(inAngles, rot1); 36 | glmc_euler_angles(rot1, outAngles); 37 | 38 | /* angles may not be equal but matrices MUST! */ 39 | 40 | /* matrices must be equal */ 41 | glmc_euler_xyz(outAngles, rot2); 42 | ASSERTIFY(test_assert_mat4_eq(rot1, rot2)) 43 | 44 | TEST_SUCCESS 45 | } 46 | -------------------------------------------------------------------------------- /test/src/test_noise.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | 10 | TEST_IMPL(GLM_PREFIX, perlin_vec4) { 11 | vec4 p1[] = { 12 | {0.1f, 0.2f, 0.3f, 0.4f}, 13 | {0.2f, 0.3f, 0.4f, 0.5f}, 14 | {0.3f, 0.4f, 0.5f, 0.6f}, 15 | {0.4f, 0.5f, 0.6f, 0.7f}, 16 | {0.5f, 0.6f, 0.7f, 0.8f}, 17 | {0.6f, 0.7f, 0.8f, 0.9f}, 18 | {0.7f, 0.8f, 0.9f, 1.0f}, 19 | {0.8f, 0.9f, 1.0f, 1.1f}, 20 | {0.9f, 1.0f, 1.1f, 1.2f}, 21 | {1.0f, 1.1f, 1.2f, 1.3f}, 22 | }; 23 | 24 | /* expected values calculated by glm::perlin */ 25 | float e[] = { 26 | -0.5091819763183594f, 27 | -0.4375732541084290f, 28 | -0.3212279379367828f, 29 | -0.2279999703168869f, 30 | -0.1577337533235550f, 31 | -0.0445968918502331f, 32 | 0.1069696992635727f, 33 | 0.2067739963531494f, 34 | 0.2106968611478806f, 35 | 0.1397782564163208f 36 | }; 37 | 38 | for (int i = 0; i < 10; i++) { 39 | ASSERT(test_eq(GLM(perlin_vec4)(p1[i]), e[i])); 40 | } 41 | 42 | TEST_SUCCESS 43 | } 44 | 45 | TEST_IMPL(GLM_PREFIX, perlin_vec3) { 46 | vec3 p1[] = { 47 | {0.1f, 0.2f, 0.3f}, 48 | {0.2f, 0.3f, 0.4f}, 49 | {0.3f, 0.4f, 0.5f}, 50 | {0.4f, 0.5f, 0.6f}, 51 | {0.5f, 0.6f, 0.7f}, 52 | {0.6f, 0.7f, 0.8f}, 53 | {0.7f, 0.8f, 0.9f}, 54 | {0.8f, 0.9f, 1.0f}, 55 | {0.9f, 1.0f, 1.1f}, 56 | {1.0f, 1.1f, 1.2f}, 57 | }; 58 | 59 | /* expected values calculated by glm::perlin */ 60 | float e[] = { 61 | -0.2909241318702698f, 62 | -0.4667602181434631f, 63 | -0.4679279625415802f, 64 | -0.2616460621356964f, 65 | 0.0562822706997395f, 66 | 0.3178773224353790f, 67 | 0.3981811404228210f, 68 | 0.3011017739772797f, 69 | 0.1263920217752457f, 70 | -0.0602480024099350f 71 | }; 72 | 73 | for (int i = 0; i < 10; i++) { 74 | ASSERT(test_eq(GLM(perlin_vec3)(p1[i]), e[i])); 75 | } 76 | 77 | TEST_SUCCESS 78 | } 79 | 80 | 81 | TEST_IMPL(GLM_PREFIX, perlin_vec2) { 82 | vec2 p1[] = { 83 | {0.1f, 0.2f}, 84 | {0.2f, 0.3f}, 85 | {0.3f, 0.4f}, 86 | {0.4f, 0.5f}, 87 | {0.5f, 0.6f}, 88 | {0.6f, 0.7f}, 89 | {0.7f, 0.8f}, 90 | {0.8f, 0.9f}, 91 | {0.9f, 1.0f}, 92 | {1.0f, 1.1f}, 93 | }; 94 | 95 | /* expected values calculated by glm::perlin */ 96 | float e[] = { 97 | 0.2841092348098755f, 98 | 0.2328013032674789f, 99 | -0.0017980185803026f, 100 | -0.3300299644470215f, 101 | -0.5998955368995667f, 102 | -0.6914522647857666f, 103 | -0.5896517634391785f, 104 | -0.3778679668903351f, 105 | -0.1557840555906296f, 106 | 0.0453133136034012f 107 | }; 108 | 109 | for (int i = 0; i < 10; i++) { 110 | ASSERT(test_eq(GLM(perlin_vec2)(p1[i]), e[i])); 111 | } 112 | 113 | TEST_SUCCESS 114 | } 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /test/src/test_plane.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | 10 | TEST_IMPL(GLM_PREFIX, plane_normalize) { 11 | vec4 p1 = {2.0f, -3.0f, 4.0f, 5.0f}, p2 = {2.0f, -3.0f, 4.0f, 5.0f}; 12 | float s = 1.0f; 13 | float norm; 14 | 15 | GLM(plane_normalize)(p2); 16 | 17 | norm = sqrtf(p1[0] * p1[0] + p1[1] * p1[1] + p1[2] * p1[2]); 18 | if (norm == 0.0f) { 19 | ASSERT(test_eq(p1[0], 0.0f)) 20 | ASSERT(test_eq(p1[1], 0.0f)) 21 | ASSERT(test_eq(p1[2], 0.0f)) 22 | ASSERT(test_eq(p1[3], 0.0f)) 23 | 24 | TEST_SUCCESS 25 | } 26 | 27 | norm = s / norm; 28 | 29 | ASSERT(test_eq(p1[0] * norm, p2[0])) 30 | ASSERT(test_eq(p1[1] * norm, p2[1])) 31 | ASSERT(test_eq(p1[2] * norm, p2[2])) 32 | ASSERT(test_eq(p1[3] * norm, p2[3])) 33 | 34 | glm_vec4_zero(p1); 35 | GLM(plane_normalize)(p1); 36 | ASSERTIFY(test_assert_vec4_eq(p1, GLM_VEC4_ZERO)) 37 | 38 | TEST_SUCCESS 39 | } 40 | -------------------------------------------------------------------------------- /test/src/test_ray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | #include "test_common.h" 9 | 10 | TEST_IMPL(GLM_PREFIX, ray_triangle) { 11 | /* Check whether a simple hit is recognized with the right distance */ 12 | vec3 origin = { 0.0f, 0.0f, 0.0f}; 13 | vec3 direction = { 1.0f, 0.0f, 0.0f}; 14 | vec3 opposite = {-1.0f, 0.0f, 0.0f}; 15 | vec3 v0 = { 5.0f, -1.0f, 1.0f}; 16 | vec3 v1 = { 5.0f, -1.0f, -1.0f}; 17 | vec3 v2 = { 5.0f, 1.0f, 0.0f}; 18 | float d; 19 | bool hit; 20 | 21 | hit = GLM(ray_triangle)(origin, direction, v0, v1, v2, &d); 22 | ASSERT(hit); 23 | ASSERT(fabsf(d - 5.0f) <= 0.0000009f); 24 | 25 | /* Check whether a simple miss works */ 26 | hit = GLM(ray_triangle)(origin, opposite, v0, v1, v2, &d); 27 | ASSERT(!hit); 28 | 29 | /* Check that we can disregard distance and pass NULL pointer instead */ 30 | hit = GLM(ray_triangle)(origin, direction, v0, v1, v2, NULL); 31 | ASSERT(hit); 32 | 33 | TEST_SUCCESS 34 | } 35 | 36 | TEST_IMPL(GLM_PREFIX, ray_sphere) { 37 | vec4 sphere = {5.0f, 0.0f, 0.0f, 1.0f}; /* Sphere: center at (5, 0, 0) with radius 1 */ 38 | float t1, t2; 39 | bool hit; 40 | 41 | /* Case 1: Ray misses the sphere */ 42 | hit = GLM(ray_sphere)((vec3){10.0f, 3.0f, 0.0f}, (vec3){1.0f, 0.0f, 0.0f}, sphere, &t1, &t2); 43 | ASSERT(!hit); /* Expect no intersection */ 44 | 45 | /* Case 2: Ray starts inside the sphere */ 46 | hit = GLM(ray_sphere)((vec3){5.0f, 0.5f, 0.0f}, (vec3){1.0f, 0.0f, 0.0f}, sphere, &t1, &t2); 47 | ASSERT(hit); /* Expect an intersection */ 48 | ASSERT(t1 < 0 && t2 > 0); /* Ray exits at t2 */ 49 | 50 | /* Case 3: Ray intersects the sphere from outside */ 51 | hit = GLM(ray_sphere)((vec3){0.0f, 0.0f, 0.0f}, (vec3){1.0f, 0.0f, 0.0f}, sphere, &t1, &t2); 52 | ASSERT(hit); /* Expect an intersection */ 53 | ASSERT(t1 > 0 && t2 > 0); /* Intersections at t1 and t2 */ 54 | 55 | TEST_SUCCESS 56 | } 57 | 58 | TEST_IMPL(GLM_PREFIX, ray_at) { 59 | vec3 origin = {0.0f, 0.0f, 0.0f}; 60 | vec3 direction = {1.0f, 1.0f, 1.0f}; /* Diagonal direction */ 61 | float distance = sqrtf(3.0f); /* Distance along the ray; sqrt(3) for unit length due to direction normalization */ 62 | vec3 result; 63 | 64 | /* Normalize the direction to ensure accurate distance measurement */ 65 | glm_vec3_normalize(direction); 66 | 67 | GLM(ray_at)(origin, direction, distance, result); 68 | ASSERT(fabsf(result[0] - 1.0f) <= 0.0000009f); /* Expecting to be 1 unit along the x-axis */ 69 | ASSERT(fabsf(result[1] - 1.0f) <= 0.0000009f); /* Expecting to be 1 unit along the y-axis */ 70 | ASSERT(fabsf(result[2] - 1.0f) <= 0.0000009f); /* Expecting to be 1 unit along the z-axis */ 71 | 72 | TEST_SUCCESS 73 | } 74 | -------------------------------------------------------------------------------- /test/src/tests.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c), Recep Aslantas. 3 | * 4 | * MIT License (MIT), http://opensource.org/licenses/MIT 5 | * Full license can be found in the LICENSE file 6 | */ 7 | 8 | /* test inline */ 9 | /*---------------------------------------------------------------------------*/ 10 | 11 | 12 | #define GLM_PREFIX glm_ 13 | #define GLM(X) (glm_ ## X) 14 | 15 | #include "test_vec2.h" 16 | #include "test_vec3.h" 17 | #include "test_vec4.h" 18 | #include "test_ivec2.h" 19 | #include "test_ivec3.h" 20 | #include "test_ivec4.h" 21 | #include "test_mat2.h" 22 | #include "test_mat2x3.h" 23 | #include "test_mat2x4.h" 24 | #include "test_mat3.h" 25 | #include "test_mat3x2.h" 26 | #include "test_mat3x4.h" 27 | #include "test_mat4.h" 28 | #include "test_mat4x2.h" 29 | #include "test_mat4x3.h" 30 | #include "test_quat.h" 31 | #include "test_project.h" 32 | #include "test_plane.h" 33 | #include "test_noise.h" 34 | #include "test_affine.h" 35 | #include "test_affine2d.h" 36 | #include "test_affine2d_post.h" 37 | #include "test_affine_mat.h" 38 | #include "test_aabb2d.h" 39 | #include "test_ray.h" 40 | #include "test_cam.h" 41 | #include "test_cam_lh_no.h" 42 | #include "test_cam_lh_zo.h" 43 | #include "test_cam_rh_no.h" 44 | #include "test_cam_rh_zo.h" 45 | #include "test_euler_to_quat_rh.h" 46 | #include "test_euler_to_quat_lh.h" 47 | 48 | #undef GLM 49 | #undef GLM_PREFIX 50 | 51 | /* test pre-compiled */ 52 | /*---------------------------------------------------------------------------*/ 53 | 54 | #define GLM_PREFIX glmc_ 55 | #define GLM(X) (glmc_ ## X) 56 | 57 | #include "test_vec2.h" 58 | #include "test_vec3.h" 59 | #include "test_vec4.h" 60 | #include "test_ivec2.h" 61 | #include "test_ivec3.h" 62 | #include "test_ivec4.h" 63 | #include "test_mat2.h" 64 | #include "test_mat2x3.h" 65 | #include "test_mat2x4.h" 66 | #include "test_mat3.h" 67 | #include "test_mat3x2.h" 68 | #include "test_mat3x4.h" 69 | #include "test_mat4.h" 70 | #include "test_mat4x2.h" 71 | #include "test_mat4x3.h" 72 | #include "test_quat.h" 73 | #include "test_project.h" 74 | #include "test_plane.h" 75 | #include "test_noise.h" 76 | #include "test_affine.h" 77 | #include "test_affine2d.h" 78 | #include "test_affine_mat.h" 79 | #include "test_aabb2d.h" 80 | #include "test_ray.h" 81 | #include "test_cam.h" 82 | #include "test_cam_lh_no.h" 83 | #include "test_cam_lh_zo.h" 84 | #include "test_cam_rh_no.h" 85 | #include "test_cam_rh_zo.h" 86 | #include "test_euler_to_quat_rh.h" 87 | #include "test_euler_to_quat_lh.h" 88 | 89 | #undef GLM 90 | #undef GLM_PREFIX 91 | 92 | /*---------------------------------------------------------------------------*/ 93 | -------------------------------------------------------------------------------- /win/.gitignore: -------------------------------------------------------------------------------- 1 | !cglm.sln 2 | 3 | !cglm.vcxproj 4 | !cglm.vcxproj.filters 5 | 6 | !cglm-test.vcxproj 7 | !cglm-test.vcxproj.filters 8 | 9 | !packages.config 10 | -------------------------------------------------------------------------------- /win/build.bat: -------------------------------------------------------------------------------- 1 | msbuild cglm.vcxproj /p:Configuration=Release 2 | --------------------------------------------------------------------------------