A SIMD-oriented linear algebra library for graphics-style code: vectors, matrices, quaternions, rigid transforms, and trig helpers. The public API lives in the mathLib namespace; include MathLib.h for the full surface (core math plus optional app helpers).
mathLib is a compact C++ library built around SSE intrinsics (__m128), with types such as Vec3, Vec4, Mat3, Mat4, and Quat, plus helpers for scale, translation, rotation, and common trig. It is intended for projects that need fast CPU-side math (transforms, animation, tooling) and a clear, documented convention for how vectors and matrices combine.
- Vectors —
Vec3,Vec4with SIMD-backed storage where applicable - Matrices —
Mat3,Mat4with row-major element layout (see below) - Quaternions —
Quatand related helpers - Transforms — scale, translation, rotation utilities (
Scale,Trans,Rot) - Trig —
Trigstatic methods (angles in radians)
- Toolchain — Microsoft Visual C++ (MSVC) is the primary supported compiler; headers use SSE intrinsics (
<xmmintrin.h>,<smmintrin.h>). - Platform — x86 / x64 Windows targets match the current intrinsics and project layout.
- C++ — A recent C++ standard with support for move semantics and
constexpras used in the headers (typically C++11 or newer). - Alignment — Several types inherit
Align16(16-byte alignment for SIMD). Your application must define this base (for example via a smallFramework.hincluded before math headers), matching how the library expects alignednew/ storage forVec3,Vec4,Mat3,Mat4, andQuat.
These rules are the “contract” between this library and your renderer or tools.
Vec4andVec3behave as row vectors on the left of a matrix.- Use
v * M(e.g.Vec4 * Mat4,Vec3 * Mat3), notM * v. - For
Vec4×Mat4, each result component is the dot product ofvwith the corresponding column ofM(equivalently: row-vector × matrix in the usual linear-algebra sense).
Mat4is stored in row-major order: scalarsm0–m3are the first row,m4–m7the second,m8–m11the third,m12–m15the fourth. The matrix is composed of four row vectors (Row4accessors).Mat3follows the same idea for its 3×3 layout (see accessors / element naming inMat3.h).- Matrix × matrix uses
Mat4 * Mat4/Mat3 * Mat3as implemented; when chaining transforms with row vectors, composition order must match your engine’s expectations—verify against a known test (e.g. translate then rotate) when wiring to rendering.
Trigfunctions take angles in radians (see parameter names inTrig.h).- The library does not fix a global clip space or NDC range; projection and handedness are your responsibility. Use the same row-vector and row-major rules when building view/projection matrices so they match
v * M. - Handedness (left- vs right-handed) is not enforced here; cross products and rotation helpers follow the implemented formulas—sanity-check against your asset pipeline if mixing with other libraries.
- Types derived from
Align16must be 16-byte aligned in memory. Avoid packing them in unaligned structs or treating them as arbitrary byte blobs without alignment guarantees.
-
Add the
include/directory to your project’s additional include paths. -
Compile and link the
src/translation units (or your static library project that wraps them). -
Ensure
Align16is defined and included before math headers, per your project’s framework. -
In code, include the umbrella header and qualify types:
#include "MathLib.h" void example() { using namespace mathLib; Vec4 v(1.0f, 0.0f, 0.0f, 1.0f); Mat4 M(Identity); Vec4 v2 = v * M; }
-
Prefer
#include "MathLib.h"for applications. For tighter dependencies you can include specific headers (e.g."Vec4.h","Mat4.h") instead.
Optional but recommended for efficiency: MATH_USE_HINTS (see Mat4.h) enables hint machinery for matrix operations; leave it as in the headers unless you have a reason to change it.
mathLib ships as include/ and src/ only. You fold it into a project you already have (executable or static library).
- Bring in the tree — Copy the
includeandsrcfolders into your repo (for examplethird_party/mathLib/includeandthird_party/mathLib/src), or keep them elsewhere and use absolute/relative paths in the steps below. - Include path — Open your project’s Property Pages → C/C++ → General → Additional Include Directories and add the directory that contains
MathLib.h(theincludefolder itself, not its parent). - Compile the sources — In Solution Explorer, right-click your project → Add → Existing Item… and add every
.cppundersrc/(or add the wholesrcfolder if your VS version supports it). Those files build as part of your target; there is no separate math.libunless you split it into its own static library project later. - C++ and intrinsics — Use a C++ dialect that matches Requirements (e.g. C/C++ → Language → C++ Language Standard set to at least C++11). MSVC enables SSE/SSE2 for typical x64 and modern Win32 configs; if you hit missing intrinsic errors on an unusual target, check C/C++ → Code Generation (e.g. enable SSE2 for 32-bit builds).
- Alignment base class — Ensure
Align16is visible to the translation units that include math headers (see Requirements). - Build — Compile your project; resolve any missing includes or linker issues the same way you would for any other added sources.
Other build systems (CMake, etc.) follow the same idea: add the include directory, compile all src/*.cpp, satisfy Align16, and use MSVC-friendly flags for SSE intrinsics.
This project is released under the MIT License. See the LICENSE file for the full text and copyright notice.