{"id":15115248,"url":"https://github.com/orosmatthew/nnm","last_synced_at":"2025-09-27T20:32:10.437Z","repository":{"id":255403228,"uuid":"830683012","full_name":"orosmatthew/nnm","owner":"orosmatthew","description":"A \"No-Nonsense\", C++ 17, single-header-only Math library geared towards graphics programming","archived":false,"fork":false,"pushed_at":"2025-01-10T20:35:21.000Z","size":891,"stargazers_count":40,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-10T20:54:07.387Z","etag":null,"topics":["cpp","math"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orosmatthew.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-18T19:02:41.000Z","updated_at":"2025-01-10T20:35:25.000Z","dependencies_parsed_at":"2024-08-29T20:14:50.947Z","dependency_job_id":"c7d0f026-685b-47b9-b692-cac83da81ade","html_url":"https://github.com/orosmatthew/nnm","commit_stats":null,"previous_names":["orosmatthew/nnm"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orosmatthew%2Fnnm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orosmatthew%2Fnnm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orosmatthew%2Fnnm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orosmatthew%2Fnnm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orosmatthew","download_url":"https://codeload.github.com/orosmatthew/nnm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234460505,"owners_count":18836837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","math"],"created_at":"2024-09-26T01:43:44.031Z","updated_at":"2025-09-27T20:32:10.432Z","avatar_url":"https://github.com/orosmatthew.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# [nnm] No Nonsense Math\n\nNNM is a \"No-Nonsense\", C++ 17, single-header-only Math library geared towards graphics programming. Think of it as a\nlightweight, more readable alternative to a library like [glm](https://github.com/g-truc/glm) and inspired by the OOP\nstyle of [Godot's](https://github.com/godotengine/godot) math library.\n\n## A Quick Example\n\n```cpp\n#define NNM_BOUNDS_CHECK // optional bounds checking\n#include \u003cnnm/nnm.hpp\u003e\n\n// Compute transform of an object in 3d space\nnnm::Transform3f calculate_object_transform(\n    const nnm::Vector3f\u0026 position, const nnm::Vector2f\u0026 rotation)\n{\n    constexpr float aspect_ratio = nnm::Vector2(16.0f, 9.0f).aspect_ratio();\n    constexpr float fov = nnm::radians(90.0f);\n    const auto projection\n        = nnm::Transform3f::from_perspective_left_hand_neg1to1(\n            fov, aspect_ratio, 0.1f, 100.0f);\n    const auto view\n        = nnm::Transform3f::from_translation(position)\n              .rotate_axis_angle(nnm::Vector3f::axis_y(), rotation.y)\n              .rotate_axis_angle(nnm::Vector3f::axis_x(), rotation.x);\n    const auto model = nnm::Transform3f::from_scale(nnm::Vector3f::all(0.5f));\n    return model.transform(view).transform(projection);\n}\n```\n\n## Features\n\nA full list of all functions/classes can be found at [**nnm.pixeled.site**](https://nnm.pixeled.site).\n\nNNM provides classes for:\n\n* Vectors\n    * `Vector2`\n    * `Vector2i`\n    * `Vector3`\n    * `Vector3i`\n    * `Vector4`\n\n* Matrices\n    * `Matrix2`\n    * `Matrix3`\n    * `Matrix4`\n\n* Transformations\n    * `Basis2`\n    * `Transform2`\n    * `Basis3`\n    * `Transform3`\n\n* Misc.\n    * `Quaternion`\n\nwhere the trailing number represents the \"dimension\" of the class. These classes are templated with either `Real` or\n`Int` types that allow for various floating point and integer types. Aliases are created for those cases such\nas `Vector2f` and `Vector2d` for `float` and `double` respectively as well as `Vector3i32`, `Vector2u16`,\n`Vector3i64`, etc. for integer classes.\n\nIn addition to these classes, NNM provides for a number of standalone math functions such as `lerp`, `clamp`,\n`approx_equal`, etc.\n\nOther notable features/qualities of NNM include:\n\n* No template magic, just the basics for your choice of `Real` floating-point value and `Int` integer value.\n* Extremely readable. There are almost no macros and light use of templates.\n* Minimal abbreviations. It's the 21st century, we can afford readable function names!\n* Optional bounds checking for accessors with an optional `#define NNM_BOUNDS_CHECK` before including.\n* No external dependencies! Even minimal use of the standard library to just `\u003ccmath\u003e`, `\u003cfunctional\u003e`, `\u003coptional\u003e`,\n  and `\u003cstdexcept\u003e` if optional bounds checking is enabled.\n* No special SIMD instructions or compiler intrinsics. This makes NNM extremely portable. I personally have faith in\n  modern compilers to auto-vectorize when necessary.\n* `std::hash` specializations for `Vector2i` and `Vector3i`.\n* `begin()` and `end()` iterators for looping through classes with a ranged-for loop.\n\n## Installation Instructions\n\nThe easiest way would be to just copy the `include/nnm/nnm.hpp` file directly into your project and just `#include` it\nto use!\n\nAnother method is to add the project as a CMake submodule by copying the repository to a directory and adding:\n\n```cmake\nadd_subdirectory(external/path/to/nnm)\ntarget_link_libraries(your_project PRIVATE nnm)\n```\n\n## Projection Matrices\n\nYou might be asking, \"What is up with all these variations of perspective/orthographic projection methods? Which one do\nI use??\" This depends on the graphics API you are using as well as the coordinate system you choose for your\napplication. There are two considerations to be aware of, the handedness and the normalization of the graphics API. Here\nis a short list of common graphics APIs' normalized device coordinate (NDC) conventions:\n\n* OpenGL/WebGL/WebGPU/Metal: left-handed, -1 to 1\n* DirectX: left-handed, 0 to 1\n* Vulkan: right-handed, 0 to 1\n\nThis means if your application and graphics API use the same coordinate system, you just need to choose the method with\nthe correct handedness and normalization corresponding to that graphics API. However, if your application and chosen\ngraphics API have mismatching handedness, you must flip the z-axis. For example, if you are using OpenGL (which is\nleft-handed) but wish to use right-handed coordinates in your application, you would still use the projection method\ncorresponding with OpenGL's convention of left-handed and -1 to 1 normalization but just need to flip the z-axis to\naccount for the switched handedness:\n\n```cpp\nconst auto proj = nnm::Transform3f::from_perspective_left_hand_neg1to1(...).scale_local({1, 1, -1});\n```\n\n## Compiling and Running Tests\n\nAfter cloning the repository, configure the project with CMake ensuring to enable building tests:\n\n```bash\ncd nnm\ncmake -S . -B build -DNNM_BUILD_TESTS=ON\ncmake --build build\n```\n\n## License\n\nNNM is licensed under the MIT license. See `LICENSE.txt` for full license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forosmatthew%2Fnnm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forosmatthew%2Fnnm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forosmatthew%2Fnnm/lists"}