HandmadeMath/Handmade-Math logo

HandmadeMath/Handmade-Math

Free

A simple math library for games and computer graphics. Compatible with both C and C++.

FreeFree tier
Type
Open Source
Company
HandmadeMath

About HandmadeMath/Handmade-Math

Handmade Math is a single-file, cross-platform, public domain graphics math library designed for game development and computer graphics. It supports vectors (2D, 3D, 4D), matrices, and quaternions, with comprehensive utilities for common operations. The library is written in C and C++, with C++ operator overloading and C11 _Generic support. It offers configurable conventions: left‑handed and right‑handed coordinate systems, zero‑to‑one or negative‑one‑to‑one NDC ranges, and choice of angle units (radians, degrees, or turns). Vector types provide swizzling via unions (e.g., .xy, .rgb). The library is public domain (CC0‑1.0), easy to modify, and requires no separate implementation file—just #include "HandmadeMath.h".

Key Features

Single-header library — just #include "HandmadeMath.h"
Supports both C (C11 _Generic) and C++ (operator overloading)
Vectors, matrices, quaternions with full set of operations
Swizzling via unions (e.g., .xyz, .rgb, .uvw, .xy, .yz)
Configurable handedness: left‑handed (LH) and right‑handed (RH) variants
Configurable NDC depth range: zero‑to‑one (ZO) and negative‑one‑to‑one (NO)
Choice of angle units: radians, degrees, or turns
Static inline functions — no extra compilation unit needed
Public domain (CC0‑1.0) — free to use and modify

Pros & Cons

Pros
  • Truly free and open source (public domain) with no restrictions
  • Single‑header design simplifies integration into any project
  • Works with both C and C++ codebases without extra wrappers
  • Highly configurable to match different graphics APIs (OpenGL, DirectX, Vulkan, Metal)
  • Lightweight and easy to understand/modify
Cons
  • Limited to basic linear algebra and quaternions; no advanced matrix factorization or solvers
  • No GPU‑specific optimizations or SIMD acceleration out of the box
  • Documentation is primarily the header comments and GitHub README

Best For

Game development (rendering, physics, animation)Computer graphics research and prototypingReal-time simulation and visualizationVR/AR applications requiring flexible coordinate conventionsEmbedded or resource‑constrained projects needing a small math library

FAQ

What conventions does Handmade Math use (row vs. column major, handedness, etc.)?
Matrices are column‑major with column vectors. Multiplication is M * V. Functions provide left‑handed and right‑handed variants, and projection functions have zero‑to‑one and negative‑one‑to‑one NDC conventions.
What if I don't want the HMM_ prefix?
You can do a find and replace in the library source to rename the prefix.
What is the license?
Handmade Math is in the public domain (CC0‑1.0 license). You can do whatever you want with it.
Where can I ask questions or get help?
Feel free to open GitHub issues for any questions, concerns, or problems you encounter.