mgmath
is a small vector/matrix math library with some basic transform support, and is meant to be used mainly in 3D graphics programming.
It is a header-only library in the most pure sense, as it only consists of a single header file, which contains everything
Some usage examples for vectors and matrices
- To create a basic vector with a number of components:
vec<2, TYPE>
withx
y
(shortvec2...
)vec<3, TYPE>
withx
y
z
(shortvec3...
)vec<4, TYPE>
withx
y
z
w
(shortvec4...
)
- After vector name
vecx
you can addi
,u
,f
,d
:i
for an intiger vector (vec2i32
for int32_t vector)u
for an unsigned intiger vector (vec2u32
for uint32_t vector)f
for a float vector (vec2f
for float vector)d
for a double vector (vec2d
for double vector)
- You can also use anything from 8-bit intigers, to 64-bit intigers (signed and unsigned)
vec2u8
vec2u16
vec2u32
vec2u64
- You can also use the
vec
template to create your own vectorvec<4, float>
is the equivalent ofvec4f
vec<3, uint16_t>
is the equivalent ofvec3u16
- The
vec
template contains functionsx()
y()
z()
w()
, equivalent to getting an element using[0]
[1]
[2]
[3]
vec<2, float> v;
-v[0] = 10;
is the same asv.x() = 10;
- To create a basic matrix, it's similar to vector
- The matrices already declared in the header are only square; To use a non-square matrix, use the template:
mat<3, 3, float>
is the equivalent of mat3fmat<4, 3, float>
creates a 4x3 matrix of floats
- Matrices have functions to rotate along any axis in any given order:
rotate2d
rotates the matrix, then returns a reference to itrotated2d
returns a rotated version of the matrix, without modifying the originalrotate3d_xyz
rotated the matrix in the orderx
, theny
, thenz
- And so on and so forth
- 2D matrices:
- 2x2 for
rotation
andscale
- 3x3 for
position
,rotation
,scale
andskew
- 2x2 for
- 3D matrices:
- 3x3 for
rotation
andscale
in all 3 axis - 4x4 for
position
,rotation
,scale
andskew
- 3x3 for
- Everything is tightly packed, so a list of float vectors is the same as a larger list of floats
- This means you can easily send them to OpenGL, Vulkan or other APIs that require you to send data in large packs
- There is SIMD support on
x86_64
andamd64
thanks to SSE and AVX. (so far only forvec4f
, andmat4f
)
- Add remaining transform functions for matrices
- Add SIMD support for every possible vector
- Add SIMD support on arm
- Add transform tree (old transform parents sucked)