A modern, header-only C++20 math library for game engines and real-time graphics applications. Provides comprehensive support for vectors, matrices, quaternions, spatial data structures, curves, and transformations.
- Vectors: Vector2, Vector3, Vector4 with full operator support
- Matrices: Matrix3, Matrix4 with inverse, transpose, decomposition
- Quaternions: Rotation, slerp, axis-angle conversion, Euler angles
- Dual Quaternions: Skeletal animation and skinning support
- Primitives: AABB, Sphere, Capsule, Cylinder, Cone, Plane, Ray, Triangle
- Intersection Testing: Ray-AABB, Ray-Sphere, Capsule-AABB, and more
- Bounding Volumes: Merge, contain, intersect operations
- BVH: Bounding Volume Hierarchy for efficient spatial queries
- Octree: 8-way spatial partitioning for large scenes
- KD-Tree: k-d tree for ray tracing and point queries
- Bezier: Quadratic and Cubic Bezier curves
- B-Spline: General B-spline curves with configurable degree
- NURBS: Non-Uniform Rational B-Splines for conic sections
- Catmull-Rom: Smooth interpolation through points
- Hermite: Tangent-controlled spline curves
- Transform: Position, rotation, scale composition
- TransformNode: Hierarchical scene graph with dirty propagation
- Basis: Orthonormal basis creation and manipulation
- Angles: Degree/radian conversion, normalization
- Interpolation: Lerp, smoothstep, ease functions
- Random: Deterministic and non-deterministic generators
- SoA: Structure of Arrays for batch operations
- SIMD: Vectorized operations using SSE/AVX (optional)
- C++20 compatible compiler (GCC 12+, Clang 14+, MSVC 19.29+)
- CMake 3.16 or higher
- SIMD: Requires CPU with SSE4.1 support (optional, enabled via CMake)
The easiest way to use MML is to download the single-header file:
-
Download
mml.hppfrom the releases page or generate it:python scripts/generate_header.py
-
Copy
mml.hppto your project -
Include in your code:
#include "mml.hpp"
Copy the src/ directory to your project:
cp -r src /your/project/include/mmlThen include in your code:
#include "mml.hpp"Add to your CMakeLists.txt:
add_subdirectory(path/to/MachinaMathLibrary)
target_link_libraries(your_target PRIVATE mml)cmake -B build -S . -DMML_USE_SIMD=ON
cmake --install build --prefix /usr/localcmake -B build -S . [options]| Option | Default | Description |
|---|---|---|
MML_USE_SIMD |
ON |
Enable SIMD vectorization (SSE4.1+) |
MML_BUILD_TESTS |
OFF |
Build test suite |
MML_BUILD_BENCHMARKS |
OFF |
Build benchmarks |
cmake --build build [--config Release]cmake --build build --target run_tests
# Or run directly:
./build/Release/MML_tests.exe # Windows
./build/Release/MML_tests # Linuxcmake -B build -S . -DMML_BUILD_EXAMPLES=ON
cmake --build build| Status | Badge |
|---|---|
| Tests | |
| Build |
#include "mml.hpp"
mml::Vector3f position(1.0f, 2.0f, 3.0f);
mml::Vector3f velocity(0.5f, 1.0f, 0.0f);
float dot = position.dot(velocity);
mml::Vector3f cross = position.cross(velocity);
mml::Vector3f normalized = position.normalized();mml::Matrix4f model = mml::Matrix4f::identity();
model = model * mml::Matrix4f::translation(1.0f, 0.0f, 0.0f);
model = model * mml::Matrix4f::rotation_y(mml::Constantsf::half_pi);
model = model * mml::Matrix4f::scale(2.0f, 2.0f, 2.0f);
mml::Vector4f transformed = model * mml::Vector4f(1.0f, 0.0f, 0.0f, 1.0f);mml::Quaternionf rotation = mml::Quaternionf::from_euler(0.5f, 0.3f, 0.2f);
mml::Quaternionf slerped = mml::Quaternionf::slerp(q1, q2, 0.5f);
mml::Vector3f axis;
float angle;
rotation.to_axis_angle(axis, angle);mml::Transformf transform;
transform.position = mml::Vector3f(0.0f, 1.0f, 0.0f);
transform.rotation = mml::Quaternionf::from_axis_angle(mml::Vector3f::unit_y(), 1.57f);
transform.scale = mml::Vector3f(2.0f, 2.0f, 2.0f);
mml::Matrix4f matrix = transform.to_matrix();
mml::Transformf inverse = transform.inverse();// Cubic Bezier
mml::BezierCubicf bezier(
mml::Vector3f(0, 0, 0),
mml::Vector3f(1, 1, 0),
mml::Vector3f(2, 1, 0),
mml::Vector3f(3, 0, 0)
);
mml::Vector3f point = bezier.evaluate(0.5f);
// B-Spline
mml::BSplinef spline(control_points, degree=3);
auto samples = spline.sample(100);
// NURBS Circle
mml::NURBSf circle = mml::NURBSf::circle_2d(1.0f, 32, 2);// BVH
mml::BVH<float, MyPrim> bvh([](const MyPrim& p) { return p.bounds; });
bvh.build(primitives);
auto hits = bvh.ray_intersect(ray_origin, ray_direction);
// Octree
mml::Octree<float, Sphere> octree;
octree.insert(sphere1);
octree.insert(sphere2);
auto nearby = octree.aabb_query(search_bounds);mml::DualQuaternionf dq = mml::DualQuaternionf::from_rotation_translation(
mml::Quaternionf::identity(),
mml::Vector3f(0.0f, 1.0f, 0.0f)
);
// Skinning
mml::Matrix4f skin_matrix = dq.to_matrix();
// Skeleton
mml::Skeletonf skeleton;
skeleton.add_bone("root", bone0);
skeleton.add_bone("child", bone1, "root");MML includes optional SIMD optimizations for batch operations:
constexpr size_t count = 4;
mml::Vector4f positions[count] = { ... };
mml::Vector4f velocities[count] = { ... };
mml::Vector4f results[count];
mml::simd::batch::add_arrays(results, positions, velocities, count);
mml::simd::batch::lerp_arrays(results, positions, velocities, 0.5f, count);Enable SIMD with:
cmake -B build -DMML_USE_SIMD=ON- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE for details.
Current version: v1.0.0
See CHANGELOG for release history.