BEFORE ALL | This library is a learning project that I mainly use to refresh my math knowledge.
MathLib is a modern, header-only mathematics library for C++.
It provides a complete foundation for 2D and 3D applications: linear algebra, geometry, transformations, and rotation handling.
MathLib is entirely independent from any graphics API or engine.
It can be used in game engines, physics simulations, rendering tools, or any project that requires a reliable and efficient mathematical core.
- Generic types:
Vec2,Vec3,Vec4,Mat2,Mat3,Mat4,Quaternion - Complete vector and matrix operations
- 3D transformations:
Translate,Rotate,Scale,LookAt,Perspective,Ortho - Quaternion-based rotations and conversions (Euler ↔ Matrix ↔ Quaternion)
- Fully
constexprand header-only (no dependencies) - Window / MSBuild Only
- SIMD-ready (SSE, AVX, NEON)
- Inspired by GLM
math/
├── common.hpp # Base types and utilities
├── vector.hpp # Generic vectors (Vec2, Vec3, Vec4)
├── matrix.hpp # Matrix types (Mat2, Mat3, Mat4)
├── quaternion.hpp # Rotations and interpolation
├── transform.hpp # Transformations and camera matrices
└── math.hpp # Global include header
#include <math/math.hpp>
using namespace math;
int main()
{
Vec3 position = { 0, 0, 5 };
Vec3 target = { 0, 0, 0 };
Vec3 up = { 0, 1, 0 };
Mat4 view = LookAt(position, target, up);
Mat4 proj = Perspective(DegToRad(70.0f), 16.0f / 9.0f, 0.1f, 100.0f);
Vec4 worldPos = { 1, 2, 3, 1 };
Vec4 clipPos = proj * view * worldPos;
return 0;
}- Implementation of
Vec,Mat,Quaternion, andTransform - Base functions (
Dot,Cross,Lerp,Clamp, etc.) - Matrix operations (multiplication, transpose, inverse, determinant)
- SIMD implementation (SSE2, AVX, NEON)
- Optimized vector and matrix operations
- Geometric types:
Ray,Plane,AABB,OBB,Sphere - Intersection tests:
RayPlane,RaySphere,AABB-AABB, etc. - Analytical functions:
Barycentric,Reflect,Refract,Project - Statistical helpers:
Average,Variance,Min,Max - Curves and interpolation:
CubicBezier,CatmullRom,Hermite
-
math::color(RGB, HSV, conversions) -
math::noise(Perlin, Simplex, Worley) -
math::random(random distributions) -
math::geometry(normals, tangents) -
math::spline(NURBS, B-Spline)
- Complete unit test coverage
- Doxygen documentation
- Example projects under
examples/
- Semantic versioning (
v1.0.0) - Contribution guidelines and PR templates
- Compatibility checks (GLM, Eigen, DirectXMath)
- Language: C++20 or higher
- Platforms: Windows
- Dependencies: None
Simply include the library headers in your project:
#include "math/math.hpp"MIT License
Free to use, modify, and distribute.
MathLib aims to provide a clear, performant, and durable mathematical foundation for any modern 3D or simulation project.