{"id":19831732,"url":"https://github.com/robrohan/r2","last_synced_at":"2025-05-01T16:32:20.724Z","repository":{"id":66564669,"uuid":"294221328","full_name":"robrohan/r2","owner":"robrohan","description":"A vector, quaternion, and matrix single-file public domain library for C99","archived":false,"fork":false,"pushed_at":"2024-12-18T06:17:02.000Z","size":136,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T15:25:34.543Z","etag":null,"topics":["c","c99","game-2d","game-development","gamedev","maths","matrix","matrix-multiplication"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robrohan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2020-09-09T20:24:17.000Z","updated_at":"2024-12-18T06:16:38.000Z","dependencies_parsed_at":"2023-10-11T04:33:23.311Z","dependency_job_id":"c51d4113-8c6d-4eaa-bfd8-d25089a96d36","html_url":"https://github.com/robrohan/r2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrohan%2Fr2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrohan%2Fr2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrohan%2Fr2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrohan%2Fr2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robrohan","download_url":"https://codeload.github.com/robrohan/r2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251906974,"owners_count":21663189,"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":["c","c99","game-2d","game-development","gamedev","maths","matrix","matrix-multiplication"],"created_at":"2024-11-12T11:34:18.902Z","updated_at":"2025-05-01T16:32:20.709Z","avatar_url":"https://github.com/robrohan.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ℝ² Some Simple, C99 Vector, Matrix, UTF8 String, and Terminal Libraries\n\nSingle-file public domain headers (or MIT licensed) libraries for C (C99)\n\n![C/C++ CI](https://github.com/robrohan/r2/workflows/C/C++%20CI/badge.svg)\n\nThe main goal of these libraries is to be fast, and usable for games \nprogramming - with a sprinkle of machine learning and general maths.\n\nThis library is in the style of: https://github.com/nothings/stb\n\nCurrent Libraries:\n\n- Vector, matrix and quaternion: [r2_maths.h](./r2_maths.h)\n- UTF-8 String library: [r2_strings.h](./r2_strings.h)\n- Simple ncurses like library thing: [r2_termui.h](./r2_termui.h)\n- Minimal unit testing: [r2_unit.h](./r2_unit.h)\n\n## Installation\n\nCopy any of the header files you want to use into your code base. See the \nheader files for instructions (mostly you just include them).\n\nExample:\n\n```bash\ncurl https://raw.githubusercontent.com/robrohan/r2/main/r2_termui.h \u003e ./src/r2_termui.h\n```\n\n## Using the Vector, Quaternion, and Matrix Functions\n\n1. Clone this library as a git submodule into a target project:\n\n```bash\n$ cd my_project\n$ mkdir vendor\n$ cd vendor\n$ git submodule add https://github.com/robrohan/r2.git\n```\n\n2. Then the vendor directory to your compiler flags: `-I./vendor`\n3. In the _main_ part of your application (only once), import the library with \nthe implementation flag:\n\n```c\n...\n# include \u003climits.h\u003e\n# define R2_MATHS_IMPLEMENTATION\n# include \"r2/r2_maths.h\"\n# include \u003cstring.h\u003e\n...\n```\n\n4. Anywhere else you need the functions, use the include without the flag:\n\n```c\n# include \u003climits.h\u003e\n# include \"r2/r2_maths.h\"\n# include \u003cstring.h\u003e\n```\n\n5. Go for gold. See `tests/r2_maths.c` for some example usages, or look at \n`r2_maths.h` for reference.\n\n```c\n  vec3 v1 = {.x = 3.f, .y = 3.f, .z = 3.f};\n  vec3 v2 = {.x = -30.f, .y = 30.f, .z = -30.f};\n  vec4 out = {0};\n  vec3_cross(\u0026v1, \u0026v2, \u0026out);\n```\n\n### Testing\n\n```sh\nmake test\n```\n\n_Note_: If you are on windows, currently, you'll have to write something like \na `test.bat` yourself (or some magic to import the files into Visual Studio). \nYou can use `test.sh` as a template.\n\n### Testing in Web Assembly\n\nTo compile and run the code in web assembly, first make sure you have \n[emscripten setup](https://emscripten.org/docs/getting_started/downloads.html), \nworking, and the `emcc` environment variables setup:\n\n```sh\nsource ~/Projects/spikes/emsdk/emsdk_env.sh\n```\n\nThen just run `make test_wasm` passing in the `emcc` compiler and output to `html`:\n\n```bash\nmake test_wasm\n```\n\nYou can then use run some sort of http server against the `bin` directory. For\nexample ([busboy](https://github.com/robrohan/busboy)), or python. Then load \nthe HTML page in a browser.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobrohan%2Fr2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobrohan%2Fr2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobrohan%2Fr2/lists"}