### Defining Install Option in Meson Source: https://github.com/recp/cglm/blob/master/meson_options.txt Defines a boolean option named `install`. It controls whether the library, headers, and pkg-config files are included when the `install` target is built. The default value is `true`, enabling installation by default. ```Meson option('install', type : 'boolean', value : true, description : 'Include the library, headers, and pkg-config file in the install target') ``` -------------------------------- ### Define Installation Rules for Library (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Specifies installation rules for the main library target, including where the built library (shared/static/runtime) should be placed in the installation directory structure. ```CMake # Install install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) ``` -------------------------------- ### Building cglm with Meson Source: https://github.com/recp/cglm/blob/master/docs/source/build.rst These Bash commands outline the standard procedure to build the cglm library using the Meson build system. It involves configuring the project with meson, compiling with ninja, and optionally installing the library system-wide. ```bash $ meson build # [Optional] --default-library=static $ cd build $ ninja $ sudo ninja install # [Optional] ``` -------------------------------- ### Building cglm with Autotools (Bash) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Provides standard command-line steps to build the cglm library using the Autotools system, including preparing configuration scripts, configuring, compiling, and installing. ```bash $ sh autogen.sh $ ./configure $ make $ make check # [Optional] $ [sudo] make install # [Optional] ``` -------------------------------- ### Struct API Matrix Example - C Source: https://github.com/recp/cglm/blob/master/README.md Provides a specific example demonstrating the Struct API with matrix operations. It shows initializing a `mat4s` using a constant `GLMS_MAT4_IDENTITY_INIT` and computing its inverse using `glms_mat4_inv`, highlighting the return-by-value approach. ```C #include mat4s mat = GLMS_MAT4_IDENTITY_INIT; mat4s inv = glms_mat4_inv(mat); ``` -------------------------------- ### Define Installation Rules for Headers (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Specifies installation rules for the public header files, ensuring the contents of the 'include/cglm' directory are installed to the appropriate header installation directory. ```CMake install(DIRECTORY include/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PATTERN ".*" EXCLUDE) ``` -------------------------------- ### Configuring cglm Build Options with Meson Source: https://github.com/recp/cglm/blob/master/docs/source/build.rst This Meson snippet shows common configuration options that can be applied during the meson setup phase. It allows specifying the C standard, build type, default library type (static/shared), and whether tests are enabled. ```meson c_std=c11 buildtype=release default_library=shared enable_tests=false # to run tests: ninja test ``` -------------------------------- ### Configure and Install Pkgconfig File (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Sets variables required for a pkg-config (.pc) file, configures the template file ('cglm.pc.in') with project-specific details, and installs the resulting .pc file to the appropriate pkg-config directory. ```CMake set(PACKAGE_NAME ${PROJECT_NAME}) set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix ${CMAKE_INSTALL_PREFIX}) if (IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") set(includedir "${CMAKE_INSTALL_INCLUDEDIR}") else() set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") endif() if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") set(libdir "${CMAKE_INSTALL_LIBDIR}") else() set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") endif() set(PACKAGE_VERSION "${PROJECT_VERSION}") configure_file(cglm.pc.in cglm.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cglm.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) ``` -------------------------------- ### Building cglm with CMake (Bash) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Provides standard command-line steps to build the cglm library using CMake on platforms where `make` is available. Includes optional arguments for shared build and installation. ```bash $ mkdir build $ cd build $ cmake .. # [Optional] -DCGLM_SHARED=ON $ make $ sudo make install # [Optional] ``` -------------------------------- ### Include GNU Install Dirs and CPack (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Includes standard CMake modules for determining installation directories based on GNU conventions and includes CPack for creating software packages. ```CMake include(GNUInstallDirs) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) if(NOT CPack_CMake_INCLUDED) include(CPack) endif() ``` -------------------------------- ### Initialize Project and Minimum Version (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Sets the minimum required CMake version (3.13) and initializes the project with its name, version, homepage URL, description, and supported languages (C). This is typically the starting point of any CMakeLists.txt file. ```CMake cmake_minimum_required(VERSION 3.13) project(cglm VERSION 0.9.6 HOMEPAGE_URL https://github.com/recp/cglm DESCRIPTION "OpenGL Mathematics (glm) for C" LANGUAGES C ) ``` -------------------------------- ### Using cglm Header-Only in CMake Project Source: https://github.com/recp/cglm/blob/master/docs/source/build.rst This CMake example demonstrates how to integrate cglm into a project as a header-only library. It requires adding cglm as a subdirectory and linking your executable against the cglm_headers target, avoiding the need to build or install cglm. ```cmake cmake_minimum_required(VERSION 3.8.2) project() add_executable(${PROJECT_NAME} src/main.c) target_link_libraries(${LIBRARY_NAME} PRIVATE cglm_headers) add_subdirectory(external/cglm/ EXCLUDE_FROM_ALL) ``` -------------------------------- ### Using cglm in Meson Project Source: https://github.com/recp/cglm/blob/master/docs/source/build.rst This Meson build file example shows how to find and use the cglm dependency within another Meson project. It assumes cglm is available as a subproject or system dependency and links it to an executable. ```meson # Clone cglm or create a cglm.wrap under /subprojects project('name', 'c') cglm_dep = dependency('cglm', fallback : 'cglm', 'cglm_dep') executable('exe', 'src/main.c', dependencies : cglm_dep) ``` -------------------------------- ### Building cglm with Autotools Source: https://github.com/recp/cglm/blob/master/docs/source/build.rst These Bash commands provide the standard build procedure for cglm using the Autotools build system. It involves running the autogen script, configuring the build, compiling with make, optionally running tests, and installing the library. ```bash $ sh autogen.sh $ ./configure $ make $ make check # run tests (optional) $ [sudo] make install # install to system (optional) ``` -------------------------------- ### Using cglm Linked in CMake Project Source: https://github.com/recp/cglm/blob/master/docs/source/build.rst This CMake example shows how to integrate cglm when it is built and linked as a library. It involves adding cglm as a subdirectory and linking your executable against the cglm target. ```cmake cmake_minimum_required(VERSION 3.8.2) project() add_executable(${PROJECT_NAME} src/main.c) target_link_libraries(${LIBRARY_NAME} PRIVATE cglm) add_subdirectory(external/cglm/) ``` -------------------------------- ### Building cglm with CMake Source: https://github.com/recp/cglm/blob/master/docs/source/build.rst These Bash commands outline the standard procedure to build the cglm library using CMake. It involves creating a build directory, configuring the project with cmake, compiling with make, and optionally installing the library system-wide. ```bash $ mkdir build $ cd build $ cmake .. # [Optional] -DCGLM_SHARED=ON $ make $ sudo make install # [Optional] ``` -------------------------------- ### Configure Target Include Directories (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Specifies the include directories for the target. It distinguishes between the installation interface (where headers will be installed) and the build interface (where headers are found during the build process), including both public headers and private source directories. ```CMake target_include_directories(${PROJECT_NAME} PUBLIC $ $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src ) ``` -------------------------------- ### Defining Core Vector and Matrix Types in cglm C Source: https://github.com/recp/cglm/blob/master/docs/source/getting_started.rst This code snippet defines the fundamental vector and matrix types used throughout the cglm library using C typedefs. These types are implemented as fixed-size arrays, not structs, enabling direct compatibility with APIs like OpenGL. Note the use of `CGLM_ALIGN_IF` for ensuring required memory alignment (16 or 32 bytes) for vectorized operations, depending on the architecture and compiler flags like `__AVX__`. ```c typedef float vec2[2]; typedef float vec3[3]; typedef int ivec3[3]; typedef CGLM_ALIGN_IF(16) float vec4[4]; typedef vec4 versor; typedef vec3 mat3[3]; #ifdef __AVX__ typedef CGLM_ALIGN_IF(32) vec4 mat4[4]; #else typedef CGLM_ALIGN_IF(16) vec4 mat4[4]; #endif ``` -------------------------------- ### Example Call for Matrix Multiplication C Source: https://github.com/recp/cglm/blob/master/docs/source/mat3x2.rst This snippet provides an example of how to call the `glm_mat3x2_mul` function in C. It takes a 3x2 matrix and a 2x3 matrix as input and stores the resulting 2x2 matrix in the destination parameter. ```C glm_mat3x2_mul(mat3x2, mat2x3, mat2); ``` -------------------------------- ### Include Specific Clipspace Header C Source: https://github.com/recp/cglm/blob/master/docs/source/opt.rst Includes a specific clipspace configuration header manually when CGLM_CLIPSPACE_INCLUDE_ALL is not defined. This example includes the header for view matrices in a right-handed coordinate system with a depth range of zero to one. ```C #include cglm/clipspace/view_rh_zo.h ``` -------------------------------- ### Export Targets for Config File Generation (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Exports the defined library target(s) to a CMake config file (`${PROJECT_NAME}Config.cmake`) in the build directory and defines installation rules for this generated config file, allowing other CMake projects to easily find and use cglm. ```CMake # Config export(TARGETS ${PROJECT_NAME} NAMESPACE ${PROJECT_NAME}:: FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" ) install(EXPORT ${PROJECT_NAME} FILE "${PROJECT_NAME}Config.cmake" NAMESPACE ${PROJECT_NAME}:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) ``` -------------------------------- ### Example Usage of glm_smc in C Source: https://github.com/recp/cglm/blob/master/docs/source/curve.rst This snippet demonstrates a typical usage of the glm_smc function to calculate a point on a curve. It passes the curve parameter 's', a basis matrix (like GLM_BEZIER_MAT for Bezier curves), and a vector containing control points. ```c Bs = glm_smc(s, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}) ``` -------------------------------- ### Using cglm Struct API (Omitted Namespace) in C Source: https://github.com/recp/cglm/blob/master/docs/source/api_struct.rst Shows how to use the cglm Struct API without the default glms_ namespace by defining the CGLM_OMIT_NS_FROM_STRUCT_API macro before including the header. Demonstrates similar matrix and vector operations as the default example. Requires defining the macro and including cglm/struct.h. ```c #define CGLM_OMIT_NS_FROM_STRUCT_API #include mat4s m1 = mat4_identity(); /* init... */ mat4s m2 = mat4_identity(); /* init... */ mat4s m3 = mat4_mul(mat4_mul(m1, m2), mat4_mul(m3, m4)); vec3s v1 = { 1.0f, 0.0f, 0.0f }; vec3s v2 = { 0.0f, 1.0f, 0.0f }; vec4s v4 = { 0.0f, 1.0f, 0.0f, 0.0f }; vec4 v5a = { 0.0f, 1.0f, 0.0f, 0.0f }; mat4s m4 = glms_rotate(m3, M_PI_2, vec3_cross(vec3_add(v1, v6) vec3_add(v1, v7))); v1.x = 1.0f; v1.y = 0.0f; v1.z = 0.0f; // or v1.raw[0] = 1.0f; v1.raw[1] = 0.0f; v1.raw[2] = 0.0f; /* use struct api with array api (mix them) */ glm_vec4_add(m4.col[0].raw, v5a, m4.col[0].raw); glm_mat4_mulv(m4.raw, v4.raw, v5a); ``` -------------------------------- ### Swapping mat2 Columns In-place in cglm (C) Source: https://github.com/recp/cglm/blob/master/docs/source/mat2.rst This snippet demonstrates how to swap two columns within a 2x2 matrix 'mat' in-place using the 'glm_mat2_swap_col' function. It initializes the matrix 'mat' and then swaps columns at specified indices (0 and 1 in this example). ```c mat2 mat = {{76.00,5.00},{3.00,6.00}}; glm_mat2_swap_col(mat, 0, 1); ``` -------------------------------- ### Create Look Rotation Quaternion from Points (CGLM) Source: https://github.com/recp/cglm/blob/master/docs/source/quat.rst Creates a "look at" rotation quaternion based on source (from) and destination (to) points. It computes the direction vector internally and uses the provided up vector (up), storing the result in dest. This is an alternative to glm_quat_for when starting and ending points are known. ```C void glm_quat_forp(vec3 from, vec3 to, vec3 up, versor dest) ``` -------------------------------- ### Swapping mat2 Rows In-place in cglm (C) Source: https://github.com/recp/cglm/blob/master/docs/source/mat2.rst This snippet shows how to swap two rows within a 2x2 matrix 'mat' in-place using the 'glm_mat2_swap_row' function. It initializes the matrix 'mat' and then swaps rows at specified indices (0 and 1 in this example). ```c mat2 mat = {{76.00,5.00},{3.00,6.00}}; glm_mat2_swap_row(mat, 0, 1); ``` -------------------------------- ### Building cglm with Devenv (Powershell) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Shows how to use the `devenv` command-line tool from Visual Studio to build the cglm solution file, providing an alternative command-line build method for Windows. ```Powershell $ devenv cglm.sln /Build Release ``` -------------------------------- ### Cubic Bezier Interpolation Formula - C (Formula) Source: https://github.com/recp/cglm/blob/master/docs/source/bezier.rst This snippet shows the mathematical formula used for cubic Bezier interpolation, as implemented by the `glm_bezier` function. It defines the interpolated value B(s) based on the parameter s, start point P0, control points C0 and C1, and end point P1. ```C (Formula) B(s) = P0*(1-s)^3 + 3*C0*s*(1-s)^2 + 3*C1*s^2*(1-s) + P1*s^3 ``` -------------------------------- ### Building cglm with Meson (Bash) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Provides standard command-line steps to build the cglm library using the Meson build system with Ninja, including configuring the build directory and compiling. ```bash $ meson build # [Optional] --default-library=static $ cd build $ ninja $ sudo ninja install # [Optional] ``` -------------------------------- ### Building cglm Documentation with Sphinx (Bash) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Provides command-line steps to build the cglm documentation using the Sphinx documentation generator from the `docs` directory. ```bash $ cd docs $ sphinx-build source build ``` -------------------------------- ### Building cglm Documentation with Sphinx Source: https://github.com/recp/cglm/blob/master/docs/source/build.rst These Bash commands show how to build the cglm documentation using the Sphinx framework. It involves navigating to the 'docs' directory and running the 'sphinx-build' command with source and build directories. ```bash $ cd cglm/docs $ sphinx-build source build ``` -------------------------------- ### cglm Meson Build Options (Meson) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Lists key configuration options used in the Meson build file for cglm, including C standard, build type, default library type (shared/static), and test build flag. ```meson c_std=c11 buildtype=release default_library=shared build_tests=true # to run tests: ninja test ``` -------------------------------- ### Including cglm in Meson Project (Meson) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Demonstrates how to integrate cglm as a subproject in a Meson project using `add_subdirectory` or `.wrap` files and obtaining a dependency object to link against. ```meson # Clone cglm or create a cglm.wrap under /subprojects project('name', 'c') cglm_dep = dependency('cglm', fallback : 'cglm', 'cglm_dep') executable('exe', 'src/main.c', dependencies : cglm_dep) ``` -------------------------------- ### Building cglm for WebAssembly with Emscripten (Bash) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Shows how to use the `emcmake` wrapper and specific CMake flags to build cglm for WebAssembly using the Emscripten SDK, ensuring a static build and standalone WASM output. ```bash $ emcmake cmake .. \ -DCMAKE_EXE_LINKER_FLAGS="-s STANDALONE_WASM" \ -DCGLM_STATIC=ON ``` -------------------------------- ### Building cglm with MSBuild (Powershell) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Command to build the cglm Visual Studio solution from the command line using MSBuild, typically run from the `win` directory. ```Powershell $ cd win $ .\build.bat ``` -------------------------------- ### Building cglm for WASI with CMake (Bash) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Provides the command-line arguments for CMake to build cglm targeting WebAssembly using the WASI SDK, specifying the toolchain file and SDK prefix. Results in a static build. ```bash $ cmake .. \ -DCMAKE_TOOLCHAIN_FILE=/path/to/wasi-sdk-19.0/share/cmake/wasi-sdk.cmake \ -DWASI_SDK_PREFIX=/path/to/wasi-sdk-19.0 ``` -------------------------------- ### Linking cglm to Swift Target (Swift) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Demonstrates how to link the cglm product (either `cglm` for static or `cglmc` for compiled) to a specific target within a Swift Package Manager `Package.swift` file. ```swift ... .target( ... dependencies: [ ... .product(name: "cglm", package: "cglm"), ] ... ) ... ``` -------------------------------- ### Get Sign of Vector4 Elements - cglm C Source: https://github.com/recp/cglm/blob/master/docs/source/vec4-ext.rst Computes the sign of each element in the input vec4 vector 'v'. The sign is returned as -1.0 for negative numbers, +1.0 for positive numbers, and 0.0 for zero. The results are stored in the destination vec4 vector 'dest'. ```C void glm_vec4_sign(vec4 v, vec4 dest) ``` -------------------------------- ### Building cglm with MSBuild (devenv fallback) Source: https://github.com/recp/cglm/blob/master/docs/source/build.rst This Bash command provides a fallback method to build the cglm Visual Studio solution file (.sln) using the 'devenv' command-line utility, which can be useful if the 'msbuild' command encounters version conflicts. ```bash $ devenv cglm.sln /Build Release ``` -------------------------------- ### Using cglm Header-Only API - C Source: https://github.com/recp/cglm/blob/master/README.md Demonstrates how to use cglm by including the main header `cglm/cglm.h` and using functions prefixed with `glm_`. This method allows using the library simply by including the header without needing to link. ```c #include "cglm/cglm.h" // ... vec2 vector; glm_vec2_zero(vector); ``` -------------------------------- ### cglm CMake Build Options (CMake) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Lists available CMake options for configuring the cglm build, including flags for shared/static builds, C99 compatibility, and test enablement, along with their default values. ```CMake option(CGLM_SHARED "Shared build" ON) option(CGLM_STATIC "Static build" OFF) option(CGLM_USE_C99 "" OFF) # C11 option(CGLM_USE_TEST "Enable Tests" OFF) # for make check - make test ``` -------------------------------- ### Cubic Hermite Interpolation Formula - C (Formula) Source: https://github.com/recp/cglm/blob/master/docs/source/bezier.rst This snippet shows the mathematical formula used for cubic Hermite interpolation, as implemented by the `glm_hermite` function. It defines the interpolated value H(s) based on the parameter s, start point P0, tangent T0, tangent T1, and end point P1. ```C (Formula) H(s) = P0*(2*s^3 - 3*s^2 + 1) + T0*(s^3 - 2*s^2 + s) + P1*(-2*s^3 + 3*s^2) + T1*(s^3 - s^2) ``` -------------------------------- ### Configure Build Options and Defaults (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Configures standard C settings, defines default build options (shared/static, C99 usage, tests), and includes logic to override build type options specifically for WASI builds. ```CMake set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED YES) set(DEFAULT_BUILD_TYPE "Release") set(CGLM_BUILD) option(CGLM_SHARED "Shared build" ON) option(CGLM_STATIC "Static build" OFF) option(CGLM_USE_C99 "" OFF) option(CGLM_USE_TEST "Enable Tests" OFF) if(CMAKE_SYSTEM_NAME STREQUAL WASI) set(CGLM_STATIC ON CACHE BOOL "Static option" FORCE) set(CGLM_SHARED OFF CACHE BOOL "Shared option" FORCE) endif() if(NOT CGLM_STATIC AND CGLM_SHARED) set(CGLM_BUILD SHARED) else(CGLM_STATIC) set(CGLM_BUILD STATIC) endif() if(CGLM_USE_C99) set(CMAKE_C_STANDARD 99) endif() ``` -------------------------------- ### Linear Interpolation Between Two vec2 Vectors - C Source: https://github.com/recp/cglm/blob/master/docs/source/vec2.rst Performs linear interpolation between two 2D vectors (`from` and `to`) based on an interpolant value (`t`). The formula used is `from + t * (to - from)`. The interpolant `t` is typically clamped between 0 and 1. The result is stored in a destination vector (`dest`). Required parameters are the start vector `from`, the end vector `to`, the interpolant `t`, and the output destination vector `dest`. ```C void glm_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest) ``` -------------------------------- ### Defining Python Documentation Dependencies - Requirements Configuration Source: https://github.com/recp/cglm/blob/master/docs/requirements.txt This snippet lists the exact versions of Python packages needed to build the project's documentation. Specifying exact versions prevents unexpected build failures due to incompatible dependency updates. ```Python Requirements # Defining the exact version will make sure things don't break sphinx==7.2.6 sphinx_rtd_theme==2.0.0 readthedocs-sphinx-search==0.3.2 ``` -------------------------------- ### Setting up mat2 Vector Multiplication in C Source: https://github.com/recp/cglm/blob/master/docs/source/mat2.rst This snippet shows the initialization of variables required for multiplying a mat2 (2x2 matrix) by a vec2 (2D vector). It declares a destination vector and initializes the source vector and matrix. The subsequent step would be calling `glm_mat2_mulv`. ```C vec2 dest; vec2 v = {33.00,55.00}; mat2 m = {{1.00,2.00},{3.00,4.00}}; ``` -------------------------------- ### Configuring cglm Build Options with CMake Source: https://github.com/recp/cglm/blob/master/docs/source/build.rst This CMake snippet lists available options to configure the cglm build process. Options control whether shared or static libraries are built, the C standard used (C99 vs C11), and whether build tests are enabled. ```cmake option(CGLM_SHARED "Shared build" ON) option(CGLM_STATIC "Static build" OFF) option(CGLM_USE_C99 "" OFF) # C11 option(CGLM_USE_TEST "Enable Tests" OFF) # for make check - make test ``` -------------------------------- ### Building cglm with MSBuild (.bat script) Source: https://github.com/recp/cglm/blob/master/docs/source/build.rst This Bash command executes the Windows batch script provided in the 'win' directory to build cglm using MSBuild. Users should navigate to the 'win' folder before running this command. ```bash $ cd win .\build.bat ``` -------------------------------- ### Include Main cglm Header C Source: https://github.com/recp/cglm/blob/master/docs/source/opt.rst Includes the primary cglm header file. This header includes most of the core functionality of the library, depending on defined configuration macros. ```C #include cglm/cglm.h ``` -------------------------------- ### Set Target Properties (Version, SOVERSION, Runtime Name) (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Sets standard target properties like VERSION and SOVERSION. Includes specific handling for WIN32 to set the RUNTIME_OUTPUT_NAME for shared libraries, as SOVERSION doesn't control naming on Windows. ```CMake set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}) if(WIN32) # Because SOVERSION has no effect to file naming on Windows set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_NAME ${PROJECT_NAME}-${PROJECT_VERSION_MAJOR}) endif() ``` -------------------------------- ### Linking cglm Library in CMake (CMake) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Shows how to integrate and link the built cglm library into an existing CMake project using `add_subdirectory` and linking to the `cglm` target. Also mentions using `find_package`. ```CMake cmake_minimum_required(VERSION 3.8.2) project() add_executable(${PROJECT_NAME} src/main.c) target_link_libraries(${LIBRARY_NAME} PRIVATE cglm) add_subdirectory(external/cglm/) # or you can use find_package to configure cglm ``` -------------------------------- ### Adding cglm Swift Package Dependency (Swift) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Shows how to add the cglm library as a dependency in a Swift Package Manager `Package.swift` file by specifying the repository URL and desired branch. ```swift ... Package( ... dependencies: [ ... .package(url: "https://github.com/recp/cglm", .branch("master")), ] ... ) ``` -------------------------------- ### Include Call API Header C Source: https://github.com/recp/cglm/blob/master/docs/source/opt.rst Includes the cglm header file for the Call API. This header provides functions with a different parameter passing convention, potentially suitable for various use cases. ```C #include cglm/call.h ``` -------------------------------- ### Using cglm Linked API - C Source: https://github.com/recp/cglm/blob/master/README.md Explains how to use cglm when linking against the compiled library instead of using it as header-only. This involves including `cglm/call.h` and using functions prefixed with `glmc_`. ```c #include "cglm/call.h" // ... vec2 vector; glmc_vec2_zero(vector); ``` -------------------------------- ### Including cglm Header-Only in CMake (CMake) Source: https://github.com/recp/cglm/blob/master/BUILDING.md Demonstrates how to integrate cglm into an existing CMake project as a header-only library using `add_subdirectory` and linking to the `cglm_headers` target. Requires cloning cglm into a subdirectory (e.g., `external/cglm`). ```CMake cmake_minimum_required(VERSION 3.8.2) project() add_executable(${PROJECT_NAME} src/main.c) target_link_libraries(${LIBRARY_NAME} PRIVATE cglm_headers) add_subdirectory(external/cglm/ EXCLUDE_FROM_ALL) ``` -------------------------------- ### Using cglm Struct API (Default Namespace) in C Source: https://github.com/recp/cglm/blob/master/docs/source/api_struct.rst Demonstrates basic usage of the cglm Struct API with its default glms_ namespace, including matrix and vector initialization, multiplication, accessing components via .x/.y/.z, and accessing raw array data via .raw to mix with the Array API. Requires including cglm/struct.h. ```c #include mat4s m1 = glms_mat4_identity(); /* init... */ mat4s m2 = glms_mat4_identity(); /* init... */ mat4s m3 = glms_mat4_mul(glms_mat4_mul(m1, m2), glms_mat4_mul(m3, m4)); vec3s v1 = { 1.0f, 0.0f, 0.0f }; vec3s v2 = { 0.0f, 1.0f, 0.0f }; vec4s v4 = { 0.0f, 1.0f, 0.0f, 0.0f }; vec4 v5a = { 0.0f, 1.0f, 0.0f, 0.0f }; mat4s m4 = glms_rotate(m3, M_PI_2, glms_vec3_cross(glms_vec3_add(v1, v6) glms_vec3_add(v1, v7))); v1.x = 1.0f; v1.y = 0.0f; v1.z = 0.0f; // or v1.raw[0] = 1.0f; v1.raw[1] = 0.0f; v1.raw[2] = 0.0f; /* use struct api with array api (mix them). */ /* use .raw to access array and use it with array api */ glm_vec4_add(m4.col[0].raw, v5a, m4.col[0].raw); glm_mat4_mulv(m4.raw, v4.raw, v5a); ``` -------------------------------- ### Defining Build Test Option in Meson Source: https://github.com/recp/cglm/blob/master/meson_options.txt Defines a boolean option named `build_tests`. It controls whether tests are built during the project compilation. The default value is `false`, meaning tests are not built by default. ```Meson option('build_tests', type : 'boolean', value : false, description : 'Build tests') ``` -------------------------------- ### Adding Test Executable Target (CMake) Source: https://github.com/recp/cglm/blob/master/test/CMakeLists.txt Creates an executable target named `${TEST_MAIN}` (which is 'tests') using the source files listed in the `${TESTFILES}` variable. This is the primary build target for the test suite. ```CMake add_executable(${TEST_MAIN} ${TESTFILES}) ``` -------------------------------- ### Include All Clipspace Headers C Macro Source: https://github.com/recp/cglm/blob/master/docs/source/opt.rst Defines CGLM_CLIPSPACE_INCLUDE_ALL to automatically include all available clipspace configuration headers when including main cglm headers (cglm.h, struct.h, call.h). Otherwise, specific clipspace headers must be included manually. ```C #define CGLM_CLIPSPACE_INCLUDE_ALL ``` -------------------------------- ### Using cglm Struct API - C Source: https://github.com/recp/cglm/blob/master/README.md Shows how to use the Struct API by including `cglm/struct.h` and using types with an `s` suffix and functions prefixed with `glms_`. This API generally takes parameters by copy and returns results, promoting the use of `const` variables. ```c #include "cglm/struct.h" // ... vec2s vector = glms_vec2_zero(); ``` -------------------------------- ### Define Library Target and Sources (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Defines the main library target named after the project, specifying whether it should be built as SHARED or STATIC based on the configured CGLM_BUILD variable and listing all the source (.c) files that make up the library. ```CMake # Target Start add_library(${PROJECT_NAME} ${CGLM_BUILD} src/euler.c src/affine.c src/io.c src/quat.c src/cam.c src/vec2.c src/ivec2.c src/vec3.c src/ivec3.c src/vec4.c src/ivec4.c src/mat2.c src/mat2x3.c src/mat2x4.c src/mat3.c src/mat3x2.c src/mat3x4.c src/mat4.c src/mat4x2.c src/mat4x3.c src/plane.c src/noise.c src/frustum.c src/box.c src/aabb2d.c src/project.c src/sphere.c src/ease.c src/curve.c src/bezier.c src/ray.c src/affine2d.c src/clipspace/ortho_lh_no.c src/clipspace/ortho_lh_zo.c src/clipspace/ortho_rh_no.c src/clipspace/ortho_rh_zo.c src/clipspace/persp_lh_no.c src/clipspace/persp_lh_zo.c src/clipspace/persp_rh_no.c src/clipspace/persp_rh_zo.c src/clipspace/view_lh_no.c src/clipspace/view_lh_zo.c src/clipspace/view_rh_no.c src/clipspace/view_rh_zo.c src/clipspace/project_no.c src/clipspace/project_zo.c ) ``` -------------------------------- ### Setting Test Executable Output Directory (CMake) Source: https://github.com/recp/cglm/blob/master/test/CMakeLists.txt Sets the runtime output directory for the test executable to the project's binary directory. This determines where the compiled executable file will be placed after the build. ```CMake set_target_properties(${TEST_MAIN} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) ``` -------------------------------- ### Define Header-Only Interface Target (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Creates a separate INTERFACE library target specifically for users who want to use cglm as a header-only library, providing only the include directory reference. ```CMake # Target for header-only usage add_library(${PROJECT_NAME}_headers INTERFACE) target_include_directories(${PROJECT_NAME}_headers INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) ``` -------------------------------- ### Configure Testing with CTest (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Includes the CTest module and enables testing if the CGLM_USE_TEST option is turned on. It then adds the 'test' subdirectory, which presumably contains the test execution logic and definitions. ```CMake # Test Configuration if(CGLM_USE_TEST) include(CTest) enable_testing() add_subdirectory(test) endif() ``` -------------------------------- ### Conditional Math Library Linking (CMake) Source: https://github.com/recp/cglm/blob/master/test/CMakeLists.txt Links the standard C math library (`m`) to the test executable target, but only if the compiler is NOT MSVC. MSVC typically includes math functions directly without needing a separate library link. ```CMake if(NOT MSVC) target_link_libraries(${TEST_MAIN} PRIVATE m) endif() ``` -------------------------------- ### Defining Test Source Files (CMake) Source: https://github.com/recp/cglm/blob/master/test/CMakeLists.txt Defines a list variable `TESTFILES` containing all the source files that are part of the test executable. This list is used later when creating the executable target. ```CMake set(TESTFILES runner.c src/test_euler.c src/test_bezier.c src/test_struct.c src/test_clamp.c src/test_common.c src/tests.c ) ``` -------------------------------- ### Initialize ivec4 Vector from ivec3 in C Source: https://github.com/recp/cglm/blob/master/docs/source/ivec4.rst Initializes a 4-element integer vector (`ivec4`) using the components of a 3-element integer vector (`ivec3`) and an additional integer value for the last component. Takes the source `ivec3` vector, the last integer component, and the destination `ivec4` vector as parameters. ```C void glm_ivec4(ivec3 v3, int last, ivec4 dest) ``` -------------------------------- ### Include Struct API Header C Source: https://github.com/recp/cglm/blob/master/docs/source/opt.rst Includes the cglm header file for the Struct API. This header provides functions that operate on cglm types passed by value (structs), configured by Struct API options. ```C #include cglm/struct.h ``` -------------------------------- ### Creating mat4x2 Matrix from Pointer in Cglm C Source: https://github.com/recp/cglm/blob/master/docs/source/mat4x2.rst Creates a 4x2 matrix (dest) by reading 8 float values from a source pointer (src). The source pointer must point to a valid memory location containing at least 8 float elements. Requires a const float pointer and a valid mat4x2 destination. ```C void glm_mat4x2_make(const float * __restrict src, mat4x2 dest) ``` -------------------------------- ### Adding Include Directories for Tests (CMake) Source: https://github.com/recp/cglm/blob/master/test/CMakeLists.txt Adds necessary include directories (`include` and `src` within the current source directory) to the include path for the test executable target. This allows the test source files to find header files from both the library and the test suite itself. ```CMake target_include_directories(${TEST_MAIN} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include ${CMAKE_CURRENT_LIST_DIR}/src ) ``` -------------------------------- ### Force SSE4 Dot Product C Macro Source: https://github.com/recp/cglm/blob/master/docs/source/opt.rst Defines CGLM_SSE4_DOT when SSE4 is enabled to force cglm to use the `_mm_dp_ps` intrinsic for dot product calculations. This leverages hardware dot product instructions. ```C #define CGLM_SSE4_DOT ``` -------------------------------- ### Adding CTest Test Entry (CMake) Source: https://github.com/recp/cglm/blob/master/test/CMakeLists.txt Defines a test entry in CTest (the CMake testing framework) named `cglm.tests`. This test simply executes the built test executable, optionally passing the defined `TEST_RUNNER_PARAMS`. ```CMake add_test( NAME cglm.${TEST_MAIN} COMMAND ${TEST_MAIN} ${TEST_RUNNER_PARAMS}) ``` -------------------------------- ### Initializing vec4 from vec3 in C Source: https://github.com/recp/cglm/blob/master/docs/source/vec4.rst Initializes a 4-component vector (vec4) using a 3-component vector (vec3) and a scalar for the last component. This approach provides control over the last item instead of automatically setting it to zero. ```C void glm_vec4(vec3 v3, float last, vec4 dest) ``` -------------------------------- ### Initializing vec2 from Vector - C Source: https://github.com/recp/cglm/blob/master/docs/source/vec2.rst Initializes a 2D vector (`dest`) using values from another vector (`v`), which can be a vec3 or vec4. Required parameters are the source vector `v` (input) and the destination vec2 `dest` (output). ```C void glm_vec2(float * v, vec2 dest) ``` -------------------------------- ### Force pshufd Instruction C Macro Source: https://github.com/recp/cglm/blob/master/docs/source/opt.rst Defines CGLM_NO_INT_DOMAIN to force the use of the `pshufd` instruction instead of `shufps` for SSE/SSE2 shuffle operations, which can sometimes be more efficient when registers are the same. ```C #define CGLM_NO_INT_DOMAIN ``` -------------------------------- ### Linking cglm Library to Tests (CMake) Source: https://github.com/recp/cglm/blob/master/test/CMakeLists.txt Links the main `cglm` library target to the test executable. This ensures that the test code can call functions and access data structures provided by the cglm library. ```CMake target_link_libraries(${TEST_MAIN} PRIVATE cglm) ``` -------------------------------- ### Creating mat2 from Array in C Source: https://github.com/recp/cglm/blob/master/docs/source/mat2.rst This snippet demonstrates how to initialize a mat2 (2x2 matrix) by copying values from a 1D float array containing at least 4 elements using the `glm_mat2_make` function. The source array's elements are mapped to the matrix columns. ```C mat2 dest = GLM_MAT2_ZERO_INIT; float src[4] = { 1.00, 5.00, 8.00, 11.00 }; glm_mat2_make(src, dest); ``` -------------------------------- ### Configure Default Build Type (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Checks if a build type is already specified (e.g., by a parent project or command line) and sets a default ('Release') if none is found. It also configures possible values for the build type in CMake GUI. ```CMake get_directory_property(hasParent PARENT_DIRECTORY) if(NOT hasParent AND NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE) # Set the possible values of build type for cmake-gui set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() ``` -------------------------------- ### Computing MVP Matrix - cglm C Source: https://github.com/recp/cglm/blob/master/docs/source/project.rst This snippet shows how to calculate the Model-View-Projection (MVP) matrix by multiplying the projection, view, and model matrices sequentially using `glm_mat4_mul`. It assumes you have pre-calculated `proj`, `view`, and `model`. The resulting `MVP` matrix is used by functions like `glm_unproject`, `glm_project`, and `glm_project_z` to transform coordinates between different spaces. ```c glm_mat4_mul(proj, view, viewProj); glm_mat4_mul(viewProj, model, MVP); ``` -------------------------------- ### Set Compiler Specific Flags (CMake) Source: https://github.com/recp/cglm/blob/master/CMakeLists.txt Adds compiler definitions and options based on the compiler (MSVC or others) and build type (Debug vs. Release/Optimized). It includes flags for warnings, optimization, and specific MSVC runtime checks removal in release builds. ```CMake if(MSVC) add_definitions(-D_WINDOWS -D_USRDLL) if(NOT CMAKE_BUILD_TYPE MATCHES Debug) add_definitions(-DNDEBUG) add_compile_options(/W3 /Ox /Gy /Oi /TC) foreach(flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO) string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}") endforeach(flag_var) endif() else() add_compile_options(-Wall -Wextra -Wpedantic -Wconversion) if(NOT CMAKE_BUILD_TYPE MATCHES Debug) add_compile_options(-O3) endif() endif() ``` -------------------------------- ### Adding Custom 'check' Target (CMake) Source: https://github.com/recp/cglm/blob/master/test/CMakeLists.txt Defines a custom target named `check`. When built, this target first runs the default 'make' command (or equivalent build tool command) to ensure all dependencies, including `cglm`, are built, and then runs CTest with verbose output (`-V`) to execute all defined tests. ```CMake add_custom_target(check make COMMAND ${CMAKE_CTEST_COMMAND} -V DEPENDS cglm) ``` -------------------------------- ### Conditional WASI Configuration (CMake) Source: https://github.com/recp/cglm/blob/master/test/CMakeLists.txt Applies specific compile definitions and link options if the target system is WASI (WebAssembly System Interface). This is necessary for compatibility and emulation of certain POSIX features. ```CMake if(CMAKE_SYSTEM_NAME STREQUAL WASI) target_compile_definitions(${TEST_MAIN} PRIVATE _WASI_EMULATED_PROCESS_CLOCKS=1) target_link_options(${TEST_MAIN} PRIVATE "-lwasi-emulated-process-clocks") endif() ``` -------------------------------- ### Setting Minimum Required CMake Version Source: https://github.com/recp/cglm/blob/master/test/CMakeLists.txt Specifies the minimum version of CMake required to build this project. This ensures that all features and commands used in the script are available. ```CMake cmake_minimum_required(VERSION 3.8.2) ``` -------------------------------- ### Force Depth Zero to One C Macro Source: https://github.com/recp/cglm/blob/master/docs/source/opt.rst Defines CGLM_FORCE_DEPTH_ZERO_TO_ONE to change the default depth range from [-1, 1] to [0, 1], making cglm compatible with APIs like Vulkan and Metal by default. Functions in modules like `cam.h` will use their `_zo` variants. ```C #define CGLM_FORCE_DEPTH_ZERO_TO_ONE ``` -------------------------------- ### Adding Min of Two vec4 Components to Destination in C Source: https://github.com/recp/cglm/blob/master/docs/source/vec4.rst Adds the component-wise minimum of two 4-component vectors (vec4 a and vec4 b) to the destination vector (vec4 dest). This is equivalent to `dest += min(a, b)` and requires `dest` to be initialized. Note: The documentation parameter description for dest is incorrect here, showing `dest += (a * b)`. ```C void glm_vec4_minadd(vec4 a, vec4 b, vec4 dest) ``` -------------------------------- ### Creating vec2 Vector from Components - C Source: https://github.com/recp/cglm/blob/master/docs/source/vec2.rst Constructs a 2D vector (`dest`) from explicit x and y component values. Note: This function signature is missing from the provided text's function list but implied by the title and documentation style. Assuming a common structure like `void glm_vec2_make(float x, float y, vec2 dest);`. Required parameters would be the x component `x`, the y component `y`, and the output destination vector `dest`. ```C void glm_vec2_make(float x, float y, vec2 dest) ``` -------------------------------- ### Illustrating Pre-Transform Matrix Multiplication in cglm C Source: https://github.com/recp/cglm/blob/master/docs/source/affine.rst This snippet illustrates conceptually how pre-transform functions like `glm_translate`, `glm_rotate`, and `glm_scale` apply their respective matrices by right-multiplying the existing transformation matrix (`T' = T * Tnew`). This multiplication order dictates the effective order in which transformations are applied to vectors. ```C TransformMatrix = TransformMatrix * TranslateMatrix; // glm_translate() TransformMatrix = TransformMatrix * RotateMatrix; // glm_rotate(), glm_quat_rotate() TransformMatrix = TransformMatrix * ScaleMatrix; // glm_scale() ```