A small, header-only C++17 mathematics library for 2D/3D work: fixed-size vectors, fixed-size matrices, and a simple scene graph. Everything has value semantics and dimensions are encoded in the type, so size mismatches are caught at compile time.
- A C++17 compiler (g++, clang++, or MSVC)
- No external dependencies (standard library only)
| Header | Provides |
|---|---|
vec.h | Vector<T, N> — generic fixed-size vector (base class) |
vec2.h | vec2<T> with .x() / .y() accessors and 2D cross |
vec3.h | vec3<T> with .x() / .y() / .z() accessors and 3D cross |
vec4.h | vec4<T> with .x() / .y() / .z() / .w() accessors |
matrix.h | matrix<T, M, N> — fixed-size matrix |
SceneGraph.h | SceneNode — hierarchical scene graph |
Mesh.h | Minimal Mesh / OGLRenderer stubs used by the scene graph |
#include"vec3.h"
vec3<float> a(1, 2, 3);
vec3<float> b(4, 5, 6);
auto sum = a + b; // component-wise addauto diff = a - b; // component-wise subtractauto had = a * b; // component-wise (Hadamard) productauto scaled = a * 2.0f; // scalar multiply (also 2.0f * a)float d = a.dot(b); // dot productauto c = a.cross(b); // cross product (vec3)float len = a.length(); // magnitudeauto unit = a.normalized(); // unit-length copyfloat xs = a.x(); // named accessor
a[0] = 10; // indexed accessAlso available: operator+= -= *= /=, unary -, operator== / !=,
lengthSquared(), and in-place normalize(). vec2::cross returns the scalar
signed area (z-component of the 3D cross product).
#include"matrix.h"
matrix<float, 2, 3> a;
a(0, 0) = 1.0f; // (row, col) accessauto i = matrix<float, 4, 4>::identity();
auto t = a.transpose(); // 3x2auto p = a * b; // (2x3)*(3x2) -> 2x2, checked at compile timeauto s = 2.0f * a; // scalar multiplyfloat dt = c.det(); // determinant (square matrices only)Dimension mismatches (e.g. multiplying incompatible sizes, or taking the determinant of a non-square matrix) are compile-time errors.
#include"SceneGraph.h"
SceneNode root;
SceneNode* child = new SceneNode(); // ownership transfers on AddChild
root.AddChild(child);
root.Update(0.0f); // propagates world transformsA node's world transform is parent.worldTransform * localTransform. Mesh.h
provides placeholder Mesh / OGLRenderer types so the scene graph compiles
standalone; swap them for your real rendering backend.
g++ -std=c++17 -Wall -Wextra Source.cpp -o mathlib_demo
./mathlib_demoSee LICENSE.