Single-file public domain headers (or MIT licensed) libraries for C (C99)
The main goal of these libraries is to be fast, and usable for games programming - with a sprinkle of machine learning and general maths.
This library is in the style of: https://github.com/nothings/stb
Current Libraries:
- Vector, matrix and quaternion: r2_maths.h
- UTF-8 String library: r2_strings.h
- Simple ncurses like library thing: r2_termui.h
- Minimal unit testing: r2_unit.h
Copy any of the header files you want to use into your code base. See the header files for instructions (mostly you just include them).
Example:
curl https://raw.githubusercontent.com/robrohan/r2/main/r2_termui.h > ./src/r2_termui.h- Clone this library as a git submodule into a target project:
$ cd my_project
$ mkdir vendor
$ cd vendor
$ git submodule add https://github.com/robrohan/r2.git- Then the vendor directory to your compiler flags:
-I./vendor - In the main part of your application (only once), import the library with the implementation flag:
...
# include <limits.h>
# define R2_MATHS_IMPLEMENTATION
# include "r2/r2_maths.h"
# include <string.h>
...- Anywhere else you need the functions, use the include without the flag:
# include <limits.h>
# include "r2/r2_maths.h"
# include <string.h>- Go for gold. See
tests/r2_maths.cfor some example usages, or look atr2_maths.hfor reference.
vec3 v1 = {.x = 3.f, .y = 3.f, .z = 3.f};
vec3 v2 = {.x = -30.f, .y = 30.f, .z = -30.f};
vec4 out = {0};
vec3_cross(&v1, &v2, &out);make testNote: If you are on windows, currently, you'll have to write something like
a test.bat yourself (or some magic to import the files into Visual Studio).
You can use test.sh as a template.
To compile and run the code in web assembly, first make sure you have
emscripten setup,
working, and the emcc environment variables setup:
source ~/Projects/spikes/emsdk/emsdk_env.shThen just run make test_wasm passing in the emcc compiler and output to html:
make test_wasmYou can then use run some sort of http server against the bin directory. For
example (busboy), or python. Then load
the HTML page in a browser.