https://github.com/nesktf/ranmath
Header only 3D graphics math library for C++20
https://github.com/nesktf/ranmath
cpp cpp20 graphics-programming header-only math
Last synced: 28 days ago
JSON representation
Header only 3D graphics math library for C++20
- Host: GitHub
- URL: https://github.com/nesktf/ranmath
- Owner: nesktf
- License: mit
- Created: 2026-04-10T18:11:53.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2026-05-22T03:48:22.000Z (2 months ago)
- Last Synced: 2026-05-22T12:44:43.832Z (2 months ago)
- Topics: cpp, cpp20, graphics-programming, header-only, math
- Language: C++
- Homepage:
- Size: 283 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## ran::math

Header only 3D graphics math library for C++20. Optimized to be used with Vulkan & OpenGL.
## Building
Clone the repo somewhere in your project's library folder.
```sh
$ cd my_funny_project/
$ mkdir -p lib/
$ git clone https://github.com/nesktf/ranmath.git ./lib/ranmath
```
Then add the library as a subdirectory in your CMakeLists.txt.
```cmake
cmake_minimum_required(VERSION 3.25)
project(my_funny_project CXX)
# ...
add_subdirectory("lib/ranmath")
# ...
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
target_link_libraries(${PROJECT_NAME} ranmath::ranmath)
```
Alternatively, you can generate a single header file either by using the script at
`script/single.py` or by defining the option `RAN_SINGLE` and running `make`. You need
Python 3 installed and available in your PATH.
```sh
$ cmake -B build -DRAN_SINGLE=1
$ make -C build -j$(nproc)
```
The script generates two header files: `ranmath/ran.hpp` with definitions and `ranmath/forward.hpp`
with declarations. These two are written to `/include/` by default. You can
just copy these two to your project folder and use them directly.
```sh
$ mkdir -p lib/ranmath/
$ cp build/include/ranmath* lib/ranmath/
```
## Usage
Include either `` for forward declarations or `` for the
actual definitions.
The library has a similar API to [GLM](https://github.com/g-truc/glm) with some small
differences to suit my tastes. Matrices are column major just like GLM.
```cpp
#include
ran::Vec3f32 rotate_y(ran::Vec3f32 vec, ran::f32 angle) {
const auto mat = ran::rotate(ran::Mat4f32::identity(), angle, ran::Vec3f32(0.f, 1.f, 0.f));
return vec * mat;
}
```
## TODO
- Add feature list
- Add tests
- Add docs
- Add examples
- Add C++20 module