HandmadeMath/HandmadeMath
FreeA simple math library for games and computer graphics. Compatible with both C and C++. Public domain and easy to modify.
FreeFree tier
About HandmadeMath/HandmadeMath
A single-file, cross-platform, public domain graphics math library for C and C++. Supports vectors, matrices, quaternions, and all expected utilities. Features include swizzling via unions, configurable angle units (radians, degrees, turns), left-handed and right-handed operations, and support for zero-to-one and negative-one-to-one NDC conventions. Matrices are column-major with column vectors. All functions are static inline, requiring only a single header include. Licensed under CC0-1.0.
Key Features
Single-header library (just #include "HandmadeMath.h")
Supports both C and C++ with operator overloading and _Generic macros
Vector, matrix, and quaternion types with swizzling via unions (XYZ, RGB, UVW)
Configurable angle units: radians, degrees, or turns
Left-handed (LH) and right-handed (RH) variants for handedness-sensitive operations
Zero-to-one (ZO) and negative-one-to-one (NO) NDC convention support
Column-major matrices with column vectors
Public domain license (CC0-1.0) – free for any use
Static inline functions – no separate implementation file required
Cross-platform: works on any platform with a C or C++ compiler
Pros & Cons
Pros
- Extremely simple integration – just include one header file
- Cross-platform and compiler independent
- Public domain license removes all legal barriers
- Supports both C and C++ with idiomatic interfaces for each
- Swizzling and configurable conventions (handedness, NDC, angle units) add flexibility
- Lightweight with no external dependencies
Cons
- Limited to core math – no higher-level game engine or rendering features
- Documentation is primarily inline header comments; no separate manual
- May not be as performance-optimized as specialized libraries (e.g., no SIMD intrinsics visible)
- Lacks advanced features like spatial transformations or easing functions
Best For
Game development (3D graphics, physics, camera transformations)Computer graphics rendering pipelines3D modeling and animation toolsScientific visualization and simulationAny C or C++ project requiring linear algebra with minimal setup
FAQ
What conventions does HMM use, e.g. row vs. column major, handedness, etc.?
Handmade Math's matrices are column-major with column vectors. It provides left-handed (LH) and right-handed (RH) variants, and zero-to-one (ZO) and negative-one-to-one (NO) NDC convention variants.
What if I don't want the HMM_ prefix?
Do a find and replace in the library source.
What's the license?
This library is in the public domain (CC0-1.0).
Where can I contact you to ask questions?
Feel free to make GitHub issues for any questions, concerns, or problems you encounter.